From 845cfe475eeabb7f532c982e641d57f6e7592ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Thu, 24 Jul 2025 16:38:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E6=89=98=E7=9B=98?= =?UTF-8?q?=E8=AF=95=E7=AE=A1=E6=8E=A7=E5=88=B6=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/common/enums/TitrationStatus.java | 19 ++++++++ .../app/controller/TraytController.java | 37 ++++++++++++++++ .../app/controller/TubeController.java | 32 ++++++++++++++ .../colortitration/app/core/state/DeviceState.java | 10 ++--- .../colortitration/app/core/state/TubeState.java | 11 ++++- .../app/model/dto/TrayTubeSetExistDTO.java | 19 ++++++++ .../app/service/DeviceInitService.java | 6 +-- .../colortitration/app/service/TrayService.java | 51 ++++++++++++++++++++++ .../colortitration/app/service/TubeService.java | 25 +++++++++++ 9 files changed, 198 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/iflytop/colortitration/app/common/enums/TitrationStatus.java create mode 100644 src/main/java/com/iflytop/colortitration/app/controller/TraytController.java create mode 100644 src/main/java/com/iflytop/colortitration/app/controller/TubeController.java create mode 100644 src/main/java/com/iflytop/colortitration/app/model/dto/TrayTubeSetExistDTO.java create mode 100644 src/main/java/com/iflytop/colortitration/app/service/TrayService.java create mode 100644 src/main/java/com/iflytop/colortitration/app/service/TubeService.java diff --git a/src/main/java/com/iflytop/colortitration/app/common/enums/TitrationStatus.java b/src/main/java/com/iflytop/colortitration/app/common/enums/TitrationStatus.java new file mode 100644 index 0000000..cb53e75 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/common/enums/TitrationStatus.java @@ -0,0 +1,19 @@ +package com.iflytop.colortitration.app.common.enums; + +/** + * 滴定状态 + */ +public enum TitrationStatus { + /** + * 滴定未开始 + */ + NOT_STARTED, + /** + * 滴定进行中 + */ + IN_PROGRESS, + /** + * 滴定完毕 + */ + COMPLETED; +} diff --git a/src/main/java/com/iflytop/colortitration/app/controller/TraytController.java b/src/main/java/com/iflytop/colortitration/app/controller/TraytController.java new file mode 100644 index 0000000..52210e3 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/controller/TraytController.java @@ -0,0 +1,37 @@ +package com.iflytop.colortitration.app.controller; + +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.service.TrayService; +import com.iflytop.colortitration.common.result.Result; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "试管") +@RestController +@RequestMapping("/api/tray") +@RequiredArgsConstructor +@Slf4j +public class TraytController { + private final TrayService trayService; + + @Operation(summary = "放入一个托盘") + @PostMapping("/tray-in") + public Result trayIn(MultipleModuleCode moduleCode) { + trayService.trayIn(moduleCode); + return Result.success(); + } + + @Operation(summary = "拿走一个托盘") + @PostMapping("/tray-out") + public Result trayOut(MultipleModuleCode moduleCode) { + trayService.trayOut(moduleCode); + return Result.success(); + } + + +} diff --git a/src/main/java/com/iflytop/colortitration/app/controller/TubeController.java b/src/main/java/com/iflytop/colortitration/app/controller/TubeController.java new file mode 100644 index 0000000..ee99317 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/controller/TubeController.java @@ -0,0 +1,32 @@ +package com.iflytop.colortitration.app.controller; + +import com.iflytop.colortitration.app.model.dto.TrayTubeSetExistDTO; +import com.iflytop.colortitration.app.service.TubeService; +import com.iflytop.colortitration.common.result.Result; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Tag(name = "试管") +@RestController +@RequestMapping("/api/tube") +@RequiredArgsConstructor +@Slf4j +public class TubeController { + private final TubeService tubeService; + + @Operation(summary = "修改托盘是否存在试管") + @PutMapping("/set-tube-exist") + public Result setTubeExist(@RequestBody List trayTubeSetExistDTOList) { + tubeService.setTubeExist(trayTubeSetExistDTOList); + return Result.success(); + } + +} diff --git a/src/main/java/com/iflytop/colortitration/app/core/state/DeviceState.java b/src/main/java/com/iflytop/colortitration/app/core/state/DeviceState.java index afdb7ff..8970ca4 100644 --- a/src/main/java/com/iflytop/colortitration/app/core/state/DeviceState.java +++ b/src/main/java/com/iflytop/colortitration/app/core/state/DeviceState.java @@ -24,11 +24,8 @@ public class DeviceState { @Schema(description = "加热模块") private final Map heatModuleStateMap = new HashMap<>(); - @Schema(description = "托盘1 试管状态") - private final Map trayTubeStateMap1 = new HashMap<>(); - - @Schema(description = "托盘2 试管状态") - private final Map trayTubeStateMap2 = new HashMap<>(); + @Schema(description = "试管状态") + private final Map trayTubeStateMap = new HashMap<>(); @Schema(description = "托盘1是否存在,true 存在 false不存在") private boolean trayExist1 = false; @@ -54,8 +51,7 @@ public class DeviceState { public JSONObject toJSON() { JSONObject json = new JSONObject(); json.putOnce("titrationModule", new ArrayList<>(titrationModuleStateMap.values())); - json.putOnce("tray1TubeState", new ArrayList<>(trayTubeStateMap1.values())); - json.putOnce("tray2TubeState", new ArrayList<>(trayTubeStateMap2.values())); + json.putOnce("trayTubeState", new ArrayList<>(trayTubeStateMap.values())); json.putOnce("trayExist1", virtual); json.putOnce("trayExist2", virtual); json.putOnce("virtual", virtual); diff --git a/src/main/java/com/iflytop/colortitration/app/core/state/TubeState.java b/src/main/java/com/iflytop/colortitration/app/core/state/TubeState.java index 27e9f68..a3ecae4 100644 --- a/src/main/java/com/iflytop/colortitration/app/core/state/TubeState.java +++ b/src/main/java/com/iflytop/colortitration/app/core/state/TubeState.java @@ -1,6 +1,7 @@ package com.iflytop.colortitration.app.core.state; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.iflytop.colortitration.app.common.enums.TitrationStatus; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.RequiredArgsConstructor; @@ -18,8 +19,11 @@ public class TubeState { @Schema(description = "试管位编号") private Integer bubeNum; - @Schema(description = "是否存在试管") - private boolean trayExist = false; + @Schema(description = "是否存在试管,true 存在 false不存在") + private boolean bubeExist = true; + + @Schema(description = "滴定状态") + private TitrationStatus titrationStatus = TitrationStatus.NOT_STARTED; @Schema(description = "体积") private Double volume; @@ -27,4 +31,7 @@ public class TubeState { @Schema(description = "结果") private Double result; + public TubeState(Integer bubeNum) { + this.bubeNum = bubeNum; + } } diff --git a/src/main/java/com/iflytop/colortitration/app/model/dto/TrayTubeSetExistDTO.java b/src/main/java/com/iflytop/colortitration/app/model/dto/TrayTubeSetExistDTO.java new file mode 100644 index 0000000..994c3b2 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/model/dto/TrayTubeSetExistDTO.java @@ -0,0 +1,19 @@ +package com.iflytop.colortitration.app.model.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Schema(description = "是否存在试管") +@Data +public class TrayTubeSetExistDTO { + + @NotNull + @Schema(description = "试管编号") + private Integer tubeNum; + + @NotNull + @Schema(description = "是否存在试管 true存在 false不存在") + private Boolean bubeExist; + +} diff --git a/src/main/java/com/iflytop/colortitration/app/service/DeviceInitService.java b/src/main/java/com/iflytop/colortitration/app/service/DeviceInitService.java index 668c5bc..c087824 100644 --- a/src/main/java/com/iflytop/colortitration/app/service/DeviceInitService.java +++ b/src/main/java/com/iflytop/colortitration/app/service/DeviceInitService.java @@ -19,7 +19,7 @@ public class DeviceInitService { private final AppEventBusService eventBus; private boolean isLink = false; private final DeviceState deviceState; - private final ObjectProvider trayStateObjectProvider; + private final ObjectProvider titrationModuleObjectProvider; @PostConstruct public void init() { @@ -46,10 +46,10 @@ public class DeviceInitService { public void initDeviceState() { log.info("初始化 initDeviceState"); - TitrationModule trayModule1 = trayStateObjectProvider.getObject(); + TitrationModule trayModule1 = titrationModuleObjectProvider.getObject(); trayModule1.setModuleCode(MultipleModuleCode.MODULE_1); deviceState.getTitrationModuleStateMap().put(MultipleModuleCode.MODULE_1, trayModule1); - TitrationModule trayModule2 = trayStateObjectProvider.getObject(); + TitrationModule trayModule2 = titrationModuleObjectProvider.getObject(); trayModule2.setModuleCode(MultipleModuleCode.MODULE_2); deviceState.getTitrationModuleStateMap().put(MultipleModuleCode.MODULE_2, trayModule2); log.info("初始化 initDeviceState完毕"); diff --git a/src/main/java/com/iflytop/colortitration/app/service/TrayService.java b/src/main/java/com/iflytop/colortitration/app/service/TrayService.java new file mode 100644 index 0000000..9a6787c --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/service/TrayService.java @@ -0,0 +1,51 @@ +package com.iflytop.colortitration.app.service; + +import com.iflytop.colortitration.app.common.enums.MultipleModuleCode; +import com.iflytop.colortitration.app.core.state.DeviceState; +import com.iflytop.colortitration.app.core.state.TubeState; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class TrayService { + private final DeviceState deviceState; + private final ObjectProvider tubeStateObjectProvider; + + /** + * 放入了一个新托盘 + */ + public synchronized void trayIn(MultipleModuleCode moduleCode) { + if (MultipleModuleCode.MODULE_1.equals(moduleCode)) { + for (int i = 1; i < 17; i++) { + deviceState.getTrayTubeStateMap().put(i, tubeStateObjectProvider.getObject(i)); + } + deviceState.setTrayExist1(true); + } else if (MultipleModuleCode.MODULE_2.equals(moduleCode)) { + for (int i = 17; i < 33; i++) { + deviceState.getTrayTubeStateMap().put(i, tubeStateObjectProvider.getObject(i)); + } + deviceState.setTrayExist2(true); + } + } + + /** + * 拿走了托盘 + */ + public synchronized void trayOut(MultipleModuleCode moduleCode) { + if (MultipleModuleCode.MODULE_1.equals(moduleCode)) { + for (int i = 1; i < 17; i++) { + deviceState.getTrayTubeStateMap().remove(i); + } + deviceState.setTrayExist1(false); + } else if (MultipleModuleCode.MODULE_2.equals(moduleCode)) { + for (int i = 17; i < 33; i++) { + deviceState.getTrayTubeStateMap().remove(i); + } + deviceState.setTrayExist2(false); + } + } +} diff --git a/src/main/java/com/iflytop/colortitration/app/service/TubeService.java b/src/main/java/com/iflytop/colortitration/app/service/TubeService.java new file mode 100644 index 0000000..ee86a42 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/service/TubeService.java @@ -0,0 +1,25 @@ +package com.iflytop.colortitration.app.service; + +import com.iflytop.colortitration.app.core.state.DeviceState; +import com.iflytop.colortitration.app.model.dto.TrayTubeSetExistDTO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Slf4j +@Service +@RequiredArgsConstructor +public class TubeService { + private final DeviceState deviceState; + /** + * 修改托盘中试管是否存在 + */ + public void setTubeExist(List trayTubeSetExistDTOList) { + for (TrayTubeSetExistDTO trayTubeSetExistDTO : trayTubeSetExistDTOList) { + deviceState.getTrayTubeStateMap().get(trayTubeSetExistDTO.getTubeNum()).setBubeExist(trayTubeSetExistDTO.getBubeExist()); + } + } + +}