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.

182 lines
7.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. package com.dreamworks.boditech.controller;
  2. import com.dreamworks.boditech.controller.entity.ApiResponse;
  3. import com.dreamworks.boditech.entity.MdbTestTubeRackTestTask;
  4. import com.dreamworks.boditech.entity.MdbTestTubeRackTestTaskTube;
  5. import com.dreamworks.boditech.entity.Project;
  6. import com.dreamworks.boditech.entity.parameter.ParamEmergencyTaskSave;
  7. import com.dreamworks.boditech.entity.parameter.ParamTestTubeRackTaskSave;
  8. import com.dreamworks.boditech.service.ProjectService;
  9. import com.dreamworks.boditech.service.TestService;
  10. import com.dreamworks.boditech.utils.MyCommon;
  11. import jakarta.annotation.Resource;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.PostMapping;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.ResponseBody;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. @Controller
  21. public class TestController extends BaseController {
  22. @Resource
  23. private TestService testService;
  24. @Resource
  25. private ProjectService projectService;
  26. @ResponseBody
  27. @PostMapping("/api/test/test-tube-rack-save")
  28. public ApiResponse testTubeRackTaskSave(@RequestBody ParamTestTubeRackTaskSave param ) {
  29. MdbTestTubeRackTestTask task = this.testService.testTubeRackTaskSave(param);
  30. return this.success(task);
  31. }
  32. @ResponseBody
  33. @PostMapping("/api/test/test-tube-rack-list")
  34. public ApiResponse testTubeRackList() {
  35. List<Map<String,Object>> list = new ArrayList<>();
  36. List<MdbTestTubeRackTestTask> racks = this.testService.testTubeRackTaskList();
  37. for ( MdbTestTubeRackTestTask rack : racks ) {
  38. Map<String,Object> item = MyCommon.objectToMap(rack);
  39. // attach tubes to rack
  40. List<MdbTestTubeRackTestTaskTube> tubes = this.testService.testTubeRackTaskTubeListByRackId(rack.id);
  41. List<Map<String,Object>> tubeList = new ArrayList<>();
  42. for ( MdbTestTubeRackTestTaskTube tube : tubes ) {
  43. Map<String,Object> tubeItem = MyCommon.objectToMap(tube);
  44. // attach projects to tube
  45. String[] ids = tube.projectIds.isEmpty() ? new String[0] : tube.projectIds.split(",");
  46. List<Integer> projectIds = new ArrayList<>();
  47. List<Map<String,Object>> projectList = new ArrayList<>();
  48. for ( String id : ids ) {
  49. Project project = this.projectService.activeProjectGetById(Integer.parseInt(id));
  50. Map<String,Object> projectItem = MyCommon.objectToMap(project);
  51. projectItem.remove("steps");
  52. projectList.add(projectItem);
  53. projectIds.add(Integer.parseInt(id));
  54. }
  55. tubeItem.put("projects", projectList);
  56. tubeItem.put("projectIds", projectIds);
  57. tubeList.add(tubeItem);
  58. }
  59. item.put("tubes", tubeList);
  60. list.add(item);
  61. }
  62. return this.success(list);
  63. }
  64. @ResponseBody
  65. @PostMapping("/api/test/test-tube-rack-delete")
  66. public ApiResponse testTubeRackBatchDelete( @RequestBody Map<String,Object> params ) {
  67. Integer id = Integer.parseInt(params.get("id").toString());
  68. this.testService.testTubeRackTaskDeleteById(id);
  69. return this.success();
  70. }
  71. @ResponseBody
  72. @PostMapping("/api/test/test-tube-rack-lock")
  73. public ApiResponse testTubeRackLock(@RequestBody Map<String,Object> params) {
  74. Integer id = Integer.parseInt(params.get("id").toString());
  75. this.testService.testTubeRackTestLock(id);
  76. return this.success();
  77. }
  78. @ResponseBody
  79. @PostMapping("/api/test/test-tube-rack-unlock")
  80. public ApiResponse testTubeRackUnlock(@RequestBody Map<String,Object> params) {
  81. Integer id = Integer.parseInt(params.get("id").toString());
  82. this.testService.testTubeRackTestUnlock(id);
  83. return this.success();
  84. }
  85. @ResponseBody
  86. @PostMapping("/api/test/emergency-task-append")
  87. public ApiResponse testEmergencyAppend( @RequestBody List<ParamEmergencyTaskSave> param) {
  88. for ( ParamEmergencyTaskSave item : param ) {
  89. this.testService.emergencyTaskSave(item);
  90. }
  91. return this.success();
  92. }
  93. @ResponseBody
  94. @PostMapping("/api/test/emergency-slot-status-get")
  95. public ApiResponse emergencySlotStatusGet() {
  96. String slot0Status = this.testService.emergencyTaskStatusGet(0);
  97. if ( null == slot0Status ) {
  98. slot0Status = "EMPTY";
  99. }
  100. String slot1Status = this.testService.emergencyTaskStatusGet(1);
  101. if ( null == slot1Status ) {
  102. slot1Status = "EMPTY";
  103. }
  104. return this.success(List.of(
  105. Map.of("index","0","status",slot0Status),
  106. Map.of("index","1","status",slot1Status)
  107. ));
  108. }
  109. @ResponseBody
  110. @PostMapping("/api/test/list")
  111. public ApiResponse list(@RequestBody Map<String,Object> params) {
  112. List<Map<String,Object>> list = new ArrayList<>();
  113. for (int i = 0; i < 20; i++) {
  114. Map<String,Object> item = new HashMap<>();
  115. item.put("recordUUID", "202110-01");
  116. item.put("samplePID", "ABCD1234");
  117. item.put("sampleUID", "016");
  118. item.put("projectName", "hsCRP");
  119. item.put("lotCode", "1234567890");
  120. item.put("tubeIndex", "05");
  121. item.put("tubeType", "WB");
  122. item.put("sampleType", "FB");
  123. item.put("incubateStartedAt", "2012-12-15 00:00:44");
  124. item.put("incubateTime", "3600");
  125. item.put("status", "INUSE");
  126. item.put("slotIndex", Integer.toString(i));
  127. list.add(item);
  128. }
  129. return this.success(list);
  130. }
  131. @ResponseBody
  132. @PostMapping("/api/test/search")
  133. public ApiResponse search( @RequestBody Map<String,Object> params ) {
  134. List<Map<String,Object>> list = new ArrayList<>();
  135. for (int i = 0; i < 20; i++) {
  136. List<Map<String, String>> results = new ArrayList<>();
  137. for (int j = 0; j < 2; j++) {
  138. Map<String, String> result = new HashMap<>();
  139. result.put("name", "sth01");
  140. result.put("value", "123.45mg/L");
  141. results.add(result);
  142. }
  143. Map<String,Object> item = new HashMap<>();
  144. item.put("recordUUID", "202110-01");
  145. item.put("samplePID", "ABCD1234");
  146. item.put("sampleUID", "016");
  147. item.put("projectName", "hsCRP");
  148. item.put("lotCode", "1234567890");
  149. item.put("tubeIndex", "05");
  150. item.put("tubeType", "WB");
  151. item.put("sampleType", "FB");
  152. item.put("incubateStartedAt", "2012-12-15 00:00:44");
  153. item.put("incubateTime", "3600");
  154. item.put("status", "INUSE");
  155. item.put("slotIndex", Integer.toString(i));
  156. item.put("results", results);
  157. list.add(item);
  158. }
  159. return this.success(Map.of(
  160. "totalCount", "100",
  161. "list", list
  162. ));
  163. }
  164. }