Browse Source

代码优化

wangxiaofei 2 weeks ago
parent
commit
b1cf6b35d2

+ 24 - 8
taphole-iron/src/main/java/com/sckj/iron/service/impl/TIronVisualScreenServiceImpl.java

@@ -1,5 +1,6 @@
 package com.sckj.iron.service.impl;
 
+import com.sckj.common.util.LocalDateUtils;
 import com.sckj.common.util.TimeUtils;
 import com.sckj.iron.dto.IronTrendL1DTO;
 import com.sckj.iron.dto.IronTrendL2DTO;
@@ -18,7 +19,6 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
@@ -558,21 +558,21 @@ public class TIronVisualScreenServiceImpl {
                         break;
                 }
                 // 定义时间格式
-                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+              //  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                 // 解析字符串为LocalDateTime对象
-                LocalDateTime startTime = LocalDateTime.parse(startMin, formatter).withSecond(0);
-                LocalDateTime endTime = LocalDateTime.parse(endMin, formatter).withSecond(0);
+                LocalDateTime startTime = LocalDateTime.parse(startMin, LocalDateUtils.DATE_TIME_FORMATTER).withSecond(0);
+                LocalDateTime endTime = LocalDateTime.parse(endMin, LocalDateUtils.DATE_TIME_FORMATTER).withSecond(0);
                 // 遍历每一分钟
                 LocalDateTime currentTime = startTime;
                 while (!currentTime.isAfter(endTime)) {
-                    timeValueMap.put(currentTime.format(formatter), v);
+                    timeValueMap.put(currentTime.format(LocalDateUtils.DATE_TIME_FORMATTER), v);
                     // 增加一分钟
                     currentTime = currentTime.plusMinutes(1);
                 }
 
             }
         }
-        java.util.List<java.util.List<Object>> arr = new java.util.ArrayList<>();
+        List<java.util.List<Object>> arr = new ArrayList<>();
         Object last = preValue;
 //        for (String time : xAxis) {
 //            Integer tapping = tappingMap.getOrDefault(time, 0);
@@ -653,6 +653,7 @@ public class TIronVisualScreenServiceImpl {
                 }
             }
         }
