Kaynağa Gözat

预测报警相关处理

wangmiaomiao 9 ay önce
ebeveyn
işleme
8ad42b3b88

+ 1 - 1
slibra-admin/src/main/java/com/slibra/web/controller/business/GRPCController.java

@@ -470,7 +470,7 @@ public class GRPCController extends BaseController {
                     .usePlaintext()
                     .build();
             InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub stub = InferenceAPIsServiceGrpc.newBlockingStub(channel);
-            String dataJson = "{\"bot_id\":\"b00001\",\"exp_id\":\"721\",\"norm\":\"出水氮\",\"session_id\":\" " + IdUtils.simpleUUID() + "  \",\"extra\":{}}";
+            String dataJson = "{\"bot_id\":\"b00001\",\"exp_id\":\"721\",\"norm\":\"出水氮\",\"session_id\":\" " + IdUtils.simpleUUID() + "  \",\"extra\":{}}";
             log.info("请求大模型的问答参数为{}", dataJson);
             PredictionsRequest request = PredictionsRequest.newBuilder()
                     .setModelName("slibra_bot")

+ 2 - 0
slibra-common/src/main/java/com/slibra/common/constant/MyConstants.java

@@ -8,6 +8,8 @@ public class MyConstants {
     public static final String SUCCESS = "操作成功";
 
     //报警计算使用的比例  默认是1.1倍
+    public static final String XIAOSUANYAN_BZK = "15";
+    public static final String XIAOSUANYAN_GKZ = "12";
     public static final String SCALE_VALUE = "1.1";
     public static final String F_M_LAST = "77239.86";
     public static final String ONE_DAY_HOURS = "24";

+ 1 - 0
slibra-framework/src/main/java/com/slibra/framework/config/SecurityConfig.java

@@ -124,6 +124,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/login", "/register", "/captchaImage","/sendSmsCode/*","/smsLogin","/test/**", "/demo/**").permitAll()
                 .antMatchers("/websocket/**").permitAll()//websocket的
                 .antMatchers("/front/**","/grpc/**").permitAll()//临时测试的
+                .antMatchers("/qiniuyun/**").permitAll()//文件上传相关
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

+ 203 - 16
slibra-quartz/src/main/java/com/slibra/quartz/task/RyTask.java

@@ -11,6 +11,8 @@ import com.slibra.business.domain.*;
 import com.slibra.business.mapper.*;
 import com.slibra.business.req.ChatReq;
 import com.slibra.business.req.DecisionReq;
+import com.slibra.business.res.ChartBasic;
+import com.slibra.business.res.ShowValueBasic;
 import com.slibra.common.constant.MyConstants;
 import com.slibra.common.enums.BusinessEnum;
 import com.slibra.common.enums.DataSourceType;
@@ -835,6 +837,62 @@ public class RyTask
         return JSON.toJSONString(result, JSONWriter.Feature.WriteNulls);
     }
 
+    /**
+     * 带图形的构建展示数据
+     * @param tXinyiWarningRecord
+     * @param tXinyiIndustry
+     * @param normConfig
+     * @return
+     */
+    private String buildShowValueWithCharts(TXinyiWarningRecord tXinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, List<ChartBasic> chartsDataList) {
+        JSONObject result = new JSONObject();
+//        JSONObject basic = new JSONObject();
+        Integer status = tXinyiWarningRecord.getStatus();
+        Date warningTime = tXinyiWarningRecord.getTime();
+        String remark = tXinyiWarningRecord.getRemark();
+        int count = DateUtils.differentHoursByMillisecond(warningTime, DateUtils.getNowDate()) + 1;
+        ShowValueBasic showValueBasic = new ShowValueBasic();
+        if("0".equals(remark)){//水质报警
+            showValueBasic.setH("在线仪表");
+            showValueBasic.setF(tXinyiWarningRecord.getLevel());
+        }else if("1".equals(remark)){//生化报警
+            showValueBasic.setH("在线仪表");
+        }else if("2".equals(remark)){//预测报错
+            showValueBasic.setH("预测");
+            showValueBasic.setF(tXinyiWarningRecord.getLevel());
+        }else {//机器人化验室报警
+            showValueBasic.setH("化验室");
+            showValueBasic.setF(tXinyiWarningRecord.getLevel());
+        }
+        //通用的
+        //        showValueBasic.setA(tXinyiWarningRecord.getReason());
+        showValueBasic.setB(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM ,warningTime));
+        showValueBasic.setC(tXinyiWarningRecord.getWarningVal());
+        showValueBasic.setD(tXinyiWarningRecord.getControlVal());
+        showValueBasic.setE(tXinyiWarningRecord.getDesignVal());
+        showValueBasic.setG(Math.min(count, MAX_COUNT));
+        if(tXinyiWarningRecord.getType() != 2)
+            showValueBasic.setI(status == 0 ? "报警中" : status == 1 ? "用户关闭" : status == 2 ? "系统关闭" : "应急处理中");
+        else
+            showValueBasic.setI(status == 0 ? "预警中" : "已完成");
+
+        result.put("basic", showValueBasic);
+        JSONObject jsData = getJsonObject(tXinyiIndustry, normConfig);//进水数据
+        result.put("jsData", jsData);
+        JSONObject csData = getCsonObject(tXinyiIndustry, normConfig);//出水数据
+        result.put("csData", csData);
+//        JSONObject chartsData = getChartsCsonObject(tXinyiIndustry, normConfig);//图表数据 因为展示不同,所以要传过来或者判断
+        result.put("chartsData", chartsDataList);
+        return JSON.toJSONString(result, JSONWriter.Feature.WriteNulls);
+    }
+
+    @Deprecated
+    private JSONObject getChartsCsonObject(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) {
+        JSONObject jsData = new JSONObject();
+        //处理图表数据
+        return jsData;
+    }
+
     private static JSONObject getJsonObject(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) {
         JSONObject jsData = new JSONObject();
         HashMap<Object, Object> temp1 = new HashMap<>();
@@ -1178,6 +1236,9 @@ public class RyTask
      *
      */
     public void predictor(){
+        //获取最新的6条工业科数据
+        List<TXinyiIndustry> tXinyiIndustries6 = this.xinyiIndustryMapper.selectNIndustry(6);
+        List<TXinyiRobot> tXinyiRobots6 = this.xinyiRobotMapper.selectNRobot(6);
         for (int i = 0; i < predictorArr.length; i++) {
             String result = testPredictor(predictorArr[i]);
             JSONObject jsonObject = JSON.parseObject(result);
@@ -1193,14 +1254,14 @@ public class RyTask
                     return;
                 }
                 //解析数据 处理报警 调研prompt 保存等
-                this.handlePredictorWarning(split, hour, task);
+                this.handlePredictorWarning(split, hour, task, tXinyiIndustries6, tXinyiRobots6);
             }else {
                 log.error("预测数据返回结果为{},无法正常解析", result);
             }
         }
     }
 
