|
@@ -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));
|
|
|
}
|
|
|
|
|
|
|