feat:修改分析结果报警条件逻辑

This commit is contained in:
nieziyan 2024-05-08 15:37:52 +08:00
parent 035e842240
commit 95a150122c
16 changed files with 81 additions and 87 deletions

View File

@ -1,13 +1,14 @@
package org.jeecg.common.util; package org.jeecg.common.util;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
public class DataTool { public class DataTool {
private int counter = 1; private int counter = 1;
private final Map<String, Object> data = new HashMap<>(); private final Map<String, Object> data = new LinkedHashMap<>();
public DataTool put(Object value) { public DataTool put(Object value) {
data.put(String.format("p%d", counter), value); data.put(String.format("p%d", counter), value);

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.base.enums;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import lombok.Getter;
/** /**
* 资源类型 * 资源类型
@ -9,22 +10,19 @@ import cn.hutool.core.util.StrUtil;
* @author nieziyan * @author nieziyan
* @date 2023-06-30 * @date 2023-06-30
*/ */
@Getter
public enum SourceType { public enum SourceType {
EMAIL("Email"), EMAIL("Email"),
DATABASE("Database"), DATABASE("Database"),
SERVER("Server"); SERVER("Server");
private String type; private final String type;
SourceType(String type) { SourceType(String type) {
this.type = type; this.type = type;
} }
public String getType() {
return type;
}
public static SourceType typeOf(String type){ public static SourceType typeOf(String type){
for (SourceType sourceType : SourceType.values()) { for (SourceType sourceType : SourceType.values()) {
if (StrUtil.equals(sourceType.getType(),type)) if (StrUtil.equals(sourceType.getType(),type))

View File

@ -14,6 +14,4 @@ import java.util.Set;
public interface GardsNuclIdedAutoMapper extends BaseMapper<GardsNuclIded> { public interface GardsNuclIdedAutoMapper extends BaseMapper<GardsNuclIded> {
List<ConcDto> getConc(Map<String,Object> param); List<ConcDto> getConc(Map<String,Object> param);
List<String> nuclideNames(Set<String> nuclideNames);
} }

View File

@ -13,6 +13,4 @@ import java.util.Set;
public interface GardsNuclIdedManMapper extends BaseMapper<GardsNuclIded> { public interface GardsNuclIdedManMapper extends BaseMapper<GardsNuclIded> {
List<ConcDto> getConc(Map<String,Object> param); List<ConcDto> getConc(Map<String,Object> param);
List<String> nuclideNames(Set<String> nuclideNames);
} }

View File

@ -14,6 +14,4 @@ import java.util.Set;
public interface GardsXeResultsAutoMapper extends BaseMapper<GardsXeResults> { public interface GardsXeResultsAutoMapper extends BaseMapper<GardsXeResults> {
List<ConcDtoXe> getConc(Map<String,Object> params); List<ConcDtoXe> getConc(Map<String,Object> params);
List<String> nuclideNames(Set<String> nuclideNames);
} }

View File

@ -14,6 +14,4 @@ import java.util.Set;
public interface GardsXeResultsManMapper extends BaseMapper<GardsXeResults> { public interface GardsXeResultsManMapper extends BaseMapper<GardsXeResults> {
List<ConcDtoXe> getConc(Map<String,Object> params); List<ConcDtoXe> getConc(Map<String,Object> params);
List<String> nuclideNames(Set<String> nuclideNames);
} }

View File

@ -23,18 +23,4 @@
</if> </if>
</where> </where>
</select> </select>
<select id="nuclideNames" resultType="java.lang.String">
SELECT
NUCLIDENAME
FROM
RNAUTO.GARDS_NUCL_IDED
WHERE
NUCLIDENAME IN
<foreach collection="nuclideNames" separator="," item="nuclideName" index="index" open="(" close=")">
#{nuclideName}
</foreach>
GROUP BY
NUCLIDENAME
</select>
</mapper> </mapper>

View File

@ -23,18 +23,4 @@
</if> </if>
</where> </where>
</select> </select>
<select id="nuclideNames" resultType="java.lang.String">
SELECT
NUCLIDENAME
FROM
RNMAN.GARDS_NUCL_IDED
WHERE
NUCLIDENAME IN
<foreach collection="nuclideNames" separator="," item="nuclideName" index="index" open="(" close=")">
#{nuclideName}
</foreach>
GROUP BY
NUCLIDENAME
</select>
</mapper> </mapper>

View File

@ -23,18 +23,4 @@
</if> </if>
</where> </where>
</select> </select>
<select id="nuclideNames" resultType="java.lang.String">
SELECT
NUCLIDE_NAME
FROM
RNAUTO.GARDS_XE_RESULTS
WHERE
NUCLIDE_NAME IN
<foreach collection="nuclideNames" separator="," item="nuclideName" index="index" open="(" close=")">
#{nuclideName}
</foreach>
GROUP BY
NUCLIDE_NAME
</select>
</mapper> </mapper>

View File

@ -23,18 +23,4 @@
</if> </if>
</where> </where>
</select> </select>
<select id="nuclideNames" resultType="java.lang.String">
SELECT
NUCLIDE_NAME
FROM
RNMAN.GARDS_XE_RESULTS
WHERE
NUCLIDE_NAME IN
<foreach collection="nuclideNames" separator="," item="nuclideName" index="index" open="(" close=")">
#{nuclideName}
</foreach>
GROUP BY
NUCLIDE_NAME
</select>
</mapper> </mapper>

View File

@ -156,6 +156,8 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
String betaOrGamma = info.getBetaOrGamma(); String betaOrGamma = info.getBetaOrGamma();
String datasource = info.getDatasource(); String datasource = info.getDatasource();
String stationId = info.getStationId(); String stationId = info.getStationId();
String sampleId = info.getSampleId();
String sampleName = info.getSampleName();
// 获取谱文件采样日期 如果为null 则默认为LocalDate.now() // 获取谱文件采样日期 如果为null 则默认为LocalDate.now()
LocalDate collDate = ObjectUtil.isNull(info.getCollectionDate()) ? LocalDate.now() : LocalDate collDate = ObjectUtil.isNull(info.getCollectionDate()) ? LocalDate.now() :
info.getCollectionDate().toLocalDate(); info.getCollectionDate().toLocalDate();
@ -163,7 +165,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
List<String> conditions = ListUtil.toList(conditionStr.split(COMMA)); List<String> conditions = ListUtil.toList(conditionStr.split(COMMA));
List<String> firstDetected = new ArrayList<>(); // 首次发现 List<String> firstDetected = new ArrayList<>(); // 首次发现
List<NuclideInfo> moreThanAvg = new ArrayList<>(); // 超浓度均值 List<NuclideInfo> moreThanAvg = new ArrayList<>(); // 超浓度均值
List<String> meanwhile = new ArrayList<>(); // 同时出现两种及以上核素 List<String> meanWhile = new ArrayList<>(); // 同时出现两种及以上核素
for (String con : conditions) { for (String con : conditions) {
Condition condition = Condition.valueOf1(con); Condition condition = Condition.valueOf1(con);
if (ObjectUtil.isNull(condition)) continue; if (ObjectUtil.isNull(condition)) continue;
@ -175,8 +177,8 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
moreThanAvg = moreThanAvg(datasource, stationId, collDate, nuclidesCross); moreThanAvg = moreThanAvg(datasource, stationId, collDate, nuclidesCross);
break; break;
case MEANWHILE: // 同时出现两种及以上核素 case MEANWHILE: // 同时出现两种及以上核素
if (CollUtil.isNotEmpty(nuclideNames) && nuclideNames.size() >= 2) meanWhile = meanWhile(betaOrGamma, datasource, nuclideNames);
meanwhile.addAll(nuclideNames); if (meanWhile.size() < 2) meanWhile = ListUtil.empty();
break; break;
default: default:
break; break;
@ -192,10 +194,13 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
.collect(Collectors.joining(StrUtil.COMMA + StrUtil.SPACE)); .collect(Collectors.joining(StrUtil.COMMA + StrUtil.SPACE));
dataTool.put("moreThanAvg", above); dataTool.put("moreThanAvg", above);
} }
if (CollUtil.isNotEmpty(meanwhile)) if (CollUtil.isNotEmpty(meanWhile))
dataTool.put("meanwhile", CollUtil.join(meanwhile, StrUtil.COMMA + StrUtil.SPACE)); dataTool.put("meanwhile", CollUtil.join(meanWhile, StrUtil.COMMA + StrUtil.SPACE));
// 如果报警数据为空 则不需要发送报警信息和生成报警日志 // 如果报警数据为空 则不需要发送报警信息和生成报警日志
if (MapUtil.isEmpty(dataTool.get())) return; if (MapUtil.isEmpty(dataTool.get())) return;
// 台站信息和Sample信息
dataTool.put("stationId", stationId).put("sampleId", sampleId).put("sampleName", sampleName);
// 构建预警信息实例 准备发送预警信息
MessageDTO messageDTO = TemplateUtil.parse1(ANALYSIS_NUCLIDE.getCode(), dataTool.get()); MessageDTO messageDTO = TemplateUtil.parse1(ANALYSIS_NUCLIDE.getCode(), dataTool.get());
// 保存报警日志 // 保存报警日志
AlarmAnalysisLog logInfo = new AlarmAnalysisLog(); AlarmAnalysisLog logInfo = new AlarmAnalysisLog();
@ -216,12 +221,12 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
/** /**
* 首次发现该核素 * 首次发现该核素
*/ */
private List<String> firstDetected(String betaOrGamma, private List<String> firstDetected(String betaOrGamma, String dataSourceType, Set<String> nuclideNames){
String dataSourceType, // 查询用户关注的核素是否存在 如果不存在则为首次发现该核素
Set<String> nuclideNames){ // 判断核素是否存在的条件: 该核素的Conc值是否大于MDC值
List<String> existNames = analysisResultService List<String> existNames = analysisResultService
.nuclideNames(betaOrGamma, dataSourceType, nuclideNames); .nuclideNames(betaOrGamma, dataSourceType, nuclideNames);
// 两个集合元素相减 // 两个集合元素相减则为不存在的核素 即为首次出现的核素
return CollUtil.subtractToList(nuclideNames, existNames); return CollUtil.subtractToList(nuclideNames, existNames);
} }
@ -260,6 +265,15 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
return nuclideInfos; return nuclideInfos;
} }
/*
* 是否同时存在两种及以上核素
* */
private List<String> meanWhile(String betaOrGamma, String dataSourceType, Set<String> nuclideNames){
// 查询用户关注的核素是否存在 如果不存在则为首次发现该核素
// 判断核素是否存在的条件: 该核素的Conc值是否大于MDC值
return analysisResultService.nuclideNames(betaOrGamma, dataSourceType, nuclideNames);
}
private void init() { private void init() {
// start 生成临时Token到线程中 // start 生成临时Token到线程中
UserTokenContext.setToken(getTempToken()); UserTokenContext.setToken(getTempToken());

View File

@ -33,7 +33,7 @@ public class AnalysisResultServiceImpl implements AnalysisResultService {
}else if (CommonConstant.GAMMA.equals(betaOrGamma)){ }else if (CommonConstant.GAMMA.equals(betaOrGamma)){
return nuclIdedAutoService.nuclideNames(nuclideNames); return nuclIdedAutoService.nuclideNames(nuclideNames);
}else { }else {
return ListUtil.toList(nuclideNames); return ListUtil.empty();
} }
} else if (CommonConstant.ARMDRRR.equals(dataSourceType)) { } else if (CommonConstant.ARMDRRR.equals(dataSourceType)) {
if (CommonConstant.BETA.equals(betaOrGamma)){ if (CommonConstant.BETA.equals(betaOrGamma)){
@ -41,10 +41,10 @@ public class AnalysisResultServiceImpl implements AnalysisResultService {
}else if (CommonConstant.GAMMA.equals(betaOrGamma)){ }else if (CommonConstant.GAMMA.equals(betaOrGamma)){
return nuclIdedManService.nuclideNames(nuclideNames); return nuclIdedManService.nuclideNames(nuclideNames);
}else { }else {
return ListUtil.toList(nuclideNames); return ListUtil.empty();
} }
}else { }else {
return ListUtil.toList(nuclideNames); return ListUtil.empty();
} }
} }
} }

View File

@ -1,5 +1,7 @@
package org.jeecg.modules.service.impl; package org.jeecg.modules.service.impl;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.NumberUtil;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.constant.DateConstant; import org.jeecg.common.constant.DateConstant;
@ -13,6 +15,7 @@ import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
@ -31,6 +34,16 @@ public class GardsNuclIdedAutoServiceImpl extends ServiceImpl<GardsNuclIdedAutoM
@Override @Override
public List<String> nuclideNames(Set<String> nuclideNames) { public List<String> nuclideNames(Set<String> nuclideNames) {
return baseMapper.nuclideNames(nuclideNames); LambdaQueryWrapper<GardsNuclIded> wrapper = new LambdaQueryWrapper<>();
wrapper.in(GardsNuclIded::getNuclideName, nuclideNames);
List<GardsNuclIded> nuclIdeds = this.list(wrapper);
// 判断核素是否存在的条件: 该核素Conc值是否大于MDC值
Set<String> existNuclides = nuclIdeds.stream()
.filter(item -> NumberUtil.isNumber(item.getConcentration()))
.filter(item -> NumberUtil.isNumber(item.getMdc()))
.filter(item ->NumberUtil.isGreater(new BigDecimal(item.getConcentration()), new BigDecimal(item.getMdc())))
.map(GardsNuclIded::getNuclideName)
.collect(Collectors.toSet());
return ListUtil.toList(existNuclides);
} }
} }

View File

@ -1,16 +1,18 @@
package org.jeecg.modules.service.impl; package org.jeecg.modules.service.impl;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.NumberUtil;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.constant.DateConstant; import org.jeecg.common.constant.DateConstant;
import org.jeecg.modules.base.dto.ConcDto; import org.jeecg.modules.base.dto.ConcDto;
import org.jeecg.modules.base.entity.rnauto.GardsXeResults;
import org.jeecg.modules.base.entity.rnman.GardsNuclIded; import org.jeecg.modules.base.entity.rnman.GardsNuclIded;
import org.jeecg.modules.mapper.GardsNuclIdedManMapper; import org.jeecg.modules.mapper.GardsNuclIdedManMapper;
import org.jeecg.modules.service.IGardsNuclIdedManService; import org.jeecg.modules.service.IGardsNuclIdedManService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
@ -29,6 +31,16 @@ public class GardsNuclIdedManServiceImpl extends ServiceImpl<GardsNuclIdedManMap
@Override @Override
public List<String> nuclideNames(Set<String> nuclideNames) { public List<String> nuclideNames(Set<String> nuclideNames) {
return baseMapper.nuclideNames(nuclideNames); LambdaQueryWrapper<GardsNuclIded> wrapper = new LambdaQueryWrapper<>();
wrapper.in(GardsNuclIded::getNuclideName, nuclideNames);
List<GardsNuclIded> nuclIdeds = this.list(wrapper);
// 判断核素是否存在的条件: 该核素Conc值是否大于MDC值
Set<String> existNuclides = nuclIdeds.stream()
.filter(item -> NumberUtil.isNumber(item.getConcentration()))
.filter(item -> NumberUtil.isNumber(item.getMdc()))
.filter(item ->NumberUtil.isGreater(new BigDecimal(item.getConcentration()), new BigDecimal(item.getMdc())))
.map(GardsNuclIded::getNuclideName)
.collect(Collectors.toSet());
return ListUtil.toList(existNuclides);
} }
} }

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -52,6 +53,15 @@ public class GardsXeResultsAutoServiceImpl extends ServiceImpl<GardsXeResultsAut
@Override @Override
public List<String> nuclideNames(Set<String> nuclideNames) { public List<String> nuclideNames(Set<String> nuclideNames) {
return baseMapper.nuclideNames(nuclideNames); LambdaQueryWrapper<GardsXeResults> wrapper = new LambdaQueryWrapper<>();
wrapper.in(GardsXeResults::getNuclideName, nuclideNames);
List<GardsXeResults> xeResults = this.list(wrapper);
// 判断核素是否存在的条件: 该核素NidFlag值是否为1
Set<String> existNuclides = xeResults.stream()
.filter(item -> ObjectUtil.isNotNull(item.getNidFlag()))
.filter(item -> item.getNidFlag() == 1)
.map(GardsXeResults::getNuclideName)
.collect(Collectors.toSet());
return ListUtil.toList(existNuclides);
} }
} }

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -52,6 +53,15 @@ public class GardsXeResultsManServiceImpl extends ServiceImpl<GardsXeResultsManM
@Override @Override
public List<String> nuclideNames(Set<String> nuclideNames) { public List<String> nuclideNames(Set<String> nuclideNames) {
return baseMapper.nuclideNames(nuclideNames); LambdaQueryWrapper<GardsXeResults> wrapper = new LambdaQueryWrapper<>();
wrapper.in(GardsXeResults::getNuclideName, nuclideNames);
List<GardsXeResults> xeResults = this.list(wrapper);
// 判断核素是否存在的条件: 该核素NidFlag值是否为1
Set<String> existNuclides = xeResults.stream()
.filter(item -> ObjectUtil.isNotNull(item.getNidFlag()))
.filter(item -> item.getNidFlag() == 1)
.map(GardsXeResults::getNuclideName)
.collect(Collectors.toSet());
return ListUtil.toList(existNuclides);
} }
} }