From d2f378ef7fcf6280b336b42e8363c9bbf2534b5c Mon Sep 17 00:00:00 2001 From: sige Date: Thu, 4 Jan 2024 17:26:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=BC=80=E5=A7=8B=E3=80=81?= =?UTF-8?q?=E7=BB=93=E6=9D=9F=E3=80=81=E6=9A=82=E5=81=9C=E3=80=81=E6=81=A2?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boditech/controller/DeviceController.java | 292 +++++++-------------- .../consumable/CsmLargeBufferTubeManager.java | 19 +- .../dreamworks/boditech/driver/task/Executor.java | 101 +++---- .../com/dreamworks/boditech/driver/task/Task.java | 5 +- .../dreamworks/boditech/driver/task/TaskBase.java | 7 +- .../dreamworks/boditech/driver/task/TaskLoad.java | 2 +- .../boditech/driver/task/TaskStopReset.java | 18 +- .../boditech/driver/task/TaskTestBase.java | 24 +- .../boditech/driver/task/TaskTestEmergency.java | 2 +- .../boditech/driver/task/TaskTestRegular.java | 2 +- .../driver/task/TaskTestTubeRackPrepare.java | 6 + .../boditech/driver/task/step/StepManager.java | 1 + .../driver/task/step/StepMoveToBackground.java | 9 + .../boditech/driver/task/step/StepWait.java | 1 + .../com/dreamworks/boditech/entity/Project.java | 2 + .../mapper/TestTubeRackTestTaskMapper.java | 3 + .../dreamworks/boditech/service/DeviceService.java | 101 +++---- .../dreamworks/boditech/service/TestService.java | 10 +- .../com/dreamworks/boditech/utils/AppError.java | 7 +- 19 files changed, 302 insertions(+), 310 deletions(-) create mode 100644 src/main/java/com/dreamworks/boditech/driver/task/step/StepMoveToBackground.java diff --git a/src/main/java/com/dreamworks/boditech/controller/DeviceController.java b/src/main/java/com/dreamworks/boditech/controller/DeviceController.java index fda153b..8a1cd87 100644 --- a/src/main/java/com/dreamworks/boditech/controller/DeviceController.java +++ b/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 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")); } } diff --git a/src/main/java/com/dreamworks/boditech/driver/consumable/CsmLargeBufferTubeManager.java b/src/main/java/com/dreamworks/boditech/driver/consumable/CsmLargeBufferTubeManager.java index 18a7333..04c32ec 100644 --- a/src/main/java/com/dreamworks/boditech/driver/consumable/CsmLargeBufferTubeManager.java +++ b/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); - } } diff --git a/src/main/java/com/dreamworks/boditech/driver/task/Executor.java b/src/main/java/com/dreamworks/boditech/driver/task/Executor.java index 4faa6b7..9d68b91 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/Executor.java +++ b/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(); -// } - } + } diff --git a/src/main/java/com/dreamworks/boditech/driver/task/Task.java b/src/main/java/com/dreamworks/boditech/driver/task/Task.java index dcdad01..77fa993 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/Task.java +++ b/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(); } \ No newline at end of file diff --git a/src/main/java/com/dreamworks/boditech/driver/task/TaskBase.java b/src/main/java/com/dreamworks/boditech/driver/task/TaskBase.java index da78f5a..adda582 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/TaskBase.java +++ b/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); } } diff --git a/src/main/java/com/dreamworks/boditech/driver/task/TaskLoad.java b/src/main/java/com/dreamworks/boditech/driver/task/TaskLoad.java index 86350fc..3c7c147 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/TaskLoad.java +++ b/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 projects = device.projectService.activeProjectGetAll(); for ( Project project : projects ) { - if ( null == project ) { + if ( null == project || !project.isLargeBufferRequired ) { continue ; } diff --git a/src/main/java/com/dreamworks/boditech/driver/task/TaskStopReset.java b/src/main/java/com/dreamworks/boditech/driver/task/TaskStopReset.java index 1922f06..bc5c8de 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/TaskStopReset.java +++ b/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"); } diff --git a/src/main/java/com/dreamworks/boditech/driver/task/TaskTestBase.java b/src/main/java/com/dreamworks/boditech/driver/task/TaskTestBase.java index cb090d0..9f30c5d 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/TaskTestBase.java +++ b/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() { diff --git a/src/main/java/com/dreamworks/boditech/driver/task/TaskTestEmergency.java b/src/main/java/com/dreamworks/boditech/driver/task/TaskTestEmergency.java index 35787f8..52756a5 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/TaskTestEmergency.java +++ b/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); } } diff --git a/src/main/java/com/dreamworks/boditech/driver/task/TaskTestRegular.java b/src/main/java/com/dreamworks/boditech/driver/task/TaskTestRegular.java index 2281105..25545d8 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/TaskTestRegular.java +++ b/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); } } diff --git a/src/main/java/com/dreamworks/boditech/driver/task/TaskTestTubeRackPrepare.java b/src/main/java/com/dreamworks/boditech/driver/task/TaskTestTubeRackPrepare.java index e31f832..815a450 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/TaskTestTubeRackPrepare.java +++ b/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); diff --git a/src/main/java/com/dreamworks/boditech/driver/task/step/StepManager.java b/src/main/java/com/dreamworks/boditech/driver/task/step/StepManager.java index 5ab49d4..1004e0e 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/step/StepManager.java +++ b/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 diff --git a/src/main/java/com/dreamworks/boditech/driver/task/step/StepMoveToBackground.java b/src/main/java/com/dreamworks/boditech/driver/task/step/StepMoveToBackground.java new file mode 100644 index 0000000..6f4bf48 --- /dev/null +++ b/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); + } +} diff --git a/src/main/java/com/dreamworks/boditech/driver/task/step/StepWait.java b/src/main/java/com/dreamworks/boditech/driver/task/step/StepWait.java index 81b8c55..07c87f8 100644 --- a/src/main/java/com/dreamworks/boditech/driver/task/step/StepWait.java +++ b/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"); } } diff --git a/src/main/java/com/dreamworks/boditech/entity/Project.java b/src/main/java/com/dreamworks/boditech/entity/Project.java index 4294be4..65090db 100644 --- a/src/main/java/com/dreamworks/boditech/entity/Project.java +++ b/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; diff --git a/src/main/java/com/dreamworks/boditech/mapper/TestTubeRackTestTaskMapper.java b/src/main/java/com/dreamworks/boditech/mapper/TestTubeRackTestTaskMapper.java index 6c0a6ee..fff59a0 100644 --- a/src/main/java/com/dreamworks/boditech/mapper/TestTubeRackTestTaskMapper.java +++ b/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 ); } diff --git a/src/main/java/com/dreamworks/boditech/service/DeviceService.java b/src/main/java/com/dreamworks/boditech/service/DeviceService.java index 4ff3560..30398e7 100644 --- a/src/main/java/com/dreamworks/boditech/service/DeviceService.java +++ b/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); } diff --git a/src/main/java/com/dreamworks/boditech/service/TestService.java b/src/main/java/com/dreamworks/boditech/service/TestService.java index 183b00c..a53b37e 100644 --- a/src/main/java/com/dreamworks/boditech/service/TestService.java +++ b/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); diff --git a/src/main/java/com/dreamworks/boditech/utils/AppError.java b/src/main/java/com/dreamworks/boditech/utils/AppError.java index d4fc111..a80b4f7 100644 --- a/src/main/java/com/dreamworks/boditech/utils/AppError.java +++ b/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, }