Browse Source

设备状态名称国际化

master
sige 2 years ago
parent
commit
ee91be0d94
  1. 12
      src/main/java/com/dreamworks/boditech/controller/DeviceController.java
  2. 20
      src/main/java/com/dreamworks/boditech/driver/Device.java
  3. 1
      src/main/java/com/dreamworks/boditech/driver/task/TaskStartReset.java
  4. 40
      src/main/java/com/dreamworks/boditech/service/ProjectService.java
  5. 4
      src/main/java/com/dreamworks/boditech/utils/AppError.java
  6. 4
      src/main/resources/static/i18n/messages_zh_CN.properties

12
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.actuator.ActuatorModule;
import com.dreamworks.boditech.driver.entity.*; import com.dreamworks.boditech.driver.entity.*;
import com.dreamworks.boditech.service.DeviceService; import com.dreamworks.boditech.service.DeviceService;
import com.dreamworks.boditech.utils.I18n;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -124,12 +125,15 @@ public class DeviceController extends BaseController {
@ResponseBody @ResponseBody
@PostMapping("/api/device/status-get") @PostMapping("/api/device/status-get")
public ApiResponse status() { 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() ) { if ( this.deviceService.device.testCards.getIsLoaded() ) {
status = "CONSUMABLES_LOADED"; status = "CONSUMABLES_LOADED";
statusName = "耗材已加载";
statusName = I18n.t("device.status.consumablesLoaded");
} }
if ( this.deviceService.isExecutorRunning() ) { if ( this.deviceService.isExecutorRunning() ) {
// status = this.deviceService.getExecutorWorkingStatus(); // status = this.deviceService.getExecutorWorkingStatus();

20
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); public static final Logger LOG = LoggerFactory.getLogger(Device.class);
@Value("${app.device.connectionType}") @Value("${app.device.connectionType}")
private String connectionType; private String connectionType;
@Value("${app.device.debug}")
private Boolean debug;
@Value("${app.device.enable}") @Value("${app.device.enable}")
public Boolean enable; public Boolean enable;
@ -65,6 +63,8 @@ public class Device {
private final Map<Integer, Actuator> actuators = new HashMap<Integer, Actuator>(); private final Map<Integer, Actuator> actuators = new HashMap<Integer, Actuator>();
// message index // message index
private short messageIndex = 0; private short messageIndex = 0;
// device ready
private Boolean isReady = false;
@PostConstruct @PostConstruct
public void init() { public void init() {
@ -190,12 +190,6 @@ public class Device {
this.deviceLogMapper.insert(entry); this.deviceLogMapper.insert(entry);
} }
public void errorAlert(String code) {
WebsocketServerMessageErrorEvent event = new WebsocketServerMessageErrorEvent();
event.code = code;
// this.websocketServerService.send(event);
}
// get connection status // get connection status
public String getConnectionStatus() { public String getConnectionStatus() {
if ("SerialPort".equals(this.connectionType)) { if ("SerialPort".equals(this.connectionType)) {
@ -203,4 +197,14 @@ public class Device {
} }
return this.websocket.getStatus(); 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;
}
} }

1
src/main/java/com/dreamworks/boditech/driver/task/TaskStartReset.java

@ -113,6 +113,7 @@ public class TaskStartReset extends TaskBase {
this.analysisPushMotor.moveTo("analysisPushMotorStandby"); this.analysisPushMotor.moveTo("analysisPushMotorStandby");
this.cleanIncubatorIfError(); this.cleanIncubatorIfError();
this.device.setIsReady(true);
LOG.info("[reset] task finished, cost {}s", (System.currentTimeMillis() - startTime)/1000.00); LOG.info("[reset] task finished, cost {}s", (System.currentTimeMillis() - startTime)/1000.00);
} }

40
src/main/java/com/dreamworks/boditech/service/ProjectService.java

@ -1,7 +1,8 @@
package com.dreamworks.boditech.service; package com.dreamworks.boditech.service;
import com.dreamworks.boditech.driver.task.TaskTestBase;
import com.dreamworks.boditech.entity.Project; import com.dreamworks.boditech.entity.Project;
import com.dreamworks.boditech.mapper.ProjectMapper; 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.PostConstruct;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -43,7 +44,7 @@ public class ProjectService {
return project; return project;
} }
} }
throw new RuntimeException("PROJECT_CODE_NOT_ACTIVE");
throw new AppRuntimeException(AppError.PROJECT_CODE_NOT_ACTIVE);
} }
// get active project by given code num // get active project by given code num
@ -56,24 +57,32 @@ public class ProjectService {
return project; return project;
} }
} }
throw new RuntimeException("PROJECT_CODE_NOT_ACTIVE");
throw new AppRuntimeException(AppError.PROJECT_CODE_NOT_ACTIVE);
} }
// active project // active project
public Project activeProjectByCodeNum(Integer posIndex, Integer codeNum, String lotCode) { public Project activeProjectByCodeNum(Integer posIndex, Integer codeNum, String lotCode) {
Project project = this.projects.get(posIndex); Project project = this.projects.get(posIndex);
if ( null != project ) { if ( null != project ) {
throw new RuntimeException("PROJECT_CODE_ALREADY_ACTIVE");
throw new AppRuntimeException(AppError.PROJECT_CODE_ALREADY_ACTIVE);
} }
project = this.findByCodeNum(codeNum); project = this.findByCodeNum(codeNum);
if ( project == null ) { 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.posIndex = posIndex;
project.lotCode = lotCode; project.lotCode = lotCode;
project.color = this.colors[posIndex];
project.color = color;
this.projects.set(posIndex, project); this.projects.set(posIndex, project);
LOG.info("project active : {} {}({})",codeNum, project.name, project.lotCode); LOG.info("project active : {} {}({})",codeNum, project.name, project.lotCode);
return project; return project;
@ -89,27 +98,8 @@ public class ProjectService {
return projectMapper.findByCodeNum(codeNum); return projectMapper.findByCodeNum(codeNum);
} }
// find by id // find by id
public Project findById(Integer id) { public Project findById(Integer id) {
return projectMapper.findById(id); return projectMapper.findById(id);
} }
// find by name
public Project findByName(String name) {
return projectMapper.findByName(name);
}
} }

4
src/main/java/com/dreamworks/boditech/utils/AppError.java

@ -3,6 +3,10 @@ public enum AppError {
// account // account
ACCOUNT_LOGIN_INVALID_ACCOUNT_OR_PIN_CODE, 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 TEST_TUBE_RACK_FEED_RACK_NOT_FOUND
} }

4
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 = 密码验证失败 Error.ACCOUNT_LOGIN_INVALID_ACCOUNT_OR_PIN_CODE = 密码验证失败
Loading…
Cancel
Save