-    private void handlePredictorWarning(String[] split, String hour, String task) {
+    private void handlePredictorWarning(String[] split, String hour, String task, List<TXinyiIndustry> tXinyiIndustries6, List<TXinyiRobot> tXinyiRobots6) {
         //获取配置表
         List<TXinyiNormConfig> tXinyiNormConfigs = this.xinyiNormConfigMapper.selectTXinyiNormConfigList(null);
         if(CollectionUtils.isEmpty(tXinyiNormConfigs)) {
@@ -1210,29 +1271,154 @@ public class RyTask
         TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0);
         //获取最新的工业库的数据
         TXinyiIndustry tXinyiIndustry = this.xinyiIndustryMapper.selectTXinyiIndustryNewest();
+        List<ChartBasic> chartsDataList = new ArrayList<>(9);
         if("cod".equals(task)){
             BigDecimal cscodBzz = normConfig.getCscodBzz();
             BigDecimal cscodGkz = normConfig.getCscodGkz();
-            handleXinYiWarningsYC(cscodBzz, split, cscodGkz, BusinessEnum.WarningCategoryEnum.CS_COD_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry);
+            //处理展示数据
+            for (int i = 0; i < tXinyiIndustries6.size(); i++) {
+                TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
+                chartBasic.setVal(tXinyiIndustryTemp.getCsCod());
+                chartsDataList.add(chartBasic);
+            }
+            String[] hours = hour.split(",");
+            for (int i = 0; i < split.length; i++) {
+                String val = split[i];
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(hours[i]);
+                chartBasic.setVal(new BigDecimal(val));
+                chartsDataList.add(chartBasic);
+            }
+            handleXinYiWarningsYC(cscodBzz, split, cscodGkz, BusinessEnum.WarningCategoryEnum.CS_COD_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList);
         }else if("ss".equals(task)){
-
+            BigDecimal csSSBzz = normConfig.getCsssBzz();
+            BigDecimal csssGkz = normConfig.getCsssGkz();
+            //处理展示数据
+            for (int i = 0; i < tXinyiIndustries6.size(); i++) {
+                TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
+                chartBasic.setVal(tXinyiIndustryTemp.getCsSs());
+                chartsDataList.add(chartBasic);
+            }
+            String[] hours = hour.split(",");
+            for (int i = 0; i < split.length; i++) {
+                String val = split[i];
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(hours[i]);
+                chartBasic.setVal(new BigDecimal(val));
+                chartsDataList.add(chartBasic);
+            }
+            handleXinYiWarningsYC(csSSBzz, split, csssGkz, BusinessEnum.WarningCategoryEnum.CS_SS_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList);
         }else if("tn".equals(task)){
-
+            BigDecimal cszzBzz = normConfig.getCszzBzz();
+            BigDecimal cszzGkz = normConfig.getCszzGkz();
+            //处理展示数据
+            for (int i = 0; i < tXinyiIndustries6.size(); i++) {
+                TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
+                chartBasic.setVal(tXinyiIndustryTemp.getCsTn());
+                chartsDataList.add(chartBasic);
+            }
+            String[] hours = hour.split(",");
+            for (int i = 0; i < split.length; i++) {
+                String val = split[i];
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(hours[i]);
+                chartBasic.setVal(new BigDecimal(val));
+                chartsDataList.add(chartBasic);
+            }
+            handleXinYiWarningsYC(cszzBzz, split, cszzGkz, BusinessEnum.WarningCategoryEnum.CS_TN_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList);
         }else if("tp".equals(task)){
-
+            BigDecimal cszlBzz = normConfig.getCszlBzz();
+            BigDecimal cszlGkz = normConfig.getCszlGkz();
+            //处理展示数据
+            for (int i = 0; i < tXinyiIndustries6.size(); i++) {
+                TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
+                chartBasic.setVal(tXinyiIndustryTemp.getCsTp());
+                chartsDataList.add(chartBasic);
+            }
+            String[] hours = hour.split(",");
+            for (int i = 0; i < split.length; i++) {
+                String val = split[i];
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(hours[i]);
+                chartBasic.setVal(new BigDecimal(val));
+                chartsDataList.add(chartBasic);
+            }
+            handleXinYiWarningsYC(cszlBzz, split, cszlGkz, BusinessEnum.WarningCategoryEnum.CS_TP_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList);
         }else if("nh3".equals(task)){
-
+            BigDecimal csadBzz = normConfig.getCsadBzz();
+            BigDecimal csadGkz = normConfig.getCsadGkz();
+            //处理展示数据
+            for (int i = 0; i < tXinyiIndustries6.size(); i++) {
+                TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
+                chartBasic.setVal(tXinyiIndustryTemp.getCsNh3());
+                chartsDataList.add(chartBasic);
+            }
+            String[] hours = hour.split(",");
+            for (int i = 0; i < split.length; i++) {
+                String val = split[i];
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(hours[i]);
+                chartBasic.setVal(new BigDecimal(val));
+                chartsDataList.add(chartBasic);
+            }
+            handleXinYiWarningsYC(csadBzz, split, csadGkz, BusinessEnum.WarningCategoryEnum.CS_AD_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList);
         }else if("xsy1".equals(task)){
-
+            BigDecimal cscodBzz = new BigDecimal(XIAOSUANYAN_BZK);
+            BigDecimal cscodGkz = new BigDecimal(XIAOSUANYAN_GKZ);
+            //处理展示数据
+            for (int i = 0; i < tXinyiRobots6.size(); i++) {
+                TXinyiRobot tXinyiRobotTemp = tXinyiRobots6.get(5 - i);
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(tXinyiRobotTemp.getTestHour().substring(11));
+                chartBasic.setVal(tXinyiRobotTemp.getNo3Hlj1Jqr());
+                chartsDataList.add(chartBasic);
+            }
+            String[] hours = hour.split(",");
+            for (int i = 0; i < split.length; i++) {
+                String val = split[i];
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(hours[i]);
+                chartBasic.setVal(new BigDecimal(val));
+                chartsDataList.add(chartBasic);
+            }
+            handleXinYiWarningsYC(cscodBzz, split, cscodGkz, BusinessEnum.WarningCategoryEnum.CS_XSY_1_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList);
         }else if("xsy2".equals(task)){
-
+            BigDecimal cscodBzz = new BigDecimal(XIAOSUANYAN_BZK);
+            BigDecimal cscodGkz = new BigDecimal(XIAOSUANYAN_GKZ);
+            //处理展示数据
+            for (int i = 0; i < tXinyiRobots6.size(); i++) {
+                TXinyiRobot tXinyiRobotTemp = tXinyiRobots6.get(5 - i);
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(tXinyiRobotTemp.getTestHour().substring(11));
+                chartBasic.setVal(tXinyiRobotTemp.getNo3Hlj2Jqr());
+                chartsDataList.add(chartBasic);
+            }
+            String[] hours = hour.split(",");
+            for (int i = 0; i < split.length; i++) {
+                String val = split[i];
+                ChartBasic chartBasic = new ChartBasic();
+                chartBasic.setTime(hours[i]);
+                chartBasic.setVal(new BigDecimal(val));
+                chartsDataList.add(chartBasic);
+            }
+            handleXinYiWarningsYC(cscodBzz, split, cscodGkz, BusinessEnum.WarningCategoryEnum.CS_XSY_2_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList);
         }else {
             log.error("暂未支持的类型{}", task);
         }
 
     }
 
-    private void handleXinYiWarningsYC(BigDecimal csBzz, String[] split, BigDecimal csGkz, String category, String hour, TXinyiNormConfig normConfig, BigDecimal currentVal, TXinyiIndustry tXinyiIndustry) {
+    private void handleXinYiWarningsYC(BigDecimal csBzz, String[] split, BigDecimal csGkz, String category, String hour, TXinyiNormConfig normConfig, BigDecimal currentVal, TXinyiIndustry tXinyiIndustry, List<ChartBasic> chartsDataList) {
         BigDecimal multiply = csBzz.multiply(new BigDecimal(MyConstants.SCALE_VALUE));
         TXinyiWarningRecord tXinyiWarningRecord = null;
         for (String forecast : split) {
@@ -1295,7 +1481,7 @@ public class RyTask
                     this.addChatRecordByWarning(tXinyiWarningRecord, tXinyiIndustry, normConfig);
                 }else {
                     //继续调用大模型prompt
-                    this.askBigModelForYC(tXinyiWarningRecord, tXinyiIndustry, normConfig);
+                    this.askBigModelForYC(tXinyiWarningRecord, tXinyiIndustry, normConfig, chartsDataList);
                 }
             }else{
                 log.info("{}:之前已经有过告警记录了,且还是继续报警,无需重复添加报警,但是决策仍然要调用", category);
@@ -1305,14 +1491,14 @@ public class RyTask
                         this.addChatRecordByWarning(tXinyiWarningRecord, tXinyiIndustry, normConfig);
                     }else {
                         //继续调用决策
-                        this.askBigModelForYC(xinyiWarningRecord, tXinyiIndustry, normConfig);
+                        this.askBigModelForYC(xinyiWarningRecord, tXinyiIndustry, normConfig, chartsDataList);
                     }
                 }
             }
         }
     }
 
