Преглед на файлове

一些杂七杂八的优化

wangmiaomiao преди 10 месеца
родител
ревизия
215ac29fab

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

@@ -1,20 +1,16 @@
 package com.slibra.web.controller.business;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.JSONWriter;
 import com.alibaba.fastjson2.JSON;
 import com.google.protobuf.ByteString;
-import com.qiniu.util.Json;
-import com.slibra.business.domain.TXinyiChatRecord;
-import com.slibra.business.domain.TXinyiDaily;
-import com.slibra.business.domain.TXinyiIndustry;
-import com.slibra.business.domain.TXinyiNormConfig;
+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.common.core.controller.BaseController;
-import com.slibra.common.core.domain.AjaxResult;
-import com.slibra.common.core.domain.R;
 import com.slibra.common.enums.BusinessEnum;
+import com.slibra.common.exception.ServiceException;
 import com.slibra.common.utils.DateUtils;
 import com.slibra.common.utils.SecurityUtils;
 import com.slibra.common.utils.StringUtils;
@@ -23,7 +19,6 @@ import com.slibra.common.utils.uuid.IdUtils;
 import io.grpc.ManagedChannel;
 import io.grpc.ManagedChannelBuilder;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringEscapeUtils;
 import org.pytorch.serve.grpc.inference.InferenceAPIsServiceGrpc;
 import org.pytorch.serve.grpc.inference.PredictionResponse;
 import org.pytorch.serve.grpc.inference.PredictionsRequest;
@@ -34,16 +29,13 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.nio.charset.StandardCharsets;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
 import java.util.*;
 
 import static com.slibra.common.constant.MyConstants.DEFAULT_ID_IDENTIFIER;
