From 2825b82e8a4eca618ab3c2306de2db74a2ecbd1d Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 06 四月 2026 15:54:58 +0800
Subject: [PATCH] #任务取消优化

---
 src/main/java/com/zy/common/service/CommonService.java |   52 +++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/zy/common/service/CommonService.java b/src/main/java/com/zy/common/service/CommonService.java
index 9169502..c34ef3d 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -124,7 +124,7 @@
         return true;
     }
 
-    public boolean cancelTask(CancelTaskParam param) {
+    public boolean cancelTask(CancelTaskParam param, boolean allowDirectCancel) {
         WrkMast wrkMast = null;
         Integer wrkNo = param.getWrkNo();
         String taskNo = param.getTaskNo();//wms浠诲姟鍙�
@@ -141,24 +141,42 @@
             throw new CoolException("浠诲姟涓嶅瓨鍦�");
         }
 
-        boolean cancelSuccess = false;
-        if (wrkMast.getIoType().equals(WrkIoType.IN.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_INBOUND.sts)) {
-            cancelSuccess = true;
-        } else if (wrkMast.getIoType().equals(WrkIoType.OUT.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_OUTBOUND.sts)) {
-            cancelSuccess = true;
-        } else if (wrkMast.getIoType().equals(WrkIoType.LOC_MOVE.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_LOC_MOVE.sts)) {
-            cancelSuccess = true;
-        } else if (wrkMast.getIoType().equals(WrkIoType.CRN_MOVE.id) && !wrkMast.getWrkSts().equals(WrkStsType.NEW_CRN_MOVE.sts)) {
-            cancelSuccess = true;
+        if (allowDirectCancel) {
+            boolean updated = wrkMastService.update(null, new UpdateWrapper<WrkMast>()
+                    .eq("wrk_no", wrkMast.getWrkNo())
+                    .set("mk", "taskCancel")
+                    .set("modi_time", new Date()));
+            if (!updated) {
+                throw new CoolException("浠诲姟鍙栨秷澶辫触");
+            }
+            return true;
         }
 
-        if (cancelSuccess) {
+        Long expectedWrkSts;
+        if (wrkMast.getIoType().equals(WrkIoType.IN.id)) {
+            expectedWrkSts = WrkStsType.NEW_INBOUND.sts;
+        } else if (wrkMast.getIoType().equals(WrkIoType.OUT.id)) {
+            expectedWrkSts = WrkStsType.NEW_OUTBOUND.sts;
+        } else if (wrkMast.getIoType().equals(WrkIoType.LOC_MOVE.id)) {
+            expectedWrkSts = WrkStsType.NEW_LOC_MOVE.sts;
+        } else if (wrkMast.getIoType().equals(WrkIoType.CRN_MOVE.id)) {
+            expectedWrkSts = WrkStsType.NEW_CRN_MOVE.sts;
+        } else {
+            throw new CoolException("浠诲姟绫诲瀷涓嶆敮鎸佸彇娑�");
+        }
+
+        if (!expectedWrkSts.equals(wrkMast.getWrkSts())) {
             throw new CoolException("浠诲姟宸叉墽琛岋紝鍙栨秷澶辫触");
         }
 
-        wrkMast.setMk("taskCancel");
-        wrkMast.setModiTime(new Date());
-        wrkMastService.updateById(wrkMast);
+        boolean updated = wrkMastService.update(null, new UpdateWrapper<WrkMast>()
+                .eq("wrk_no", wrkMast.getWrkNo())
+                .eq("wrk_sts", expectedWrkSts)
+                .set("mk", "taskCancel")
+                .set("modi_time", new Date()));
+        if (!updated) {
+            throw new CoolException("浠诲姟鐘舵�佸凡鍙樺寲锛屽彇娑堝け璐�");
+        }
         return true;
     }
 
@@ -264,6 +282,10 @@
     }
 
     public CancelTaskBatchResult cancelTaskBatch(CancelTaskBatchParam param) {
+        return cancelTaskBatch(param, false);
+    }
+
+    public CancelTaskBatchResult cancelTaskBatch(CancelTaskBatchParam param, boolean allowDirectCancel) {
         if (param == null) {
             throw new CoolException("鍙傛暟涓嶈兘涓虹┖");
         }
@@ -283,7 +305,7 @@
 
             boolean cancelStatus = false;
             try {
-                cancelStatus = cancelTask(cancelTaskParam);
+                cancelStatus = cancelTask(cancelTaskParam, allowDirectCancel);
             } catch (Exception e) {
             }
 

--
Gitblit v1.9.1