From 51e110ca563b40854763ec5a317514da8fda548c Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期日, 19 四月 2026 11:30:09 +0800
Subject: [PATCH] #优化工作档和工作号事务V3.0.0.4

---
 src/main/java/com/zy/common/service/CommonService.java |   57 ++++++++++++++++++++++-----------------------------------
 1 files changed, 22 insertions(+), 35 deletions(-)

diff --git a/src/main/java/com/zy/common/service/CommonService.java b/src/main/java/com/zy/common/service/CommonService.java
index d3abb1f..2870463 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -64,36 +64,10 @@
      * 鐢熸垚宸ヤ綔鍙�
      * @return workNo(宸ヤ綔鍙�)
      */
-    public synchronized int getWorkNo(Integer wrkMk) {
-        WrkLastno wrkLastno = wrkLastnoService.getById(wrkMk);
-        if (Cools.isEmpty(wrkLastno)) {
-            throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�");
-        }
-
-        int workNo = wrkLastno.getWrkNo();
-        int sNo = wrkLastno.getsNo();
-        int eNo = wrkLastno.geteNo();
-        workNo = workNo>=eNo ? sNo : workNo+1;
-        while (true) {
-            WrkMast wrkMast = wrkMastService.selectByWorkNo(workNo);
-            if (null != wrkMast) {
-                workNo = workNo>=eNo ? sNo : workNo+1;
-            } else {
-                break;
-            }
-        }
-        // 淇敼搴忓彿璁板綍
-        if (workNo > 0){
-            wrkLastno.setWrkNo(workNo);
-            wrkLastnoService.updateById(wrkLastno);
-        }
-        // 妫�楠�
-        if (workNo == 0) {
+    public int getWorkNo(Integer wrkMk) {
+        int workNo = wrkLastnoService.allocateNextWorkNo(wrkMk);
+        if (workNo <= 0) {
             throw new CoolException("鐢熸垚宸ヤ綔鍙峰け璐ワ紝璇疯仈绯荤鐞嗗憳");
-        } else {
-            if (wrkMastService.selectByWorkNo(workNo)!=null) {
-                throw new CoolException("鐢熸垚宸ヤ綔鍙�" + workNo + "鍦ㄥ伐浣滄。涓凡瀛樺湪");
-            }
         }
         return workNo;
     }
@@ -115,18 +89,29 @@
             throw new CoolException("浠诲姟涓嶅瓨鍦�");
         }
 
+        Long currentWrkSts = wrkMast.getWrkSts();
+        Long targetWrkSts;
         if (wrkMast.getIoType() == WrkIoType.IN.id) {
-            wrkMast.setWrkSts(WrkStsType.COMPLETE_INBOUND.sts);
+            targetWrkSts = WrkStsType.COMPLETE_INBOUND.sts;
         }else if (wrkMast.getIoType() == WrkIoType.OUT.id) {
-            wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts);
+            targetWrkSts = WrkStsType.COMPLETE_OUTBOUND.sts;
         } else if (wrkMast.getIoType() == WrkIoType.LOC_MOVE.id) {
-            wrkMast.setWrkSts(WrkStsType.COMPLETE_LOC_MOVE.sts);
+            targetWrkSts = WrkStsType.COMPLETE_LOC_MOVE.sts;
         } else if (wrkMast.getIoType() == WrkIoType.CRN_MOVE.id) {
-            wrkMast.setWrkSts(WrkStsType.COMPLETE_CRN_MOVE.sts);
+            targetWrkSts = WrkStsType.COMPLETE_CRN_MOVE.sts;
+        } else {
+            throw new CoolException("浠诲姟绫诲瀷涓嶆敮鎸佸畬鎴�");
         }
 
-        wrkMast.setModiTime(new Date());
-        wrkMastService.updateById(wrkMast);
+        boolean updated = wrkMastService.update(null, new UpdateWrapper<WrkMast>()
+                .set("wrk_sts", targetWrkSts)
+                .set("modi_time", new Date())
+                .set("memo", "鎵嬪姩瀹屾垚")
+                .eq("wrk_no", wrkMast.getWrkNo())
+                .eq("wrk_sts", currentWrkSts));
+        if (!updated) {
+            throw new CoolException("浠诲姟鐘舵�佸凡鍙樺寲锛屽畬鎴愬け璐�");
+        }
         return true;
     }
 
@@ -169,6 +154,7 @@
                 .eq("wrk_no", wrkMast.getWrkNo())
                 .eq("wrk_sts", expectedWrkSts)
                 .set("mk", "taskCancel")
+                .set("memo", "鎵嬪姩鍙栨秷")
                 .set("modi_time", new Date()));
         if (!updated) {
             throw new CoolException("浠诲姟鐘舵�佸凡鍙樺寲锛屽彇娑堝け璐�");
@@ -197,6 +183,7 @@
         boolean updated = wrkMastService.update(null, new UpdateWrapper<WrkMast>()
                 .eq("wrk_no", wrkMast.getWrkNo())
                 .set("mk", "taskForceCancel")
+                .set("memo", "鎵嬪姩瀹屾垚")
                 .set("modi_time", new Date()));
         if (!updated) {
             throw new CoolException("浠诲姟寮哄埗鍙栨秷澶辫触");

--
Gitblit v1.9.1