Browse Source

PSSR安全阀多线程处理优化

jiangbiao 5 months ago
parent
commit
18f141a6e1

+ 38 - 12
master/src/main/java/com/ruoyi/project/pssr/controller/TPssrSafetyValveController.java

@@ -31,6 +31,9 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStream;
 import java.util.List;
 import java.util.List;
 import java.util.UUID;
 import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 
 /**
 /**
  * 安全设施-安全阀Controller
  * 安全设施-安全阀Controller
@@ -42,7 +45,7 @@ import java.util.UUID;
 @RequestMapping("/pssr/safetyValve")
 @RequestMapping("/pssr/safetyValve")
 public class TPssrSafetyValveController extends BaseController {
 public class TPssrSafetyValveController extends BaseController {
     @Resource
     @Resource
-     private TPssrSafetyValveMapper tPssrSafetyValveMapper;
+    private TPssrSafetyValveMapper tPssrSafetyValveMapper;
     @Autowired
     @Autowired
     private ITPssrFileService tPssrFileService;
     private ITPssrFileService tPssrFileService;
 
 
@@ -63,11 +66,33 @@ public class TPssrSafetyValveController extends BaseController {
     public TableDataInfo list(TPssrSafetyValve tPssrSafetyValve) {
     public TableDataInfo list(TPssrSafetyValve tPssrSafetyValve) {
         startPage();
         startPage();
         List<TPssrSafetyValve> list = tPssrSafetyValveService.selectTPssrSafetyValveList(tPssrSafetyValve);
         List<TPssrSafetyValve> list = tPssrSafetyValveService.selectTPssrSafetyValveList(tPssrSafetyValve);
-        list.forEach(item -> {
-            item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "aqss-v"));
-            if (item.getApproveStatus() != 2)
-                item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "aqss-v"));
-        });
+
+        if (list.size() > 0) {
+            //线程池
+            ExecutorService executorService = Executors.newFixedThreadPool(30);
+            final CountDownLatch latch = new CountDownLatch(list.size()); //相同线程数量的计数
+            for (TPssrSafetyValve item : list
+            ) {
+                executorService.submit(() -> {
+                    try {
+                        item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "aqss-v"));
+                        if (item.getApproveStatus() != 2)
+                            item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "aqss-v"));
+                    } catch (Exception e) {
+                        logger.error("e:", e);
+                    } finally {
+                        latch.countDown(); //线程计数
+                    }
+                });
+            }
+            try {
+                latch.await(); //线程计数完毕后继续执行
+            } catch (InterruptedException e) {
+                logger.error("e", e);
+            }
+            executorService.shutdown();
+        }
+
         return getDataTable(list);
         return getDataTable(list);
     }
     }
 
 
@@ -139,7 +164,7 @@ public class TPssrSafetyValveController extends BaseController {
                 num++;
                 num++;
                 rowIndex++;
                 rowIndex++;
             }
             }
-            filename =  "PSSR_14_安全设施_安全阀_" + UUID.randomUUID().toString() + ".xlsx";
+            filename = "PSSR_14_安全设施_安全阀_" + UUID.randomUUID().toString() + ".xlsx";
             out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
             out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
             wb.write(out);
             wb.write(out);
             wb.close();
             wb.close();
@@ -158,8 +183,8 @@ public class TPssrSafetyValveController extends BaseController {
     public AjaxResult getInfo(@PathVariable("id") Long id) {
     public AjaxResult getInfo(@PathVariable("id") Long id) {
         TPssrSafetyValve item = tPssrSafetyValveService.selectTPssrSafetyValveById(id);
         TPssrSafetyValve item = tPssrSafetyValveService.selectTPssrSafetyValveById(id);
         item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "aqss-v"));
         item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "aqss-v"));
-            if (item.getApproveStatus() != 2)
-                item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "aqss-v"));
+        if (item.getApproveStatus() != 2)
+            item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "aqss-v"));
         return AjaxResult.success(item);
         return AjaxResult.success(item);
     }
     }
 
 
@@ -170,7 +195,7 @@ public class TPssrSafetyValveController extends BaseController {
     @Log(title = "安全设施-安全阀", businessType = BusinessType.INSERT)
     @Log(title = "安全设施-安全阀", businessType = BusinessType.INSERT)
     @PostMapping
     @PostMapping
     public AjaxResult add(@RequestBody TPssrSafetyValve tPssrSafetyValve) {
     public AjaxResult add(@RequestBody TPssrSafetyValve tPssrSafetyValve) {
-        if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())){
+        if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())) {
             return AjaxResult.error("确认人不能为同一人,请重新选择!");
             return AjaxResult.error("确认人不能为同一人,请重新选择!");
         }
         }
         tPssrSafetyValve.setApproveStatus(0L);
         tPssrSafetyValve.setApproveStatus(0L);
@@ -184,7 +209,7 @@ public class TPssrSafetyValveController extends BaseController {
     @Log(title = "安全设施-安全阀", businessType = BusinessType.UPDATE)
     @Log(title = "安全设施-安全阀", businessType = BusinessType.UPDATE)
     @PutMapping
     @PutMapping
     public AjaxResult edit(@RequestBody TPssrSafetyValve tPssrSafetyValve) {
     public AjaxResult edit(@RequestBody TPssrSafetyValve tPssrSafetyValve) {
-        if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())){
+        if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())) {
             return AjaxResult.error("确认人不能为同一人,请重新选择!");
             return AjaxResult.error("确认人不能为同一人,请重新选择!");
         }
         }
         tPssrFileService.updateFileRelevance(tPssrSafetyValve.getFileIds(), "aqss-v", tPssrSafetyValve.getId(), tPssrSafetyValve.getSubId());
         tPssrFileService.updateFileRelevance(tPssrSafetyValve.getFileIds(), "aqss-v", tPssrSafetyValve.getId(), tPssrSafetyValve.getSubId());
@@ -198,11 +223,12 @@ public class TPssrSafetyValveController extends BaseController {
     @Log(title = "安全设施-安全阀", businessType = BusinessType.UPDATE)
     @Log(title = "安全设施-安全阀", businessType = BusinessType.UPDATE)
     @PutMapping("/editBatch")
     @PutMapping("/editBatch")
     public AjaxResult editb(@RequestBody TPssrSafetyValve tPssrSafetyValve) {
     public AjaxResult editb(@RequestBody TPssrSafetyValve tPssrSafetyValve) {
-        if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())){
+        if (tPssrSafetyValve.getConfirmer1().equals(tPssrSafetyValve.getConfirmer2())) {
             return AjaxResult.error("确认人不能为同一人,请重新选择!");
             return AjaxResult.error("确认人不能为同一人,请重新选择!");
         }
         }
         return toAjax(tPssrSafetyValveMapper.updateTPssrSafetyValveByIds(tPssrSafetyValve));
         return toAjax(tPssrSafetyValveMapper.updateTPssrSafetyValveByIds(tPssrSafetyValve));
     }
     }
+
     /**
     /**
      * 删除安全设施-安全阀
      * 删除安全设施-安全阀
      */
      */

+ 9 - 0
master/src/main/java/com/ruoyi/project/pssr/domain/TPssrOverhaulExchanger.java

@@ -107,6 +107,15 @@ public class TPssrOverhaulExchanger extends BaseEntity
 
 
     private String reason;
     private String reason;
     private String completionStatus;
     private String completionStatus;
+    private String pid;
+
+    public String getPid() {
+        return pid;
+    }
+
+    public void setPid(String pid) {
+        this.pid = pid;
+    }
 
 
     public String getCompletionStatus() {
     public String getCompletionStatus() {
         return completionStatus;
         return completionStatus;