RyTask.java 111 KB

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