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

2 years ago
2 years ago
2 years ago
2 years ago
  1. package com.dreamworks.boditech.service;
  2. import com.dreamworks.boditech.driver.*;
  3. import com.dreamworks.boditech.driver.consumable.*;
  4. import com.dreamworks.boditech.driver.entity.*;
  5. import com.dreamworks.boditech.driver.task.*;
  6. import com.dreamworks.boditech.driver.task.TaskStopReset;
  7. import com.dreamworks.boditech.entity.ParamTestEmergencyAppend;
  8. import com.dreamworks.boditech.entity.ParamTestRegularAppend;
  9. import com.dreamworks.boditech.entity.ParamTestRegularAppendTask;
  10. import jakarta.annotation.Resource;
  11. import org.springframework.stereotype.Service;
  12. import java.util.*;
  13. @Service
  14. public class DeviceService {
  15. @Resource
  16. public Device device;
  17. @Resource
  18. public RuntimeVariableService runtimeVariableService;
  19. // tasks
  20. private final List<Task> tasks = new ArrayList<>();
  21. // task executor
  22. private Executor taskExecutor;
  23. // task executor thread
  24. private Thread taskExecutorThread;
  25. /**
  26. * load consumable resources
  27. */
  28. public void load() {
  29. TaskLoad task = new TaskLoad();
  30. Executor.executeTask(this.device, task);
  31. }
  32. // scan and load test cards
  33. public void testCardLoad() {
  34. TaskTestCardLoad task = new TaskTestCardLoad();
  35. Executor.executeTask(this.device, task);
  36. }
  37. // update test cards by box
  38. public void testCardUpdateByBox(ParamTestCardUpdateByBox update) {
  39. this.device.testCards.testCardUpdateByBox(update);
  40. }
  41. // update pipette tips
  42. public void pipetteTipUpdateByBox(ParamPipetteTipUpdate param) {
  43. this.device.pipetteTips.updateByBox(param);
  44. }
  45. // load large buffer tubes
  46. public List<CsmLargeBufferTube> largeBufferTubeLoad() {
  47. TaskLargeBufferTubeLoad task = new TaskLargeBufferTubeLoad();
  48. Executor.executeTask(this.device, task);
  49. return this.device.largeBufferTubes.getAll();
  50. }
  51. // update large buffer tubes
  52. public void largeBufferTubeUpdate(ParamLargeBufferTubeUpdate param) {
  53. this.device.largeBufferTubes.update(param);
  54. }
  55. // load buffer tubes
  56. public void bufferTubeLoad() {
  57. TaskBufferTubeLoad task = new TaskBufferTubeLoad();
  58. Executor.executeTask(this.device, task);
  59. }
  60. // update buffer tubes by box
  61. public void bufferTubeUpdateByBox(ParamBufferTubeUpdateByBox param ) {
  62. this.device.bufferTubes.updateByBox(param);
  63. }
  64. // get status
  65. public Map<String, Object> status() {
  66. Map<String,Object> status = new HashMap<>();
  67. // large buffer tube
  68. List<CsmLargeBufferTube> largeBufferTubeList = this.device.largeBufferTubes.getAll();
  69. CsmLargeBufferTube[] largeBufferTubes = new CsmLargeBufferTube[6];
  70. for ( int i=0; i<largeBufferTubes.length; i++ ) {
  71. largeBufferTubes[i] = new CsmLargeBufferTube(this.device.largeBufferTubes);
  72. }
  73. for ( CsmLargeBufferTube largeBufferTube : largeBufferTubeList ) {
  74. Integer index = largeBufferTube.position;
  75. largeBufferTubes[index].projectName = largeBufferTube.projectName;
  76. }
  77. status.put("largeBufferTubes", largeBufferTubes);
  78. // buffer tube area
  79. BufferTubeArea[] bufferTubeAreas = new BufferTubeArea[6];
  80. for ( int i=0; i<bufferTubeAreas.length; i++ ) {
  81. bufferTubeAreas[i] = new BufferTubeArea();
  82. }
  83. return status;
  84. }
  85. /**
  86. * 复位设备 如果设备未正常复位 需要给个警告弹框然后再执行错误复位
  87. * @throws RuntimeException 设备未正常复位
  88. */
  89. public void reset( Boolean errorReset ) {
  90. String deviceWorkingStatus = this.runtimeVariableService.getString("DeviceWorkingStatus");
  91. if ( !errorReset && "RUNNING".equals(deviceWorkingStatus) ) {
  92. throw new RuntimeException("设备未正常复位, 需要给个警告弹框,然后再执行错误复位");
  93. }
  94. TaskStartReset task = new TaskStartReset();
  95. task.mode = errorReset ? TaskStartReset.MODE_ERROR : TaskStartReset.MODE_NORMAL;
  96. Executor.executeTask(this.device, task);
  97. this.runtimeVariableService.setString("DeviceWorkingStatus","RUNNING");
  98. }
  99. // start
  100. public void start() {
  101. this.taskExecutor = new Executor(this.tasks, this.device);
  102. this.taskExecutorThread = new Thread(this.taskExecutor);
  103. this.taskExecutorThread.setName("task-executor");
  104. this.taskExecutorThread.start();
  105. }
  106. // stop
  107. public void stop() {
  108. TaskStopReset task = new TaskStopReset();
  109. Executor.executeTask(this.device, task);
  110. this.runtimeVariableService.setString("DeviceWorkingStatus", "STOPPED");
  111. this.taskExecutor.stop();
  112. try {
  113. this.taskExecutorThread.join();
  114. } catch (InterruptedException e) {
  115. throw new RuntimeException(e);
  116. }
  117. }
  118. // emergency task append
  119. public void testEmergencyAppend(ParamTestEmergencyAppend param) {
  120. TaskTestEmergency task = new TaskTestEmergency();
  121. task.barcode = param.barcode;
  122. // task.patientId = param.patientId;
  123. // task.projectName = param.projectName;
  124. // task.bloodType = param.bloodType;
  125. task.position = param.position;
  126. this.taskAppend(task);
  127. }
  128. // regular task append
  129. public void regularTaskAppend(ParamTestRegularAppend param) {
  130. TaskBatchTubePrepare task = new TaskBatchTubePrepare();
  131. task.tests = new ArrayList<>();
  132. for (ParamTestRegularAppendTask taskItem : param.tubes) {
  133. TaskBatchTubeTestInfo test = new TaskBatchTubeTestInfo();
  134. // test.tubeIndex = taskItem.tubeIndex;
  135. // test.patientCode = taskItem.patientCode;
  136. // test.barcode = taskItem.barCode;
  137. // test.testTube = taskItem.tubeType;
  138. // test.projectNames = taskItem.projectNames;
  139. // test.blood = taskItem.bloodType;
  140. task.tests.add(test);
  141. }
  142. this.taskAppend(task);
  143. }
  144. // append task
  145. public void taskAppend(Task task) {
  146. synchronized (this.tasks) {
  147. this.tasks.add(task);
  148. this.tasks.notifyAll();
  149. }
  150. }
  151. }