feat:nuclideConcAvg计算

This commit is contained in:
nieziyan 2024-02-18 19:26:38 +08:00
parent 12f2f1e23e
commit bbe1ba7110
6 changed files with 88 additions and 34 deletions
jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/entity/postgre
jeecg-module-abnormal-alarm/src/main/java/org/jeecg/modules

View File

@ -19,6 +19,14 @@ public class AlarmAnalysisNuclideAvg extends JeecgEntity {
this.val = val; this.val = val;
} }
public AlarmAnalysisNuclideAvg(String stationId ,String nuclide, String val) {
this.stationId = stationId;
this.nuclide = nuclide;
this.val = val;
}
private String stationId;
/** 核素名称 */ /** 核素名称 */
private String nuclide; private String nuclide;

View File

@ -13,6 +13,8 @@
<where> <where>
ana.ANALYSISBEGIN BETWEEN to_date(#{startDate},'yyyy-mm-dd hh24:mi:ss') ana.ANALYSISBEGIN BETWEEN to_date(#{startDate},'yyyy-mm-dd hh24:mi:ss')
AND to_date(#{endDate},'yyyy-mm-dd hh24:mi:ss') AND to_date(#{endDate},'yyyy-mm-dd hh24:mi:ss')
AND samp.DATA_TYPE = 'S' AND samp.STATUS IN ('P', 'R')
AND samp.STATION_ID = #{stationId}
<if test="nuclideName != null and nuclideName.size() > 0"> <if test="nuclideName != null and nuclideName.size() > 0">
AND nucl.NUCLIDENAME IN AND nucl.NUCLIDENAME IN
<foreach collection="nuclideName" open="(" close=")" index="index" item="item" separator=","> <foreach collection="nuclideName" open="(" close=")" index="index" item="item" separator=",">

View File

@ -13,6 +13,8 @@
<where> <where>
ana.ANALYSISBEGIN BETWEEN to_date(#{startDate},'yyyy-mm-dd hh24:mi:ss') ana.ANALYSISBEGIN BETWEEN to_date(#{startDate},'yyyy-mm-dd hh24:mi:ss')
AND to_date(#{endDate},'yyyy-mm-dd hh24:mi:ss') AND to_date(#{endDate},'yyyy-mm-dd hh24:mi:ss')
AND samp.DATA_TYPE = 'S' AND samp.STATUS IN ('P', 'R')
AND samp.STATION_ID = #{stationId}
<if test="nuclideName != null and nuclideName.size() > 0"> <if test="nuclideName != null and nuclideName.size() > 0">
AND nucl.NUCLIDENAME IN AND nucl.NUCLIDENAME IN
<foreach collection="nuclideName" open="(" close=")" index="index" item="item" separator=","> <foreach collection="nuclideName" open="(" close=")" index="index" item="item" separator=",">

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.mapper.GardsXeResultsAutoMapper"> <mapper namespace="org.jeecg.modules.mapper.GardsXeResultsAutoMapper">
<select id="getConc" resultType="org.jeecg.modules.base.dto.ConcDtoXe"> <select id="getConc" resultType="org.jeecg.modules.base.dto.ConcDtoXe">
SELECT SELECT
xe.NUCLIDE_NAME, xe.NUCLIDE_NAME,
@ -14,6 +13,8 @@
<where> <where>
ana.ANALYSISBEGIN BETWEEN to_date(#{startDate},'yyyy-mm-dd hh24:mi:ss') ana.ANALYSISBEGIN BETWEEN to_date(#{startDate},'yyyy-mm-dd hh24:mi:ss')
AND to_date(#{endDate},'yyyy-mm-dd hh24:mi:ss') AND to_date(#{endDate},'yyyy-mm-dd hh24:mi:ss')
AND samp.DATA_TYPE = 'S' AND samp.STATUS IN ('P', 'R')
AND samp.STATION_ID = #{stationId}
<if test="nuclideName != null and nuclideName.size() > 0"> <if test="nuclideName != null and nuclideName.size() > 0">
AND xe.NUCLIDE_NAME IN AND xe.NUCLIDE_NAME IN
<foreach collection="nuclideName" open="(" close=")" index="index" item="item" separator=","> <foreach collection="nuclideName" open="(" close=")" index="index" item="item" separator=",">

View File

@ -13,6 +13,8 @@
<where> <where>
ana.ANALYSISBEGIN BETWEEN to_date(#{startDate},'yyyy-mm-dd hh24:mi:ss') ana.ANALYSISBEGIN BETWEEN to_date(#{startDate},'yyyy-mm-dd hh24:mi:ss')
AND to_date(#{endDate},'yyyy-mm-dd hh24:mi:ss') AND to_date(#{endDate},'yyyy-mm-dd hh24:mi:ss')
AND samp.DATA_TYPE = 'S' AND samp.STATUS IN ('P', 'R')
AND samp.STATION_ID = #{stationId}
<if test="nuclideName != null and nuclideName.size() > 0"> <if test="nuclideName != null and nuclideName.size() > 0">
AND xe.NUCLIDE_NAME IN AND xe.NUCLIDE_NAME IN
<foreach collection="nuclideName" open="(" close=")" index="index" item="item" separator=","> <foreach collection="nuclideName" open="(" close=")" index="index" item="item" separator=",">

View File

@ -53,14 +53,29 @@ public class CalculateConcServiceImpl implements CalculateConcService {
public boolean calcAndSave() { public boolean calcAndSave() {
try { try {
String comma = SymbolConstant.COMMA; String comma = SymbolConstant.COMMA;
// 获取所有生效的报警规则
List<AlarmAnalysisRule> analysisRules = analysisRuleService.allAnalysisRule(); List<AlarmAnalysisRule> analysisRules = analysisRuleService.allAnalysisRule();
Set<String> nuclideNames = analysisRules.stream() // 对所有报警规则的关注台站和关注核素进行统计
.map(AlarmAnalysisRule::getNuclides) Map<String, Set<String>> nuclideMap = new HashMap<>(); // key:台站code value:核素列表
.filter(StrUtil::isNotBlank) for (AlarmAnalysisRule analysisRule : analysisRules) {
.flatMap(nuclides -> ListUtil.toList(nuclides.split(comma)).stream()) String stationStr = analysisRule.getStations();
.collect(Collectors.toSet()); String nuclideStr = analysisRule.getNuclides();
// 获取关注台站
List<String> stations = ListUtil.toList(StrUtil.split(stationStr, comma));
// 获取关注核素
Set<String> nuclides = new HashSet<>(ListUtil.toList(StrUtil.split(nuclideStr, comma)));
for (String station : stations) {
if (nuclideMap.containsKey(station)){
Set<String> partNuclides = new HashSet<>(nuclideMap.get(station));
partNuclides.addAll(nuclides);
nuclideMap.put(station, partNuclides);
}else {
nuclideMap.put(station, nuclides);
}
}
}
// 核素浓度值查询参数准备
Map<String,Object> params = new HashMap<>(); Map<String,Object> params = new HashMap<>();
params.put("nuclideName",nuclideNames);
AlarmAnalysisNuclideParam paramLatest = nuclideParamService.getLatest(); AlarmAnalysisNuclideParam paramLatest = nuclideParamService.getLatest();
BigDecimal index = paramLatest.getIndex(); BigDecimal index = paramLatest.getIndex();
Integer days = paramLatest.getDays(); Integer days = paramLatest.getDays();
@ -71,38 +86,62 @@ public class CalculateConcServiceImpl implements CalculateConcService {
String endDate = dayAgo.format(formatter); String endDate = dayAgo.format(formatter);
params.put("startDate",startDate + DateConstant.TIME_START); params.put("startDate",startDate + DateConstant.TIME_START);
params.put("endDate",endDate + DateConstant.TIME_END); params.put("endDate",endDate + DateConstant.TIME_END);
/* Auto自动处理 */
// beta-gamma
List<ConcDtoXe> xeConcAuto = xeResultsAutoService.getConc(params);
// gamma
List<ConcDto> nuclConcAuto = nuclIdedAutoService.getConc(params);
Map<String,String> autoResult = new HashMap<>(); // 遍历所有台站 计算每个台站的所有核素浓度均值
autoResult.putAll(calculate(concDto(xeConcAuto), index)); /* Auto自动处理 */
autoResult.putAll(calculate(nuclConcAuto, index)); List<AlarmAnalysisNuclideAvg> autoAvgs = new ArrayList<>();
List<AlarmAnalysisNuclideAvg> autoAvgs = autoResult.entrySet().stream() for (Map.Entry<String, Set<String>> entry : nuclideMap.entrySet()) {
.map(entry -> new AlarmAnalysisNuclideAvg(entry.getKey(), entry.getValue())) String station = entry.getKey();
.collect(Collectors.toList()); Set<String> nuclides = entry.getValue();
autoAvgs.forEach(item -> item.setDataSourceType(CommonConstant.ARMDARR)); // 查询指定台站的所有的核素浓度 并计算核素浓度均值
params.put("nuclideName", nuclides);
params.put("stationId", station);
List<ConcDtoXe> xeConcAuto = xeResultsAutoService.getConc(params); // beta-gamma
List<ConcDto> nuclConcAuto = nuclIdedAutoService.getConc(params); // gamma
Map<String, String> autoResult = new HashMap<>();
autoResult.putAll(calculate(concDto(xeConcAuto), index));
autoResult.putAll(calculate(nuclConcAuto, index));
for (String nuclide : nuclides) {
String val = autoResult.get(nuclide);
AlarmAnalysisNuclideAvg analysisNuclideAvg = new AlarmAnalysisNuclideAvg(station, nuclide, val);
analysisNuclideAvg.setDataSourceType(CommonConstant.ARMDARR);
autoAvgs.add(analysisNuclideAvg);
}
}
/* Man人工交互 */ /* Man人工交互 */
// beta-gamma List<AlarmAnalysisNuclideAvg> manAvgs = new ArrayList<>();
List<ConcDtoXe> xeConcMan = xeResultsManService.getConc(params); for (Map.Entry<String, Set<String>> entry : nuclideMap.entrySet()) {
// gamma String station = entry.getKey();
List<ConcDto> nuclConcMan = nuclIdedManService.getConc(params); Set<String> nuclides = entry.getValue();
Map<String,String> manResult = new HashMap<>(); // 查询指定台站的所有的核素浓度 并计算核素浓度均值
manResult.putAll(calculate(concDto(xeConcMan), index)); params.put("nuclideName", nuclides);
manResult.putAll(calculate(nuclConcMan, index)); params.put("stationId", station);
List<AlarmAnalysisNuclideAvg> manAvgs = manResult.entrySet().stream() List<ConcDtoXe> xeConcMan = xeResultsManService.getConc(params); // beta-gamma
.map(entry -> new AlarmAnalysisNuclideAvg(entry.getKey(), entry.getValue())) List<ConcDto> nuclConcMan = nuclIdedManService.getConc(params); // gamma
.collect(Collectors.toList()); Map<String,String> manResult = new HashMap<>();
manAvgs.forEach(item -> item.setDataSourceType(CommonConstant.ARMDRRR)); manResult.putAll(calculate(concDto(xeConcMan), index));
manAvgs.addAll(autoAvgs); manResult.putAll(calculate(nuclConcMan, index));
for (String nuclide : nuclides) {
String val = manResult.get(nuclide);
AlarmAnalysisNuclideAvg analysisNuclideAvg = new AlarmAnalysisNuclideAvg(station, nuclide, val);
analysisNuclideAvg.setDataSourceType(CommonConstant.ARMDRRR);
manAvgs.add(analysisNuclideAvg);
}
}
// 自动处理和人工交互库的台站核素浓度均值结果合并
List<AlarmAnalysisNuclideAvg> allAvgs = new ArrayList<>();
allAvgs.addAll(autoAvgs);
allAvgs.addAll(manAvgs);
// 计算周期和计算日期
String cycle = startDate + SymbolConstant.WELL_NUMBER + endDate; String cycle = startDate + SymbolConstant.WELL_NUMBER + endDate;
manAvgs.forEach(item -> item.setCycle(cycle).setCaclDate(dayAgo)); allAvgs.forEach(item -> item.setCycle(cycle).setCaclDate(dayAgo));
// 记录日志 // 记录日志
log.info(log(manAvgs)); log.info(log(allAvgs));
return nuclideAvgService.saveBatch(manAvgs); return nuclideAvgService.saveBatch(allAvgs);
}catch (Throwable e){ }catch (Throwable e){
e.printStackTrace(); e.printStackTrace();
log.error("核素浓度计算过程异常: {}", e.getMessage()); log.error("核素浓度计算过程异常: {}", e.getMessage());