From 010c96a06d1e2dd088603334b220d9a0b4680206 Mon Sep 17 00:00:00 2001 From: 86156 <823267011@qq.com> Date: Thu, 8 Jan 2026 14:20:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=9C=E6=9C=BA=E9=80=BB=E8=BE=91=E5=8A=A0?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comm/OPC/MessageReceiveSchedule.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/business/src/main/java/com/fizz/business/comm/OPC/MessageReceiveSchedule.java b/business/src/main/java/com/fizz/business/comm/OPC/MessageReceiveSchedule.java index 0fddfe1..fd23f2f 100644 --- a/business/src/main/java/com/fizz/business/comm/OPC/MessageReceiveSchedule.java +++ b/business/src/main/java/com/fizz/business/comm/OPC/MessageReceiveSchedule.java @@ -5,6 +5,8 @@ import com.fizz.business.constants.enums.OpcMessageType; import com.fizz.business.domain.msg.*; import com.fizz.business.scheduled.BaseSchedule; import com.fizz.business.service.hanle.OpcReceiverHandler; +import com.fizz.business.service.ProStoppageService; +import com.fizz.business.domain.ProStoppage; import com.kangaroohy.milo.model.ReadWriteEntity; import com.kangaroohy.milo.service.MiloService; import lombok.AllArgsConstructor; @@ -17,6 +19,9 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.lang.reflect.Field; +import java.time.Duration; +import java.time.LocalDateTime; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -34,6 +39,22 @@ public class MessageReceiveSchedule extends BaseSchedule { @Resource private OpcReceiverHandler opcReceiverHandler; + + @Resource + private ProStoppageService proStoppageService; + + /** + * 低速监控状态 + */ + private LocalDateTime lowSpeedStartTime; + private boolean stopRecorded = false; + private Long currentStopId; + + /** + * 恢复监控状态 + */ + private LocalDateTime highSpeedStartTime; + @Scheduled(fixedDelay = 1000) public void L1L2LineMeasure() { try { @@ -55,6 +76,9 @@ public class MessageReceiveSchedule extends BaseSchedule { msg.setAppMeasureCoatMessage(coat); msg.setAppMeasureFurnaceMessage(fur); msg.setAppMeasureExitMessage(exit); + + monitorStripSpeed(entry); + opcReceiverHandler.onMessageReceived(OpcMessageType.APP_MEASURE,msg); } catch (Exception e) { @@ -86,4 +110,67 @@ public class MessageReceiveSchedule extends BaseSchedule { } }); } + + /** + * stripSpeed<5 持续5分钟判定停机,>5 持续1分钟结束停机并更新维持时间 + */ + private void monitorStripSpeed(AppMeasureEntryMessage entry) { + if (entry == null || entry.getStripSpeed() == null) { + resetSpeedFlags(); + return; + } + + boolean lowSpeed = entry.getStripSpeed().compareTo(BigDecimal.valueOf(5)) < 0; + LocalDateTime now = LocalDateTime.now(); + + if (lowSpeed) { + highSpeedStartTime = null; // 重置恢复计时 + if (lowSpeedStartTime == null) { + lowSpeedStartTime = now; + } + // 低速已持续超过5分钟且尚未入库,则新增停机记录 + if (!stopRecorded && Duration.between(lowSpeedStartTime, now).toMinutes() >= 5) { + ProStoppage stoppage = new ProStoppage(); + stoppage.setStartDate(lowSpeedStartTime); + stoppage.setDuration(BigDecimal.ZERO); // 初始为0,恢复后再更新 + stoppage.setStopType("AUTO_LOW_SPEED"); + stoppage.setRemark("stripSpeed<5 自动停机"); + if (proStoppageService.save(stoppage)) { + currentStopId = stoppage.getStopid(); + stopRecorded = true; + log.info("自动新增低速停机记录,stopId={} start={}", currentStopId, lowSpeedStartTime); + } else { + log.warn("自动新增低速停机记录失败"); + } + } + } else { + lowSpeedStartTime = null; + if (stopRecorded) { + if (highSpeedStartTime == null) { + highSpeedStartTime = now; + } + if (Duration.between(highSpeedStartTime, now).toMinutes() >= 1 && currentStopId != null) { + ProStoppage update = new ProStoppage(); + update.setStopid(currentStopId); + update.setEndDate(now); + // duration 以秒存储 + ProStoppage existing = proStoppageService.getById(currentStopId); + LocalDateTime start = existing != null && existing.getStartDate() != null ? existing.getStartDate() : highSpeedStartTime; + long seconds = Duration.between(start, now).getSeconds(); + update.setDuration(BigDecimal.valueOf(seconds)); + proStoppageService.updateById(update); + log.info("低速停机结束更新,stopId={} duration={}s", currentStopId, seconds); + resetSpeedFlags(); + } + } else { + highSpeedStartTime = null; + } + } + } + + private void resetSpeedFlags() { + lowSpeedStartTime = null; + highSpeedStartTime = null; + // 不重置 stopRecorded/currentStopId,避免短暂无值时丢失状态 + } }