RyTask.java 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  1. package com.slibra.quartz.task;
  2. import cn.hutool.core.date.DateUtil;
  3. import cn.hutool.http.HttpRequest;
  4. import cn.hutool.http.HttpUtil;
  5. import com.alibaba.fastjson2.JSON;
  6. import com.alibaba.fastjson2.JSONArray;
  7. import com.alibaba.fastjson2.JSONObject;
  8. import com.alibaba.fastjson2.JSONWriter;
  9. import com.google.protobuf.ByteString;
  10. import com.slibra.business.domain.*;
  11. import com.slibra.business.mapper.*;
  12. import com.slibra.business.req.ChatReq;
  13. import com.slibra.business.req.ChatRequest;
  14. import com.slibra.business.req.GenerateArgs;
  15. import com.slibra.business.req.PredictorRequest;
  16. import com.slibra.business.res.ChartBasic;
  17. import com.slibra.business.res.ShowValueChartBasic;
  18. import com.slibra.business.service.ITXinyiForecastComparisonService;
  19. import com.slibra.common.DecimalUtils;
  20. import com.slibra.common.config.BigModelConfig;
  21. import com.slibra.common.constant.MyConstants;
  22. import com.slibra.common.enums.BusinessEnum;
  23. import com.slibra.common.enums.DataSourceType;
  24. import com.slibra.common.utils.DateUtils;
  25. import com.slibra.common.utils.LocalDateTimeUtil;
  26. import com.slibra.common.utils.uuid.IdUtils;
  27. import com.slibra.framework.datasource.DynamicDataSourceContextHolder;
  28. import inference.InferenceAPIsServiceGrpc;
  29. import inference.PredictionResponse;
  30. import inference.PredictionsRequest;
  31. import io.grpc.ManagedChannel;
  32. import io.grpc.ManagedChannelBuilder;
  33. import lombok.extern.slf4j.Slf4j;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.stereotype.Component;
  36. import com.slibra.common.utils.StringUtils;
  37. import org.springframework.util.CollectionUtils;
  38. import java.io.IOException;
  39. import java.math.BigDecimal;
  40. import java.text.ParseException;
  41. import java.time.LocalDateTime;
  42. import java.time.format.DateTimeFormatter;
  43. import java.util.*;
  44. import java.util.concurrent.TimeUnit;
  45. import java.util.stream.Collectors;
  46. import static com.slibra.common.constant.MyConstants.*;
  47. /**
  48. * 定时任务调度测试
  49. *
  50. *
  51. */
  52. @Component("ryTask")
  53. @Slf4j
  54. public class RyTask
  55. {
  56. public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
  57. {
  58. System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
  59. }
  60. public void ryParams(String params)
  61. {
  62. System.out.println("执行有参方法:" + params);
  63. }
  64. public void ryNoParams()
  65. {
  66. System.out.println("执行无参方法");
  67. }
  68. //----------------------------------------------下面是新增的方法----------------------------------------------
  69. @Autowired
  70. private TXinyiIndustryMapper xinyiIndustryMapper;
  71. @Autowired
  72. private TXinyiRobotMapper xinyiRobotMapper;
  73. @Autowired
  74. private TXinyiNormConfigMapper xinyiNormConfigMapper;
  75. @Autowired
  76. private TXinyiWarningRecordMapper xinyiWarningRecordMapper;
  77. @Autowired
  78. private TXinyiChatRecordMapper xinyiChatRecordMapper;
  79. @Autowired
  80. private TXinyiDailyMapper xinyiDailyMapper;
  81. @Autowired
  82. private AsyncTask asyncTask;
  83. @Autowired
  84. private ITXinyiForecastComparisonService xinyiForecastComparisonService;
  85. @Autowired
  86. private BigModelConfig bigModelConfig;
  87. @Autowired
  88. private TXinyiBigTableDayMapper xinyiBigTableDayMapper;
  89. @Autowired
  90. private TXinyiBigTableMonthMapper xinyiBigTableMonthMapper;
  91. @Autowired
  92. private TXinyiBigTableHourMapper xinyiBigTableHourMapper;
  93. // public final static StopWatch watch = new StopWatch("task");
  94. 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预测值_"};
  95. /**
  96. *
  97. * 2024年6月21日14:52:05 调整逻辑:
  98. * 出水总氮 的预测:使用 (xsy1 + xsy2) /2 /0.8 做为出水总氮的结果
  99. *
  100. */
  101. // public static final String[] predictorArr = {"出水COD", "出水SS", "出水总磷", "出水氨氮"};
  102. public static final String[] predictorArr = {"出水COD", "出水SS", "出水总磷", "出水氨氮", "xsy1", "xsy2"};
  103. public static final String[] predictorArrSpecial = {"xsy1", "xsy2"};
  104. /**
  105. * 定时从工业库获取数据
  106. *
  107. * 2024年4月17日17:44:15 调整逻辑:考虑到因断电等情况导致服务断电,所以不再同步最近一小时,而是同步从上次成功的最后一条数据开始。
  108. */
  109. public void getIndustryData(){
  110. log.info("进入了定时同步工业库数据的任务");
  111. //耗时工具
  112. // watch.start("parseJob");
  113. // 给定时间段的起始时间和结束时间
  114. LocalDateTime endTime = LocalDateTime.now();
  115. // LocalDateTime startTime = endTime.plusMinutes(-60);
  116. //获取上次最后一条同步的数据的日期到 分钟维度
  117. String lastDateHour = this.xinyiIndustryMapper.getLastMinute();
  118. log.info("获取上次同步工业库的最后一条记录的时间是{}", lastDateHour);
  119. lastDateHour = lastDateHour + ":00";
  120. //开始时间
  121. LocalDateTime startTime = LocalDateTime.parse(lastDateHour.replaceAll("/", "-").replace(" ", "T"));
  122. startTime = startTime.plusMinutes(60L);//加一分钟 从上次最后一条记录的下一分钟开始
  123. /*LocalDateTime startTime = LocalDateTime.parse("2024-02-26T00:00:00");
  124. LocalDateTime endTime = LocalDateTime.parse("2024-02-27T00:00:00");*/
  125. // 每个小时的时间格式
  126. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  127. // 循环按小时分割
  128. LocalDateTime currentHour = startTime;
  129. //最终获取的数据
  130. Map<String, TXinyiIndustry> needMap = new LinkedHashMap<>();
  131. while (currentHour.isBefore(endTime)) {
  132. String begin = currentHour.format(formatter);
  133. String end = currentHour.plusMinutes(5).format(formatter);
  134. // 输出当前小时的起始时间和结束时间
  135. System.out.println("起始时间:" + begin);
  136. System.out.println("结束时间:" + end);
  137. // 当前小时加一小时,作为下一个小时的起始时间
  138. currentHour = currentHour.plusMinutes(5);
  139. //每个小时查询一次数据
  140. String url = "http://10.0.0.27:4568/api/v1/khquerydata";
  141. HashMap<String, Object> req = new HashMap<>();
  142. req.put("tagNames", queryTags);
  143. req.put("startTime", begin);
  144. req.put("endTime", end);
  145. req.put("recordNumbers", 100000);
  146. String body = HttpRequest.post(url).header("Authorization", "c2E6c2E=").header("clientName", "hongshan").body(JSON.toJSONString(req)).execute().body();
  147. // System.out.println("body = " + body);
  148. List<HashMap<String, String>> list = new ArrayList<>();
  149. //行转列数据处理
  150. for (String queryTag : queryTags) {
  151. JSONArray array = JSON.parseObject(body).getJSONArray(queryTag);
  152. //特殊数据处理一
  153. if(Objects.isNull(array) || array.isEmpty()){
  154. System.out.println(queryTag + "查询到了空的数据,跳过本次循环");
  155. continue;
  156. }
  157. int size = array.size();
  158. //特殊数据处理二
  159. if("0".equals(array.get(1) + "")){
  160. System.out.println(queryTag + "查询到了数据,但是数据集合只有一条,且都是0");
  161. continue;
  162. }
  163. //结合至少62个数据才满足条件(有可能获取不到)
  164. /*if(size < 62){
  165. System.out.println(queryTag + "查询到了不符合条件的数据,跳过本次循环");
  166. continue;
  167. }*/
  168. //存放的数据集
  169. //利用map去重
  170. HashMap<String, String> map = new LinkedHashMap<>();
  171. for (int i = 2; i < size; i++) {
  172. // System.out.println(i + "" + array.get(i));
  173. JSONArray oneRecord = JSON.parseArray(JSON.toJSONString(array.get(i)));
  174. //处理为空或者为0的数据
  175. Object timeStampValue = oneRecord.get(2);
  176. if(Objects.isNull(timeStampValue) || "0".equals(timeStampValue + ""))
  177. continue;
  178. BigDecimal value = Objects.isNull(oneRecord.get(0)) ? null : new BigDecimal(oneRecord.get(0) + "");
  179. long timestamp = (long) timeStampValue;
  180. String format = DateUtil.format(new Date(timestamp), DateUtils.YYYYMMDDHH_TS);
  181. map.put(format, queryTag + "-" + value);
  182. }
  183. list.add(map);
  184. }
  185. Set<String> recordTimeSet = new HashSet<>();
  186. Map<String, TXinyiIndustry> recordMap = new HashMap<>();
  187. for (int i = 0; i < list.size(); i++) {
  188. HashMap<String, String> map = list.get(i);
  189. int finalJ = i;
  190. map.forEach((k, v) ->{
  191. TXinyiIndustry industry = null;
  192. if(!recordTimeSet.contains(k)){//第一次
  193. industry = new TXinyiIndustry();
  194. recordTimeSet.add(k);
  195. recordMap.put(k, industry);
  196. }else{
  197. industry = recordMap.get(k);
  198. }
  199. industry.setTestTime(k + ":00");
  200. //2024年4月15日11:19:52 额外增加2个字段
  201. industry.setTestDate(k.substring(0,10));
  202. industry.setTestHour(k.substring(0,13));
  203. //解析值
  204. String[] split = v.split("-");
  205. String type = split[0];
  206. BigDecimal value = new BigDecimal(split[1]);
  207. if ("信义污水厂JS_COD_Value".equals(type)) {
  208. industry.setJsCod(value);
  209. } else if ("信义污水厂JS_PH_Value".equals(type)) {
  210. industry.setJsPh(value);
  211. } else if ("信义污水厂JS_SS_Value".equals(type)) {
  212. // log.info("************----------真实的进水SS的值为{}\n时间为{}", value, k);
  213. industry.setJsSs(value);
  214. } else if ("信义污水厂JS_ZL_Value".equals(type)) {
  215. industry.setJsTp(value);
  216. } else if ("信义污水厂JS_ZA_Value".equals(type)) {
  217. industry.setJsTn(value);
  218. } else if ("信义污水厂JS_AD_Value".equals(type)) {
  219. industry.setJsNh3(value);
  220. } else if ("信义污水厂JS_T_Value".equals(type)) {
  221. industry.setJsSwPh(value);
  222. } else if ("信义污水厂进水泵房液位".equals(type)) {
  223. industry.setJsBfyw(value);
  224. } else if ("信义污水厂出水瞬时流量".equals(type)) {
  225. industry.setCsSlqc(value);
  226. } else if ("信义污水厂升级出水COD".equals(type)) {
  227. industry.setCsCod(value);
  228. } else if ("信义污水厂升级出水PH".equals(type)) {
  229. industry.setCsPh(value);
  230. } else if ("信义污水厂升级出水SS".equals(type)) {
  231. industry.setCsSs(value);
  232. } else if ("信义污水厂升级出水TN".equals(type)) {
  233. // log.info("************----------真实的出水总氮的值为{}\n时间为{}", value, k);
  234. // industry.setCsTn(new BigDecimal(17));
  235. industry.setCsTn(value);
  236. } else if ("信义污水厂升级出水TP".equals(type)) {
  237. industry.setCsTp(value);
  238. } else if ("信义污水厂升级出水氨氮".equals(type)) {
  239. industry.setCsNh3(value);
  240. } else if ("信义污水厂AIT202_Value".equals(type)) {
  241. industry.setOneHyzdDo(value);
  242. } else if ("信义污水厂AIT203_Value".equals(type)) {
  243. industry.setOneHymdDo(value);
  244. } else if ("信义污水厂AIT207_Value".equals(type)) {
  245. industry.setTwoHyzdDo(value);
  246. } else if ("信义污水厂AIT206_Value".equals(type)) {
  247. industry.setTwoHymdDo(value);
  248. } else if ("信义污水厂AIT209_Value".equals(type)) {
  249. industry.setOneMlss(value);
  250. } else if ("信义污水厂AIT210_Value".equals(type)) {
  251. industry.setTwoMlss(value);
  252. } else if ("信义污水厂进水TDS".equals(type)) {
  253. industry.setJsTds(value);
  254. } else if ("信义污水厂FT101_Value".equals(type)) {
  255. industry.setJsSlq(value);
  256. } else if ("信义污水厂SWCHHYHLB1_R_Value".equals(type)) {
  257. industry.setNHlbOneGp(value);
  258. } else if ("信义污水厂SWCHHYHLB2_R_Value".equals(type)) {
  259. industry.setNHlbTwoGp(value);
  260. } else if ("信义污水厂SWCHHYHLB3_R_Value".equals(type)) {
  261. industry.setNHlbThreeGp(value);
  262. } else if ("信义污水厂SWCHHYHLB4_R_Value".equals(type)) {
  263. industry.setNHlbFourGp(value);
  264. } else if ("信义污水厂SWCHHYHLB5_R_Value".equals(type)) {
  265. industry.setNhlBFiveGp(value);
  266. } else if ("信义污水厂SWCHHYHLB6_R_Value".equals(type)) {
  267. industry.setNHlbSixGp(value);
  268. } else if ("信义污水厂SWCWNHLB1_R_Value".equals(type)) {
  269. industry.setWHlbOneGp(value);
  270. } else if ("信义污水厂SWCWNHLB2_R_Value".equals(type)) {
  271. industry.setWHlbTwoGp(value);
  272. } else if ("信义污水厂SWCWNHLB3_R_Value".equals(type)) {
  273. industry.setWHlbThreeGp(value);
  274. } else if ("信义污水厂SWCWNHLB4_R_Value".equals(type)) {
  275. industry.setWHlbFourGp(value);
  276. } else if ("信义污水厂SWCWNHLB5_R_Value".equals(type)) {
  277. industry.setWHlbFiveGp(value);
  278. } else if ("信义污水厂GFJ1_R_Value".equals(type)) {
  279. industry.setFjOne(value);
  280. } else if ("信义污水厂GFJ2_R_Value".equals(type)) {
  281. industry.setFjTwo(value);
  282. } else if ("信义污水厂GFJ3_R_Value".equals(type)) {
  283. industry.setFjThree(value);
  284. } else if ("信义污水厂GFJ4_R_Value".equals(type)) {
  285. industry.setFjFour(value);
  286. } else if ("信义污水厂GFJ5_R_Value".equals(type)) {
  287. industry.setFjFive(value);
  288. } else if ("信义污水厂GFJ6_R_Value".equals(type)) {
  289. industry.setFjSix(value);
  290. } else if ("信义污水厂GFJ1_KQLL_Value".equals(type)) {
  291. industry.setKqllOne(value);
  292. } else if ("信义污水厂GFJ2_KQLL_Value".equals(type)) {
  293. industry.setKqllTwo(value);
  294. } else if ("信义污水厂GFJ3_KQLL_Value".equals(type)) {
  295. industry.setKqllThree(value);
  296. } else if ("信义污水厂GFJ4_KQLL_Value".equals(type)) {
  297. industry.setKqllFour(value);
  298. } else if ("信义污水厂GFJ5_KQLL_Value".equals(type)) {
  299. industry.setKqllFive(value);
  300. } else if ("信义污水厂GFJ6_KQLL_Value".equals(type)) {
  301. industry.setKqllSix(value);
  302. }else if ("信义污水厂实际碳源加药量".equals(type)) {
  303. industry.setSJTYJLY(value);
  304. }else if ("信义污水厂除磷加药瞬时流量".equals(type)) {
  305. industry.setCLJYSSLL(value);
  306. } else if ("信义污水厂_除磷P04预测值_".equals(type)) {
  307. industry.setCLP04YCZ(value);
  308. }
  309. //只有最后一次才执行数据库添加
  310. if(finalJ == list.size()-1){
  311. needMap.put(industry.getTestHour(), industry);
  312. }
  313. });
  314. }
  315. }
  316. //保存数据 触发告警 决策 问答记录等等
  317. needMap.forEach((k, industry) ->{
  318. //2024年4月22日15:45:24 额外保存两个字段 数组
  319. List<BigDecimal> extraList = new ArrayList<>();
  320. extraList.add(industry.getOneHymdDo());
  321. extraList.add(industry.getTwoHymdDo());
  322. industry.setHycRjyAll(JSON.toJSONString(extraList));
  323. extraList.clear();
  324. extraList.add(industry.getOneHyzdDo());
  325. extraList.add(industry.getTwoHyzdDo());
  326. industry.setHycRjyZdAll(JSON.toJSONString(extraList));
  327. extraList.clear();
  328. extraList.add(industry.getOneMlss());
  329. extraList.add(industry.getTwoMlss());
  330. industry.setHycWnndAll(JSON.toJSONString(extraList));
  331. //插入数据库
  332. xinyiIndustryMapper.insertTXinyiIndustry(industry);
  333. //判断是否触发告警、接触告警、保存决策等等
  334. // this.handleWarning(industry);
  335. //2024年5月30日18:29:20 改为异步处理
  336. asyncTask.handleWarning(industry);
  337. });
  338. //执行完成 测试执行时间
  339. //计时结束
  340. // watch.stop();
  341. // System.out.println(watch.getLastTaskName() + " 执行耗时:" + watch.getLastTaskTimeMillis() + " ms");
  342. }
  343. private String buildShowValueDeviceErr(TXinyiWarningRecord tXinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) {
  344. JSONObject result = new JSONObject();
  345. JSONObject basic = new JSONObject();
  346. Integer status = tXinyiWarningRecord.getStatus();
  347. Date warningTime = tXinyiWarningRecord.getTime();
  348. int count = DateUtils.differentHoursByMillisecond(warningTime, DateUtils.getNowDate()) + 1;
  349. basic.put("title", tXinyiWarningRecord.getReason());
  350. basic.put("报警时间", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM ,warningTime));
  351. basic.put("报警值", DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getWarningVal(), INT_2));
  352. basic.put("标准值", DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getDesignVal(), INT_2));
  353. basic.put("管控值", DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getControlVal(), INT_2));
  354. basic.put("报警次数", Math.min(count, MAX_COUNT));
  355. if(tXinyiWarningRecord.getType() != 2)
  356. basic.put("状态", status == 0 ? "报警中" : status == 1 ? "用户关闭" : status == 2 ? "系统关闭" : "应急处理中");
  357. else
  358. basic.put("状态", status == 0 ? "预警中" : "已完成");
  359. //2024年5月27日14:04:22 额外返回2个字段 [管控值 和 告警级别] 返回的json没有数据是因为value没有值
  360. // basic.put("管控值", tXinyiWarningRecord.getControlVal());
  361. basic.put("告警级别", tXinyiWarningRecord.getLevel());
  362. result.put("basic", basic);
  363. JSONObject jsData = getJsonObject(tXinyiIndustry, normConfig);//进水数据
  364. result.put("jsData", jsData);
  365. JSONObject csData = getCsonObject(tXinyiIndustry, normConfig);//出水数据
  366. result.put("csData", csData);
  367. return JSON.toJSONString(result, JSONWriter.Feature.WriteNulls);
  368. }
  369. /**
  370. * 带图形的构建展示数据
  371. *
  372. * @param tXinyiWarningRecord
  373. * @param tXinyiIndustry
  374. * @param normConfig
  375. * @param date
  376. * @param yjHour
  377. * @param nowDate
  378. * @return
  379. */
  380. private String buildShowValueWithCharts(TXinyiWarningRecord tXinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, List<ChartBasic> chartsDataList, String date, String yjHour, Date nowDate) {
  381. JSONObject result = new JSONObject();
  382. // JSONObject basic = new JSONObject();
  383. Integer status = tXinyiWarningRecord.getStatus();
  384. /*Date warningTime = tXinyiWarningRecord.getTime();
  385. String remark = tXinyiWarningRecord.getRemark();
  386. int count = DateUtils.differentHoursByMillisecond(warningTime, DateUtils.getNowDate()) + 1;*/
  387. ShowValueChartBasic showValueChartBasic = new ShowValueChartBasic();
  388. /*if("0".equals(remark)){//水质报警
  389. showValueChartBasic.setH("在线仪表");
  390. }else if("1".equals(remark)){//生化报警
  391. showValueChartBasic.setH("在线仪表");
  392. }else if("2".equals(remark)){//预测报错
  393. showValueChartBasic.setH("预测");
  394. }else {//机器人化验室报警
  395. showValueChartBasic.setH("连续监测");
  396. }*/
  397. //通用的
  398. // showValueBasic.setA(tXinyiWarningRecord.getReason());
  399. //2024年6月23日17:01:30 预警时间改成当前时间
  400. showValueChartBasic.setB(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, nowDate));
  401. showValueChartBasic.setC(date + " " + yjHour);//预计超标时间
  402. showValueChartBasic.setD(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getWarningVal(), INT_2));//改成现在值 不是报警时候的值(在发现存在告警记录的时候更新)
  403. showValueChartBasic.setE(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getForecastVal(), INT_2));//改成预测值 不是报警时候的值(在发现存在告警记录的时候更新)
  404. showValueChartBasic.setF(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getControlVal(), INT_2));
  405. showValueChartBasic.setG(DecimalUtils.getAbsAndScale(tXinyiWarningRecord.getDesignVal(), INT_2));
  406. // showValueChartBasic.setH(Math.min(count, MAX_COUNT));
  407. if(tXinyiWarningRecord.getType() != 2)
  408. showValueChartBasic.setI(status == 0 ? "报警中" : status == 1 ? "用户关闭" : status == 2 ? "系统关闭" : "应急处理中");
  409. else
  410. showValueChartBasic.setI(status == 0 ? "预警中" : "已完成");
  411. result.put("basic", showValueChartBasic);
  412. JSONObject jsData = getJsonObject(tXinyiIndustry, normConfig);//进水数据
  413. result.put("jsData", jsData);
  414. JSONObject csData = getCsonObject(tXinyiIndustry, normConfig);//出水数据
  415. result.put("csData", csData);
  416. // JSONObject chartsData = getChartsCsonObject(tXinyiIndustry, normConfig);//图表数据 因为展示不同,所以要传过来或者判断
  417. result.put("chartsData", chartsDataList);
  418. result.put("chartsTitle", tXinyiWarningRecord.getCategory() + "数据趋势图");
  419. return JSON.toJSONString(result, JSONWriter.Feature.WriteNulls);
  420. }
  421. private static JSONObject getJsonObject(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) {
  422. JSONObject jsData = new JSONObject();
  423. HashMap<Object, Object> temp1 = new HashMap<>();
  424. BigDecimal jsSlq = tXinyiIndustry.getJsSlq();
  425. temp1.put("value", DecimalUtils.getAbsAndScale(jsSlq, INT_2));
  426. temp1.put("exceed", jsSlq.compareTo(normConfig.getJsslSjz()) >0);
  427. jsData.put("流量", temp1);
  428. HashMap<Object, Object> temp2 = new HashMap<>();
  429. BigDecimal jsCod = tXinyiIndustry.getJsCod();
  430. temp2.put("value", DecimalUtils.getAbsAndScale(jsCod, INT_2));
  431. temp2.put("exceed", jsCod.compareTo(normConfig.getJscodSjz()) > 0);
  432. jsData.put("COD", temp2);
  433. HashMap<Object, Object> temp3 = new HashMap<>();
  434. BigDecimal jsNh3 = tXinyiIndustry.getJsNh3();
  435. temp3.put("value", DecimalUtils.getAbsAndScale(jsNh3, INT_2));
  436. temp3.put("exceed", jsNh3.compareTo(normConfig.getJsadSjz()) > 0);
  437. jsData.put("NH3-N", temp3);
  438. HashMap<Object, Object> temp4 = new HashMap<>();
  439. BigDecimal jsTp = tXinyiIndustry.getJsTp();
  440. temp4.put("value", DecimalUtils.getAbsAndScale(jsTp, INT_2));
  441. temp4.put("exceed", jsTp.compareTo(normConfig.getJszlSjz()) > 0);
  442. jsData.put("TP", temp4);
  443. HashMap<Object, Object> temp5 = new HashMap<>();
  444. BigDecimal jsSs = tXinyiIndustry.getJsSs();
  445. temp5.put("value", DecimalUtils.getAbsAndScale(jsSs, INT_2));
  446. temp5.put("exceed", jsSs.compareTo(normConfig.getJsssSjz()) > 0);
  447. jsData.put("SS", temp5);
  448. HashMap<Object, Object> temp6 = new HashMap<>();
  449. BigDecimal jsTn = tXinyiIndustry.getJsTn();
  450. temp6.put("value", DecimalUtils.getAbsAndScale(jsTn, INT_2));
  451. temp6.put("exceed", jsTn.compareTo(normConfig.getJszdSjz()) > 0);
  452. jsData.put("TN", temp6);
  453. return jsData;
  454. }
  455. private static JSONObject getCsonObject(TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) {
  456. JSONObject csData = new JSONObject();
  457. HashMap<Object, Object> temp1 = new HashMap<>();
  458. BigDecimal csSlq = tXinyiIndustry.getCsSlqc();
  459. temp1.put("value", DecimalUtils.getAbsAndScale(csSlq, INT_2));
  460. temp1.put("exceed", false);//出水水量没有管控值
  461. csData.put("流量", temp1);
  462. HashMap<Object, Object> temp2 = new HashMap<>();
  463. BigDecimal csCod = tXinyiIndustry.getCsCod();
  464. temp2.put("value", DecimalUtils.getAbsAndScale(csCod, INT_2));
  465. temp2.put("exceed", csCod.compareTo(normConfig.getCscodGkz()) > 0);
  466. csData.put("COD", temp2);
  467. HashMap<Object, Object> temp3 = new HashMap<>();
  468. BigDecimal csNh3 = tXinyiIndustry.getCsNh3();
  469. temp3.put("value", DecimalUtils.getAbsAndScale(csNh3, INT_2));
  470. temp3.put("exceed", csNh3.compareTo(normConfig.getCsadGkz()) > 0);
  471. csData.put("NH3-N", temp3);
  472. HashMap<Object, Object> temp4 = new HashMap<>();
  473. BigDecimal csTp = tXinyiIndustry.getCsTp();
  474. temp4.put("value", DecimalUtils.getAbsAndScale(csTp, INT_2));
  475. temp4.put("exceed", csTp.compareTo(normConfig.getCszlGkz()) > 0);
  476. csData.put("TP", temp4);
  477. HashMap<Object, Object> temp5 = new HashMap<>();
  478. BigDecimal csSs = tXinyiIndustry.getCsSs();
  479. temp5.put("value", DecimalUtils.getAbsAndScale(csSs, INT_2));
  480. temp5.put("exceed", csSs.compareTo(normConfig.getCsssGkz()) > 0);
  481. csData.put("SS", temp5);
  482. HashMap<Object, Object> temp6 = new HashMap<>();
  483. BigDecimal csTn = tXinyiIndustry.getCsTn();
  484. temp6.put("value", DecimalUtils.getAbsAndScale(csTn, INT_2));
  485. temp6.put("exceed", csTn.compareTo(normConfig.getCszzGkz()) > 0);
  486. csData.put("TN", temp6);
  487. return csData;
  488. }
  489. private void addChatRecordByDeviceErr(TXinyiWarningRecord tXinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig) {
  490. ChatReq chatReq = new ChatReq();
  491. //保存聊天记录
  492. //将问答更新到数据库中
  493. chatReq.setSessionId(IdUtils.simpleUUID());
  494. chatReq.setType(1);//0问答 1决策 2本地 3仿真预测
  495. chatReq.setModule(3);
  496. /*String userId = SecurityUtils.getUserId().toString();
  497. String username = SecurityUtils.getUsername();*/
  498. chatReq.setUserId(WARNING_DEFAULT_CREATE);
  499. String showVal = this.buildShowValueDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig);
  500. chatReq.setShowVal(showVal);//前端展示的数据和提问的数据不一致
  501. chatReq.setQuestion(WARNING_DEFAULT_QUESTION);//本地问题
  502. chatReq.setAnswer(tXinyiWarningRecord.getReason() + ",请检查设备是否正常运行");
  503. chatReq.setWarningId(String.valueOf(tXinyiWarningRecord.getId()));
  504. chatReq.setCounts(1);//问答次数
  505. chatReq.setCreateBy(WARNING_DEFAULT_CREATE);
  506. chatReq.setCreateTime(DateUtils.getNowDate());
  507. this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq);
  508. }
  509. /**
  510. * 定时从sqlserver获取数据
  511. */
  512. public void sqlserverData(){
  513. log.info("进入了定时同步SqlServer的任务");
  514. //主库获取上次最新的同步日期
  515. String lastTime = this.xinyiRobotMapper.selectLastTime();
  516. log.info("上次同步的日期是{}", lastTime);
  517. //从
  518. DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
  519. List<TXinyiRobot> tXinyiRobots = xinyiRobotMapper.selectTXinyiRobotListByTime(lastTime);
  520. DynamicDataSourceContextHolder.clearDataSourceType();
  521. // System.out.println(JSON.toJSONString(tXinyiRobots));
  522. // System.out.println("-------------");
  523. //主
  524. List<TXinyiRobot> needHandleList = new ArrayList<>();
  525. if(!CollectionUtils.isEmpty(tXinyiRobots)){
  526. for (TXinyiRobot tXinyiRobot : tXinyiRobots) {
  527. String date = handleDate(tXinyiRobot.getVDate().replaceAll(" ", ""));//有空格
  528. String time = handleDate(tXinyiRobot.getVTime().replaceAll(" ", ""));//有空格
  529. tXinyiRobot.setVDate(date);
  530. tXinyiRobot.setVTime(time);
  531. tXinyiRobot.setVDateTime(date + " " + time);
  532. //处理给前端展示的字段
  533. tXinyiRobot.setTestDate(date);//日期
  534. tXinyiRobot.setTestHour(date + " " + time.substring(0, 2));//小时
  535. tXinyiRobot.setTestTime(date + " " + time.substring(0, 5));//分钟
  536. tXinyiRobot.setCreatedTime(new Date());
  537. //2024年5月29日10:33:32 额外处理几个新增的字段 多个池子数据合并一个
  538. List<BigDecimal> extraList = new ArrayList<>();
  539. extraList.add(tXinyiRobot.getNo3Hlj1Jqr());
  540. extraList.add(tXinyiRobot.getNo3Hlj2Jqr());
  541. tXinyiRobot.setHycxsyAll(JSON.toJSONString(extraList));
  542. extraList.clear();
  543. extraList.add(tXinyiRobot.getNh31Jqr());
  544. extraList.add(tXinyiRobot.getNh32Jqr());
  545. tXinyiRobot.setQyanAll(JSON.toJSONString(extraList));
  546. extraList.clear();
  547. extraList.add(tXinyiRobot.getNo3Qyc1Jqr());
  548. extraList.add(tXinyiRobot.getNo3Qyc2Jqr());
  549. tXinyiRobot.setQyckxsyAll(JSON.toJSONString(extraList));
  550. extraList.clear();
  551. extraList.add(tXinyiRobot.getTpHl1Jqr());
  552. extraList.add(tXinyiRobot.getTpHl2Jqr());
  553. tXinyiRobot.setHyzlsyAll(JSON.toJSONString(extraList));
  554. //按照小时填充集合 然后处理报警相关逻辑
  555. //2024年6月17日13:32:59 因为机器人化验室数据基本几个小时的都一致 改成一小时取一次
  556. needHandleList.add(tXinyiRobot);
  557. // this.xinyiRobotMapper.insertTXinyiRobot(tXinyiRobot);
  558. }
  559. }
  560. if(!CollectionUtils.isEmpty(needHandleList)){
  561. List<TXinyiRobot> uniqueList = needHandleList.stream()
  562. .collect(Collectors.collectingAndThen(
  563. Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TXinyiRobot::getTestHour))),
  564. ArrayList::new
  565. ));
  566. if(!CollectionUtils.isEmpty(uniqueList))
  567. for (TXinyiRobot tXinyiRobot : uniqueList) {
  568. //判断是否添加过了(小时)
  569. String testHour = tXinyiRobot.getTestHour();
  570. List<TXinyiRobot> tXinyiRobotList = this.xinyiRobotMapper.selectTXinyiRobotList(TXinyiRobot.builder().testHour(testHour).build());
  571. if(CollectionUtils.isEmpty(tXinyiRobotList)){
  572. this.xinyiRobotMapper.insertTXinyiRobot(tXinyiRobot);
  573. //2024年6月18日10:45:20 额外计算一下预测的准确度
  574. asyncTask.updateForecastComparisonByRobot(tXinyiRobot);
  575. //2024年7月6日10:32:36 大宽表的数据处理
  576. asyncTask.updateBigTableHourByRobot(tXinyiRobot);
  577. }
  578. else
  579. log.info("{}已经吧保存过了,无需重复保存***&&&···", testHour);
  580. }
  581. asyncTask.handleRobotWarning(uniqueList);
  582. }
  583. }
  584. /**
  585. *
  586. * 定时生成每日简报数据
  587. *
  588. */
  589. public void generateShortReport(){
  590. log.info("进入了定时生成每日简报数据");
  591. List<TXinyiDaily> dailyTwoRecords = this.xinyiDailyMapper.selectNRecords(DAILY_REPORT_COUNT_RECORD);
  592. //正常不会有这种问题 因为日报有很多条
  593. if(CollectionUtils.isEmpty(dailyTwoRecords) || dailyTwoRecords.size() < DAILY_REPORT_COUNT_RECORD){
  594. log.error("进入了定时生成每日简报数据 获取最新的{}条数据不足,终止", DAILY_REPORT_COUNT_RECORD);
  595. return;
  596. }
  597. //暂时不考虑因为没有填写日报 导致生成重复数据的问题(后续需要的话再添加)
  598. //处理数据 并 拼装
  599. String queryData = buildShortReportQueryDataNew(dailyTwoRecords);
  600. // log.info("定时生成简报,组装好的请求大模型的参数为:{}", queryData);
  601. if(StringUtils.isBlank(queryData)){
  602. log.error("无法拼装请求数据!!!!!!");
  603. return;
  604. }
  605. String showVal = formateDateStr(dailyTwoRecords.get(0).getTestDate()) + JIAN_BAO_END;
  606. //调用模型 并保存结果
  607. this.askBigModel(queryData, showVal);
  608. log.info("定时生成简报任务结束~~~~~~~~~~~~~~");
  609. }
  610. /**
  611. *
  612. * 每小时发一一次预测
  613. *
  614. */
  615. public void predictor(){
  616. //获取最新的6条工业科数据
  617. List<TXinyiIndustry> tXinyiIndustries6 = this.xinyiIndustryMapper.selectNIndustry(6);
  618. List<TXinyiRobot> tXinyiRobots6 = this.xinyiRobotMapper.selectNRobot(6);
  619. //先处理xsy1 和 xsy2 合并成一个数据
  620. // this.predictorSpecial(tXinyiIndustries6, tXinyiRobots6);
  621. //2024年7月11日16:55:27 xsy1 和 xsy2 又不合并了。。。 再次分开处理
  622. for (int i = 0; i < predictorArr.length; i++) {
  623. String result = getPredictor(predictorArr[i]);
  624. if(StringUtils.isBlank(result) || "error".equals(result)){
  625. log.info("预测数据返回结果不符合解析条件,返回结果为{}", result);
  626. continue;
  627. }
  628. JSONObject jsonObject = null;
  629. try {
  630. jsonObject = JSON.parseObject(result);
  631. } catch (Exception e) {
  632. log.error("[转JSON的时候]预测数据返回结果不符合解析条件,返回结果为{}", result);
  633. continue;
  634. }
  635. log.info("^^^^^^^^^^^^^预测接口转弯JSON对象后,原内容是{}", JSON.toJSONString(jsonObject));
  636. //2024年7月8日15:25:51 加个校验 因为各种奇葩返回。。 比如返回的结果是 "null"
  637. if(Objects.isNull(jsonObject)){
  638. log.error("[转JSON的时候]预测数据返回结果是null,不处里");
  639. continue;
  640. }
  641. String task = jsonObject.getString("task");
  642. String hour = jsonObject.getString("hour");
  643. String pred = jsonObject.getString("pred");
  644. String date = jsonObject.getString("date");
  645. if(StringUtils.isNotBlank(pred) && pred.contains(",")){
  646. String[] split = pred.split(",");
  647. if(split.length != 3){
  648. log.error("预测数据返回结果为{},长度不是3,无法正常解析", result);
  649. //因为部分预测还不支持 所以不需要
  650. // handleXinYiWarningsYC(cscodBzz, split, cscodGkz, BusinessEnum.WarningCategoryEnum.CS_COD_YC.getCode(), hour, normConfig);
  651. continue;
  652. }
  653. //解析数据 处理报警 调研prompt 保存等
  654. this.handlePredictorWarning(split, hour, task, tXinyiIndustries6, tXinyiRobots6, date);
  655. }else {
  656. log.error("预测数据返回结果为{},无法正常解析", result);
  657. }
  658. }
  659. }
  660. /**
  661. *
  662. * 每天定时计算天维度的数据
  663. *
  664. */
  665. public void bigModelDayHandle(){
  666. log.info("进入了定时处理 按天维度的大表数据 处理");
  667. //获取昨日的统计数据
  668. TXinyiBigTableDay xinyiBigTableDay = this.xinyiBigTableDayMapper.selectAvgByDay(LocalDateTimeUtil.getCurrentDate().plusDays(-1).format(DateTimeFormatter.ofPattern(DateUtils.YYYYMMDD_TS)));
  669. //保存到插入对象
  670. //插入到数据库
  671. if(!Objects.isNull(xinyiBigTableDay))
  672. this.xinyiBigTableDayMapper.insertTXinyiBigTableDay(xinyiBigTableDay);
  673. }
  674. /**
  675. *
  676. * 每个月第一天定时计算月度维度的数据
  677. *
  678. */
  679. public void bigModelMonthHandle(){
  680. log.info("进入了 每个月第一天定时计算月度维度的数据 处理");
  681. //获取上个月的第一天和最后一天(定时任务是某个月第一天开始执行的 所以减7天,肯定是上个月的数据)
  682. LocalDateTime lastMonthDateTime = LocalDateTime.now().plusDays(-7);
  683. String begin = LocalDateTimeUtil.getMonthFirst(lastMonthDateTime).format(DateTimeFormatter.ofPattern(DateUtils.YYYYMMDD_TS));
  684. String end = LocalDateTimeUtil.getMonthLast(lastMonthDateTime).format(DateTimeFormatter.ofPattern(DateUtils.YYYYMMDD_TS));
  685. //获取昨日的统计数据
  686. TXinyiBigTableMonth xinyiBigTableMonth = this.xinyiBigTableMonthMapper.selectAvgByMonth(begin, end);
  687. //保存到插入对象
  688. //插入到数据库
  689. if(!Objects.isNull(xinyiBigTableMonth)){
  690. //先把日期处理一下 处理成只要月份的
  691. xinyiBigTableMonth.setTestDate(xinyiBigTableMonth.getTestDate().substring(0, 7));
  692. this.xinyiBigTableMonthMapper.insertTXinyiBigTableMonth(xinyiBigTableMonth);
  693. }
  694. }
  695. private void predictorSpecial(List<TXinyiIndustry> tXinyiIndustries6, List<TXinyiRobot> tXinyiRobots6) {
  696. //数据1
  697. String result1 = getPredictor(predictorArrSpecial[0]);
  698. if(StringUtils.isBlank(result1) || "error".equals(result1)){
  699. log.info("预测数据返回结果不符合解析条件,返回结果为{}", result1);
  700. return;
  701. }
  702. JSONObject jsonObject1 = null;
  703. try {
  704. jsonObject1 = JSON.parseObject(result1);
  705. } catch (Exception e) {
  706. log.error("[转JSON的时候]预测数据返回结果不符合解析条件,返回结果为{}", result1);
  707. return;
  708. }
  709. String hour1 = jsonObject1.getString("hour");
  710. String pred1 = jsonObject1.getString("pred");
  711. String date1 = jsonObject1.getString("date");
  712. //数据2
  713. String result2 = getPredictor(predictorArrSpecial[1]);
  714. if(StringUtils.isBlank(result2) || "error".equals(result2)){
  715. log.info("预测数据返回结果不符合解析条件,返回结果为{}", result2);
  716. return;
  717. }
  718. JSONObject jsonObject2 = null;
  719. try {
  720. jsonObject2 = JSON.parseObject(result2);
  721. } catch (Exception e) {
  722. log.error("[转JSON的时候]预测数据返回结果不符合解析条件,返回结果为{}", result2);
  723. return;
  724. }
  725. String pred2 = jsonObject2.getString("pred");
  726. if(StringUtils.isNotBlank(pred1) && pred1.contains(",") && StringUtils.isNotBlank(pred2) && pred2.contains(",")){
  727. String[] split1 = pred1.split(",");
  728. String[] split2 = pred2.split(",");
  729. if(split1.length != 3 || split2.length != 3){
  730. return;
  731. }
  732. //构建两个的平均值
  733. String[] splitNew = new String[3];
  734. for (int i = 0; i < split1.length; i++) {
  735. splitNew[i] = String.valueOf((Double.parseDouble(split1[i]) + Double.parseDouble(split2[i]))/2/0.8);
  736. }
  737. // log.info("取完平均值再组装的数组为{}", Arrays.toString(splitNew));
  738. //解析数据 处理报警 调研prompt 保存等
  739. this.handlePredictorWarningSpecialTn(splitNew, hour1, "tn", tXinyiIndustries6, tXinyiRobots6, date1);
  740. }else {
  741. log.error("预测数据返回结果为{}和{},无法正常解析", result1, result2);
  742. }
  743. }
  744. private void handlePredictorWarningSpecialTn(String[] split, String hour, String task, List<TXinyiIndustry> tXinyiIndustries6, List<TXinyiRobot> tXinyiRobots6, String date) {
  745. String[] hours = hour.split(",");
  746. //2024年6月23日18:28:55 因为存在跨天问题 所以日期也是逗号拼接的
  747. String[] dates = date.split(",");
  748. //2024年6月18日13:41:10 统一格式,否则查询不到结果
  749. //2024年6月18日10:36:49 增加预测记录,预测准确度计算等
  750. TXinyiForecastComparison tXinyiForecastComparison = new TXinyiForecastComparison();
  751. tXinyiForecastComparison.setCategory(task);
  752. tXinyiForecastComparison.setForecastTimeOne(dates[0].replaceAll("-", "/") + " " + hours[0]);
  753. tXinyiForecastComparison.setForecastTimeTwo(dates[1].replaceAll("-", "/") + " " + hours[1]);
  754. tXinyiForecastComparison.setForecastTimeThree(dates[2].replaceAll("-", "/") + " " + hours[2]);
  755. tXinyiForecastComparison.setHsForecastOne(new BigDecimal(split[0]));
  756. tXinyiForecastComparison.setHsForecastTwo(new BigDecimal(split[1]));
  757. tXinyiForecastComparison.setHsForecastThree(new BigDecimal(split[2]));
  758. //2024年6月20日14:28:31 增加字段,方便查询
  759. tXinyiForecastComparison.setRemark(DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYYMMDDHH_TS));
  760. //防止工业库挂掉以后持续预测同一数据
  761. //2024年6月20日14:59:23 因为预测bug 判断是否生成过了否则不生成
  762. String remark = tXinyiForecastComparison.getRemark();
  763. String category = tXinyiForecastComparison.getCategory();
  764. TXinyiForecastComparison tXinyiForecastComparisonReq = new TXinyiForecastComparison();
  765. tXinyiForecastComparisonReq.setRemark(remark);
  766. tXinyiForecastComparisonReq.setCategory(category);
  767. List<TXinyiForecastComparison> tXinyiForecastComparisons = this.xinyiForecastComparisonService.selectTXinyiForecastComparisonList(tXinyiForecastComparisonReq);
  768. if(!CollectionUtils.isEmpty(tXinyiForecastComparisons)){
  769. log.error("预测已经进行过了,无需重复运行~~~~~~~~~~~@@@@@@@,时间为{}\n类型为{}", remark, category);
  770. return;
  771. }
  772. //获取配置表
  773. List<TXinyiNormConfig> tXinyiNormConfigs = this.xinyiNormConfigMapper.selectTXinyiNormConfigList(null);
  774. if(CollectionUtils.isEmpty(tXinyiNormConfigs)) {
  775. log.error( "未查询到配置信息");
  776. return;
  777. }
  778. TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0);
  779. //获取最新的工业库的数据
  780. TXinyiIndustry tXinyiIndustry = this.xinyiIndustryMapper.selectTXinyiIndustryNewest();
  781. List<ChartBasic> chartsDataList = new ArrayList<>(9);
  782. //同时调用跃渊的预测接口 保存记录值
  783. try {
  784. String result = HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=3&time=" + DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYY_MM_DD_HH), INT_10000);
  785. if(!StringUtils.isBlank(result)){
  786. JSONArray array = JSON.parseArray(result);
  787. tXinyiForecastComparison.setYyForecastOne(array.getBigDecimal(6));
  788. tXinyiForecastComparison.setYyForecastTwo(array.getBigDecimal(7));
  789. tXinyiForecastComparison.setYyForecastThree(array.getBigDecimal(8));
  790. }
  791. } catch (Exception e) {
  792. log.error("调用跃渊的预测接口出现异常,异常信息为{}", e.getMessage());
  793. }
  794. // this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
  795. BigDecimal cscodBzz = normConfig.getCscodBzz();
  796. BigDecimal cscodGkz = normConfig.getCscodGkz();
  797. //处理展示数据
  798. for (int i = 0; i < tXinyiIndustries6.size(); i++) {
  799. TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
  800. ChartBasic chartBasic = new ChartBasic();
  801. chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
  802. //todo 2024年6月25日10:09:24 目前就存放工业库的,后续看是否调整取化验室的
  803. chartBasic.setVal(tXinyiIndustryTemp.getCsTn());
  804. chartsDataList.add(chartBasic);
  805. }
  806. for (int i = 0; i < split.length; i++) {
  807. String val = split[i];
  808. ChartBasic chartBasic = new ChartBasic();
  809. chartBasic.setTime(hours[i]);
  810. chartBasic.setVal(new BigDecimal(val));
  811. chartsDataList.add(chartBasic);
  812. }
  813. handleXinYiWarningsYC(cscodBzz, split, cscodGkz, BusinessEnum.WarningCategoryEnum.CS_TN_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsTn(), tXinyiIndustry, chartsDataList, date);
  814. //插入到数据库
  815. //2024年6月21日14:18:55 如果红杉预测和跃渊预测都有数据再保存
  816. //2024年7月8日15:15:46 逻辑调整:只要红杉的数据不为空就保存
  817. if(Objects.isNull(tXinyiForecastComparison.getHsForecastOne()) || Objects.isNull(tXinyiForecastComparison.getHsForecastTwo()) ||Objects.isNull(tXinyiForecastComparison.getHsForecastThree())){
  818. // || Objects.isNull(tXinyiForecastComparison.getYyForecastOne()) || Objects.isNull(tXinyiForecastComparison.getYyForecastTwo()) || Objects.isNull(tXinyiForecastComparison.getYyForecastThree())){
  819. log.error("保存预测对比数据时,有存在不满足条件的数据,不再保存数据,数据为{}", JSON.toJSONString(tXinyiForecastComparison));
  820. }else
  821. this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
  822. }
  823. private void handlePredictorWarning(String[] split, String hour, String task, List<TXinyiIndustry> tXinyiIndustries6, List<TXinyiRobot> tXinyiRobots6, String date) {
  824. String[] hours = hour.split(",");
  825. //2024年6月23日18:28:55 因为存在跨天问题 所以日期也是逗号拼接的
  826. String[] dates = date.split(",");
  827. //2024年6月18日13:41:10 统一格式,否则查询不到结果
  828. //2024年6月18日10:36:49 增加预测记录,预测准确度计算等
  829. TXinyiForecastComparison tXinyiForecastComparison = new TXinyiForecastComparison();
  830. //2024年7月11日17:04:11 TP改为zlsy
  831. tXinyiForecastComparison.setCategory(BusinessEnum.BigModelForecastEnum.TP.getCode().equalsIgnoreCase(task) ? BusinessEnum.BigModelForecastEnum.ZLSY.getCode() : task);
  832. tXinyiForecastComparison.setForecastTimeOne(dates[0].replaceAll("-", "/") + " " + hours[0]);
  833. tXinyiForecastComparison.setForecastTimeTwo(dates[1].replaceAll("-", "/") + " " + hours[1]);
  834. tXinyiForecastComparison.setForecastTimeThree(dates[2].replaceAll("-", "/") + " " + hours[2]);
  835. tXinyiForecastComparison.setHsForecastOne(new BigDecimal(split[0]));
  836. tXinyiForecastComparison.setHsForecastTwo(new BigDecimal(split[1]));
  837. tXinyiForecastComparison.setHsForecastThree(new BigDecimal(split[2]));
  838. //2024年6月20日14:28:31 增加字段,方便查询
  839. tXinyiForecastComparison.setRemark(DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYYMMDDHH_TS));
  840. //防止工业库挂掉以后持续预测同一数据
  841. //2024年6月20日14:59:23 因为预测bug 判断是否生成过了否则不生成
  842. String remark = tXinyiForecastComparison.getRemark();
  843. String category = tXinyiForecastComparison.getCategory();
  844. TXinyiForecastComparison tXinyiForecastComparisonReq = new TXinyiForecastComparison();
  845. tXinyiForecastComparisonReq.setRemark(remark);
  846. tXinyiForecastComparisonReq.setCategory(category);
  847. List<TXinyiForecastComparison> tXinyiForecastComparisons = this.xinyiForecastComparisonService.selectTXinyiForecastComparisonList(tXinyiForecastComparisonReq);
  848. if(!CollectionUtils.isEmpty(tXinyiForecastComparisons)){
  849. log.error("预测已经进行过了,无需重复运行~~~~~~~~~~~@@@@@@@,时间为{}\n类型为{}", remark, category);
  850. return;
  851. }
  852. //获取配置表
  853. List<TXinyiNormConfig> tXinyiNormConfigs = this.xinyiNormConfigMapper.selectTXinyiNormConfigList(null);
  854. if(CollectionUtils.isEmpty(tXinyiNormConfigs)) {
  855. log.error( "未查询到配置信息");
  856. return;
  857. }
  858. TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0);
  859. //获取最新的工业库的数据
  860. TXinyiIndustry tXinyiIndustry = this.xinyiIndustryMapper.selectTXinyiIndustryNewest();
  861. List<ChartBasic> chartsDataList = new ArrayList<>(9);
  862. if("cod".equals(task)){
  863. //同时调用跃渊的预测接口 保存记录值
  864. try {
  865. String result = HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=2&time=" + DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYY_MM_DD_HH), INT_10000);
  866. if(!StringUtils.isBlank(result)){
  867. JSONArray array = JSON.parseArray(result);
  868. tXinyiForecastComparison.setYyForecastOne(array.getBigDecimal(6));
  869. tXinyiForecastComparison.setYyForecastTwo(array.getBigDecimal(7));
  870. tXinyiForecastComparison.setYyForecastThree(array.getBigDecimal(8));
  871. }
  872. } catch (Exception e) {
  873. log.error("调用跃渊的预测接口出现异常,异常信息为{}", e.getMessage());
  874. }
  875. // this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
  876. BigDecimal cscodBzz = normConfig.getCscodBzz();
  877. BigDecimal cscodGkz = normConfig.getCscodGkz();
  878. //处理展示数据
  879. for (int i = 0; i < tXinyiIndustries6.size(); i++) {
  880. TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
  881. ChartBasic chartBasic = new ChartBasic();
  882. chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
  883. //2024年6月25日10:10:38 bug修改,需要判断类型赋不同的值
  884. if(BusinessEnum.BigModelForecastEnum.TN.getCode().equalsIgnoreCase(category)
  885. || BusinessEnum.BigModelForecastEnum.XSY1.getCode().equalsIgnoreCase(category)
  886. || BusinessEnum.BigModelForecastEnum.XSY2.getCode().equalsIgnoreCase(category))
  887. chartBasic.setVal(DecimalUtils.getAbsAndScale(tXinyiIndustryTemp.getCsTn(), INT_2));
  888. if(BusinessEnum.BigModelForecastEnum.COD.getCode().equalsIgnoreCase(category))
  889. chartBasic.setVal(DecimalUtils.getAbsAndScale(tXinyiIndustryTemp.getCsCod(), INT_2));
  890. if(BusinessEnum.BigModelForecastEnum.SS.getCode().equalsIgnoreCase(category))
  891. chartBasic.setVal(DecimalUtils.getAbsAndScale(tXinyiIndustryTemp.getCsSs(), INT_2));
  892. if(BusinessEnum.BigModelForecastEnum.TP.getCode().equalsIgnoreCase(category)
  893. || BusinessEnum.BigModelForecastEnum.ZLSY.getCode().equalsIgnoreCase(category))
  894. chartBasic.setVal(DecimalUtils.getAbsAndScale(tXinyiIndustryTemp.getCsTp(), INT_2));
  895. if(BusinessEnum.BigModelForecastEnum.NH3.getCode().equalsIgnoreCase(category))
  896. chartBasic.setVal(DecimalUtils.getAbsAndScale(tXinyiIndustryTemp.getCsNh3(), INT_2));
  897. chartsDataList.add(chartBasic);
  898. }
  899. for (int i = 0; i < split.length; i++) {
  900. String val = split[i];
  901. ChartBasic chartBasic = new ChartBasic();
  902. chartBasic.setTime(hours[i]);
  903. chartBasic.setVal(new BigDecimal(val));
  904. chartsDataList.add(chartBasic);
  905. }
  906. handleXinYiWarningsYC(cscodBzz, split, cscodGkz, BusinessEnum.WarningCategoryEnum.CS_COD_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList, date);
  907. }else if("ss".equals(task)){
  908. //同时调用跃渊的预测接口 保存记录值
  909. try {
  910. String result = HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=5&time=" + DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYY_MM_DD_HH), INT_10000);
  911. if(!StringUtils.isBlank(result)){
  912. JSONArray array = JSON.parseArray(result);
  913. tXinyiForecastComparison.setYyForecastOne(array.getBigDecimal(6));
  914. tXinyiForecastComparison.setYyForecastTwo(array.getBigDecimal(7));
  915. tXinyiForecastComparison.setYyForecastThree(array.getBigDecimal(8));
  916. }
  917. } catch (Exception e) {
  918. log.error("调用跃渊的预测接口出现异常,异常信息为{}", e.getMessage());
  919. }
  920. // this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
  921. BigDecimal csSSBzz = normConfig.getCsssBzz();
  922. BigDecimal csssGkz = normConfig.getCsssGkz();
  923. //处理展示数据
  924. for (int i = 0; i < tXinyiIndustries6.size(); i++) {
  925. TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
  926. ChartBasic chartBasic = new ChartBasic();
  927. chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
  928. chartBasic.setVal(tXinyiIndustryTemp.getCsSs());
  929. chartsDataList.add(chartBasic);
  930. }
  931. for (int i = 0; i < split.length; i++) {
  932. String val = split[i];
  933. ChartBasic chartBasic = new ChartBasic();
  934. chartBasic.setTime(hours[i]);
  935. chartBasic.setVal(new BigDecimal(val));
  936. chartsDataList.add(chartBasic);
  937. }
  938. handleXinYiWarningsYC(csSSBzz, split, csssGkz, BusinessEnum.WarningCategoryEnum.CS_SS_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsSs(), tXinyiIndustry, chartsDataList, date);
  939. }/*else if("tn".equals(task)){
  940. //同时调用跃渊的预测接口 保存记录值
  941. try {
  942. String result = HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=3&time=" + DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYY_MM_DD_HH), INT_10);
  943. if(!StringUtils.isBlank(result)){
  944. JSONArray array = JSON.parseArray(result);
  945. tXinyiForecastComparison.setYyForecastOne(array.getBigDecimal(6));
  946. tXinyiForecastComparison.setYyForecastTwo(array.getBigDecimal(7));
  947. tXinyiForecastComparison.setYyForecastThree(array.getBigDecimal(8));
  948. }
  949. } catch (Exception e) {
  950. log.error("调用跃渊的预测接口出现异常,异常信息为{}", e.getMessage());
  951. }
  952. // this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
  953. BigDecimal cszzBzz = normConfig.getCszzBzz();
  954. BigDecimal cszzGkz = normConfig.getCszzGkz();
  955. //处理展示数据
  956. for (int i = 0; i < tXinyiIndustries6.size(); i++) {
  957. TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
  958. ChartBasic chartBasic = new ChartBasic();
  959. chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
  960. chartBasic.setVal(tXinyiIndustryTemp.getCsTn());
  961. chartsDataList.add(chartBasic);
  962. }
  963. for (int i = 0; i < split.length; i++) {
  964. String val = split[i];
  965. ChartBasic chartBasic = new ChartBasic();
  966. chartBasic.setTime(hours[i]);
  967. chartBasic.setVal(new BigDecimal(val));
  968. chartsDataList.add(chartBasic);
  969. }
  970. handleXinYiWarningsYC(cszzBzz, split, cszzGkz, BusinessEnum.WarningCategoryEnum.CS_TN_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList, date);
  971. }*/else if("tp".equals(task)){
  972. //同时调用跃渊的预测接口 保存记录值
  973. try {
  974. String result = HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=1&time=" + DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYY_MM_DD_HH), INT_10000);
  975. if(!StringUtils.isBlank(result)){
  976. JSONArray array = JSON.parseArray(result);
  977. tXinyiForecastComparison.setYyForecastOne(array.getBigDecimal(6));
  978. tXinyiForecastComparison.setYyForecastTwo(array.getBigDecimal(7));
  979. tXinyiForecastComparison.setYyForecastThree(array.getBigDecimal(8));
  980. }
  981. } catch (Exception e) {
  982. log.error("调用跃渊的预测接口出现异常,异常信息为{}", e.getMessage());
  983. }
  984. // this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
  985. BigDecimal cszlBzz = normConfig.getCszlBzz();
  986. BigDecimal cszlGkz = normConfig.getCszlGkz();
  987. //处理展示数据
  988. for (int i = 0; i < tXinyiIndustries6.size(); i++) {
  989. TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
  990. ChartBasic chartBasic = new ChartBasic();
  991. chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
  992. chartBasic.setVal(tXinyiIndustryTemp.getCsTp());
  993. chartsDataList.add(chartBasic);
  994. }
  995. for (int i = 0; i < split.length; i++) {
  996. String val = split[i];
  997. ChartBasic chartBasic = new ChartBasic();
  998. chartBasic.setTime(hours[i]);
  999. chartBasic.setVal(new BigDecimal(val));
  1000. chartsDataList.add(chartBasic);
  1001. }
  1002. handleXinYiWarningsYC(cszlBzz, split, cszlGkz, BusinessEnum.WarningCategoryEnum.CS_TP_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsTp(), tXinyiIndustry, chartsDataList, date);
  1003. }else if("nh3".equals(task)){
  1004. //同时调用跃渊的预测接口 保存记录值
  1005. try {
  1006. String result = HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=4&time=" + DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYY_MM_DD_HH), INT_10000);
  1007. if(!StringUtils.isBlank(result)){
  1008. JSONArray array = JSON.parseArray(result);
  1009. tXinyiForecastComparison.setYyForecastOne(array.getBigDecimal(6));
  1010. tXinyiForecastComparison.setYyForecastTwo(array.getBigDecimal(7));
  1011. tXinyiForecastComparison.setYyForecastThree(array.getBigDecimal(8));
  1012. }
  1013. } catch (Exception e) {
  1014. log.error("调用跃渊的预测接口出现异常,异常信息为{}", e.getMessage());
  1015. }
  1016. // this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
  1017. BigDecimal csadBzz = normConfig.getCsadBzz();
  1018. BigDecimal csadGkz = normConfig.getCsadGkz();
  1019. //处理展示数据
  1020. for (int i = 0; i < tXinyiIndustries6.size(); i++) {
  1021. TXinyiIndustry tXinyiIndustryTemp = tXinyiIndustries6.get(5 - i);
  1022. ChartBasic chartBasic = new ChartBasic();
  1023. chartBasic.setTime(tXinyiIndustryTemp.getTestHour().substring(11));
  1024. chartBasic.setVal(tXinyiIndustryTemp.getCsNh3());
  1025. chartsDataList.add(chartBasic);
  1026. }
  1027. for (int i = 0; i < split.length; i++) {
  1028. String val = split[i];
  1029. ChartBasic chartBasic = new ChartBasic();
  1030. chartBasic.setTime(hours[i]);
  1031. chartBasic.setVal(new BigDecimal(val));
  1032. chartsDataList.add(chartBasic);
  1033. }
  1034. handleXinYiWarningsYC(csadBzz, split, csadGkz, BusinessEnum.WarningCategoryEnum.CS_AD_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsNh3(), tXinyiIndustry, chartsDataList, date);
  1035. }else if("xsy1".equals(task)){
  1036. //2024年6月21日14:57:02 红杉的出水总氮预测改成 不用工业库的,用化验科的两个xsy 相关指标
  1037. //同时调用跃渊的预测接口 保存记录值
  1038. try {
  1039. String result = HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=3&time=" + DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYY_MM_DD_HH), INT_10000);
  1040. if(!StringUtils.isBlank(result)){
  1041. JSONArray array = JSON.parseArray(result);
  1042. tXinyiForecastComparison.setYyForecastOne(array.getBigDecimal(6));
  1043. tXinyiForecastComparison.setYyForecastTwo(array.getBigDecimal(7));
  1044. tXinyiForecastComparison.setYyForecastThree(array.getBigDecimal(8));
  1045. }
  1046. } catch (Exception e) {
  1047. log.error("调用跃渊的预测接口出现异常,异常信息为{}", e.getMessage());
  1048. }
  1049. // this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
  1050. /*BigDecimal cscodBzz = new BigDecimal(XIAOSUANYAN_BZK);
  1051. BigDecimal cscodGkz = new BigDecimal(XIAOSUANYAN_GKZ);*/
  1052. //2024年7月11日17:19:47 1#好氧硝酸盐、2#好氧硝酸盐使用总氮标准值和管控值来预警
  1053. BigDecimal cszzBzz = normConfig.getCszzBzz();
  1054. BigDecimal cszzGkz = normConfig.getCszzGkz();
  1055. //处理展示数据
  1056. for (int i = 0; i < tXinyiRobots6.size(); i++) {
  1057. TXinyiRobot tXinyiRobotTemp = tXinyiRobots6.get(5 - i);
  1058. ChartBasic chartBasic = new ChartBasic();
  1059. chartBasic.setTime(tXinyiRobotTemp.getTestHour().substring(11));
  1060. chartBasic.setVal(tXinyiRobotTemp.getNo3Hlj1Jqr());
  1061. chartsDataList.add(chartBasic);
  1062. }
  1063. for (int i = 0; i < split.length; i++) {
  1064. String val = split[i];
  1065. ChartBasic chartBasic = new ChartBasic();
  1066. chartBasic.setTime(hours[i]);
  1067. chartBasic.setVal(new BigDecimal(val));
  1068. chartsDataList.add(chartBasic);
  1069. }
  1070. handleXinYiWarningsYC(cszzBzz, split, cszzGkz, BusinessEnum.WarningCategoryEnum.CS_XSY_1_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList, date);
  1071. }else if("xsy2".equals(task)){
  1072. //同时调用跃渊的预测接口 保存记录值
  1073. try {
  1074. String result = HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=3&time=" + DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYY_MM_DD_HH), INT_10000);
  1075. if(!StringUtils.isBlank(result)){
  1076. JSONArray array = JSON.parseArray(result);
  1077. tXinyiForecastComparison.setYyForecastOne(array.getBigDecimal(6));
  1078. tXinyiForecastComparison.setYyForecastTwo(array.getBigDecimal(7));
  1079. tXinyiForecastComparison.setYyForecastThree(array.getBigDecimal(8));
  1080. }
  1081. } catch (Exception e) {
  1082. log.error("调用跃渊的预测接口出现异常,异常信息为{}", e.getMessage());
  1083. }
  1084. // this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
  1085. /*BigDecimal cscodBzz = new BigDecimal(XIAOSUANYAN_BZK);
  1086. BigDecimal cscodGkz = new BigDecimal(XIAOSUANYAN_GKZ);*/
  1087. //2024年7月11日17:19:47 1#好氧硝酸盐、2#好氧硝酸盐使用总氮标准值和管控值来预警
  1088. BigDecimal cszzBzz = normConfig.getCszzBzz();
  1089. BigDecimal cszzGkz = normConfig.getCszzGkz();
  1090. //处理展示数据
  1091. for (int i = 0; i < tXinyiRobots6.size(); i++) {
  1092. TXinyiRobot tXinyiRobotTemp = tXinyiRobots6.get(5 - i);
  1093. ChartBasic chartBasic = new ChartBasic();
  1094. chartBasic.setTime(tXinyiRobotTemp.getTestHour().substring(11));
  1095. chartBasic.setVal(tXinyiRobotTemp.getNo3Hlj2Jqr());
  1096. chartsDataList.add(chartBasic);
  1097. }
  1098. for (int i = 0; i < split.length; i++) {
  1099. String val = split[i];
  1100. ChartBasic chartBasic = new ChartBasic();
  1101. chartBasic.setTime(hours[i]);
  1102. chartBasic.setVal(new BigDecimal(val));
  1103. chartsDataList.add(chartBasic);
  1104. }
  1105. handleXinYiWarningsYC(cszzBzz, split, cszzGkz, BusinessEnum.WarningCategoryEnum.CS_XSY_2_YC.getCode(), hour, normConfig,tXinyiIndustry.getCsCod(), tXinyiIndustry, chartsDataList, date);
  1106. }else {
  1107. log.error("暂未支持的类型{}", task);
  1108. }
  1109. //插入到数据库
  1110. //2024年6月21日14:18:55 如果红杉预测和跃渊预测都有数据再保存
  1111. //2024年7月8日15:15:46 逻辑调整:只要红杉的数据不为空就保存
  1112. if(Objects.isNull(tXinyiForecastComparison.getHsForecastOne()) || Objects.isNull(tXinyiForecastComparison.getHsForecastTwo()) ||Objects.isNull(tXinyiForecastComparison.getHsForecastThree())){
  1113. // || Objects.isNull(tXinyiForecastComparison.getYyForecastOne()) || Objects.isNull(tXinyiForecastComparison.getYyForecastTwo()) || Objects.isNull(tXinyiForecastComparison.getYyForecastThree())){
  1114. log.error("保存预测对比数据时,有存在不满足条件的数据,不再保存数据,数据为{}", JSON.toJSONString(tXinyiForecastComparison));
  1115. }else
  1116. this.xinyiForecastComparisonService.insertTXinyiForecastComparison(tXinyiForecastComparison);
  1117. }
  1118. private void handleXinYiWarningsYC(BigDecimal csBzz, String[] split, BigDecimal csGkz, String category, String hour, TXinyiNormConfig normConfig, BigDecimal currentVal, TXinyiIndustry tXinyiIndustry, List<ChartBasic> chartsDataList, String date) {
  1119. BigDecimal multiply = csBzz.multiply(new BigDecimal(MyConstants.SCALE_VALUE));
  1120. TXinyiWarningRecord tXinyiWarningRecord = null;
  1121. String yjHour = null;
  1122. for (int i = 0, splitLength = split.length; i < splitLength; i++) {
  1123. String forecast = split[i];
  1124. /*BigDecimal forecastVal = new BigDecimal("10000");*/
  1125. BigDecimal forecastVal = new BigDecimal(forecast);
  1126. tXinyiWarningRecord = new TXinyiWarningRecord();
  1127. /*String category = BusinessEnum.WarningCategoryEnum.CS_AD.getCode();*/
  1128. tXinyiWarningRecord.setStatus(0);
  1129. tXinyiWarningRecord.setType(2);
  1130. tXinyiWarningRecord.setCategory(category);
  1131. tXinyiWarningRecord.setWarningVal(currentVal);//当前值
  1132. tXinyiWarningRecord.setForecastVal(forecastVal);
  1133. tXinyiWarningRecord.setDesignVal(csBzz);
  1134. tXinyiWarningRecord.setControlVal(csGkz);
  1135. tXinyiWarningRecord.setCreateBy(WARNING_DEFAULT_CREATE);
  1136. tXinyiWarningRecord.setCreateTime(DateUtils.getNowDate());
  1137. tXinyiWarningRecord.setRemark("2");
  1138. //2024年5月25日17:52:33 如果工业库获取不到数据,也触发报警,但是不调用决策接口
  1139. if (Objects.isNull(forecastVal)) {
  1140. tXinyiWarningRecord.setReason(category + EXCEPTION_WARNING_YC);
  1141. tXinyiWarningRecord.setLevel(WARNING_LEVEL_NO_DATE);
  1142. } else if (forecastVal.compareTo(multiply) > 0) {//一级
  1143. tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING_YC);
  1144. tXinyiWarningRecord.setLevel(WARNING_LEVEL_ONE);
  1145. } else if (forecastVal.compareTo(csBzz) >= 0 && forecastVal.compareTo(multiply) <= 0) {//二级
  1146. tXinyiWarningRecord.setReason(category + CHAOBIAO_WARNING_YC);
  1147. tXinyiWarningRecord.setLevel(WARNING_LEVEL_TWO);
  1148. } else if (!Objects.isNull(csGkz) && forecastVal.compareTo(csGkz) > 0) {
  1149. tXinyiWarningRecord.setReason(category + CHAOGUANKONG_WARNING_YC);
  1150. tXinyiWarningRecord.setLevel(WARNING_LEVEL_THREE);
  1151. } else {
  1152. tXinyiWarningRecord = null;//这种的无需处理
  1153. }
  1154. if (!Objects.isNull(tXinyiWarningRecord)) {
  1155. log.info("预测报警中出现了超标的情况,循环可以退出了");
  1156. yjHour = hour.split(",")[i];
  1157. date = date.split(",")[i];//2024年6月23日18:34:49 日期也是多个了
  1158. //预计超标时间 不是当前值,是预测超标的时间。
  1159. try {
  1160. tXinyiWarningRecord.setTime(DateUtils.parseDate(date + " " + yjHour, DateUtils.YYYY_MM_DD_HH));
  1161. } catch (ParseException e) {
  1162. log.error("处理语句的预计超标时间是,异常,异常信息为{}", e.getMessage());
  1163. }
  1164. break;
  1165. }
  1166. }
  1167. //当前状态正常 需要查询历史有无正在报警的数据,如果有,将报警状态改完2(系统自动关闭)
  1168. List<TXinyiWarningRecord> tXinyiWarningRecords = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordList(TXinyiWarningRecord.builder().delFlag(0).type(2).category(category).warningStatus(0).build());
  1169. if(Objects.isNull(tXinyiWarningRecord)){//数据正常,无告警信息
  1170. if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){
  1171. log.info( "{}:现在恢复正常,历史报警数据为{}", category,JSON.toJSONString(tXinyiWarningRecords));
  1172. for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) {
  1173. xinyiWarningRecord.setStatus(2);
  1174. Date nowDate = DateUtils.getNowDate();
  1175. xinyiWarningRecord.setOffTime(nowDate);
  1176. xinyiWarningRecord.setUpdateTime(nowDate);
  1177. xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE);
  1178. this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord);
  1179. }
  1180. }
  1181. }else{//有告警信息
  1182. //2024年6月27日10:45:49 列表的预警时间和showval里的预警时间保持一致(用同一个,否则可能有一分钟左右的误差)
  1183. Date nowDate = DateUtils.getNowDate();
  1184. if(CollectionUtils.isEmpty(tXinyiWarningRecords)){//之前没有告警记录
  1185. //保存到数据库中
  1186. this.xinyiWarningRecordMapper.insertTXinyiWarningRecord(tXinyiWarningRecord);
  1187. if(WARNING_LEVEL_NO_DATE.equals(tXinyiWarningRecord.getLevel())){
  1188. //只保存一个普通的问答记录 不需要调用决策信息,但是实时数据还是要记录的
  1189. this.addChatRecordByDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig);
  1190. }else {
  1191. //继续调用大模型prompt
  1192. try {
  1193. this.askBigModelForYC(tXinyiWarningRecord, tXinyiIndustry, normConfig, chartsDataList, date, yjHour, nowDate);
  1194. } catch (Exception e) {
  1195. log.error("预测完成调用大模型获取解决方案时异常,异常信息为{}", JSON.toJSONString(e));
  1196. }
  1197. }
  1198. }else{
  1199. log.info("{}:之前已经有过告警记录了,且还是继续报警,无需重复添加报警,但是决策仍然要调用", category);
  1200. for (TXinyiWarningRecord xinyiWarningRecord : tXinyiWarningRecords) {//理论上只有一个的
  1201. if(WARNING_LEVEL_NO_DATE.equals(tXinyiWarningRecord.getLevel())){
  1202. //只保存一个普通的问答记录 不需要调用决策信息,但是实时数据还是要记录的
  1203. this.addChatRecordByDeviceErr(tXinyiWarningRecord, tXinyiIndustry, normConfig);
  1204. }else {
  1205. //2024年6月25日11:32:13 预测的相对特殊:因为前端不展示次数,所以这里把 超标时间+现在值+预测值更新一下
  1206. xinyiWarningRecord.setForecastVal(tXinyiWarningRecord.getForecastVal());
  1207. xinyiWarningRecord.setWarningVal(currentVal);
  1208. xinyiWarningRecord.setTime(tXinyiWarningRecord.getTime());
  1209. xinyiWarningRecord.setUpdateTime(nowDate);
  1210. xinyiWarningRecord.setUpdateBy(WARNING_DEFAULT_CREATE);
  1211. //更新数据库
  1212. this.xinyiWarningRecordMapper.updateTXinyiWarningRecord(xinyiWarningRecord);
  1213. //继续调用决策
  1214. try {
  1215. this.askBigModelForYC(xinyiWarningRecord, tXinyiIndustry, normConfig, chartsDataList, date, yjHour, nowDate);
  1216. } catch (Exception e) {
  1217. log.error("预测完成调用大模型获取解决方案时异常,异常信息为{}", JSON.toJSONString(e));
  1218. }
  1219. }
  1220. }
  1221. }
  1222. }
  1223. }
  1224. private void askBigModelForYC(TXinyiWarningRecord xinyiWarningRecord, TXinyiIndustry tXinyiIndustry, TXinyiNormConfig normConfig, List<ChartBasic> chartsDataList, String date, String yjHour, Date nowDate) {
  1225. log.info("预测进入了后台接口调⽤⼤模型获取问答结果处理(预测)");
  1226. StringBuilder sb = new StringBuilder();
  1227. String sessionId = IdUtils.simpleUUID();
  1228. ChatReq chatReq = new ChatReq();
  1229. // String ipAddr = IpUtils.getIpAddr();//获取用户的ip地址 传给大模型
  1230. String ipAddr = "";//获取用户的ip地址 传给大模型 定时任务获取不到ip地址
  1231. int counts = 1;//默认是第一次
  1232. //这种问答 没有历史问答的概念 直接把问题扔进去就行 无需查询历史记录
  1233. List<String> historyDates = new ArrayList<>();
  1234. //构建问题(替换提示词中的占位符)
  1235. /*String shWarningPrompt = YC_WARNING_PROMPT;
  1236. shWarningPrompt =shWarningPrompt.replace("#{0}", xinyiWarningRecord.getReason());
  1237. shWarningPrompt =shWarningPrompt.replace("#{1}", String.valueOf(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getDesignVal(), INT_2)));
  1238. shWarningPrompt =shWarningPrompt.replace("#{2}", String.valueOf(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getWarningVal(), INT_2)));
  1239. shWarningPrompt =shWarningPrompt.replace("#{3}", String.valueOf(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getForecastVal(), INT_2)));*/
  1240. StringBuilder prompt = new StringBuilder(YC_WARNING_PROMPT_1);
  1241. prompt.append(xinyiWarningRecord.getReason());
  1242. prompt.append(YC_WARNING_PROMPT_2).append(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getDesignVal(), INT_2));
  1243. prompt.append(YC_WARNING_PROMPT_3).append(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getWarningVal(), INT_2));
  1244. prompt.append(YC_WARNING_PROMPT_4).append(DecimalUtils.getAbsAndScale(xinyiWarningRecord.getForecastVal(), INT_2));
  1245. prompt.append(YC_WARNING_PROMPT_5);
  1246. historyDates.add(prompt.toString());
  1247. // 获取输出流
  1248. ManagedChannel channel = null;
  1249. try {
  1250. channel = ManagedChannelBuilder.forAddress(bigModelConfig.getIp(), bigModelConfig.getPort())
  1251. .usePlaintext()
  1252. .build();
  1253. InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub stub = InferenceAPIsServiceGrpc.newBlockingStub(channel);
  1254. // 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) + "}";
  1255. //2024年6月27日10:51:47 优化:不再手动拼接JSON字符串
  1256. String dataJson = buildBigModelReqForChat(sessionId, historyDates);
  1257. // log.info("请求大模型的问答参数为{}", dataJson);
  1258. PredictionsRequest request = PredictionsRequest.newBuilder()
  1259. .setModelName("slibra_bot")
  1260. .putInput("method", ByteString.copyFrom("infer_stream", "utf-8"))//推理
  1261. .putInput("data", ByteString.copyFrom(dataJson, "utf-8"))
  1262. .buildPartial();
  1263. Iterator<PredictionResponse> predictions = stub.streamPredictions(request);
  1264. //将结果记录到问答表
  1265. while (predictions.hasNext()) {
  1266. String responseStr = predictions.next().getPrediction().toStringUtf8();
  1267. // log.info("大模型问答返回的原始结果为{}", responseStr);
  1268. responseStr = JSON.parseObject(responseStr).getString("message");
  1269. if("complete".equals(responseStr)){
  1270. log.info("结尾语句并且是非JSON,无需处理");
  1271. }else{
  1272. sb.append(responseStr);
  1273. }
  1274. }
  1275. //将问答更新到数据库中
  1276. chatReq.setSessionId(sessionId);
  1277. chatReq.setType(1);//0问答 1决策 2本地 3仿真预测 预测报警这里也算是决策 仿真预测是在调用仿真那里使用的
  1278. chatReq.setModule(3);//0专家问答 1智能工单 2智能体助手 3告警 4简报
  1279. String showVal = this.buildShowValueWithCharts(xinyiWarningRecord, tXinyiIndustry, normConfig, chartsDataList, date, yjHour, nowDate);
  1280. chatReq.setShowVal(showVal);
  1281. chatReq.setQuestion(prompt.toString());
  1282. chatReq.setAnswer(sb.toString());
  1283. chatReq.setWarningId(String.valueOf(xinyiWarningRecord.getId()));
  1284. chatReq.setCounts(counts);//问答次数
  1285. chatReq.setUserId(WARNING_DEFAULT_CREATE);
  1286. chatReq.setCreateBy(WARNING_DEFAULT_CREATE);
  1287. chatReq.setCreateTime(DateUtils.getNowDate());
  1288. this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq);
  1289. } catch (IOException e) {
  1290. throw new RuntimeException(e);
  1291. } finally {
  1292. // 关闭输出流
  1293. channel.shutdown();
  1294. }
  1295. }
  1296. private String buildBigModelReqForChat(String sessionId, List<String> historyDates) {
  1297. ChatRequest chatRequest = new ChatRequest();
  1298. chatRequest.setSessionId(sessionId);
  1299. chatRequest.setHistoryDia(historyDates);
  1300. //2024年7月5日13:24:10 temperature做区分
  1301. GenerateArgs generateArgs = new GenerateArgs();
  1302. generateArgs.setTemperature(bigModelConfig.getTemperature());
  1303. chatRequest.setGenerateArgs(generateArgs);
  1304. Map<String, Object> extra = new HashMap<>();
  1305. // extra.put("ip_address", IpUtils.getIpAddr());
  1306. extra.put("ip_address", null);
  1307. chatRequest.setExtra(extra);
  1308. chatRequest.setStrengthen(true);
  1309. return JSON.toJSONString(chatRequest);
  1310. }
  1311. public String getPredictor(String type){
  1312. // 获取输出流
  1313. ManagedChannel channel = null;
  1314. try {
  1315. channel = ManagedChannelBuilder.forAddress(bigModelConfig.getIp(), bigModelConfig.getPort())
  1316. .usePlaintext()
  1317. .build();
  1318. InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub stub = InferenceAPIsServiceGrpc.newBlockingStub(channel);
  1319. // String dataJson = "{\"bot_id\":\"b00001\",\"exp_id\":\"721\",\"norm\":\"" + type + "\",\"session_id\":\" " + IdUtils.simpleUUID() + " \",\"extra\":{}}";
  1320. //2024年6月27日13:23:25 优化:改成非拼接JSON字符串
  1321. String dataJson = buildBigModelReqForPredictor(type);
  1322. // log.info("请求大模型的预测的参数为{}", dataJson);
  1323. PredictionsRequest request = PredictionsRequest.newBuilder()
  1324. .setModelName("slibra_bot")
  1325. .putInput("method", ByteString.copyFrom("predictor", "utf-8"))//推理
  1326. .putInput("data", ByteString.copyFrom(dataJson, "utf-8"))
  1327. .buildPartial();
  1328. /*Iterator<PredictionResponse> predictions = stub.streamPredictions(request);
  1329. //将结果记录到问答表
  1330. String responseStr = predictions.next().getPrediction().toStringUtf8();
  1331. log.info("大模型的预测的返回结果为{}", responseStr);*/
  1332. //2024年6月21日11:46:36 改成非流式输出
  1333. PredictionResponse predictions = stub.predictions(request);
  1334. String responseStr = predictions.getPrediction().toStringUtf8();
  1335. log.info("调用TFT预测大模型返回的原始结果为{}", responseStr);
  1336. // return JSON.parseObject(responseStr).getString("pred");
  1337. return responseStr;
  1338. } catch (IOException e) {
  1339. throw new RuntimeException(e);
  1340. } finally {
  1341. assert channel != null;
  1342. channel.shutdown();
  1343. }
  1344. }
  1345. private static String buildBigModelReqForPredictor(String type) {
  1346. PredictorRequest predictorRequest = new PredictorRequest();
  1347. predictorRequest.setNorm(type);
  1348. predictorRequest.setSessionId(IdUtils.simpleUUID());
  1349. return JSON.toJSONString(predictorRequest);
  1350. }
  1351. /**
  1352. *
  1353. * 2022/01/01 转成2022年01月01日 数据
  1354. * @param testDate
  1355. * @return
  1356. */
  1357. private String formateDateStr(String testDate) {
  1358. if(StringUtils.isBlank(testDate))
  1359. return "";
  1360. if(!testDate.contains("/"))
  1361. return testDate;
  1362. String[] split = testDate.split("/");
  1363. return split[0] + "年" + split[1] + "月" + split[2] + "日";
  1364. }
  1365. private void askBigModel(String question, String showVal) {
  1366. log.info("进入了后台接口调⽤⼤模型获取问答结果处理");
  1367. StringBuilder sb = new StringBuilder();
  1368. String sessionId = IdUtils.simpleUUID();
  1369. ChatReq chatReq = new ChatReq();
  1370. // String ipAddr = IpUtils.getIpAddr();//获取用户的ip地址 传给大模型
  1371. String ipAddr = "";//获取用户的ip地址 传给大模型 定时任务获取不到ip地址
  1372. int counts = 1;//默认是第一次
  1373. //这种问答 没有历史问答的概念 直接把问题扔进去就行 无需查询历史记录
  1374. List<String> historyDates = new ArrayList<>();
  1375. historyDates.add(question);
  1376. // 获取输出流
  1377. ManagedChannel channel = null;
  1378. try {
  1379. channel = ManagedChannelBuilder.forAddress(bigModelConfig.getIp(), bigModelConfig.getPort())
  1380. .usePlaintext()
  1381. .build();
  1382. InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub stub = InferenceAPIsServiceGrpc.newBlockingStub(channel);
  1383. // 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) + "}";
  1384. //2024年6月27日10:51:47 优化:不再手动拼接JSON字符串
  1385. String dataJson = buildBigModelReqForChat(sessionId, historyDates);
  1386. // log.info("请求大模型的问答参数为{}", dataJson);
  1387. PredictionsRequest request = PredictionsRequest.newBuilder()
  1388. .setModelName("slibra_bot")
  1389. .putInput("method", ByteString.copyFrom("infer_stream", "utf-8"))//推理
  1390. .putInput("data", ByteString.copyFrom(dataJson, "utf-8"))
  1391. .buildPartial();
  1392. Iterator<PredictionResponse> predictions = stub.streamPredictions(request);
  1393. //将结果记录到问答表
  1394. while (predictions.hasNext()) {
  1395. String responseStr = predictions.next().getPrediction().toStringUtf8();
  1396. // log.info("大模型问答返回的原始结果为{}", responseStr);
  1397. responseStr = JSON.parseObject(responseStr).getString("message");
  1398. if("complete".equals(responseStr)){
  1399. System.out.println("结尾语句并且是非JSON,无需处理");
  1400. //结束语句也流式输出,但是并不记录下来 2024年5月24日11:15:23 也不返回前端
  1401. /*outputStream.write(responseStr.getBytes());
  1402. outputStream.flush();*/
  1403. }else{
  1404. sb.append(responseStr);
  1405. }
  1406. }
  1407. //将问答更新到数据库中
  1408. chatReq.setSessionId(sessionId);
  1409. chatReq.setType(2);//0问答 1决策 2本地 3仿真预测
  1410. chatReq.setModule(4);//0专家问答 1智能工单 2智能体助手 3告警 4简报
  1411. chatReq.setShowVal(showVal);
  1412. chatReq.setQuestion(question);
  1413. chatReq.setAnswer(sb.toString());
  1414. chatReq.setCounts(counts);//问答次数
  1415. chatReq.setUserId(WARNING_DEFAULT_CREATE);
  1416. chatReq.setCreateBy(WARNING_DEFAULT_CREATE);
  1417. chatReq.setCreateTime(DateUtils.getNowDate());
  1418. this.xinyiChatRecordMapper.insertTXinyiChatRecord(chatReq);
  1419. } catch (IOException e) {
  1420. throw new RuntimeException(e);
  1421. } finally {
  1422. // 关闭输出流
  1423. channel.shutdown();
  1424. }
  1425. }
  1426. /**
  1427. * @param dailyTwoRecords
  1428. * @return
  1429. */
  1430. @Deprecated
  1431. private String buildShortReportQueryData(List<TXinyiDaily> dailyTwoRecords) {
  1432. //查询配置信息
  1433. List<TXinyiNormConfig> tXinyiNormConfigs = this.xinyiNormConfigMapper.selectTXinyiNormConfigList(null);
  1434. if(CollectionUtils.isEmpty(tXinyiNormConfigs))
  1435. return null;
  1436. TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0);
  1437. //获取数据
  1438. TXinyiDaily yesterdayData = dailyTwoRecords.get(0);
  1439. TXinyiDaily beforeYesterdayData = dailyTwoRecords.get(1);
  1440. String originStr = JIAN_BAO_PROMPT;
  1441. String yesterdayStr = yesterdayData.getTestDate().substring(5).replace("/", "月") + "日";
  1442. String beforeYesterdayStr = beforeYesterdayData.getTestDate().substring(5).replace("/", "月") + "日";
  1443. originStr = originStr.replace("#{0}", yesterdayStr);
  1444. originStr = originStr.replace("#{1}", beforeYesterdayStr);
  1445. originStr = originStr.replace("#{2}", String.valueOf(yesterdayData.getJsCod()));
  1446. originStr = originStr.replace("#{3}", String.valueOf(yesterdayData.getJsTn()));
  1447. originStr = originStr.replace("#{4}", String.valueOf(yesterdayData.getJsTp()));
  1448. originStr = originStr.replace("#{5}", String.valueOf(yesterdayData.getJsNh3()));
  1449. originStr = originStr.replace("#{6}", String.valueOf(yesterdayData.getJsSs()));
  1450. originStr = originStr.replace("#{7}", String.valueOf(yesterdayData.getJSL()));
  1451. originStr = originStr.replace("#{8}", String.valueOf(yesterdayData.getCsCod()));
  1452. originStr = originStr.replace("#{9}", String.valueOf(yesterdayData.getCsTn()));
  1453. originStr = originStr.replace("#{10}", String.valueOf(yesterdayData.getCsTp()));
  1454. originStr = originStr.replace("#{11}", String.valueOf(yesterdayData.getCsNh3()));
  1455. originStr = originStr.replace("#{12}", String.valueOf(yesterdayData.getCsSs()));
  1456. originStr = originStr.replace("#{13}", String.valueOf(yesterdayData.getCSL()));
  1457. originStr = originStr.replace("#{14}", String.valueOf(beforeYesterdayData.getJsCod()));
  1458. originStr = originStr.replace("#{15}", String.valueOf(beforeYesterdayData.getJsTn()));
  1459. originStr = originStr.replace("#{16}", String.valueOf(beforeYesterdayData.getJsTp()));
  1460. originStr = originStr.replace("#{17}", String.valueOf(beforeYesterdayData.getJsNh3()));
  1461. originStr = originStr.replace("#{18}", String.valueOf(beforeYesterdayData.getJsSs()));
  1462. originStr = originStr.replace("#{19}", String.valueOf(beforeYesterdayData.getJSL()));
  1463. originStr = originStr.replace("#{20}", String.valueOf(beforeYesterdayData.getCsCod()));
  1464. originStr = originStr.replace("#{21}", String.valueOf(beforeYesterdayData.getCsTn()));
  1465. originStr = originStr.replace("#{22}", String.valueOf(beforeYesterdayData.getCsTp()));
  1466. originStr = originStr.replace("#{23}", String.valueOf(beforeYesterdayData.getCsNh3()));
  1467. originStr = originStr.replace("#{24}", String.valueOf(beforeYesterdayData.getCsSs()));
  1468. originStr = originStr.replace("#{25}", String.valueOf(beforeYesterdayData.getCSL()));
  1469. originStr = originStr.replace("#{26}", String.valueOf(normConfig.getJscodSjz()));
  1470. originStr = originStr.replace("#{27}", String.valueOf(normConfig.getJszdSjz()));
  1471. originStr = originStr.replace("#{28}", String.valueOf(normConfig.getJszlSjz()));
  1472. originStr = originStr.replace("#{29}", String.valueOf(normConfig.getJsadSjz()));
  1473. originStr = originStr.replace("#{30}", String.valueOf(normConfig.getJsssSjz()));
  1474. originStr = originStr.replace("#{31}", String.valueOf(normConfig.getCscodBzz()));
  1475. originStr = originStr.replace("#{32}", String.valueOf(normConfig.getCszzBzz()));
  1476. originStr = originStr.replace("#{33}", String.valueOf(normConfig.getCszlBzz()));
  1477. originStr = originStr.replace("#{34}", String.valueOf(normConfig.getCsadBzz()));
  1478. originStr = originStr.replace("#{35}", String.valueOf(normConfig.getCsssBzz()));
  1479. return originStr;
  1480. }
  1481. //2024年6月23日19:58:21 简报生成的prompt调整。
  1482. private String buildShortReportQueryDataNew(List<TXinyiDaily> dailyTwoRecords) {
  1483. //查询配置信息
  1484. List<TXinyiNormConfig> tXinyiNormConfigs = this.xinyiNormConfigMapper.selectTXinyiNormConfigList(null);
  1485. if(CollectionUtils.isEmpty(tXinyiNormConfigs))
  1486. return null;
  1487. TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0);
  1488. //获取数据
  1489. TXinyiDaily yesterdayData = dailyTwoRecords.get(0);
  1490. // String originStr = SHORT_REPORT_BEGIN.replace("#{0}", yesterdayData.getTestDate());
  1491. StringBuilder sb = new StringBuilder(SHORT_REPORT_BEGIN_1);
  1492. sb.append(yesterdayData.getTestDate());
  1493. sb.append(SHORT_REPORT_BEGIN_2);
  1494. for (TXinyiDaily dailyTwoRecord : dailyTwoRecords) {
  1495. sb.append(formateDateStr(dailyTwoRecord.getTestDate())).append("进出水质数据:\n");
  1496. sb.append("进水:\n");
  1497. sb.append("进水COD").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getJsCod(), 2)).append("mg/L、");
  1498. sb.append("进水总氮").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getJsTn(), 2)).append("mg/L、");
  1499. sb.append("进水总磷").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getJsTp(), 2)).append("mg/L、");
  1500. sb.append("进水氨氮").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getJsNh3(), 2)).append("mg/L、");
  1501. sb.append("进水SS").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getJsSs(), 2)).append("mg/L、");
  1502. sb.append("进水水量").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getJSL(), 2)).append("m³/d").append(";\n");
  1503. sb.append("出水:\n");
  1504. sb.append("出水COD").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getCsCod(), 2)).append("mg/L、");
  1505. sb.append("出水总氮").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getCsTn(), 2)).append("mg/L、");
  1506. sb.append("出水总磷").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getCsTp(), 2)).append("mg/L、");
  1507. sb.append("出水氨氮").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getCsNh3(), 2)).append("mg/L、");
  1508. sb.append("出水SS").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getCsSs(), 2)).append("mg/L、");
  1509. sb.append("出水水量").append(DecimalUtils.getAbsAndScale(dailyTwoRecord.getCSL(), 2)).append("m³/d").append("。\n");
  1510. }
  1511. sb.append(SHORT_REPORT_END);
  1512. sb.append("进水COD:").append(DecimalUtils.getAbsAndScale(normConfig.getJscodSjz(), 2)).append("mg/L、");
  1513. sb.append("进水总氮:").append(DecimalUtils.getAbsAndScale(normConfig.getJszdSjz(), 2)).append("mg/L、");
  1514. sb.append("进水总磷:").append(DecimalUtils.getAbsAndScale(normConfig.getJszlSjz(), 2)).append("mg/L、");
  1515. sb.append("进水氨氮:").append(DecimalUtils.getAbsAndScale(normConfig.getJsadSjz(), 2)).append("mg/L、");
  1516. sb.append("进水SS:").append(DecimalUtils.getAbsAndScale(normConfig.getJsssSjz(), 2)).append("mg/L、");
  1517. sb.append("出水COD:").append(DecimalUtils.getAbsAndScale(normConfig.getCscodBzz(), 2)).append("mg/L、");
  1518. sb.append("出水总氮:").append(DecimalUtils.getAbsAndScale(normConfig.getCszzBzz(), 2)).append("mg/L、");
  1519. sb.append("出水总磷:").append(DecimalUtils.getAbsAndScale(normConfig.getCszlBzz(), 2)).append("mg/L、");
  1520. sb.append("出水氨氮:").append(DecimalUtils.getAbsAndScale(normConfig.getCsadBzz(), 2)).append("mg/L、");
  1521. sb.append("出水SS:").append(DecimalUtils.getAbsAndScale(normConfig.getCsssBzz(), 2)).append("mg/L").append("。");
  1522. return sb.toString();
  1523. }
  1524. public static String handleDate(String str){
  1525. StringBuilder sb = new StringBuilder();
  1526. if(str.contains(" ")){//包含空格 就是年月日时分秒了
  1527. String[] split = str.split(" ");
  1528. addBeforeZero(sb, split[0], "/");
  1529. sb.append(" ");
  1530. addBeforeZero(sb, split[1], ":");
  1531. }else{
  1532. if(str.contains("/")){//年月日
  1533. addBeforeZero(sb, str, "/");
  1534. }else if(str.contains(":")){//时分秒
  1535. addBeforeZero(sb, str, ":");
  1536. }else {
  1537. sb.append(str);
  1538. }
  1539. }
  1540. return sb.toString();
  1541. }
  1542. public static StringBuilder addBeforeZero(StringBuilder sb, String str, String tag){
  1543. String[] split = str.split(tag);
  1544. int length = split.length;
  1545. for (int i = 0; i < length; i++) {
  1546. String value = split[i];
  1547. Integer intValue = Integer.parseInt(value);
  1548. if(intValue < 10 && value.length() == 1){////防止有正确的情况 额外再补充字符串
  1549. sb.append(0).append(value);
  1550. }else{
  1551. sb.append(value);
  1552. }
  1553. if(i < length-1){
  1554. sb.append(tag);
  1555. }
  1556. }
  1557. return sb;
  1558. }
  1559. public static void main(String[] args) throws ParseException, InterruptedException {
  1560. /*LocalDateTime endTime = LocalDateTime.now();
  1561. System.out.println("endTime = " + endTime);
  1562. endTime = endTime.plusMinutes(60);
  1563. System.out.println("endTime = " + endTime);*/
  1564. /*String str = "2024/04/15 09:55";
  1565. System.out.println(str);
  1566. System.out.println(str.substring(0,10));
  1567. System.out.println(str.substring(0,13));*/
  1568. /*String str = "2024/04/18 08:00";
  1569. str = str + ":00";
  1570. System.out.println(str);
  1571. LocalDateTime startTime = LocalDateTime.parse(str.replaceAll("/", "-").replace(" ", "T"));
  1572. System.out.println(startTime.plusMinutes(1L).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));*/
  1573. /*ArrayList<Integer> objects = new ArrayList<>();
  1574. objects.add(1);
  1575. objects.add(2);
  1576. objects.add(3);
  1577. System.out.println(objects);
  1578. objects.clear();
  1579. System.out.println(objects);
  1580. // test();
  1581. Date date = new Date();
  1582. System.out.println(DateUtils.differentHoursByMillisecond(date, date));
  1583. HashMap<Object, Object> map = new HashMap<>();
  1584. map.put("a", null);
  1585. map.put("b", "ab");
  1586. map.put("c", "");
  1587. map.put("d", '1');
  1588. System.out.println(JSON.toJSONString(map, JSONWriter.Feature.WriteNulls));
  1589. TXinyiIndustry tXinyiIndustry = new TXinyiIndustry();
  1590. System.out.println(JSON.toJSONString(tXinyiIndustry, JSONWriter.Feature.WriteNulls));*/
  1591. /*String s = "2022/01/01".substring(5).replace("/", "月") + "日";
  1592. System.out.println("s = " + s);
  1593. // System.out.println(new BigDecimal("1").compareTo(null));//空指针 要判断
  1594. System.out.println("2022/01/01 10".substring(11));
  1595. String date = DateUtil.format(DateUtils.getNowDate(), DateUtils.YYYY_MM_DD_HH);
  1596. System.out.println("date = " + date);
  1597. System.out.println(HttpUtil.get("http://10.0.3.52:10003/system/forecast?type=2&time=" + date, INT_10));*/
  1598. System.out.println("2024-06-18 14".replaceAll("-", "/"));
  1599. String[] splitNew = new String[3];
  1600. splitNew[0] = "0";
  1601. splitNew[1] = "1";
  1602. splitNew[2] = "2";
  1603. System.out.println(Arrays.toString(splitNew));
  1604. System.out.println(DateUtils.parseDate("2024-06-25 10", DateUtils.YYYY_MM_DD_HH));
  1605. String yesterdayStr = LocalDateTimeUtil.getCurrentDate().plusDays(-1).format(DateTimeFormatter.ofPattern(DateUtils.YYYYMMDD_TS));//昨天
  1606. System.out.println(yesterdayStr);
  1607. TimeUnit.MILLISECONDS.sleep(INT_10000);
  1608. System.out.println("2024/07/07 12".substring(0, 7));
  1609. }
  1610. //测试工业库 没小时保存一条记录是否可行
  1611. public static void test() {
  1612. // 每个小时的时间格式
  1613. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  1614. LocalDateTime startTime = LocalDateTime.parse("2024-05-18T00:00:00");
  1615. LocalDateTime endTime = LocalDateTime.now();
  1616. // 循环按小时分割
  1617. LocalDateTime currentHour = startTime;
  1618. //最终获取的数据
  1619. Map<String, TXinyiIndustry> needMap = new LinkedHashMap<>();
  1620. while (currentHour.isBefore(endTime)) {
  1621. String begin = currentHour.format(formatter);
  1622. String end = currentHour.plusMinutes(5).format(formatter);
  1623. // 输出当前小时的起始时间和结束时间
  1624. System.out.println("起始时间:" + begin);
  1625. System.out.println("结束时间:" + end);
  1626. // 当前小时加一小时,作为下一个小时的起始时间
  1627. currentHour = currentHour.plusMinutes(5);
  1628. //每个小时查询一次数据
  1629. String url = "http://10.0.0.27:4568/api/v1/khquerydata";
  1630. HashMap<String, Object> req = new HashMap<>();
  1631. req.put("tagNames", queryTags);
  1632. req.put("startTime", begin);
  1633. req.put("endTime", end);
  1634. req.put("recordNumbers", 100000);
  1635. String body = HttpRequest.post(url).header("Authorization", "c2E6c2E=").header("clientName", "hongshan").body(JSON.toJSONString(req)).execute().body();
  1636. // System.out.println("body = " + body);
  1637. List<HashMap<String, String>> list = new ArrayList<>();
  1638. //行转列数据处理
  1639. for (String queryTag : queryTags) {
  1640. JSONArray array = JSON.parseObject(body).getJSONArray(queryTag);
  1641. //特殊数据处理一
  1642. if(Objects.isNull(array) || array.isEmpty()){
  1643. System.out.println(queryTag + "查询到了空的数据,跳过本次循环");
  1644. continue;
  1645. }
  1646. int size = array.size();
  1647. //特殊数据处理二
  1648. if("0".equals(array.get(1) + "")){
  1649. System.out.println(queryTag + "查询到了数据,但是数据集合只有一条,且都是0");
  1650. continue;
  1651. }
  1652. //结合至少62个数据才满足条件(有可能获取不到)
  1653. /*if(size < 62){
  1654. System.out.println(queryTag + "查询到了不符合条件的数据,跳过本次循环");
  1655. continue;
  1656. }*/
  1657. //存放的数据集
  1658. //利用map去重
  1659. HashMap<String, String> map = new LinkedHashMap<>();
  1660. for (int i = 2; i < size; i++) {
  1661. // System.out.println(i + "" + array.get(i));
  1662. JSONArray oneRecord = JSON.parseArray(JSON.toJSONString(array.get(i)));
  1663. //处理为空或者为0的数据
  1664. Object timeStampValue = oneRecord.get(2);
  1665. if(Objects.isNull(timeStampValue) || "0".equals(timeStampValue + ""))
  1666. continue;
  1667. BigDecimal value = Objects.isNull(oneRecord.get(0)) ? null : new BigDecimal(oneRecord.get(0) + "");
  1668. long timestamp = (long) timeStampValue;
  1669. String format = DateUtil.format(new Date(timestamp), DateUtils.YYYYMMDDHH_TS);
  1670. map.put(format, queryTag + "-" + value);
  1671. }
  1672. list.add(map);
  1673. }
  1674. Set<String> recordTimeSet = new HashSet<>();
  1675. Map<String, TXinyiIndustry> recordMap = new HashMap<>();
  1676. for (int i = 0; i < list.size(); i++) {
  1677. HashMap<String, String> map = list.get(i);
  1678. int finalJ = i;
  1679. map.forEach((k, v) ->{
  1680. TXinyiIndustry industry = null;
  1681. if(!recordTimeSet.contains(k)){//第一次
  1682. industry = new TXinyiIndustry();
  1683. recordTimeSet.add(k);
  1684. recordMap.put(k, industry);
  1685. }else{
  1686. industry = recordMap.get(k);
  1687. }
  1688. industry.setTestTime(k + ":00");
  1689. //2024年4月15日11:19:52 额外增加2个字段
  1690. industry.setTestDate(k.substring(0,10));
  1691. industry.setTestHour(k.substring(0,13));
  1692. //解析值
  1693. String[] split = v.split("-");
  1694. String type = split[0];
  1695. BigDecimal value = new BigDecimal(split[1]);
  1696. if ("信义污水厂JS_COD_Value".equals(type)) {
  1697. industry.setJsCod(value);
  1698. } else if ("信义污水厂JS_PH_Value".equals(type)) {
  1699. industry.setJsPh(value);
  1700. } else if ("信义污水厂JS_SS_Value".equals(type)) {
  1701. industry.setJsSs(value);
  1702. } else if ("信义污水厂JS_ZL_Value".equals(type)) {
  1703. industry.setJsTp(value);
  1704. } else if ("信义污水厂JS_ZA_Value".equals(type)) {
  1705. industry.setJsTn(value);
  1706. } else if ("信义污水厂JS_AD_Value".equals(type)) {
  1707. industry.setJsNh3(value);
  1708. } else if ("信义污水厂JS_T_Value".equals(type)) {
  1709. industry.setJsSwPh(value);
  1710. } else if ("信义污水厂进水泵房液位".equals(type)) {
  1711. industry.setJsBfyw(value);
  1712. } else if ("信义污水厂出水瞬时流量".equals(type)) {
  1713. industry.setCsSlqc(value);
  1714. } else if ("信义污水厂升级出水COD".equals(type)) {
  1715. industry.setCsCod(value);
  1716. } else if ("信义污水厂升级出水PH".equals(type)) {
  1717. industry.setCsPh(value);
  1718. } else if ("信义污水厂升级出水SS".equals(type)) {
  1719. industry.setCsSs(value);
  1720. } else if ("信义污水厂升级出水TN".equals(type)) {
  1721. industry.setCsTn(value);
  1722. } else if ("信义污水厂升级出水TP".equals(type)) {
  1723. industry.setCsTp(value);
  1724. } else if ("信义污水厂升级出水氨氮".equals(type)) {
  1725. industry.setCsNh3(value);
  1726. } else if ("信义污水厂AIT202_Value".equals(type)) {
  1727. industry.setOneHyzdDo(value);
  1728. } else if ("信义污水厂AIT203_Value".equals(type)) {
  1729. industry.setOneHymdDo(value);
  1730. } else if ("信义污水厂AIT207_Value".equals(type)) {
  1731. industry.setTwoHyzdDo(value);
  1732. } else if ("信义污水厂AIT206_Value".equals(type)) {
  1733. industry.setTwoHymdDo(value);
  1734. } else if ("信义污水厂AIT209_Value".equals(type)) {
  1735. industry.setOneMlss(value);
  1736. } else if ("信义污水厂AIT210_Value".equals(type)) {
  1737. industry.setTwoMlss(value);
  1738. } else if ("信义污水厂进水TDS".equals(type)) {
  1739. industry.setJsTds(value);
  1740. } else if ("信义污水厂FT101_Value".equals(type)) {
  1741. industry.setJsSlq(value);
  1742. } else if ("信义污水厂SWCHHYHLB1_R_Value".equals(type)) {
  1743. industry.setNHlbOneGp(value);
  1744. } else if ("信义污水厂SWCHHYHLB2_R_Value".equals(type)) {
  1745. industry.setNHlbTwoGp(value);
  1746. } else if ("信义污水厂SWCHHYHLB3_R_Value".equals(type)) {
  1747. industry.setNHlbThreeGp(value);
  1748. } else if ("信义污水厂SWCHHYHLB4_R_Value".equals(type)) {
  1749. industry.setNHlbFourGp(value);
  1750. } else if ("信义污水厂SWCHHYHLB5_R_Value".equals(type)) {
  1751. industry.setNhlBFiveGp(value);
  1752. } else if ("信义污水厂SWCHHYHLB6_R_Value".equals(type)) {
  1753. industry.setNHlbSixGp(value);
  1754. } else if ("信义污水厂SWCWNHLB1_R_Value".equals(type)) {
  1755. industry.setWHlbOneGp(value);
  1756. } else if ("信义污水厂SWCWNHLB2_R_Value".equals(type)) {
  1757. industry.setWHlbTwoGp(value);
  1758. } else if ("信义污水厂SWCWNHLB3_R_Value".equals(type)) {
  1759. industry.setWHlbThreeGp(value);
  1760. } else if ("信义污水厂SWCWNHLB4_R_Value".equals(type)) {
  1761. industry.setWHlbFourGp(value);
  1762. } else if ("信义污水厂SWCWNHLB5_R_Value".equals(type)) {
  1763. industry.setWHlbFiveGp(value);
  1764. } else if ("信义污水厂GFJ1_R_Value".equals(type)) {
  1765. industry.setFjOne(value);
  1766. } else if ("信义污水厂GFJ2_R_Value".equals(type)) {
  1767. industry.setFjTwo(value);
  1768. } else if ("信义污水厂GFJ3_R_Value".equals(type)) {
  1769. industry.setFjThree(value);
  1770. } else if ("信义污水厂GFJ4_R_Value".equals(type)) {
  1771. industry.setFjFour(value);
  1772. } else if ("信义污水厂GFJ5_R_Value".equals(type)) {
  1773. industry.setFjFive(value);
  1774. } else if ("信义污水厂GFJ6_R_Value".equals(type)) {
  1775. industry.setFjSix(value);
  1776. } else if ("信义污水厂GFJ1_KQLL_Value".equals(type)) {
  1777. industry.setKqllOne(value);
  1778. } else if ("信义污水厂GFJ2_KQLL_Value".equals(type)) {
  1779. industry.setKqllTwo(value);
  1780. } else if ("信义污水厂GFJ3_KQLL_Value".equals(type)) {
  1781. industry.setKqllThree(value);
  1782. } else if ("信义污水厂GFJ4_KQLL_Value".equals(type)) {
  1783. industry.setKqllFour(value);
  1784. } else if ("信义污水厂GFJ5_KQLL_Value".equals(type)) {
  1785. industry.setKqllFive(value);
  1786. } else if ("信义污水厂GFJ6_KQLL_Value".equals(type)) {
  1787. industry.setKqllSix(value);
  1788. }else if ("信义污水厂实际碳源加药量".equals(type)) {
  1789. industry.setSJTYJLY(value);
  1790. }else if ("信义污水厂除磷加药瞬时流量".equals(type)) {
  1791. industry.setCLJYSSLL(value);
  1792. } else if ("信义污水厂_除磷P04预测值_".equals(type)) {
  1793. industry.setCLP04YCZ(value);
  1794. }
  1795. //只有最后一次才执行数据库添加
  1796. if(finalJ == list.size()-1){
  1797. needMap.put(industry.getTestHour(), industry);
  1798. }
  1799. });
  1800. }
  1801. }
  1802. //保存数据 触发告警 决策 问答记录等等
  1803. needMap.forEach((k, industry) ->{
  1804. System.out.println(JSON.toJSONString(industry));
  1805. });
  1806. }
  1807. }