diff --git a/src/main/java/com/dreamworks/boditech/controller/DeviceController.java b/src/main/java/com/dreamworks/boditech/controller/DeviceController.java index c96b516..bedf1ba 100644 --- a/src/main/java/com/dreamworks/boditech/controller/DeviceController.java +++ b/src/main/java/com/dreamworks/boditech/controller/DeviceController.java @@ -7,6 +7,7 @@ import com.dreamworks.boditech.driver.actuator.ActModuleTestCardBoxCaseTemperatu import com.dreamworks.boditech.driver.actuator.ActuatorModule; import com.dreamworks.boditech.driver.entity.*; import com.dreamworks.boditech.service.DeviceService; +import com.dreamworks.boditech.utils.I18n; import jakarta.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; @@ -124,12 +125,15 @@ public class DeviceController extends BaseController { @ResponseBody @PostMapping("/api/device/status-get") public ApiResponse status() { - // @TODO : 这里需要将名字从翻译文件中获取 - String statusName = "就绪"; - String status = "READY"; + String statusName = I18n.t("device.status.powerOn"); + String status = "POWER_ON"; + if ( this.deviceService.device.getIsReady() ) { + status = "READY"; + statusName = I18n.t("device.status.ready"); + } if ( this.deviceService.device.testCards.getIsLoaded() ) { status = "CONSUMABLES_LOADED"; - statusName = "耗材已加载"; + statusName = I18n.t("device.status.consumablesLoaded"); } if ( this.deviceService.isExecutorRunning() ) { // status = this.deviceService.getExecutorWorkingStatus(); diff --git a/src/main/java/com/dreamworks/boditech/driver/Device.java b/src/main/java/com/dreamworks/boditech/driver/Device.java index 905af7c..a520762 100644 --- a/src/main/java/com/dreamworks/boditech/driver/Device.java +++ b/src/main/java/com/dreamworks/boditech/driver/Device.java @@ -27,8 +27,6 @@ public class Device { public static final Logger LOG = LoggerFactory.getLogger(Device.class); @Value("${app.device.connectionType}") private String connectionType; - @Value("${app.device.debug}") - private Boolean debug; @Value("${app.device.enable}") public Boolean enable; @@ -65,6 +63,8 @@ public class Device { private final Map actuators = new HashMap(); // message index private short messageIndex = 0; + // device ready + private Boolean isReady = false; @PostConstruct public void init() { @@ -190,12 +190,6 @@ public class Device { this.deviceLogMapper.insert(entry); } - public void errorAlert(String code) { - WebsocketServerMessageErrorEvent event = new WebsocketServerMessageErrorEvent(); - event.code = code; -// this.websocketServerService.send(event); - } - // get connection status public String getConnectionStatus() { if ("SerialPort".equals(this.connectionType)) { @@ -203,4 +197,14 @@ public class Device { } return this.websocket.getStatus(); } + + // get is device ready + public Boolean getIsReady() { + return this.isReady; + } + + // set is device ready + public void setIsReady(Boolean isReady) { + this.isReady = isReady; + } } diff --git a/src/main/java/com/dreamworks/boditech/driver/task/TaskStartReset.java b/src/main/java/com/dreamworks/boditech/driver/task/TaskStartReset.java index f1a3f67..aba9f16 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/TaskStartReset.java +++ b/src/main/java/com/dreamworks/boditech/driver/task/TaskStartReset.java @@ -113,6 +113,7 @@ public class TaskStartReset extends TaskBase { this.analysisPushMotor.moveTo("analysisPushMotorStandby"); this.cleanIncubatorIfError(); + this.device.setIsReady(true); LOG.info("[reset] task finished, cost {}s", (System.currentTimeMillis() - startTime)/1000.00); } diff --git a/src/main/java/com/dreamworks/boditech/service/ProjectService.java b/src/main/java/com/dreamworks/boditech/service/ProjectService.java index 505dc72..497f51f 100644 --- a/src/main/java/com/dreamworks/boditech/service/ProjectService.java +++ b/src/main/java/com/dreamworks/boditech/service/ProjectService.java @@ -1,7 +1,8 @@ package com.dreamworks.boditech.service; -import com.dreamworks.boditech.driver.task.TaskTestBase; import com.dreamworks.boditech.entity.Project; import com.dreamworks.boditech.mapper.ProjectMapper; +import com.dreamworks.boditech.utils.AppError; +import com.dreamworks.boditech.utils.AppRuntimeException; import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; import org.slf4j.Logger; @@ -43,7 +44,7 @@ public class ProjectService { return project; } } - throw new RuntimeException("PROJECT_CODE_NOT_ACTIVE"); + throw new AppRuntimeException(AppError.PROJECT_CODE_NOT_ACTIVE); } // get active project by given code num @@ -56,24 +57,32 @@ public class ProjectService { return project; } } - throw new RuntimeException("PROJECT_CODE_NOT_ACTIVE"); + throw new AppRuntimeException(AppError.PROJECT_CODE_NOT_ACTIVE); } // active project public Project activeProjectByCodeNum(Integer posIndex, Integer codeNum, String lotCode) { Project project = this.projects.get(posIndex); if ( null != project ) { - throw new RuntimeException("PROJECT_CODE_ALREADY_ACTIVE"); + throw new AppRuntimeException(AppError.PROJECT_CODE_ALREADY_ACTIVE); } project = this.findByCodeNum(codeNum); if ( project == null ) { - throw new RuntimeException("PROJECT_CODE_NOT_AVAILABLE"); + throw new AppRuntimeException(AppError.PROJECT_CODE_NOT_AVAILABLE); + } + + String color = this.colors[posIndex]; + for ( Project activeProject : this.projects ) { + if ( null != activeProject && activeProject.codeNum.equals(codeNum) && activeProject.lotCode.equals(lotCode)) { + // if project already active, use the same color + color = activeProject.color; + } } project.posIndex = posIndex; project.lotCode = lotCode; - project.color = this.colors[posIndex]; + project.color = color; this.projects.set(posIndex, project); LOG.info("project active : {} {}({})",codeNum, project.name, project.lotCode); return project; @@ -89,27 +98,8 @@ public class ProjectService { return projectMapper.findByCodeNum(codeNum); } - - - - - - - - - - - - // find by id public Project findById(Integer id) { return projectMapper.findById(id); } - - - - // find by name - public Project findByName(String name) { - return projectMapper.findByName(name); - } } diff --git a/src/main/java/com/dreamworks/boditech/utils/AppError.java b/src/main/java/com/dreamworks/boditech/utils/AppError.java index c804274..11d88bd 100644 --- a/src/main/java/com/dreamworks/boditech/utils/AppError.java +++ b/src/main/java/com/dreamworks/boditech/utils/AppError.java @@ -3,6 +3,10 @@ public enum AppError { // account ACCOUNT_LOGIN_INVALID_ACCOUNT_OR_PIN_CODE, + // project + PROJECT_CODE_NOT_ACTIVE, + PROJECT_CODE_ALREADY_ACTIVE, + PROJECT_CODE_NOT_AVAILABLE, TEST_TUBE_RACK_FEED_RACK_NOT_FOUND } diff --git a/src/main/resources/static/i18n/messages_zh_CN.properties b/src/main/resources/static/i18n/messages_zh_CN.properties index 60c01a8..0392368 100644 --- a/src/main/resources/static/i18n/messages_zh_CN.properties +++ b/src/main/resources/static/i18n/messages_zh_CN.properties @@ -1 +1,5 @@ +device.status.powerOn = 设备已开机 +device.status.ready = 设备已就绪 +device.status.consumablesLoaded = 耗材已装载 + Error.ACCOUNT_LOGIN_INVALID_ACCOUNT_OR_PIN_CODE = 密码验证失败 \ No newline at end of file