-    private void askBigModelForYC(TXinyiWarningRecord xinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) {
+    private void askBigModelForYC(TXinyiWarningRecord xinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, List<ChartBasic> chartsDataList) {
         log.info("预测进入了后台接口调⽤⼤模型获取问答结果处理(预测)");
         StringBuilder sb = new StringBuilder();
         String sessionId = IdUtils.simpleUUID();
@@ -1359,8 +1545,7 @@ public class RyTask
             chatReq.setSessionId(sessionId);
             chatReq.setType(3);//0问答 1决策 2本地 3仿真预测
             chatReq.setModule(3);//0专家问答 1智能工单 2智能体助手 3告警 4简报
-            //todo 这里不需要再查询数据,让前端展示表格了,大模型做了该功能。
-            String showVal = this.buildShowValue(xinyiWarningRecord, tXinyiIndustry, normConfig);
+            String showVal = this.buildShowValueWithCharts(xinyiWarningRecord, tXinyiIndustry, normConfig, chartsDataList);
             chatReq.setShowVal(showVal);
             chatReq.setQuestion(shWarningPrompt);
             chatReq.setAnswer(sb.toString());
@@ -1612,7 +1797,9 @@ public class RyTask
         String s = "2022/01/01".substring(5).replace("/", "月") + "日";
         System.out.println("s = " + s);
 
-        System.out.println(new BigDecimal("1").compareTo(null));//空指针 要判断
+//        System.out.println(new BigDecimal("1").compareTo(null));//空指针 要判断
+
+        System.out.println("2022/01/01 10".substring(11));
     }
 
 

+ 3 - 0
slibra-system/src/main/java/com/slibra/business/mapper/TXinyiIndustryMapper.java

@@ -5,6 +5,7 @@ import java.util.HashMap;
 import java.util.List;
 
 import com.slibra.business.domain.TXinyiIndustry;
+import com.slibra.business.domain.TXinyiRobot;
 import com.slibra.business.req.DecisionReq;
 import org.apache.ibatis.annotations.Param;
 
@@ -79,4 +80,6 @@ public interface TXinyiIndustryMapper
     List<DecisionReq> selectLast10RecordsForDecisionOnlyIndustry();
 
     TXinyiIndustry selectTXinyiIndustryNewest();
+
+    List<TXinyiIndustry> selectNIndustry(int size);
 }

