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 tasks = new ArrayList<>(); // task executor private Executor taskExecutor; // task executor thread private Thread taskExecutorThread; // scan and load test cards public List 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 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 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 status() { Map status = new HashMap<>(); // test card box List testCards = this.device.testCards.getAll(); TestCardBox[] testCardBoxes = new TestCardBox[6]; for ( int i=0; i 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 largeBufferTubeList = this.device.largeBufferTubes.getAll(); CsmLargeBufferTube[] largeBufferTubes = new CsmLargeBufferTube[6]; for ( int i=0; i 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(); } } }