Commit c51e5840 authored by tianbo's avatar tianbo

修改气瓶充装信息统计与定时任务数据同步不一致问题

parent a46a2470
package com.yeejoin.amos.config; //package com.yeejoin.amos.config;
//
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; //import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; //import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; //import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//
@Configuration //@Configuration
@EnableWebSecurity //@EnableWebSecurity
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { //public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
//
@Override // @Override
protected void configure(HttpSecurity http) throws Exception { // protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().and() // http.httpBasic().and()
.authorizeRequests() // .authorizeRequests()
.regexMatchers("^(?!/actuator).*$").permitAll() // .regexMatchers("^(?!/actuator).*$").permitAll()
.regexMatchers("/actuator/health").permitAll() // .regexMatchers("/actuator/health").permitAll()
.regexMatchers("/actuator/info").permitAll() // .regexMatchers("/actuator/info").permitAll()
.regexMatchers("/actuator/metrics").permitAll() // .regexMatchers("/actuator/metrics").permitAll()
.antMatchers("/actuator/metrics/**").permitAll() // .antMatchers("/actuator/metrics/**").permitAll()
.anyRequest() // .anyRequest()
.authenticated() // .authenticated()
.and().csrf().disable(); // .and().csrf().disable();
} // }
} //}
package com.yeejoin.amos; package com.yeejoin.amos;
import java.net.InetAddress; import com.yeejoin.amos.boot.biz.common.utils.oConvertUtils;
import java.net.UnknownHostException; import com.yeejoin.amos.boot.module.tzs.biz.listener.BaseEnterpriseMqTtlListener;
import com.yeejoin.amos.boot.module.tzs.biz.listener.CarcylUnitInspectMqTtlListener;
import com.yeejoin.amos.boot.module.tzs.biz.listener.FillingRecordSyncListener;
import com.yeejoin.amos.boot.module.tzs.biz.listener.PrivilegeCompanyDeleteListener; import com.yeejoin.amos.boot.module.tzs.biz.listener.PrivilegeCompanyDeleteListener;
import com.yeejoin.amos.boot.module.tzs.biz.listener.PrivilegeCompanyUpdateAddListener; import com.yeejoin.amos.boot.module.tzs.biz.listener.PrivilegeCompanyUpdateAddListener;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.StartPlatformTokenService;
import com.yeejoin.amos.boot.module.tzs.flc.api.service.ICylinderInfoService;
import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttException;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -26,11 +29,8 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -26,11 +29,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.typroject.tyboot.component.emq.EmqKeeper; import org.typroject.tyboot.component.emq.EmqKeeper;
import com.yeejoin.amos.boot.biz.common.utils.oConvertUtils; import java.net.InetAddress;
import com.yeejoin.amos.boot.module.tzs.biz.listener.BaseEnterpriseMqTtlListener; import java.net.UnknownHostException;
import com.yeejoin.amos.boot.module.tzs.biz.listener.CarcylUnitInspectMqTtlListener;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.StartPlatformTokenService;
import com.yeejoin.amos.boot.module.tzs.flc.api.service.ICylinderInfoService;
/** /**
* <pre> * <pre>
...@@ -73,6 +73,9 @@ public class AmosTzsApplication { ...@@ -73,6 +73,9 @@ public class AmosTzsApplication {
private PrivilegeCompanyDeleteListener privilegeCompanyDeleteListener; private PrivilegeCompanyDeleteListener privilegeCompanyDeleteListener;
@Autowired @Autowired
private FillingRecordSyncListener fillingRecordSyncListener;
@Autowired
ICylinderInfoService cylinderInfoServiceImpl; ICylinderInfoService cylinderInfoServiceImpl;
public static void main(String[] args) throws UnknownHostException { public static void main(String[] args) throws UnknownHostException {
...@@ -98,6 +101,7 @@ public class AmosTzsApplication { ...@@ -98,6 +101,7 @@ public class AmosTzsApplication {
emqKeeper.getMqttClient().subscribe("/tm/tz_base_enterprise_info", 1, baseEnterpriseMqTtlListener); emqKeeper.getMqttClient().subscribe("/tm/tz_base_enterprise_info", 1, baseEnterpriseMqTtlListener);
emqKeeper.getMqttClient().subscribe("/tz/privilege_company_add_update", 1, privilegeCompanyUpdateAddListener); emqKeeper.getMqttClient().subscribe("/tz/privilege_company_add_update", 1, privilegeCompanyUpdateAddListener);
emqKeeper.getMqttClient().subscribe("/tz/privilege_company_delete", 1, privilegeCompanyDeleteListener); emqKeeper.getMqttClient().subscribe("/tz/privilege_company_delete", 1, privilegeCompanyDeleteListener);
emqKeeper.getMqttClient().subscribe("/tzs/sync/fillingRecord", 1, fillingRecordSyncListener);
// emqKeeper.getMqttClient().subscribe("topic_mqtt_exam", 1, examMqTtlListener); // emqKeeper.getMqttClient().subscribe("topic_mqtt_exam", 1, examMqTtlListener);
// emqKeeper.getMqttClient().subscribe("topic_mqtt_exam_record", 1, examMqTtRecordListener); // emqKeeper.getMqttClient().subscribe("topic_mqtt_exam_record", 1, examMqTtRecordListener);
} }
......
package com.yeejoin.amos.boot.module.tzs.biz.listener;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.tzs.flc.biz.service.impl.CylinderInfoServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqxListener;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
/**
* @Description: 气瓶充装信息mqtt监听服务
* @Author: tb
* @Date: 2022/12/20
*/
@Component
@Slf4j
public class FillingRecordSyncListener extends EmqxListener {
@Autowired
CylinderInfoServiceImpl cylinderInfoService;
@Override
public void processMessage(String topic, MqttMessage message) throws Exception {
System.out.println(message);
if (!ValidationUtil.isEmpty(message.toString())) {
cylinderInfoService.synUnitFillingCheckData();
}
}
}
...@@ -30,4 +30,12 @@ public class CylinderFillingCheckDataUnitServiceImpl extends BaseService<Cylinde ...@@ -30,4 +30,12 @@ public class CylinderFillingCheckDataUnitServiceImpl extends BaseService<Cylinde
public List<CylinderFillingCheckDataUnitDto> queryForCylinderFillingCheckDataUnitList() { public List<CylinderFillingCheckDataUnitDto> queryForCylinderFillingCheckDataUnitList() {
return this.queryForList("" , false); return this.queryForList("" , false);
} }
/**
* 列表查询 示例
*/
public List<CylinderFillingCheckDataUnitDto> queryCylinderFillingCheckListByParam(String appId,
String fillingDate) {
return this.queryForList("" , false, appId, fillingDate);
}
} }
\ No newline at end of file
...@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
...@@ -556,66 +557,100 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind ...@@ -556,66 +557,100 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?") @Scheduled(cron = "0 0 2 * * ?")
public void synUnitFillingCheckData() { public void synUnitFillingCheckData() {
cylinderFillingCheckDataUnitServiceImpl.remove(new LambdaQueryWrapper<CylinderFillingCheckDataUnit>()); // cylinderFillingCheckDataUnitServiceImpl.remove(new LambdaQueryWrapper<CylinderFillingCheckDataUnit>());
countByUnit(cylinderUnit -> { countByUnit(cylinderUnit -> {
List<CylinderFillingCheckDataUnitDto> allCylinderFillingCheckDataList =
cylinderFillingCheckDataUnitServiceImpl.queryCylinderFillingCheckListByParam(cylinderUnit.getAppId(), null);
// 按照月份 获取数据 取一年数据 // 按照月份 获取数据 取一年数据
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
// 按月份获取充装量 // 第一次查询到该appId对应的统计数据为空,则计算过去一年12个月的数据统计
// 当月与上月 对比获取数据 if (ValidationUtil.isEmpty(allCylinderFillingCheckDataList)) {
for (int i = 0; i < 12; i++) { // 按月份获取充装量
// 获取当月数据 // 当月与上月 对比获取数据
CylinderFillingCheckDataUnitDto temp = new CylinderFillingCheckDataUnitDto(); for (int i = 0; i < 12; i++) {
String year = c.get(Calendar.YEAR) + ""; // 获取当月数据
int month = c.get(Calendar.MONTH) + 1; CylinderFillingCheckDataUnitDto temp = new CylinderFillingCheckDataUnitDto();
String monthStr = month < 10 ? "0" + month : month + ""; calcCylinderFillingCheckDataUnitData(cylinderUnit, c, temp);
temp.setFillingMonth(monthStr); c.add(Calendar.MONTH, -1);
temp.setFillingYear(year); cylinderFillingCheckDataUnitServiceImpl.createWithModel(temp);
temp.setFillingDate(year + "-" + monthStr);
Integer countThisMonth = cylinderFillingRecordServiceImpl
.getFillingCountByMonth(cylinderUnit.getAppId(), c.getTime());
temp.setTotalSum((long) countThisMonth);
// 获取本月数据
Integer fillingCount = cylinderFillingServiceImpl.getFillingCountByMonth(cylinderUnit.getAppId(),
c.getTime());
Integer fillingCheckCount = cylinderFillingCheckServiceImpl
.getFillingCountByMonth(cylinderUnit.getAppId(), c.getTime());
// 充装前检查率:充装前检查次数/充装次数
double before = 0d;
if (countThisMonth != 0) {
before = (double) (fillingCount) / (double) countThisMonth;
} }
temp.setFillingCount((long) fillingCount); } else {
temp.setFillingPercent(before * 100); // 如果已经有该appId对应数据,则直接更新当前月的数据即可
// 充装后检查率:充装后检查次数/充装次数 Calendar current = Calendar.getInstance();
double after = 0d; String year = current.get(Calendar.YEAR) + "";
if (countThisMonth != 0) { int month = current.get(Calendar.MONTH) + 1;
after = (double) (fillingCheckCount) / (double) countThisMonth; String monthStr = month < 10 ? "0" + month : month + "";
} List<CylinderFillingCheckDataUnitDto> existDataDtoList =
temp.setFillingCheckCount((long) fillingCheckCount); cylinderFillingCheckDataUnitServiceImpl.queryCylinderFillingCheckListByParam(cylinderUnit.getAppId(), year + "-" + monthStr);
temp.setFillingCheckPercent(after * 100); CylinderFillingCheckDataUnitDto tempDto = new CylinderFillingCheckDataUnitDto();
// 充装合格率:充装前检查合格次数+充装后检查合格次数/2*充装次数 if (!ValidationUtil.isEmpty(existDataDtoList) && !ValidationUtil.isEmpty(existDataDtoList.get(0))) {
double passed = 0d; tempDto = existDataDtoList.get(0);
// 充装前检查合格次数 calcCylinderFillingCheckDataUnitData(cylinderUnit, current, tempDto);
Integer fillingPassedCount = cylinderFillingServiceImpl cylinderFillingCheckDataUnitServiceImpl.updateWithModel(tempDto);
.getFillingPassedCountByMonth(cylinderUnit.getAppId(), c.getTime()); } else if (ValidationUtil.isEmpty(existDataDtoList)) {
// 充装后检查合格次数 // 处理当前月第一天还没数据情况
Integer fillingCheckPassedCount = cylinderFillingCheckServiceImpl calcCylinderFillingCheckDataUnitData(cylinderUnit, current, tempDto);
.getFillingPassedCountByMonth(cylinderUnit.getAppId(), c.getTime()); cylinderFillingCheckDataUnitServiceImpl.createWithModel(tempDto);
if (countThisMonth != 0) {
passed = ((double) (fillingPassedCount) + (double) fillingCheckPassedCount)
/ (double) (2 * countThisMonth);
} }
temp.setFillingPassedCount((long) (fillingPassedCount + fillingCheckPassedCount));
temp.setTotalSumDouble((long) 2 * countThisMonth);
temp.setFillingPassedPercent(passed * 100);
temp.setAppId(cylinderUnit.getAppId());
c.add(Calendar.MONTH, -1);
cylinderFillingCheckDataUnitServiceImpl.createWithModel(temp);
} }
}); });
} }
/** /**
* 计算当前单位的充装检查数据统计
*
* @param cylinderUnit
* @param calender
* @param cylinderFillingCheckDataUnitDto
*/
public void calcCylinderFillingCheckDataUnitData(CylinderUnit cylinderUnit, Calendar calender, CylinderFillingCheckDataUnitDto cylinderFillingCheckDataUnitDto) {
String year = calender.get(Calendar.YEAR) + "";
int month = calender.get(Calendar.MONTH) + 1;
String monthStr = month < 10 ? "0" + month : month + "";
cylinderFillingCheckDataUnitDto.setFillingMonth(monthStr);
cylinderFillingCheckDataUnitDto.setFillingYear(year);
cylinderFillingCheckDataUnitDto.setFillingDate(year + "-" + monthStr);
Integer countThisMonth = cylinderFillingRecordServiceImpl
.getFillingCountByMonth(cylinderUnit.getAppId(), calender.getTime());
cylinderFillingCheckDataUnitDto.setTotalSum((long) countThisMonth);
// 获取本月数据
Integer fillingCount = cylinderFillingServiceImpl.getFillingCountByMonth(cylinderUnit.getAppId(),
calender.getTime());
Integer fillingCheckCount = cylinderFillingCheckServiceImpl
.getFillingCountByMonth(cylinderUnit.getAppId(), calender.getTime());
// 充装前检查率:充装前检查次数/充装次数
double before = 0d;
if (countThisMonth != 0) {
before = (double) (fillingCount) / (double) countThisMonth;
}
cylinderFillingCheckDataUnitDto.setFillingCount((long) fillingCount);
cylinderFillingCheckDataUnitDto.setFillingPercent(before * 100);
// 充装后检查率:充装后检查次数/充装次数
double after = 0d;
if (countThisMonth != 0) {
after = (double) (fillingCheckCount) / (double) countThisMonth;
}
cylinderFillingCheckDataUnitDto.setFillingCheckCount((long) fillingCheckCount);
cylinderFillingCheckDataUnitDto.setFillingCheckPercent(after * 100);
// 充装合格率:充装前检查合格次数+充装后检查合格次数/2*充装次数
double passed = 0d;
// 充装前检查合格次数
Integer fillingPassedCount = cylinderFillingServiceImpl
.getFillingPassedCountByMonth(cylinderUnit.getAppId(), calender.getTime());
// 充装后检查合格次数
Integer fillingCheckPassedCount = cylinderFillingCheckServiceImpl
.getFillingPassedCountByMonth(cylinderUnit.getAppId(), calender.getTime());
if (countThisMonth != 0) {
passed = ((double) (fillingPassedCount) + (double) fillingCheckPassedCount)
/ (double) (2 * countThisMonth);
}
cylinderFillingCheckDataUnitDto.setFillingPassedCount((long) (fillingPassedCount + fillingCheckPassedCount));
cylinderFillingCheckDataUnitDto.setTotalSumDouble((long) 2 * countThisMonth);
cylinderFillingCheckDataUnitDto.setFillingPassedPercent(passed * 100);
cylinderFillingCheckDataUnitDto.setAppId(cylinderUnit.getAppId());
}
/**
* 充装量、卸液量按单位统计 * 充装量、卸液量按单位统计
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment