wangmiaomiao 10 сар өмнө
parent
commit
3dec6a26fa

+ 1 - 1
slibra-admin/src/main/java/com/slibra/SlibraApplication.java

@@ -16,7 +16,7 @@ public class SlibraApplication
     {
         // System.setProperty("spring.devtools.restart.enabled", "false");
         SpringApplication.run(SlibraApplication.class, args);
-        System.out.println("(♥◠‿◠)ノ゙  fuxicarbon启动成功   ლ(´ڡ`ლ)゙  \n");
+        System.out.println("(♥◠‿◠)ノ゙  slibraAI后台启动成功   ლ(´ڡ`ლ)゙  \n");
 
     }
 }

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

@@ -5,13 +5,12 @@ import cn.hutool.http.HttpRequest;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.alibaba.fastjson2.JSONWriter;
 import com.google.protobuf.ByteString;
-import com.slibra.business.domain.TXinyiIndustry;
-import com.slibra.business.domain.TXinyiNormConfig;
-import com.slibra.business.domain.TXinyiRobot;
-import com.slibra.business.domain.TXinyiWarningRecord;
+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.constant.MyConstants;
 import com.slibra.common.enums.BusinessEnum;
 import com.slibra.common.enums.DataSourceType;
@@ -32,6 +31,7 @@ import org.springframework.util.CollectionUtils;
 
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
@@ -79,6 +79,9 @@ public class RyTask
     @Autowired
     private TXinyiChatRecordMapper xinyiChatRecordMapper;
 
+    @Autowired
+    private TXinyiDailyMapper xinyiDailyMapper;
+
 
 //    public final static StopWatch watch = new StopWatch("task");
     public static final String[] queryTags = {"信义污水厂JS_COD_Value","信义污水厂JS_PH_Value","信义污水厂JS_SS_Value","信义污水厂JS_ZL_Value","信义污水厂JS_ZA_Value","信义污水厂JS_AD_Value","信义污水厂JS_T_Value","信义污水厂进水泵房液位","信义污水厂出水瞬时流量","信义污水厂升级出水COD","信义污水厂升级出水PH","信义污水厂升级出水SS","信义污水厂升级出水TN","信义污水厂升级出水TP","信义污水厂升级出水氨氮","信义污水厂AIT202_Value","信义污水厂AIT203_Value","信义污水厂AIT207_Value","信义污水厂AIT206_Value","信义污水厂AIT209_Value","信义污水厂AIT210_Value","信义污水厂进水TDS","信义污水厂FT101_Value","信义污水厂SWCHHYHLB1_R_Value","信义污水厂SWCHHYHLB2_R_Value","信义污水厂SWCHHYHLB3_R_Value","信义污水厂SWCHHYHLB4_R_Value","信义污水厂SWCHHYHLB5_R_Value","信义污水厂SWCHHYHLB6_R_Value","信义污水厂SWCWNHLB1_R_Value","信义污水厂SWCWNHLB2_R_Value","信义污水厂SWCWNHLB3_R_Value","信义污水厂SWCWNHLB4_R_Value","信义污水厂SWCWNHLB5_R_Value","信义污水厂GFJ1_R_Value","信义污水厂GFJ2_R_Value","信义污水厂GFJ3_R_Value","信义污水厂GFJ4_R_Value","信义污水厂GFJ5_R_Value","信义污水厂GFJ6_R_Value","信义污水厂GFJ1_KQLL_Value","信义污水厂GFJ2_KQLL_Value","信义污水厂GFJ3_KQLL_Value","信义污水厂GFJ4_KQLL_Value","信义污水厂GFJ5_KQLL_Value","信义污水厂GFJ6_KQLL_Value","信义污水厂实际碳源加药量","信义污水厂除磷加药瞬时流量", "信义污水厂_除磷P04预测值_"};
@@ -426,13 +429,45 @@ public class RyTask
     private void handleDecision(TXinyiWarningRecord tXinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) {
         log.info("进入了调⽤大模型决策接口");
         ChatReq chatReq = new ChatReq();
-        StringBuilder sb = new StringBuilder();
+//        StringBuilder sb = new StringBuilder();
+        //大模型结果 放入一个结合中
+        List<String> resultData = new ArrayList<>();
         //决策和问答不一样 没有历史的概念 所以sessionId都是新的  次数都是1
         String sessionId = IdUtils.simpleUUID();
         String feedback = chatReq.getFeedback();
         //决策请求的业务参数
-        List<HashMap<String, Object>> list = this.xinyiIndustryMapper.selectLast10RecordsForDecision();
-        String rows = JSON.toJSONString(list);
+//        List<HashMap<String, Object>> list = this.xinyiIndustryMapper.selectLast10RecordsForDecision();
+        //2024年5月21日15:23:07 这里不能用关联查询处理,日报要获取最新的一条而不是今日的数据。
+        List<DecisionReq> decisionReqs = this.xinyiIndustryMapper.selectLast10RecordsForDecisionOnlyIndustry();
+        if(!CollectionUtils.isEmpty(decisionReqs)){
+            for (DecisionReq decisionReq : decisionReqs) {
+                //处理日报数据
+                TXinyiDaily daily = this.xinyiDailyMapper.selectNewestData();
+                if(!Objects.isNull(daily)){
+                    decisionReq.setT(daily.getJsSw());
+                    decisionReq.setSVI(daily.getWntjzsAll());
+                    decisionReq.setSV(daily.getWncjbAll());
+                    decisionReq.setMLVSS(daily.getHfxwnndAll());
+                    decisionReq.setDO_ana(daily.getYycRjyAll());
+                    decisionReq.setDO_que(daily.getQycRjyAll());
+                    BigDecimal jsBod5 = daily.getJsBod5();
+                    decisionReq.setBOD_in(jsBod5);
+                    BigDecimal tpIn = decisionReq.getTP_in();
+                    BigDecimal tnIn = decisionReq.getTN_in();
+                    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));
+                        }
+                    }
+
+
+                }
+            }
+        }
+        String rows = JSON.toJSONString(decisionReqs, JSONWriter.Feature.WriteNulls);
         // 获取输出流
         ManagedChannel channel = null;
         String dataJson = "";
@@ -456,13 +491,16 @@ public class RyTask
                 if("complete".equals(responseStr)){
                     System.out.println("结尾语句并且是非JSON,无需处理");
                 }else{
-                    sb.append(responseStr);
+//                    sb.append(responseStr);
+                    resultData.add(responseStr);
                 }
+                // todo 类型判断处理
             }
         } catch (Exception e) {
-            throw new RuntimeException(e);
+//            throw new RuntimeException(e);
+            log.error("处理大模型推理异常,异常信息为{}", JSON.toJSONString(e));
         } finally {
-            System.out.println(sb.toString());
+            System.out.println(JSON.toJSONString(resultData));
             //保存聊天记录
             //将问答更新到数据库中
             chatReq.setSessionId(sessionId);
@@ -474,7 +512,7 @@ public class RyTask
             String showVal = this.buildShowValue(tXinyiWarningRecord, tXinyiIndustry, normConfig);
             chatReq.setShowVal(showVal);//前端展示的数据和提问的数据不一致
             chatReq.setQuestion(dataJson);
-            chatReq.setAnswer(sb.toString());
+            chatReq.setAnswer(JSON.toJSONString(resultData));
             chatReq.setWarningId(String.valueOf(tXinyiWarningRecord.getId()));
             chatReq.setCounts(1);//问答次数
 
@@ -821,6 +859,14 @@ public class RyTask
         Date date = new Date();
         System.out.println(DateUtils.differentHoursByMillisecond(date, date));
 
+        HashMap<Object, Object> map = new HashMap<>();
+        map.put("a", null);
+        map.put("b", "ab");
+        map.put("c", "");
+        map.put("d", '1');
+        System.out.println(JSON.toJSONString(map, JSONWriter.Feature.WriteNulls));
+        TXinyiIndustry tXinyiIndustry = new TXinyiIndustry();
+        System.out.println(JSON.toJSONString(tXinyiIndustry, JSONWriter.Feature.WriteNulls));
     }
 
 

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

@@ -65,4 +65,6 @@ public interface TXinyiDailyMapper
     public int deleteTXinyiDailyByIDs(Long[] IDs);
 
     HashMap<String, BigDecimal> selectAvgWater(@Param("begin") String begin, @Param("end") String end);
+
+    TXinyiDaily selectNewestData();
 }

+ 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.req.DecisionReq;
 import org.apache.ibatis.annotations.Param;
 
 /**
@@ -74,4 +75,6 @@ public interface TXinyiIndustryMapper
     String getLastMinute();
 
     List<HashMap<String, Object>> selectLast10RecordsForDecision();
+
+    List<DecisionReq> selectLast10RecordsForDecisionOnlyIndustry();
 }

+ 79 - 0
slibra-system/src/main/java/com/slibra/business/req/DecisionReq.java

@@ -0,0 +1,79 @@
+package com.slibra.business.req;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class DecisionReq {
+
+    private Long ID;
+    private String TEST_DATE;
+    private String TEST_HOUR;
+
+    private BigDecimal COD_in;
+    private BigDecimal COD_in_name;
+    private BigDecimal COD_off;
+    private BigDecimal COD_off_name;
+    private BigDecimal COD_off_con;
+    private BigDecimal TP_in;
+    private BigDecimal TP_in_name;
+    private BigDecimal TP_off;
+    private BigDecimal TP_off_name;
+    private BigDecimal TP_off_con;
+    private BigDecimal TN_in;
+    private BigDecimal TN_in_name;
+    private BigDecimal TN_off;
+    private BigDecimal TN_off_name;
+    private BigDecimal TN_off_con;
+    private BigDecimal andan_in;
+    private BigDecimal andan_in_name;
+    private BigDecimal andan_off;
+    private BigDecimal andan_off_name;
+    private BigDecimal andan_off_con;
+    private BigDecimal SS_in;
+    private BigDecimal SS_in_name;
+    private BigDecimal SS_off;
+    private BigDecimal SS_off_name;
+    private BigDecimal SS_off_con;
+    private BigDecimal TDS_in;
+    private BigDecimal TDS_in_name;
+    private BigDecimal T;
+    private BigDecimal pH;
+    private BigDecimal Q_in;
+    private BigDecimal Q_in_name;
+    private BigDecimal continuity;
+    private BigDecimal check_rise;
+    private BigDecimal time_tips;
+    private BigDecimal cs_continuity;
+    private String SVI;
+    private BigDecimal SVI_con;
+    private String SV;
+    private BigDecimal SV_con;
+    private String MLVSS;
+    private String MLSS;
+    private BigDecimal MLVSS_wentai;
+    private BigDecimal MLSS_wentai;
+    private String DO_ana;
+    private String DO_O;
+    private String DO_que;
+    private BigDecimal DO_que_wentai;
+    private BigDecimal DO_ana_wentai;
+    private BigDecimal DO_O_wentai;
+    private BigDecimal BOD_in;
+    private BigDecimal c;
+    private BigDecimal b;
+    private BigDecimal BTP_wending;
+    private BigDecimal JS_TN_wentai;
+    private BigDecimal CL_P04_YCZ;
+    private BigDecimal TP_LV;
+    private BigDecimal TP_LV_continuity;
+
+}

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

@@ -361,4 +361,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE
             TEST_DATE BETWEEN #{begin} AND #{end}
     </select>
+
+    <select id="selectNewestData" resultMap="TXinyiDailyResult">
+        <include refid="selectTXinyiDailyVo"/> order by id desc limit 1
+    </select>
 </mapper>

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

@@ -425,4 +425,66 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ORDER BY a.ID DESC
             LIMIT 10
     </select>
+
+
+    <select id="selectLast10RecordsForDecisionOnlyIndustry" resultType="com.slibra.business.req.DecisionReq">
+        SELECT
+            a.ID ID,
+            a.TEST_DATE TEST_DATE,
+            a.TEST_HOUR TEST_HOUR,
+            a.JS_COD COD_in,
+            b.JSCOD_SJZ COD_in_name,
+            a.CS_COD COD_off,
+            b.CSCOD_BZZ COD_off_name,
+            b.CSCOD_GKZ COD_off_con,
+            a.JS_TP TP_in,
+            b.JSZL_SJZ TP_in_name,
+            a.CS_TP TP_off,
+            b.CSZL_BZZ TP_off_name,
+            b.CSZL_GKZ TP_off_con,
+            a.JS_TN TN_in,
+            b.JSZD_SJZ TN_in_name,
+            a.CS_TN TN_off,
+            b.CSZZ_BZZ TN_off_name,
+            b.CSZZ_GKZ TN_off_con,
+            a.JS_NH3 andan_in,
+            b.JSAD_SJZ andan_in_name,
+            a.CS_NH3 andan_off,
+            b.CSAD_BZZ  andan_off_name,
+            b.CSAD_GKZ andan_off_con,
+            a.JS_SS SS_in,
+            b.JSSS_SJZ SS_in_name,
+            a.CS_SS SS_off,
+            b.CSSS_BZZ SS_off_name,
+            b.CSSS_GKZ  SS_off_con,
+            a.JS_TDS TDS_in,
+            b.JDTDS_GKZ TDS_in_name,
+            a.JS_PH pH,
+            a.JS_SLQ Q_in,
+            b.JSSL_SJZ Q_in_name,
+            '' continuity,
+            '' check_rise,
+            '' time_tips,
+            '' cs_continuity,
+            b.WNTJZS_GKZ SVI_con,
+            b.WNCJB_GKZ SV_con,
+            a.HYC_WNND_ALL MLSS,
+            '' MLVSS_wentai,
+            '' MLSS_wentai,
+            a.HYC_RJY_ALL DO_O,
+            '' DO_que_wentai,
+            '' DO_ana_wentai,
+            '' DO_O_wentai,
+            '' BTP_wending,
+            '' JS_TN_wentai,
+            a.CL_P04_YCZ CL_P04_YCZ,
+            (a.JS_TP - a.CL_P04_YCZ)/a.JS_TP TP_LV,
+            '' TP_LV_continuity
+        FROM
+            t_xinyi_industry a
+                LEFT JOIN t_xinyi_norm_config b on 1 = 1
+        WHERE 1 = 1
+        ORDER BY a.ID DESC
+            LIMIT 10
+    </select>
 </mapper>