Browse Source

任务开始、结束、暂停、恢复

master
sige 2 years ago
parent
commit
d2f378ef7f
  1. 292
      src/main/java/com/dreamworks/boditech/controller/DeviceController.java
  2. 19
      src/main/java/com/dreamworks/boditech/driver/consumable/CsmLargeBufferTubeManager.java
  3. 101
      src/main/java/com/dreamworks/boditech/driver/task/Executor.java
  4. 5
      src/main/java/com/dreamworks/boditech/driver/task/Task.java
  5. 7
      src/main/java/com/dreamworks/boditech/driver/task/TaskBase.java
  6. 2
      src/main/java/com/dreamworks/boditech/driver/task/TaskLoad.java
  7. 18
      src/main/java/com/dreamworks/boditech/driver/task/TaskStopReset.java
  8. 24
      src/main/java/com/dreamworks/boditech/driver/task/TaskTestBase.java
  9. 2
      src/main/java/com/dreamworks/boditech/driver/task/TaskTestEmergency.java
  10. 2
      src/main/java/com/dreamworks/boditech/driver/task/TaskTestRegular.java
  11. 6
      src/main/java/com/dreamworks/boditech/driver/task/TaskTestTubeRackPrepare.java
  12. 1
      src/main/java/com/dreamworks/boditech/driver/task/step/StepManager.java
  13. 9
      src/main/java/com/dreamworks/boditech/driver/task/step/StepMoveToBackground.java
  14. 1
      src/main/java/com/dreamworks/boditech/driver/task/step/StepWait.java
  15. 2
      src/main/java/com/dreamworks/boditech/entity/Project.java
  16. 3
      src/main/java/com/dreamworks/boditech/mapper/TestTubeRackTestTaskMapper.java
  17. 101
      src/main/java/com/dreamworks/boditech/service/DeviceService.java
  18. 10
      src/main/java/com/dreamworks/boditech/service/TestService.java
  19. 7
      src/main/java/com/dreamworks/boditech/utils/AppError.java

292
src/main/java/com/dreamworks/boditech/controller/DeviceController.java

