diff --git a/src/main/java/com/iflytop/gd/app/cmd/HeatStartCommand.java b/src/main/java/com/iflytop/gd/app/cmd/HeatStartCommand.java index c9bcce2..b952813 100644 --- a/src/main/java/com/iflytop/gd/app/cmd/HeatStartCommand.java +++ b/src/main/java/com/iflytop/gd/app/cmd/HeatStartCommand.java @@ -3,6 +3,7 @@ package com.iflytop.gd.app.cmd; import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.model.dto.CmdDTO; import com.iflytop.gd.app.service.DeviceCommandUtilService; +import com.iflytop.gd.app.service.DeviceStateService; import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.enums.HeatModuleCode; import lombok.RequiredArgsConstructor; @@ -20,13 +21,14 @@ import java.util.concurrent.CompletableFuture; @CommandMapping("heat_start")//业务指令注解 public class HeatStartCommand extends BaseCommandHandler { private final DeviceCommandUtilService deviceCommandUtilService; + private final DeviceStateService deviceStateService; @Override public CompletableFuture handle(CmdDTO cmdDTO) { String heatId = cmdDTO.getStringParam("heatId"); - Double temperature = cmdDTO.getDoubleParam("temperature"); HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId); return runAsync(() -> { + double temperature = deviceStateService.getHeatModuleState(heatModuleId).getTemperature(); deviceCommandUtilService.heatRodOpen(heatModuleId, temperature); }); } diff --git a/src/main/java/com/iflytop/gd/app/controller/HeatModuleController.java b/src/main/java/com/iflytop/gd/app/controller/HeatModuleController.java new file mode 100644 index 0000000..73f1266 --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/controller/HeatModuleController.java @@ -0,0 +1,30 @@ +package com.iflytop.gd.app.controller; + +import com.iflytop.gd.app.model.vo.SetTargetTemperatureVO; +import com.iflytop.gd.app.service.HeatModuleService; +import com.iflytop.gd.common.result.Result; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +/** + * 加热模块控制 + */ +@Tag(name = "加热模块控制") +@RestController +@RequestMapping("/api/heat") +@RequiredArgsConstructor +@Slf4j +public class HeatModuleController { + private final HeatModuleService heatModuleService; + + @Operation(summary = "加热模块设定目标温度") + @PostMapping("/target-temperature") + public Result setTargetTemperature(@Valid @RequestBody SetTargetTemperatureVO setTargetTemperatureVO) { + heatModuleService.setTargetTemperature(setTargetTemperatureVO); + return Result.success(); + } +} diff --git a/src/main/java/com/iflytop/gd/app/core/device/DeviceState.java b/src/main/java/com/iflytop/gd/app/core/device/DeviceState.java index 88b3d0a..fd92c70 100644 --- a/src/main/java/com/iflytop/gd/app/core/device/DeviceState.java +++ b/src/main/java/com/iflytop/gd/app/core/device/DeviceState.java @@ -24,11 +24,11 @@ public class DeviceState { @Schema(description = "龙门架机械臂状态") private final GantryArmState gantryArm = new GantryArmState(); - @Schema(description = "加液操作区属性") - private final SolutionAreaState solutionArea = new SolutionAreaState(); + @Schema(description = "加液操作模块属性") + private final SolutionModuleState solutionModule = new SolutionModuleState(); - @Schema(description = "加热操作区属性") - private final List heatArea = new ArrayList<>(); + @Schema(description = "加热操作模块属性") + private final List heatModule = new ArrayList<>(); @Schema(description = "托盘") private final List tray = new ArrayList<>(); diff --git a/src/main/java/com/iflytop/gd/app/core/device/HeatAreaState.java b/src/main/java/com/iflytop/gd/app/core/device/HeatModuleState.java similarity index 91% rename from src/main/java/com/iflytop/gd/app/core/device/HeatAreaState.java rename to src/main/java/com/iflytop/gd/app/core/device/HeatModuleState.java index 6a1091b..ee7a2a3 100644 --- a/src/main/java/com/iflytop/gd/app/core/device/HeatAreaState.java +++ b/src/main/java/com/iflytop/gd/app/core/device/HeatModuleState.java @@ -6,7 +6,7 @@ import lombok.Data; @Schema(description = "加热模块") @Data -public class HeatAreaState { +public class HeatModuleState { @Schema(description = "加热模块code") private HeatModuleCode moduleCode; @@ -25,7 +25,7 @@ public class HeatAreaState { @Schema(description = "加热器当前温度") private double temperature = 0.0; - public HeatAreaState(HeatModuleCode moduleCode) { + public HeatModuleState(HeatModuleCode moduleCode) { this.moduleCode = moduleCode; } } diff --git a/src/main/java/com/iflytop/gd/app/core/device/SolutionAreaState.java b/src/main/java/com/iflytop/gd/app/core/device/SolutionModuleState.java similarity index 86% rename from src/main/java/com/iflytop/gd/app/core/device/SolutionAreaState.java rename to src/main/java/com/iflytop/gd/app/core/device/SolutionModuleState.java index 8f6b3b5..8b7efeb 100644 --- a/src/main/java/com/iflytop/gd/app/core/device/SolutionAreaState.java +++ b/src/main/java/com/iflytop/gd/app/core/device/SolutionModuleState.java @@ -1,17 +1,14 @@ package com.iflytop.gd.app.core.device; -import com.iflytop.gd.common.enums.ContainerCode; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; @Schema(description = "加液模块") @Data -public class SolutionAreaState { +public class SolutionModuleState { @Schema(description = "是否空闲,true为空闲,false为占用") private boolean idle = true; diff --git a/src/main/java/com/iflytop/gd/app/core/device/TrayState.java b/src/main/java/com/iflytop/gd/app/core/device/TrayState.java index edafebb..8f0a61b 100644 --- a/src/main/java/com/iflytop/gd/app/core/device/TrayState.java +++ b/src/main/java/com/iflytop/gd/app/core/device/TrayState.java @@ -15,11 +15,11 @@ public class TrayState { @Schema(description = "所属加热模块id") private HeatModuleCode heatModuleId; - @Schema(description = "是否在加液区") - private boolean inSolutionArea = false; + @Schema(description = "是否在加液模块中") + private boolean inSolutionModule = false; - @Schema(description = "是否在加热区") - private boolean inHeatArea = false; + @Schema(description = "是否在加热模块中") + private boolean inHeatModule = false; @Schema(description = "试管") private TubeState[] tubes = new TubeState[16]; diff --git a/src/main/java/com/iflytop/gd/app/model/vo/SetTargetTemperatureVO.java b/src/main/java/com/iflytop/gd/app/model/vo/SetTargetTemperatureVO.java new file mode 100644 index 0000000..13255cc --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/model/vo/SetTargetTemperatureVO.java @@ -0,0 +1,16 @@ +package com.iflytop.gd.app.model.vo; + +import com.iflytop.gd.common.enums.HeatModuleCode; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = false) +@Data +public class SetTargetTemperatureVO { + @Schema(description = "加热模块code") + private HeatModuleCode moduleCode; + + @Schema(description = "目标温度") + private Double temperature; +} diff --git a/src/main/java/com/iflytop/gd/app/service/DeviceStateInitializerService.java b/src/main/java/com/iflytop/gd/app/service/DeviceStateInitializerService.java index 1f7ea66..00aaf7a 100644 --- a/src/main/java/com/iflytop/gd/app/service/DeviceStateInitializerService.java +++ b/src/main/java/com/iflytop/gd/app/service/DeviceStateInitializerService.java @@ -1,7 +1,7 @@ package com.iflytop.gd.app.service; import com.iflytop.gd.app.core.device.DeviceState; -import com.iflytop.gd.app.core.device.HeatAreaState; +import com.iflytop.gd.app.core.device.HeatModuleState; import com.iflytop.gd.app.core.device.SolutionContainerState; import com.iflytop.gd.app.model.entity.Container; import com.iflytop.gd.common.enums.ContainerCode; @@ -22,13 +22,13 @@ public class DeviceStateInitializerService { @PostConstruct public void initializeDeviceState() { DeviceState deviceState = deviceStateService.getDeviceState(); - List heatArea = deviceState.getHeatArea(); + List heatArea = deviceState.getHeatModule(); for (HeatModuleCode code : HeatModuleCode.values()) { - heatArea.add(new HeatAreaState(code)); + heatArea.add(new HeatModuleState(code)); } List containerList = containerService.getList(); - List solutionBucket = deviceState.getSolutionArea().getSolutionContainer(); + List solutionBucket = deviceState.getSolutionModule().getSolutionContainer(); for (Container container : containerList) { if (container.getType() == 0) { solutionBucket.add(new SolutionContainerState(container.getId(), ContainerCode.valueOf(container.getCode()), ContainerType.solution)); diff --git a/src/main/java/com/iflytop/gd/app/service/DeviceStateService.java b/src/main/java/com/iflytop/gd/app/service/DeviceStateService.java index 3ecf5f3..822e310 100644 --- a/src/main/java/com/iflytop/gd/app/service/DeviceStateService.java +++ b/src/main/java/com/iflytop/gd/app/service/DeviceStateService.java @@ -30,6 +30,17 @@ public class DeviceStateService { support.addPropertyChangeListener(deviceStateListener); } + public synchronized HeatModuleState getHeatModuleState(HeatModuleCode moduleCode) { + HeatModuleState heatModuleState = null; + for (HeatModuleState t : deviceState.getHeatModule()) { + if (moduleCode.equals(t.getModuleCode())) { + heatModuleState = t; + break; + } + } + return heatModuleState; + } + public synchronized void setVirtual(boolean virtual) { boolean oldValue = deviceState.isVirtual(); deviceState.setVirtual(virtual); @@ -60,103 +71,103 @@ public class DeviceStateService { support.firePropertyChange("setGantryArmStateIdle", oldValue, idle); } - public synchronized void setHeatAreaStateTrayStatus(HeatModuleCode heatModuleId, int trayStatus) { - HeatAreaState heatAreaState = null; - for (HeatAreaState t : deviceState.getHeatArea()) { + public synchronized void setHeatModuleStateTrayStatus(HeatModuleCode heatModuleId, int trayStatus) { + HeatModuleState heatModuleState = null; + for (HeatModuleState t : deviceState.getHeatModule()) { if (heatModuleId.equals(t.getModuleCode())) { - heatAreaState = t; + heatModuleState = t; break; } } - assert heatAreaState != null; - int oldValue = heatAreaState.getTrayStatus(); - heatAreaState.setTrayStatus(trayStatus); - support.firePropertyChange("setHeatAreaStateTrayStatus", oldValue, trayStatus); + assert heatModuleState != null; + int oldValue = heatModuleState.getTrayStatus(); + heatModuleState.setTrayStatus(trayStatus); + support.firePropertyChange("setHeatModuleStateTrayStatus", oldValue, trayStatus); } - public synchronized void setHeatAreaStateHeating(HeatModuleCode heatModuleId, boolean heating) { - HeatAreaState heatAreaState = null; - for (HeatAreaState t : deviceState.getHeatArea()) { + public synchronized void setHeatModuleStateHeating(HeatModuleCode heatModuleId, boolean heating) { + HeatModuleState heatModuleState = null; + for (HeatModuleState t : deviceState.getHeatModule()) { if (heatModuleId.equals(t.getModuleCode())) { - heatAreaState = t; + heatModuleState = t; break; } } - assert heatAreaState != null; - boolean oldValue = heatAreaState.isHeating(); - heatAreaState.setHeating(heating); - support.firePropertyChange("setHeatAreaStateHeating", oldValue, heating); + assert heatModuleState != null; + boolean oldValue = heatModuleState.isHeating(); + heatModuleState.setHeating(heating); + support.firePropertyChange("setHeatModuleStateHeating", oldValue, heating); } - public synchronized void setHeatAreaStateCapExist(HeatModuleCode heatModuleId, boolean capStatus) { - HeatAreaState heatAreaState = null; - for (HeatAreaState t : deviceState.getHeatArea()) { + public synchronized void setHeatModuleStateCapExist(HeatModuleCode heatModuleId, boolean capStatus) { + HeatModuleState heatModuleState = null; + for (HeatModuleState t : deviceState.getHeatModule()) { if (heatModuleId.equals(t.getModuleCode())) { - heatAreaState = t; + heatModuleState = t; break; } } - assert heatAreaState != null; - boolean oldValue = heatAreaState.isCapExist(); - heatAreaState.setCapExist(capStatus); - support.firePropertyChange("setHeatAreaStateCapExist", oldValue, capStatus); + assert heatModuleState != null; + boolean oldValue = heatModuleState.isCapExist(); + heatModuleState.setCapExist(capStatus); + support.firePropertyChange("setHeatModuleStateCapExist", oldValue, capStatus); } - public synchronized void setHeatAreaStateTargetTemperature(HeatModuleCode heatModuleId, double targetTemperature) { - HeatAreaState heatAreaState = null; - for (HeatAreaState t : deviceState.getHeatArea()) { + public synchronized void setHeatModuleStateTargetTemperature(HeatModuleCode heatModuleId, double targetTemperature) { + HeatModuleState heatModuleState = null; + for (HeatModuleState t : deviceState.getHeatModule()) { if (heatModuleId.equals(t.getModuleCode())) { - heatAreaState = t; + heatModuleState = t; break; } } - assert heatAreaState != null; - double oldValue = heatAreaState.getTargetTemperature(); - heatAreaState.setTemperature(targetTemperature); - support.firePropertyChange("setHeatAreaStateTargetTemperature", oldValue, targetTemperature); + assert heatModuleState != null; + double oldValue = heatModuleState.getTargetTemperature(); + heatModuleState.setTemperature(targetTemperature); + support.firePropertyChange("setHeatModuleStateTargetTemperature", oldValue, targetTemperature); } - public synchronized void setHeatAreaStateTemperature(HeatModuleCode heatModuleId, double temperature) { - HeatAreaState heatAreaState = null; - for (HeatAreaState t : deviceState.getHeatArea()) { + public synchronized void setHeatModuleStateTemperature(HeatModuleCode heatModuleId, double temperature) { + HeatModuleState heatModuleState = null; + for (HeatModuleState t : deviceState.getHeatModule()) { if (heatModuleId.equals(t.getModuleCode())) { - heatAreaState = t; + heatModuleState = t; break; } } - assert heatAreaState != null; - double oldValue = heatAreaState.getTemperature(); - heatAreaState.setTemperature(temperature); - support.firePropertyChange("setHeatAreaStateTemperature", oldValue, temperature); + assert heatModuleState != null; + double oldValue = heatModuleState.getTemperature(); + heatModuleState.setTemperature(temperature); + support.firePropertyChange("setHeatModuleStateTemperature", oldValue, temperature); } - public synchronized void setSolutionAreaStateIdle(boolean idle) { - boolean oldValue = deviceState.getSolutionArea().isIdle(); - deviceState.getSolutionArea().setIdle(idle); - support.firePropertyChange("setSolutionAreaStateIdle", oldValue, idle); + public synchronized void setSolutionModuleStateIdle(boolean idle) { + boolean oldValue = deviceState.getSolutionModule().isIdle(); + deviceState.getSolutionModule().setIdle(idle); + support.firePropertyChange("setSolutionModuleStateIdle", oldValue, idle); } - public synchronized void setSolutionAreaStateShaking(boolean shaking) { - boolean oldValue = deviceState.getSolutionArea().isShaking(); - deviceState.getSolutionArea().setShaking(shaking); - support.firePropertyChange("setSolutionAreaStateShaking", oldValue, shaking); + public synchronized void setSolutionModuleStateShaking(boolean shaking) { + boolean oldValue = deviceState.getSolutionModule().isShaking(); + deviceState.getSolutionModule().setShaking(shaking); + support.firePropertyChange("setSolutionModuleStateShaking", oldValue, shaking); } - public synchronized void setSolutionAreaStateTrayStatus(int trayStatus) { - int oldValue = deviceState.getSolutionArea().getTrayStatus(); - deviceState.getSolutionArea().setTrayStatus(trayStatus); - support.firePropertyChange("setSolutionAreaStateTrayStatus", oldValue, trayStatus); + public synchronized void setSolutionModuleStateTrayStatus(int trayStatus) { + int oldValue = deviceState.getSolutionModule().getTrayStatus(); + deviceState.getSolutionModule().setTrayStatus(trayStatus); + support.firePropertyChange("setSolutionModuleStateTrayStatus", oldValue, trayStatus); } - public synchronized void setSolutionAreaStatePumping(boolean pumping) { - boolean oldValue = deviceState.getSolutionArea().isPumping(); - deviceState.getSolutionArea().setPumping(pumping); - support.firePropertyChange("setSolutionAreaStatePumping", oldValue, pumping); + public synchronized void setSolutionModuleStatePumping(boolean pumping) { + boolean oldValue = deviceState.getSolutionModule().isPumping(); + deviceState.getSolutionModule().setPumping(pumping); + support.firePropertyChange("setSolutionModuleStatePumping", oldValue, pumping); } public synchronized void setSolutionContainerStateEmpty(ContainerCode containerCode, boolean empty) { SolutionContainerState solutionContainerState = null; - for (SolutionContainerState t : deviceState.getSolutionArea().getSolutionContainer()) { + for (SolutionContainerState t : deviceState.getSolutionModule().getSolutionContainer()) { if (containerCode.equals(t.getContainerCode())) { solutionContainerState = t; break; @@ -170,7 +181,7 @@ public class DeviceStateService { public synchronized void setSolutionContainerStateFull(ContainerCode containerCode, boolean full) { SolutionContainerState solutionContainerState = null; - for (SolutionContainerState t : deviceState.getSolutionArea().getSolutionContainer()) { + for (SolutionContainerState t : deviceState.getSolutionModule().getSolutionContainer()) { if (containerCode.equals(t.getContainerCode())) { solutionContainerState = t; break; @@ -196,7 +207,7 @@ public class DeviceStateService { support.firePropertyChange("setTrayStateHeatModuleId", oldValue, heatModuleId); } - public synchronized void setTrayStateInSolutionArea(String trayUUID, boolean inSolutionArea) { + public synchronized void setTrayStateInSolutionModule(String trayUUID, boolean inSolutionModule) { TrayState foundTrayState = null; for (TrayState t : deviceState.getTray()) { if (trayUUID.equals(t.getUuid())) { @@ -205,12 +216,12 @@ public class DeviceStateService { } } assert foundTrayState != null; - boolean oldValue = foundTrayState.isInSolutionArea(); - foundTrayState.setInSolutionArea(inSolutionArea); - support.firePropertyChange("traySetInSolutionArea", oldValue, inSolutionArea); + boolean oldValue = foundTrayState.isInSolutionModule(); + foundTrayState.setInSolutionModule(inSolutionModule); + support.firePropertyChange("traySetInSolutionModule", oldValue, inSolutionModule); } - public synchronized void setTrayStateInHeatArea(String trayUUID, boolean inHeatArea) { + public synchronized void setTrayStateInHeatModule(String trayUUID, boolean inHeatModule) { TrayState foundTrayState = null; for (TrayState t : deviceState.getTray()) { if (trayUUID.equals(t.getUuid())) { @@ -219,9 +230,9 @@ public class DeviceStateService { } } assert foundTrayState != null; - boolean oldValue = foundTrayState.isInHeatArea(); - foundTrayState.setInHeatArea(inHeatArea); - support.firePropertyChange("setTrayStateInHeatArea", oldValue, inHeatArea); + boolean oldValue = foundTrayState.isInHeatModule(); + foundTrayState.setInHeatModule(inHeatModule); + support.firePropertyChange("setTrayStateInHeatModule", oldValue, inHeatModule); } diff --git a/src/main/java/com/iflytop/gd/app/service/GantryArmService.java b/src/main/java/com/iflytop/gd/app/service/GantryArmService.java index c4362db..7212852 100644 --- a/src/main/java/com/iflytop/gd/app/service/GantryArmService.java +++ b/src/main/java/com/iflytop/gd/app/service/GantryArmService.java @@ -1,7 +1,6 @@ package com.iflytop.gd.app.service; -import com.iflytop.gd.app.core.device.DeviceState; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -24,7 +23,7 @@ public class GantryArmService { public void waitLiquidIdle() { liquidLock.lock(); try { - while (!deviceStateService.getDeviceState().getSolutionArea().isIdle()) { + while (!deviceStateService.getDeviceState().getSolutionModule().isIdle()) { liquidIdleCondition.await(); } } catch (InterruptedException e) { @@ -40,7 +39,7 @@ public class GantryArmService { public void setLiquidIdleTrue() { liquidLock.lock(); try { - deviceStateService.setSolutionAreaStateIdle(true); + deviceStateService.setSolutionModuleStateIdle(true); liquidIdleCondition.signalAll(); // 唤醒所有等待的线程 } finally { liquidLock.unlock(); diff --git a/src/main/java/com/iflytop/gd/app/service/HeatModuleService.java b/src/main/java/com/iflytop/gd/app/service/HeatModuleService.java new file mode 100644 index 0000000..99f88a0 --- /dev/null +++ b/src/main/java/com/iflytop/gd/app/service/HeatModuleService.java @@ -0,0 +1,18 @@ +package com.iflytop.gd.app.service; + +import com.iflytop.gd.app.model.vo.SetTargetTemperatureVO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * 加热模块服务 + */ +@Service +@RequiredArgsConstructor +public class HeatModuleService { + private final DeviceStateService deviceStateService; + + public void setTargetTemperature(SetTargetTemperatureVO setTargetTemperatureVO) { + deviceStateService.setHeatModuleStateTargetTemperature(setTargetTemperatureVO.getModuleCode(), setTargetTemperatureVO.getTemperature()); + } +}