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.
 
 

175 lines
6.0 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.ParamTestRegularAppend;
import com.dreamworks.boditech.entity.ParamTestRegularAppendTask;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class DeviceService {
@Resource
public Device device;
@Resource
public RuntimeVariableService runtimeVariableService;
// tasks
private final List<Task> tasks = new ArrayList<>();
// task executor
private Executor taskExecutor;
// task executor thread
private Thread taskExecutorThread;
/**
* load consumable resources
*/
public void load() {
TaskLoad task = new TaskLoad();
Executor.executeTask(this.device, task);
}
// 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() {
Map<String,Object> status = new HashMap<>();
// large buffer tube
List<CsmLargeBufferTube> largeBufferTubeList = this.device.largeBufferTubes.getAll();
CsmLargeBufferTube[] largeBufferTubes = new CsmLargeBufferTube[6];
for ( int i=0; i<largeBufferTubes.length; i++ ) {
largeBufferTubes[i] = new CsmLargeBufferTube(this.device.largeBufferTubes);
}
for ( CsmLargeBufferTube largeBufferTube : largeBufferTubeList ) {
Integer index = largeBufferTube.position;
largeBufferTubes[index].projectName = largeBufferTube.projectName;
}
status.put("largeBufferTubes", largeBufferTubes);
// buffer tube area
BufferTubeArea[] bufferTubeAreas = new BufferTubeArea[6];
for ( int i=0; i<bufferTubeAreas.length; i++ ) {
bufferTubeAreas[i] = new BufferTubeArea();
}
return status;
}
/**
* 复位设备, 如果设备未正常复位, 需要给个警告弹框,然后再执行错误复位
* @throws RuntimeException 设备未正常复位
*/
public void reset( Boolean errorReset ) {
String deviceWorkingStatus = this.runtimeVariableService.getString("DeviceWorkingStatus");
if ( !errorReset && "RUNNING".equals(deviceWorkingStatus) ) {
throw new RuntimeException("设备未正常复位, 需要给个警告弹框,然后再执行错误复位");
}
TaskStartReset task = new TaskStartReset();
task.mode = errorReset ? TaskStartReset.MODE_ERROR : TaskStartReset.MODE_NORMAL;
Executor.executeTask(this.device, task);
this.runtimeVariableService.setString("DeviceWorkingStatus","RUNNING");
}
// start
public void start() {
this.taskExecutor = new Executor(this.tasks, this.device);
this.taskExecutorThread = new Thread(this.taskExecutor);
this.taskExecutorThread.setName("task-executor");
this.taskExecutorThread.start();
}
// 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(ParamTestRegularAppend param) {
TaskBatchTubePrepare task = new TaskBatchTubePrepare();
task.tests = new ArrayList<>();
for (ParamTestRegularAppendTask 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();
}
}
}