@ -48,64 +48,35 @@ public class DeviceController extends BaseController {
return this.success();
}
@ResponseBody
@PostMapping("/api/device/test-card-status-get")
public ApiResponse testCardStatusGet() {
return this.success(this.deviceService.device.testCards.getAllBoxes());
}
@ResponseBody
@PostMapping("/api/device/buffer-tube-status-get")
public ApiResponse bufferTubeStatusGet() {
return this.success(this.deviceService.device.bufferTubes.getAllBoxes());
}
@ResponseBody
@PostMapping("/api/device/power-off")
public ApiResponse powerOff() {
DeviceService theDeviceService = this.deviceService;
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
theDeviceService.powerOff();
}
};
Timer timer = new Timer();
timer.schedule(timerTask, 1000);
return this.success();
@PostMapping("/api/device/pipette-tip-box-status-get")
public ApiResponse pipetteTipStatusGet() {
return this.success(this.deviceService.device.pipetteTips.getAll());
}
@ResponseBody
@PostMapping("/api/device/reboot")
public ApiResponse reboot() {
DeviceService theDeviceService = this.deviceService;
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
theDeviceService.reboot();
}
};
Timer timer = new Timer();
timer.schedule(timerTask, 1000);
return this.success();
@PostMapping("/api/device/large-buffer-tube-status-get")
public ApiResponse largeBufferTubeStatusGet() {
return this.success(this.deviceService.device.largeBufferTubes.getAll());
}
@ResponseBody
@PostMapping("/api/device/temperature-get")
public ApiResponse temperatureGet() {
Integer mid = ActuatorModule.TEST_CARD_BOX_CASE_TEMPERATURE;
ActModuleTestCardBoxCaseTemperature module = (ActModuleTestCardBoxCaseTemperature)this.deviceService.device.getActuator(mid);
Double temperature = module.getTemperature();
return this.success(Map.of(
"testCardBoxCase", temperature
));
@PostMapping("/api/device/test-card-update-by-box")
public ApiResponse testCardUpdateByBox( @RequestBody ParamTestCardUpdateByBox update ) {
this.deviceService.testCardUpdateByBox(update);
return this.success();
}
@ResponseBody
@ -116,51 +87,21 @@ public class DeviceController extends BaseController {
}
@ResponseBody
@PostMapping("/api/device/pipette-tip-box-status-get")
public ApiResponse pipetteTipStatusGet() {
return this.success(this.deviceService.device.pipetteTips.getAll());
}
@ResponseBody
@PostMapping("/api/device/buffer-tube-update-by-box")
public ApiResponse bufferTubeUpdateByBox( @RequestBody ParamBufferTubeUpdateByBox param) {
this.deviceService.bufferTubeUpdateByBox(param);
this.deviceService.largeBufferTubeUpdate(param);
return this.success();
}
@ResponseBody
@PostMapping("/api/device/status-get")
public ApiResponse status() {
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 = I18n.t("device.status.consumablesLoaded");
}
if ( this.deviceService.isExecutorRunning() ) {
// status = this.deviceService.getExecutorWorkingStatus();
status = "RUNNING";
statusName = "运行中";
}
return this.success(Map.of("status", status, "statusName", statusName));
}
@ResponseBody
@PostMapping("/api/device/incubator-status-get")
public ApiResponse incubatorStatusGet() {
Device device = this.deviceService.device;
ActIncubator incubator = (ActIncubator)device.getActuator(ActuatorModule.INCUBATOR_MOTOR);
IncubatorSlot[] slots = incubator.getSlots();
ActModuleIncubatorTemperature temperatureMod = (ActModuleIncubatorTemperature)device.getActuator(ActuatorModule.INCUBATOR_TEMPERATURE);
Double temperature = temperatureMod.getTemperature();
@PostMapping("/api/device/temperature-get")
public ApiResponse temperatureGet() {
Integer mid = ActuatorModule.TEST_CARD_BOX_CASE_TEMPERATURE;
ActModuleTestCardBoxCaseTemperature module = (ActModuleTestCardBoxCaseTemperature)this.deviceService.device.getActuator(mid);
Double temperature = module.getTemperature();
return this.success(Map.of(
"temperature", temperature,
"slots", slots
"testCardBoxCase", temperature
));
}
@ -181,12 +122,14 @@ public class DeviceController extends BaseController {
@ResponseBody
@PostMapping("/api/device/pause")
public ApiResponse pause() {
this.deviceService.pause();
return this.success();
}
@ResponseBody
@PostMapping("/api/device/resume")
public ApiResponse resume() {
this.deviceService.resume();
return this.success();
}
@ -204,30 +147,33 @@ public class DeviceController extends BaseController {
@ResponseBody
@PostMapping("/api/device/service-status-get")
public ApiResponse serviceStatusGet() {
String deviceConnection = this.deviceService.device.getConnectionStatus();
// @TODO : 想个办法获取数据库连接状态
String databaseConnection = "connected";
return this.success(Map.of(
"deviceConnection", deviceConnection,
"databaseConnection", databaseConnection
));
@PostMapping("/api/device/power-off")
public ApiResponse powerOff() {
DeviceService theDeviceService = this.deviceService;
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
theDeviceService.powerOff();
}
};
Timer timer = new Timer();
timer.schedule(timerTask, 1000);
return this.success();
}
@ResponseBody
@PostMapping("/api/device/restore")
public ApiResponse restore() {
this.deviceService.reset();
@PostMapping("/api/device/reboot")
public ApiResponse reboot() {
DeviceService theDeviceService = this.deviceService;
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
theDeviceService.reboot();
}
};
Timer timer = new Timer();
timer.schedule(timerTask, 1000);
return this.success();
}
@ -235,6 +181,26 @@ public class DeviceController extends BaseController {
@ResponseBody
@PostMapping("/api/device/status-get")
public ApiResponse status() {
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 = I18n.t("device.status.consumablesLoaded");
}
if ( this.deviceService.isExecutorRunning() ) {
// status = this.deviceService.getExecutorWorkingStatus();
status = "RUNNING";
statusName = "运行中";
}
return this.success(Map.of("status", status, "statusName", statusName));
}
@ -262,107 +228,51 @@ public class DeviceController extends BaseController {
@ResponseBody
@RequestMapping("/api/device/id-chip-status-get")
public ApiResponse statusGet() {
return this.success(Map.of(
"status" , "OFFLINE"
));
}
@ResponseBody
@PostMapping("/api/device/test-card-load")
public ApiResponse testCardLoad(@RequestHeader(name="IS-FS-READY",required = false) String isFsReady ) {
// @TODO : 删除该标记
if ( "NO".equals(isFsReady) ) {
return this.success();
}
this.deviceService.testCardLoad();
return this.success();
}
@ResponseBody
@PostMapping("/api/device/test-card-update-by-box")
public ApiResponse testCardUpdateByBox( @RequestBody ParamTestCardUpdateByBox update ) {
this.deviceService.testCardUpdateByBox(update);
return this.success();
}
@ResponseBody
@PostMapping("/api/device/test-card-status-get")
public ApiResponse testCardStatusGet() {
return this.success(this.deviceService.device.testCards.getAllBoxes());
}
@ResponseBody
@PostMapping("/api/device/buffer-tube-load")
public ApiResponse bufferTubeLoad() {
// List<CsmBufferTube> list = this.deviceService.bufferTubeLoad();
@PostMapping("/api/device/restore")
public ApiResponse restore() {
this.deviceService.reset();
return this.success();
}
@ResponseBody
@PostMapping("/api/device/buffer-tube-status-get")
public ApiResponse bufferTubeStatusGet() {
return this.success(this.deviceService.device.bufferTubes.getAllBoxes());
}
@PostMapping("/api/device/incubator-status-get")
public ApiResponse incubatorStatusGet() {
Device device = this.deviceService.device;
ActIncubator incubator = (ActIncubator)device.getActuator(ActuatorModule.INCUBATOR_MOTOR);
IncubatorSlot[] slots = incubator.getSlots();
@ResponseBody
@PostMapping("/api/device/large-buffer-tube-load")
public ApiResponse largeBufferTubeLoad() {
// List< CsmLargeBufferTube> list = this.deviceService.largeBufferTubeLoad();
return this.success();
ActModuleIncubatorTemperature temperatureMod = (ActModuleIncubatorTemperature)device.getActuator(ActuatorModule.INCUBATOR_TEMPERATURE);
Double temperature = temperatureMod.getTemperature();
return this.success(Map.of(
"temperature", temperature,
"slots", slots
));
}
@ResponseBody
@PostMapping("/api/device/large-buffer-tube-update")
public ApiResponse largeBufferTubeUpdate(@RequestBody ParamLargeBufferTubeUpdate param) {
this.deviceService.largeBufferTubeUpdate(param);
return this.success();
@PostMapping("/api/device/service-status-get")
public ApiResponse serviceStatusGet() {
String deviceConnection = this.deviceService.device.getConnectionStatus();
// @TODO : 想个办法获取数据库连接状态
String databaseConnection = "connected";
return this.success(Map.of(
"deviceConnection", deviceConnection,
"databaseConnection", databaseConnection
));
}
@ResponseBody
@PostMapping("/api/device/large-buffer-tube-status-get")
public ApiResponse largeBufferTubeStatusGet() {
return this.success(this.deviceService.device.largeBufferTubes.getAll());
@RequestMapping("/api/device/id-chip-status-get")
public ApiResponse statusGet() {
// @TODO : 这里硬件设备未安装先这么返回
return this.success(Map.of("status" , "OFFLINE"));
}
@ResponseBody
@PostMapping("/api/device/trash-box-status-get")
public ApiResponse trashBoxStatusGet() {
return this.success(Map.of(
"status", "EMPTY"
));
// @TODO : 这里硬件设备未安装先这么返回
return this.success(Map.of("status", "EMPTY"));
}
}

19
src/main/java/com/dreamworks/boditech/driver/consumable/CsmLargeBufferTubeManager.java

@ -1,5 +1,6 @@
package com.dreamworks.boditech.driver.consumable;
import com.dreamworks.boditech.driver.Device;
import com.dreamworks.boditech.driver.entity.ParamBufferTubeUpdateByBox;
import com.dreamworks.boditech.driver.entity.ParamLargeBufferTubeUpdate;
import com.dreamworks.boditech.entity.Project;
import java.util.ArrayList;
@ -84,8 +85,11 @@ public class CsmLargeBufferTubeManager {
tube.isLoaded = true;
}
// update by box
public void update(ParamBufferTubeUpdateByBox param ) {
CsmLargeBufferTube tube = this.largeBufferTubes.get(param.index);
tube.amount = param.tubeAmount;
}
@ -137,15 +141,4 @@ public class CsmLargeBufferTubeManager {
}
return tube;
}
// update large buffer tube
public void update(ParamLargeBufferTubeUpdate param ) {
// delete all large buffer tubes with matched position
// this.largeBufferTubes.removeIf(largeBufferTube -> largeBufferTube.position.equals(param.position));
// CsmLargeBufferTube largeBufferTube = new CsmLargeBufferTube(this);
// largeBufferTube.position = param.position;
// largeBufferTube.projectName = param.projectName;
// this.largeBufferTubes.add(largeBufferTube);
}
}

101
src/main/java/com/dreamworks/boditech/driver/task/Executor.java

@ -57,6 +57,7 @@ public class Executor implements Runnable {
while (!Objects.equals(this.status, Executor.STATUS_STOP_REQUEST)) {
Task task = this.findExecutableTask();
if (Objects.equals(Executor.STATUS_STOP_REQUEST, this.status)) {
LOG.info("task executor stop @[new task found]");
break;
}
if ( null == task ) {
@ -66,6 +67,11 @@ public class Executor implements Runnable {
try {
task.execute(this);
if (Objects.equals(Executor.STATUS_STOP_REQUEST, this.status)) {
LOG.info("task executor stop @[task end]");
task.afterStop();
break;
}
if (Task.STATUS_FINISHED.equals(task.getStatus())) {
this.tasks.remove(task);
}
@ -85,10 +91,31 @@ public class Executor implements Runnable {
* @return task instance
*/
private Task findExecutableTask() {
// if executor is stopping, then no task can be executed
if (Objects.equals(Executor.STATUS_STOP_REQUEST, this.status)) {
return null;
}
if ( Objects.equals(Executor.STATUS_PAUSE_REQUEST, this.status) ) {
LOG.info("task executor pause");
this.status = Executor.STATUS_PAUSED;
synchronized (this.statusLock) {
this.statusLock.notifyAll();
}
}
// if executor is paused, only background task can be executed
if ( Objects.equals(Executor.STATUS_PAUSED, this.status) ) {
LOG.info("task executor look for background task");
for ( Task task : this.tasks ) {
if ( task.getIsBackgroundTask() && Objects.equals(task.getStatus(), Task.STATUS_READY)) {
LOG.info("task executor found background task");
return task;
}
}
return null;
}
// find ready task first
for ( Task task : this.tasks ) {
if ( Objects.equals(task.getStatus(), Task.STATUS_READY) ) {
@ -125,36 +152,6 @@ public class Executor implements Runnable {
}
return null;
// if ( Executor.STATUS_PAUSE_REQUEST.equals(this.status) ) {
// this.status = Executor.STATUS_PAUSED;
// this.workingStatus = "PAUSED";
// this.statusLock.notifyAll();
// }
//
// // find background task if executor paused
// if ( Executor.STATUS_PAUSED.equals(this.status) ) {
// for ( Task task : this.tasks ) {
// if ( task.getIsBackgroundTask()
// && Objects.equals(task.getStatus(), Task.STATUS_READY)) {
// return task;
// }
// }
// return null;
// }
//
//
// // no task found
// return null;
}
// new task notify
@ -177,6 +174,35 @@ public class Executor implements Runnable {
}
}
/**
* pause executor
*/
public void pause() {
LOG.info("task executor pause : start");
this.status = Executor.STATUS_PAUSE_REQUEST;
synchronized (this.tasks) {
this.tasks.notifyAll();
}
synchronized (this.statusLock) {
try {
this.statusLock.wait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
LOG.info("task executor pause : end");
}
// resume executor
public void resume() {
LOG.info("task executor resume : start");
this.status = Executor.STATUS_RUNNING;
synchronized (this.tasks) {
this.tasks.notifyAll();
}
LOG.info("task executor resume : end");
}
// append task
public void appendTask(Task task) {
synchronized (this.tasks) {
@ -239,20 +265,7 @@ public class Executor implements Runnable {
/**
* pause executor
*/
public void pause() {
// synchronized (this.tasks) {
// this.tasks.notifyAll();
// }
// this.status = Executor.STATUS_PAUSE_REQUEST;
// try {
// this.statusLock.wait();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
}
}

5
src/main/java/com/dreamworks/boditech/driver/task/Task.java

@ -49,6 +49,9 @@ public interface Task {
*/
void execute(Executor executor);
// called when task is stopped
// called when task is trying to stop
void stop();
// called when task is stopped
void afterStop();
}

7
src/main/java/com/dreamworks/boditech/driver/task/TaskBase.java

@ -25,8 +25,13 @@ abstract public class TaskBase implements Task {
this.isBackgroundTask = isBackgroundTask;
}
// called when executor is stopped
// called when executor is trying to stop
public void stop() {
// nothing to do here.
}
// called when task is stopped
public void afterStop() {
this.setStatus(Task.STATUS_STOPPED);
}
}

2
src/main/java/com/dreamworks/boditech/driver/task/TaskLoad.java

@ -121,7 +121,7 @@ public class TaskLoad extends TaskBase {
// init buffer tube box by active projects
List<Project> projects = device.projectService.activeProjectGetAll();
for ( Project project : projects ) {
if ( null == project ) {
if ( null == project || !project.isLargeBufferRequired ) {
continue ;
}

18
src/main/java/com/dreamworks/boditech/driver/task/TaskStopReset.java

@ -15,12 +15,25 @@ public class TaskStopReset extends TaskBase {
this.cleanPipetteTip(device);
// 02. 清理孵育盘
this.cleanIncubator(device);
// 03. 清理试管架
this.cleanTestTubeRackTrack(device);
}
// clean test tube rack track
private void cleanTestTubeRackTrack(Device device) {
// 试管架夹复位
ActMotor testTubeClipMotor = (ActMotor)device.getActuator(ActuatorModule.TEST_TUBE_SHAKING_CLIP_MOTOR);
testTubeClipMotor.reset();
// 试管架移动复位
ActMotor testTubeRackTrackMoveMotor = (ActMotor)device.getActuator(ActuatorModule.TEST_TUBE_RACK_MOVE_MOTOR);
testTubeRackTrackMoveMotor.reset();
}
// clean pipette tip
private void cleanPipetteTip(Device device) {
ActPipette pipette = (ActPipette)device.getActuator(ActuatorModule.ARM_Z_PIPETTE);
if ( pipette.getHasTip() ) {
if ( !pipette.getHasTip() ) {
return ;
}
@ -28,7 +41,7 @@ public class TaskStopReset extends TaskBase {
pipette.dropTip();
ActArmXY armXY = (ActArmXY)device.getActuator(ActuatorModule.ARM_XY);
armXY.reset();
armXY.moveTo(0,0);
}
// clean incubator
@ -51,6 +64,7 @@ public class TaskStopReset extends TaskBase {
incubator.moveTo(slot.getExitLocation());
analysisPushMotor.moveTo("analysisPushMotorScanStart");
analysisPushMotor.moveTo("analysisPushMotorStandby");
incubator.unlockSlot(slot.index);
}
analysisScanMotor.moveTo("analysisScanMotorStandBy");
}

24
src/main/java/com/dreamworks/boditech/driver/task/TaskTestBase.java

@ -38,19 +38,32 @@ abstract public class TaskTestBase extends TaskBase implements TaskTest {
private IncubatorSlot incubatorSlot;
// sample tube
private CsmSampleTube sampleTube;
// request task stop
private Boolean requestTaskStop = false;
@Override
public void stop() {
if ( null == this.device ) {
super.stop();
return ;
}
this.requestTaskStop = true;
if ( Task.STATUS_WAITING.equals(this.getStatus()) ) {
Step step = this.steps.get(this.stepIndex - 1);
step.stop();
}
this.device.testService.testCancel(this.test);
this.beforeTestStop(this.test);
super.stop();
}
@Override
public void afterStop() {
this.device.testService.testCancel(this.test);
this.afterTestStop(this.test);
super.afterStop();
}
@Override
public void execute(Executor executor) {
this.device = executor.getDevice();
this.taskExecutor = executor;
@ -58,6 +71,11 @@ abstract public class TaskTestBase extends TaskBase implements TaskTest {
// execute steps
while ( this.stepIndex < this.steps.size() ) {
if ( this.requestTaskStop ) {
this.setStatus(Task.STATUS_STOPPED);
break ;
}
Step step = this.steps.get(this.stepIndex);
this.executeStep(step);
this.stepIndex++;
@ -129,7 +147,7 @@ abstract public class TaskTestBase extends TaskBase implements TaskTest {
// after task execute
abstract protected void afterTaskExecute(MdbTest test);
// on canceled
abstract protected void beforeTestStop(MdbTest test);
abstract protected void afterTestStop(MdbTest test);
// get reaction tube
public CsmBufferTube getReactionTube() {

2
src/main/java/com/dreamworks/boditech/driver/task/TaskTestEmergency.java

@ -53,7 +53,7 @@ public class TaskTestEmergency extends TaskTestBase {
}
@Override
protected void beforeTestStop(MdbTest test) {
protected void afterTestStop(MdbTest test) {
this.taskExecutor.getDevice().testService.emergencyTaskCancel(this.mdbTask);
}
}

2
src/main/java/com/dreamworks/boditech/driver/task/TaskTestRegular.java

@ -66,7 +66,7 @@ public class TaskTestRegular extends TaskTestBase {
}
@Override
protected void beforeTestStop(MdbTest test) {
protected void afterTestStop(MdbTest test) {
this.taskExecutor.getDevice().testService.regularTaskCancel(this.mdbTask);
}
}

6
src/main/java/com/dreamworks/boditech/driver/task/TaskTestTubeRackPrepare.java

@ -36,6 +36,12 @@ public class TaskTestTubeRackPrepare extends TaskBase {
}
@Override
public void afterStop() {
this.testService.regularTaskCancel(this.mdbTask);
super.afterStop();
}
@Override
public void execute( Executor executor ) {
this.setStatus(Task.STATUS_EXECUTING);

1
src/main/java/com/dreamworks/boditech/driver/task/step/StepManager.java

@ -21,6 +21,7 @@ public class StepManager {
StepManager.stepMap.put("analysis", StepAnalysis.class);
StepManager.stepMap.put("wait", StepWait.class);
StepManager.stepMap.put("cap-tube", StepCapTube.class);
StepManager.stepMap.put("move-to-background", StepMoveToBackground.class);
}
// build step by given name

9
src/main/java/com/dreamworks/boditech/driver/task/step/StepMoveToBackground.java

@ -0,0 +1,9 @@
package com.dreamworks.boditech.driver.task.step;
import com.dreamworks.boditech.driver.task.Executor;
import com.dreamworks.boditech.driver.task.Task;
public class StepMoveToBackground extends StepBase {
@Override
public void execute(Executor executor, Task task) {
task.setIsBackgroundTask(true);
}
}

1
src/main/java/com/dreamworks/boditech/driver/task/step/StepWait.java

@ -39,5 +39,6 @@ public class StepWait extends StepBase {
public void stop() {
super.stop();
this.timer.cancel();
LOG.info("step wait stopped");
}
}

2
src/main/java/com/dreamworks/boditech/entity/Project.java

@ -4,6 +4,8 @@ public class Project {
public String name;
public String code;
public Integer codeNum;
public Boolean isLargeBufferRequired;
// color of project
public String color;
public String steps;

3
src/main/java/com/dreamworks/boditech/mapper/TestTubeRackTestTaskMapper.java

@ -52,4 +52,7 @@ public interface TestTubeRackTestTaskMapper {
@Update("UPDATE btd_test_tube_rack_test_tasks SET status = #{status}, execFinishedAt = #{execFinishedAt} WHERE id = #{id}")
void testFinish( MdbTestTubeRackTestTask task );
@Update("UPDATE btd_test_tube_rack_test_tasks SET status = #{status}, execFinishedAt = #{execFinishedAt} WHERE id = #{id}")
void testCancel( MdbTestTubeRackTestTask task );
}

101
src/main/java/com/dreamworks/boditech/service/DeviceService.java

@ -72,9 +72,65 @@ public class DeviceService {
this.projectService.unload();
}
/**
* start task executor
*/
public void start() {
if ( null != this.taskExecutor ) {
throw new AppRuntimeException(AppError.DEVICE_ALREADY_STARTED);
}
if ( !this.device.testCards.getIsLoaded() ) {
throw new AppRuntimeException(AppError.DEVICE_CONSUMABLE_NOT_LOADED);
}
if (this.device.pipetteTips.isEmpty()
|| this.device.testCards.isEmpty()
|| this.device.bufferTubes.isEmpty()
) {
throw new AppRuntimeException(AppError.DEVICE_CONSUMABLE_NOT_ENOUGH);
}
this.actionLog.log("device.start");
this.taskExecutor = new Executor(this.testService, this.device);
this.taskExecutorThread = new Thread(this.taskExecutor);
this.taskExecutorThread.setName("task-executor");
this.taskExecutorThread.start();
}
// stop
public void stop() {
if ( null == this.taskExecutor ) {
throw new AppRuntimeException(AppError.DEVICE_NOT_STARTED);
}
this.taskExecutor.stop();
try {
this.taskExecutorThread.join();
} catch (InterruptedException e) {
throw new AppRuntimeException(AppError.DEVICE_STOP_FAILED);
}
TaskStopReset task = new TaskStopReset();
Executor.executeTask(this.device, task);
this.runtimeVariableService.setString("DeviceWorkingStatus", "STOPPED");
this.taskExecutor = null;
}
// pause
public void pause() {
if ( null == this.taskExecutor ) {
throw new AppRuntimeException(AppError.DEVICE_NOT_STARTED);
}
this.taskExecutor.pause();
}
// resume
public void resume() {
if ( null == this.taskExecutor ) {
throw new AppRuntimeException(AppError.DEVICE_NOT_STARTED);
}
this.taskExecutor.resume();
}
@ -114,52 +170,9 @@ public class DeviceService {
/**
* start task executor
*/
public void start() {
// @TODO : 这里要等会重新取消注释
// if ( null != this.taskExecutor ) {
// throw new RuntimeException("设备已启动");
// }
// @TODO : 后面要详细检查耗材
if ( !this.device.testCards.getIsLoaded() ) {
throw new RuntimeException("耗材未加载");
}
if (this.device.pipetteTips.isEmpty()
|| this.device.testCards.isEmpty()
|| this.device.bufferTubes.isEmpty()
// || this.device.largeBufferTubes.isEmpty()
) {
throw new RuntimeException("耗材不足, 请检查耗材");
}
this.actionLog.log("device.start");
this.taskExecutor = new Executor(this.testService, this.device);
this.taskExecutorThread = new Thread(this.taskExecutor);
this.taskExecutorThread.setName("task-executor");
this.taskExecutorThread.start();
}
// stop
public void stop() {
// @TODO : 下面还有点问题 先注释掉
// if ( null == this.taskExecutor ) {
// throw new RuntimeException("DEVICE_NOT_STARTED");
// }
//
// this.taskExecutor.stop();
// try {
// this.taskExecutorThread.join();
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
// TaskStopReset task = new TaskStopReset();
// Executor.executeTask(this.device, task);
this.runtimeVariableService.setString("DeviceWorkingStatus", "STOPPED");
this.taskExecutor = null;
}
@ -223,7 +236,7 @@ public class DeviceService {
}
// update large buffer tubes
public void largeBufferTubeUpdate(ParamLargeBufferTubeUpdate param) {
public void largeBufferTubeUpdate(ParamBufferTubeUpdateByBox param) {
this.device.largeBufferTubes.update(param);
}

10
src/main/java/com/dreamworks/boditech/service/TestService.java

@ -300,7 +300,9 @@ public class TestService {
// emergency task cancel
public void regularTaskCancel( MdbTestTubeRackTestTask task ) {
// @TODO : implement this method later
task.status = MdbTestTubeRackTestTask.STATUS_CANCELED;
task.execFinishedAt = System.currentTimeMillis();
this.testTubeRackTestTaskMapper.testCancel(task);
}
@ -313,12 +315,6 @@ public class TestService {
// test update
public void testUpdate( MdbTest test ) {
this.testMapper.update(test);

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

@ -16,5 +16,10 @@ public enum AppError {
INCUBATOR_NO_FREE_SLOT,
// device
DEVICE_BUSY
DEVICE_BUSY,
DEVICE_ALREADY_STARTED,
DEVICE_CONSUMABLE_NOT_LOADED,
DEVICE_CONSUMABLE_NOT_ENOUGH,
DEVICE_NOT_STARTED,
DEVICE_STOP_FAILED,
}
Loading…
Cancel
Save