TIronVisualScreenServiceImpl.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. package com.sckj.iron.service.impl;
  2. import com.sckj.common.util.TimeUtils;
  3. import com.sckj.iron.dto.IronTrendL1DTO;
  4. import com.sckj.iron.dto.IronTrendL2DTO;
  5. import com.sckj.iron.dto.RealtimeData;
  6. import com.sckj.l2.dto.TrendRequest;
  7. import com.sckj.l2.entity.TL2Data;
  8. import com.sckj.l2.service.impl.TL2DataServiceImpl;
  9. import com.sckj.opc.entity.OPCData;
  10. import com.sckj.opc.service.OPCDataServiceImpl;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.apache.commons.lang3.ObjectUtils;
  13. import org.springframework.stereotype.Service;
  14. import javax.annotation.Resource;
  15. import java.text.SimpleDateFormat;
  16. import java.time.LocalDateTime;
  17. import java.time.format.DateTimeFormatter;
  18. import java.util.*;
  19. import java.util.concurrent.CompletableFuture;
  20. import java.util.stream.Collectors;
  21. @Slf4j
  22. @Service
  23. public class TIronVisualScreenServiceImpl {
  24. @Resource
  25. OPCDataServiceImpl opcDataService;
  26. @Resource
  27. TL2DataServiceImpl tl2DataService;
  28. private static final SimpleDateFormat sdfMinute = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:00");
  29. /***
  30. * 实时数据图图例
  31. * @param ironChart
  32. * @return
  33. */
  34. public synchronized Map<String, Object> getIronLegend(Map<String, Object> ironChart, int ironPasstime) {
  35. Map<String, Object> result = new LinkedHashMap<>();
  36. if (ObjectUtils.isEmpty(ironChart)) {
  37. return result;
  38. }
  39. // 1. 计算起止时间
  40. int hours = 24;
  41. //给固定时间,24小时之内
  42. java.util.Date endTime = new java.util.Date();
  43. java.util.Calendar cal = java.util.Calendar.getInstance();
  44. cal.setTime(endTime);
  45. cal.add(java.util.Calendar.HOUR_OF_DAY, -hours);
  46. java.util.Date startTime = cal.getTime();
  47. // // 1. 计算起止时间
  48. // // 临时调试用,固定时间范围
  49. // final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  50. // final java.util.Date startTime;
  51. // final java.util.Date endTime;
  52. // try {
  53. // startTime = sdf.parse("2025-07-13 02:15:00");
  54. // endTime = sdf.parse("2025-07-14 00:20:00");
  55. // } catch (Exception e) {
  56. // throw new RuntimeException("时间解析失败", e);
  57. // }
  58. List<TL2Data> tl2DataList = tl2DataService.lambdaQuery()
  59. .between(TL2Data::getIronStarttime,
  60. new SimpleDateFormat("yyyyMMddHHmmss").format(startTime),
  61. new SimpleDateFormat("yyyyMMddHHmmss").format(endTime))
  62. .eq(TL2Data::getTapholeId, "1")
  63. .orderByAsc(TL2Data::getIronStarttime)
  64. .list();
  65. List<List<Object>> elementS = (List<List<Object>>) ironChart.get("elementS");
  66. List<List<Object>> elementSi = (List<List<Object>>) ironChart.get("elementSi");
  67. List<List<Object>> mudWeight = (List<List<Object>>) ironChart.get("mudWeight");
  68. List<List<Object>> pollMm = (List<List<Object>>) ironChart.get("pollMm");
  69. List<List<Object>> openDepth = (List<List<Object>>) ironChart.get("openDepth");
  70. List<List<Object>> ironCosttime = (List<List<Object>>) ironChart.get("ironCosttime");
  71. List<List<Object>> ironSpeed = (List<List<Object>>) ironChart.get("ironSpeed");
  72. List<List<Object>> ironTemp = (List<List<Object>>) ironChart.get("ironTemp");
  73. List<List<Object>> ironWeight = (List<List<Object>>) ironChart.get("ironWeight");
  74. result.put("elementS", RealtimeData.builder().desc("铁水成分-硫").value(elementS.get(elementS.size() - 1).get(1)).build());
  75. result.put("elementSi", RealtimeData.builder().desc("铁水成分-硅").value(elementSi.get(elementSi.size() - 1).get(1)).build());
  76. result.put("mudWeight", RealtimeData.builder().desc("打泥量").value(mudWeight.get(mudWeight.size() - 1).get(1)).unit("L").build());
  77. result.put("pollMm", RealtimeData.builder().desc("钻杆直径").value(pollMm.get(pollMm.size() - 1).get(1)).unit("mm").build());
  78. result.put("openDepth", RealtimeData.builder().desc("开口深度").value(openDepth.get(openDepth.size() - 1).get(1)).unit("mm").build());
  79. RealtimeData realtimeDataIronConsttime = RealtimeData.builder().desc("出铁时间").unit("min").value(ironPasstime).build();
  80. if (ObjectUtils.isNotEmpty(tl2DataList)) {
  81. List<List<Map<String, Object>>> collect = tl2DataList.stream().map(item -> {
  82. List<Map<String, Object>> mapList = new ArrayList<>();
  83. Map<String, Object> map = new HashMap<>();
  84. map.put("name", String.format("第%s次出铁\n(%s号铁口)%s分钟", item.getIronNo(), item.getTapholeId(), item.getIronCosttime()));
  85. map.put("xAxis", TimeUtils.formatPartialDateString(item.getIronStarttime()));
  86. mapList.add(map);
  87. map = new HashMap<>();
  88. map.put("xAxis", TimeUtils.formatPartialDateString(item.getIronEndtime()));
  89. mapList.add(map);
  90. return mapList;
  91. }).collect(Collectors.toList());
  92. Map<String, Object> extraMap = new HashMap<>();
  93. extraMap.put("mark", collect);
  94. realtimeDataIronConsttime.setExtra(extraMap);
  95. }
  96. result.put("ironCosttime", realtimeDataIronConsttime);
  97. result.put("ironWeight", RealtimeData.builder().desc("累计出铁量").value(ironWeight.get(ironWeight.size() - 1).get(1)).unit("t").build());
  98. result.put("ironSpeed", RealtimeData.builder().desc("铁水流速").value(ironSpeed.get(ironSpeed.size() - 1).get(1)).unit("t/min").build());
  99. result.put("ironTemp", RealtimeData.builder().desc("铁水温度").value(ironTemp.get(ironTemp.size() - 1).get(1)).unit("℃").build());
  100. return result;
  101. }
  102. /***
  103. * 实时折线图数据,
  104. * BF4_1_IRONNOTCH_TAPPING表示出铁状态,数值只有0和1,1表示正在出铁,0表示未出铁
  105. * BF4_1TH_1_MIR_NWT表示四高炉1TH-1号车铁水净重,BF4_1TH_2_MIR_NWT表示四高炉1TH-2号车铁水净重,这2车一开始的重量为0,然后装入铁水重量不断增加,直到满载,然后减为0,然后继续增加,以此往复
  106. *
  107. * @param queryDateType
  108. * @return
  109. */
  110. public synchronized Map<String, Object> getIronChart(TrendRequest queryDateType) {
  111. // 1. 计算起止时间
  112. int hours = Objects.isNull(queryDateType.getQueryHourBefore()) ? 24 : queryDateType.getQueryHourBefore();
  113. //给固定时间,24小时之内
  114. java.util.Date endTime = new java.util.Date();
  115. java.util.Calendar cal = java.util.Calendar.getInstance();
  116. cal.setTime(endTime);
  117. cal.add(java.util.Calendar.HOUR_OF_DAY, -hours);
  118. java.util.Date startTime = cal.getTime();
  119. // 临时调试用,固定时间范围
  120. // final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  121. // final java.util.Date startTime;
  122. // final java.util.Date endTime;
  123. // try {
  124. // startTime = sdf.parse("2025-07-19 09:30:00");
  125. // endTime = sdf.parse("2025-07-20 09:30:00");
  126. // } catch (Exception e) {
  127. // throw new RuntimeException("时间解析失败", e);
  128. // }
  129. // 2. 异步查询所有数据
  130. CompletableFuture<List<OPCData>> opcDataFuture = CompletableFuture.supplyAsync(() ->
  131. opcDataService.lambdaQuery()
  132. .in(OPCData::getPointName, Arrays.asList(
  133. "BF4_1_IRONNOTCH_MIR_TEMP", // 温度
  134. "BF4_1_IRONNOTCH_RAILLINE_ACPIRON_SPEED1", // 1车流速
  135. "BF4_1_IRONNOTCH_RAILLINE_ACPIRON_SPEED2", // 2车流速
  136. "BF4_1TH_1_MIR_NWT", // 四高炉1TH-1号车铁水净重
  137. "BF4_1TH_2_MIR_NWT", // 四高炉1TH-2号车铁水净重
  138. "BF4_1_IRONNOTCH_TAPPING", // 1号铁口出铁状态
  139. "BF4_1TH_2_TPC_CARNO", // 1TH-2号车混铁车车号
  140. "BF4_1TH_1_TPC_CARNO" // 1TH-1号车混铁车车号
  141. ))
  142. .between(OPCData::getServerTime, startTime, endTime)
  143. .orderByAsc(OPCData::getServerTime)
  144. .list()
  145. );
  146. CompletableFuture<List<TL2Data>> l2DataFuture = CompletableFuture.supplyAsync(() ->
  147. tl2DataService.lambdaQuery()
  148. .between(TL2Data::getIronStarttime,
  149. new SimpleDateFormat("yyyyMMddHHmmss").format(startTime),
  150. new SimpleDateFormat("yyyyMMddHHmmss").format(endTime))
  151. .eq(TL2Data::getTapholeId, "1")
  152. .orderByAsc(TL2Data::getIronStarttime)
  153. .list()
  154. );
  155. // 3. 等待所有查询完成并转换数据
  156. try {
  157. // 4. 按pointName分类OPC数据并转换为DTO
  158. Map<String, List<OPCData>> opcDataMap = opcDataFuture.get().stream()
  159. .collect(Collectors.groupingBy(OPCData::getPointName));
  160. List<TL2Data> l2DataList = l2DataFuture.get();
  161. // 并行转换所有数据
  162. //铁水温度
  163. CompletableFuture<List<IronTrendL1DTO>> tempListFuture = CompletableFuture.supplyAsync(() ->
  164. opcDataMap.getOrDefault("BF4_1_IRONNOTCH_MIR_TEMP", new ArrayList<>())
  165. .stream().map(item -> {
  166. IronTrendL1DTO dto = new IronTrendL1DTO();
  167. dto.setData(item.getData());
  168. dto.setCreateTime(item.getSourceTime());
  169. return dto;
  170. }).collect(Collectors.toList())
  171. );
  172. //1TH-1号车受铁速度
  173. CompletableFuture<List<IronTrendL1DTO>> speed1ListFuture = CompletableFuture.supplyAsync(() ->
  174. opcDataMap.getOrDefault("BF4_1_IRONNOTCH_RAILLINE_ACPIRON_SPEED1", new ArrayList<>())
  175. .stream().map(item -> {
  176. IronTrendL1DTO dto = new IronTrendL1DTO();
  177. dto.setData(item.getData());
  178. dto.setCreateTime(item.getSourceTime());
  179. return dto;
  180. }).collect(Collectors.toList())
  181. );
  182. //1TH-2号车受铁速度
  183. CompletableFuture<List<IronTrendL1DTO>> speed2ListFuture = CompletableFuture.supplyAsync(() ->
  184. opcDataMap.getOrDefault("BF4_1_IRONNOTCH_RAILLINE_ACPIRON_SPEED2", new ArrayList<>())
  185. .stream().map(item -> {
  186. IronTrendL1DTO dto = new IronTrendL1DTO();
  187. dto.setData(item.getData());
  188. dto.setCreateTime(item.getSourceTime());
  189. return dto;
  190. }).collect(Collectors.toList())
  191. );
  192. //BF4_1TH_1_MIR_NWT 1号车净重
  193. CompletableFuture<List<IronTrendL1DTO>> weight1ListFuture = CompletableFuture.supplyAsync(() ->
  194. opcDataMap.getOrDefault("BF4_1TH_1_MIR_NWT", new ArrayList<>())
  195. .stream().map(item -> {
  196. IronTrendL1DTO dto = new IronTrendL1DTO();
  197. dto.setData(item.getData());
  198. dto.setCreateTime(item.getSourceTime());
  199. return dto;
  200. }).collect(Collectors.toList())
  201. );
  202. //BF4_1TH_2_MIR_NWT 2号车净重
  203. CompletableFuture<List<IronTrendL1DTO>> weight2ListFuture = CompletableFuture.supplyAsync(() ->
  204. opcDataMap.getOrDefault("BF4_1TH_2_MIR_NWT", new ArrayList<>())
  205. .stream().map(item -> {
  206. IronTrendL1DTO dto = new IronTrendL1DTO();
  207. dto.setData(item.getData());
  208. dto.setCreateTime(item.getSourceTime());
  209. return dto;
  210. }).collect(Collectors.toList())
  211. );
  212. //L2
  213. CompletableFuture<List<IronTrendL2DTO>> elemenListFuture = CompletableFuture.supplyAsync(() ->
  214. l2DataList.stream().map(item -> {
  215. IronTrendL2DTO dto = new IronTrendL2DTO();
  216. try {
  217. dto.setElementS(item.getElementS() != null ? Double.parseDouble(item.getElementS()) : null);
  218. } catch (NumberFormatException e) {
  219. dto.setElementS(null);
  220. }
  221. try {
  222. dto.setElementSi(item.getElementSi() != null ? Double.parseDouble(item.getElementSi()) : null);
  223. } catch (NumberFormatException e) {
  224. dto.setElementSi(null);
  225. }
  226. dto.setIronStarttime(item.getIronStarttime());
  227. dto.setIronEndtime(item.getIronEndtime());
  228. dto.setPollMm(item.getPollMm());
  229. dto.setOpenDepth(item.getOpenDepth());
  230. dto.setMudWeight(item.getMudWeight());
  231. dto.setIronCosttime(item.getIronCosttime());
  232. return dto;
  233. }).collect(Collectors.toList())
  234. );
  235. // 等待所有转换完成
  236. CompletableFuture.allOf(
  237. tempListFuture,
  238. speed1ListFuture,
  239. speed2ListFuture,
  240. weight1ListFuture,
  241. weight2ListFuture,
  242. elemenListFuture
  243. ).join();
  244. // 5. 封装返回
  245. List<IronTrendL1DTO> tempList = tempListFuture.get();
  246. List<IronTrendL1DTO> speed1List = speed1ListFuture.get();
  247. List<IronTrendL1DTO> speed2List = speed2ListFuture.get();
  248. List<IronTrendL1DTO> weight1List = weight1ListFuture.get();
  249. List<IronTrendL1DTO> weight2List = weight2ListFuture.get();
  250. List<IronTrendL2DTO> elemenList = elemenListFuture.get();
  251. // 1. 生成完整的每一分钟时间点
  252. java.util.List<String> xAxis = new java.util.ArrayList<>();
  253. java.util.Calendar cursor = java.util.Calendar.getInstance();
  254. cursor.setTime(startTime);
  255. while (!cursor.getTime().after(endTime)) {
  256. xAxis.add(sdfMinute.format(cursor.getTime()));
  257. cursor.add(java.util.Calendar.MINUTE, 1);
  258. }
  259. // 查询区间前的最近一条历史数据(前置值)
  260. // OPC类
  261. OPCData preTemp = opcDataService.lambdaQuery()
  262. .eq(OPCData::getPointName, "BF4_1_IRONNOTCH_MIR_TEMP")
  263. .isNotNull(OPCData::getData)
  264. .lt(OPCData::getServerTime, startTime)
  265. .orderByDesc(OPCData::getServerTime)
  266. .last("limit 1").one();
  267. OPCData preSpeed1 = opcDataService.lambdaQuery()
  268. .eq(OPCData::getPointName, "BF4_1_IRONNOTCH_RAILLINE_ACPIRON_SPEED1")
  269. .isNotNull(OPCData::getData)
  270. .lt(OPCData::getServerTime, startTime)
  271. .orderByDesc(OPCData::getServerTime)
  272. .last("limit 1").one();
  273. OPCData preSpeed2 = opcDataService.lambdaQuery()
  274. .eq(OPCData::getPointName, "BF4_1_IRONNOTCH_RAILLINE_ACPIRON_SPEED2")
  275. .isNotNull(OPCData::getData)
  276. .lt(OPCData::getServerTime, startTime)
  277. .orderByDesc(OPCData::getServerTime)
  278. .last("limit 1").one();
  279. OPCData preWeight1 = opcDataService.lambdaQuery()
  280. .eq(OPCData::getPointName, "BF4_1TH_1_MIR_NWT")
  281. .isNotNull(OPCData::getData)
  282. .lt(OPCData::getServerTime, startTime)
  283. .orderByDesc(OPCData::getServerTime)
  284. .last("limit 1").one();
  285. OPCData preWeight2 = opcDataService.lambdaQuery()
  286. .eq(OPCData::getPointName, "BF4_1TH_2_MIR_NWT")
  287. .isNotNull(OPCData::getData)
  288. .lt(OPCData::getServerTime, startTime)
  289. .orderByDesc(OPCData::getServerTime)
  290. .last("limit 1").one();
  291. // tappingMap补齐每一分钟,前面无数据用前置值补齐
  292. // 先查区间前最近一条tapping
  293. Integer preTappingVal = 0;
  294. OPCData preTapping = opcDataService.lambdaQuery()
  295. .eq(OPCData::getPointName, "BF4_1_IRONNOTCH_TAPPING")
  296. .isNotNull(OPCData::getData)
  297. .lt(OPCData::getServerTime, startTime)
  298. .orderByDesc(OPCData::getServerTime)
  299. .last("limit 1").one();
  300. // L2类
  301. TL2Data preL2 = tl2DataService.lambdaQuery()
  302. .lt(TL2Data::getIronStarttime, new SimpleDateFormat("yyyyMMddHHmmss").format(startTime))
  303. .eq(TL2Data::getTapholeId, "1")
  304. .orderByDesc(TL2Data::getIronStarttime)
  305. .last("limit 1").one();
  306. // 2. 构建每分钟补全的二维数组
  307. java.util.Map<String, Object> result = new java.util.LinkedHashMap<>();
  308. //
  309. if (preTapping != null && preTapping.getData() != null) {
  310. Object v = preTapping.getData();
  311. if (v instanceof Number) preTappingVal = ((Number) v).intValue();
  312. else if (v instanceof String) {
  313. String str = ((String) v).trim();
  314. if (!str.isEmpty()) {
  315. try {
  316. preTappingVal = Integer.parseInt(str);
  317. } catch (Exception ignore) {
  318. }
  319. }
  320. }
  321. }
  322. // 构建每分钟tappingMap
  323. Map<String, Integer> tappingMap = new LinkedHashMap<>();
  324. List<OPCData> tappingList = opcDataMap.getOrDefault("BF4_1_IRONNOTCH_TAPPING", new ArrayList<>());
  325. Map<String, Integer> rawTappingMap = new LinkedHashMap<>();
  326. for (OPCData item : tappingList) {
  327. if (item.getServerTime() != null && item.getData() != null) {
  328. String min = sdfMinute.format(item.getServerTime());
  329. Integer val = null;
  330. Object v = item.getData();
  331. if (v instanceof Number) val = ((Number) v).intValue();
  332. else if (v instanceof String) {
  333. String str = ((String) v).trim();
  334. if (!str.isEmpty()) {
  335. try {
  336. val = Integer.parseInt(str);
  337. } catch (Exception ignore) {
  338. }
  339. }
  340. }
  341. if (val != null) rawTappingMap.put(min, val);
  342. }
  343. }
  344. Integer last = preTappingVal;
  345. for (String t : xAxis) {
  346. Integer v = rawTappingMap.getOrDefault(t, last);
  347. tappingMap.put(t, v);
  348. if (v != null) last = v;
  349. }
  350. int ironWeightScale = 2; // 可调整为0、1、2等
  351. List<List<Object>> ironFlowArr = buildIronWeightMinuteArray(xAxis, tappingMap, weight1List, weight2List, ironWeightScale);
  352. result.put("ironWeight", ironFlowArr);
  353. // 处理铁水流速,出铁中按原逻辑,出铁结束后为0
  354. List<List<Object>> ironSpeedArr = buildMinuteArrayForSpeed(xAxis, speed1List, speed2List, tappingMap);
  355. List<List<Object>> ironTempArr = buildMinuteArray(tempList, xAxis, preTemp != null ? preTemp.getData() : null);
  356. for (int i = 0; i < xAxis.size(); i++) {
  357. String t = xAxis.get(i);
  358. Integer tapping = tappingMap.getOrDefault(t, 0);
  359. if (tapping == 0 && ironSpeedArr.get(i).size() > 1) {
  360. ironSpeedArr.get(i).set(1, 0);
  361. ironTempArr.get(i).set(1, 0);
  362. }
  363. }
  364. result.put("ironSpeed", ironSpeedArr);
  365. result.put("ironTemp", ironTempArr);
  366. // 处理L2类数据,tapping=0时设为0
  367. List<List<Object>> elementSArr = buildL2MinuteArray(elemenList, xAxis, tappingMap, "elementS", preL2 != null ? preL2.getElementS() : null);
  368. List<List<Object>> elementSiArr = buildL2MinuteArray(elemenList, xAxis, tappingMap, "elementSi", preL2 != null ? preL2.getElementSi() : null);
  369. List<List<Object>> mudWeightArr = buildL2MinuteArray(elemenList, xAxis, tappingMap, "mudWeight", preL2 != null ? preL2.getMudWeight() : null);
  370. List<List<Object>> pollMmArr = buildL2MinuteArray(elemenList, xAxis, tappingMap, "pollMm", preL2 != null ? preL2.getPollMm() : null);
  371. List<List<Object>> openDepthArr = buildL2MinuteArray(elemenList, xAxis, tappingMap, "openDepth", preL2 != null ? preL2.getOpenDepth() : null);
  372. List<List<Object>> ironCosttimeArr = buildL2MinuteArray(elemenList, xAxis, tappingMap, "ironCosttime", preL2 != null ? preL2.getIronCosttime() : null);
  373. // for (int i = 0; i < xAxis.size(); i++) {
  374. // String t = xAxis.get(i);
  375. // Integer tapping = tappingMap.getOrDefault(t, 0);
  376. // if (tapping == 0) {
  377. // if (elementSArr.get(i).size() > 1) elementSArr.get(i).set(1, 0);
  378. // if (elementSiArr.get(i).size() > 1) elementSiArr.get(i).set(1, 0);
  379. // if (mudWeightArr.get(i).size() > 1) mudWeightArr.get(i).set(1, 0);
  380. // if (pollMmArr.get(i).size() > 1) pollMmArr.get(i).set(1, 0);
  381. // if (openDepthArr.get(i).size() > 1) openDepthArr.get(i).set(1, 0);
  382. // if (ironCosttimeArr.get(i).size() > 1) ironCosttimeArr.get(i).set(1, 0);
  383. // }
  384. // }
  385. result.put("elementS", elementSArr);
  386. result.put("elementSi", elementSiArr);
  387. result.put("mudWeight", mudWeightArr);
  388. result.put("pollMm", pollMmArr);
  389. result.put("openDepth", openDepthArr);
  390. result.put("ironCosttime", ironCosttimeArr);
  391. return result;
  392. } catch (Exception e) {
  393. e.printStackTrace();
  394. }
  395. return null;
  396. }
  397. // 新增工具方法:L1类型
  398. private java.util.List<java.util.List<Object>> buildMinuteArray(java.util.List<IronTrendL1DTO> list, java.util.List<String> xAxis, Object preValue) {
  399. java.util.Map<String, Object> timeValueMap = new java.util.LinkedHashMap<>();
  400. for (IronTrendL1DTO e : list) {
  401. if (e.getCreateTime() != null) {
  402. String min = sdfMinute.format(e.getCreateTime());
  403. timeValueMap.put(min, e.getData());
  404. }
  405. }
  406. java.util.List<java.util.List<Object>> arr = new java.util.ArrayList<>();
  407. Object last = preValue;
  408. for (String t : xAxis) {
  409. Object v = timeValueMap.getOrDefault(t, last);
  410. arr.add(java.util.Arrays.asList(t, v));
  411. if (v != null) last = v;
  412. }
  413. return arr;
  414. }
  415. // 铁水流速(重写:合并取最大值,出铁周期内补齐空值,且出铁周期内流速不允许为0)
  416. private java.util.List<java.util.List<Object>> buildMinuteArrayForSpeed(java.util.List<String> xAxis, java.util.List<IronTrendL1DTO> speed1List, java.util.List<IronTrendL1DTO> speed2List, java.util.Map<String, Integer> tappingMap) {
  417. java.util.Map<String, Double> speed1Map = new java.util.LinkedHashMap<>();
  418. java.util.Map<String, Double> speed2Map = new java.util.LinkedHashMap<>();
  419. for (IronTrendL1DTO e : speed1List) {
  420. if (e.getCreateTime() != null) {
  421. String min = sdfMinute.format(e.getCreateTime());
  422. Object v = e.getData();
  423. Double value = null;
  424. if (v instanceof Number) value = ((Number) v).doubleValue();
  425. else if (v instanceof String) {
  426. try {
  427. value = Double.parseDouble((String) v);
  428. } catch (Exception ignore) {
  429. }
  430. }
  431. if (value != null) speed1Map.put(min, value);
  432. }
  433. }
  434. for (IronTrendL1DTO e : speed2List) {
  435. if (e.getCreateTime() != null) {
  436. String min = sdfMinute.format(e.getCreateTime());
  437. Object v = e.getData();
  438. Double value = null;
  439. if (v instanceof Number) value = ((Number) v).doubleValue();
  440. else if (v instanceof String) {
  441. try {
  442. value = Double.parseDouble((String) v);
  443. } catch (Exception ignore) {
  444. }
  445. }
  446. if (value != null) speed2Map.put(min, value);
  447. }
  448. }
  449. // 合并为最大值map
  450. java.util.Map<String, Double> speedMap = new java.util.LinkedHashMap<>();
  451. for (String key : speed1Map.keySet()) {
  452. speedMap.put(key, speed1Map.get(key));
  453. }
  454. for (String key : speed2Map.keySet()) {
  455. double v2 = speed2Map.get(key);
  456. speedMap.put(key, Math.max(speedMap.getOrDefault(key, 0d), v2));
  457. }
  458. java.util.List<java.util.List<Object>> arr = new java.util.ArrayList<>();
  459. Double last = null;
  460. for (String t : xAxis) {
  461. Integer tapping = tappingMap.getOrDefault(t, 0);
  462. Double v = speedMap.get(t);
  463. if (tapping == 1) {
  464. if (v == null || v == 0) {
  465. // 出铁周期内流速不允许为0,用上一个非0值
  466. v = last != null ? last : 0d;
  467. }
  468. arr.add(java.util.Arrays.asList(t, v));
  469. if (v != null && v != 0) last = v;
  470. } else {
  471. arr.add(java.util.Arrays.asList(t, 0));
  472. }
  473. }
  474. return arr;
  475. }
  476. //L2
  477. private java.util.List<java.util.List<Object>> buildL2MinuteArray(java.util.List<IronTrendL2DTO> list, java.util.List<String> xAxis, Map<String, Integer> tappingMap, String field, Object preValue) {
  478. java.util.Map<String, Object> timeValueMap = new java.util.LinkedHashMap<>();
  479. for (IronTrendL2DTO e : list) {
  480. String startMin = TimeUtils.formatPartialDateStringMin(e.getIronStarttime());
  481. String endMin = TimeUtils.formatPartialDateStringMin(e.getIronEndtime());
  482. if (startMin != null && endMin != null) {
  483. Object v = null;
  484. switch (field) {
  485. case "elementS":
  486. v = e.getElementS();
  487. break;
  488. case "elementSi":
  489. v = e.getElementSi();
  490. break;
  491. case "mudWeight":
  492. v = e.getMudWeight();
  493. break;
  494. case "pollMm":
  495. v = e.getPollMm();
  496. break;
  497. case "openDepth":
  498. v = e.getOpenDepth();
  499. break;
  500. case "ironCosttime":
  501. v = e.getIronCosttime();
  502. break;
  503. }
  504. // 定义时间格式
  505. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:00");
  506. // 解析字符串为LocalDateTime对象
  507. LocalDateTime startTime = LocalDateTime.parse(startMin, formatter);
  508. LocalDateTime endTime = LocalDateTime.parse(endMin, formatter);
  509. // 遍历每一分钟
  510. LocalDateTime currentTime = startTime;
  511. while (!currentTime.isAfter(endTime)) {
  512. timeValueMap.put(currentTime.format(formatter), v);
  513. // 增加一分钟
  514. currentTime = currentTime.plusMinutes(1);
  515. }
  516. }
  517. }
  518. java.util.List<java.util.List<Object>> arr = new java.util.ArrayList<>();
  519. Object last = preValue;
  520. // for (String time : xAxis) {
  521. // Integer tapping = tappingMap.getOrDefault(time, 0);
  522. // Object v = timeValueMap.getOrDefault(time, last);
  523. // double value = Double.parseDouble(v.toString());
  524. // if (tapping == 1) {
  525. // if (value == 0 ) {
  526. // //
  527. // value = last != null ? Double.parseDouble(last.toString()) : 0;
  528. // }
  529. // arr.add(java.util.Arrays.asList(time,value));
  530. // if (value != 0){
  531. // last = value;
  532. // }
  533. // } else {
  534. // arr.add(java.util.Arrays.asList(time, 0));
  535. // last = 0;
  536. // }
  537. // }
  538. for (String time : xAxis) {
  539. Object value = timeValueMap.getOrDefault(time, last);
  540. List item = new ArrayList();
  541. item.add(time);
  542. Integer tapping = tappingMap.getOrDefault(time, 0);
  543. if (tapping == 0) {
  544. item.add(0);
  545. last = null;
  546. } else {
  547. if (null == value) {
  548. item.add(0);
  549. last = null;
  550. } else {
  551. item.add(value);
  552. last = value;
  553. }
  554. }
  555. arr.add(item);
  556. }
  557. //处理正在出铁的情况
  558. if (tappingMap.getOrDefault(xAxis.get(xAxis.size() - 1), 0) > 0) {
  559. //表明正在出铁中
  560. for (int i = xAxis.size() - 1; i >= 0; i--) {
  561. Integer tapping = tappingMap.getOrDefault(xAxis.get(i), 0);
  562. if (tapping <= 0) {
  563. break;
  564. } else {
  565. if (arr.get(i).size() > 1) arr.get(i).set(1, 0);
  566. }
  567. }
  568. }
  569. return arr;
  570. }
  571. //铁水重量
  572. private List<List<Object>> buildIronWeightMinuteArray(List<String> xAxis, Map<String, Integer> tappingMap, List<IronTrendL1DTO> weight1List, List<IronTrendL1DTO> weight2List, int scale) {
  573. Map<String, Double> weight1Map = new LinkedHashMap<>();
  574. for (IronTrendL1DTO e : weight1List) {
  575. if (e.getCreateTime() != null) {
  576. String min = sdfMinute.format(e.getCreateTime());
  577. Object v = e.getData();
  578. Double value = null;
  579. if (v instanceof Number) value = ((Number) v).doubleValue();
  580. else if (v instanceof String) {
  581. String str = ((String) v).trim();
  582. if (!str.isEmpty()) {
  583. try {
  584. value = Double.parseDouble(str);
  585. } catch (Exception ignore) {
  586. }
  587. }
  588. }
  589. if (value != null) {
  590. weight1Map.put(min, value);
  591. }
  592. }
  593. }
  594. Map<String, Double> weight2Map = new LinkedHashMap<>();
  595. for (IronTrendL1DTO e : weight2List) {
  596. if (e.getCreateTime() != null) {
  597. String min = sdfMinute.format(e.getCreateTime());
  598. Object v = e.getData();
  599. Double value = null;
  600. if (v instanceof Number) value = ((Number) v).doubleValue();
  601. else if (v instanceof String) {
  602. String str = ((String) v).trim();
  603. if (!str.isEmpty()) {
  604. try {
  605. value = Double.parseDouble(str);
  606. } catch (Exception ignore) {
  607. }
  608. }
  609. }
  610. if (value != null) {
  611. weight2Map.put(min, value);
  612. }
  613. }
  614. }
  615. // 合并weight1Map和weight2Map到weightMap,取最大值
  616. Map<String, Double> weightMap = new LinkedHashMap<>();
  617. for (Map.Entry<String, Double> entry : weight1Map.entrySet()) {
  618. weightMap.put(entry.getKey(), entry.getValue());
  619. }
  620. for (Map.Entry<String, Double> entry : weight2Map.entrySet()) {
  621. weightMap.put(entry.getKey(), Math.max(weightMap.getOrDefault(entry.getKey(), 0d), entry.getValue()));
  622. }
  623. // 按key正序排序
  624. weightMap = weightMap.entrySet().stream()
  625. .sorted(Map.Entry.comparingByKey())
  626. .collect(java.util.LinkedHashMap::new, (m, e) -> m.put(e.getKey(), e.getValue()), java.util.LinkedHashMap::putAll);
  627. List<List<Object>> arr = new ArrayList<>();
  628. boolean inTappingCycle = false;
  629. java.math.BigDecimal cycleTotal = java.math.BigDecimal.ZERO;
  630. java.math.BigDecimal lastW = java.math.BigDecimal.ZERO;
  631. for (int i = 0; i < xAxis.size(); i++) {
  632. String time = xAxis.get(i);
  633. Integer tapping = tappingMap.getOrDefault(time, 0);
  634. java.math.BigDecimal w = new java.math.BigDecimal(weightMap.getOrDefault(time, 0d).toString());
  635. if (tapping == 1) {
  636. if (!inTappingCycle) {
  637. inTappingCycle = true;
  638. //System.out.println("[出铁周期结束] 开始于: " + time);
  639. }
  640. if (w.compareTo(java.math.BigDecimal.ZERO) == 0) {
  641. w = lastW;
  642. weightMap.put(time, w.doubleValue());
  643. } else {
  644. lastW = w;
  645. }
  646. if (i > 0) {
  647. java.math.BigDecimal prevW = new java.math.BigDecimal(weightMap.getOrDefault(xAxis.get(i - 1), 0d).toString());
  648. //上一个减去当前的
  649. if (prevW.subtract(w).compareTo(new java.math.BigDecimal("130")) > 0) {
  650. //System.out.println("[出铁周期满载情况] 时间: " + xAxis.get(i - 1) + ", 铁水满载值: " + prevW);
  651. cycleTotal = cycleTotal.add(prevW);
  652. }
  653. }
  654. arr.add(java.util.Arrays.asList(time, w.add(cycleTotal).setScale(scale, java.math.RoundingMode.HALF_UP).doubleValue()));
  655. } else {
  656. if (inTappingCycle) {
  657. double value = cycleTotal.setScale(scale, java.math.RoundingMode.HALF_UP).doubleValue();
  658. //System.out.println("[出铁周期结束] 结束于: " + time + ", 本周期铁水总净重: " + value);
  659. arr.add(java.util.Arrays.asList(time, value));
  660. inTappingCycle = false;
  661. cycleTotal = java.math.BigDecimal.ZERO;
  662. // for (List<Object> objects : arr) {
  663. // System.out.println(objects.get(0)+" >>> "+objects.get(1));
  664. // }
  665. } else {
  666. arr.add(java.util.Arrays.asList(time, 0));
  667. }
  668. }
  669. }
  670. return arr;
  671. }
  672. }