停机逻辑加入
This commit is contained in:
@@ -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,避免短暂无值时丢失状态
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user