+
         Map<String, Double> weight2Map = new LinkedHashMap<>();
         for (IronTrendL1DTO e : weight2List) {
             if (e.getCreateTime() != null) {
@@ -694,32 +695,47 @@ public class TIronVisualScreenServiceImpl {
         BigDecimal cycleTotal = BigDecimal.ZERO;
         //
         BigDecimal lastValue = BigDecimal.ZERO;
+
+        BigDecimal bigDecimal  = BigDecimal.ZERO;
+
         for (int i = 0; i < xAxis.size(); i++) {
             String time = xAxis.get(i);
             Integer tapping = tappingMap.getOrDefault(time, 0);
-            BigDecimal bigDecimal = new BigDecimal(weightMap.getOrDefault(time, 0d).toString());
+            bigDecimal = new BigDecimal(weightMap.getOrDefault(time, 0d).toString());
             if (tapping == 1) {
+                //切换到出铁状态
                 if (!inTappingCycle) {
+                    //刚刚开始出铁
                     inTappingCycle = true;
                     //System.out.println("[出铁周期结束] 开始于: " + time);
                 }
                 if (bigDecimal.compareTo(BigDecimal.ZERO) == 0) {
+                    //复用上次的数据
                     bigDecimal = lastValue;
                     weightMap.put(time, bigDecimal.doubleValue());
                 } else {
                     lastValue = bigDecimal;
                 }
                 if (i > 0) {
+                    //按照时间正序(10:00:00,10:01:00,10:02:00)
+                    //将10:00:00对应的数据 - 10:01:00对应的数据
                     BigDecimal prevW = new BigDecimal(weightMap.getOrDefault(xAxis.get(i - 1), 0d).toString());
                     //上一个减去当前的
-                    if (prevW.subtract(bigDecimal).compareTo(new BigDecimal("130")) > 0) {
+                    if (prevW.subtract(bigDecimal).compareTo(new BigDecimal("70")) > 0) {
                         System.out.println("[出铁周期满载情况] 时间: " + xAxis.get(i - 1) + ", 铁水满载值: " + prevW);
                         cycleTotal = cycleTotal.add(prevW);
                     }
                 }
+
                 arr.add(java.util.Arrays.asList(time, bigDecimal.add(cycleTotal).setScale(scale, RoundingMode.HALF_UP).doubleValue()));
             } else {
+                //切换到出铁结束
                 if (inTappingCycle) {
+                    //刚刚从出铁结束切换过来
+                    cycleTotal = cycleTotal.add(bigDecimal);
+                    System.out.println("[出铁周期结束] 最后时间点的铁水重量: " + bigDecimal);
+                    bigDecimal = BigDecimal.ZERO;
+
                     double value = cycleTotal.setScale(scale, RoundingMode.HALF_UP).doubleValue();
                     System.out.println("[出铁周期结束] 结束于: " + time + ", 本周期铁水总净重: " + value);
                     arr.add(java.util.Arrays.asList(time, value));

+ 33 - 25
taphole-iron/src/main/java/com/sckj/iron/socketio/DeviceEventListener.java

@@ -307,7 +307,7 @@ public class DeviceEventListener extends AbstractEventListener { //
                 scheduledTaskManager.addTask(opcdasubscribe.getName(), opcdasubscribe.getDelay(), opcdasubscribe.getPeriod(), TimeUnit.SECONDS, () -> {
                     if ("prod".equals(activeProfiles)) {
                         log.info("HDC subscribe available");
-                        hdService.subscribeAvailable();
+                         hdService.subscribeAvailable();
                     } else if ("test".equals(activeProfiles)) {
                         log.info("DA subscribe available");
                         opcuaService.subscribeAvailable();
@@ -801,7 +801,7 @@ public class DeviceEventListener extends AbstractEventListener { //
     /***
      * 剩余出铁时间 = (理论铁量(1300)-累计出铁量)/流速
      */
-    private void getCloseTime() {
+    private void getCloseTime(BigDecimal totalWeight) {
         log.info("开始计算预计剩余出铁时间");
 
         RealtimeData realtimeData = new RealtimeData();
@@ -833,7 +833,7 @@ public class DeviceEventListener extends AbstractEventListener { //
         //最大出铁标准量
         double stdIronWeightMax = Double.parseDouble(mContext.lookupVariable(ExpressionConstants.stdIronWeightMax).toString());
         //实时总铁量
-        BigDecimal totalWeight = mTotalWeight;
+       // BigDecimal totalWeight = rtTotalWeight;
         //平均流速
         BigDecimal avgSpeed = totalWeight.divide(BigDecimal.valueOf(ironElapsedMinute), 2, RoundingMode.HALF_UP);
         //剩余重量
@@ -1057,6 +1057,15 @@ public class DeviceEventListener extends AbstractEventListener { //
         log.info("🛑 ====== 开始执行 taphole1End - 出铁结束处理 ======");
 
         synchronized (scheduledTaskManager) {
+            log.info("   ├─ ⏸️ 出铁结束,1号罐车有余存铁量进行记录");
+            mTotalWeight = mTotalWeight.add(ironWeight1Pre);
+            log.info("出铁结束,铁水总流量:{},1号线剩余铁水流量:{}",
+                    mTotalWeight, ironWeight1Pre);
+            log.info("   ├─ ⏸️ 出铁结束,2号罐车有余存铁量进行记录");
+            mTotalWeight = mTotalWeight.add(ironWeight2Pre);
+            log.info("出铁结束,铁水总流量:{},2号线剩余铁水流量:{}",
+                    mTotalWeight, ironWeight2Pre);
+
             // 记录当前出铁统计信息
             log.info("📊 出铁结束统计: 总时长={}分钟, 总重量={}吨",
                     getIronElapsedMinute(),
@@ -1101,8 +1110,7 @@ public class DeviceEventListener extends AbstractEventListener { //
 
             // 4. 取消相关预警
             log.info("🚨 取消相关预警信息...");
-            PushData.send2CancelWarn(WarnData.warnClose("出铁结束", ""));
-            PushData.send2CancelWarn(WarnData.warnTapping("出铁结束", ""));
+            PushData.send2CancelWarn(new TAudioDTO());
             log.info("✅ 预警信息已取消");
 
             // 5. 清空打泥量
@@ -1233,7 +1241,7 @@ public class DeviceEventListener extends AbstractEventListener { //
                         }
                     } else {
                         mWarnCountMap.put(modelKey1, 0);
-                        PushData.send2CancelWarn(WarnData.warnClose("取消堵口告警1", ""));
+                        PushData.send2CancelWarn(new TAudioDTO());
                     }
 
                     String modelExpression2 = modelClosureWarn2.getModelExpression();
@@ -1262,7 +1270,7 @@ public class DeviceEventListener extends AbstractEventListener { //
                         }
                     } else {
                         mWarnCountMap.put(modelKey2, 0);
-                        PushData.send2CancelWarn(WarnData.warnClose("取消堵口告警2", ""));
+                        PushData.send2CancelWarn(new TAudioDTO());
                     }
 
                     String modelExpression3 = modelClosureWarn3.getModelExpression();
@@ -1290,7 +1298,7 @@ public class DeviceEventListener extends AbstractEventListener { //
                         }
                     } else {
                         mWarnCountMap.put(modelKey3, 0);
-                        PushData.send2CancelWarn(WarnData.warnClose("取消堵口告警3", ""));
+                        PushData.send2CancelWarn(new TAudioDTO());
                     }
                 } else {
                     log.info("使用实时速度预警模式");
@@ -1638,7 +1646,7 @@ public class DeviceEventListener extends AbstractEventListener { //
                             log.info("预警条件不满足,重置计数器,原计数: {}", oldCount);
                         }
                         mWarnCountMap.put(modelKey, 0);
-                        PushData.send2CancelWarn(WarnData.warnTapping("压差正常", ""));
+                        PushData.send2CancelWarn(new TAudioDTO());
                     }
                 } catch (Exception e) {
                     log.error("执行急需出铁预警表达式时发生异常", e);
@@ -2260,7 +2268,7 @@ public class DeviceEventListener extends AbstractEventListener { //
                     }
 
                     //剩余铁量计算-流速
-                    getCloseTime();
+                    //getCloseTime();
 
                 }
             } else if (opcData.getPointName().contains(SubscribeTagConstants.TAG_TAPHOLE2_STATUS(opcData.getServerType()))) {
@@ -2311,7 +2319,7 @@ public class DeviceEventListener extends AbstractEventListener { //
                         BigDecimal diff = ironWeight1Pre.subtract(bigDecimalNew);
                         log.info("   ├─ 计算差值: {} - {} = {}", ironWeight1Pre, bigDecimalNew, diff);
 
-                        if (diff.compareTo(new BigDecimal("130")) > 0) {
+                        if (diff.compareTo(new BigDecimal("70")) > 0) {
                             log.info("   ├─ 🔄 检测到满载流量变化 (差值 > 130t)");
                             log.info("   ├─ 累加前总流量: {} t", mTotalWeight);
 
@@ -2324,11 +2332,15 @@ public class DeviceEventListener extends AbstractEventListener { //
 
                             log.info("铁水总流量:{},1号线铁水满载流量:{},下一个流量:{}",
                                     mTotalWeight, ironWeight1Pre, bigDecimalNew);
+
+                            getCloseTime(mTotalWeight);
+
                         } else {
                             log.info("   ├─ ⏭️ 未达到满载阈值 (差值 ≤ 130t),跳过累加");
                             log.info("   ├─ 当前差值: {} t ≤ 130 t", diff);
-                        }
 
+                            getCloseTime(mTotalWeight.add(bigDecimalNew));
+                        }
 
                         // 更新上次流量值
                         log.info("   ├─ 📝 更新上次流量值: {} → {}", ironWeight1Pre, bigDecimalNew);
@@ -2338,15 +2350,13 @@ public class DeviceEventListener extends AbstractEventListener { //
                         log.info("   ├─ 📍 检测到 TAG_IRON_WEIGHT12 - 2号车铁水流量");
                         realtimeData.setValue(2);
 
-
                         BigDecimal diff = ironWeight2Pre.subtract(bigDecimalNew);
                         log.info("   ├─ 计算差值: {} - {} = {}", ironWeight2Pre, bigDecimalNew, diff);
 
-                        if (diff.compareTo(new BigDecimal("130")) > 0) {
+                        if (diff.compareTo(new BigDecimal("70")) > 0) {
                             log.info("   ├─ 🔄 检测到满载流量变化 (差值 > 130t)");
                             log.info("   ├─ 累加前总流量: {} t", mTotalWeight);
 
-
                             mTotalWeight = mTotalWeight.add(ironWeight2Pre);
 
                             log.info("   ├─ ✅ 累加后总流量: {} t", mTotalWeight);
@@ -2355,9 +2365,15 @@ public class DeviceEventListener extends AbstractEventListener { //
 
                             log.info("铁水总流量:{},2号线铁水满载流量:{},下一个流量:{}",
                                     mTotalWeight, ironWeight2Pre, bigDecimalNew);
+
+                            getCloseTime(mTotalWeight);
+
                         } else {
                             log.info("   ├─ ⏭️ 未达到满载阈值 (差值 ≤ 130t),跳过累加");
                             log.info("   ├─ 当前差值: {} t ≤ 130 t", diff);
+
+                            getCloseTime(mTotalWeight.add(bigDecimalNew));
+
                         }
 
                         // 更新上次流量值
@@ -2366,19 +2382,11 @@ public class DeviceEventListener extends AbstractEventListener { //
                     }
 
                 } else {
-                    log.info("   ├─ ⏸️ 出铁状态未激活,流量值设为0");
-                    mTotalWeight = mTotalWeight.add(ironWeight1Pre);
-                    log.info("出铁结束,铁水总流量:{},1号线剩余铁水流量:{}",
-                            mTotalWeight, ironWeight1Pre);
-                    mTotalWeight = mTotalWeight.add(ironWeight2Pre);
-                    log.info("出铁结束,铁水总流量:{},2号线剩余铁水流量:{}",
-                            mTotalWeight, ironWeight2Pre);
-
                     realtimeData.setValue(0);
                 }
 
                 //剩余铁量计算-流量
-                getCloseTime();
+
 
                 log.info("📋 【实时数据构建】");
                 realtimeData.setDesc("摆动溜嘴的摆动方向");
@@ -3051,7 +3059,7 @@ public class DeviceEventListener extends AbstractEventListener { //
      * @param message
      */
     @OnEvent(value = PushData.IRON_CANCEL_WARN)
-    public void cancelWarn(SocketIOClient client, WarnData message) {
+    public void cancelWarn(SocketIOClient client, String message) {
         if (null == validateClientOnline(client)) {
             return;
         }