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.exception.ServiceException; 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.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.text.ParseException; 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 * @param normConfig * @param xinyiCalculate */ // @Async("customizeExecutor") public void handleWarning(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, TXinyiCalculate xinyiCalculate){ //2024年08月09日14:26:29 为了节省费用,测试环境关闭报警并增加手动触发报警操作 if(PROD_ENVIRONMENT.equalsIgnoreCase(environment) || DENGBAO_ENVIRONMENT.equalsIgnoreCase(environment) || DEV_ENVIRONMENT.equalsIgnoreCase(environment) || LOCAL_ENVIRONMENT.equalsIgnoreCase(environment)){ log.info("进入了定时任务处理工业库报警的具体逻辑处理"); //新的逻辑: //只要当前获取的工业库数据和当前时间 //如果当前时间和工业库传过来的相差不到一个小时,说明正常,工业库没挂掉:需要查询是否有挂掉的记录,有的话,关闭此报警,并触发整体的业务数据报警。 //如果超过1小时了,说明工业库同步数据挂掉了,这时候去查询有无此类型的报警,如果有,不做任何处理,程序结束;如果没有,新增该类型报警并结束程序。 Date nowDate = DateUtils.getNowDate(); Date warningDate = null; try { warningDate = DateUtils.parseDate(tXinyiIndustry.getTestHour(), DateUtils.YYYYMMDDHH_TS); } catch (ParseException e) { // throw new RuntimeException(e.getMessage()); log.error("将工业库的化验时间转换date类型异常,异常信息为{}", e.getMessage()); return; } //查询工业库同步任务失败的报警正在进行的数据 /*TXinyiWarningRecord warningRecord = TXinyiWarningRecord.builder().symbol(BusinessEnum.WarningSymbolEnum.INDUSTRY_SYNC_ERROR.getCode()).status(0).build(); List tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecord);*/ long hours = DateUtils.differentHoursByLocalDateTime(nowDate, warningDate); if(hours == 0L){ //查看是否有正在进行的同步任务失败的报警 /*if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ closeWarning(tXinyiWarningRecords.get(0)); }*/ //正常的业务数据报警 //水质报警 //2025年02月20日10:52:31 在具体的报警类型中增加新的判断 仪表故障 数据异常等 this.handleSZWarning(tXinyiIndustry, normConfig); //2024年5月28日14:14:26 下面是新增的 生化报警处理 this.handleSHWarning(tXinyiIndustry, normConfig, xinyiCalculate); }else{ log.info("同步工业库任务获取最新的数据失败,无法处理报警信息。"); log.error("同步工业库任务获取最新的数据失败,无法处理报警信息。"); //todo 发送短信 //查询是否有正在工业库的同步任务失败的报警,有的话,什么都不做; 没有的话,新增该类型报警 /*if(CollectionUtils.isEmpty(tXinyiWarningRecords)){ //插入该类型报警 warningRecord.setType(0); String msg = BusinessEnum.WarningSymbolEnum.INDUSTRY_SYNC_ERROR.getMsg(); warningRecord.setCategory(msg); warningRecord.setTime(nowDate); warningRecord.setReason(msg); warningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.INDUSTRY_SYNC_ERROR.getCode()); warningRecord.setCreateBy(WARNING_DEFAULT_CREATE); warningRecord.setCreateTime(nowDate); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecord); }else{ log.info("工业库报警的时候,发现同步工业库任务挂掉了,并且已经有该类型报警了,不做任何处理"); }*/ //将其他类型的报警全部关闭 //2025年02月27日17:09:56 此场景不关闭其他报警 // closeOtherWarningsBySymbol(null); } } } /** * 将不是此报警类型的报警全部关闭 * @param symbol */ private void closeOtherWarningsBySymbol(Integer symbol) { List tXinyiWarningRecords = this.xinyiWarningRecordMapper.getOtherWarningsBySymbol(symbol); if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ for (TXinyiWarningRecord tXinyiWarningRecord : tXinyiWarningRecords) { this.closeWarning(tXinyiWarningRecord); } } } /** * 将此化验类型的其他的报警全部关闭 * @param category */ private void closeOtherWarningsByCategory(String category, Integer symbol) { List tXinyiWarningRecords = this.xinyiWarningRecordMapper.getOtherWarningsByCategory(category, symbol); if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ for (TXinyiWarningRecord tXinyiWarningRecord : tXinyiWarningRecords) { this.closeWarning(tXinyiWarningRecord); } } } private void closeWarning(TXinyiWarningRecord tXinyiWarningRecord) { Date nowDate = DateUtils.getNowDate(); tXinyiWarningRecord.setStatus(2); tXinyiWarningRecord.setOffTime(nowDate); tXinyiWarningRecord.setUpdateTime(nowDate); tXinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(tXinyiWarningRecord); } public 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 */ public 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(); BigDecimal jlForecastOne = tXinyiForecastComparison.getJlForecastOne(); 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(!Objects.isNull(jlForecastOne)){ BigDecimal subtract = csCod.subtract(jlForecastOne); tXinyiForecastComparison.setJlErrorRateOne((subtract).divide(csCod, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setJlOneSubtract(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(); BigDecimal jlForecastTwo = tXinyiForecastComparison.getJlForecastTwo(); 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(!Objects.isNull(jlForecastTwo)){ BigDecimal subtract = csCod.subtract(jlForecastTwo); tXinyiForecastComparison.setJlErrorRateTwo((subtract).divide(csCod, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setJlTwoSubtract(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(); BigDecimal jlForecastThree = tXinyiForecastComparison.getJlForecastThree(); 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(!Objects.isNull(jlForecastThree)){ BigDecimal subtract = csCod.subtract(jlForecastThree); tXinyiForecastComparison.setJlErrorRateThree((subtract).divide(csCod, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setJlThreeSubtract(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(); //2024年09月08日11:28:17 新增的四个预测使用 BigDecimal no3Qyc1Jqr = tXinyiRobot.getNo3Qyc1Jqr(); BigDecimal no3Qyc2Jqr = tXinyiRobot.getNo3Qyc2Jqr(); BigDecimal nh31Jqr = tXinyiRobot.getNh31Jqr(); BigDecimal nh32Jqr = tXinyiRobot.getNh32Jqr(); 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)); } } } //2024年09月08日11:31:16 新增四个预测的真实值的字段更新 if(BusinessEnum.BigModelForecastEnum.QYXSY1.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(no3Qyc1Jqr); if(!Objects.isNull(no3Qyc1Jqr) && no3Qyc1Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)){ BigDecimal subtract = no3Qyc1Jqr.subtract(hsForecastOne); tXinyiForecastComparison.setHsErrorRateOne((subtract).divide(no3Qyc1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastOne)){ BigDecimal subtract = no3Qyc1Jqr.subtract(yyForecastOne); tXinyiForecastComparison.setYyErrorRateOne((subtract).divide(no3Qyc1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.QYXSY2.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(no3Qyc2Jqr); if(!Objects.isNull(no3Qyc2Jqr) && no3Qyc2Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)){ BigDecimal subtract = no3Qyc2Jqr.subtract(hsForecastOne); tXinyiForecastComparison.setHsErrorRateOne((subtract).divide(no3Qyc2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastOne)){ BigDecimal subtract = no3Qyc2Jqr.subtract(yyForecastOne); tXinyiForecastComparison.setYyErrorRateOne((subtract).divide(no3Qyc2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.QYNH31.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(nh31Jqr); if(!Objects.isNull(nh31Jqr) && nh31Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)){ BigDecimal subtract = nh31Jqr.subtract(hsForecastOne); tXinyiForecastComparison.setHsErrorRateOne((subtract).divide(nh31Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastOne)){ BigDecimal subtract = nh31Jqr.subtract(yyForecastOne); tXinyiForecastComparison.setYyErrorRateOne((subtract).divide(nh31Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.QYNH32.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealOne(nh32Jqr); if(!Objects.isNull(nh32Jqr) && nh32Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastOne)){ BigDecimal subtract = nh32Jqr.subtract(hsForecastOne); tXinyiForecastComparison.setHsErrorRateOne((subtract).divide(nh32Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsOneSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastOne)){ BigDecimal subtract = nh32Jqr.subtract(yyForecastOne); tXinyiForecastComparison.setYyErrorRateOne((subtract).divide(nh32Jqr, 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)); } } } //2024年09月08日11:31:16 新增四个预测的真实值的字段更新 if(BusinessEnum.BigModelForecastEnum.QYXSY1.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(no3Qyc1Jqr); if(!Objects.isNull(no3Qyc1Jqr) && no3Qyc1Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)){ BigDecimal subtract = no3Qyc1Jqr.subtract(hsForecastTwo); tXinyiForecastComparison.setHsErrorRateTwo((subtract).divide(no3Qyc1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastTwo)){ BigDecimal subtract = no3Qyc1Jqr.subtract(yyForecastTwo); tXinyiForecastComparison.setYyErrorRateTwo((subtract).divide(no3Qyc1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.QYXSY2.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(no3Qyc2Jqr); if(!Objects.isNull(no3Qyc2Jqr) && no3Qyc2Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)){ BigDecimal subtract = no3Qyc2Jqr.subtract(hsForecastTwo); tXinyiForecastComparison.setHsErrorRateTwo((subtract).divide(no3Qyc2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastTwo)){ BigDecimal subtract = no3Qyc2Jqr.subtract(yyForecastTwo); tXinyiForecastComparison.setYyErrorRateTwo((subtract).divide(no3Qyc2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.QYNH31.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(nh31Jqr); if(!Objects.isNull(nh31Jqr) && nh31Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)){ BigDecimal subtract = nh31Jqr.subtract(hsForecastTwo); tXinyiForecastComparison.setHsErrorRateTwo((subtract).divide(nh31Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastTwo)){ BigDecimal subtract = nh31Jqr.subtract(yyForecastTwo); tXinyiForecastComparison.setYyErrorRateTwo((subtract).divide(nh31Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.QYNH32.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealTwo(nh32Jqr); if(!Objects.isNull(nh32Jqr) && nh32Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastTwo)){ BigDecimal subtract = nh32Jqr.subtract(hsForecastTwo); tXinyiForecastComparison.setHsErrorRateTwo((subtract).divide(nh32Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsTwoSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastTwo)){ BigDecimal subtract = nh32Jqr.subtract(yyForecastTwo); tXinyiForecastComparison.setYyErrorRateTwo((subtract).divide(nh32Jqr, 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)); } } } //2024年09月08日11:31:16 新增四个预测的真实值的字段更新 if(BusinessEnum.BigModelForecastEnum.QYXSY1.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(no3Qyc1Jqr); if(!Objects.isNull(no3Qyc1Jqr) && no3Qyc1Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)){ BigDecimal subtract = no3Qyc1Jqr.subtract(hsForecastThree); tXinyiForecastComparison.setHsErrorRateThree((subtract).divide(no3Qyc1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastThree)){ BigDecimal subtract = no3Qyc1Jqr.subtract(yyForecastThree); tXinyiForecastComparison.setYyErrorRateThree((subtract).divide(no3Qyc1Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.QYXSY2.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(no3Qyc2Jqr); if(!Objects.isNull(no3Qyc2Jqr) && no3Qyc2Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)){ BigDecimal subtract = no3Qyc2Jqr.subtract(hsForecastThree); tXinyiForecastComparison.setHsErrorRateThree((subtract).divide(no3Qyc2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastThree)){ BigDecimal subtract = no3Qyc2Jqr.subtract(yyForecastThree); tXinyiForecastComparison.setYyErrorRateThree((subtract).divide(no3Qyc2Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.QYNH31.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(nh31Jqr); if(!Objects.isNull(nh31Jqr) && nh31Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)){ BigDecimal subtract = nh31Jqr.subtract(hsForecastThree); tXinyiForecastComparison.setHsErrorRateThree((subtract).divide(nh31Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastThree)){ BigDecimal subtract = nh31Jqr.subtract(yyForecastThree); tXinyiForecastComparison.setYyErrorRateThree((subtract).divide(nh31Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } if(BusinessEnum.BigModelForecastEnum.QYNH32.getCode().equalsIgnoreCase(tXinyiForecastComparison.getCategory())){ tXinyiForecastComparison.setRealThree(nh32Jqr); if(!Objects.isNull(nh32Jqr) && nh32Jqr.compareTo(BigDecimal.ZERO) > 0){ if(!Objects.isNull(hsForecastThree)){ BigDecimal subtract = nh32Jqr.subtract(hsForecastThree); tXinyiForecastComparison.setHsErrorRateThree((subtract).divide(nh32Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setHsThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } if(!Objects.isNull(yyForecastThree)){ BigDecimal subtract = nh32Jqr.subtract(yyForecastThree); tXinyiForecastComparison.setYyErrorRateThree((subtract).divide(nh32Jqr, NUMBER_SCALE_4, RoundingMode.HALF_UP)); tXinyiForecastComparison.setYyThreeSubtract(DecimalUtils.getAbsAndScale(subtract, INT_2)); } } } this.xinyiForecastComparisonMapper.updateTXinyiForecastComparison(tXinyiForecastComparison); } } } public 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报警 //2025年02月14日10:22:05 计算出相应的超污染物限制 和 超污染物负荷值,然后传到下一个方法,否则下一个方法很多判断 BigDecimal csCod = tXinyiIndustry.getCsCod(); BigDecimal cscodBzz = normConfig.getCscodBzz(); BigDecimal cscodGkz = normConfig.getCscodGkz(); BigDecimal jsSlq = tXinyiIndustry.getJsSlq(); BigDecimal jsslSjz = normConfig.getJsslSjz(); BigDecimal cszlBzz = normConfig.getCszlBzz(); BigDecimal cszlGkz = normConfig.getCszlGkz(); BigDecimal cszzBzz = normConfig.getCszzBzz(); BigDecimal cszzGkz = normConfig.getCszzGkz(); BigDecimal csadBzz = normConfig.getCsadBzz(); BigDecimal csadGkz = normConfig.getCsadGkz(); BigDecimal csSSBzz = normConfig.getCsssBzz(); BigDecimal csssGkz = normConfig.getCsssGkz(); BigDecimal jszlSjz = normConfig.getJszlSjz(); BigDecimal jszdSjz = normConfig.getJszdSjz(); BigDecimal jscodSjz = normConfig.getJscodSjz(); BigDecimal jsadSjz = normConfig.getJsadSjz(); BigDecimal jsSSSjz = normConfig.getJsssSjz(); //2025年02月20日11:19:17 累计的断点数量 int breakpointCount = 0; int noChange = 0; List breakPointList = new ArrayList<>();//断点集合 List noChangeList = new ArrayList<>();//连续不变集合 //2025年02月27日16:17:47 标识进出水的指标是否可以进行后续的报警 boolean csCodExecute = true; boolean csZLExecute = true; boolean csZDExecute = true; boolean csADExecute = true; boolean csSSExecute = true; boolean jsZLExecute = true; boolean jsCodExecute = true; boolean jsZDExecute = true; boolean jsADExecute = true; boolean jsSSExecute = true; //出水cod超标报警 WarningMoreExceed warningMoreExceed = handleXinYiWarningsCsMore(cscodBzz, csCod, cscodGkz, CS_COD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsCod(), jsslSjz, normConfig.getJscodSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } if(warningMoreExceed.isNoChange()){ noChange++; noChangeList.add(warningMoreExceed.getNoChangeWarningRecord()); } //出水总磷超标报警 BigDecimal csTp = tXinyiIndustry.getCsTp(); warningMoreExceed = handleXinYiWarningsCsMore(cszlBzz, csTp, cszlGkz, BusinessEnum.WarningCategoryEnum.CS_ZL.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTp(), jsslSjz, normConfig.getJszlSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } if(warningMoreExceed.isNoChange()){ noChange++; noChangeList.add(warningMoreExceed.getNoChangeWarningRecord()); } //出水总氮超标报警 BigDecimal csTn = tXinyiIndustry.getCsTn(); warningMoreExceed = handleXinYiWarningsCsMore(cszzBzz, csTn, cszzGkz, BusinessEnum.WarningCategoryEnum.CS_ZD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } if(warningMoreExceed.isNoChange()){ noChange++; noChangeList.add(warningMoreExceed.getNoChangeWarningRecord()); } //出水氨氮超标报警 BigDecimal csNh3 = tXinyiIndustry.getCsNh3(); warningMoreExceed = handleXinYiWarningsCsMore(csadBzz, csNh3, csadGkz, BusinessEnum.WarningCategoryEnum.CS_AD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsNh3(), jsslSjz, normConfig.getJsadSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } if(warningMoreExceed.isNoChange()){ noChange++; noChangeList.add(warningMoreExceed.getNoChangeWarningRecord()); } //出水SS超标报警 BigDecimal csSS = tXinyiIndustry.getCsSs(); warningMoreExceed = handleXinYiWarningsCsMore(csSSBzz, csSS, csssGkz, BusinessEnum.WarningCategoryEnum.CS_SS.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsSs(), jsslSjz, normConfig.getJsssSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } if(warningMoreExceed.isNoChange()){ noChange++; noChangeList.add(warningMoreExceed.getNoChangeWarningRecord()); } //进水相关报警 //进水总磷超标报警 BigDecimal jsTp = tXinyiIndustry.getJsTp(); warningMoreExceed = handleXinYiWarningRecordJSMore(jszlSjz, jsTp, BusinessEnum.WarningCategoryEnum.JS_ZL.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTp(), jsslSjz, normConfig.getJszlSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } if(warningMoreExceed.isNoChange()){ noChange++; noChangeList.add(warningMoreExceed.getNoChangeWarningRecord()); } //进水COD超标报警 BigDecimal jsCod = tXinyiIndustry.getJsCod(); warningMoreExceed = handleXinYiWarningRecordJSMore(jscodSjz, jsCod, BusinessEnum.WarningCategoryEnum.JS_COD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsCod(), jsslSjz, normConfig.getJscodSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } if(warningMoreExceed.isNoChange()){ noChange++; noChangeList.add(warningMoreExceed.getNoChangeWarningRecord()); } //进水总氮超标报警 BigDecimal jsTn = tXinyiIndustry.getJsTn(); warningMoreExceed = handleXinYiWarningRecordJSMore(jszdSjz, jsTn, BusinessEnum.WarningCategoryEnum.JS_ZD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } if(warningMoreExceed.isNoChange()){ noChange++; noChangeList.add(warningMoreExceed.getNoChangeWarningRecord()); } //进水氨氮超标报警 BigDecimal jsNh3 = tXinyiIndustry.getJsNh3(); warningMoreExceed = handleXinYiWarningRecordJSMore(jsadSjz, jsNh3, BusinessEnum.WarningCategoryEnum.JS_AD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsNh3(), jsslSjz, normConfig.getJsadSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } if(warningMoreExceed.isNoChange()){ noChange++; noChangeList.add(warningMoreExceed.getNoChangeWarningRecord()); } //进水SS超标报警 BigDecimal jsSS = tXinyiIndustry.getJsSs(); warningMoreExceed = handleXinYiWarningRecordJSMore(jsSSSjz, jsSS, BusinessEnum.WarningCategoryEnum.JS_SS.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsSs(), jsslSjz, normConfig.getJsssSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } if(warningMoreExceed.isNoChange()){ noChange++; noChangeList.add(warningMoreExceed.getNoChangeWarningRecord()); } Date nowDate = DateUtils.getNowDate(); //下面是处理多个指标的 【断点】和 连续不变的报警 //断点 //2025年02月28日13:45:49 逻辑调整:多指标断点/联系不变 也要记录对应的化验类型 所以下面可以查询出来多个 TXinyiWarningRecord warningRecord = TXinyiWarningRecord.builder().symbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getCode()).status(0).build(); List tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecord); if(breakpointCount < 1){//恢复正常 关闭多个断点报警 //关闭之前的多个 多指标断点报警 if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ for (TXinyiWarningRecord tXinyiWarningRecord : tXinyiWarningRecords) { closeWarning(tXinyiWarningRecord); } } }else if(breakpointCount == 1){//只有单个的断点 TXinyiWarningRecord warningRecordBreakPointOne = breakPointList.get(0); String category = warningRecordBreakPointOne.getCategory(); TXinyiWarningRecord warningRecordReq = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()).status(0).build(); List tXinyiBreakPointSingleWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecordReq); //关闭同类型的其他报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()); //触发报警 并且模拟大模型返回决策问答数据 if(CollectionUtils.isEmpty(tXinyiBreakPointSingleWarningRecords)){ //插入该类型报警 this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordBreakPointOne); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByBreakPointsSingle(warningRecordBreakPointOne, tXinyiIndustry, normConfig, category); }else{ log.info("工业库报警的时候,发现存在仪表故障(断点不变单个指标)的报警,并且已经有该类型报警了,不做任何处理"); //2025年03月06日10:52:57 逻辑调整:更新一直报警的那条记录的显示值 TXinyiWarningRecord xinyiWarningRecord = tXinyiBreakPointSingleWarningRecords.get(0); xinyiWarningRecord.setWarningVal(warningRecordBreakPointOne.getWarningVal()); xinyiWarningRecord.setTime(warningRecordBreakPointOne.getTime()); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); //2024年7月31日09:20:47 报警的原因(超标还是超管控也需要更新) xinyiWarningRecord.setReason(warningRecordBreakPointOne.getReason()); //更新数据库 this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); //继续调用决策【本地模拟的决策】 addChatRecordByBreakPointsSingle(xinyiWarningRecord, tXinyiIndustry, normConfig, category); } //额外判断当前的异常是哪个指标,并处理标识 if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ csCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ csZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ csZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ csADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ csSSExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ jsZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ jsCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ jsZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ jsADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ jsSSExecute = false; }else{ log.error("处理是否后续报警的报警类型是不支持的类型"); throw new ServiceException("处理是否后续报警的报警类型是不支持的类型"); } //关闭之前的多个 多指标断点报警 if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ for (TXinyiWarningRecord tXinyiWarningRecord : tXinyiWarningRecords) { closeWarning(tXinyiWarningRecord); } } }else{ //将其他类型的报警全部关闭 //2025年02月27日17:09:56 此场景不关闭其他报警 // closeOtherWarningsBySymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getCode()); //再新增新的类型的报警 /*if(CollectionUtils.isEmpty(tXinyiWarningRecords)){ //插入该类型报警 warningRecord.setType(0); String msg = BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getMsg(); warningRecord.setCategory(msg); warningRecord.setTime(nowDate); warningRecord.setReason(msg); warningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getCode()); warningRecord.setCreateBy(WARNING_DEFAULT_CREATE); warningRecord.setCreateTime(nowDate); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecord); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByBreakPointsMore(warningRecord, tXinyiIndustry, normConfig); }else{ log.info("工业库报警的时候,发现存在仪表故障(断点多个指标)的报警,并且已经有该类型报警了,不做任何处理"); } log.info("工业库报警的时候,发现存在仪表故障(断点多个指标)的报警,其他报警不再处理"); return;*/ //逻辑调整:要按指标报多指标断点 需要当前的集合和原来的集合判断,新的报警增加,如果之前有了报警则不处理 if(CollectionUtils.isEmpty(tXinyiWarningRecords)){ //新增的断点的数据全部都报警 for (TXinyiWarningRecord tXinyiWarningRecord : breakPointList) { String category = tXinyiWarningRecord.getCategory(); //判断那些指标不能再次执行 //额外判断当前的异常是哪个指标,并处理标识 if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ csCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ csZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ csZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ csADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ csSSExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ jsZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ jsCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ jsZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ jsADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ jsSSExecute = false; }else{ log.error("处理是否后续报警的报警类型是不支持的类型"); throw new ServiceException("处理是否后续报警的报警类型是不支持的类型"); } //关闭该指标的其他类型的报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getCode()); //原来集合里存放的都是单指标异常 下面2个值需要重新赋值 tXinyiWarningRecord.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getMsg()); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getCode()); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByBreakPointsMore(tXinyiWarningRecord, tXinyiIndustry, normConfig); } }else{//之前存在报警了 所以需要2个集合数据进行匹配,如果新的和原来的一样则不用做任何操作【持续报警】;如果不一样,则新的要报警,老报警要关闭 List breakPointListNew = new ArrayList<>(breakPointList);//断点集合[需要新增的] breakPointListNew.removeAll(tXinyiWarningRecords); List breakPointListClose = new ArrayList<>(tXinyiWarningRecords);//断点集合[需要关闭的] 还有2这重叠的,这种重叠的,是不需要做任何操作的,持续报警 breakPointListClose.removeAll(breakPointList); //插入新的报警 if(!CollectionUtils.isEmpty(breakPointListNew)){ for (TXinyiWarningRecord tXinyiWarningRecord : breakPointListNew) { String category = tXinyiWarningRecord.getCategory(); //判断那些指标不能再次执行 //额外判断当前的异常是哪个指标,并处理标识 if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ csCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ csZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ csZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ csADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ csSSExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ jsZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ jsCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ jsZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ jsADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ jsSSExecute = false; }else{ log.error("处理是否后续报警的报警类型是不支持的类型"); throw new ServiceException("处理是否后续报警的报警类型是不支持的类型"); } //关闭该指标的其他类型的报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getCode()); //新插入 //原来集合里存放的都是单指标异常 下面2个值需要重新赋值 tXinyiWarningRecord.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getMsg()); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getCode()); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByBreakPointsMore(tXinyiWarningRecord, tXinyiIndustry, normConfig); } } //关闭老的报警 if(!CollectionUtils.isEmpty(breakPointListClose)){ for (TXinyiWarningRecord tXinyiWarningRecord : breakPointListClose) { //老的报警,新的没有出现,关闭 closeWarning(tXinyiWarningRecord); } } //2025年03月06日10:56:41 需要额外记录哪些是历史报警,现在仍然报警的,这种的更新部分信息,更新决策内容 List breakPointListContinue = new ArrayList<>(tXinyiWarningRecords); breakPointListContinue.removeAll(breakPointListNew); if(!CollectionUtils.isEmpty(breakPointListContinue)){ for (TXinyiWarningRecord tXinyiWarningRecord : breakPointListContinue) { //2025年03月06日10:52:57 逻辑调整:更新一直报警的那条记录的显示值 //需要匹配新的报警中的最新的值 String category = tXinyiWarningRecord.getCategory(); TXinyiWarningRecord tXinyiWarningRecordContinue = tXinyiWarningRecord;//兜底处理 Optional optional = breakPointListNew.stream().filter(r -> category.equals(r.getCategory())).findAny(); if(optional.isPresent()){ tXinyiWarningRecordContinue = optional.get(); log.info("存在之前多指标断点,现在仍然断点的数据{}", JSON.toJSONString(tXinyiWarningRecordContinue)); } tXinyiWarningRecord.setWarningVal(tXinyiWarningRecordContinue.getWarningVal()); tXinyiWarningRecord.setTime(tXinyiWarningRecordContinue.getTime()); tXinyiWarningRecord.setUpdateTime(nowDate); tXinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); //从单指标变成多指标 这个不可以修改 // tXinyiWarningRecord.setReason(tXinyiWarningRecordContinue.getReason()); //更新数据库 this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(tXinyiWarningRecord); //继续调用决策【本地模拟的决策】 addChatRecordByBreakPointsMore(tXinyiWarningRecord, tXinyiIndustry, normConfig); } } } //如果出现多指标问题,后续的报警不再处理 // return; //2025年03月03日16:07:09 不是其他报警都不执行,只是出现异常的问题不再进行报警,其他的还需要再次报警 } //连续不变 TXinyiWarningRecord warningRecordNoChangeMore = TXinyiWarningRecord.builder().symbol(BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getCode()).status(0).build(); List tXinyiWarningNoChangeMoreRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecordNoChangeMore); if(noChange < 1){//恢复正常,关闭多个连续不变报警 //关闭之前的多个 多指标断点报警 if(!CollectionUtils.isEmpty(tXinyiWarningNoChangeMoreRecords)){ for (TXinyiWarningRecord tXinyiWarningRecord : tXinyiWarningNoChangeMoreRecords) { closeWarning(tXinyiWarningRecord); } } }else if(noChange == 1){ TXinyiWarningRecord noChangeWarningRecord = noChangeList.get(0); String category = noChangeWarningRecord.getCategory(); TXinyiWarningRecord warningRecordReq = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getCode()).status(0).build(); List tXinyiNoChangeSingleWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecordReq); //关闭同类型的其他报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getCode()); //触发报警 并且模拟大模型返回决策问答数据 if(CollectionUtils.isEmpty(tXinyiNoChangeSingleWarningRecords)){ //插入该类型报警 this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(noChangeWarningRecord); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByNoChangeSingle(noChangeWarningRecord, tXinyiIndustry, normConfig, category); }else{ log.info("工业库报警的时候,发现存在仪表故障(连续不变单个指标)的报警,并且已经有该类型报警了,不做任何处理"); //2025年03月06日10:52:57 逻辑调整:更新一直报警的那条记录的显示值 TXinyiWarningRecord xinyiWarningRecord = tXinyiNoChangeSingleWarningRecords.get(0); xinyiWarningRecord.setWarningVal(noChangeWarningRecord.getWarningVal()); xinyiWarningRecord.setTime(noChangeWarningRecord.getTime()); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); //2024年7月31日09:20:47 报警的原因(超标还是超管控也需要更新) xinyiWarningRecord.setReason(noChangeWarningRecord.getReason()); //更新数据库 this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); //继续调用决策【本地模拟的决策】 addChatRecordByNoChangeSingle(xinyiWarningRecord, tXinyiIndustry, normConfig, category); } //额外判断当前的异常是哪个指标,并处理标识 if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ csCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ csZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ csZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ csADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ csSSExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ jsZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ jsCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ jsZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ jsADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ jsSSExecute = false; }else{ log.error("处理是否后续报警的报警类型是不支持的类型"); throw new ServiceException("处理是否后续报警的报警类型是不支持的类型"); } //关闭之前的多个 多指标断点报警 if(!CollectionUtils.isEmpty(tXinyiWarningNoChangeMoreRecords)){ for (TXinyiWarningRecord tXinyiWarningRecord : tXinyiWarningNoChangeMoreRecords) { closeWarning(tXinyiWarningRecord); } } }else{ //将其他类型的报警全部关闭 //2025年02月27日17:09:56 此场景不关闭其他报警 // closeOtherWarningsBySymbol(BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getCode()); //触发 多个连续不变报警 /*if(CollectionUtils.isEmpty(tXinyiWarningNoChangeMoreRecords)){ //插入该类型报警 warningRecordNoChangeMore.setType(0); String msg = BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getMsg(); warningRecordNoChangeMore.setCategory(msg); warningRecordNoChangeMore.setTime(nowDate); warningRecordNoChangeMore.setReason(msg); warningRecordNoChangeMore.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getCode()); warningRecordNoChangeMore.setCreateBy(WARNING_DEFAULT_CREATE); warningRecordNoChangeMore.setCreateTime(nowDate); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordNoChangeMore); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByNoChangeMore(warningRecordNoChangeMore, tXinyiIndustry, normConfig); }else{ log.info("工业库报警的时候,发现存在仪表故障(连续不变多个指标)的报警,并且已经有该类型报警了,不做任何处理"); } log.info("发现存在仪表故障(连续不变多个指标)的报警,其他报警不再处理"); return;*/ //逻辑调整:要按指标报多指标断点 需要当前的集合和原来的集合判断,新的报警增加,如果之前有了报警则不处理 if(CollectionUtils.isEmpty(tXinyiWarningNoChangeMoreRecords)){ //新增的断点的数据全部都报警 for (TXinyiWarningRecord tXinyiWarningRecord : noChangeList) { String category = tXinyiWarningRecord.getCategory(); //判断那些指标不能再次执行 //额外判断当前的异常是哪个指标,并处理标识 if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ csCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ csZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ csZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ csADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ csSSExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ jsZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ jsCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ jsZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ jsADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ jsSSExecute = false; }else{ log.error("处理是否后续报警的报警类型是不支持的类型"); throw new ServiceException("处理是否后续报警的报警类型是不支持的类型"); } //关闭该指标的其他类型的报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getCode()); //原来集合里存放的都是单指标异常 下面2个值需要重新赋值 tXinyiWarningRecord.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getMsg()); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getCode()); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByNoChangeMore(tXinyiWarningRecord, tXinyiIndustry, normConfig); } }else{//之前存在报警了 所以需要2个集合数据进行匹配,如果新的和原来的一样则不用做任何操作【持续报警】;如果不一样,则新的要报警,老报警要关闭 List noChangeListNew = new ArrayList<>(noChangeList);//断点集合[需要新增的] noChangeListNew.removeAll(tXinyiWarningNoChangeMoreRecords); List noChangeListClose = new ArrayList<>(tXinyiWarningNoChangeMoreRecords);//断点集合[需要关闭的] 还有2这重叠的,这种重叠的,是不需要做任何操作的,持续报警 noChangeListClose.removeAll(noChangeList); //插入新的报警 if(!CollectionUtils.isEmpty(noChangeListNew)){ for (TXinyiWarningRecord tXinyiWarningRecord : noChangeListNew) { String category = tXinyiWarningRecord.getCategory(); //判断那些指标不能再次执行 //额外判断当前的异常是哪个指标,并处理标识 if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ csCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ csZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ csZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ csADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ csSSExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ jsZLExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ jsCodExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ jsZDExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ jsADExecute = false; }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ jsSSExecute = false; }else{ log.error("处理是否后续报警的报警类型是不支持的类型"); throw new ServiceException("处理是否后续报警的报警类型是不支持的类型"); } //关闭该指标的其他类型的报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getCode()); //新插入 //原来集合里存放的都是单指标异常 下面2个值需要重新赋值 tXinyiWarningRecord.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getMsg()); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getCode()); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByNoChangeMore(tXinyiWarningRecord, tXinyiIndustry, normConfig); } } //关闭老的报警 if(!CollectionUtils.isEmpty(noChangeListClose)){ for (TXinyiWarningRecord tXinyiWarningRecord : noChangeListClose) { //老的报警,新的没有出现,关闭 closeWarning(tXinyiWarningRecord); } } //2025年03月06日10:56:41 需要额外记录哪些是历史报警,现在仍然报警的,这种的更新部分信息,更新决策内容 List noChangeListContinue = new ArrayList<>(tXinyiWarningRecords); noChangeListContinue.removeAll(noChangeListNew); if(!CollectionUtils.isEmpty(noChangeListContinue)){ for (TXinyiWarningRecord tXinyiWarningRecord : noChangeListContinue) { //2025年03月06日10:52:57 逻辑调整:更新一直报警的那条记录的显示值 //需要匹配新的报警中的最新的值 String category = tXinyiWarningRecord.getCategory(); TXinyiWarningRecord tXinyiWarningRecordContinue = tXinyiWarningRecord;//兜底处理 Optional optional = noChangeListNew.stream().filter(r -> category.equals(r.getCategory())).findAny(); if(optional.isPresent()){ tXinyiWarningRecordContinue = optional.get(); log.info("存在之前多指标连续不变的数据,现在仍然连续不变的数据{}", JSON.toJSONString(tXinyiWarningRecordContinue)); } tXinyiWarningRecord.setWarningVal(tXinyiWarningRecordContinue.getWarningVal()); tXinyiWarningRecord.setTime(tXinyiWarningRecordContinue.getTime()); tXinyiWarningRecord.setUpdateTime(nowDate); tXinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); //从单指标变成多指标 这个不可以修改 // tXinyiWarningRecord.setReason(tXinyiWarningRecordContinue.getReason()); //更新数据库 this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(tXinyiWarningRecord); //继续调用决策【本地模拟的决策】 addChatRecordByNoChangeMore(tXinyiWarningRecord, tXinyiIndustry, normConfig); } } } //如果出现多指标问题,后续的报警不再处理 // return; //2025年03月03日16:07:09 不是其他报警都不执行,只是出现异常的问题不再进行报警,其他的还需要再次报警 } //开始走正常的水质报警 + 突变 //2025年02月27日15:33:39 加上校验:此次的检查指标必须是不存在断点且不存在连续不变才执行下面的报警。 //没有断点,且没有连续不变,全部执行 /*if(breakpointCount < 1 && noChange < 1){ handleXinYiWarningsCsOrigin(cscodBzz, csCod, cscodGkz, CS_COD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsCod(), jsslSjz, normConfig.getJscodSjz())); handleXinYiWarningsCsOrigin(cszlBzz, csTp, cszlGkz, BusinessEnum.WarningCategoryEnum.CS_ZL.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTp(), jsslSjz, normConfig.getJszlSjz())); handleXinYiWarningsCsOrigin(cszzBzz, csTn, cszzGkz, BusinessEnum.WarningCategoryEnum.CS_ZD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); handleXinYiWarningsCsOrigin(csadBzz, csNh3, csadGkz, BusinessEnum.WarningCategoryEnum.CS_AD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsNh3(), jsslSjz, normConfig.getJsadSjz())); handleXinYiWarningsCsOrigin(csSSBzz, csSS, csssGkz, BusinessEnum.WarningCategoryEnum.CS_SS.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsSs(), jsslSjz, normConfig.getJsssSjz())); handleXinYiWarningRecordJSOrigin(jszlSjz, jsTp, BusinessEnum.WarningCategoryEnum.JS_ZL.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTp(), jsslSjz, normConfig.getJszlSjz())); handleXinYiWarningRecordJSOrigin(jscodSjz, jsCod, BusinessEnum.WarningCategoryEnum.JS_COD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsCod(), jsslSjz, normConfig.getJscodSjz())); handleXinYiWarningRecordJSOrigin(jszdSjz, jsTn, BusinessEnum.WarningCategoryEnum.JS_ZD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); handleXinYiWarningRecordJSOrigin(jsadSjz, jsNh3, BusinessEnum.WarningCategoryEnum.JS_AD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsNh3(), jsslSjz, normConfig.getJsadSjz())); handleXinYiWarningRecordJSOrigin(jsSSSjz, jsSS, BusinessEnum.WarningCategoryEnum.JS_SS.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsSs(), jsslSjz, normConfig.getJsssSjz())); }*/ //如果只有单一的报警,只有该指标不再进行报警,其他的指标还是要报警的 /*if(breakpointCount == 1 && noChange == 0){//只有断点 } if(breakpointCount == 0 && noChange == 1){//只有连续不变 } if(breakpointCount == 1 && noChange == 1){//既有断点,又有连续不变 【可能是相同的指标,也可能是不同的指标】 }*/ //综合上面3中情况,断点和连续不变的,2个报警类型至少有一个报警,且只能有一个指标报警 //上述逻辑存在bug:如果是不同的指标 比如出水cod断点 出水ss连续不变 则无法处理。 所以决定进出水的指标是否报警,需要每个知道都要单独记录,只要存在异常项就不能再走 异常升高/偏低/普通的报警了 //后续的指标是否往下进行,用新的逻辑: if(csCodExecute && !Objects.isNull(cscodBzz) && cscodBzz.compareTo(BigDecimal.ZERO) > 0 && !Objects.isNull(cscodGkz) && cscodGkz.compareTo(BigDecimal.ZERO) > 0) handleXinYiWarningsCsOrigin(cscodBzz, csCod, cscodGkz, CS_COD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsCod(), jsslSjz, normConfig.getJscodSjz())); if(csZLExecute && !Objects.isNull(cszlBzz) && cszlBzz.compareTo(BigDecimal.ZERO) > 0 && !Objects.isNull(cszlGkz) && cszlGkz.compareTo(BigDecimal.ZERO) > 0) handleXinYiWarningsCsOrigin(cszlBzz, csTp, cszlGkz, BusinessEnum.WarningCategoryEnum.CS_ZL.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTp(), jsslSjz, normConfig.getJszlSjz())); if(csZDExecute && !Objects.isNull(cszzBzz) && cszzBzz.compareTo(BigDecimal.ZERO) > 0 && !Objects.isNull(cszzGkz) && cszzGkz.compareTo(BigDecimal.ZERO) > 0) handleXinYiWarningsCsOrigin(cszzBzz, csTn, cszzGkz, BusinessEnum.WarningCategoryEnum.CS_ZD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); if(csADExecute && !Objects.isNull(csadBzz) && csadBzz.compareTo(BigDecimal.ZERO) > 0 && !Objects.isNull(csadGkz) && csadGkz.compareTo(BigDecimal.ZERO) > 0) handleXinYiWarningsCsOrigin(csadBzz, csNh3, csadGkz, BusinessEnum.WarningCategoryEnum.CS_AD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsNh3(), jsslSjz, normConfig.getJsadSjz())); if(csSSExecute && !Objects.isNull(csSSBzz) && csSSBzz.compareTo(BigDecimal.ZERO) > 0 && !Objects.isNull(csssGkz) && csssGkz.compareTo(BigDecimal.ZERO) > 0) handleXinYiWarningsCsOrigin(csSSBzz, csSS, csssGkz, BusinessEnum.WarningCategoryEnum.CS_SS.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsSs(), jsslSjz, normConfig.getJsssSjz())); if(jsZLExecute && !Objects.isNull(jszlSjz) && jszlSjz.compareTo(BigDecimal.ZERO) > 0) handleXinYiWarningRecordJSOrigin(jszlSjz, jsTp, BusinessEnum.WarningCategoryEnum.JS_ZL.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTp(), jsslSjz, normConfig.getJszlSjz())); if(jsCodExecute && !Objects.isNull(jscodSjz) && jscodSjz.compareTo(BigDecimal.ZERO) > 0) handleXinYiWarningRecordJSOrigin(jscodSjz, jsCod, BusinessEnum.WarningCategoryEnum.JS_COD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsCod(), jsslSjz, normConfig.getJscodSjz())); if(jsZDExecute && !Objects.isNull(jszdSjz) && jszdSjz.compareTo(BigDecimal.ZERO) > 0) handleXinYiWarningRecordJSOrigin(jszdSjz, jsTn, BusinessEnum.WarningCategoryEnum.JS_ZD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); if(jsADExecute && !Objects.isNull(jsadSjz) && jsadSjz.compareTo(BigDecimal.ZERO) > 0) handleXinYiWarningRecordJSOrigin(jsadSjz, jsNh3, BusinessEnum.WarningCategoryEnum.JS_AD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsNh3(), jsslSjz, normConfig.getJsadSjz())); if(jsSSExecute && !Objects.isNull(jsSSSjz) && jsSSSjz.compareTo(BigDecimal.ZERO) > 0) handleXinYiWarningRecordJSOrigin(jsSSSjz, jsSS, BusinessEnum.WarningCategoryEnum.JS_SS.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsSs(), jsslSjz, normConfig.getJsssSjz())); } 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()); } //如果是机器人化验室的报警,需要把总磷和总氮,获取化验室对应的数据且计算 //2024年08月20日15:16:16 化验室的报警和工业库传参一样 新增了4个参数额外标记化验室数据 /*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)); } } }*/ } } // 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(); }*/ //2024年08月25日15:40:31 处理数据映射,改成字母,但是显示的还是中文 category = this.parseCategory(category); 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(); } } private String parseCategory(String category) { switch (category) { case "进水COD" : return "js_cod"; case "进水总磷" : return "js_tp"; case "进水总氮" : return "js_tn"; case "进水氨氮" : return "js_andan"; case "进水SS" : return "js_ss"; case "出水COD" : return "cs_cod"; case "出水总磷" : return "cs_tp"; case "出水总氮" : return "cs_tn"; case "出水氨氮" : return "cs_andan"; case "出水SS" : return "cs_ss"; case "#1好氧硝酸盐" : return "cs_tn_lxjc1"; case "#2好氧硝酸盐" : return "cs_tn_lxjc2"; case "出水氨氮连续检测" : return "cs_andan_lxjc1"; case "二沉池正磷酸盐" : return "cs_tp_lxjc"; default: throw new ServiceException("暂时不支持的类型"); } } /** * 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(); //2025年02月21日17:09:29 因为报警时间改过一次逻辑,以前是最开始的那个时候,后来每次报警都更新它,所以这里需要的是创建时间 Date warningTime = tXinyiWarningRecord.getCreateTime(); String remark = tXinyiWarningRecord.getRemark(); //2025年02月26日16:17:10 这里计算的截止时间可能是当前时间,也可能是报警结束时间,需要判断 Date endDate = null; //判断类型 如果结束了 截止时间就是告警截止时间; 如果正在报警 截止时间就是当前时间 if(0 == tXinyiWarningRecord.getStatus() || 3 == tXinyiWarningRecord.getStatus()) endDate = DateUtils.getNowDate(); else endDate = tXinyiWarningRecord.getOffTime(); long count = DateUtils.differentHoursByLocalDateTime(warningTime, endDate) + 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.setF(tXinyiWarningRecord.getSymbolDesc()); showValueSHBasic.setH("计算"); //通用的 // showValueBasic.setA(tXinyiWarningRecord.getReason()); showValueSHBasic.setB(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, tXinyiWarningRecord.getTime())); showValueSHBasic.setC(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getWarningVal(), INT_2) + unit); showValueSHBasic.setD(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getDesignVal(), INT_2) + unit); showValueSHBasic.setG(count > MAX_COUNT ? MAX_COUNT_STR : String.valueOf(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(); //2025年02月21日17:09:29 因为报警时间改过一次逻辑,以前是最开始的那个时候,后来每次报警都更新它,所以这里需要的是创建时间 Date warningTime = tXinyiWarningRecord.getCreateTime(); String remark = tXinyiWarningRecord.getRemark(); //2025年02月26日16:17:10 这里计算的截止时间可能是当前时间,也可能是报警结束时间,需要判断 Date endDate = null; //判断类型 如果结束了 截止时间就是告警截止时间; 如果正在报警 截止时间就是当前时间 if(0 == tXinyiWarningRecord.getStatus() || 3 == tXinyiWarningRecord.getStatus()) endDate = DateUtils.getNowDate(); else endDate = tXinyiWarningRecord.getOffTime(); long count = DateUtils.differentHoursByLocalDateTime(warningTime, endDate) + 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("报警次数", count > MAX_COUNT ? MAX_COUNT_STR : 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) || ROBOT_CS_AD.getCode().equalsIgnoreCase(category)){//出水的展示 ShowValueCSBasic showValueCSBasic = new ShowValueCSBasic(); if(ZERO_SZ_WARNING.getCode().equals(remark)){//水质报警 showValueCSBasic.setH(ZAIXIANYIBIAO); // showValueCSBasic.setF(tXinyiWarningRecord.getLevel()); showValueCSBasic.setF(tXinyiWarningRecord.getSymbolDesc()); }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()); showValueCSBasic.setF(tXinyiWarningRecord.getSymbolDesc()); } //通用的 // 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(count > MAX_COUNT ? MAX_COUNT_STR : String.valueOf(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()); showValueJSBasic.setF(tXinyiWarningRecord.getSymbolDesc()); }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()); showValueJSBasic.setF(tXinyiWarningRecord.getSymbolDesc()); } //通用的 // showValueBasic.setA(tXinyiWarningRecord.getReason()); showValueJSBasic.setB(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM ,tXinyiWarningRecord.getTime())); showValueJSBasic.setC(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getWarningVal(), INT_2)); showValueJSBasic.setE(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getDesignVal(), INT_2)); showValueJSBasic.setG(count > MAX_COUNT ? MAX_COUNT_STR : String.valueOf(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 currentVal * @param category * 2025年02月20日11:15:05 返回map 分别是是否断点 是否连续不变 * @return */ private WarningMoreExceed handleXinYiWarningsCsMore(BigDecimal csBzz, BigDecimal currentVal, BigDecimal csGkz, String category, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, BigDecimal cwrwfhz) { WarningMoreExceed warningMoreExceed = new WarningMoreExceed(); boolean breakpoint = false; boolean noChange = false; List tXinyiIndustries = this.xinyiIndustryMapper.selectNIndustry(INT_3); if(CollectionUtils.isEmpty(tXinyiIndustries) || tXinyiIndustries.size() < 3){ log.error("处理生化报警时,获取最近的3条工业库数据失败~~~~~~~"); return new WarningMoreExceed(); } TXinyiIndustry tXinyiIndustry1 = tXinyiIndustries.get(INDEX_1);//前一个小时 //2025年02月20日14:17:29 在这里处理额外的其他报警项 //该类型的断点历史报警 Date nowDate = DateUtils.getNowDate(); //是否存在断点 if(!Objects.isNull(tXinyiIndustry1)){ if(existsBreakPoints(currentVal, category, tXinyiIndustry1)){ //关闭同类型的其他报警 //2025年02月25日14:45:09 不用在此关闭,因为在后续处理的时候,判断是单一报警还是多指标表报警的时候,都做了对应的关闭。 // closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()); breakpoint = true; //插入该类型报警 TXinyiWarningRecord warningRecord = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()).status(0).build(); warningRecord.setTime(nowDate); warningRecord.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getMsg()); warningRecord.setWaterType(BusinessEnum.WaterTypeEnum.CS.getCode()); warningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()); warningRecord.setCreateBy(WARNING_DEFAULT_CREATE); warningRecord.setCreateTime(nowDate); warningRecord.setWarningVal(currentVal); warningRecord.setDesignVal(csBzz); warningRecord.setControlVal(csGkz); warningRecord.setCwrwfhz(cwrwfhz); warningRecord.setRemark(ZERO_SZ_WARNING.getCode()); warningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, false));//根据当前值和类型以及是否超标处理 //存放起来 warningMoreExceed.setBreakPointWarningRecord(warningRecord); //这里不报警 需要根据优先级报警 // this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecord); //同时处理决策 不用调用大模型,本地处理问答 // addChatRecordByBreakPointsSingle(warningRecord, tXinyiIndustry, normConfig, category); } } //是否存在连续不变 if(!CollectionUtils.isEmpty(tXinyiIndustries) && tXinyiIndustries.size() == INT_3){ //2025年02月21日14:20:41 这里要改成当前值和上个小时比较 上个小时和上上个小时比较 if(existsNoChange(currentVal, category, tXinyiIndustries)){ //关闭同类型的其他报警 //2025年02月25日14:45:09 不用在此关闭,因为在后续处理的时候,判断是单一报警还是多指标表报警的时候,都做了对应的关闭。 // closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getCode()); noChange = true; //触发报警 并且模拟大模型返回决策问答数据 //插入该类型报警 //该类型的连续不变报警 TXinyiWarningRecord warningRecordNoChangeSingle = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getCode()).status(0).build(); warningRecordNoChangeSingle.setTime(nowDate); warningRecordNoChangeSingle.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getMsg()); warningRecordNoChangeSingle.setWaterType(BusinessEnum.WaterTypeEnum.CS.getCode()); warningRecordNoChangeSingle.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getCode()); warningRecordNoChangeSingle.setCreateBy(WARNING_DEFAULT_CREATE); warningRecordNoChangeSingle.setCreateTime(nowDate); warningRecordNoChangeSingle.setWarningVal(currentVal); warningRecordNoChangeSingle.setDesignVal(csBzz); warningRecordNoChangeSingle.setControlVal(csGkz); warningRecordNoChangeSingle.setCwrwfhz(cwrwfhz); warningRecordNoChangeSingle.setRemark(ZERO_SZ_WARNING.getCode()); warningRecordNoChangeSingle.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, false));//根据当前值和类型以及是否超标处理 //存放起来 warningMoreExceed.setNoChangeWarningRecord(warningRecordNoChangeSingle); // // this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordNoChangeSingle); // //同时处理决策 不用调用大模型,本地处理问答 // addChatRecordByNoChangeSingle(warningRecordNoChangeSingle, tXinyiIndustry, normConfig, category); } } //是否连续不变 warningMoreExceed.setBreakpoint(breakpoint); warningMoreExceed.setNoChange(noChange); return warningMoreExceed; } /** * 通过输入的值 生成对应类型的报警对象(出水) * * @param csBzz * @param currentVal * @param csGkz * @param category * @param tXinyiIndustry * @param normConfig * @param cwrwfhz * 2025年02月20日11:15:05 返回map 分别是是否断点 是否连续不变 * @return */ private void handleXinYiWarningsCsOrigin(BigDecimal csBzz, BigDecimal currentVal, BigDecimal csGkz, String category, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, BigDecimal cwrwfhz) { Date nowDate = DateUtils.getNowDate(); List tXinyiIndustries = this.xinyiIndustryMapper.selectNIndustry(INT_3); TXinyiIndustry tXinyiIndustry1 = null; if(CollectionUtils.isEmpty(tXinyiIndustries) || tXinyiIndustries.size() < 3){ log.error("处理生化报警时,获取最近的3条工业库数据失败~~~~~~~"); return ; } tXinyiIndustry1 = tXinyiIndustries.get(INDEX_1);//前一个小时 //单点突变-异常升高报警 TXinyiWarningRecord warningRecordYCSG = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getCode()).status(0).build(); List tXinyiNoChangeYCSGRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecordYCSG); //是否存在异常升高的问题 if(!CollectionUtils.isEmpty(tXinyiIndustries) && tXinyiIndustries.size() == INT_3){ //2025年02月21日14:33:37 这里要改成当前值和上个小时比较 上个小时和上上个小时比较 BigDecimal exceedVal = existsYCSG(currentVal, category, tXinyiIndustries); if(!Objects.isNull(exceedVal)){//这里不能只返回一个布尔类型的结果,因为还要获取百分比的值 //关闭同类型的其他报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getCode()); //触发报警 并且模拟大模型返回决策问答数据 if(CollectionUtils.isEmpty(tXinyiNoChangeYCSGRecords)){ //插入该类型报警 warningRecordYCSG.setTime(nowDate); warningRecordYCSG.setReason(category + BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getMsg()); warningRecordYCSG.setWaterType(BusinessEnum.WaterTypeEnum.CS.getCode()); warningRecordYCSG.setSymbol(BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getCode()); warningRecordYCSG.setCreateBy(WARNING_DEFAULT_CREATE); warningRecordYCSG.setCreateTime(nowDate); warningRecordYCSG.setWarningVal(currentVal); warningRecordYCSG.setDesignVal(csBzz); warningRecordYCSG.setControlVal(csGkz); warningRecordYCSG.setRemark(ZERO_SZ_WARNING.getCode()); warningRecordYCSG.setCwrwfhz(cwrwfhz); warningRecordYCSG.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, true));//根据当前值和类型以及是否超标处理 this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordYCSG); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByYCSG(warningRecordYCSG, tXinyiIndustry, normConfig, category, exceedVal); }else{ log.info("工业库报警的时候,发现存在异常升高的报警,并且已经有该类型报警了,不做任何处理"); } log.info("工业库报警的时候,发现存在{}异常升高的报警,后续同指标报警不再处理", category); return; }else{//不存在 查看历史是否有报警,有的话关闭 if(!CollectionUtils.isEmpty(tXinyiNoChangeYCSGRecords)){ closeWarning(tXinyiNoChangeYCSGRecords.get(0)); } } } //单点突变-异常偏低报警 //2025年03月03日15:00:55 异常偏低的报警暂时不需要了 // TXinyiWarningRecord warningRecordYCPD = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getCode()).status(0).build(); // List tXinyiNoChangeYCPDRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecordYCPD); // //是否存在异常偏低的问题 // if(!Objects.isNull(tXinyiIndustry1)){ // //2025年02月21日15:05:41 这里只需要比较当前值和标准值的差 以及上个小时的值和标准值的差 所以不用取最近3个小时的 // BigDecimal exceedVal = existsYCPD(currentVal, category, tXinyiIndustry1, csBzz); // if(!Objects.isNull(exceedVal)){//这里不能只返回一个布尔类型的结果,因为还要获取百分比的值 // //关闭同类型的其他报警 // closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getCode()); // //触发报警 并且模拟大模型返回决策问答数据 // if(CollectionUtils.isEmpty(tXinyiNoChangeYCPDRecords)){ // //插入该类型报警 // warningRecordYCPD.setType(0); // warningRecordYCPD.setCategory(category); // warningRecordYCPD.setTime(nowDate); // warningRecordYCPD.setReason(category + BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getMsg()); // warningRecordYCPD.setWaterType(BusinessEnum.WaterTypeEnum.CS.getCode()); // warningRecordYCPD.setSymbol(BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getCode()); // warningRecordYCPD.setCreateBy(WARNING_DEFAULT_CREATE); // warningRecordYCPD.setCreateTime(nowDate); // warningRecordYCPD.setWarningVal(currentVal); // this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordYCPD); // //同时处理决策 不用调用大模型,本地处理问答 // addChatRecordByYCPD(warningRecordYCPD, tXinyiIndustry, normConfig, category, exceedVal); // }else{ // log.info("工业库报警的时候,发现存在异常偏低的报警,并且已经有该类型报警了,不做任何处理"); // } // log.info("工业库报警的时候,发现存在{}异常偏低的报警,后续同指标报警不再处理", category); // return; // }else{//不存在 查看历史是否有报警,有的话关闭 // if(!CollectionUtils.isEmpty(tXinyiNoChangeYCPDRecords)){ // closeWarning(tXinyiNoChangeYCPDRecords.get(0)); // } // } // } //下面是最原始的处理 超标准 超管控报警 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()); //2025年02月10日14:45:08 下面是新增加的字段 tXinyiWarningRecord.setWaterType(BusinessEnum.WaterTypeEnum.CS.getCode()); //超污染物限制:计算公式为:当前氨氮/氨氮设计值 或者 当前氨氮/氨氮管控值(智能工单使用) 这里是出水的 【需要根据超标还是超管控,具体计算】 //超污染物负荷值:计算公式为:当前水量与氨氮乘积 / 设计水量与设计进水氨氮的乘积(智能工单使用) tXinyiWarningRecord.setCwrwfhz(cwrwfhz);//2025年02月14日10:42:53 具体指标具体计算,由上游传过来。 //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); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.CBZZ.getCode()); tXinyiWarningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, true));//根据当前值和类型以及是否超标处理 }else if(currentVal.compareTo(csBzz) >= 0 && currentVal.compareTo(multiply) <= 0){//二级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_TWO); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.CBZZ.getCode()); tXinyiWarningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, true));//根据当前值和类型以及是否超标处理 }else if(!Objects.isNull(csGkz) && currentVal.compareTo(csGkz) > 0){ tXinyiWarningRecord.setReason(category + CHAOGUANKONG_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_THREE); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.CGKZ.getCode()); tXinyiWarningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, false));//根据当前值和类型以及是否超标处理 }else{ tXinyiWarningRecord = null;//这种的无需处理 } //当前状态正常 需要查询历史有无正在报警的数据,如果有,将报警状态改完2(系统自动关闭) List tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(TXinyiWarningRecord.builder().type(0).category(category).status(0).build()); //2024年7月18日16:23:11 新增逻辑,查询是否有连续升高的趋势,如果有才需要报警 if(Objects.isNull(tXinyiWarningRecord)){//数据正常,无告警信息 if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ log.info( "{}:现在恢复正常,历史报警数据为{}", category,JSON.toJSONString(tXinyiWarningRecords)); for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) { xinyiWarningRecord.setStatus(2); xinyiWarningRecord.setOffTime(nowDate); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); } } }else{//有告警信息 if(CollectionUtils.isEmpty(tXinyiWarningRecords)){//之前没有告警记录 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); } } } } } /** * * 超污染物负荷值:计算公式为:当前水量与氨氮乘积 / 设计水量与设计进水氨氮的乘积(智能工单使用) * 因为配置的值都不为0 所以不做校验了 * @param tXinyiIndustry * @param normConfig * @return */ /*@Deprecated private BigDecimal getCwrwfhz(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) { return (tXinyiIndustry.getJsSlq().multiply(tXinyiIndustry.getJsNh3())).divide((normConfig.getJsslSjz().multiply(normConfig.getJsadSjz())), NUMBER_SCALE_4, RoundingMode.HALF_UP); }*/ /** * 2025年02月14日10:26:03 因为超污染物负荷值 要根据具体的指标计算 * @param itemVal * @param jsslSjz * @return */ private BigDecimal getCwrwfhzByDetail(BigDecimal jsSlq, BigDecimal itemVal, BigDecimal jsslSjz, BigDecimal itemConfigVal) { return (jsSlq.multiply(itemVal)).divide((jsslSjz.multiply(itemConfigVal)), NUMBER_SCALE_4, RoundingMode.HALF_UP); } /** * 计算超污染物限制的值: 需要判断进水还是出水;是超标准还是超管控 出水的标准值=进水的设计值 * @param currentVal * @param normConfig * @param code * @param isBzz * @return */ private BigDecimal getCwrwxzByDetail(BigDecimal currentVal, TXinyiNormConfig normConfig, String code, boolean isBzz) { if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(code)){ if(isBzz) return currentVal.divide(normConfig.getCscodBzz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); return currentVal.divide(normConfig.getCscodGkz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(code) || ROBOT_ECCZLSY.getCode().equals(code)){ if(isBzz) return currentVal.divide(normConfig.getCszlBzz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); return currentVal.divide(normConfig.getCszlGkz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(code) || ROBOT_XSY_1.getCode().equals(code) || ROBOT_XSY_2.getCode().equals(code)){ if(isBzz) return currentVal.divide(normConfig.getCszzBzz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); return currentVal.divide(normConfig.getCszzGkz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(code) || ROBOT_CS_AD.getCode().equals(code)){ if(isBzz) return currentVal.divide(normConfig.getCsadBzz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); return currentVal.divide(normConfig.getCsadGkz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(code)){ if(isBzz) return currentVal.divide(normConfig.getCsssBzz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); return currentVal.divide(normConfig.getCsssGkz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(code)){ return currentVal.divide(normConfig.getJszlSjz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(code)){ return currentVal.divide(normConfig.getJscodSjz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(code)){ return currentVal.divide(normConfig.getJszdSjz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(code)){ return currentVal.divide(normConfig.getJsadSjz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(code)){ return currentVal.divide(normConfig.getJsssSjz(), NUMBER_SCALE_4, RoundingMode.HALF_UP); }else{ log.error("暂时不支持的类型,返回null"); return null; } } /** * [工业库]通过输入的值 生成对应类型的报警对象(进水) * * @param currentVal * @param category * @return */ private WarningMoreExceed handleXinYiWarningRecordJSMore(BigDecimal jsBzz, BigDecimal currentVal, String category, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, BigDecimal cwrwfhz) { WarningMoreExceed warningMoreExceed = new WarningMoreExceed(); boolean breakpoint = false; boolean noChange = false; List tXinyiIndustries = this.xinyiIndustryMapper.selectNIndustry(INT_3); if(CollectionUtils.isEmpty(tXinyiIndustries) || tXinyiIndustries.size() < 3){ log.error("处理生化报警时,获取最近的3条工业库数据失败~~~~~~~"); return new WarningMoreExceed(); } TXinyiIndustry tXinyiIndustry1 = tXinyiIndustries.get(INDEX_1);//前一个小时 //2025年02月21日10:32:42 在这里处理额外的其他报警项 //该类型的断点历史报警 TXinyiWarningRecord warningRecord = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()).status(0).build(); Date nowDate = DateUtils.getNowDate(); //是否存在断点 if(!Objects.isNull(tXinyiIndustry1)){ if(existsBreakPoints(currentVal, category, tXinyiIndustry1)){ //关闭同类型的其他报警 //2025年02月25日14:45:09 不用在此关闭,因为在后续处理的时候,判断是单一报警还是多指标表报警的时候,都做了对应的关闭。 // closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()); breakpoint = true; //触发报警 并且模拟大模型返回决策问答数据 //插入该类型报警 warningRecord.setTime(nowDate); warningRecord.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getMsg()); warningRecord.setWaterType(BusinessEnum.WaterTypeEnum.JS.getCode()); warningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()); warningRecord.setCreateBy(WARNING_DEFAULT_CREATE); warningRecord.setCreateTime(nowDate); warningRecord.setWarningVal(currentVal); warningRecord.setDesignVal(jsBzz); warningRecord.setRemark(ZERO_SZ_WARNING.getCode()); warningRecord.setCwrwfhz(cwrwfhz); warningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, true));//根据当前值和类型以及是否超标处理 //存起来 warningMoreExceed.setBreakPointWarningRecord(warningRecord); // this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecord); //同时处理决策 不用调用大模型,本地处理问答 // addChatRecordByBreakPointsSingle(warningRecord, tXinyiIndustry, normConfig, category); } } //该类型的连续不变报警 TXinyiWarningRecord warningRecordNoChangeSingle = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getCode()).status(0).build(); //是否存在连续不变的数据 if(!CollectionUtils.isEmpty(tXinyiIndustries) && tXinyiIndustries.size() == INT_3){ //2025年02月21日14:20:41 这里要改成当前值和上个小时比较 上个小时和上上个小时比较 if(existsNoChange(currentVal, category, tXinyiIndustries)){ //关闭同类型的其他报警‘ //2025年02月25日14:45:09 不用在此关闭,因为在后续处理的时候,判断是单一报警还是多指标表报警的时候,都做了对应的关闭。 // closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getCode()); noChange = true; //触发报警 并且模拟大模型返回决策问答数据 //插入该类型报警 warningRecordNoChangeSingle.setType(0); warningRecordNoChangeSingle.setCategory(category); warningRecordNoChangeSingle.setTime(nowDate); warningRecordNoChangeSingle.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getMsg()); warningRecordNoChangeSingle.setWaterType(BusinessEnum.WaterTypeEnum.JS.getCode()); warningRecordNoChangeSingle.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getCode()); warningRecordNoChangeSingle.setCreateBy(WARNING_DEFAULT_CREATE); warningRecordNoChangeSingle.setCreateTime(nowDate); warningRecordNoChangeSingle.setWarningVal(currentVal); warningRecord.setDesignVal(jsBzz); warningRecord.setRemark(ZERO_SZ_WARNING.getCode()); warningRecord.setCwrwfhz(cwrwfhz); warningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, true));//根据当前值和类型以及是否超标处理 //存起来 warningMoreExceed.setNoChangeWarningRecord(warningRecordNoChangeSingle); // this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordNoChangeSingle); //同时处理决策 不用调用大模型,本地处理问答 // addChatRecordByNoChangeSingle(warningRecordNoChangeSingle, tXinyiIndustry, normConfig, category); } } warningMoreExceed.setBreakpoint(breakpoint); warningMoreExceed.setNoChange(noChange); return warningMoreExceed; } /** * [化验室]通过输入的值 生成对应类型的报警对象(进水) * 化验室只有断点报警,没有连续不变报警(因为化验室数据本身就是4-8个小时一轮 是重复的) * @param currentVal * @param category * @return */ private WarningMoreExceed handleXinYiWarningRecordRobotMore(BigDecimal csBzz, BigDecimal currentVal, BigDecimal csGkz, String category, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, BigDecimal cwrwfhz) { WarningMoreExceed warningMoreExceed = new WarningMoreExceed(); boolean breakpoint = false; Date nowDate = DateUtils.getNowDate(); List tXinyiRobots = this.xinyiRobotMapper.selectNRobot(INT_3); if(CollectionUtils.isEmpty(tXinyiRobots) || tXinyiRobots.size() < 3){ log.error("处理连续检测报警时,获取最近的3条化验数据失败~~~~~~~"); return new WarningMoreExceed(); } TXinyiRobot tXinyiRobot1 = tXinyiRobots.get(INDEX_1);//前一个小时 //2025年02月21日10:32:42 在这里处理额外的其他报警项 //该类型的断点历史报警 TXinyiWarningRecord warningRecord = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()).status(0).build(); //是否存在断点 if(!Objects.isNull(tXinyiRobot1)){ if(existsRobotBreakPoints(currentVal, category, tXinyiRobot1)){ //关闭同类型的其他报警 //2025年02月25日14:45:09 不用在此关闭,因为在后续处理的时候,判断是单一报警还是多指标表报警的时候,都做了对应的关闭。 // closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()); breakpoint = true; //触发报警 并且模拟大模型返回决策问答数据 //插入该类型报警 warningRecord.setTime(nowDate); warningRecord.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getMsg()); warningRecord.setWaterType(BusinessEnum.WaterTypeEnum.CS.getCode()); warningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()); warningRecord.setCreateBy(WARNING_DEFAULT_CREATE); warningRecord.setCreateTime(nowDate); warningRecord.setWarningVal(currentVal); warningRecord.setDesignVal(csBzz); warningRecord.setControlVal(csGkz); warningRecord.setRemark(THREE_HYS_WARNING.getCode());//化验室 warningRecord.setCwrwfhz(cwrwfhz);//2025年02月14日10:42:53 具体指标具体计算,由上游传过来。 warningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, false));//根据当前值和类型以及是否超标处理 //存起来 warningMoreExceed.setBreakPointWarningRecord(warningRecord); // this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecord); //同时处理决策 不用调用大模型,本地处理问答 // addChatRecordByBreakPointsSingle(warningRecord, tXinyiIndustry, normConfig, category); } } warningMoreExceed.setBreakpoint(breakpoint); return warningMoreExceed; } /** * 通过输入的值 生成对应类型的报警对象(进水) * * @param jsBzz * @param currentVal * @param category * @param tXinyiIndustry * @param normConfig * @param cwrwfhz * @return */ private void handleXinYiWarningRecordJSOrigin(BigDecimal jsBzz, BigDecimal currentVal, String category, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, BigDecimal cwrwfhz) { Date nowDate = DateUtils.getNowDate(); List tXinyiIndustries = this.xinyiIndustryMapper.selectNIndustry(INT_3); if(CollectionUtils.isEmpty(tXinyiIndustries) || tXinyiIndustries.size() < 3){ log.error("处理生化报警时,获取最近的3条工业库数据失败~~~~~~~"); return ; } TXinyiIndustry tXinyiIndustry1 = tXinyiIndustries.get(INDEX_1);//前一个小时 //单点突变-异常升高报警 TXinyiWarningRecord warningRecordYCSG = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getCode()).status(0).build(); List tXinyiNoChangeYCSGRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecordYCSG); //是否存在异常升高的问题 if(!CollectionUtils.isEmpty(tXinyiIndustries) && tXinyiIndustries.size() == INT_3){ //2025年02月21日14:33:37 这里要改成当前值和上个小时比较 上个小时和上上个小时比较 BigDecimal exceedVal = existsYCSG(currentVal, category, tXinyiIndustries); if(!Objects.isNull(exceedVal)){//这里不能只返回一个布尔类型的结果,因为还要获取百分比的值 //关闭同类型的其他报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getCode()); //触发报警 并且模拟大模型返回决策问答数据 if(CollectionUtils.isEmpty(tXinyiNoChangeYCSGRecords)){ //插入该类型报警 warningRecordYCSG.setTime(nowDate); warningRecordYCSG.setReason(category + BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getMsg()); warningRecordYCSG.setWaterType(BusinessEnum.WaterTypeEnum.JS.getCode()); warningRecordYCSG.setSymbol(BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getCode()); warningRecordYCSG.setCreateBy(WARNING_DEFAULT_CREATE); warningRecordYCSG.setCreateTime(nowDate); warningRecordYCSG.setWarningVal(currentVal); warningRecordYCSG.setDesignVal(jsBzz); warningRecordYCSG.setRemark(ZERO_SZ_WARNING.getCode()); warningRecordYCSG.setCwrwfhz(cwrwfhz); warningRecordYCSG.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, true));//根据当前值和类型以及是否超标处理 this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordYCSG); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByYCSG(warningRecordYCSG, tXinyiIndustry, normConfig, category, exceedVal); }else{ log.info("工业库报警的时候,发现存在异常升高的报警,并且已经有该类型报警了,不做任何处理"); } //后续的报警不再进行 log.info("工业库报警的时候,发现存在{}异常升高的报警,后续报警不再处理", category); return; }else{//不存在 查看历史是否有报警,有的话关闭 if(!CollectionUtils.isEmpty(tXinyiNoChangeYCSGRecords)){ TXinyiWarningRecord warningRecordExists = tXinyiNoChangeYCSGRecords.get(0); warningRecordExists.setStatus(2); warningRecordExists.setOffTime(nowDate); warningRecordExists.setUpdateTime(nowDate); warningRecordExists.setUpdateBy(WARNING_DEFAULT_CREATE); this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(warningRecordExists); } } } //单点突变-异常偏低报警 //2025年03月03日15:00:55 异常偏低的报警暂时不需要了 // TXinyiWarningRecord warningRecordYCPD = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getCode()).status(0).build(); // List tXinyiNoChangeYCPDRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecordYCPD); // //是否存在异常偏低的问题 // if(!Objects.isNull(tXinyiIndustry1)){ // //2025年02月21日15:05:41 这里只需要比较当前值和标准值的差 以及上个小时的值和标准值的差 所以不用取最近3个小时的 // BigDecimal exceedVal = existsYCPD(currentVal, category, tXinyiIndustry1, jsBzz); // if(!Objects.isNull(exceedVal)){//这里不能只返回一个布尔类型的结果,因为还要获取百分比的值 // //关闭同类型的其他报警 // closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getCode()); // //触发报警 并且模拟大模型返回决策问答数据 // if(CollectionUtils.isEmpty(tXinyiNoChangeYCPDRecords)){ // //插入该类型报警 // warningRecordYCPD.setType(0); // warningRecordYCPD.setCategory(category); // warningRecordYCPD.setTime(nowDate); // warningRecordYCPD.setReason(category + BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getMsg()); // warningRecordYCPD.setWaterType(BusinessEnum.WaterTypeEnum.JS.getCode()); // warningRecordYCPD.setSymbol(BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getCode()); // warningRecordYCPD.setCreateBy(WARNING_DEFAULT_CREATE); // warningRecordYCPD.setCreateTime(nowDate); // warningRecordYCPD.setWarningVal(currentVal); // this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordYCPD); // //同时处理决策 不用调用大模型,本地处理问答 // addChatRecordByYCPD(warningRecordYCPD, tXinyiIndustry, normConfig, category, exceedVal); // }else{ // log.info("工业库报警的时候,发现存在异常偏低的报警,并且已经有该类型报警了,不做任何处理"); // } // //后续的报警不再进行 // return; // }else{//不存在 查看历史是否有报警,有的话关闭 // if(!CollectionUtils.isEmpty(tXinyiNoChangeYCPDRecords)){ // TXinyiWarningRecord warningRecordExists = tXinyiNoChangeYCPDRecords.get(0); // warningRecordExists.setStatus(2); // warningRecordExists.setOffTime(nowDate); // warningRecordExists.setUpdateTime(nowDate); // warningRecordExists.setUpdateBy(WARNING_DEFAULT_CREATE); // this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(warningRecordExists); // } // } // } 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()); //2025年02月10日14:45:08 下面是新增加的字段 tXinyiWarningRecord.setWaterType(BusinessEnum.WaterTypeEnum.JS.getCode()); //超污染物限制:计算公式为:当前氨氮/氨氮设计值 或者 当前氨氮/氨氮管控值(智能工单使用) 这里是出水的 【需要根据超标还是超管控,具体计算】 //超污染物负荷值:计算公式为:当前水量与氨氮乘积 / 设计水量与设计进水氨氮的乘积(智能工单使用) tXinyiWarningRecord.setCwrwfhz(cwrwfhz);//2025年02月14日10:48:32 具体的值由上游传过来 //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); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.CBZZ.getCode()); tXinyiWarningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, true));//根据当前值和类型以及是否超标处理 }else if(currentVal.compareTo(jsBzz) >= 0 && currentVal.compareTo(multiply) <= 0){//二级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_TWO); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.CBZZ.getCode()); tXinyiWarningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, true));//根据当前值和类型以及是否超标处理 }else{ tXinyiWarningRecord = null;//这种的无需处理 } /*else if(!Objects.isNull(csGkz) && currentVal.compareTo(csGkz) > 0){ tXinyiWarningRecord.setReason(category + CHAOGUANKONG_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_THREE); }*/ //最近3条输出 连续升高趋势 和 新增的报警都需要 //当前状态正常 需要查询历史有无正在报警的数据,如果有,将报警状态改完2(系统自动关闭) List tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(TXinyiWarningRecord.builder().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); xinyiWarningRecord.setOffTime(nowDate); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); } } }else{//有告警信息 if(CollectionUtils.isEmpty(tXinyiWarningRecords)){//之前没有告警记录 //2024年7月18日16:23:11 新增逻辑,查询是否有连续升高的趋势,如果有才需要报警 if(CollectionUtils.isEmpty(tXinyiIndustries) || tXinyiIndustries.size() < 3){ log.error("处理生化报警时,获取最近的3条工业库数据失败~~~~~~~"); return ; } 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); } } } } } /** * 先判断该指标计算值是否大于最低阈值,如果超过了,返回对应的超过的值; 如果没有超标,返回null。 * 一个字段返回用作2个地方 * * @param currentVal * @param category * @param tXinyiIndustry1 * @param bzz * @return */ private BigDecimal existsYCPD(BigDecimal currentVal, String category, TXinyiIndustry tXinyiIndustry1, BigDecimal bzz) { BigDecimal result = null;//默认不超标 BigDecimal compareVal = BigDecimal.valueOf(YCPD_VAL_CONF); if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ BigDecimal csCod1 = tXinyiIndustry1.getCsCod(); if(!Objects.isNull(currentVal) && !Objects.isNull(csCod1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(csCod1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ BigDecimal csSs1 = tXinyiIndustry1.getCsSs(); if(!Objects.isNull(currentVal) && !Objects.isNull(csSs1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(csSs1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ BigDecimal csTn1 = tXinyiIndustry1.getCsTn(); if(!Objects.isNull(currentVal) && !Objects.isNull(csTn1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(csTn1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ BigDecimal csTp1 = tXinyiIndustry1.getCsTp(); if(!Objects.isNull(currentVal) && !Objects.isNull(csTp1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(csTp1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ BigDecimal csNh31 = tXinyiIndustry1.getCsNh3(); if(!Objects.isNull(currentVal) && !Objects.isNull(csNh31)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(csNh31).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ BigDecimal jsCod1 = tXinyiIndustry1.getJsCod(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsCod1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(jsCod1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ BigDecimal jsSs1 = tXinyiIndustry1.getJsSs(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsSs1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(jsSs1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ BigDecimal jsTn1 = tXinyiIndustry1.getJsTn(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsTn1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(jsTn1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ BigDecimal jsTp1 = tXinyiIndustry1.getJsTp(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsTp1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(jsTp1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ BigDecimal jsNh31 = tXinyiIndustry1.getJsNh3(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsNh31)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(jsNh31).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else{ log.error("暂时还不支持的报警类型~~~~"); } return result; } /** * * 【工业库异常升高】先判断该指标是否超过最大值,如果超过了,返回对应的超过的值; 如果没有超标,返回null。 * 一个字段返回用作2个地方 * 2025年03月06日10:35:30 判断是否超标,不再获取最近3个小时;最近2个小时比较即可。 * @param currentVal * @param category * @param industryList * @return */ private BigDecimal existsYCSG(BigDecimal currentVal, String category, List industryList) { // BigDecimal result = null;//默认不超标 // TXinyiIndustry tXinyiIndustry1 = industryList.get(INDEX_1); // TXinyiIndustry tXinyiIndustry2 = industryList.get(INDEX_2); // BigDecimal compareVal = BigDecimal.valueOf(YCSG_VAL_CONF); // if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ // BigDecimal csCod1 = tXinyiIndustry1.getCsCod(); // BigDecimal csCod2 = tXinyiIndustry2.getCsCod(); // if(!Objects.isNull(currentVal) && !Objects.isNull(csCod1) && !Objects.isNull(csCod2)){ // BigDecimal divide1 = currentVal.subtract(csCod1).divide(csCod1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = csCod1.subtract(csCod2).divide(csCod2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ // BigDecimal csSs1 = tXinyiIndustry1.getCsSs(); // BigDecimal csSs2 = tXinyiIndustry2.getCsSs(); // if(!Objects.isNull(currentVal) && !Objects.isNull(csSs1) && !Objects.isNull(csSs2)){ // BigDecimal divide1 = currentVal.subtract(csSs1).divide(csSs1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = csSs1.subtract(csSs2).divide(csSs2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ // BigDecimal csTn1 = tXinyiIndustry1.getCsTn(); // BigDecimal csTn2 = tXinyiIndustry2.getCsTn(); // if(!Objects.isNull(currentVal) && !Objects.isNull(csTn1)){ // BigDecimal divide1 = currentVal.subtract(csTn1).divide(csTn1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = csTn1.subtract(csTn2).divide(csTn2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ // BigDecimal csTp1 = tXinyiIndustry1.getCsTp(); // BigDecimal csTp2 = tXinyiIndustry2.getCsTp(); // if(!Objects.isNull(currentVal) && !Objects.isNull(csTp1)){ // BigDecimal divide1 = currentVal.subtract(csTp1).divide(csTp1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = csTp1.subtract(csTp2).divide(csTp2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ // BigDecimal csNh31 = tXinyiIndustry1.getCsNh3(); // BigDecimal csNh32 = tXinyiIndustry2.getCsNh3(); // if(!Objects.isNull(currentVal) && !Objects.isNull(csNh31)){ // BigDecimal divide1 = currentVal.subtract(csNh31).divide(csNh31, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = csNh31.subtract(csNh32).divide(csNh32, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ // BigDecimal jsCod1 = tXinyiIndustry1.getJsCod(); // BigDecimal jsCod2 = tXinyiIndustry2.getJsCod(); // if(!Objects.isNull(currentVal) && !Objects.isNull(jsCod1)){ // BigDecimal divide1 = currentVal.subtract(jsCod1).divide(jsCod1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = jsCod1.subtract(jsCod2).divide(jsCod2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ // BigDecimal jsSs1 = tXinyiIndustry1.getJsSs(); // BigDecimal jsSs2 = tXinyiIndustry2.getJsSs(); // if(!Objects.isNull(currentVal) && !Objects.isNull(jsSs1)){ // BigDecimal divide1 = currentVal.subtract(jsSs1).divide(jsSs1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = jsSs1.subtract(jsSs2).divide(jsSs2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ // BigDecimal jsTn1 = tXinyiIndustry1.getJsTn(); // BigDecimal jsTn2 = tXinyiIndustry2.getJsTn(); // if(!Objects.isNull(currentVal) && !Objects.isNull(jsTn1)){ // BigDecimal divide1 = currentVal.subtract(jsTn1).divide(jsTn1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = jsTn1.subtract(jsTn2).divide(jsTn2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ // BigDecimal jsTp1 = tXinyiIndustry1.getJsTp(); // BigDecimal jsTp2 = tXinyiIndustry2.getJsTp(); // if(!Objects.isNull(currentVal) && !Objects.isNull(jsTp1)){ // BigDecimal divide1 = currentVal.subtract(jsTp1).divide(jsTp1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = jsTp1.subtract(jsTp2).divide(jsTp2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ // BigDecimal jsNh31 = tXinyiIndustry1.getJsNh3(); // BigDecimal jsNh32 = tXinyiIndustry2.getJsNh3(); // if(!Objects.isNull(currentVal) && !Objects.isNull(jsNh31)){ // BigDecimal divide1 = currentVal.subtract(jsNh31).divide(jsNh31, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = jsNh31.subtract(jsNh32).divide(jsNh32, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else{ // log.error("暂时还不支持的报警类型~~~~"); // } // return result; BigDecimal result = null;//默认不超标 TXinyiIndustry tXinyiIndustry1 = industryList.get(INDEX_1); BigDecimal compareVal = BigDecimal.valueOf(YCSG_VAL_CONF); if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ BigDecimal csCod1 = tXinyiIndustry1.getCsCod(); if(!Objects.isNull(currentVal) && !Objects.isNull(csCod1)){ BigDecimal divide1 = currentVal.subtract(csCod1).divide(csCod1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ BigDecimal csSs1 = tXinyiIndustry1.getCsSs(); if(!Objects.isNull(currentVal) && !Objects.isNull(csSs1)){ BigDecimal divide1 = currentVal.subtract(csSs1).divide(csSs1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ BigDecimal csTn1 = tXinyiIndustry1.getCsTn(); if(!Objects.isNull(currentVal) && !Objects.isNull(csTn1)){ BigDecimal divide1 = currentVal.subtract(csTn1).divide(csTn1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ BigDecimal csTp1 = tXinyiIndustry1.getCsTp(); if(!Objects.isNull(currentVal) && !Objects.isNull(csTp1)){ BigDecimal divide1 = currentVal.subtract(csTp1).divide(csTp1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ BigDecimal csNh31 = tXinyiIndustry1.getCsNh3(); if(!Objects.isNull(currentVal) && !Objects.isNull(csNh31)){ BigDecimal divide1 = currentVal.subtract(csNh31).divide(csNh31, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ BigDecimal jsCod1 = tXinyiIndustry1.getJsCod(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsCod1)){ BigDecimal divide1 = currentVal.subtract(jsCod1).divide(jsCod1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ BigDecimal jsSs1 = tXinyiIndustry1.getJsSs(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsSs1)){ BigDecimal divide1 = currentVal.subtract(jsSs1).divide(jsSs1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ BigDecimal jsTn1 = tXinyiIndustry1.getJsTn(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsTn1)){ BigDecimal divide1 = currentVal.subtract(jsTn1).divide(jsTn1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ BigDecimal jsTp1 = tXinyiIndustry1.getJsTp(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsTp1)){ BigDecimal divide1 = currentVal.subtract(jsTp1).divide(jsTp1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ BigDecimal jsNh31 = tXinyiIndustry1.getJsNh3(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsNh31)){ BigDecimal divide1 = currentVal.subtract(jsNh31).divide(jsNh31, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else{ log.error("暂时还不支持的报警类型~~~~"); } return result; } /** * * 【化验室异常升高】先判断该指标是否超过最大值,如果超过了,返回对应的超过的值; 如果没有超标,返回null。 * 一个字段返回用作2个地方 * 2025年03月06日10:40:54 不再用连续2个小时超标,只判断当前值和上个小时的值比较 * @param currentVal * @param category * @param tXinyiRobots * @return */ private BigDecimal existsRobotYCSG(BigDecimal currentVal, String category, List tXinyiRobots) { // BigDecimal result = null;//默认不超标 // TXinyiRobot tXinyiRobot1 = tXinyiRobots.get(INDEX_1); // TXinyiRobot tXinyiRobot2 = tXinyiRobots.get(INDEX_2); // BigDecimal compareVal = BigDecimal.valueOf(YCSG_VAL_CONF); // if(BusinessEnum.WarningCategoryEnum.ROBOT_XSY_1.getCode().equals(category)){ // BigDecimal no3Hlj1Jqr1 = tXinyiRobot1.getNo3Hlj1Jqr(); // BigDecimal no3Hlj1Jqr2 = tXinyiRobot2.getNo3Hlj1Jqr(); // if(!Objects.isNull(currentVal) && !Objects.isNull(no3Hlj1Jqr1) && !Objects.isNull(no3Hlj1Jqr2)){ // BigDecimal divide1 = currentVal.subtract(no3Hlj1Jqr1).divide(no3Hlj1Jqr1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = no3Hlj1Jqr1.subtract(no3Hlj1Jqr2).divide(no3Hlj1Jqr2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.ROBOT_XSY_2.getCode().equals(category)){ // BigDecimal no3Hlj2Jqr1 = tXinyiRobot1.getNo3Hlj2Jqr(); // BigDecimal no3Hlj2Jqr2 = tXinyiRobot2.getNo3Hlj2Jqr(); // if(!Objects.isNull(currentVal) && !Objects.isNull(no3Hlj2Jqr1) && !Objects.isNull(no3Hlj2Jqr2)){ // BigDecimal divide1 = currentVal.subtract(no3Hlj2Jqr1).divide(no3Hlj2Jqr1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = no3Hlj2Jqr1.subtract(no3Hlj2Jqr2).divide(no3Hlj2Jqr2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.ROBOT_ECCZLSY.getCode().equals(category)){ // BigDecimal tpRccJqr1 = tXinyiRobot1.getTpRccJqr(); // BigDecimal tpRccJqr2 = tXinyiRobot2.getTpRccJqr(); // if(!Objects.isNull(currentVal) && !Objects.isNull(tpRccJqr1) && !Objects.isNull(tpRccJqr2)){ // BigDecimal divide1 = currentVal.subtract(tpRccJqr1).divide(tpRccJqr1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = tpRccJqr1.subtract(tpRccJqr2).divide(tpRccJqr2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else if(BusinessEnum.WarningCategoryEnum.ROBOT_CS_AD.getCode().equals(category)){//2025年02月25日16:23:08 合并一个指标:出水氨氮 通过计算获得 // //计算得到对应的值 // //计算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 anDan1 = 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 anDan2 = anDan21.add(anDan22).divide(DECIMAL_2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // // if(!Objects.isNull(currentVal) && !Objects.isNull(anDan1) && !Objects.isNull(anDan2)){ // BigDecimal divide1 = currentVal.subtract(anDan1).divide(anDan1, NUMBER_SCALE_4, RoundingMode.HALF_UP); // BigDecimal divide2 = anDan1.subtract(anDan2).divide(anDan2, NUMBER_SCALE_4, RoundingMode.HALF_UP); // if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) // result = divide1; // } // }else{ // log.error("化验室暂时还不支持的报警类型~~~~"); // } // return result; BigDecimal result = null;//默认不超标 TXinyiRobot tXinyiRobot1 = tXinyiRobots.get(INDEX_1); BigDecimal compareVal = BigDecimal.valueOf(YCSG_VAL_CONF); if(BusinessEnum.WarningCategoryEnum.ROBOT_XSY_1.getCode().equals(category)){ BigDecimal no3Hlj1Jqr1 = tXinyiRobot1.getNo3Hlj1Jqr(); if(!Objects.isNull(currentVal) && !Objects.isNull(no3Hlj1Jqr1)){ BigDecimal divide1 = currentVal.subtract(no3Hlj1Jqr1).divide(no3Hlj1Jqr1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.ROBOT_XSY_2.getCode().equals(category)){ BigDecimal no3Hlj2Jqr1 = tXinyiRobot1.getNo3Hlj2Jqr(); if(!Objects.isNull(currentVal) && !Objects.isNull(no3Hlj2Jqr1) ){ BigDecimal divide1 = currentVal.subtract(no3Hlj2Jqr1).divide(no3Hlj2Jqr1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.ROBOT_ECCZLSY.getCode().equals(category)){ BigDecimal tpRccJqr1 = tXinyiRobot1.getTpRccJqr(); if(!Objects.isNull(currentVal) && !Objects.isNull(tpRccJqr1)){ BigDecimal divide1 = currentVal.subtract(tpRccJqr1).divide(tpRccJqr1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.ROBOT_CS_AD.getCode().equals(category)){//2025年02月25日16:23:08 合并一个指标:出水氨氮 通过计算获得 //计算得到对应的值 //计算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 anDan1 = anDan11.add(anDan12).divide(DECIMAL_2, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(!Objects.isNull(currentVal) && !Objects.isNull(anDan1)){ BigDecimal divide1 = currentVal.subtract(anDan1).divide(anDan1, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0) result = divide1; } }else{ log.error("化验室暂时还不支持的报警类型~~~~"); } return result; } /** * * 【化验室异常偏低】先判断该指标计算值是否大于最低阈值,如果超过了,返回对应的超过的值; 如果没有超标,返回null。 * 一个字段返回用作2个地方 * @param currentVal * @param category * @param tXinyiRobot1 * @param bzz * @return */ private BigDecimal existsRobotYCPD(BigDecimal currentVal, String category, TXinyiRobot tXinyiRobot1, BigDecimal bzz) { BigDecimal result = null;//默认不超标 BigDecimal compareVal = BigDecimal.valueOf(YCPD_VAL_CONF); if(BusinessEnum.WarningCategoryEnum.ROBOT_XSY_1.getCode().equals(category)){ BigDecimal no3Hlj1Jqr1 = tXinyiRobot1.getNo3Hlj1Jqr(); if(!Objects.isNull(currentVal) && !Objects.isNull(no3Hlj1Jqr1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(no3Hlj1Jqr1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.ROBOT_XSY_2.getCode().equals(category)){ BigDecimal no3Hlj2Jqr1 = tXinyiRobot1.getNo3Hlj2Jqr(); if(!Objects.isNull(currentVal) && !Objects.isNull(no3Hlj2Jqr1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(no3Hlj2Jqr1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.ROBOT_ECCZLSY.getCode().equals(category)){ BigDecimal tpRccJqr1 = tXinyiRobot1.getTpRccJqr(); if(!Objects.isNull(currentVal) && !Objects.isNull(tpRccJqr1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(tpRccJqr1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else if(BusinessEnum.WarningCategoryEnum.ROBOT_CS_AD.getCode().equals(category)){//2025年02月25日16:23:08 合并一个指标:出水氨氮 通过计算获得 //计算得到对应的值 //计算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 anDan1 = anDan11.add(anDan12).divide(DECIMAL_2, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(!Objects.isNull(currentVal) && !Objects.isNull(anDan1)){ BigDecimal divide1 = bzz.subtract(currentVal).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); BigDecimal divide2 = bzz.subtract(anDan1).divide(bzz, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(divide1.compareTo(compareVal) > 0 && divide2.compareTo(compareVal) > 0) result = divide1; } }else{ log.error("化验室暂时还不支持的报警类型~~~~"); } return result; } /** * * 判断当前时间和上个时间段的值是否存在连续不变 * @param currentVal * @param category * @param industryList * @return */ private boolean existsNoChange(BigDecimal currentVal, String category, List industryList) { boolean result = false;//默认不超标 TXinyiIndustry tXinyiIndustry1 = industryList.get(INDEX_1); TXinyiIndustry tXinyiIndustry2 = industryList.get(INDEX_2); if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ BigDecimal csCod1 = tXinyiIndustry1.getCsCod(); BigDecimal csCod2 = tXinyiIndustry2.getCsCod(); if(!Objects.isNull(currentVal) && !Objects.isNull(csCod1) && currentVal.compareTo(csCod1) == 0 && !Objects.isNull(csCod2) && currentVal.compareTo(csCod2) == 0) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ BigDecimal csSs1 = tXinyiIndustry1.getCsSs(); BigDecimal csSs2 = tXinyiIndustry2.getCsSs(); if(!Objects.isNull(currentVal) && !Objects.isNull(csSs1) && currentVal.compareTo(csSs1) == 0 && !Objects.isNull(csSs2) && currentVal.compareTo(csSs2) == 0) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ BigDecimal csTn1 = tXinyiIndustry1.getCsTn(); BigDecimal csTn2 = tXinyiIndustry2.getCsTn(); if(!Objects.isNull(currentVal) && !Objects.isNull(csTn1) && currentVal.compareTo(csTn1) == 0 && !Objects.isNull(csTn2) && currentVal.compareTo(csTn2) == 0) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ BigDecimal csTp1 = tXinyiIndustry1.getCsTp(); BigDecimal csTp2 = tXinyiIndustry2.getCsTp(); if(!Objects.isNull(currentVal) && !Objects.isNull(csTp1) && currentVal.compareTo(csTp1) == 0 && !Objects.isNull(csTp2) && currentVal.compareTo(csTp2) == 0) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ BigDecimal csNh31 = tXinyiIndustry1.getCsNh3(); BigDecimal csNh32 = tXinyiIndustry2.getCsNh3(); if(!Objects.isNull(currentVal) && !Objects.isNull(csNh31) && currentVal.compareTo(csNh31) == 0 && !Objects.isNull(csNh32) && currentVal.compareTo(csNh32) == 0) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ BigDecimal jsCod1 = tXinyiIndustry1.getJsCod(); BigDecimal jsCod2 = tXinyiIndustry2.getJsCod(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsCod1) && currentVal.compareTo(jsCod1) == 0 && !Objects.isNull(jsCod2) && currentVal.compareTo(jsCod2) == 0) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ BigDecimal jsSs1 = tXinyiIndustry1.getJsSs(); BigDecimal jsSs2 = tXinyiIndustry2.getJsSs(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsSs1) && currentVal.compareTo(jsSs1) == 0 && !Objects.isNull(jsSs2) && currentVal.compareTo(jsSs2) == 0) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ BigDecimal jsTn1 = tXinyiIndustry1.getJsTn(); BigDecimal jsTn2 = tXinyiIndustry2.getJsTn(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsTn1) && currentVal.compareTo(jsTn1) == 0 && !Objects.isNull(jsTn2) && currentVal.compareTo(jsTn2) == 0) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ BigDecimal jsTp1 = tXinyiIndustry1.getJsTp(); BigDecimal jsTp2 = tXinyiIndustry2.getJsTp(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsTp1) && currentVal.compareTo(jsTp1) == 0 && !Objects.isNull(jsTp2) && currentVal.compareTo(jsTp2) == 0) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ BigDecimal jsNh31 = tXinyiIndustry1.getJsNh3(); BigDecimal jsNh32 = tXinyiIndustry2.getJsNh3(); if(!Objects.isNull(currentVal) && !Objects.isNull(jsNh31) && currentVal.compareTo(jsNh31) == 0 && !Objects.isNull(jsNh32) && currentVal.compareTo(jsNh32) == 0) result = true; }else{ log.error("暂时还不支持的报警类型~~~~"); } return result; } /** * * 判断当前时间和上个时间段的值是否存在断点 * @param currentVal * @param category * @param tXinyiIndustry1 * @return */ private boolean existsBreakPoints(BigDecimal currentVal, String category, TXinyiIndustry tXinyiIndustry1) { boolean result = false;//默认不超标 boolean currentBreakpoint = Objects.isNull(currentVal) || BigDecimal.ZERO.compareTo(currentVal) == 0; if(BusinessEnum.WarningCategoryEnum.CS_COD.getCode().equals(category)){ BigDecimal csCod1 = tXinyiIndustry1.getCsCod(); if(currentBreakpoint && (Objects.isNull(csCod1) || BigDecimal.ZERO.compareTo(csCod1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_SS.getCode().equals(category)){ BigDecimal csSs1 = tXinyiIndustry1.getCsSs(); if(currentBreakpoint && (Objects.isNull(csSs1) || BigDecimal.ZERO.compareTo(csSs1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_ZD.getCode().equals(category)){ BigDecimal csTn1 = tXinyiIndustry1.getCsTn(); if(currentBreakpoint && (Objects.isNull(csTn1) || BigDecimal.ZERO.compareTo(csTn1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_ZL.getCode().equals(category)){ BigDecimal csTp1 = tXinyiIndustry1.getCsTp(); if(currentBreakpoint && (Objects.isNull(csTp1) || BigDecimal.ZERO.compareTo(csTp1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.CS_AD.getCode().equals(category)){ BigDecimal csNh31 = tXinyiIndustry1.getCsNh3(); if(currentBreakpoint && (Objects.isNull(csNh31) || BigDecimal.ZERO.compareTo(csNh31) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_COD.getCode().equals(category)){ BigDecimal jsCod1 = tXinyiIndustry1.getJsCod(); if(currentBreakpoint && (Objects.isNull(jsCod1) || BigDecimal.ZERO.compareTo(jsCod1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_SS.getCode().equals(category)){ BigDecimal jsSs1 = tXinyiIndustry1.getJsSs(); if(currentBreakpoint && (Objects.isNull(jsSs1) || BigDecimal.ZERO.compareTo(jsSs1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_ZD.getCode().equals(category)){ BigDecimal jsTn1 = tXinyiIndustry1.getJsTn(); if(currentBreakpoint && (Objects.isNull(jsTn1) || BigDecimal.ZERO.compareTo(jsTn1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_ZL.getCode().equals(category)){ BigDecimal jsTp1 = tXinyiIndustry1.getJsTp(); if(currentBreakpoint && (Objects.isNull(jsTp1) || BigDecimal.ZERO.compareTo(jsTp1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.JS_AD.getCode().equals(category)){ BigDecimal jsNh31 = tXinyiIndustry1.getJsNh3(); if(currentBreakpoint && (Objects.isNull(jsNh31) || BigDecimal.ZERO.compareTo(jsNh31) == 0)) result = true; }else{ log.error("暂时还不支持的报警类型~~~~"); } return result; } /** * * 判断当前时间和上个时间段的值是否存在断点 * @param currentVal * @param category * @param tXinyiRobot1 * @return */ private boolean existsRobotBreakPoints(BigDecimal currentVal, String category, TXinyiRobot tXinyiRobot1) { boolean result = false;//默认不超标 boolean currentBreakpoint = Objects.isNull(currentVal) || BigDecimal.ZERO.compareTo(currentVal) == 0; if(BusinessEnum.WarningCategoryEnum.ROBOT_XSY_1.getCode().equals(category)){ BigDecimal no3Hlj1Jqr1 = tXinyiRobot1.getNo3Hlj1Jqr(); if(currentBreakpoint && (Objects.isNull(no3Hlj1Jqr1) || BigDecimal.ZERO.compareTo(no3Hlj1Jqr1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.ROBOT_XSY_2.getCode().equals(category)){ BigDecimal no3Hlj2Jqr1 = tXinyiRobot1.getNo3Hlj2Jqr(); if(currentBreakpoint && (Objects.isNull(no3Hlj2Jqr1) || BigDecimal.ZERO.compareTo(no3Hlj2Jqr1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.ROBOT_ECCZLSY.getCode().equals(category)){ BigDecimal tpRccJqr1 = tXinyiRobot1.getTpRccJqr(); if(currentBreakpoint && (Objects.isNull(tpRccJqr1) || BigDecimal.ZERO.compareTo(tpRccJqr1) == 0)) result = true; }else if(BusinessEnum.WarningCategoryEnum.ROBOT_CS_AD.getCode().equals(category)){//2025年02月25日16:23:08 合并一个指标:出水氨氮 通过计算获得 //计算得到对应的值 //计算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 anDan1 = anDan11.add(anDan12).divide(DECIMAL_2, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(currentBreakpoint && (Objects.isNull(anDan1) || BigDecimal.ZERO.compareTo(anDan1) == 0)) result = true; }else{ log.error("化验室暂时还不支持的报警类型~~~~"); } return result; } 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); } private void addChatRecordByYCPD(TXinyiWarningRecord warningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, String category, BigDecimal exceedVal) { 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(warningRecord, tXinyiIndustry, normConfig, DateUtils.getNowDate()); chatReq.setShowVal(showVal);//前端展示的数据和提问的数据不一致 chatReq.setQuestion(BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getMsg());//本地问题 chatReq.setAnswer(category + YCPD_ANSWER_ONE + exceedVal.multiply(BigDecimal_100) + "%" + YCPD_ANSWER_TWO); chatReq.setWarningId(String.valueOf(warningRecord.getId())); chatReq.setCounts(1);//问答次数 chatReq.setCreateBy(WARNING_DEFAULT_CREATE); chatReq.setCreateTime(DateUtils.getNowDate()); this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq); } private void addChatRecordByYCSG(TXinyiWarningRecord warningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, String category, BigDecimal exceedVal) { 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(warningRecord, tXinyiIndustry, normConfig, DateUtils.getNowDate()); chatReq.setShowVal(showVal);//前端展示的数据和提问的数据不一致 chatReq.setQuestion(BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getMsg());//本地问题 // chatReq.setAnswer(category + YCSG_ANSWER_ONE + exceedVal.multiply(BigDecimal_100) + "%" + YCSG_ANSWER_TWO + warningRecord.getWarningVal() + YCSG_ANSWER_THREE); chatReq.setAnswer(YCSG_ANSWER_REPLACE.replaceAll("@@@0", category).replaceAll("@@@1", String.valueOf(DecimalUtils.getAbsAndScale(warningRecord.getWarningVal(), INT_2))).replaceAll("@@@2", DecimalUtils.getAbsAndScale(exceedVal.multiply(BigDecimal_100), INT_1) + "%")); chatReq.setWarningId(String.valueOf(warningRecord.getId())); chatReq.setCounts(1);//问答次数 chatReq.setCreateBy(WARNING_DEFAULT_CREATE); chatReq.setCreateTime(DateUtils.getNowDate()); this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq); } private void addChatRecordByNoChangeSingle(TXinyiWarningRecord warningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, String category) { 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(warningRecord, tXinyiIndustry, normConfig, DateUtils.getNowDate()); chatReq.setShowVal(showVal);//前端展示的数据和提问的数据不一致 chatReq.setQuestion(BusinessEnum.WarningSymbolEnum.YBGZ_LX_SINGLE.getMsg());//本地问题 // chatReq.setAnswer(SINGLE_NO_CHANGE_ANSWER_ONE + category + SINGLE_NO_CHANGE_ANSWER_TWO + category + SINGLE_NO_CHANGE_ANSWER_THREE); chatReq.setAnswer(SINGLE_NO_CHANGE_ANSWER_REPLACE.replaceAll("@@@0", category).replaceAll("@@@1", String.valueOf(DecimalUtils.getAbsAndScale(warningRecord.getWarningVal(), INDEX_2)))); chatReq.setWarningId(String.valueOf(warningRecord.getId())); chatReq.setCounts(1);//问答次数 chatReq.setCreateBy(WARNING_DEFAULT_CREATE); chatReq.setCreateTime(DateUtils.getNowDate()); this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq); } private void addChatRecordByBreakPointsSingle(TXinyiWarningRecord warningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, String category) { 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(warningRecord, tXinyiIndustry, normConfig, DateUtils.getNowDate()); chatReq.setShowVal(showVal);//前端展示的数据和提问的数据不一致 chatReq.setQuestion(BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getMsg());//本地问题 // chatReq.setAnswer(SINGLE_BREAKPOINT_ANSWER_PREFIX + category + SINGLE_BREAKPOINT_ANSWER_SUFFIX); chatReq.setAnswer(SINGLE_BREAKPOINT_ANSWER_REPLACE.replaceAll("@@@0", category)); chatReq.setWarningId(String.valueOf(warningRecord.getId())); chatReq.setCounts(1);//问答次数 chatReq.setCreateBy(WARNING_DEFAULT_CREATE); chatReq.setCreateTime(DateUtils.getNowDate()); this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq); } private void addChatRecordByNoChangeMore(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(BusinessEnum.WarningSymbolEnum.YBGZ_LX_MORE.getMsg());//本地问题 // chatReq.setAnswer(MORE_NO_CHANGE_ANSWER); chatReq.setAnswer(MORE_NO_CHANGE_ANSWER_REPLACE.replaceAll("@@@0", tXinyiWarningRecord.getCategory()).replaceAll("@@@1", String.valueOf(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getWarningVal(), INT_2)))); chatReq.setWarningId(String.valueOf(tXinyiWarningRecord.getId())); chatReq.setCounts(1);//问答次数 chatReq.setCreateBy(WARNING_DEFAULT_CREATE); chatReq.setCreateTime(DateUtils.getNowDate()); this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq); } private void addChatRecordByBreakPointsMore(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(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_GYK.getMsg());//本地问题 // chatReq.setAnswer(MORE_BREAKPOINT_ANSWER); chatReq.setAnswer(MORE_BREAKPOINT_ANSWER_REPLACE.replaceAll("@@@0", tXinyiWarningRecord.getCategory())); 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)); String s = "asd@@@1dsa@@@1111@@@1222".replaceAll("@@@1", "!"); System.out.println(s); } /** * 处理机器人化验数据报警 * 2025年02月25日15:54:05 此报警不再使用 */ // 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(); // // BigDecimal jsSlq = tXinyiIndustry.getJsSlq(); // BigDecimal jsslSjz = normConfig.getJsslSjz(); // // //#1好氧硝酸盐 // BigDecimal no3Hlj1Jqr = tXinyiRobot.getNo3Hlj1Jqr(); // if(!Objects.isNull(no3Hlj1Jqr)){ // if(!Objects.isNull(cszzBzz)){ // handleXinYiWarningsRobotOrigin(cszzBzz, no3Hlj1Jqr, cszzGkz, ROBOT_XSY_1.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); // } // } // // //#2好氧硝酸盐 // BigDecimal no3Hlj2Jqr = tXinyiRobot.getNo3Hlj2Jqr(); // if(!Objects.isNull(no3Hlj2Jqr)){ // if(!Objects.isNull(cszzBzz)){ // handleXinYiWarningsRobotOrigin(cszzBzz, no3Hlj2Jqr, cszzGkz, ROBOT_XSY_2.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); // } // } // // //总磷 // 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)){ // handleXinYiWarningsRobotOrigin(cszlBzz, csTp, cszlGkz, ROBOT_ECCZLSY.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTp(), jsslSjz, normConfig.getJszlSjz())); // } // } // // //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); // handleXinYiWarningsRobotOrigin(csadBzz, divide, csadGkz, ROBOT_CS_AD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsNh3(), jsslSjz, normConfig.getJsadSjz())); // } // } // } public void handleRobotWarningNew(TXinyiRobot tXinyiRobot) { log.info("进入了定时任务判断机器人化验库是否超标及后续逻辑--新的逻辑处理"); //查询配置 List tXinyiNormConfigs = this.xinyiNormConfigMapper.selectTXinyiNormConfigList(null); if(CollectionUtils.isEmpty(tXinyiNormConfigs)){ // throw new ServiceException("未查询到配置信息"); log.error("未查询到配置信息"); return; } TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0); String testHour = tXinyiRobot.getTestHour(); if(StringUtils.isBlank(testHour)){ log.error("化验室报警的时候,获取化验室的化验时间-小时失败,无法处理后续操作"); return; } //查询最新的一条工业库的数据(showvalue展示使用) //2025年02月26日15:55:16 逻辑调整:这里不使用最新的一条工业库数据,获取化验室的同时段的数据 // List tXinyiIndustries = this.xinyiIndustryMapper.selectNIndustry(1); List tXinyiIndustries = this.xinyiIndustryMapper.selectTXinyiIndustryList(TXinyiIndustry.builder().testHour(testHour).build()); if(CollectionUtils.isEmpty(tXinyiIndustries)){ // throw new ServiceException("未查询到对应的工业库数据,无法进行图表数据展示!"); log.error("未查询到对应的工业库数据,无法进行图表数据展示!"); return; } TXinyiIndustry tXinyiIndustry = tXinyiIndustries.get(0); //新的逻辑: //只要当前获取的工业库数据和当前时间 //如果当前时间和工业库传过来的相差不到一个小时,说明正常,工业库没挂掉:需要查询是否有挂掉的记录,有的话,关闭此报警,并触发整体的业务数据报警。 //如果超过1小时了,说明工业库同步数据挂掉了,这时候去查询有无此类型的报警,如果有,不做任何处理,程序结束;如果没有,新增该类型报警并结束程序。 Date nowDate = DateUtils.getNowDate(); Date warningDate = null; try { warningDate = DateUtils.parseDate(testHour, DateUtils.YYYYMMDDHH_TS); } catch (ParseException e) { // throw new RuntimeException(e.getMessage()); log.error("将化验室的的化验时间转换date类型异常,异常信息为{}", e.getMessage()); return; } //查询工业库同步任务失败的报警正在进行的数据 //2025年03月03日15:05:21 同步任务的报警不需要展示 后期考虑短信或者其他方式报警 /*TXinyiWarningRecord warningRecord = TXinyiWarningRecord.builder().symbol(BusinessEnum.WarningSymbolEnum.ROBOT_SYNC_ERROR.getCode()).status(0).build(); List tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecord);*/ long hours = DateUtils.differentHoursByLocalDateTime(nowDate, warningDate); if(hours == 0L){ //查看是否有正在进行的同步任务失败的报警 /*if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ closeWarning(tXinyiWarningRecords.get(0)); }*/ //正常的业务数据报警 robotWarningDetail(tXinyiRobot, normConfig, tXinyiIndustry); }else{ log.info("同步化验室任务获取最新的数据失败,无法处理报警信息。"); log.error("同步化验室任务获取最新的数据失败,无法处理报警信息。"); //todo 发送短信 //查询是否有正在工业库的同步任务失败的报警,有的话,什么都不做; 没有的话,新增该类型报警 /*if(CollectionUtils.isEmpty(tXinyiWarningRecords)){ //插入该类型报警 warningRecord.setType(0); String msg = BusinessEnum.WarningSymbolEnum.ROBOT_SYNC_ERROR.getMsg(); warningRecord.setCategory(msg); warningRecord.setTime(nowDate); warningRecord.setReason(msg); warningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.ROBOT_SYNC_ERROR.getCode()); warningRecord.setCreateBy(WARNING_DEFAULT_CREATE); warningRecord.setCreateTime(nowDate); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecord); }else{ log.info("化验室报警的时候,发现同步化验室同步定时任务挂掉了,并且已经有该类型报警了,不做任何处理"); }*/ //将其他类型的报警全部关闭 //2025年02月27日17:35:37 此场景不关闭其他报警 // closeOtherWarningsBySymbol(null); } } private void robotWarningDetail(TXinyiRobot tXinyiRobot, TXinyiNormConfig normConfig, TXinyiIndustry tXinyiIndustry) { //先查看数据是否有断点--单指标 断点--多指标 int breakpointCount = 0; List breakPointList = new ArrayList<>();//断点集合 //判断单指标断点,后续同指标的其他报警是否可以继续执行 boolean xsy1Execute = true; boolean xsy2Execute = true; boolean ecczlxyExecute = true; boolean csADExecute = true; //#1好氧硝酸盐 BigDecimal no3Hlj1Jqr = tXinyiRobot.getNo3Hlj1Jqr(); //#2好氧硝酸盐 BigDecimal no3Hlj2Jqr = tXinyiRobot.getNo3Hlj2Jqr(); //总磷 BigDecimal tpRccJqr = tXinyiRobot.getTpRccJqr(); //1#缺氧出-硝酸盐 BigDecimal no3Qyc1Jqr = tXinyiRobot.getNo3Qyc1Jqr(); BigDecimal nh31Jqr = tXinyiRobot.getNh31Jqr(); //2#缺氧出-硝酸盐 BigDecimal no3Qyc2Jqr = tXinyiRobot.getNo3Qyc2Jqr(); BigDecimal nh32Jqr = tXinyiRobot.getNh32Jqr(); //总氮的标准值和管控值 BigDecimal cszzBzz = normConfig.getCszzBzz(); BigDecimal cszzGkz = normConfig.getCszzGkz(); //氨氮的标准值和管控值 BigDecimal csadBzz = normConfig.getCsadBzz(); BigDecimal csadGkz = normConfig.getCsadGkz(); BigDecimal jsSlq = tXinyiIndustry.getJsSlq(); BigDecimal jsslSjz = normConfig.getJsslSjz(); BigDecimal cszlBzz = normConfig.getCszlBzz(); BigDecimal cszlGkz = normConfig.getCszlGkz(); WarningMoreExceed warningMoreExceed = null; if(!Objects.isNull(no3Hlj1Jqr)){ warningMoreExceed = handleXinYiWarningRecordRobotMore(cszzBzz, no3Hlj1Jqr, cszzGkz, ROBOT_XSY_1.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } } if(!Objects.isNull(no3Hlj2Jqr)){ warningMoreExceed = handleXinYiWarningRecordRobotMore(cszzBzz, no3Hlj2Jqr, cszzGkz, ROBOT_XSY_2.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } } if(!Objects.isNull(tpRccJqr)){ BigDecimal csTp = tpRccJqr.divide(ROBOT_HY_DIVIDE, NUMBER_SCALE_4, RoundingMode.HALF_UP); warningMoreExceed = handleXinYiWarningRecordRobotMore(cszlBzz, csTp, cszlGkz, ROBOT_ECCZLSY.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTp(), jsslSjz, normConfig.getJszlSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } } //判断 增加容错 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(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); BigDecimal divide = anDan1.add(anDan2).divide(DECIMAL_2, INT_2, RoundingMode.HALF_UP); warningMoreExceed = handleXinYiWarningRecordRobotMore(csadBzz, divide, csadGkz, ROBOT_CS_AD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsNh3(), jsslSjz, normConfig.getJsadSjz())); if(warningMoreExceed.isBreakpoint()){ breakpointCount++; breakPointList.add(warningMoreExceed.getBreakPointWarningRecord()); } Date nowDate = DateUtils.getNowDate(); //下面是处理多个指标的 【断点】报警 //断点 TXinyiWarningRecord warningRecord = TXinyiWarningRecord.builder().symbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_HYS.getCode()).status(0).build(); List tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecord); if(breakpointCount < 1){//恢复正常 关闭多个断点报警 //2025年02月28日15:18:30 即使多指标断点,也是按具体分类报警 关闭多个报警 if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ for (TXinyiWarningRecord tXinyiWarningRecord : tXinyiWarningRecords) { closeWarning(tXinyiWarningRecord); } } }else if(breakpointCount == 1){//只有单个的断点 TXinyiWarningRecord warningRecordBreakPointOne = breakPointList.get(0); String category = warningRecordBreakPointOne.getCategory(); TXinyiWarningRecord warningRecordReq = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()).status(0).build(); List tXinyiBreakPointSingleWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecordReq); //关闭同类型的其他报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_DD_SINGLE.getCode()); //触发报警 并且模拟大模型返回决策问答数据 if(CollectionUtils.isEmpty(tXinyiBreakPointSingleWarningRecords)){ //插入该类型报警 this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordBreakPointOne); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByBreakPointsSingle(warningRecordBreakPointOne, tXinyiIndustry, normConfig, category); }else{ log.info("化验室报警的时候,发现存在仪表故障(断点不变单个指标)的报警,并且已经有该类型报警了,不做任何处理"); //2025年03月06日10:52:57 逻辑调整:更新一直报警的那条记录的显示值 TXinyiWarningRecord xinyiWarningRecord = tXinyiBreakPointSingleWarningRecords.get(0); xinyiWarningRecord.setWarningVal(warningRecordBreakPointOne.getWarningVal()); xinyiWarningRecord.setTime(warningRecordBreakPointOne.getTime()); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); //2024年7月31日09:20:47 报警的原因(超标还是超管控也需要更新) // xinyiWarningRecord.setReason(warningRecordBreakPointOne.getReason()); //更新数据库 this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); //继续调用决策【本地模拟的决策】 addChatRecordByBreakPointsSingle(xinyiWarningRecord, tXinyiIndustry, normConfig, category); } //如果出现单指标报警 标识后续同指标是否可以继续报警 if(ROBOT_XSY_1.getCode().equals(category)) xsy1Execute = false; if(ROBOT_XSY_2.getCode().equals(category)) xsy2Execute = false; if(ROBOT_ECCZLSY.getCode().equals(category)) ecczlxyExecute = false; if(ROBOT_CS_AD.getCode().equals(category)) csADExecute = false; //2025年02月28日15:18:30 即使多指标断点,也是按具体分类报警 关闭多个报警 if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){ for (TXinyiWarningRecord tXinyiWarningRecord : tXinyiWarningRecords) { closeWarning(tXinyiWarningRecord); } } }else{ //将其他类型的报警全部关闭 //2025年02月27日17:35:37 此场景不关闭其他报警 // closeOtherWarningsBySymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_HYS.getCode()); //再新增新的类型的报警 /*if(CollectionUtils.isEmpty(tXinyiWarningRecords)){ //插入该类型报警 warningRecord.setType(0); String msg = BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_HYS.getMsg(); warningRecord.setCategory(msg); warningRecord.setTime(nowDate); warningRecord.setReason(msg); warningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_HYS.getCode()); warningRecord.setCreateBy(WARNING_DEFAULT_CREATE); warningRecord.setCreateTime(nowDate); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecord); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByBreakPointsMore(warningRecord, tXinyiIndustry, normConfig); }else{ log.info("化验室报警的时候,发现存在仪表故障(断点多个指标)的报警,并且已经有该类型报警了,不做任何处理"); } log.info("化验室报警的时候,发现存在仪表故障(断点多个指标)的报警,其他报警不再处理"); return;*/ //逻辑调整:要按指标报多指标断点 需要当前的集合和原来的集合判断,新的报警增加,如果之前有了报警则不处理 if(CollectionUtils.isEmpty(tXinyiWarningRecords)){ //新增的断点的数据全部都报警 for (TXinyiWarningRecord tXinyiWarningRecord : breakPointList) { String category = tXinyiWarningRecord.getCategory(); //后续对应的指标是否可以进行报警 //如果出现单指标报警 标识后续同指标是否可以继续报警 if(ROBOT_XSY_1.getCode().equals(category)) xsy1Execute = false; if(ROBOT_XSY_2.getCode().equals(category)) xsy2Execute = false; if(ROBOT_ECCZLSY.getCode().equals(category)) ecczlxyExecute = false; if(ROBOT_CS_AD.getCode().equals(category)) csADExecute = false; //关闭该指标的其他类型的报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_HYS.getCode()); //原来集合里存放的都是单指标异常 下面2个值需要重新赋值 tXinyiWarningRecord.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_HYS.getMsg()); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_HYS.getCode()); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByBreakPointsMore(tXinyiWarningRecord, tXinyiIndustry, normConfig); } }else{//之前存在报警了 所以需要2个集合数据进行匹配,如果新的和原来的一样则不用做任何操作【持续报警】;如果不一样,则新的要报警,老报警要关闭 List breakPointListNew = new ArrayList<>(breakPointList);//断点集合[需要新增的] breakPointListNew.removeAll(tXinyiWarningRecords); List breakPointListClose = new ArrayList<>(tXinyiWarningRecords);//断点集合[需要关闭的] 还有2这重叠的,这种重叠的,是不需要做任何操作的,持续报警 breakPointListClose.removeAll(breakPointList); //插入新的报警 if(!CollectionUtils.isEmpty(breakPointListNew)){ for (TXinyiWarningRecord tXinyiWarningRecord : breakPointListNew) { String category = tXinyiWarningRecord.getCategory(); //后续对应的指标是否可以进行报警 //如果出现单指标报警 标识后续同指标是否可以继续报警 if(ROBOT_XSY_1.getCode().equals(category)) xsy1Execute = false; if(ROBOT_XSY_2.getCode().equals(category)) xsy2Execute = false; if(ROBOT_ECCZLSY.getCode().equals(category)) ecczlxyExecute = false; if(ROBOT_CS_AD.getCode().equals(category)) csADExecute = false; //关闭该指标的其他类型的报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_HYS.getCode()); //新插入 //原来集合里存放的都是单指标异常 下面2个值需要重新赋值 tXinyiWarningRecord.setReason(category + BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_HYS.getMsg()); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.YBGZ_DD_MORE_HYS.getCode()); this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByBreakPointsMore(tXinyiWarningRecord, tXinyiIndustry, normConfig); } } //关闭老的报警 if(!CollectionUtils.isEmpty(breakPointListClose)){ for (TXinyiWarningRecord tXinyiWarningRecord : breakPointListClose) { //老的报警,新的没有出现,关闭 closeWarning(tXinyiWarningRecord); } } //2025年03月06日10:56:41 需要额外记录哪些是历史报警,现在仍然报警的,这种的更新部分信息,更新决策内容 List breakPointListContinue = new ArrayList<>(tXinyiWarningRecords); breakPointListContinue.removeAll(breakPointListNew); if(!CollectionUtils.isEmpty(breakPointListContinue)){ for (TXinyiWarningRecord tXinyiWarningRecord : breakPointListContinue) { //2025年03月06日10:52:57 逻辑调整:更新一直报警的那条记录的显示值 //需要匹配新的报警中的最新的值 String category = tXinyiWarningRecord.getCategory(); TXinyiWarningRecord tXinyiWarningRecordContinue = tXinyiWarningRecord;//兜底处理 Optional optional = breakPointListNew.stream().filter(r -> category.equals(r.getCategory())).findAny(); if(optional.isPresent()){ tXinyiWarningRecordContinue = optional.get(); log.info("存在之前多指标断点,现在仍然断点的数据{}", JSON.toJSONString(tXinyiWarningRecordContinue)); } tXinyiWarningRecord.setWarningVal(tXinyiWarningRecordContinue.getWarningVal()); tXinyiWarningRecord.setTime(tXinyiWarningRecordContinue.getTime()); tXinyiWarningRecord.setUpdateTime(nowDate); tXinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); //从单指标变成多指标 这个不可以修改 // tXinyiWarningRecord.setReason(tXinyiWarningRecordContinue.getReason()); //更新数据库 this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(tXinyiWarningRecord); //继续调用决策【本地模拟的决策】 addChatRecordByBreakPointsMore(tXinyiWarningRecord, tXinyiIndustry, normConfig); } } } //如果出现多指标问题,后续的报警不再处理 //2025年03月03日17:31:53 只有上述指标出现异常的,才不可以报警,不会让所有的都不报警 // return; } //最原始的标准值和管控制报警 //2025年02月25日15:58:15 需要在最原始的报警里,增加是否出现单点突变 - 异常升高 和 单点突变 - 异常偏低的报警 // robotOriginWarning(tXinyiRobot, normConfig, tXinyiIndustry); //这里需要根据是否出现了断点判断,做不同的 其他类型的报警 不能执行所有指标的 因为有可能某个指标是 单指标断点,这种的就不用执行其他报警了 //#1好氧硝酸盐 if(!Objects.isNull(no3Hlj1Jqr) && no3Hlj1Jqr.compareTo(BigDecimal.ZERO) > 0 && xsy1Execute){ if(!Objects.isNull(cszzBzz)){ handleXinYiWarningsRobotOrigin(cszzBzz, no3Hlj1Jqr, cszzGkz, ROBOT_XSY_1.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); } } //#2好氧硝酸盐 if(!Objects.isNull(no3Hlj2Jqr) && no3Hlj2Jqr.compareTo(BigDecimal.ZERO) > 0 && xsy2Execute){ if(!Objects.isNull(cszzBzz)){ handleXinYiWarningsRobotOrigin(cszzBzz, no3Hlj2Jqr, cszzGkz, ROBOT_XSY_2.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); } } //总磷 if(!Objects.isNull(tpRccJqr) && tpRccJqr.compareTo(BigDecimal.ZERO) > 0 && ecczlxyExecute){ BigDecimal csTp = tpRccJqr.divide(ROBOT_HY_DIVIDE, NUMBER_SCALE_4, RoundingMode.HALF_UP); if(!Objects.isNull(cszlBzz)){ handleXinYiWarningsRobotOrigin(cszlBzz, csTp, cszlGkz, ROBOT_ECCZLSY.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTp(), jsslSjz, normConfig.getJszlSjz())); } } //2#缺氧出-硝酸盐 if(!Objects.isNull(csadBzz) && csADExecute){ handleXinYiWarningsRobotOrigin(csadBzz, divide, csadGkz, ROBOT_CS_AD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsNh3(), jsslSjz, normConfig.getJsadSjz())); } } // private void robotOriginWarning(TXinyiRobot tXinyiRobot, TXinyiNormConfig normConfig, TXinyiIndustry tXinyiIndustry) { // //总氮的标准值和管控值 // BigDecimal cszzBzz = normConfig.getCszzBzz(); // BigDecimal cszzGkz = normConfig.getCszzGkz(); // //氨氮的标准值和管控值 // BigDecimal csadBzz = normConfig.getCsadBzz(); // BigDecimal csadGkz = normConfig.getCsadGkz(); // // BigDecimal jsSlq = tXinyiIndustry.getJsSlq(); // BigDecimal jsslSjz = normConfig.getJsslSjz(); // // //#1好氧硝酸盐 // BigDecimal no3Hlj1Jqr = tXinyiRobot.getNo3Hlj1Jqr(); // if(!Objects.isNull(no3Hlj1Jqr)){ // if(!Objects.isNull(cszzBzz)){ // handleXinYiWarningsRobotOrigin(cszzBzz, no3Hlj1Jqr, cszzGkz, ROBOT_XSY_1.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); // } // } // // //#2好氧硝酸盐 // BigDecimal no3Hlj2Jqr = tXinyiRobot.getNo3Hlj2Jqr(); // if(!Objects.isNull(no3Hlj2Jqr)){ // if(!Objects.isNull(cszzBzz)){ // handleXinYiWarningsRobotOrigin(cszzBzz, no3Hlj2Jqr, cszzGkz, ROBOT_XSY_2.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTn(), jsslSjz, normConfig.getJszdSjz())); // } // } // // //总磷 // 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)){ // handleXinYiWarningsRobotOrigin(cszlBzz, csTp, cszlGkz, ROBOT_ECCZLSY.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsTp(), jsslSjz, normConfig.getJszlSjz())); // } // } // // //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); // // // //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); // handleXinYiWarningsRobotOrigin(csadBzz, divide, csadGkz, ROBOT_CS_AD.getCode(), tXinyiIndustry, normConfig, getCwrwfhzByDetail(jsSlq, tXinyiIndustry.getJsNh3(), jsslSjz, normConfig.getJsadSjz())); // } // } /** * 通过输入的值 生成对应类型的报警对象(出水) * * @param csBzz * @param currentVal * @param csGkz * @param category * @param tXinyiIndustry * @param normConfig * @param cwrwfhz * @return */ private void handleXinYiWarningsRobotOrigin(BigDecimal csBzz, BigDecimal currentVal, BigDecimal csGkz, String category, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, BigDecimal cwrwfhz) { Date nowDate = DateUtils.getNowDate(); List tXinyiRobots = this.xinyiRobotMapper.selectNRobot(INT_3); if(CollectionUtils.isEmpty(tXinyiRobots) || tXinyiRobots.size() < 3){ log.error("处理连续检测报警时,获取最近的3条化验数据失败~~~~~~~"); return; } TXinyiRobot tXinyiRobot1 = tXinyiRobots.get(INDEX_1);//前一个小时 //单点突变-异常升高报警 TXinyiWarningRecord warningRecordYCSG = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getCode()).status(0).build(); List tXinyiNoChangeYCSGRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecordYCSG); //是否存在异常升高的问题 if(!CollectionUtils.isEmpty(tXinyiRobots) && tXinyiRobots.size() == INT_3){ //2025年02月21日14:33:37 这里要改成当前值和上个小时比较 上个小时和上上个小时比较 BigDecimal exceedVal = existsRobotYCSG(currentVal, category, tXinyiRobots); if(!Objects.isNull(exceedVal)){//这里不能只返回一个布尔类型的结果,因为还要获取百分比的值 //关闭同类型的其他报警 closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getCode()); //触发报警 并且模拟大模型返回决策问答数据 if(CollectionUtils.isEmpty(tXinyiNoChangeYCSGRecords)){ //插入该类型报警 warningRecordYCSG.setTime(nowDate); warningRecordYCSG.setReason(category + BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getMsg()); warningRecordYCSG.setWaterType(BusinessEnum.WaterTypeEnum.CS.getCode()); warningRecordYCSG.setSymbol(BusinessEnum.WarningSymbolEnum.SJYC_YCSG.getCode()); warningRecordYCSG.setCreateBy(WARNING_DEFAULT_CREATE); warningRecordYCSG.setCreateTime(nowDate); warningRecordYCSG.setWarningVal(currentVal); warningRecordYCSG.setDesignVal(csBzz); warningRecordYCSG.setControlVal(csGkz); warningRecordYCSG.setRemark(THREE_HYS_WARNING.getCode());//化验室 warningRecordYCSG.setCwrwfhz(cwrwfhz);//2025年02月14日10:42:53 具体指标具体计算,由上游传过来。 warningRecordYCSG.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, false));//根据当前值和类型以及是否超标处理 this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordYCSG); //同时处理决策 不用调用大模型,本地处理问答 addChatRecordByYCSG(warningRecordYCSG, tXinyiIndustry, normConfig, category, exceedVal); }else{ log.info("化验室报警的时候,发现存在异常升高的报警,并且已经有该类型报警了,不做任何处理"); } log.info("化验室报警的时候,发现存在异常升高的报警,后续同指标报警不再处理"); return; }else{//不存在 查看历史是否有报警,有的话关闭 if(!CollectionUtils.isEmpty(tXinyiNoChangeYCSGRecords)){ closeWarning(tXinyiNoChangeYCSGRecords.get(0)); } } } //单点突变-异常偏低报警 //2025年03月03日15:00:55 异常偏低的报警暂时不需要了 // TXinyiWarningRecord warningRecordYCPD = TXinyiWarningRecord.builder().type(0).category(category).symbol(BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getCode()).status(0).build(); // List tXinyiNoChangeYCPDRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(warningRecordYCPD); // //是否存在异常偏低的问题 // if(!Objects.isNull(tXinyiRobot1)){ // //2025年02月21日15:05:41 这里只需要比较当前值和标准值的差 以及上个小时的值和标准值的差 所以不用取最近3个小时的 // BigDecimal exceedVal = existsRobotYCPD(currentVal, category, tXinyiRobot1, csBzz); // if(!Objects.isNull(exceedVal)){//这里不能只返回一个布尔类型的结果,因为还要获取百分比的值 // //关闭同类型的其他报警 // closeOtherWarningsByCategory(category, BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getCode()); // //触发报警 并且模拟大模型返回决策问答数据 // if(CollectionUtils.isEmpty(tXinyiNoChangeYCPDRecords)){ // //插入该类型报警 // warningRecordYCPD.setType(0); // warningRecordYCPD.setCategory(category); // warningRecordYCPD.setTime(nowDate); // warningRecordYCPD.setReason(category + BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getMsg()); // warningRecordYCPD.setWaterType(BusinessEnum.WaterTypeEnum.CS.getCode()); // warningRecordYCPD.setSymbol(BusinessEnum.WarningSymbolEnum.SJYC_YCPD.getCode()); // warningRecordYCPD.setCreateBy(WARNING_DEFAULT_CREATE); // warningRecordYCPD.setCreateTime(nowDate); // warningRecordYCPD.setWarningVal(currentVal); // this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(warningRecordYCPD); // //同时处理决策 不用调用大模型,本地处理问答 // addChatRecordByYCPD(warningRecordYCPD, tXinyiIndustry, normConfig, category, exceedVal); // }else{ // log.info("化验室报警的时候,发现存在异常偏低的报警,并且已经有该类型报警了,不做任何处理"); // } // log.info("化验室报警的时候,发现存在异常偏低的报警,后续同指标报警不再处理"); // return; // }else{//不存在 查看历史是否有报警,有的话关闭 // if(!CollectionUtils.isEmpty(tXinyiNoChangeYCPDRecords)){ // closeWarning(tXinyiNoChangeYCPDRecords.get(0)); // } // } // } //下面是最原始的处理 超标准 超管控报警 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());//化验室 tXinyiWarningRecord.setCwrwfhz(cwrwfhz);//2025年02月14日10:42:53 具体指标具体计算,由上游传过来。 //2025年02月17日13:53:49 化验室的报警都是对应的类型都是出水 tXinyiWarningRecord.setWaterType(BusinessEnum.WaterTypeEnum.CS.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); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.CBZZ.getCode()); tXinyiWarningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, true));//根据当前值和类型以及是否超标处理 }else if(currentVal.compareTo(csBzz) >= 0 && currentVal.compareTo(multiply) <= 0){//二级 tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_TWO); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.CBZZ.getCode()); tXinyiWarningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, true));//根据当前值和类型以及是否超标处理 }else if(!Objects.isNull(csGkz) && currentVal.compareTo(csGkz) > 0){ tXinyiWarningRecord.setReason(category + CHAOGUANKONG_WARNING); tXinyiWarningRecord.setLevel(WARNING_LEVEL_THREE); tXinyiWarningRecord.setSymbol(BusinessEnum.WarningSymbolEnum.CGKZ.getCode()); tXinyiWarningRecord.setCwrwxz(getCwrwxzByDetail(currentVal, normConfig, category, false));//根据当前值和类型以及是否超标处理 }else{ tXinyiWarningRecord = null;//这种的无需处理 } //当前状态正常 需要查询历史有无正在报警的数据,如果有,将报警状态改完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); xinyiWarningRecord.setOffTime(nowDate); xinyiWarningRecord.setUpdateTime(nowDate); xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE); this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord); } } }else{//有告警信息 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.ROBOT_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); } }