You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

247 lines
6.6 KiB

package com.dreamworks.boditech.service;
import com.dreamworks.boditech.driver.*;
import com.dreamworks.boditech.driver.consumable.*;
import com.dreamworks.boditech.driver.entity.*;
import com.dreamworks.boditech.driver.task.*;
import com.dreamworks.boditech.driver.task.TaskStopReset;
import com.dreamworks.boditech.entity.ParamTestEmergencyAppend;
import com.dreamworks.boditech.entity.parameter.ParamTestTubeRackTaskSave;
import com.dreamworks.boditech.entity.parameter.ParamTestTubeRackTaskSaveTube;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.*;
@Service
public class DeviceService {
@Resource
public Device device;
@Resource
public RuntimeVariableService runtimeVariableService;
@Resource
private ActionLogService actionLog;
// tasks
private final List<Task> tasks = new ArrayList<>();
// task executor
private Executor taskExecutor;
// task executor thread
private Thread taskExecutorThread;
/**
* get is executor running
* @return is executor running
*/
public Boolean isExecutorRunning() {
if ( null == this.taskExecutor ) {
return false;
}
return Executor.STATUS_RUNNING.equals(this.taskExecutor.getStatus());
}
// get executor working status
public String getExecutorWorkingStatus() {
if ( null == this.taskExecutor ) {
return null;
}
return this.taskExecutor.workingStatus;
}
/**
* load consumable resources
*/
public void load() {
this.actionLog.log("device.load");
TaskLoad task = new TaskLoad();
Executor.executeTask(this.device, task);
}
/**
* unload consumable resources
*/
public void unload() {
if ( this.isExecutorRunning() ) {
throw new RuntimeException("DEVICE_STILL_RUNNING");
}
this.actionLog.log("device.unload");
this.device.testCards.clear();
this.device.bufferTubes.clear();
this.device.largeBufferTubes.clear();
}
/**
* start task executor
*/
public void start() {
this.actionLog.log("device.start");
this.taskExecutor = new Executor(this.tasks, this.device);
this.taskExecutorThread = new Thread(this.taskExecutor);
this.taskExecutorThread.setName("task-executor");
this.taskExecutorThread.start();
}
/**
* 复位设备, 如果设备未正常复位, 需要给个警告弹框,然后再执行错误复位
* @throws RuntimeException 设备未正常复位
*/
public void reset( Boolean errorReset ) {
String deviceWorkingStatus = this.runtimeVariableService.getString("DeviceWorkingStatus");
if ( !errorReset && "RUNNING".equals(deviceWorkingStatus) ) {
throw new RuntimeException("DEVICE_RESET_NOT_CLEAN");
}
TaskStartReset task = new TaskStartReset();
task.mode = errorReset ? TaskStartReset.MODE_ERROR : TaskStartReset.MODE_NORMAL;
Executor.executeTask(this.device, task);
this.runtimeVariableService.setString("DeviceWorkingStatus","RUNNING");
}
// scan and load test cards
public void testCardLoad() {
TaskTestCardLoad task = new TaskTestCardLoad();
Executor.executeTask(this.device, task);
}
// update test cards by box
public void testCardUpdateByBox(ParamTestCardUpdateByBox update) {
this.device.testCards.testCardUpdateByBox(update);
}
// update pipette tips
public void pipetteTipUpdateByBox(ParamPipetteTipUpdate param) {
this.device.pipetteTips.updateByBox(param);
}
// load large buffer tubes
public List<CsmLargeBufferTube> largeBufferTubeLoad() {
TaskLargeBufferTubeLoad task = new TaskLargeBufferTubeLoad();
Executor.executeTask(this.device, task);
return this.device.largeBufferTubes.getAll();
}
// update large buffer tubes
public void largeBufferTubeUpdate(ParamLargeBufferTubeUpdate param) {
this.device.largeBufferTubes.update(param);
}
// load buffer tubes
public void bufferTubeLoad() {
TaskBufferTubeLoad task = new TaskBufferTubeLoad();
Executor.executeTask(this.device, task);
}
// update buffer tubes by box
public void bufferTubeUpdateByBox(ParamBufferTubeUpdateByBox param ) {
this.device.bufferTubes.updateByBox(param);
}
// get status
public Map<String, Object> status() {
return new HashMap<>();
}
// stop
public void stop() {
TaskStopReset task = new TaskStopReset();
Executor.executeTask(this.device, task);
this.runtimeVariableService.setString("DeviceWorkingStatus", "STOPPED");
this.taskExecutor.stop();
try {
this.taskExecutorThread.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
// emergency task append
public void testEmergencyAppend(ParamTestEmergencyAppend param) {
TaskTestEmergency task = new TaskTestEmergency();
task.barcode = param.barcode;
// task.patientId = param.patientId;
// task.projectName = param.projectName;
// task.bloodType = param.bloodType;
task.position = param.position;
this.taskAppend(task);
}
// regular task append
public void regularTaskAppend(ParamTestTubeRackTaskSave param) {
TaskBatchTubePrepare task = new TaskBatchTubePrepare();
task.tests = new ArrayList<>();
for (ParamTestTubeRackTaskSaveTube taskItem : param.tubes) {
TaskBatchTubeTestInfo test = new TaskBatchTubeTestInfo();
// test.tubeIndex = taskItem.tubeIndex;
// test.patientCode = taskItem.patientCode;
// test.barcode = taskItem.barCode;
// test.testTube = taskItem.tubeType;
// test.projectNames = taskItem.projectNames;
// test.blood = taskItem.bloodType;
task.tests.add(test);
}
this.taskAppend(task);
}
// append task
public void taskAppend(Task task) {
synchronized (this.tasks) {
this.tasks.add(task);
this.tasks.notifyAll();
}
}
// power off the device
public void powerOff() {
try {
Runtime.getRuntime().exec("poweroff");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
// reboot the device
public void reboot() {
try {
Runtime.getRuntime().exec("reboot");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}