package com.slibra.quartz.task; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONWriter; import com.google.protobuf.ByteString; import com.slibra.business.domain.*; import com.slibra.business.mapper.*; import com.slibra.business.req.*; import com.slibra.business.res.ShowValueCSBasic; import com.slibra.business.res.ShowValueJSBasic; import com.slibra.business.res.ShowValueSHBasic; import com.slibra.business.service.ITXinyiDailyService; import com.slibra.common.DecimalUtils; import com.slibra.common.config.BigModelConfig; import com.slibra.common.constant.MyConstants; import com.slibra.common.core.domain.DecisionReq; import com.slibra.common.core.domain.TXinyiDaily; import com.slibra.common.enums.BusinessEnum; import com.slibra.common.utils.DateUtils; import com.slibra.common.utils.LocalDateTimeUtil; import com.slibra.common.utils.StringUtils; import com.slibra.common.utils.format.WaterFormat; import com.slibra.common.utils.uuid.IdUtils; import com.slibra.quartz.business.JsCsFormatData; import inference.InferenceAPIsServiceGrpc; import inference.PredictionResponse; import inference.PredictionsRequest; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import lombok.extern.slf4j.Slf4j; import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; import static com.slibra.common.constant.MyConstants.*; import static com.slibra.common.enums.BusinessEnum.BigModelWarningTypeRemarkEnum.*; import static com.slibra.common.enums.BusinessEnum.WarningCategoryEnum.*; @Component @Slf4j public class AsyncTask { @Autowired private TXinyiIndustryMapper xinyiIndustryMapper; @Autowired private TXinyiNormConfigMapper xinyiNormConfigMapper; @Autowired private TXinyiWarningRecordMapper xinyiWarningRecordMapper; @Autowired private TXinyiChatRecordMapper xinyiChatRecordMapper; @Autowired private TXinyiDailyMapper xinyiDailyMapper; @Autowired private TXinyiCalculateMapper xinyiCalculateMapper; @Autowired private TXinyiRobotMapper xinyiRobotMapper; @Autowired private TXinyiForecastComparisonMapper xinyiForecastComparisonMapper; @Autowired private TXinyiBigTableHourMapper xinyiBigTableHourMapper; @Autowired private BigModelConfig bigModelConfig; @Autowired private JsCsFormatData jsCsFormatData; /** 使用的是哪个环境 */ @Value("${spring.profiles.active}") private String environment; @Autowired private ITXinyiDailyService xinyiDailyService; /** * * 异步处理告警任务 * @param tXinyiIndustry */ @Async("customizeExecutor") public void handleWarning(TXinyiIndustry tXinyiIndustry){ //2024年6月18日10:45:20 额外计算一下预测的准确度 try { this.updateForecastComparisonByIndustry(tXinyiIndustry); } catch (Exception e) { log.error("-------------------------------更新预测准确度的时候异常,异常信息为{}", e.getMessage()); } log.info("进入了定时任务保存工业库数据并触发报警操作"); //获取配置表 List tXinyiNormConfigs = this.xinyiNormConfigMapper.selectTXinyiNormConfigList(null); if(CollectionUtils.isEmpty(tXinyiNormConfigs)) throw new RuntimeException("未查询到配置信息"); TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0); //2024年6月7日15:26:44 把一些额外的计算的值,同时记录下来(xinyiCalculate对象在生化报警可能用的到) TXinyiCalculate xinyiCalculate = this.addCalculateByIndustry(tXinyiIndustry, normConfig); this.xinyiCalculateMapper.insertTXinyiCalculate(xinyiCalculate); //2024年08月09日14:26:29 为了节省费用,测试环境关闭报警并增加手动触发报警操作 if(PROD_ENVIRONMENT.equalsIgnoreCase(environment)){ //水质报警 this.handleSZWarning(tXinyiIndustry, normConfig); //2024年5月28日14:14:26 下面是新增的 生化报警处理 this.handleSHWarning(tXinyiIndustry, normConfig, xinyiCalculate); } //2024年7月3日18:01:13 额外处理大表数据 this.addBigTable(tXinyiIndustry, xinyiCalculate); } private void addBigTable(TXinyiIndustry tXinyiIndustry, TXinyiCalculate xinyiCalculate) { TXinyiBigTableHour xinyiBigTableHour = TXinyiBigTableHour.builder().build(); //处理工业库的在线数据 this.addIndustry2BigTable(xinyiBigTableHour, tXinyiIndustry); //处理计算的数据 this.addCalculate2BigTable(xinyiBigTableHour, xinyiCalculate); //2024年08月13日13:35:15 修复bug:如果工业库挂了某段时间,那么这段时间内的日报和化验数据可能就一直无法获取到了 //先去查询日报是否,查看是否已经有了 List tXinyiDailies = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(tXinyiIndustry.getTestDate()).build()); if(CollectionUtils.isEmpty(tXinyiDailies)){ log.info("~~~~进入了兜底处理因为工业库挂掉或者其他原因,导致日报数据早于工业库数据的问题@@@%%%"); TXinyiDaily tXinyiDaily = tXinyiDailies.get(0); //处理天级的数据 xinyiDailyService.addDailyData(tXinyiDaily, xinyiBigTableHour); } //再去查询化验库,查看是否已经存在化验库的数据了 List tXinyiRobots = this.xinyiRobotMapper.selectTXinyiRobotList(TXinyiRobot.builder().testHour(tXinyiIndustry.getTestHour()).build()); if(CollectionUtils.isEmpty(tXinyiRobots)){ log.info("~~~~进入了兜底处理因为工业库挂掉或者其他原因,导致化验室数据早于工业库数据的问题@@@***"); TXinyiRobot tXinyiRobot = tXinyiRobots.get(0); jsCsFormatData.addRobot2Hour(xinyiBigTableHour, tXinyiRobot); } //插入 this.xinyiBigTableHourMapper.insertTXinyiBigTableHour(xinyiBigTableHour); } private void addIndustry2BigTable(TXinyiBigTableHour xinyiBigTableHour, TXinyiIndustry tXinyiIndustry) { //2024年7月5日18:13:43 处理时间和日期 xinyiBigTableHour.setTestDate(tXinyiIndustry.getTestDate()); xinyiBigTableHour.setTestHour(tXinyiIndustry.getTestHour()); xinyiBigTableHour.setGyJsCod(tXinyiIndustry.getJsCod()); xinyiBigTableHour.setGyJsPh(tXinyiIndustry.getJsPh()); xinyiBigTableHour.setGyJsSs(tXinyiIndustry.getJsSs()); xinyiBigTableHour.setGyJsTp(tXinyiIndustry.getJsTp()); xinyiBigTableHour.setGyJsTn(tXinyiIndustry.getJsTn()); xinyiBigTableHour.setGyJsNh3(tXinyiIndustry.getJsNh3()); xinyiBigTableHour.setGyJsSwPh(tXinyiIndustry.getJsSwPh()); xinyiBigTableHour.setGyJsBfyw(tXinyiIndustry.getJsBfyw()); xinyiBigTableHour.setGyCsSlqc(tXinyiIndustry.getCsSlqc()); xinyiBigTableHour.setGyCsCod(tXinyiIndustry.getCsCod()); xinyiBigTableHour.setGyCsPh(tXinyiIndustry.getCsPh()); xinyiBigTableHour.setGyCsSs(tXinyiIndustry.getCsSs()); xinyiBigTableHour.setGyCsTn(tXinyiIndustry.getCsTn()); xinyiBigTableHour.setGyCsTp(tXinyiIndustry.getCsTp()); xinyiBigTableHour.setGyCsNh3(tXinyiIndustry.getCsNh3()); xinyiBigTableHour.setGyOneHyzdDo(tXinyiIndustry.getOneHyzdDo()); xinyiBigTableHour.setGyOneHymdDo(tXinyiIndustry.getOneHymdDo()); xinyiBigTableHour.setGyTwoHyzdDo(tXinyiIndustry.getTwoHyzdDo()); xinyiBigTableHour.setGyTwoHymdDo(tXinyiIndustry.getTwoHymdDo()); xinyiBigTableHour.setGyOneMlss(tXinyiIndustry.getOneMlss()); xinyiBigTableHour.setGyTwoMlss(tXinyiIndustry.getTwoMlss()); xinyiBigTableHour.setGyJsTds(tXinyiIndustry.getJsTds()); xinyiBigTableHour.setGyJsSlq(tXinyiIndustry.getJsSlq()); xinyiBigTableHour.setGyNHlbOneGp(tXinyiIndustry.getNHlbOneGp()); xinyiBigTableHour.setGyNHlbTwoGp(tXinyiIndustry.getNHlbTwoGp()); xinyiBigTableHour.setGyNHlbThreeGp(tXinyiIndustry.getNHlbThreeGp()); xinyiBigTableHour.setGyNHlbFourGp(tXinyiIndustry.getNHlbFourGp()); xinyiBigTableHour.setGyNhlBFiveGp(tXinyiIndustry.getNhlBFiveGp()); xinyiBigTableHour.setGyNHlbSixGp(tXinyiIndustry.getNHlbSixGp()); xinyiBigTableHour.setGyWHlbOneGp(tXinyiIndustry.getWHlbOneGp()); xinyiBigTableHour.setGyWHlbTwoGp(tXinyiIndustry.getWHlbTwoGp()); xinyiBigTableHour.setGyWHlbThreeGp(tXinyiIndustry.getWHlbThreeGp()); xinyiBigTableHour.setGyWHlbFourGp(tXinyiIndustry.getWHlbFourGp()); xinyiBigTableHour.setGyWHlbFiveGp(tXinyiIndustry.getWHlbFiveGp()); xinyiBigTableHour.setGyFjOne(tXinyiIndustry.getFjOne()); xinyiBigTableHour.setGyFjTwo(tXinyiIndustry.getFjTwo()); xinyiBigTableHour.setGyFjThree(tXinyiIndustry.getFjThree()); xinyiBigTableHour.setGyFjFour(tXinyiIndustry.getFjFour()); xinyiBigTableHour.setGyFjFive(tXinyiIndustry.getFjFive()); xinyiBigTableHour.setGyFjSix(tXinyiIndustry.getFjSix()); xinyiBigTableHour.setGyKqllOne(tXinyiIndustry.getKqllOne()); xinyiBigTableHour.setGyKqllTwo(tXinyiIndustry.getKqllTwo()); xinyiBigTableHour.setGyKqllThree(tXinyiIndustry.getKqllThree()); xinyiBigTableHour.setGyKqllFour(tXinyiIndustry.getKqllFour()); xinyiBigTableHour.setGyKqllFive(tXinyiIndustry.getKqllFive()); xinyiBigTableHour.setGyKqllSix(tXinyiIndustry.getKqllSix()); xinyiBigTableHour.setGySjtyjly(tXinyiIndustry.getSJTYJLY()); xinyiBigTableHour.setGyCljyssll(tXinyiIndustry.getCLJYSSLL()); xinyiBigTableHour.setGyHycRjyAll(tXinyiIndustry.getHycRjyAll()); xinyiBigTableHour.setGyHycRjyZdAll(tXinyiIndustry.getHycRjyZdAll()); xinyiBigTableHour.setGyHycWnndAll(tXinyiIndustry.getHycWnndAll()); xinyiBigTableHour.setGyClP04Ycz(tXinyiIndustry.getCLP04YCZ()); } private void addCalculate2BigTable(TXinyiBigTableHour xinyiBigTableHour, TXinyiCalculate xinyiCalculate) { xinyiBigTableHour.setJsJsTdb(xinyiCalculate.getJsTdb()); xinyiBigTableHour.setJsJsTlb(xinyiCalculate.getJsTlb()); xinyiBigTableHour.setJsJsBodBCod(xinyiCalculate.getJsBodBCod()); xinyiBigTableHour.setJsYyqHrt(xinyiCalculate.getYyqHrt()); xinyiBigTableHour.setJsQyqHrt(xinyiCalculate.getQyqHrt()); xinyiBigTableHour.setJsHyqHrt(xinyiCalculate.getHyqHrt()); xinyiBigTableHour.setJsHfxwnndzb(xinyiCalculate.getHFXWNNDZB()); xinyiBigTableHour.setJsFM(xinyiCalculate.getFM()); xinyiBigTableHour.setJsGsls(xinyiCalculate.getGSLS()); xinyiBigTableHour.setJsGslsOne(xinyiCalculate.getGslsOne()); xinyiBigTableHour.setJsGslsTwo(xinyiCalculate.getGslsTwo()); xinyiBigTableHour.setJsXgsGsls(xinyiCalculate.getXgsGsls()); xinyiBigTableHour.setJsXlcscBmfh(xinyiCalculate.getXlcscBmfh()); xinyiBigTableHour.setJsXlcscHrt(xinyiCalculate.getXlcscHrt()); xinyiBigTableHour.setJsCccdcBmfh(xinyiCalculate.getCccdcBmfh()); xinyiBigTableHour.setJsCccdcHrt(xinyiCalculate.getCccdcHrt()); xinyiBigTableHour.setJsEccBmfh(xinyiCalculate.getEccBmfh()); xinyiBigTableHour.setJsEccHrt(xinyiCalculate.getEccHrt()); xinyiBigTableHour.setJsEccGtfh(xinyiCalculate.getEccGtfh()); xinyiBigTableHour.setJsClsnJcsj(xinyiCalculate.getClsnJcsj()); xinyiBigTableHour.setJsXgcdcQsqSsls(xinyiCalculate.getXgcdcQsqSsls()); xinyiBigTableHour.setJsWhlb(xinyiCalculate.getWHLB()); xinyiBigTableHour.setJsNhlb(xinyiCalculate.getNHLB()); xinyiBigTableHour.setJsWdscnl(xinyiCalculate.getWDSCNL()); xinyiBigTableHour.setJsQsb(xinyiCalculate.getQSB()); xinyiBigTableHour.setJsFcxsl(xinyiCalculate.getFCXSL()); xinyiBigTableHour.setJsFcxslbl(xinyiCalculate.getFCXSLBL()); //2024年7月11日15:57:20 外回流比采用新的公式计算 xinyiBigTableHour.setJsWhlbRN(xinyiCalculate.getWhlRN()); } /** * 额外计算一下预测的准确度 * @param tXinyiIndustry */ private void updateForecastComparisonByIndustry(TXinyiIndustry tXinyiIndustry) { BigDecimal csCod = tXinyiIndustry.getCsCod(); BigDecimal csSs = tXinyiIndustry.getCsSs(); BigDecimal csTn = tXinyiIndustry.getCsTn(); BigDecimal csTp = tXinyiIndustry.getCsTp(); BigDecimal csNh3 = tXinyiIndustry.getCsNh3(); String testHour = tXinyiIndustry.getTestHour(); //时间段1 List tXinyiForecastComparisons1 = this.xinyiForecastComparisonMapper.selectTXinyiForecastComparisonList(TXinyiForecastComparison.builder().forecastTimeOne(testHour).build()); if(!CollectionUtils.isEmpty(tXinyiForecastComparisons1)){ for (TXinyiForecastComparison tXinyiForecastComparison : tXinyiForecastComparisons1) { BigDecimal hsForecastOne = tXinyiForecastComparison.getHsForecastOne(); BigDecimal yyForecastOne = tXinyiForecastComparison.getYyForecastOne(); if(BusinessEnum.BigModelForecastEnum.COD.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(csCod); if(!Objects.isNull(csCod) && csCod.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)){ BigDecimal subtract = csCod.subtract(hsForecastOne); tXinyiForecastComparison.setHsErrorRateOne((subtract).divide(csCod, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastOne)){ BigDecimal subtract = csCod.subtract(yyForecastOne); tXinyiForecastComparison.setYyErrorRateOne((subtract).divide(csCod, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.SS.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(csSs); if(!Objects.isNull(csSs) && csSs.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)){ BigDecimal subtract = csSs.subtract(hsForecastOne); tXinyiForecastComparison.setHsErrorRateOne((subtract).divide(csSs, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastOne)){ BigDecimal subtract = csSs.subtract(yyForecastOne); tXinyiForecastComparison.setYyErrorRateOne((subtract).divide(csSs, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } //2024年6月21日16:28:56 tn总氮的预测用xsy1和xsy2计算 并从化验库获取 /*if(TN.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(csTn); if(!Objects.isNull(csTn) && csTn.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)) tXinyiForecastComparison.setHsErrorRateOne((csTn.subtract(hsForecastOne)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(yyForecastOne)) tXinyiForecastComparison.setYyErrorRateOne((csTn.subtract(yyForecastOne)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } }*/ //2024年6月20日11:16:55 出水总磷的真实值从化验室获取 /*if(TP.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(csTp); if(!Objects.isNull(csTp) && csTp.compareTo(BigDecimal.ZERO) > 0){ tXinyiForecastComparison.setHsErrorRateOne((csTp.subtract(hsForecastOne)).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyErrorRateOne((csTp.subtract(yyForecastOne)).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } }*/ if(BusinessEnum.BigModelForecastEnum.NH3.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(csNh3); if(!Objects.isNull(csNh3) && csNh3.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)){ BigDecimal subtract = csNh3.subtract(hsForecastOne); tXinyiForecastComparison.setHsErrorRateOne((subtract).divide(csNh3, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastOne)){ BigDecimal subtract = csNh3.subtract(yyForecastOne); tXinyiForecastComparison.setYyErrorRateOne((subtract).divide(csNh3, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } this.xinyiForecastComparisonMapper.updateTXinyiForecastComparison(tXinyiForecastComparison); } } //时间段2 List tXinyiForecastComparisons2 = this.xinyiForecastComparisonMapper.selectTXinyiForecastComparisonList(TXinyiForecastComparison.builder().forecastTimeTwo(testHour).build()); if(!CollectionUtils.isEmpty(tXinyiForecastComparisons2)){ for (TXinyiForecastComparison tXinyiForecastComparison : tXinyiForecastComparisons2) { BigDecimal hsForecastTwo = tXinyiForecastComparison.getHsForecastTwo(); BigDecimal yyForecastTwo = tXinyiForecastComparison.getYyForecastTwo(); if(BusinessEnum.BigModelForecastEnum.COD.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(csCod); if(!Objects.isNull(csCod) && csCod.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)){ BigDecimal subtract = csCod.subtract(hsForecastTwo); tXinyiForecastComparison.setHsErrorRateTwo((subtract).divide(csCod, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastTwo)){ BigDecimal subtract = csCod.subtract(yyForecastTwo); tXinyiForecastComparison.setYyErrorRateTwo((subtract).divide(csCod, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.SS.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(csSs); if(!Objects.isNull(csSs) && csSs.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)){ BigDecimal subtract = csSs.subtract(hsForecastTwo); tXinyiForecastComparison.setHsErrorRateTwo((subtract).divide(csSs, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastTwo)){ BigDecimal subtract = csSs.subtract(yyForecastTwo); tXinyiForecastComparison.setYyErrorRateTwo((subtract).divide(csSs, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } /*if(TN.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(csTn); if(!Objects.isNull(csTn) && csTn.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)) tXinyiForecastComparison.setHsErrorRateTwo((csTn.subtract(hsForecastTwo)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(yyForecastTwo)) tXinyiForecastComparison.setYyErrorRateTwo((csTn.subtract(yyForecastTwo)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } }*/ //2024年6月20日11:16:55 出水总磷的真实值从化验室获取 /*if(TP.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(csTp); if(!Objects.isNull(csTp) && csTp.compareTo(BigDecimal.ZERO) > 0){ tXinyiForecastComparison.setHsErrorRateTwo((csTp.subtract(hsForecastTwo)).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyErrorRateTwo((csTp.subtract(yyForecastTwo)).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } }*/ if(BusinessEnum.BigModelForecastEnum.NH3.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(csNh3); if(!Objects.isNull(csNh3) && csNh3.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)){ BigDecimal subtract = csNh3.subtract(hsForecastTwo); tXinyiForecastComparison.setHsErrorRateTwo((subtract).divide(csNh3, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastTwo)){ BigDecimal subtract = csNh3.subtract(yyForecastTwo); tXinyiForecastComparison.setYyErrorRateTwo((subtract).divide(csNh3, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } this.xinyiForecastComparisonMapper.updateTXinyiForecastComparison(tXinyiForecastComparison); } } //时间段3 List tXinyiForecastComparisons3 = this.xinyiForecastComparisonMapper.selectTXinyiForecastComparisonList(TXinyiForecastComparison.builder().forecastTimeThree(testHour).build()); if(!CollectionUtils.isEmpty(tXinyiForecastComparisons3)){ for (TXinyiForecastComparison tXinyiForecastComparison : tXinyiForecastComparisons3) { BigDecimal hsForecastThree = tXinyiForecastComparison.getHsForecastThree(); BigDecimal yyForecastThree = tXinyiForecastComparison.getYyForecastThree(); if(BusinessEnum.BigModelForecastEnum.COD.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(csCod); if(!Objects.isNull(csCod) && csCod.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)){ BigDecimal subtract = csCod.subtract(hsForecastThree); tXinyiForecastComparison.setHsErrorRateThree((subtract).divide(csCod, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastThree)){ BigDecimal subtract = csCod.subtract(yyForecastThree); tXinyiForecastComparison.setYyErrorRateThree((subtract).divide(csCod, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.SS.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(csSs); if(!Objects.isNull(csSs) && csSs.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)){ BigDecimal subtract = csSs.subtract(hsForecastThree); tXinyiForecastComparison.setHsErrorRateThree((subtract).divide(csSs, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastThree)){ BigDecimal subtract = csSs.subtract(yyForecastThree); tXinyiForecastComparison.setYyErrorRateThree((subtract).divide(csSs, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } /*if(TN.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(csTn); if(!Objects.isNull(csTn) && csTn.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)) tXinyiForecastComparison.setHsErrorRateThree((csTn.subtract(hsForecastThree)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(yyForecastThree)) tXinyiForecastComparison.setYyErrorRateThree((csTn.subtract(yyForecastThree)).divide(csTn, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } }*/ //2024年6月20日11:16:55 出水总磷的真实值从化验室获取 /*if(TP.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(csTp); if(!Objects.isNull(csTp) && csTp.compareTo(BigDecimal.ZERO) > 0){ tXinyiForecastComparison.setHsErrorRateThree((csTp.subtract(hsForecastThree)).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyErrorRateThree((csTp.subtract(yyForecastThree)).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } }*/ if(BusinessEnum.BigModelForecastEnum.NH3.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(csNh3); if(!Objects.isNull(csNh3) && csNh3.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)){ BigDecimal subtract = csNh3.subtract(hsForecastThree); tXinyiForecastComparison.setHsErrorRateThree((subtract).divide(csNh3, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastThree)){ BigDecimal subtract = csNh3.subtract(yyForecastThree); tXinyiForecastComparison.setYyErrorRateThree((subtract).divide(csNh3, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } this.xinyiForecastComparisonMapper.updateTXinyiForecastComparison(tXinyiForecastComparison); } } } /** * 额外计算一下预测的准确度 * @param tXinyiRobot */ public void updateForecastComparisonByRobot(TXinyiRobot tXinyiRobot) { BigDecimal no3Hlj1Jqr = tXinyiRobot.getNo3Hlj1Jqr(); BigDecimal no3Hlj2Jqr = tXinyiRobot.getNo3Hlj2Jqr(); String testHour = tXinyiRobot.getTestHour(); BigDecimal tpRccJqr = tXinyiRobot.getTpRccJqr(); BigDecimal csTp = null; // BigDecimal csTn = null; if(!Objects.isNull(tpRccJqr)){ csTp = tpRccJqr.divide(ROBOT_HY_DIVIDE, NUMBER_SCALE_4, RoundingMode.HALF_UP); //2024年6月20日13:44:26 先不计算,结果会更准确 //2024年6月21日14:23:14 就是要 除以0.8 // csTp = tpRccJqr; } //2024年7月12日16:29:00 需要单独计算了 csTn不再合并,分别从两个池子获取。。。 // if(!Objects.isNull(no3Hlj1Jqr) && !Objects.isNull(no3Hlj2Jqr)) // csTn = (no3Hlj1Jqr.add(no3Hlj2Jqr)).divide(DECIMAL_2, NUMBER_SCALE_4, RoundingMode.HALF_UP).divide(ROBOT_HY_DIVIDE, NUMBER_SCALE_4, RoundingMode.HALF_UP); //时间段1 List tXinyiForecastComparisons1 = this.xinyiForecastComparisonMapper.selectTXinyiForecastComparisonList(TXinyiForecastComparison.builder().forecastTimeOne(testHour).build()); if(!CollectionUtils.isEmpty(tXinyiForecastComparisons1)){ for (TXinyiForecastComparison tXinyiForecastComparison : tXinyiForecastComparisons1) { BigDecimal hsForecastOne = tXinyiForecastComparison.getHsForecastOne(); BigDecimal yyForecastOne = tXinyiForecastComparison.getYyForecastOne(); /*if(XSY1.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(no3Hlj1Jqr); if(!Objects.isNull(no3Hlj1Jqr) && no3Hlj1Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)) tXinyiForecastComparison.setHsErrorRateOne((no3Hlj1Jqr.subtract(hsForecastOne)).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(yyForecastOne)) tXinyiForecastComparison.setYyErrorRateOne((no3Hlj1Jqr.subtract(yyForecastOne)).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } } if(XSY2.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(no3Hlj2Jqr); if(!Objects.isNull(no3Hlj2Jqr) && no3Hlj2Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)) tXinyiForecastComparison.setHsErrorRateOne((no3Hlj2Jqr.subtract(hsForecastOne)).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(yyForecastOne)) tXinyiForecastComparison.setYyErrorRateOne((no3Hlj2Jqr.subtract(yyForecastOne)).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } }*/ //2024年6月21日17:04:01 总氮的真实值也从化验室获取 //2024年7月12日10:31:29 tn又改成xsy1和xsy2了。。。 if(BusinessEnum.BigModelForecastEnum.TN.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory()) || BusinessEnum.BigModelForecastEnum.XSY1.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(no3Hlj1Jqr); if(!Objects.isNull(no3Hlj1Jqr) && no3Hlj1Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)){ BigDecimal subtract = no3Hlj1Jqr.subtract(hsForecastOne); tXinyiForecastComparison.setHsErrorRateOne((subtract).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastOne)){ BigDecimal subtract = no3Hlj1Jqr.subtract(yyForecastOne); tXinyiForecastComparison.setYyErrorRateOne((subtract).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.TN.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory()) || BusinessEnum.BigModelForecastEnum.XSY2.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(no3Hlj2Jqr); if(!Objects.isNull(no3Hlj2Jqr) && no3Hlj2Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)){ BigDecimal subtract = no3Hlj2Jqr.subtract(hsForecastOne); tXinyiForecastComparison.setHsErrorRateOne((subtract).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastOne)){ BigDecimal subtract = no3Hlj2Jqr.subtract(yyForecastOne); tXinyiForecastComparison.setYyErrorRateOne((subtract).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } //2024年6月20日11:14:42 总磷的真实值也从化验室获取 //2024年7月11日17:08:51 tp改名字了。。。 if(BusinessEnum.BigModelForecastEnum.TP.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory()) || BusinessEnum.BigModelForecastEnum.ZLSY.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(csTp); if(!Objects.isNull(csTp) && csTp.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)){ BigDecimal subtract = csTp.subtract(hsForecastOne); tXinyiForecastComparison.setHsErrorRateOne((subtract).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastOne)){ BigDecimal subtract = csTp.subtract(yyForecastOne); tXinyiForecastComparison.setYyErrorRateOne((subtract).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } this.xinyiForecastComparisonMapper.updateTXinyiForecastComparison(tXinyiForecastComparison); } } //时间段2 List tXinyiForecastComparisons2 = this.xinyiForecastComparisonMapper.selectTXinyiForecastComparisonList(TXinyiForecastComparison.builder().forecastTimeTwo(testHour).build()); if(!CollectionUtils.isEmpty(tXinyiForecastComparisons2)){ for (TXinyiForecastComparison tXinyiForecastComparison : tXinyiForecastComparisons2) { BigDecimal hsForecastTwo = tXinyiForecastComparison.getHsForecastTwo(); BigDecimal yyForecastTwo = tXinyiForecastComparison.getYyForecastTwo(); /*if(XSY1.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(no3Hlj1Jqr); if(!Objects.isNull(no3Hlj1Jqr) && no3Hlj1Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)) tXinyiForecastComparison.setHsErrorRateTwo((no3Hlj1Jqr.subtract(hsForecastTwo)).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(yyForecastTwo)) tXinyiForecastComparison.setYyErrorRateTwo((no3Hlj1Jqr.subtract(yyForecastTwo)).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } } if(XSY2.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(no3Hlj2Jqr); if(!Objects.isNull(no3Hlj2Jqr) && no3Hlj2Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)) tXinyiForecastComparison.setHsErrorRateTwo((no3Hlj2Jqr.subtract(hsForecastTwo)).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(yyForecastTwo)) tXinyiForecastComparison.setYyErrorRateTwo((no3Hlj2Jqr.subtract(yyForecastTwo)).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } }*/ //2024年6月21日17:04:01 总氮的真实值也从化验室获取 //2024年7月12日10:31:29 tn又改成xsy1和xsy2了。。。 if(BusinessEnum.BigModelForecastEnum.TN.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory()) || BusinessEnum.BigModelForecastEnum.XSY1.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(no3Hlj1Jqr); if(!Objects.isNull(no3Hlj1Jqr) && no3Hlj1Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)){ BigDecimal subtract = no3Hlj1Jqr.subtract(hsForecastTwo); tXinyiForecastComparison.setHsErrorRateTwo((subtract).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastTwo)){ BigDecimal subtract = no3Hlj1Jqr.subtract(yyForecastTwo); tXinyiForecastComparison.setYyErrorRateTwo((subtract).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.TN.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory()) || BusinessEnum.BigModelForecastEnum.XSY2.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(no3Hlj2Jqr); if(!Objects.isNull(no3Hlj2Jqr) && no3Hlj2Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)){ BigDecimal subtract = no3Hlj2Jqr.subtract(hsForecastTwo); tXinyiForecastComparison.setHsErrorRateTwo((subtract).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastTwo)){ BigDecimal subtract = no3Hlj2Jqr.subtract(yyForecastTwo); tXinyiForecastComparison.setYyErrorRateTwo((subtract).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } //2024年6月20日11:14:42 总磷的真实值也从化验室获取 //2024年7月11日17:08:51 tp改名字了。。。 if(BusinessEnum.BigModelForecastEnum.TP.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory()) || BusinessEnum.BigModelForecastEnum.ZLSY.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(csTp); if(!Objects.isNull(csTp) && csTp.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)){ BigDecimal subtract = csTp.subtract(hsForecastTwo); tXinyiForecastComparison.setHsErrorRateTwo((subtract).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastTwo)){ BigDecimal subtract = csTp.subtract(yyForecastTwo); tXinyiForecastComparison.setYyErrorRateTwo((subtract).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } this.xinyiForecastComparisonMapper.updateTXinyiForecastComparison(tXinyiForecastComparison); } } //时间段3 List tXinyiForecastComparisons3 = this.xinyiForecastComparisonMapper.selectTXinyiForecastComparisonList(TXinyiForecastComparison.builder().forecastTimeThree(testHour).build()); if(!CollectionUtils.isEmpty(tXinyiForecastComparisons3)){ for (TXinyiForecastComparison tXinyiForecastComparison : tXinyiForecastComparisons3) { BigDecimal hsForecastThree = tXinyiForecastComparison.getHsForecastThree(); BigDecimal yyForecastThree = tXinyiForecastComparison.getYyForecastThree(); /*if(XSY1.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(no3Hlj1Jqr); if(!Objects.isNull(no3Hlj1Jqr) && no3Hlj1Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)) tXinyiForecastComparison.setHsErrorRateThree((no3Hlj1Jqr.subtract(hsForecastThree)).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(yyForecastThree)) tXinyiForecastComparison.setYyErrorRateThree((no3Hlj1Jqr.subtract(yyForecastThree)).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } } if(XSY2.equals(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(no3Hlj2Jqr); if(!Objects.isNull(no3Hlj2Jqr) && no3Hlj2Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)) tXinyiForecastComparison.setHsErrorRateThree((no3Hlj2Jqr.subtract(hsForecastThree)).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(yyForecastThree)) tXinyiForecastComparison.setYyErrorRateThree((no3Hlj2Jqr.subtract(yyForecastThree)).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); } }*/ //2024年6月21日17:04:01 总氮的真实值也从化验室获取 //2024年7月12日10:31:29 tn又改成xsy1和xsy2了。。。 if(BusinessEnum.BigModelForecastEnum.TN.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory()) || BusinessEnum.BigModelForecastEnum.XSY1.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(no3Hlj1Jqr); if(!Objects.isNull(no3Hlj1Jqr) && no3Hlj1Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)){ BigDecimal subtract = no3Hlj1Jqr.subtract(hsForecastThree); tXinyiForecastComparison.setHsErrorRateThree((subtract).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastThree)){ BigDecimal subtract = no3Hlj1Jqr.subtract(yyForecastThree); tXinyiForecastComparison.setYyErrorRateThree((subtract).divide(no3Hlj1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.TN.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory()) || BusinessEnum.BigModelForecastEnum.XSY2.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(no3Hlj2Jqr); if(!Objects.isNull(no3Hlj2Jqr) && no3Hlj2Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)){ BigDecimal subtract = no3Hlj2Jqr.subtract(hsForecastThree); tXinyiForecastComparison.setHsErrorRateThree((subtract).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastThree)){ BigDecimal subtract = no3Hlj2Jqr.subtract(yyForecastThree); tXinyiForecastComparison.setYyErrorRateThree((subtract).divide(no3Hlj2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } //2024年6月20日11:14:42 总磷的真实值也从化验室获取 //2024年7月11日17:08:51 tp改名字了。。。 if(BusinessEnum.BigModelForecastEnum.TP.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory()) || BusinessEnum.BigModelForecastEnum.ZLSY.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(csTp); if(!Objects.isNull(csTp) && csTp.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)){ BigDecimal subtract = csTp.subtract(hsForecastThree); tXinyiForecastComparison.setHsErrorRateThree((subtract).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastThree)){ BigDecimal subtract = csTp.subtract(yyForecastThree); tXinyiForecastComparison.setYyErrorRateThree((subtract).divide(csTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } this.xinyiForecastComparisonMapper.updateTXinyiForecastComparison(tXinyiForecastComparison); } } } private TXinyiCalculate addCalculateByIndustry(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) { //获取的一些配置信息 BigDecimal nhlbqdsl = normConfig.getNHLBQDSL(); BigDecimal nhlbdsjll = normConfig.getNHLBDSJLL(); BigDecimal nhlbgzxl = normConfig.getNHLBGZXL(); BigDecimal whlbqdsl = normConfig.getWHLBQDSL(); BigDecimal whlbdsjll = normConfig.getWHLBDSJLL(); BigDecimal whlbgzxl = normConfig.getWHLBGZXL(); BigDecimal gfjgzts = normConfig.getGFJGZTS(); BigDecimal gfjckll = normConfig.getGFJCKLL(); BigDecimal fcxbsjll = normConfig.getFCXBSJLL(); BigDecimal fclbsl = normConfig.getFCLBSL(); BigDecimal fcxbgzxl = normConfig.getFCXBGZXL(); //结算结果 TXinyiCalculate tXinyiCalculate = new TXinyiCalculate(); //时间相关 tXinyiCalculate.setTestDate(tXinyiIndustry.getTestDate()); tXinyiCalculate.setTestHour(tXinyiIndustry.getTestHour()); tXinyiCalculate.setTestTime(tXinyiIndustry.getTestTime()); //获取最新的一条日报信息 TXinyiDaily tXinyiDaily = this.xinyiDailyMapper.selectNewestData(); if(Objects.isNull(tXinyiDaily)){ //理论不会出现 log.error("没有日报数据"); return null; } BigDecimal jsBod5 = tXinyiDaily.getJsBod5(); BigDecimal csBod5 = tXinyiDaily.getCsBod5(); BigDecimal whlR = tXinyiDaily.getWhlR(); BigDecimal oneMlvss = tXinyiDaily.getShcHyOneMlvss(); BigDecimal twoMlvss = tXinyiDaily.getShcHyTwoMlvss(); BigDecimal avgMlvss = null; if(!Objects.isNull(oneMlvss) && !Objects.isNull(twoMlvss)) avgMlvss = ((oneMlvss.add(twoMlvss)).divide(new BigDecimal(2),4, RoundingMode.HALF_UP)); BigDecimal oneMlss = tXinyiDaily.getShcHyOneMlss(); BigDecimal twoMlss = tXinyiDaily.getShcHyTwoMlss(); BigDecimal avgMlss = null; if(!Objects.isNull(oneMlss) && !Objects.isNull(twoMlss)) avgMlss = ((oneMlss.add(twoMlss)).divide(new BigDecimal(NUMBER_2),NUMBER_SCALE_4, RoundingMode.HALF_UP)); //工业库的指标 BigDecimal jsTn = tXinyiIndustry.getJsTn(); BigDecimal jsTp = tXinyiIndustry.getJsTp(); BigDecimal jsCod = tXinyiIndustry.getJsCod(); BigDecimal jsSlq = tXinyiIndustry.getJsSlq(); //计算 if(!Objects.isNull(jsBod5)){ if(!Objects.isNull(jsTn) && jsTn.compareTo(BigDecimal.ZERO) > 0) tXinyiCalculate.setJsTdb(jsBod5.divide(jsTn, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(jsTp) && jsTp.compareTo(BigDecimal.ZERO) > 0) tXinyiCalculate.setJsTlb(jsBod5.divide(jsTp, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(jsCod) && jsCod.compareTo(BigDecimal.ZERO) > 0) tXinyiCalculate.setJsBodBCod(jsBod5.divide(jsCod, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(csBod5) && !Objects.isNull(avgMlss) && avgMlss.compareTo(BigDecimal.ZERO) > 0 && !Objects.isNull(jsSlq) && jsSlq.compareTo(BigDecimal.ZERO) > 0) tXinyiCalculate.setFM(new BigDecimal(ONE_DAY_HOURS).multiply((jsBod5.subtract(csBod5))).multiply(jsSlq).divide(avgMlss, NUMBER_SCALE_4, RoundingMode.HALF_UP).divide(new BigDecimal(F_M_LAST), NUMBER_SCALE_4, RoundingMode.HALF_UP)); } if(!Objects.isNull(avgMlss) && avgMlss.compareTo(BigDecimal.ZERO) > 0 && !Objects.isNull(avgMlvss) && avgMlvss.compareTo(BigDecimal.ZERO) > 0) tXinyiCalculate.setHFXWNNDZB(avgMlvss.divide(avgMlss, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(jsSlq) && jsSlq.compareTo(BigDecimal.ZERO) > 0){ tXinyiCalculate.setYyqHrt(new BigDecimal(YYQ_TLSJ_FIRST).divide(jsSlq, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setQyqHrt(new BigDecimal(QYQ_TLSJ_FIRST).divide(jsSlq, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setHyqHrt(new BigDecimal(HYQ_TLSJ_FIRST).divide(jsSlq, NUMBER_SCALE_4, RoundingMode.HALF_UP)); // tXinyiCalculate.setGSLS(jsSlq.divide(new BigDecimal(NUMBER_3600), NUMBER_SCALE_4, RoundingMode.HALF_UP).multiply(new BigDecimal(NUMBER_4)).divide((new BigDecimal(Math.PI).multiply(new BigDecimal(NUMBER_0_0_0_3)).multiply(new BigDecimal(NUMBER_0_0_0_3)).multiply(new BigDecimal(NUMBER_4)).multiply(new BigDecimal(NUMBER_4)).multiply(new BigDecimal(NUMBER_97119))) , NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setGSLS(jsSlq.divide(GSLS_LAST, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setGslsOne(jsSlq.divide(new BigDecimal(NUMBER_3600), NUMBER_SCALE_4, RoundingMode.HALF_UP).multiply(new BigDecimal(Math.sqrt(Math.sin(Math.toRadians(DOUBLE_75))))).divide(GSLSONE_LAST, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setGslsTwo(jsSlq.divide(new BigDecimal(NUMBER_3600), NUMBER_SCALE_4, RoundingMode.HALF_UP).multiply(new BigDecimal(Math.sqrt(Math.sin(Math.toRadians(DOUBLE_75))))).divide(GSLSTWO_LAST, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setXgsGsls(jsSlq.divide(new BigDecimal(NUMBER_3600), NUMBER_SCALE_4, RoundingMode.HALF_UP).multiply(new BigDecimal(NUMBER_4)).divide((GSLS_XGS_LAST) , NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setXlcscBmfh(jsSlq.divide(XLCSCBMFH_LAST, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setXlcscHrt(XLCSCHRT_LAST.divide(jsSlq, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setCccdcBmfh(jsSlq.divide(CCCDCBMFH_LAST, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setCccdcHrt(CCCDCHRT_LAST.divide(jsSlq, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setEccBmfh(jsSlq.divide(ECCBMFH_LAST, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setEccHrt(ECCHRT_LAST.divide(jsSlq, NUMBER_SCALE_4, RoundingMode.HALF_UP)); //2024年7月1日17:16:16 计算逻辑调整 tXinyiCalculate.setEccGtfh((new BigDecimal(1).add(whlR.divide(BigDecimal_100, NUMBER_SCALE_4, RoundingMode.HALF_UP))).multiply(jsSlq).multiply(new BigDecimal(NUMBER_24)).multiply(avgMlss).divide(ECCGTFH_LAST, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setClsnJcsj(CLSNJCSJ_LAST.divide(jsSlq, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiCalculate.setXgcdcQsqSsls(jsSlq.multiply(XGCDCQSQSSLS_LAST)); //2024年6月29日15:18:01 增加几个新的计算指标 if(!Objects.isNull(nhlbqdsl) && !Objects.isNull(nhlbdsjll) && !Objects.isNull(nhlbgzxl)) tXinyiCalculate.setNHLB(nhlbqdsl.multiply(nhlbdsjll).multiply(nhlbgzxl).multiply(BigDecimal_100).divide(jsSlq, 4, RoundingMode.HALF_UP)); if(!Objects.isNull(whlbqdsl) && !Objects.isNull(whlbdsjll) && !Objects.isNull(whlbgzxl)) tXinyiCalculate.setWHLB(whlbqdsl.multiply(whlbdsjll).multiply(whlbgzxl).multiply(BigDecimal_100).divide(jsSlq, 4, RoundingMode.HALF_UP)); if(!Objects.isNull(gfjgzts) && !Objects.isNull(gfjckll)) tXinyiCalculate.setQSB(gfjgzts.multiply(gfjckll).divide(jsSlq, NUMBER_SCALE_4, RoundingMode.HALF_UP)); if(!Objects.isNull(fcxbsjll) && !Objects.isNull(fclbsl) && !Objects.isNull(fcxbgzxl)){ BigDecimal fcxsl = fcxbsjll.multiply(fclbsl).multiply(fcxbgzxl); tXinyiCalculate.setFCXSL(fcxsl); //2024年7月3日10:54:28 额外再增加一个字段 tXinyiCalculate.setFCXSLBL(fcxsl.divide(jsSlq, NUMBER_SCALE_4, RoundingMode.HALF_UP).multiply(BigDecimal_100)); } //2024年7月11日15:43:47 之前给的外回流比计算不准确,额外一个字段记录新的外回流比 BigDecimal divide = jsSlq.divide(DECIMAL_2, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide.compareTo(DECIMAL_1500) < 0) tXinyiCalculate.setWhlRN(DECIMAL_1200.divide(divide, NUMBER_SCALE_4, RoundingMode.HALF_UP).multiply(BigDecimal_100)); else tXinyiCalculate.setWhlRN(DECIMAL_1620.divide(divide, NUMBER_SCALE_4, RoundingMode.HALF_UP).multiply(BigDecimal_100)); } return tXinyiCalculate; } public void handleSHWarning(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, TXinyiCalculate xinyiCalculate) { //判断对应指标是否报警 然后调研大模型获取决策信息 // BigDecimal jsSlq = tXinyiIndustry.getJsSlq(); //内回流比报警 // BigDecimal nhlbSjz = normConfig.getNhlbSjz();//400 // BigDecimal nhlbnkSxz = normConfig.getNhlbnkSxz();//360 BigDecimal nhlbnkXxz = normConfig.getNhlbnkXxz();//270 // BigDecimal nhlbqdsl = normConfig.getNHLBQDSL(); // BigDecimal nhlbdsjll = normConfig.getNHLBDSJLL(); // BigDecimal nhlbgzxl = normConfig.getNHLBGZXL(); /*BigDecimal nhlb = xinyiCalculate.getNHLB(); if(!Objects.isNull(nhlb) && !Objects.isNull(nhlbnkXxz)){ // BigDecimal divide = nhlbqdsl.multiply(nhlbdsjll).multiply(nhlbgzxl).divide(jsSlq, 4, RoundingMode.HALF_UP); handleXinYiWarningsSH(nhlbnkXxz, nhlb, BusinessEnum.WarningCategoryEnum.NHLB.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.PERCENT.getCode()); }*/ //外回流比报警 // BigDecimal whlbqdsl = normConfig.getWHLBQDSL(); // BigDecimal whlbdsjll = normConfig.getWHLBDSJLL(); // BigDecimal whlbgzxl = normConfig.getWHLBGZXL(); BigDecimal whlbnkXxz = normConfig.getWhlbnkXxz();//75 // BigDecimal whlbSjz = normConfig.getWhlbSjz(); // BigDecimal whlb = xinyiCalculate.getWHLB(); //2024年7月11日15:54:19 外回流比采用新的计算方式获取的值 BigDecimal whlb = xinyiCalculate.getWhlRN(); if(!Objects.isNull(whlb) && !Objects.isNull(whlbnkXxz)){ handleXinYiWarningsSH(whlbnkXxz, whlb, BusinessEnum.WarningCategoryEnum.WHLB.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.PERCENT.getCode()); } //最新的一条日报数据 /*List tXinyiDailies = this.xinyiDailyMapper.selectTXinyiDailyList(null); if(CollectionUtils.isEmpty(tXinyiDailies)) return;//肯定不会出现这种情况 因为有很多历史数据了 TXinyiDaily tXinyiDaily = tXinyiDailies.get(0);*/ TXinyiDaily tXinyiDaily = this.xinyiDailyMapper.selectNewestData(); if(Objects.isNull(tXinyiDaily)) return;//肯定不会出现这种情况 因为有很多历史数据了 新水厂可能会有这个问题 // log.info("生化报警获取日报的最新的一条数据为{}", JSON.toJSONString(tXinyiDaily)); //污泥浓度报警 BigDecimal sjscgkz = null; //判断是否是夏季 if(LocalDateTimeUtil.isSummer()) sjscgkz = normConfig.getXjwnndXxz(); else sjscgkz = normConfig.getDjwnndXxz(); //#1 BigDecimal oneMlss = tXinyiIndustry.getOneMlss(); if(!Objects.isNull(oneMlss) && !Objects.isNull(sjscgkz)){ handleXinYiWarningsSH(sjscgkz, oneMlss, BusinessEnum.WarningCategoryEnum.WNND_MLSS_1.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.MG_L.getCode()); } //#1 BigDecimal twoMlss = tXinyiIndustry.getTwoMlss(); if(!Objects.isNull(twoMlss) && !Objects.isNull(sjscgkz)){ handleXinYiWarningsSH(sjscgkz, twoMlss, BusinessEnum.WarningCategoryEnum.WNND_MLSS_2.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.MG_L.getCode()); } //污泥负荷(需要从日报获取数据) 计算 + 部分数据从日报获取 //污泥负荷=[Ls]=24*([BOD_in]-[BOD_off])*[Q_in]/[MLSS]/([V_hao]+[V_que]+[V_yan])/2 kgBOD/(kgMLSS·d) //2024年6月27日17:18:33 直接从计算结果拿到 BigDecimal fm = xinyiCalculate.getFM(); //2024年6月28日17:17:03 已经配置了新的 BigDecimal wnfhnkXxz = normConfig.getWnfhnkXxz(); if(!Objects.isNull(fm) && !Objects.isNull(wnfhnkXxz)){ handleXinYiWarningsSH(wnfhnkXxz, fm, BusinessEnum.WarningCategoryEnum.WNFH.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.KGBOD_KGMLSS_D.getCode()); } //万吨水产泥率(todo 没有计算规则,只能从日报获取) //挥发性污泥浓度占比(MLVSS/MLSS) //特殊:小于 BigDecimal hfxwnndzb = xinyiCalculate.getHFXWNNDZB(); BigDecimal hfxwnndzbSjz = normConfig.getHfxwnndzbSjz(); if(!Objects.isNull(hfxwnndzb) && !Objects.isNull(hfxwnndzbSjz)){ handleXinYiWarningsSH(hfxwnndzbSjz, hfxwnndzb, BusinessEnum.WarningCategoryEnum.HFXWNNDZB.getCode(), tXinyiIndustry, normConfig, false, BusinessEnum.BigModelUnitEnum.NULL.getCode()); } //进水碳氮比 BigDecimal jsTdb = xinyiCalculate.getJsTdb(); BigDecimal jstdbnkzXxz = normConfig.getJstdbnkzXxz(); if(!Objects.isNull(jsTdb) && !Objects.isNull(jstdbnkzXxz)){ handleXinYiWarningsSH(jstdbnkzXxz, jsTdb, BusinessEnum.WarningCategoryEnum.TDB.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.NULL.getCode()); } //进水碳磷比 BigDecimal jsTlb = xinyiCalculate.getJsTlb(); BigDecimal jstlbNkz = normConfig.getJstlbNkz(); if(!Objects.isNull(jsTlb) && !Objects.isNull(jstlbNkz)){ handleXinYiWarningsSH(jstlbNkz, jsTlb, BusinessEnum.WarningCategoryEnum.TLB.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.NULL.getCode()); } //进水BOD与COD比值(生化性) BigDecimal jsBodBCod = xinyiCalculate.getJsBodBCod(); String jsbodycodbzGkz = normConfig.getJsbodycodbzGkz(); if(!StringUtils.isBlank(jsbodycodbzGkz) && jsbodycodbzGkz.contains("-")){ String[] split = jsbodycodbzGkz.split("-"); sjscgkz = new BigDecimal(split[0]); if(!Objects.isNull(jsBodBCod)){ handleXinYiWarningsSH(sjscgkz, jsBodBCod, BusinessEnum.WarningCategoryEnum.BODCODB.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.NULL.getCode()); } } //好氧区DO(一池) 2024年5月31日14:04:37 加数据,让他一直报警 BigDecimal shcHyOneDo = tXinyiIndustry.getOneHymdDo(); // BigDecimal shcHyOneDo = new BigDecimal("5"); // BigDecimal hycrjysjzSxz = normConfig.getHycrjysjzSxz(); BigDecimal hycrjyNkz = normConfig.getHycrjyNkz(); if(!Objects.isNull(shcHyOneDo) && !Objects.isNull(hycrjyNkz)){ handleXinYiWarningsSH(hycrjyNkz, shcHyOneDo, BusinessEnum.WarningCategoryEnum.HYQDO_ONE.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.MG_L.getCode()); } //好氧区DO(二池) 2024年5月31日14:09:36 溶解氧从日报获取 工业的不准 //2024年6月27日17:00:31 都先从工业库获取,日报没有必要再报警了 BigDecimal shcHyTwoDo = tXinyiIndustry.getTwoHymdDo(); if(!Objects.isNull(shcHyTwoDo) && !Objects.isNull(hycrjyNkz)){ handleXinYiWarningsSH(hycrjyNkz, shcHyTwoDo, BusinessEnum.WarningCategoryEnum.HYQDO_TWO.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.MG_L.getCode()); } //气水比 BigDecimal qsb = xinyiCalculate.getQSB(); BigDecimal shcqbNkz = normConfig.getShcqbNkz(); if(!Objects.isNull(qsb) && !Objects.isNull(shcqbNkz)) handleXinYiWarningsSH(shcqbNkz, qsb, BusinessEnum.WarningCategoryEnum.QSB.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.M3_M3.getCode()); //二沉池表面负荷 BigDecimal eccBmfh = xinyiCalculate.getEccBmfh(); BigDecimal eccbmfhznkzXxz = normConfig.getEccbmfhznkzXxz(); if(!Objects.isNull(eccBmfh) && !Objects.isNull(eccbmfhznkzXxz)){ handleXinYiWarningsSH(eccbmfhznkzXxz, eccBmfh, BusinessEnum.WarningCategoryEnum.ECC_BMFH.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.M3_M2_H.getCode()); } //二沉池固体负荷 BigDecimal eccGtfh = xinyiCalculate.getEccGtfh(); BigDecimal eccgtfhnkxxz = normConfig.getECCGTFHNKXXZ(); if(!Objects.isNull(eccGtfh) && !Objects.isNull(eccgtfhnkxxz)){ handleXinYiWarningsSH(eccgtfhnkxxz, eccGtfh, BusinessEnum.WarningCategoryEnum.ECC_GTFH.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.KG_M2_D.getCode()); } //反冲洗水量 //2024年7月3日10:59:32 这里用反冲洗水量比例做计算 BigDecimal fcxslBl = xinyiCalculate.getFCXSLBL(); BigDecimal fcxslblsjzXxz = normConfig.getFcxslblsjzXxz(); if(!Objects.isNull(fcxslBl) && !Objects.isNull(fcxslblsjzXxz)) handleXinYiWarningsSH(fcxslblsjzXxz, fcxslBl, BusinessEnum.WarningCategoryEnum.FCXSL.getCode(), tXinyiIndustry, normConfig, true, BusinessEnum.BigModelUnitEnum.PERCENT.getCode()); } /** * 处理信义生化报警的逻辑 统一处理 * @param sjscgkz :实际生产管控值 * @param currentVal * @param category * @param tXinyiIndustry * @param normConfig * @param normal 是否常规判断:默认都是超过;只有这个挥发性污泥浓度占比(VSS/SS)是小于才报警 * 2024年6月27日15:39:15 调整:生化报警只取实际生产管控指标 * 2024年7月11日10:44:11 新增单位unit 拼接完单位以后返回 * */ private void handleXinYiWarningsSH(BigDecimal sjscgkz, BigDecimal currentVal, String category, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, Boolean normal, String unit) { TXinyiWarningRecord tXinyiWarningRecord = new TXinyiWarningRecord(); /*String category = BusinessEnum.WarningCategoryEnum.CS_AD.getCode();*/ tXinyiWarningRecord.setStatus(0); tXinyiWarningRecord.setType(1); tXinyiWarningRecord.setCategory(category); tXinyiWarningRecord.setTime(DateUtils.getNowDate()); tXinyiWarningRecord.setWarningVal(currentVal); tXinyiWarningRecord.setDesignVal(sjscgkz); tXinyiWarningRecord.setControlVal(sjscgkz); tXinyiWarningRecord.setCreateBy(WARNING_DEFAULT_CREATE); tXinyiWarningRecord.setCreateTime(DateUtils.getNowDate()); tXinyiWarningRecord.setRemark(ONE_SH_WARNING.getCode()); //2024年6月27日17:36:25 有一个判断是反正的 if(normal){ //2024年5月25日17:52:33 如果工业库获取不到数据,也触发报警,但是不调用决策接口 if (Objects.isNull(currentVal) || currentVal.compareTo(BigDecimal.ZERO) == 0) { tXinyiWarningRecord.setReason(category + EXCEPTION_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_NO_DATE); } else if (currentVal.compareTo(sjscgkz) > 0) {//一级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_ONE); } /*else if (currentVal.compareTo(bzz) >= 0 && currentVal.compareTo(multiply) <= 0) {//二级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_TWO); } else if (!Objects.isNull(gkz) && currentVal.compareTo(gkz) > 0) { tXinyiWarningRecord.setReason(category + CHAOGUANKONG_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_THREE); }*/ else { tXinyiWarningRecord = null;//这种的无需处理 } }else{ //2024年5月25日17:52:33 如果工业库获取不到数据,也触发报警,但是不调用决策接口 if (Objects.isNull(currentVal) || currentVal.compareTo(BigDecimal.ZERO) == 0) { tXinyiWarningRecord.setReason(category + EXCEPTION_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_NO_DATE); } else if (currentVal.compareTo(sjscgkz) < 0) {//一级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_ONE); } /*else if (currentVal.compareTo(bzz) >= 0 && currentVal.compareTo(multiply) <= 0) {//二级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_TWO); } else if (!Objects.isNull(gkz) && currentVal.compareTo(gkz) > 0) { tXinyiWarningRecord.setReason(category + CHAOGUANKONG_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_THREE); }*/ else { tXinyiWarningRecord = null;//这种的无需处理 } } //当前状态正常 需要查询历史有无正在报警的数据,如果有,将报警状态改完2(系统自动关闭) List tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(TXinyiWarningRecord.builder().delFlag(0).type(1).category(category).status(0).build()); if(Objects.isNull(tXinyiWarningRecord)){//数据正常,无告警信息 if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ log.info( "{}:现在恢复正常,历史报警数据为{}", category,JSON.toJSONString(tXinyiWarningRecords)); for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) { xinyiWarningRecord.setStatus(2); Date nowDate = DateUtils.getNowDate(); xinyiWarningRecord.setOffTime(nowDate); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); } } }else{//有新的告警信息 Date nowDate = DateUtils.getNowDate(); if(CollectionUtils.isEmpty(tXinyiWarningRecords)){//之前没有告警记录 //保存到数据库中 //2024年7月15日11:06:16 因为只有一个告警记录,但是如果一直报警,现在报警时间取的是更新时间,兼容第一次报警处理 tXinyiWarningRecord.setUpdateTime(nowDate); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord); if(WARNING_LEVEL_NO_DATE.equals(tXinyiWarningRecord.getLevel())){ //只保存一个普通的问答记录 不需要调用决策信息,但是实时数据还是要记录的 this.addChatRecordByDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig); }else { //继续调用决策(普通问答) this.askBigModelForSHWarning(tXinyiWarningRecord, tXinyiIndustry, normConfig, unit); } }else{ log.info("{}:之前已经有过告警记录了,且还是继续报警,无需重复添加报警,但是决策仍然要调用", category); for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) {//理论上只有一个的 if(WARNING_LEVEL_NO_DATE.equals(tXinyiWarningRecord.getLevel())){ //只保存一个普通的问答记录 不需要调用决策信息,但是实时数据还是要记录的 this.addChatRecordByDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig); }else { //2024年7月5日10:45:24 逻辑调整:更新一直报警的那条记录的显示值 xinyiWarningRecord.setWarningVal(tXinyiWarningRecord.getWarningVal()); // xinyiWarningRecord.setDesignVal(tXinyiWarningRecord.getDesignVal()); // tXinyiWarningRecord.setControlVal(tXinyiWarningRecord.getControlVal()); xinyiWarningRecord.setTime(tXinyiWarningRecord.getTime()); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); //2024年7月15日11:07:33 报警的级别也要重新计算并更新 xinyiWarningRecord.setLevel(tXinyiWarningRecord.getLevel()); //2024年7月31日09:20:47 报警的原因(超标还是超管控也需要更新) xinyiWarningRecord.setReason(tXinyiWarningRecord.getReason()); //更新数据库 this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); //继续调用决策(普通问答) this.askBigModelForSHWarning(xinyiWarningRecord, tXinyiIndustry, normConfig, unit); } } } } } public void handleSZWarning(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) { //出水相关 //出水COD报警 BigDecimal csCod = tXinyiIndustry.getCsCod(); BigDecimal cscodBzz = normConfig.getCscodBzz(); BigDecimal cscodGkz = normConfig.getCscodGkz(); if(!Objects.isNull(cscodBzz)){ handleXinYiWarningsCs(cscodBzz, csCod, cscodGkz, BusinessEnum.WarningCategoryEnum.CS_COD.getCode(), tXinyiIndustry, normConfig); } //出水总磷超标报警 BigDecimal csTp = tXinyiIndustry.getCsTp(); BigDecimal cszlBzz = normConfig.getCszlBzz(); BigDecimal cszlGkz = normConfig.getCszlGkz(); if(!Objects.isNull(cszlBzz)){ handleXinYiWarningsCs(cszlBzz, csTp, cszlGkz, BusinessEnum.WarningCategoryEnum.CS_ZL.getCode(), tXinyiIndustry, normConfig); } //出水总氮超标报警 BigDecimal csTn = tXinyiIndustry.getCsTn(); BigDecimal cszzBzz = normConfig.getCszzBzz(); BigDecimal cszzGkz = normConfig.getCszzGkz(); if(!Objects.isNull(cszzBzz)){ handleXinYiWarningsCs(cszzBzz, csTn, cszzGkz, BusinessEnum.WarningCategoryEnum.CS_ZD.getCode(), tXinyiIndustry, normConfig); } //出水氨氮超标报警 BigDecimal csNh3 = tXinyiIndustry.getCsNh3(); BigDecimal csadBzz = normConfig.getCsadBzz(); BigDecimal csadGkz = normConfig.getCsadGkz(); if(!Objects.isNull(csadBzz)){ handleXinYiWarningsCs(csadBzz, csNh3, csadGkz, BusinessEnum.WarningCategoryEnum.CS_AD.getCode(), tXinyiIndustry, normConfig); } //出水SS超标报警 BigDecimal csSS = tXinyiIndustry.getCsSs(); BigDecimal csSSBzz = normConfig.getCsssBzz(); BigDecimal csssGkz = normConfig.getCsssGkz(); if(!Objects.isNull(csSSBzz)){ handleXinYiWarningsCs(csSSBzz, csSS, csssGkz, BusinessEnum.WarningCategoryEnum.CS_SS.getCode(), tXinyiIndustry, normConfig); } //进水相关报警 //进水总磷超标报警 BigDecimal jsTp = tXinyiIndustry.getJsTp(); BigDecimal jszlSjz = normConfig.getJszlSjz(); if(!Objects.isNull(jszlSjz)){ handleXinYiWarningRecordJS(jszlSjz, jsTp, BusinessEnum.WarningCategoryEnum.JS_ZL.getCode(), tXinyiIndustry, normConfig); } //进水COD超标报警 BigDecimal jsCod = tXinyiIndustry.getJsCod(); BigDecimal jscodSjz = normConfig.getJscodSjz(); if(!Objects.isNull(jscodSjz)){ handleXinYiWarningRecordJS(jscodSjz, jsCod, BusinessEnum.WarningCategoryEnum.JS_COD.getCode(), tXinyiIndustry, normConfig); } //进水总氮超标报警 BigDecimal jsTn = tXinyiIndustry.getJsTn(); BigDecimal jszdSjz = normConfig.getJszdSjz(); if(!Objects.isNull(jszdSjz)){ handleXinYiWarningRecordJS(jszdSjz, jsTn, BusinessEnum.WarningCategoryEnum.JS_ZD.getCode(), tXinyiIndustry, normConfig); } //进水氨氮超标报警 BigDecimal jsNh3 = tXinyiIndustry.getJsNh3(); BigDecimal jsadSjz = normConfig.getJsadSjz(); if(!Objects.isNull(jsadSjz)){ handleXinYiWarningRecordJS(jsadSjz, jsNh3, BusinessEnum.WarningCategoryEnum.JS_AD.getCode(), tXinyiIndustry, normConfig); } //进水SS超标报警 BigDecimal jsSS = tXinyiIndustry.getJsSs(); BigDecimal jsSSSjz = normConfig.getJsssSjz(); if(!Objects.isNull(jsSSSjz)){ handleXinYiWarningRecordJS(jsSSSjz, jsSS, BusinessEnum.WarningCategoryEnum.JS_SS.getCode(), tXinyiIndustry, normConfig); } } private void askBigModelForSHWarning(TXinyiWarningRecord xinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, String unit) { log.info("进入了后台接口调⽤⼤模型获取问答结果处理"); StringBuilder sb = new StringBuilder(); String sessionId = IdUtils.simpleUUID(); ChatReq chatReq = new ChatReq(); // String ipAddr = IpUtils.getIpAddr();//获取用户的ip地址 传给大模型 String ipAddr = "";//获取用户的ip地址 传给大模型 定时任务获取不到ip地址 int counts = 1;//默认是第一次 //这种问答 没有历史问答的概念 直接把问题扔进去就行 无需查询历史记录 List historyDates = new ArrayList<>(); //构建问题(替换提示词中的占位符) /*String shWarningPrompt = SH_WARNING_PROMPT; shWarningPrompt =shWarningPrompt.replace("#{0}", xinyiWarningRecord.getReason()); shWarningPrompt =shWarningPrompt.replace("#{1}", String.valueOf(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getDesignVal(), INT_2))); shWarningPrompt =shWarningPrompt.replace("#{2}", String.valueOf(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getControlVal(), INT_2))); shWarningPrompt =shWarningPrompt.replace("#{3}", String.valueOf(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getWarningVal(), INT_2)));*/ //2024年7月5日10:08:54 拼接优化 StringBuilder prompt = new StringBuilder(SH_WARNING_PROMPT_1); prompt.append(xinyiWarningRecord.getReason()); prompt.append(SH_WARNING_PROMPT_2).append(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getDesignVal(), INT_2)); prompt.append(SH_WARNING_PROMPT_3).append(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getControlVal(), INT_2)); prompt.append(SH_WARNING_PROMPT_4).append(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getWarningVal(), INT_2)); prompt.append(SH_WARNING_PROMPT_5); historyDates.add(prompt.toString()); // 获取输出流 ManagedChannel channel = null; try { channel = ManagedChannelBuilder.forAddress(bigModelConfig.getIp(), bigModelConfig.getPort()) .usePlaintext() .build(); InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub stub = InferenceAPIsServiceGrpc.newBlockingStub(channel); // String dataJson = "{\"bot_id\":\"721\",\"exp_id\":\"721\",\"session_id\":\"" + sessionId + "\",\"use_rag\":\"true\",\"prompt\":\"你是⼀个资深⽔务领域专家,能回答各种⽔务相关问题\",\"history_dia\":" + JSON.toJSONString(historyDates) + ",\"generate_args\":{\"max_new_tokens\":2048,\"max_length\":4096,\"num_beams\":1,\"do_sample\":true,\"top_p\":0.7,\"temperature\":0.95},\"extra\":{ \"ip_address\": \"" + ipAddr + "\" },\"strengthen\":" + (true) + "}"; //2024年6月27日13:29:18 优化,不再使用拼接JSON字符串 String dataJson = buildBigModelReqForChat(sessionId, historyDates, ipAddr, false); // log.info("请求大模型的问答参数为{}", dataJson); PredictionsRequest request = PredictionsRequest.newBuilder() .setModelName("slibra_bot") .putInput("method", ByteString.copyFrom("infer_stream", "utf-8"))//推理 .putInput("data", ByteString.copyFrom(dataJson, "utf-8")) .buildPartial(); Iterator predictions = stub.streamPredictions(request); //将结果记录到问答表 while (predictions.hasNext()) { String responseStr = predictions.next().getPrediction().toStringUtf8(); // log.info("大模型问答返回的原始结果为{}", responseStr); responseStr = JSON.parseObject(responseStr).getString("message"); if("complete".equals(responseStr)){ log.info("结尾语句并且是非JSON,无需处理"); }else{ sb.append(responseStr); } } //将问答更新到数据库中 chatReq.setSessionId(sessionId); chatReq.setType(1);//0问答 1决策 2本地 3仿真预测 chatReq.setModule(3);//0专家问答 1智能工单 2智能体助手 3告警 4简报 String showVal = this.buildShowValueSH(xinyiWarningRecord, tXinyiIndustry, normConfig, DateUtils.getNowDate(), unit); chatReq.setShowVal(showVal); chatReq.setQuestion(prompt.toString()); chatReq.setAnswer(sb.toString()); chatReq.setWarningId(String.valueOf(xinyiWarningRecord.getId())); chatReq.setCounts(counts);//问答次数 chatReq.setUserId(WARNING_DEFAULT_CREATE); chatReq.setCreateBy(WARNING_DEFAULT_CREATE); chatReq.setCreateTime(DateUtils.getNowDate()); this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq); } catch (IOException e) { throw new RuntimeException(e); } finally { // 关闭输出流 channel.shutdown(); } } private String buildBigModelReqForChat(String sessionId, List historyDates, String ipAddr, Boolean strengthen) { ChatRequest chatRequest = new ChatRequest(); chatRequest.setSessionId(sessionId); chatRequest.setHistoryDia(historyDates); //2024年7月5日13:24:10 temperature做区分 GenerateArgs generateArgs = new GenerateArgs(); generateArgs.setTemperature(bigModelConfig.getTemperature()); chatRequest.setGenerateArgs(generateArgs); Map extra = new HashMap<>(); extra.put("ip_address", ipAddr); chatRequest.setExtra(extra); chatRequest.setStrengthen(strengthen); //2024年7月3日16:21:28 明确该场景不用调工具 chatRequest.setTools(String.valueOf(false)); return JSON.toJSONString(chatRequest); } /** * 调用大模型获取决策结果 并同时记录对应信息到聊天记录表中 * * @param tXinyiWarningRecord * @param tXinyiIndustry * @param normConfig * @param isSpecial 机器人化验库,需要把总磷和总氮的值特殊处理一下 * @param nowDate */ private void handleDecision(TXinyiWarningRecord tXinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, boolean isSpecial, Date nowDate) { log.info("进入了调⽤大模型决策接口"); ChatReq chatReq = new ChatReq(); // StringBuilder sb = new StringBuilder(); //大模型结果 放入一个结合中 List resultData = new ArrayList<>(); //决策和问答不一样 没有历史的概念 所以sessionId都是新的 次数都是1 String sessionId = IdUtils.simpleUUID(); // String feedback = chatReq.getFeedback(); //决策请求的业务参数 // List> list = this.xinyiIndustryMapper.selectLast10RecordsForDecision(); //2024年5月21日15:23:07 这里不能用关联查询处理,日报要获取最新的一条而不是今日的数据。 List decisionReqs = this.xinyiIndustryMapper.selectLast10RecordsForDecisionOnlyIndustry(); if(!CollectionUtils.isEmpty(decisionReqs)){ //处理日报数据 TXinyiDaily daily = this.xinyiDailyMapper.selectNewestData(); for (DecisionReq decisionReq : decisionReqs) { if(!Objects.isNull(daily)){ WaterFormat.getWaterDecimationData(decisionReq, daily); // decisionReq.setT(daily.getJsSw()); // decisionReq.setSVI(daily.getWntjzsAll()); // decisionReq.setSV(daily.getWncjbAll()); // decisionReq.setMlvss(daily.getHfxwnndAll()); // //2024年7月2日17:20:12 mlss和DO_O也要从日报获取 // decisionReq.setMlss(daily.getHycWnndAll()); // decisionReq.setDoO(daily.getHycRjyAll()); // decisionReq.setDoAna(daily.getYycRjyAll()); // decisionReq.setDoQue(daily.getQycRjyAll()); // //2024年5月26日11:59:02 干污泥量数据做了同步 // decisionReq.setGwnl(daily.getGWNL()); // BigDecimal jsBod5 = daily.getJsBod5(); // decisionReq.setBodIn(jsBod5); // BigDecimal tpIn = decisionReq.getTpIn(); // BigDecimal tnIn = decisionReq.getTnIn(); // if(!Objects.isNull(jsBod5)){ // if(!Objects.isNull(tpIn) && tpIn.compareTo(new BigDecimal("0")) >0){ // decisionReq.setC(jsBod5.divide(tpIn, 4, RoundingMode.HALF_UP)); // } // if(!Objects.isNull(tnIn) && tnIn.compareTo(new BigDecimal("0")) >0){ // decisionReq.setB(jsBod5.divide(tnIn, 4, RoundingMode.HALF_UP)); // } // } // //2024年6月1日08:37:09 内回流加上 // decisionReq.setR(daily.getNhlR()); // decisionReq.setRR(daily.getWhlR()); } //如果是机器人化验室的报警,需要把总磷和总氮,获取化验室对应的数据且计算 if(isSpecial){ List xinyiRobots = this.xinyiRobotMapper.selectTXinyiRobotList(TXinyiRobot.builder().testHour(tXinyiIndustry.getTestHour()).build()); if(CollectionUtils.isEmpty(xinyiRobots)){ log.error("{}获取化验室数据失败", tXinyiIndustry.getTestHour()); }else{ TXinyiRobot tXinyiRobot = xinyiRobots.get(0); //总氮 BigDecimal no3Hlj1Jqr = tXinyiRobot.getNo3Hlj1Jqr(); BigDecimal no3Hlj2Jqr = tXinyiRobot.getNo3Hlj2Jqr(); if(!Objects.isNull(no3Hlj1Jqr) && !Objects.isNull(no3Hlj2Jqr)){ decisionReq.setTnOff((no3Hlj1Jqr.add(no3Hlj2Jqr)).divide((new BigDecimal("2").multiply(ROBOT_HY_DIVIDE)), INT_0, RoundingMode.HALF_UP)); } //总磷 BigDecimal tpRccJqr = tXinyiRobot.getTpRccJqr(); if(!Objects.isNull(tpRccJqr)){ decisionReq.setTpOff(tpRccJqr.divide(ROBOT_HY_DIVIDE, INT_0, RoundingMode.HALF_UP)); } } } //todo 字符串的调用getAbsAndScaleStr() } } // String rows = JSON.toJSONString(decisionReqs, JSONWriter.Feature.WriteNulls); // 获取输出流 ManagedChannel channel = null; String dataJson = ""; try { channel = ManagedChannelBuilder.forAddress(bigModelConfig.getIp(), bigModelConfig.getPort()) .usePlaintext() .build(); InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub stub = InferenceAPIsServiceGrpc.newBlockingStub(channel); // dataJson = "{\"bot_id\":\"b00001\",\"exp_id\":\"721\",\"norm\":\"" + tXinyiWarningRecord.getCategory() + "\",\"feedback\":" + feedback + ",\"session_id\":" + "\"" + sessionId + "\"" + ",\"generate_args\":{\"max_new_tokens\":1024,\"max_length\":4096,\"num_beams\":1,\"do_sample\":true,\"top_p\":0.7,\"temperature\":0.95},\"extra\":{\"rows\":" + rows + "}}"; //2024年6月24日17:59:17 优化,不再拼接JSON字符串 PolicyReq policyReq = new PolicyReq(); //2024年7月11日17:57:53 因为化验室的改了 但是 调用决策还得用原来的几个值 String category = tXinyiWarningRecord.getCategory(); if(ROBOT_XSY_1.getCode().equalsIgnoreCase(category) || ROBOT_XSY_2.getCode().equalsIgnoreCase(category)){ category = CS_ZD.getCode(); } else if (ROBOT_ANDAN_1.getCode().equalsIgnoreCase(category) || ROBOT_ANDAN_2.getCode().equalsIgnoreCase(category)) { category = CS_AD.getCode(); }else if (ROBOT_ECCZLSY.getCode().equalsIgnoreCase(category)) { category = CS_ZL.getCode(); } policyReq.setNorm(category); HashMap hashMap = new HashMap<>(); policyReq.setFeedback(hashMap);//不能传null policyReq.setSimulate(hashMap);//不能传null policyReq.setSessionId(sessionId); //2024年7月5日13:24:10 temperature做区分 GenerateArgs generateArgs = new GenerateArgs(); generateArgs.setTemperature(bigModelConfig.getTemperature()); policyReq.setGenerateArgs(generateArgs); HashMap map = new HashMap<>(); map.put("rows", decisionReqs); //2024年6月25日14:16:05 增加报警是管控值报警还是标准值报警 if(WARNING_LEVEL_ONE.equals(tXinyiWarningRecord.getLevel()) || WARNING_LEVEL_TWO.equals(tXinyiWarningRecord.getLevel())) map.put("source", "bzz"); else map.put("source", "gkz"); policyReq.setExtra(map); dataJson = JSON.toJSONString(policyReq, JSONWriter.Feature.WriteNulls); // log.info("~~~~~~请求大模型的决策的参数为{}", dataJson); PredictionsRequest request = PredictionsRequest.newBuilder() .setModelName("slibra_bot") .putInput("method", ByteString.copyFrom("decision_stream", "utf-8"))//推理 .putInput("data", ByteString.copyFrom(dataJson, "utf-8")) .buildPartial(); Iterator predictions = stub.streamPredictions(request); while (predictions.hasNext()) { String responseStr = predictions.next().getPrediction().toStringUtf8(); // log.info("决策流式返回的结果是{}", responseStr); //2024年5月25日16:37:16 按照大模型返回的类型解析数据 String biz = JSON.parseObject(responseStr).getString("biz"); if(BusinessEnum.BigModelBizEnum.OK.getCode().equals(biz)){ log.info("结尾语句并且是非JSON,无需处理"); //结束语句也流式输出,但是并不记录下来 2024年5月24日11:15:23 也不返回前端 /*outputStream.write(responseStr.getBytes()); outputStream.flush();*/ }else if(BusinessEnum.BigModelBizEnum.DECISION_DEBUGGER.getCode().equals(biz)){ log.info("中间过程,目前只打印日志,不记录数据,也不返回给前端,返回数据为{}", responseStr); //结束语句也流式输出,但是并不记录下来 2024年5月24日11:15:23 也不返回前端 /*outputStream.write(responseStr.getBytes()); outputStream.flush();*/ }else{//其他 要么错误 要么alert 要么出的报告 // sb.append(responseStr); resultData.add(responseStr); } } } catch (Exception e) { // throw new RuntimeException(e); log.error("定时任务处理告警调用决策异常,异常信息为{}", JSON.toJSONString(e)); resultData.add("{\"biz\":\"ERROR\",\"message\":\"大模型分析数据异常,请稍后再试\"}"); } finally { // log.info("决策最终要保存的数据是{}", JSON.toJSONString(resultData)); //保存聊天记录 //将问答更新到数据库中 chatReq.setSessionId(sessionId); chatReq.setType(1);//0问答 1决策 chatReq.setModule(3); /*String userId = SecurityUtils.getUserId().toString(); String username = SecurityUtils.getUsername();*/ chatReq.setUserId(WARNING_DEFAULT_CREATE); String showVal = this.buildShowValue(tXinyiWarningRecord, tXinyiIndustry, normConfig, nowDate); chatReq.setShowVal(showVal);//前端展示的数据和提问的数据不一致 chatReq.setQuestion(dataJson); chatReq.setAnswer(JSON.toJSONString(resultData)); chatReq.setWarningId(String.valueOf(tXinyiWarningRecord.getId())); chatReq.setCounts(1);//问答次数 chatReq.setCreateBy(WARNING_DEFAULT_CREATE); chatReq.setCreateTime(DateUtils.getNowDate()); this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq); // 关闭输出流 if(!Objects.isNull(channel)) channel.shutdown(); } } /** * 2024年7月11日10:32:49 生化报警的展示额外处理(因为涉及到很多的单位) * * @param tXinyiWarningRecord * @param tXinyiIndustry * @param normConfig * @param nowDate * @param unit * @return */ private String buildShowValueSH(TXinyiWarningRecord tXinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, Date nowDate, String unit) { JSONObject result = new JSONObject(); // JSONObject basic = new JSONObject(); Integer status = tXinyiWarningRecord.getStatus(); Date warningTime = tXinyiWarningRecord.getTime(); String remark = tXinyiWarningRecord.getRemark(); int count = DateUtils.differentHoursByMillisecond(warningTime, DateUtils.getNowDate()) + 1; ShowValueSHBasic showValueSHBasic = new ShowValueSHBasic(); /*if("0".equals(remark)){//水质报警 showValueSHBasic.setH(ZAIXIANYIBIAO); showValueSHBasic.setF(tXinyiWarningRecord.getLevel()); }else if("1".equals(remark)){//生化报警 showValueSHBasic.setH(ZAIXIANYIBIAO); }else if("2".equals(remark)){//预测报警 showValueSHBasic.setH(YVCE); // showValueCSBasic.setF(tXinyiWarningRecord.getLevel()); }else {//机器人化验室报警(特殊的 水质报警) showValueSHBasic.setH(LIANXUJIANCE); showValueSHBasic.setF(tXinyiWarningRecord.getLevel()); }*/ //生化报警固定了 showValueSHBasic.setF(tXinyiWarningRecord.getLevel()); showValueSHBasic.setH("计算"); //通用的 // showValueBasic.setA(tXinyiWarningRecord.getReason()); showValueSHBasic.setB(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM ,warningTime)); showValueSHBasic.setC(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getWarningVal(), INT_2) + unit); showValueSHBasic.setD(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getDesignVal(), INT_2) + unit); showValueSHBasic.setG(Math.min(count, MAX_COUNT)); if(tXinyiWarningRecord.getType() != 2) showValueSHBasic.setI(status == 0 ? "报警中" : status == 1 ? "用户关闭" : status == 2 ? "系统关闭" : "应急处理中"); else showValueSHBasic.setI(status == 0 ? "预警中" : "已完成"); result.put("basic", showValueSHBasic); JSONObject jsData = jsCsFormatData.getJsonObject(tXinyiIndustry, normConfig);//进水数据 result.put("jsData", jsData); JSONObject csData = jsCsFormatData.getCsonObject(tXinyiIndustry, normConfig);//出水数据 result.put("csData", csData); // return JSON.toJSONString(result, JSONWriter.Feature.WriteNulls); return JSON.toJSONString(result); } private String buildShowValue(TXinyiWarningRecord tXinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, Date nowDate) { JSONObject result = new JSONObject(); // JSONObject basic = new JSONObject(); Integer status = tXinyiWarningRecord.getStatus(); Date warningTime = tXinyiWarningRecord.getTime(); String remark = tXinyiWarningRecord.getRemark(); int count = DateUtils.differentHoursByMillisecond(warningTime, DateUtils.getNowDate()) + 1; String category = tXinyiWarningRecord.getCategory(); /*basic.put("title", tXinyiWarningRecord.getReason()); basic.put("报警时间", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM ,warningTime)); basic.put("报警值", tXinyiWarningRecord.getWarningVal()); basic.put("标准值", tXinyiWarningRecord.getDesignVal()); basic.put("管控值", tXinyiWarningRecord.getControlVal()); basic.put("报警次数", Math.min(count, MAX_COUNT)); if(tXinyiWarningRecord.getType() != 2) basic.put("状态", status == 0 ? "报警中" : status == 1 ? "用户关闭" : status == 2 ? "系统关闭" : "应急处理中"); else basic.put("状态", status == 0 ? "预警中" : "已完成"); //2024年5月27日14:04:22 额外返回2个字段 [管控值 和 告警级别] 返回的json没有数据是因为value没有值 // basic.put("管控值", tXinyiWarningRecord.getControlVal()); basic.put("告警级别", tXinyiWarningRecord.getLevel());*/ //2024年6月25日16:00:18 进出水展示的不一样 //2024年7月15日10:57:31 因为新增了化验室的3个指标,也是出水数据 if(category.contains(CHUSHUI) || ROBOT_ECCZLSY.getCode().equalsIgnoreCase(category) || ROBOT_XSY_1.getCode().equalsIgnoreCase(category) || ROBOT_XSY_2.getCode().equalsIgnoreCase(category) || ROBOT_ANDAN_1.getCode().equalsIgnoreCase(category) || ROBOT_ANDAN_2.getCode().equalsIgnoreCase(category)){//出水的展示 ShowValueCSBasic showValueCSBasic = new ShowValueCSBasic(); if(ZERO_SZ_WARNING.getCode().equals(remark)){//水质报警 showValueCSBasic.setH(ZAIXIANYIBIAO); showValueCSBasic.setF(tXinyiWarningRecord.getLevel()); }else if(ONE_SH_WARNING.getCode().equals(remark)){//生化报警 showValueCSBasic.setH(ZAIXIANYIBIAO); }else if(BusinessEnum.BigModelWarningTypeRemarkEnum.TWO_YC_WARNING.getCode().equals(remark)){//预测报警 showValueCSBasic.setH(YVCE); // showValueCSBasic.setF(tXinyiWarningRecord.getLevel()); }else {//机器人化验室报警(特殊的水质报警) showValueCSBasic.setH(LIANXUJIANCE); showValueCSBasic.setF(tXinyiWarningRecord.getLevel()); } //通用的 // showValueBasic.setA(tXinyiWarningRecord.getReason()); // showValueCSBasic.setB(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM ,warningTime)); showValueCSBasic.setB(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM ,nowDate)); showValueCSBasic.setC(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getWarningVal(), INT_2)); showValueCSBasic.setD(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getControlVal(), INT_2)); showValueCSBasic.setE(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getDesignVal(), INT_2)); showValueCSBasic.setG(Math.min(count, MAX_COUNT)); if(tXinyiWarningRecord.getType() != 2) showValueCSBasic.setI(status == 0 ? "报警中" : status == 1 ? "用户关闭" : status == 2 ? "系统关闭" : "应急处理中"); else showValueCSBasic.setI(status == 0 ? "预警中" : "已完成"); result.put("basic", showValueCSBasic); }else{//进水的展示 ShowValueJSBasic showValueJSBasic = new ShowValueJSBasic(); if(ZERO_SZ_WARNING.getCode().equals(remark)){//水质报警 showValueJSBasic.setH(ZAIXIANYIBIAO); showValueJSBasic.setF(tXinyiWarningRecord.getLevel()); }else if(ONE_SH_WARNING.getCode().equals(remark)){//生化报警 showValueJSBasic.setH(ZAIXIANYIBIAO); }else if(BusinessEnum.BigModelWarningTypeRemarkEnum.TWO_YC_WARNING.getCode().equals(remark)){//预测报警 showValueJSBasic.setH(YVCE); // showValueCSBasic.setF(tXinyiWarningRecord.getLevel()); }else {//机器人化验室报警(特殊的 水质报警) showValueJSBasic.setH(LIANXUJIANCE); showValueJSBasic.setF(tXinyiWarningRecord.getLevel()); } //通用的 // showValueBasic.setA(tXinyiWarningRecord.getReason()); showValueJSBasic.setB(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM ,warningTime)); showValueJSBasic.setC(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getWarningVal(), INT_2)); showValueJSBasic.setE(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getDesignVal(), INT_2)); showValueJSBasic.setG(Math.min(count, MAX_COUNT)); if(tXinyiWarningRecord.getType() != 2) showValueJSBasic.setI(status == 0 ? "报警中" : status == 1 ? "用户关闭" : status == 2 ? "系统关闭" : "应急处理中"); else showValueJSBasic.setI(status == 0 ? "预警中" : "已完成"); result.put("basic", showValueJSBasic); } JSONObject jsData = jsCsFormatData.getJsonObject(tXinyiIndustry, normConfig);//进水数据 result.put("jsData", jsData); JSONObject csData = jsCsFormatData.getCsonObject(tXinyiIndustry, normConfig);//出水数据 result.put("csData", csData); // return JSON.toJSONString(result, JSONWriter.Feature.WriteNulls); return JSON.toJSONString(result); } private static JSONObject getJsonObject(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) { JSONObject jsData = new JSONObject(); HashMap temp1 = new HashMap<>(); BigDecimal jsSlq = tXinyiIndustry.getJsSlq(); temp1.put("value", DecimalUtils.getAbsAndScale(jsSlq, INT_2)); temp1.put("exceed", jsSlq.compareTo(normConfig.getJsslSjz()) >0); jsData.put("流量", temp1); HashMap temp2 = new HashMap<>(); BigDecimal jsCod = tXinyiIndustry.getJsCod(); temp2.put("value", DecimalUtils.getAbsAndScale(jsCod, INT_2)); temp2.put("exceed", jsCod.compareTo(normConfig.getJscodSjz()) > 0); jsData.put("COD", temp2); HashMap temp3 = new HashMap<>(); BigDecimal jsNh3 = tXinyiIndustry.getJsNh3(); temp3.put("value", DecimalUtils.getAbsAndScale(jsNh3, INT_2)); temp3.put("exceed", jsNh3.compareTo(normConfig.getJsadSjz()) > 0); jsData.put("NH3-N", temp3); HashMap temp4 = new HashMap<>(); BigDecimal jsTp = tXinyiIndustry.getJsTp(); temp4.put("value", DecimalUtils.getAbsAndScale(jsTp, INT_2)); temp4.put("exceed", jsTp.compareTo(normConfig.getJszlSjz()) > 0); jsData.put("TP", temp4); HashMap temp5 = new HashMap<>(); BigDecimal jsSs = tXinyiIndustry.getJsSs(); temp5.put("value", DecimalUtils.getAbsAndScale(jsSs, INT_2)); temp5.put("exceed", jsSs.compareTo(normConfig.getJsssSjz()) > 0); jsData.put("SS", temp5); HashMap temp6 = new HashMap<>(); BigDecimal jsTn = tXinyiIndustry.getJsTn(); temp6.put("value", DecimalUtils.getAbsAndScale(jsTn, INT_2)); temp6.put("exceed", jsTn.compareTo(normConfig.getJszdSjz()) > 0); jsData.put("TN", temp6); return jsData; } private static JSONObject getCsonObject(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) { JSONObject csData = new JSONObject(); HashMap temp1 = new HashMap<>(); BigDecimal csSlq = tXinyiIndustry.getCsSlqc(); temp1.put("value", DecimalUtils.getAbsAndScale(csSlq, INT_2)); temp1.put("exceed", false);//出水水量没有管控值 csData.put("流量", temp1); HashMap temp2 = new HashMap<>(); BigDecimal csCod = tXinyiIndustry.getCsCod(); temp2.put("value", DecimalUtils.getAbsAndScale(csCod, INT_2)); temp2.put("exceed", csCod.compareTo(normConfig.getCscodGkz()) > 0); csData.put("COD", temp2); HashMap temp3 = new HashMap<>(); BigDecimal csNh3 = tXinyiIndustry.getCsNh3(); temp3.put("value", DecimalUtils.getAbsAndScale(csNh3, INT_2)); temp3.put("exceed", csNh3.compareTo(normConfig.getCsadGkz()) > 0); csData.put("NH3-N", temp3); HashMap temp4 = new HashMap<>(); BigDecimal csTp = tXinyiIndustry.getCsTp(); temp4.put("value", DecimalUtils.getAbsAndScale(csTp, INT_2)); temp4.put("exceed", csTp.compareTo(normConfig.getCszlGkz()) > 0); csData.put("TP", temp4); HashMap temp5 = new HashMap<>(); BigDecimal csSs = tXinyiIndustry.getCsSs(); temp5.put("value", DecimalUtils.getAbsAndScale(csSs, INT_2)); temp5.put("exceed", csSs.compareTo(normConfig.getCsssGkz()) > 0); csData.put("SS", temp5); HashMap temp6 = new HashMap<>(); BigDecimal csTn = tXinyiIndustry.getCsTn(); temp6.put("value", DecimalUtils.getAbsAndScale(csTn, INT_2)); temp6.put("exceed", csTn.compareTo(normConfig.getCszzGkz()) > 0); csData.put("TN", temp6); return csData; } /** * 通过输入的值 生成对应类型的报警对象(出水) * * @param csBzz * @param currentVal * @param csGkz * @param category * @param tXinyiIndustry * @param normConfig * @return */ private void handleXinYiWarningsCs(BigDecimal csBzz, BigDecimal currentVal, BigDecimal csGkz, String category, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) { BigDecimal multiply = csBzz.multiply(new BigDecimal(MyConstants.SCALE_VALUE)); TXinyiWarningRecord tXinyiWarningRecord = new TXinyiWarningRecord(); /*String category = BusinessEnum.WarningCategoryEnum.CS_AD.getCode();*/ tXinyiWarningRecord.setStatus(0); tXinyiWarningRecord.setType(0); tXinyiWarningRecord.setCategory(category); tXinyiWarningRecord.setTime(DateUtils.getNowDate()); tXinyiWarningRecord.setWarningVal(currentVal); tXinyiWarningRecord.setDesignVal(csBzz); tXinyiWarningRecord.setControlVal(csGkz); tXinyiWarningRecord.setCreateBy(WARNING_DEFAULT_CREATE); tXinyiWarningRecord.setCreateTime(DateUtils.getNowDate()); tXinyiWarningRecord.setRemark(ZERO_SZ_WARNING.getCode()); //2024年5月25日17:52:33 如果工业库获取不到数据,也触发报警,但是不调用决策接口 if(Objects.isNull(currentVal) || currentVal.compareTo(BigDecimal.ZERO) == 0){ tXinyiWarningRecord.setReason(category + EXCEPTION_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_NO_DATE); }else if(currentVal.compareTo(multiply) > 0){//一级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_ONE); }else if(currentVal.compareTo(csBzz) >= 0 && currentVal.compareTo(multiply) <= 0){//二级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_TWO); }else if(!Objects.isNull(csGkz) && currentVal.compareTo(csGkz) > 0){ tXinyiWarningRecord.setReason(category + CHAOGUANKONG_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_THREE); }else{ tXinyiWarningRecord = null;//这种的无需处理 } //当前状态正常 需要查询历史有无正在报警的数据,如果有,将报警状态改完2(系统自动关闭) List tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(TXinyiWarningRecord.builder().delFlag(0).type(0).category(category).warningStatus(0).build()); if(Objects.isNull(tXinyiWarningRecord)){//数据正常,无告警信息 if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ log.info( "{}:现在恢复正常,历史报警数据为{}", category,JSON.toJSONString(tXinyiWarningRecords)); for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) { xinyiWarningRecord.setStatus(2); Date nowDate = DateUtils.getNowDate(); xinyiWarningRecord.setOffTime(nowDate); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); } } }else{//有告警信息 Date nowDate = DateUtils.getNowDate(); if(CollectionUtils.isEmpty(tXinyiWarningRecords)){//之前没有告警记录 //2024年7月18日16:23:11 新增逻辑,查询是否有连续升高的趋势,如果有才需要报警 List tXinyiIndustries = this.xinyiIndustryMapper.selectNIndustry(INT_3); if(CollectionUtils.isEmpty(tXinyiIndustries) || tXinyiIndustries.size() < 3){ log.error("处理生化报警时,获取最近的3条工业库数据失败~~~~~~~"); return; } TXinyiIndustry tXinyiIndustry1 = tXinyiIndustries.get(INDEX_1);//前一个小时 TXinyiIndustry tXinyiIndustry2 = tXinyiIndustries.get(INDEX_2);//前两个小时 if(!this.judgeContinuousIndustry(tXinyiIndustry1, tXinyiIndustry2, category)){ log.info("虽然当前超标了,但是没有连续升高趋势,所以不报警,当前没有报警出来的数据为{}\n,前一个小时数据为{}\n前两个小时数据为{}", JSON.toJSONString(tXinyiWarningRecord), JSON.toJSONString(tXinyiIndustry1), JSON.toJSONString(tXinyiIndustry2)); return; } //保存到数据库中 //2024年7月15日11:06:16 因为只有一个告警记录,但是如果一直报警,现在报警时间取的是更新时间,兼容第一次报警处理 tXinyiWarningRecord.setUpdateTime(nowDate); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord); if(WARNING_LEVEL_NO_DATE.equals(tXinyiWarningRecord.getLevel())){ //只保存一个普通的问答记录 不需要调用决策信息,但是实时数据还是要记录的 this.addChatRecordByDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig); }else { //继续调用决策 this.handleDecision(tXinyiWarningRecord, tXinyiIndustry, normConfig, false, nowDate); } }else{ log.info("{}:之前已经有过告警记录了,且还是继续报警,无需重复添加报警,但是决策仍然要调用", category); for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) {//理论上只有一个的 if(WARNING_LEVEL_NO_DATE.equals(tXinyiWarningRecord.getLevel())){ //只保存一个普通的问答记录 不需要调用决策信息,但是实时数据还是要记录的 this.addChatRecordByDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig); }else { //2024年7月5日10:45:24 逻辑调整:更新一直报警的那条记录的显示值 xinyiWarningRecord.setWarningVal(tXinyiWarningRecord.getWarningVal()); // xinyiWarningRecord.setDesignVal(tXinyiWarningRecord.getDesignVal()); // tXinyiWarningRecord.setControlVal(tXinyiWarningRecord.getControlVal()); xinyiWarningRecord.setTime(tXinyiWarningRecord.getTime()); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); //2024年7月15日11:07:33 报警的级别也要重新计算并更新 xinyiWarningRecord.setLevel(tXinyiWarningRecord.getLevel()); //2024年7月31日09:20:47 报警的原因(超标还是超管控也需要更新) xinyiWarningRecord.setReason(tXinyiWarningRecord.getReason()); //更新数据库 this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); //继续调用决策 this.handleDecision(xinyiWarningRecord, tXinyiIndustry, normConfig, false, nowDate); } } } } } /** * 通过输入的值 生成对应类型的报警对象(进水) * * @param jsBzz * @param currentVal * @param category * @param tXinyiIndustry * @param normConfig * @return */ private void handleXinYiWarningRecordJS(BigDecimal jsBzz, BigDecimal currentVal, String category, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) { BigDecimal multiply = jsBzz.multiply(new BigDecimal(MyConstants.SCALE_VALUE)); TXinyiWarningRecord tXinyiWarningRecord = new TXinyiWarningRecord(); /*String category = BusinessEnum.WarningCategoryEnum.CS_AD.getCode();*/ tXinyiWarningRecord.setStatus(0); tXinyiWarningRecord.setType(0); tXinyiWarningRecord.setCategory(category); tXinyiWarningRecord.setTime(DateUtils.getNowDate()); tXinyiWarningRecord.setWarningVal(currentVal); tXinyiWarningRecord.setDesignVal(jsBzz); // tXinyiWarningRecord.setControlVal(csGkz); tXinyiWarningRecord.setCreateBy(WARNING_DEFAULT_CREATE); tXinyiWarningRecord.setCreateTime(DateUtils.getNowDate()); tXinyiWarningRecord.setRemark(ZERO_SZ_WARNING.getCode()); //2024年5月25日17:52:33 如果工业库获取不到数据,也触发报警,但是不调用决策接口 if(Objects.isNull(currentVal) || currentVal.compareTo(BigDecimal.ZERO) == 0){ tXinyiWarningRecord.setReason(category + EXCEPTION_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_NO_DATE); }else if(currentVal.compareTo(multiply) > 0){//一级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_ONE); }else if(currentVal.compareTo(jsBzz) >= 0 && currentVal.compareTo(multiply) <= 0){//二级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_TWO); }else{ tXinyiWarningRecord = null;//这种的无需处理 } /*else if(!Objects.isNull(csGkz) && currentVal.compareTo(csGkz) > 0){ tXinyiWarningRecord.setReason(category + CHAOGUANKONG_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_THREE); }*/ //当前状态正常 需要查询历史有无正在报警的数据,如果有,将报警状态改完2(系统自动关闭) List tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(TXinyiWarningRecord.builder().delFlag(0).type(0).category(category).status(0).build()); if(Objects.isNull(tXinyiWarningRecord)){//数据正常,无告警信息 if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ log.info( "{}:现在恢复正常,历史报警数据为{}", category,JSON.toJSONString(tXinyiWarningRecords)); for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) { xinyiWarningRecord.setStatus(2); Date nowDate = DateUtils.getNowDate(); xinyiWarningRecord.setOffTime(nowDate); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); } } }else{//有告警信息 Date nowDate = DateUtils.getNowDate(); if(CollectionUtils.isEmpty(tXinyiWarningRecords)){//之前没有告警记录 //2024年7月18日16:23:11 新增逻辑,查询是否有连续升高的趋势,如果有才需要报警 List tXinyiIndustries = this.xinyiIndustryMapper.selectNIndustry(INT_3); if(CollectionUtils.isEmpty(tXinyiIndustries) || tXinyiIndustries.size() < 3){ log.error("处理生化报警时,获取最近的3条工业库数据失败~~~~~~~"); return; } TXinyiIndustry tXinyiIndustry1 = tXinyiIndustries.get(INDEX_1);//前一个小时 TXinyiIndustry tXinyiIndustry2 = tXinyiIndustries.get(INDEX_2);//前两个小时 if(!this.judgeContinuousIndustry(tXinyiIndustry1, tXinyiIndustry2, category)){ log.info("虽然当前超标了,但是没有连续升高趋势,所以不报警,当前没有报警出来的数据为{}\n,前一个小时数据为{}\n前两个小时数据为{}", JSON.toJSONString(tXinyiWarningRecord), JSON.toJSONString(tXinyiIndustry1), JSON.toJSONString(tXinyiIndustry2)); return; } //保存到数据库中 //2024年7月15日11:06:16 因为只有一个告警记录,但是如果一直报警,现在报警时间取的是更新时间,兼容第一次报警处理 tXinyiWarningRecord.setUpdateTime(nowDate); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord); if(WARNING_LEVEL_NO_DATE.equals(tXinyiWarningRecord.getLevel())){ //只保存一个普通的问答记录 不需要调用决策信息,但是实时数据还是要记录的 this.addChatRecordByDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig); }else { //继续调用决策 this.handleDecision(tXinyiWarningRecord, tXinyiIndustry, normConfig, false, nowDate); } }else{ log.info("{}:之前已经有过告警记录了,且还是继续报警,无需重复添加报警,但是决策仍然要调用", category); for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) {//理论上只有一个的 if(WARNING_LEVEL_NO_DATE.equals(tXinyiWarningRecord.getLevel())){ //只保存一个普通的问答记录 不需要调用决策信息,但是实时数据还是要记录的 this.addChatRecordByDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig); }else { //2024年7月5日10:45:24 逻辑调整:更新一直报警的那条记录的显示值 xinyiWarningRecord.setWarningVal(tXinyiWarningRecord.getWarningVal()); // xinyiWarningRecord.setDesignVal(tXinyiWarningRecord.getDesignVal()); // tXinyiWarningRecord.setControlVal(tXinyiWarningRecord.getControlVal()); xinyiWarningRecord.setTime(tXinyiWarningRecord.getTime()); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); //2024年7月15日11:07:33 报警的级别也要重新计算并更新 xinyiWarningRecord.setLevel(tXinyiWarningRecord.getLevel()); //2024年7月31日09:20:47 报警的原因(超标还是超管控也需要更新) xinyiWarningRecord.setReason(tXinyiWarningRecord.getReason()); //更新数据库 this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); //继续调用决策 this.handleDecision(xinyiWarningRecord, tXinyiIndustry, normConfig, false, nowDate); } } } } } private boolean judgeContinuousIndustry(TXinyiIndustry tXinyiIndustry1, TXinyiIndustry tXinyiIndustry2, String category) { boolean result = false;//默认不超标 if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ BigDecimal csCod1 = tXinyiIndustry1.getCsCod(); BigDecimal csCod2 = tXinyiIndustry2.getCsCod(); if(!Objects.isNull(csCod1) && !Objects.isNull(csCod2) && csCod1.compareTo(csCod2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ BigDecimal csSs1 = tXinyiIndustry1.getCsSs(); BigDecimal csSs2 = tXinyiIndustry2.getCsSs(); if(!Objects.isNull(csSs1) && !Objects.isNull(csSs2) && csSs1.compareTo(csSs2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ BigDecimal csTn1 = tXinyiIndustry1.getCsTn(); BigDecimal csTn2 = tXinyiIndustry2.getCsTn(); if(!Objects.isNull(csTn1) && !Objects.isNull(csTn2) && csTn1.compareTo(csTn2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ BigDecimal csTp1 = tXinyiIndustry1.getCsTp(); BigDecimal csTp2 = tXinyiIndustry2.getCsTp(); if(!Objects.isNull(csTp1) && !Objects.isNull(csTp2) && csTp1.compareTo(csTp2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ BigDecimal csNh31 = tXinyiIndustry1.getCsNh3(); BigDecimal csNh32 = tXinyiIndustry2.getCsNh3(); if(!Objects.isNull(csNh31) && !Objects.isNull(csNh32) && csNh31.compareTo(csNh32) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ BigDecimal jsCod1 = tXinyiIndustry1.getJsCod(); BigDecimal jsCod2 = tXinyiIndustry2.getJsCod(); if(!Objects.isNull(jsCod1) && !Objects.isNull(jsCod2) && jsCod1.compareTo(jsCod2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ BigDecimal jsSs1 = tXinyiIndustry1.getJsSs(); BigDecimal jsSs2 = tXinyiIndustry2.getJsSs(); if(!Objects.isNull(jsSs1) && !Objects.isNull(jsSs2) && jsSs1.compareTo(jsSs2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ BigDecimal jsTn1 = tXinyiIndustry1.getJsTn(); BigDecimal jsTn2 = tXinyiIndustry2.getJsTn(); if(!Objects.isNull(jsTn1) && !Objects.isNull(jsTn2) && jsTn1.compareTo(jsTn2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ BigDecimal jsTp1 = tXinyiIndustry1.getJsTp(); BigDecimal jsTp2 = tXinyiIndustry2.getJsTp(); if(!Objects.isNull(jsTp1) && !Objects.isNull(jsTp2) && jsTp1.compareTo(jsTp2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ BigDecimal jsNh31 = tXinyiIndustry1.getJsNh3(); BigDecimal jsNh32 = tXinyiIndustry2.getJsNh3(); if(!Objects.isNull(jsNh31) && !Objects.isNull(jsNh32) && jsNh31.compareTo(jsNh32) > INT_0) result = true; }else{ log.error("暂时还不支持的报警类型~~~~"); } return result; } private void addChatRecordByDeviceErr(TXinyiWarningRecord tXinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) { ChatReq chatReq = new ChatReq(); //保存聊天记录 //将问答更新到数据库中 chatReq.setSessionId(IdUtils.simpleUUID()); chatReq.setType(1);//0问答 1决策 2本地 3仿真预测 chatReq.setModule(3); /*String userId = SecurityUtils.getUserId().toString(); String username = SecurityUtils.getUsername();*/ chatReq.setUserId(WARNING_DEFAULT_CREATE); String showVal = this.buildShowValue(tXinyiWarningRecord, tXinyiIndustry, normConfig, DateUtils.getNowDate()); chatReq.setShowVal(showVal);//前端展示的数据和提问的数据不一致 chatReq.setQuestion(WARNING_DEFAULT_QUESTION);//本地问题 chatReq.setAnswer(tXinyiWarningRecord.getReason() + ",请检查设备是否正常运行"); chatReq.setWarningId(String.valueOf(tXinyiWarningRecord.getId())); chatReq.setCounts(1);//问答次数 chatReq.setCreateBy(WARNING_DEFAULT_CREATE); chatReq.setCreateTime(DateUtils.getNowDate()); this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq); } public static void main(String[] args) { System.out.println(CCCDCHRT_LAST); System.out.println(GSLS_LAST); System.out.println(BigDecimal.valueOf(1).subtract(null)); } /** * 处理机器人化验数据报警 * @param uniqueList */ public void handleRobotWarning(List uniqueList) { log.info("进入了定时任务判断机器人化验库是否超标及后续逻辑"); //查询配置 List tXinyiNormConfigs = this.xinyiNormConfigMapper.selectTXinyiNormConfigList(null); if(CollectionUtils.isEmpty(tXinyiNormConfigs)) throw new RuntimeException("未查询到配置信息"); TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0); //查询最新的一条工业库的数据(showvalue展示使用) List tXinyiIndustries = this.xinyiIndustryMapper.selectNIndustry(1); TXinyiIndustry tXinyiIndustry = CollectionUtils.isEmpty(tXinyiIndustries) ? new TXinyiIndustry() : tXinyiIndustries.get(0); //处理数据 for (TXinyiRobot tXinyiRobot : uniqueList) { //2024年7月11日17:27:32 化验室报警项原有总氮和总氮改为 1#好氧硝酸盐、2#好氧硝酸盐、二沉池正磷酸盐 //处理总氮和总磷报警 //总氮 /*BigDecimal no3Hlj1Jqr = tXinyiRobot.getNo3Hlj1Jqr(); BigDecimal no3Hlj2Jqr = tXinyiRobot.getNo3Hlj2Jqr(); if(!Objects.isNull(no3Hlj1Jqr) && !Objects.isNull(no3Hlj2Jqr)){ BigDecimal csTn = (no3Hlj1Jqr.add(no3Hlj2Jqr)).divide((new BigDecimal("2").multiply(ROBOT_HY_DIVIDE)), NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal cszzBzz = normConfig.getCszzBzz(); BigDecimal cszzGkz = normConfig.getCszzGkz(); if(!Objects.isNull(cszzBzz)){ handleXinYiWarningsRobot(cszzBzz, csTn, cszzGkz, BusinessEnum.WarningCategoryEnum.CS_ZD.getCode(), tXinyiIndustry, normConfig); } }*/ //总氮的标准值和管控值 BigDecimal cszzBzz = normConfig.getCszzBzz(); BigDecimal cszzGkz = normConfig.getCszzGkz(); //氨氮的标准值和管控值 BigDecimal csadBzz = normConfig.getCsadBzz(); BigDecimal csadGkz = normConfig.getCsadGkz(); //#1好氧硝酸盐 BigDecimal no3Hlj1Jqr = tXinyiRobot.getNo3Hlj1Jqr(); if(!Objects.isNull(no3Hlj1Jqr)){ if(!Objects.isNull(cszzBzz)){ handleXinYiWarningsRobot(cszzBzz, no3Hlj1Jqr, cszzGkz, ROBOT_XSY_1.getCode(), tXinyiIndustry, normConfig); } } //#2好氧硝酸盐 BigDecimal no3Hlj2Jqr = tXinyiRobot.getNo3Hlj2Jqr(); if(!Objects.isNull(no3Hlj2Jqr)){ if(!Objects.isNull(cszzBzz)){ handleXinYiWarningsRobot(cszzBzz, no3Hlj2Jqr, cszzGkz, ROBOT_XSY_2.getCode(), tXinyiIndustry, normConfig); } } //总磷 BigDecimal tpRccJqr = tXinyiRobot.getTpRccJqr(); if(!Objects.isNull(tpRccJqr)){ BigDecimal csTp = tpRccJqr.divide(ROBOT_HY_DIVIDE, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal cszlBzz = normConfig.getCszlBzz(); BigDecimal cszlGkz = normConfig.getCszlGkz(); if(!Objects.isNull(cszlBzz)){ handleXinYiWarningsRobot(cszlBzz, csTp, cszlGkz, ROBOT_ECCZLSY.getCode(), tXinyiIndustry, normConfig); } } //2024年7月18日10:48:15 新增报警:出水氨氮 - 连续检测报警 //1池 /*BigDecimal no3Qyc1Jqr = tXinyiRobot.getNo3Qyc1Jqr(); BigDecimal nh31Jqr = tXinyiRobot.getNh31Jqr(); //判断 增加容错 if(Objects.isNull(no3Qyc1Jqr)) no3Qyc1Jqr = BigDecimal.ZERO; if(Objects.isNull(nh31Jqr)) nh31Jqr = BigDecimal.ZERO; if(Objects.isNull(no3Hlj1Jqr)) no3Hlj1Jqr = BigDecimal.ZERO; BigDecimal anDan1 = no3Qyc1Jqr.add(nh31Jqr).subtract(no3Hlj1Jqr); if(!Objects.isNull(csadBzz)){ handleXinYiWarningsRobot(csadBzz, anDan1, csadGkz, ROBOT_ANDAN_1.getCode(), tXinyiIndustry, normConfig); } //2池 BigDecimal no3Qyc2Jqr = tXinyiRobot.getNo3Qyc2Jqr(); BigDecimal nh32Jqr = tXinyiRobot.getNh32Jqr(); //判断 增加容错 if(Objects.isNull(no3Qyc2Jqr)) no3Qyc2Jqr = BigDecimal.ZERO; if(Objects.isNull(nh32Jqr)) nh32Jqr = BigDecimal.ZERO; if(Objects.isNull(no3Hlj2Jqr)) no3Hlj2Jqr = BigDecimal.ZERO; BigDecimal anDan2 = no3Qyc2Jqr.add(nh32Jqr).subtract(no3Hlj2Jqr); if(!Objects.isNull(csadBzz)){ handleXinYiWarningsRobot(csadBzz, anDan2, csadGkz, ROBOT_ANDAN_2.getCode(), tXinyiIndustry, normConfig); }*/ BigDecimal no3Qyc1Jqr = tXinyiRobot.getNo3Qyc1Jqr(); BigDecimal nh31Jqr = tXinyiRobot.getNh31Jqr(); //判断 增加容错 if(Objects.isNull(no3Qyc1Jqr)) no3Qyc1Jqr = BigDecimal.ZERO; if(Objects.isNull(nh31Jqr)) nh31Jqr = BigDecimal.ZERO; if(Objects.isNull(no3Hlj1Jqr)) no3Hlj1Jqr = BigDecimal.ZERO; BigDecimal anDan1 = no3Qyc1Jqr.add(nh31Jqr).subtract(no3Hlj1Jqr); //2池 BigDecimal no3Qyc2Jqr = tXinyiRobot.getNo3Qyc2Jqr(); BigDecimal nh32Jqr = tXinyiRobot.getNh32Jqr(); //判断 增加容错 if(Objects.isNull(no3Qyc2Jqr)) no3Qyc2Jqr = BigDecimal.ZERO; if(Objects.isNull(nh32Jqr)) nh32Jqr = BigDecimal.ZERO; if(Objects.isNull(no3Hlj2Jqr)) no3Hlj2Jqr = BigDecimal.ZERO; BigDecimal anDan2 = no3Qyc2Jqr.add(nh32Jqr).subtract(no3Hlj2Jqr); if(!Objects.isNull(csadBzz)){ BigDecimal divide = anDan1.add(anDan2).divide(DECIMAL_2, INT_2, RoundingMode.HALF_UP); handleXinYiWarningsRobot(csadBzz, divide, csadGkz, CS_AD.getCode(), tXinyiIndustry, normConfig); } } } /** * 通过输入的值 生成对应类型的报警对象(出水) * * @param csBzz * @param currentVal * @param csGkz * @param category * @param tXinyiIndustry * @param normConfig * @return */ private void handleXinYiWarningsRobot(BigDecimal csBzz, BigDecimal currentVal, BigDecimal csGkz, String category, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) { BigDecimal multiply = csBzz.multiply(new BigDecimal(MyConstants.SCALE_VALUE)); TXinyiWarningRecord tXinyiWarningRecord = new TXinyiWarningRecord(); tXinyiWarningRecord.setStatus(0); tXinyiWarningRecord.setType(0); tXinyiWarningRecord.setCategory(category); tXinyiWarningRecord.setTime(DateUtils.getNowDate()); tXinyiWarningRecord.setWarningVal(currentVal); tXinyiWarningRecord.setDesignVal(csBzz); tXinyiWarningRecord.setControlVal(csGkz); tXinyiWarningRecord.setCreateBy(WARNING_DEFAULT_CREATE); tXinyiWarningRecord.setCreateTime(DateUtils.getNowDate()); tXinyiWarningRecord.setRemark(THREE_HYS_WARNING.getCode());//化验室 //2024年5月25日17:52:33 如果工业库获取不到数据,也触发报警,但是不调用决策接口 if(Objects.isNull(currentVal)){ tXinyiWarningRecord.setReason(category + EXCEPTION_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_NO_DATE); }else if(currentVal.compareTo(multiply) > 0){//一级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_ONE); }else if(currentVal.compareTo(csBzz) >= 0 && currentVal.compareTo(multiply) <= 0){//二级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_TWO); }else if(!Objects.isNull(csGkz) && currentVal.compareTo(csGkz) > 0){ tXinyiWarningRecord.setReason(category + CHAOGUANKONG_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_THREE); }else{ tXinyiWarningRecord = null;//这种的无需处理 } //当前状态正常 需要查询历史有无正在报警的数据,如果有,将报警状态改完2(系统自动关闭) List tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(TXinyiWarningRecord.builder().delFlag(0).type(0).category(category).warningStatus(0).build()); if(Objects.isNull(tXinyiWarningRecord)){//数据正常,无告警信息 if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ log.info( "{}:现在恢复正常,历史报警数据为{}", category,JSON.toJSONString(tXinyiWarningRecords)); for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) { xinyiWarningRecord.setStatus(2); Date nowDate = DateUtils.getNowDate(); xinyiWarningRecord.setOffTime(nowDate); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); } } }else{//有告警信息 Date nowDate = DateUtils.getNowDate(); if(CollectionUtils.isEmpty(tXinyiWarningRecords)){//之前没有告警记录 //2024年7月18日16:23:11 新增逻辑,查询是否有连续升高的趋势,如果有才需要报警 List tXinyiRobots = this.xinyiRobotMapper.selectNRobot(INT_3); if(CollectionUtils.isEmpty(tXinyiRobots) || tXinyiRobots.size() < 3){ log.error("处理连续检测报警时,获取最近的3条化验数据失败~~~~~~~"); return; } TXinyiRobot tXinyiRobot1 = tXinyiRobots.get(INDEX_1);//前一个小时 TXinyiRobot tXinyiRobot2 = tXinyiRobots.get(INDEX_2);//前两个小时 if(!this.judgeContinuousRobot(tXinyiRobot1, tXinyiRobot2, category)){ log.info("虽然当前超标了,但是没有连续升高趋势,所以不报警,当前没有报警出来的数据为{}\n,前一个小时数据为{}\n前两个小时数据为{}", JSON.toJSONString(tXinyiWarningRecord), JSON.toJSONString(tXinyiRobot1), JSON.toJSONString(tXinyiRobot2)); return; } //保存到数据库中 //2024年7月15日11:06:16 因为只有一个告警记录,但是如果一直报警,现在报警时间取的是更新时间,兼容第一次报警处理 tXinyiWarningRecord.setUpdateTime(nowDate); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord); if(WARNING_LEVEL_NO_DATE.equals(tXinyiWarningRecord.getLevel())){ //只保存一个普通的问答记录 不需要调用决策信息,但是实时数据还是要记录的 this.addChatRecordByDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig); }else { //继续调用决策 this.handleDecision(tXinyiWarningRecord, tXinyiIndustry, normConfig, true, nowDate); } }else{ log.info("{}:之前已经有过告警记录了,且还是继续报警,无需重复添加报警,但是决策仍然要调用", category); for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) {//理论上只有一个的 if(WARNING_LEVEL_NO_DATE.equals(tXinyiWarningRecord.getLevel())){ //只保存一个普通的问答记录 不需要调用决策信息,但是实时数据还是要记录的 this.addChatRecordByDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig); }else { //2024年7月5日10:45:24 逻辑调整:更新一直报警的那条记录的显示值 xinyiWarningRecord.setWarningVal(tXinyiWarningRecord.getWarningVal()); // xinyiWarningRecord.setDesignVal(tXinyiWarningRecord.getDesignVal()); // tXinyiWarningRecord.setControlVal(tXinyiWarningRecord.getControlVal()); xinyiWarningRecord.setTime(tXinyiWarningRecord.getTime()); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); //2024年7月15日11:07:33 报警的级别也要重新计算并更新 xinyiWarningRecord.setLevel(tXinyiWarningRecord.getLevel()); //2024年7月31日09:20:47 报警的原因(超标还是超管控也需要更新) xinyiWarningRecord.setReason(tXinyiWarningRecord.getReason()); //更新数据库 this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); //继续调用决策 this.handleDecision(xinyiWarningRecord, tXinyiIndustry, normConfig, true, nowDate); } } } } } private boolean judgeContinuousRobot(TXinyiRobot tXinyiRobot1, TXinyiRobot tXinyiRobot2, String category) { boolean result = false;//默认不超标 if(BusinessEnum.WarningCategoryEnum.ROBOT_XSY_1.getCode().equals(category)){ BigDecimal no3Hlj1Jqr1 = tXinyiRobot1.getNo3Hlj1Jqr(); BigDecimal no3Hlj1Jqr2 = tXinyiRobot2.getNo3Hlj1Jqr(); if(!Objects.isNull(no3Hlj1Jqr1) && !Objects.isNull(no3Hlj1Jqr2) && no3Hlj1Jqr1.compareTo(no3Hlj1Jqr2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.ROBOT_XSY_2.getCode().equals(category)){ BigDecimal no3Hlj2Jqr1 = tXinyiRobot1.getNo3Hlj2Jqr(); BigDecimal no3Hlj2Jqr2 = tXinyiRobot2.getNo3Hlj2Jqr(); if(!Objects.isNull(no3Hlj2Jqr1) && !Objects.isNull(no3Hlj2Jqr2) && no3Hlj2Jqr1.compareTo(no3Hlj2Jqr2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.ROBOT_ECCZLSY.getCode().equals(category)){ BigDecimal tpRccJqr1 = tXinyiRobot1.getTpRccJqr(); BigDecimal tpRccJqr2 = tXinyiRobot2.getTpRccJqr(); if(!Objects.isNull(tpRccJqr1) && !Objects.isNull(tpRccJqr2) && tpRccJqr1.compareTo(tpRccJqr2) > INT_0) result = true; }/*else if(BusinessEnum.WarningCategoryEnum.ROBOT_ANDAN_1.getCode().equals(category)){ //计算1 BigDecimal no3Qyc1Jqr1 = tXinyiRobot1.getNo3Qyc1Jqr(); BigDecimal nh31Jqr1 = tXinyiRobot1.getNh31Jqr(); BigDecimal no3Hlj1Jqr1 = tXinyiRobot1.getNo3Hlj1Jqr(); if(Objects.isNull(no3Qyc1Jqr1)) no3Qyc1Jqr1 = BigDecimal.ZERO; if(Objects.isNull(nh31Jqr1)) nh31Jqr1 = BigDecimal.ZERO; if(Objects.isNull(no3Hlj1Jqr1)) no3Hlj1Jqr1 = BigDecimal.ZERO; BigDecimal anDan1 = no3Qyc1Jqr1.add(nh31Jqr1).subtract(no3Hlj1Jqr1); //计算2 BigDecimal no3Qyc1Jqr2 = tXinyiRobot2.getNo3Qyc1Jqr(); BigDecimal nh31Jqr2 = tXinyiRobot2.getNh31Jqr(); BigDecimal no3Hlj1Jqr2 = tXinyiRobot2.getNo3Hlj1Jqr(); if(Objects.isNull(no3Qyc1Jqr2)) no3Qyc1Jqr2 = BigDecimal.ZERO; if(Objects.isNull(nh31Jqr2)) nh31Jqr2 = BigDecimal.ZERO; if(Objects.isNull(no3Hlj1Jqr2)) no3Hlj1Jqr2 = BigDecimal.ZERO; BigDecimal anDan2 = no3Qyc1Jqr2.add(nh31Jqr2).subtract(no3Hlj1Jqr2); if(anDan1.compareTo(anDan2) > INT_0) result = true; }else if(BusinessEnum.WarningCategoryEnum.ROBOT_ANDAN_2.getCode().equals(category)){ //计算1 BigDecimal no3Qyc1Jqr1 = tXinyiRobot1.getNo3Qyc2Jqr(); BigDecimal nh31Jqr1 = tXinyiRobot1.getNh32Jqr(); BigDecimal no3Hlj1Jqr1 = tXinyiRobot1.getNo3Hlj2Jqr(); if(Objects.isNull(no3Qyc1Jqr1)) no3Qyc1Jqr1 = BigDecimal.ZERO; if(Objects.isNull(nh31Jqr1)) nh31Jqr1 = BigDecimal.ZERO; if(Objects.isNull(no3Hlj1Jqr1)) no3Hlj1Jqr1 = BigDecimal.ZERO; BigDecimal anDan1 = no3Qyc1Jqr1.add(nh31Jqr1).subtract(no3Hlj1Jqr1); //计算2 BigDecimal no3Qyc1Jqr2 = tXinyiRobot2.getNo3Qyc2Jqr(); BigDecimal nh31Jqr2 = tXinyiRobot2.getNh32Jqr(); BigDecimal no3Hlj1Jqr2 = tXinyiRobot2.getNo3Hlj2Jqr(); if(Objects.isNull(no3Qyc1Jqr2)) no3Qyc1Jqr2 = BigDecimal.ZERO; if(Objects.isNull(nh31Jqr2)) nh31Jqr2 = BigDecimal.ZERO; if(Objects.isNull(no3Hlj1Jqr2)) no3Hlj1Jqr2 = BigDecimal.ZERO; BigDecimal anDan2 = no3Qyc1Jqr2.add(nh31Jqr2).subtract(no3Hlj1Jqr2); if(anDan1.compareTo(anDan2) > INT_0) result = true; }*/else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){//2024年7月26日14:33:39 合并一个指标:出水氨氮 //计算1(1池) BigDecimal no3Qyc1Jqr11 = tXinyiRobot1.getNo3Qyc1Jqr(); BigDecimal nh31Jqr11 = tXinyiRobot1.getNh31Jqr(); BigDecimal no3Hlj1Jqr11 = tXinyiRobot1.getNo3Hlj1Jqr(); if(Objects.isNull(no3Qyc1Jqr11)) no3Qyc1Jqr11 = BigDecimal.ZERO; if(Objects.isNull(nh31Jqr11)) nh31Jqr11 = BigDecimal.ZERO; if(Objects.isNull(no3Hlj1Jqr11)) no3Hlj1Jqr11 = BigDecimal.ZERO; BigDecimal anDan11 = no3Qyc1Jqr11.add(nh31Jqr11).subtract(no3Hlj1Jqr11); //计算1(2池) BigDecimal no3Qyc1Jqr12 = tXinyiRobot1.getNo3Qyc2Jqr(); BigDecimal nh31Jqr12 = tXinyiRobot1.getNh32Jqr(); BigDecimal no3Hlj1Jqr12 = tXinyiRobot1.getNo3Hlj2Jqr(); if(Objects.isNull(no3Qyc1Jqr12)) no3Qyc1Jqr12 = BigDecimal.ZERO; if(Objects.isNull(nh31Jqr12)) nh31Jqr12 = BigDecimal.ZERO; if(Objects.isNull(no3Hlj1Jqr12)) no3Hlj1Jqr12 = BigDecimal.ZERO; BigDecimal anDan12 = no3Qyc1Jqr12.add(nh31Jqr12).subtract(no3Hlj1Jqr12); BigDecimal divide1 = anDan11.add(anDan12).divide(DECIMAL_2, NUMBER_SCALE_4, RoundingMode.HALF_UP); //计算2(1池) BigDecimal no3Qyc1Jqr21 = tXinyiRobot2.getNo3Qyc1Jqr(); BigDecimal nh31Jqr21 = tXinyiRobot2.getNh31Jqr(); BigDecimal no3Hlj1Jqr21 = tXinyiRobot2.getNo3Hlj1Jqr(); if(Objects.isNull(no3Qyc1Jqr21)) no3Qyc1Jqr21 = BigDecimal.ZERO; if(Objects.isNull(nh31Jqr21)) nh31Jqr21 = BigDecimal.ZERO; if(Objects.isNull(no3Hlj1Jqr21)) no3Hlj1Jqr21 = BigDecimal.ZERO; BigDecimal anDan21 = no3Qyc1Jqr21.add(nh31Jqr21).subtract(no3Hlj1Jqr21); //计算2(2池) BigDecimal no3Qyc1Jqr22 = tXinyiRobot2.getNo3Qyc2Jqr(); BigDecimal nh31Jqr22 = tXinyiRobot2.getNh32Jqr(); BigDecimal no3Hlj1Jqr22 = tXinyiRobot2.getNo3Hlj2Jqr(); if(Objects.isNull(no3Qyc1Jqr22)) no3Qyc1Jqr22 = BigDecimal.ZERO; if(Objects.isNull(nh31Jqr22)) nh31Jqr22 = BigDecimal.ZERO; if(Objects.isNull(no3Hlj1Jqr22)) no3Hlj1Jqr22 = BigDecimal.ZERO; BigDecimal anDan22 = no3Qyc1Jqr22.add(nh31Jqr22).subtract(no3Hlj1Jqr22); BigDecimal divide2 = anDan21.add(anDan22).divide(DECIMAL_2, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(divide2) > INT_0) result = true; }else{ log.error("暂时还不支持的报警类型~~~~"); } return result; } /** * * 大宽表的数据处理 * @param tXinyiRobot */ public void updateBigTableHourByRobot(TXinyiRobot tXinyiRobot) { List tXinyiBigTableHours = this.xinyiBigTableHourMapper.selectTXinyiBigTableHourList(TXinyiBigTableHour.builder().testHour(tXinyiRobot.getTestHour()).build()); if(!CollectionUtils.isEmpty(tXinyiBigTableHours)){ for (TXinyiBigTableHour tXinyiBigTableHour : tXinyiBigTableHours) { this.updateBigTableByRobot(tXinyiBigTableHour, tXinyiRobot); } } } private void updateBigTableByRobot(TXinyiBigTableHour tXinyiBigTableHour, TXinyiRobot tXinyiRobot) { jsCsFormatData.addRobot2Hour(tXinyiBigTableHour, tXinyiRobot); //更新数据库 this.xinyiBigTableHourMapper.updateTXinyiBigTableHour(tXinyiBigTableHour); } }