|
|
@ -1,7 +1,6 @@ |
|
|
|
package com.iflytop.gd.app.service.scheduled; |
|
|
|
|
|
|
|
import com.iflytop.gd.app.model.bo.status.device.HeatModuleState; |
|
|
|
import com.iflytop.gd.app.model.bo.status.device.TrayState; |
|
|
|
import com.iflytop.gd.app.model.vo.HeatCountdownVO; |
|
|
|
import com.iflytop.gd.app.service.api.DevicePositionService; |
|
|
|
import com.iflytop.gd.app.service.device.DeviceStateService; |
|
|
@ -10,7 +9,6 @@ import com.iflytop.gd.app.ws.server.WebSocketSender; |
|
|
|
import com.iflytop.gd.common.enums.HeatingType; |
|
|
|
import com.iflytop.gd.common.enums.data.DevicePositionCode; |
|
|
|
import com.iflytop.gd.common.utils.LocalDateTimeUtil; |
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
@ -22,7 +20,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* 加热时间到自动抬起 |
|
|
|
* 加热倒计时 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
@ -33,42 +31,58 @@ public class HeatCountdownScheduledTask { |
|
|
|
private final HeatModuleService heatModuleService; |
|
|
|
private final WebSocketSender webSocketSender; |
|
|
|
|
|
|
|
@Scheduled(fixedDelay = 1000) |
|
|
|
private double trayLift; |
|
|
|
|
|
|
|
private void init() { |
|
|
|
trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); |
|
|
|
} |
|
|
|
|
|
|
|
@Scheduled(fixedRate = 1000) |
|
|
|
public void fetchTemperature() { |
|
|
|
try { |
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
List<HeatCountdownVO> heatCountdownVOList = new ArrayList<>(); |
|
|
|
for (HeatModuleState heatModuleState : deviceStateService.getDeviceState().getHeatModule()) { |
|
|
|
//工艺除外 |
|
|
|
TrayState trayState = deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleState.getModuleCode()); |
|
|
|
if (trayState != null && trayState.getCrafts() != null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (heatModuleState.getHeatingType() == HeatingType.thermostatic) {//如果这个加热模块在加热中 |
|
|
|
if (heatModuleState.getTemperature() + 1 > heatModuleState.getHeatTemperature()) {//当前温度达到目标温度,允许有1度以内的误差 |
|
|
|
heatModuleState.setStartHeatTime(now); |
|
|
|
heatModuleState.setHeatingType(HeatingType.constant);//修改状态为恒温中 |
|
|
|
} |
|
|
|
} else if (heatModuleState.getHeatingType() == HeatingType.constant) { |
|
|
|
LocalDateTime endTime = heatModuleState.getStartHeatTime().plusSeconds(heatModuleState.getTargetTime()); |
|
|
|
//判断是否达到目标加热时间 |
|
|
|
long diffSeconds = Duration.between(now, endTime).getSeconds();//计算剩余时间 |
|
|
|
if (diffSeconds <= 0) {//加热完毕 |
|
|
|
double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); |
|
|
|
//抬起托盘 |
|
|
|
heatModuleService.heaterMotorMove(heatModuleState.getModuleCode(), trayLift); |
|
|
|
heatModuleState.setTrayUp(1); |
|
|
|
//关闭加棒 |
|
|
|
heatModuleService.heatRodClose(heatModuleState.getModuleCode()); |
|
|
|
//还原状态 |
|
|
|
heatModuleState.setStartHeatTime(null);//开始加热时间 |
|
|
|
heatModuleState.setTargetTime(null);//加热器目标加热时间 |
|
|
|
heatModuleState.setWarmUpTemperature(null);//加热器预热温度 |
|
|
|
heatModuleState.setHeatTemperature(null);//加热器加热温度 |
|
|
|
heatModuleState.setTargetTemperature(null);//加热器目标温度 |
|
|
|
heatModuleState.setHeatingType(HeatingType.finish); |
|
|
|
if (heatModuleState.getStartHeatTime() == null) { |
|
|
|
//设定开始加热时间 |
|
|
|
heatModuleState.setStartHeatTime(now); |
|
|
|
} else { |
|
|
|
LocalDateTime endTime = heatModuleState.getStartHeatTime().minusSeconds(heatModuleState.getTargetTime()); |
|
|
|
//判断是否达到目标加热时间 |
|
|
|
if (endTime.isBefore(now)) {//加热完毕 |
|
|
|
//抬起托盘 |
|
|
|
heatModuleService.heaterMotorMove(heatModuleState.getModuleCode(), trayLift); |
|
|
|
heatModuleState.setTrayUp(1); |
|
|
|
//关闭加棒 |
|
|
|
heatModuleService.heatRodClose(heatModuleState.getModuleCode()); |
|
|
|
heatModuleState.setHeatingType(HeatingType.stop); |
|
|
|
//还原状态 |
|
|
|
heatModuleState.setStartHeatTime(null); |
|
|
|
heatModuleState.setTargetTime(null); |
|
|
|
heatModuleState.setWarmUpTemperature(null); |
|
|
|
heatModuleState.setHeatTemperature(null); |
|
|
|
heatModuleState.setTargetTemperature(null); |
|
|
|
heatModuleState.setHeatingType(HeatingType.stop); |
|
|
|
} else {//加热中 |
|
|
|
long diffSeconds = Duration.between(now, endTime).getSeconds();//计算剩余时间 |
|
|
|
HeatCountdownVO heatCountdownVO = new HeatCountdownVO(); |
|
|
|
heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode()); |
|
|
|
heatCountdownVO.setCountdown((int) diffSeconds); |
|
|
|
heatCountdownVO.setCountdownStr(LocalDateTimeUtil.formatSecondsToHMS(diffSeconds)); |
|
|
|
heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime()); |
|
|
|
heatCountdownVO.setEndTime(endTime); |
|
|
|
heatCountdownVOList.add(heatCountdownVO); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!heatCountdownVOList.isEmpty()) { |
|
|
|
webSocketSender.pushHeatCountdown(heatCountdownVOList); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("加热倒计时错误", e); |
|
|
|
} |
|
|
|