-import static com.slibra.common.constant.MyConstants.WARNING_DEFAULT_CREATE;
+import static com.slibra.common.enums.BusinessEnum.BigModelBizEnum.DECISION_REPORT;
 
 /**
  * 告警相关
@@ -66,6 +58,9 @@ public class GRPCController extends BaseController {
     @Autowired
     private TXinyiChatRecordMapper xinyiChatRecordMapper;
 
+    @Autowired
+    private TXinyiWarningRecordMapper xinyiWarningRecordMapper;
+
 
     /*private InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub getStub(){
         return InferenceAPIsServiceGrpc.newBlockingStub(ManagedChannelBuilder.forAddress("10.0.0.24", 17070)
@@ -82,6 +77,27 @@ public class GRPCController extends BaseController {
 //    public void decisionStream(HttpServletResponse response,  ChatReq chatReq)
     {
         log.info("进入了调⽤大模型决策接口");
+        //        response.setContentType("text/plain");
+        response.setContentType("text/event-stream");
+        response.setCharacterEncoding("utf-8");
+        //2024年5月29日14:15:58 新增逻辑,判断报警状态是否已经结束了,如果结束了就直接模拟一个report返回给前端,不再调用大模型
+        String warningId = chatReq.getWarningId();
+        if(StringUtils.isBlank(warningId))
+            throw new ServiceException("请输入正确的告警id");
+        TXinyiWarningRecord xinyiWarningRecord = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordById(Long.parseLong(warningId));
+        if(Objects.isNull(xinyiWarningRecord))
+            throw new ServiceException("请输入正确的告警id,没有查询到告警信息");
+        if(1 == xinyiWarningRecord.getStatus() || 2 == xinyiWarningRecord.getStatus()){
+            //已经关闭的报警,不允许再次点击报警了
+            String message = this.buildMsg();
+            try {
+                OutputStream outputStream = response.getOutputStream();
+                outputStream.write(message.getBytes());
+                outputStream.flush();
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
 //        StringBuilder sb = new StringBuilder();
         //大模型结果 放入一个结合中
         List<String> resultData = new ArrayList<>();
@@ -92,7 +108,6 @@ public class GRPCController extends BaseController {
         int type = 3;//仿真预测
         if(StringUtils.isBlank(simulate) || "{}".equals(simulate))
             type = 1;//决策
-        String warningId = String.valueOf(chatReq.getWarningId());
         //决策请求的业务参数
 //        List<HashMap<String, Object>> list = this.xinyiIndustryMapper.selectLast10RecordsForDecision();
         //2024年5月21日15:23:07 这里不能用关联查询处理,日报要获取最新的一条而不是今日的数据。
@@ -129,9 +144,6 @@ public class GRPCController extends BaseController {
         // 获取输出流
         OutputStream outputStream = null;
         ManagedChannel channel = null;
-//        response.setContentType("text/plain");
-        response.setContentType("text/event-stream");
-        response.setCharacterEncoding("utf-8");
         String dataJson = "";
         try {
             channel = ManagedChannelBuilder.forAddress("10.0.0.24", 17070)
@@ -182,7 +194,8 @@ public class GRPCController extends BaseController {
             log.error("处理大模型推理异常,异常信息为{}", JSON.toJSONString(e));
             //出现异常 给前端返回一句话
             try {
-                outputStream.write("大模型分析数据异常,请稍后再试".getBytes());
+                String errMsg = this.buildErrMsg();
+                outputStream.write(errMsg.getBytes());
                 outputStream.flush();
             } catch (IOException ex) {
                 throw new RuntimeException(ex);
@@ -222,11 +235,19 @@ public class GRPCController extends BaseController {
         }
     }
 
+    private String buildErrMsg() {
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("biz", DECISION_REPORT.getCode());
+        jsonObject.put("message", "大模型决策方案生成有点问题,请稍后再试");
+        return JSON.toJSONString(jsonObject);
+    }
 
-
-
-
-
+    private String buildMsg() {
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("biz", DECISION_REPORT.getCode());
+        jsonObject.put("message", "此报警已经关闭了,无法生成决策方案");
+        return JSON.toJSONString(jsonObject);
+    }
 
 
     /**

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

@@ -810,7 +810,7 @@ public class RyTask
         basic.put("管控值", tXinyiWarningRecord.getControlVal());
         basic.put("报警次数", Math.min(count, MAX_COUNT));
         if(tXinyiWarningRecord.getType() != 2)
-            basic.put("状态", status == 0 ? "警中" : status == 1 ? "用户关闭" : status == 2 ? "系统自动关闭" : "用户转为应急处理中");
+            basic.put("状态", status == 0 ? "警中" : status == 1 ? "用户关闭" : status == 2 ? "系统关闭" : "应急处理中");
         else
             basic.put("状态", status == 0 ? "预警中" : "已完成");
         //2024年5月27日14:04:22  额外返回2个字段 [管控值 和 告警级别]  返回的json没有数据是因为value没有值

+ 11 - 13
slibra-system/src/main/resources/mapper/business/TXinyiIndustryMapper.xml

@@ -427,7 +427,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
 
-    <!-- todo 以后不用sql拼接实验室数据 处理历史数据并新增字段,直接获取 另外把关联查询改成在java代码中处理 -->
+    <!-- todo 以后不用sql拼接实验室数据 处理历史数据并新增字段,直接获取 另外把关联查询改成在java代码中处理
+     不用再拼接了 SqlServer同步过来的机器人实验室数据已经有了新的字段
+     -->
     <select id="selectLast10RecordsForDecisionOnlyIndustry" resultType="com.slibra.business.req.DecisionReq">
         SELECT
             a.ID ID,
@@ -483,27 +485,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             '' tpLvContinuity,
             a.SJTYJLY tyjyl,
             a.CLJYSSLL cltjl,
-            CONCAT( "[", c.NO3_HLJ1_JQR, ",", c.NO3_HLJ2_JQR, "]" ) hycxsyAll,
-            CONCAT( "[", c.NH3_1_JQR, ",", c.NH3_2_JQR, "]" ) qyanAll,
-            CONCAT( "[", c.NO3_QYC_1_JQR, ",", c.NO3_QYC_2_JQR, "]" ) qyckxsyAll,
+            c.HYCXSY_ALL hycxsyAll,
+            c.QYAN_ALL qyanAll,
+            c.QYCKXSY_ALL qyckxsyAll,
             '' gwnl,
             c.TP_RCC_JQR eccZl,
-            CONCAT( "[", c.TP_HL1_JQR, ",", c.TP_HL2_JQR, "]" ) hyzlsyAll
+            c.HYZLSY_ALL hyzlsyAll
         FROM
             t_xinyi_industry a
                 LEFT JOIN t_xinyi_norm_config b ON 1 = 1
                 LEFT JOIN (
                 SELECT
                     TEST_HOUR,
-                    any_value ( NO3_HLJ1_JQR ) NO3_HLJ1_JQR,
-                    any_value ( NO3_HLJ2_JQR ) NO3_HLJ2_JQR,
-                    any_value ( NH3_1_JQR ) NH3_1_JQR,
-                    any_value ( NH3_2_JQR ) NH3_2_JQR,
-                    any_value ( NO3_QYC_1_JQR ) NO3_QYC_1_JQR,
-                    any_value ( NO3_QYC_2_JQR ) NO3_QYC_2_JQR,
+                    any_value ( HYCXSY_ALL ) HYCXSY_ALL,
+                    any_value ( QYAN_ALL ) QYAN_ALL,
+                    any_value ( QYCKXSY_ALL ) QYCKXSY_ALL,
                     any_value ( TP_RCC_JQR ) TP_RCC_JQR,
-                    any_value ( TP_HL1_JQR ) TP_HL1_JQR,
-                    any_value ( TP_HL2_JQR ) TP_HL2_JQR
+                    any_value ( HYZLSY_ALL ) HYZLSY_ALL
                 FROM
                     t_xinyi_robot
                 GROUP BY