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.
 
 

200 lines
7.4 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;
// scan and load test cards
public List<CsmTestCard> testCardLoad() {
TaskTestCardLoad task = new TaskTestCardLoad();
Executor.executeTask(this.device, task);
return this.device.testCards.getAll();
}
// update test cards by box
public void testCardUpdateByBox(ParamTestCardUpdateByBox update) {
this.device.testCards.testCardUpdateByBox(update);
}
// update pipette tips
public void pipetteTipUpdate(ParamPipetteTipUpdate param) {
this.device.pipetteTips.update(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 List<CsmBufferTube> bufferTubeLoad() {
TaskBufferTubeLoad task = new TaskBufferTubeLoad();
Executor.executeTask(this.device, task);
return this.device.bufferTubes.getAll();
}
// 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<>();
// test card box
List<CsmTestCard> testCards = this.device.testCards.getAll();
TestCardBox[] testCardBoxes = new TestCardBox[6];
for ( int i=0; i<testCardBoxes.length; i++ ) {
testCardBoxes[i] = new TestCardBox();
}
for ( CsmTestCard testCard : testCards ) {
Integer index = testCard.position;
testCardBoxes[index].index = index;
testCardBoxes[index].amount ++;
testCardBoxes[index].projectName = testCard.projectName;
}
status.put("testCardBoxes", testCardBoxes);
// pipette tip area
PipetteTipArea[] pipetteTipAreas = new PipetteTipArea[3];
for ( int i=0; i<pipetteTipAreas.length; i++ ) {
pipetteTipAreas[i] = new PipetteTipArea();
}
List<CsmPipetteTip> pipetteTips = this.device.pipetteTips.getAll();
for ( CsmPipetteTip pipetteTip : pipetteTips ) {
Integer index = pipetteTip.areaIndex;
pipetteTipAreas[index].index = index;
pipetteTipAreas[index].amount ++;
}
status.put("pipetteTipAreas", pipetteTipAreas);
// 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();
}
List<CsmBufferTube> bufferTubeList = this.device.bufferTubes.getAll();
for ( CsmBufferTube bufferTube : bufferTubeList ) {
Integer index = bufferTube.areaIndex;
bufferTubeAreas[index].areaIndex = index;
bufferTubeAreas[index].amount ++;
bufferTubeAreas[index].projectName = bufferTube.projectName;
}
status.put("bufferTubeAreas", bufferTubeAreas);
return status;
}
// reset to initial state
public void reset() {
TaskStartReset task = new TaskStartReset();
Executor.executeTask(this.device, task);
}
// 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();
Boolean isDeviceAllModuleReset = this.runtimeVariableService.getBoolean("DeviceIsAllModuleReset");
if ( !isDeviceAllModuleReset) {
throw new RuntimeException("设备未正常复位, 需要给个警告弹框,然后再执行错误复位");
}
this.runtimeVariableService.setBoolean("DeviceIsAllModuleReset", false);
TaskStartReset task = new TaskStartReset();
task.mode = TaskStartReset.MODE_NORMAL;
Executor.executeTask(this.device, task);
}
// stop
public void stop() {
TaskStopReset task = new TaskStopReset();
Executor.executeTask(this.device, task);
this.runtimeVariableService.setBoolean("DeviceIsAllModuleReset", true);
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.tasks) {
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();
}
}
}