RyTask.java 132 KB

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