+ 2 - 0
slibra-system/src/main/java/com/slibra/business/mapper/TXinyiRobotMapper.java

@@ -64,4 +64,6 @@ public interface TXinyiRobotMapper
     List<TXinyiRobot> selectTXinyiRobotListByTime(String lastTime);
 
     TXinyiRobot selectNewest();
+
+    List<TXinyiRobot> selectNRobot(int size);
 }

+ 24 - 0
slibra-system/src/main/java/com/slibra/business/res/ChartBasic.java

@@ -0,0 +1,24 @@
+package com.slibra.business.res;
+
+
+import com.alibaba.fastjson2.annotation.JSONField;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+
+@Builder
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class ChartBasic {
+
+
+    private String time;
+
+    private BigDecimal val;
+
+
+}

+ 5 - 0
slibra-system/src/main/resources/mapper/business/TXinyiIndustryMapper.xml

@@ -519,4 +519,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectTXinyiIndustryVo"/>
         order by id desc limit 1
     </select>
+
+    <select id="selectNIndustry" resultMap="TXinyiIndustryResult">
+        <include refid="selectTXinyiIndustryVo"/>
+        order by id desc limit #{size}
+    </select>
 </mapper>

+ 4 - 0
slibra-system/src/main/resources/mapper/business/TXinyiRobotMapper.xml

@@ -240,4 +240,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectNewest" resultMap="TXinyiRobotResult">
         <include refid="selectTXinyiRobotVo"/> order by id desc limit 1
     </select>
+
+    <select id="selectNRobot" resultMap="TXinyiRobotResult">
+        <include refid="selectTXinyiRobotVo"/> order by id desc limit #{size}
+    </select>
 </mapper>