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

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. // scan and load test cards
  26. public List<CsmTestCard> testCardLoad() {
  27. TaskTestCardLoad task = new TaskTestCardLoad();
  28. Executor.executeTask(this.device, task);
  29. return this.device.testCards.getAll();
  30. }
  31. // update test cards by box
  32. public void testCardUpdateByBox(ParamTestCardUpdateByBox update) {
  33. this.device.testCards.testCardUpdateByBox(update);
  34. }
  35. // update pipette tips
  36. public void pipetteTipUpdate(ParamPipetteTipUpdate param) {
  37. this.device.pipetteTips.update(param);
  38. }
  39. // load large buffer tubes
  40. public List<CsmLargeBufferTube> largeBufferTubeLoad() {
  41. TaskLargeBufferTubeLoad task = new TaskLargeBufferTubeLoad();
  42. Executor.executeTask(this.device, task);
  43. return this.device.largeBufferTubes.getAll();
  44. }
  45. // update large buffer tubes
  46. public void largeBufferTubeUpdate(ParamLargeBufferTubeUpdate param) {
  47. this.device.largeBufferTubes.update(param);
  48. }
  49. // load buffer tubes
  50. public List<CsmBufferTube> bufferTubeLoad() {
  51. TaskBufferTubeLoad task = new TaskBufferTubeLoad();
  52. Executor.executeTask(this.device, task);
  53. return this.device.bufferTubes.getAll();
  54. }
  55. // update buffer tubes by box
  56. public void bufferTubeUpdateByBox(ParamBufferTubeUpdateByBox param ) {
  57. this.device.bufferTubes.updateByBox(param);
  58. }
  59. // get status
  60. public Map<String, Object> status() {
  61. Map<String,Object> status = new HashMap<>();
  62. // test card box
  63. List<CsmTestCard> testCards = this.device.testCards.getAll();
  64. TestCardBox[] testCardBoxes = new TestCardBox[6];
  65. for ( int i=0; i<testCardBoxes.length; i++ ) {
  66. testCardBoxes[i] = new TestCardBox();
  67. }
  68. for ( CsmTestCard testCard : testCards ) {
  69. Integer index = testCard.position;
  70. testCardBoxes[index].index = index;
  71. testCardBoxes[index].amount ++;
  72. testCardBoxes[index].projectName = testCard.projectName;
  73. }
  74. status.put("testCardBoxes", testCardBoxes);
  75. // pipette tip area
  76. PipetteTipArea[] pipetteTipAreas = new PipetteTipArea[3];
  77. for ( int i=0; i<pipetteTipAreas.length; i++ ) {
  78. pipetteTipAreas[i] = new PipetteTipArea();
  79. }
  80. List<CsmPipetteTip> pipetteTips = this.device.pipetteTips.getAll();
  81. for ( CsmPipetteTip pipetteTip : pipetteTips ) {
  82. Integer index = pipetteTip.areaIndex;
  83. pipetteTipAreas[index].index = index;
  84. pipetteTipAreas[index].amount ++;
  85. }
  86. status.put("pipetteTipAreas", pipetteTipAreas);
  87. // large buffer tube
  88. List<CsmLargeBufferTube> largeBufferTubeList = this.device.largeBufferTubes.getAll();
  89. CsmLargeBufferTube[] largeBufferTubes = new CsmLargeBufferTube[6];
  90. for ( int i=0; i<largeBufferTubes.length; i++ ) {
  91. largeBufferTubes[i] = new CsmLargeBufferTube(this.device.largeBufferTubes);
  92. }
  93. for ( CsmLargeBufferTube largeBufferTube : largeBufferTubeList ) {
  94. Integer index = largeBufferTube.position;
  95. largeBufferTubes[index].projectName = largeBufferTube.projectName;
  96. }
  97. status.put("largeBufferTubes", largeBufferTubes);
  98. // buffer tube area
  99. BufferTubeArea[] bufferTubeAreas = new BufferTubeArea[6];
  100. for ( int i=0; i<bufferTubeAreas.length; i++ ) {
  101. bufferTubeAreas[i] = new BufferTubeArea();
  102. }
  103. List<CsmBufferTube> bufferTubeList = this.device.bufferTubes.getAll();
  104. for ( CsmBufferTube bufferTube : bufferTubeList ) {
  105. Integer index = bufferTube.areaIndex;
  106. bufferTubeAreas[index].areaIndex = index;
  107. bufferTubeAreas[index].amount ++;
  108. bufferTubeAreas[index].projectName = bufferTube.projectName;
  109. }
  110. status.put("bufferTubeAreas", bufferTubeAreas);
  111. return status;
  112. }
  113. // reset to initial state
  114. public void reset() {
  115. TaskStartReset task = new TaskStartReset();
  116. Executor.executeTask(this.device, task);
  117. }
  118. // start
  119. public void start() {
  120. this.taskExecutor = new Executor(this.tasks, this.device);
  121. this.taskExecutorThread = new Thread(this.taskExecutor);
  122. this.taskExecutorThread.setName("task-executor");
  123. this.taskExecutorThread.start();
  124. Boolean isDeviceAllModuleReset = this.runtimeVariableService.getBoolean("DeviceIsAllModuleReset");
  125. if ( !isDeviceAllModuleReset) {
  126. throw new RuntimeException("设备未正常复位, 需要给个警告弹框,然后再执行错误复位");
  127. }
  128. this.runtimeVariableService.setBoolean("DeviceIsAllModuleReset", false);
  129. TaskStartReset task = new TaskStartReset();
  130. task.mode = TaskStartReset.MODE_NORMAL;
  131. Executor.executeTask(this.device, task);
  132. }
  133. // stop
  134. public void stop() {
  135. TaskStopReset task = new TaskStopReset();
  136. Executor.executeTask(this.device, task);
  137. this.runtimeVariableService.setBoolean("DeviceIsAllModuleReset", true);
  138. this.taskExecutor.stop();
  139. try {
  140. this.taskExecutorThread.join();
  141. } catch (InterruptedException e) {
  142. throw new RuntimeException(e);
  143. }
  144. }
  145. // emergency task append
  146. public void testEmergencyAppend(ParamTestEmergencyAppend param) {
  147. TaskTestEmergency task = new TaskTestEmergency();
  148. task.barcode = param.barcode;
  149. task.patientId = param.patientId;
  150. task.projectName = param.projectName;
  151. task.bloodType = param.bloodType;
  152. task.position = param.position;
  153. this.taskAppend(task);
  154. }
  155. // regular task append
  156. public void regularTaskAppend(ParamTestRegularAppend param) {
  157. TaskBatchTubePrepare task = new TaskBatchTubePrepare();
  158. task.tests = new ArrayList<>();
  159. for (ParamTestRegularAppendTask taskItem : param.tasks) {
  160. TaskBatchTubeTestInfo test = new TaskBatchTubeTestInfo();
  161. test.tubeIndex = taskItem.tubeIndex;
  162. test.patientCode = taskItem.patientCode;
  163. test.barcode = taskItem.barCode;
  164. test.testTube = taskItem.tubeType;
  165. test.projectNames = taskItem.projectNames;
  166. test.blood = taskItem.bloodType;
  167. task.tests.add(test);
  168. }
  169. this.taskAppend(task);
  170. }
  171. // append task
  172. public void taskAppend(Task task) {
  173. synchronized (this.tasks) {
  174. this.tasks.add(task);
  175. this.tasks.notifyAll();
  176. }
  177. }
  178. }