From faaf77b2ed6609e1ec159f163cb97c79f37df532 Mon Sep 17 00:00:00 2001
From: Administrator <XS@163.COM>
Date: 星期六, 25 四月 2026 23:46:56 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/plugin/XiaosongProcess.java |  300 +++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 189 insertions(+), 111 deletions(-)

diff --git a/src/main/java/com/zy/core/plugin/XiaosongProcess.java b/src/main/java/com/zy/core/plugin/XiaosongProcess.java
index f62e8ec..cabdf39 100644
--- a/src/main/java/com/zy/core/plugin/XiaosongProcess.java
+++ b/src/main/java/com/zy/core/plugin/XiaosongProcess.java
@@ -95,137 +95,215 @@
     private void submitGenerateStoreWrkFileTask() {
         mainProcessTaskSubmitter.submitSerialTask(
                 MainProcessLane.GENERATE_STORE,
-                "generateStoreWrkFile",
+                "submitGenerateStoreWrkFileTask",
                 DISPATCH_INTERVAL_MS,
-                this::generateStoreWrkFile
+                this::submitGenerateStoreWrkFileTasksInternal
         );
     }
 
-    /**
-     * 璇锋眰鐢熸垚鍏ュ簱浠诲姟
-     * 鍏ュ簱绔欙紝鏍规嵁鏉$爜鎵弿鐢熸垚鍏ュ簱宸ヤ綔妗�
-     */
-    public synchronized void generateStoreWrkFile() {
-        try {
-            Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
-            if (systemConfigMapObj == null) {
-                return;
-            }
-            HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
-
-            int conveyorStationTaskLimit = 30;
-            String conveyorStationTaskLimitStr = systemConfigMap.get("conveyorStationTaskLimit");
-            if (conveyorStationTaskLimitStr != null) {
-                conveyorStationTaskLimit = Integer.parseInt(conveyorStationTaskLimitStr);
-            }
-            int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
-            if (currentStationTaskCount > conveyorStationTaskLimit) {
-                News.error("杈撻�佺珯鐐逛换鍔″凡杈惧埌涓婇檺锛屼笂闄愬�硷細{}锛岀珯鐐逛换鍔℃暟锛歿}", conveyorStationTaskLimit, currentStationTaskCount);
-                return;
+    private void submitGenerateStoreWrkFileTasksInternal() {
+        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
+        for (final BasDevp basDevp : basDevps) {
+            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
+            if (stationThread == null) {
+                continue;
             }
 
-            List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
-            for (BasDevp basDevp : basDevps) {
-                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-                if (stationThread == null) {
+            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
+            if (stationMap == null || stationMap.isEmpty()) {
+                continue;
+            }
+
+            List<StationObjModel> list = basDevp.getBarcodeStationList$();
+            for (final StationObjModel entity : list) {
+                Integer stationId = entity == null ? null : entity.getStationId();
+                if (stationId == null || !stationMap.containsKey(stationId)) {
                     continue;
                 }
-
-                Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
-
-                List<StationObjModel> list = basDevp.getBarcodeStationList$();
-                for (StationObjModel entity : list) {
-                    Integer stationId = entity.getStationId();
-                    if (!stationMap.containsKey(stationId)) {
-                        continue;
-                    }
-
-                    StationProtocol stationProtocol = stationMap.get(stationId);
-                    if (stationProtocol == null) {
-                        continue;
-                    }
-
-                    if (stationProtocol.isAutoing()
-                            && stationProtocol.isLoading()
-                            && stationProtocol.isInEnable()
-                            && stationProtocol.getTaskNo() > 0) {
-                        if (Cools.isEmpty(stationProtocol.getBarcode())) {
-                            continue;
-                        }
-
-                        if (stationProtocol.getError() > 0) {
-                            Object lock = redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo());
-                            if (lock != null) {
-                                continue;
+                mainProcessTaskSubmitter.submitKeyedSerialTask(
+                        MainProcessLane.GENERATE_STORE,
+                        stationId,
+                        "generateStoreWrkFile",
+                        DISPATCH_INTERVAL_MS,
+                        new Runnable() {
+                            @Override
+                            public void run() {
+                                generateStoreWrkFile(basDevp, entity);
                             }
-                            StationObjModel backStation = entity.getBackStation();
-                            StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.STATION_BACK.id), stationId, backStation.getStationId(), 0);
-                            if (command == null) {
-                                News.taskInfo(stationProtocol.getTaskNo(), "{}宸ヤ綔,鑾峰彇杈撻�佺嚎鍛戒护澶辫触", stationProtocol.getTaskNo());
-                                continue;
-                            }
-                            MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
-                            News.taskInfo(stationProtocol.getTaskNo(), "{}鎵爜寮傚父锛屽凡閫�鍥炶嚦{}", backStation.getStationId());
-                            redisUtil.set(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo(), "lock", 10);
-                                continue;
                         }
+                );
+            }
+        }
+    }
 
-                        // 妫�娴嬩换鍔℃槸鍚︾敓鎴�
-                        List<WrkMast> wrkMasts = wrkMastService
-                                .selectList(new EntityWrapper<WrkMast>()
-                                        .eq("barcode", stationProtocol.getBarcode()));
-                        if (!wrkMasts.isEmpty()) {
-                            for (WrkMast wrkMast : wrkMasts) {
-                                if (wrkMast.getIoType().equals(WrkIoType.OUT.id) && wrkMast.getWrkSts().equals(WrkStsType.STATION_RUN.sts)) {
-                                    wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts);
-                                    wrkMast.setModiTime(new Date());
-                                    wrkMastService.updateById(wrkMast);
-                                }
-                            }
-                            continue;
-                        }
+    private void generateStoreWrkFile(BasDevp basDevp, StationObjModel entity) {
+        if (basDevp == null || entity == null || entity.getStationId() == null) {
+            return;
+        }
 
-                        Object lock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
-                        if (lock != null) {
-                            continue;
-                        }
+        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+        if (systemConfigMapObj == null) {
+            return;
+        }
+        HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
 
-                        String barcode = stationProtocol.getBarcode();
-                        Integer stationIdVal = stationProtocol.getStationId();
+        int conveyorStationTaskLimit = 30;
+        String conveyorStationTaskLimitStr = systemConfigMap.get("conveyorStationTaskLimit");
+        if (conveyorStationTaskLimitStr != null) {
+            conveyorStationTaskLimit = Integer.parseInt(conveyorStationTaskLimitStr);
+        }
+        int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
+        if (currentStationTaskCount > conveyorStationTaskLimit) {
+            News.error("杈撻�佺珯鐐逛换鍔″凡杈惧埌涓婇檺锛屼笂闄愬�硷細{}锛岀珯鐐逛换鍔℃暟锛歿}", conveyorStationTaskLimit, currentStationTaskCount);
+            return;
+        }
 
-                        String response = wmsOperateUtils.applyInTask(barcode, stationIdVal,
-                                stationProtocol.getPalletHeight());
-                        if (response == null) {
-                            News.error("WMS鍏ュ簱鍚屾璇锋眰澶辫触锛屾帴鍙f湭鍝嶅簲锛宐arcode={}锛宻tationId={}", barcode, stationIdVal);
-                            redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
-                            stationProtocol.setSystemWarning("璇锋眰鍏ュ簱澶辫触锛學MS鏃犺繑鍥�");
-                            continue;
-                        }
+        Integer stationId = entity.getStationId();
+        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
+        if (stationThread == null) {
+            return;
+        }
 
-                        JSONObject jsonObject = JSON.parseObject(response);
-                        Integer code = jsonObject.getInteger("code");
-                        if (code != null && code.equals(200)) {
-                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
+        Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
+        if (stationMap == null || !stationMap.containsKey(stationId)) {
+            return;
+        }
 
-                            CreateInTaskParam taskParam = new CreateInTaskParam();
-                            taskParam.setTaskNo(dto.getTaskNo());
-                            taskParam.setLocNo(dto.getLocNo());
-                            taskParam.setTaskPri(dto.getTaskPri());
-                            taskParam.setBarcode(barcode);
-                            WrkMast wrkMast = commonService.createInTask(taskParam);
-                            stationProtocol.setSystemWarning("");
-                        } else {
-                            News.error("WMS鍏ュ簱鍚屾璇锋眰澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛宐arcode={}锛宻tationId={}锛宺esponse={}",
-                                    barcode, stationIdVal, response);
-                            redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
-                            stationProtocol.setSystemWarning("璇锋眰鍏ュ簱澶辫触锛學MS杩斿洖=" + response);
-                        }
+        StationProtocol stationProtocol = stationMap.get(stationId);
+        if (stationProtocol == null) {
+            return;
+        }
+
+        if (!(stationProtocol.isAutoing()
+                && stationProtocol.isLoading()
+                && stationProtocol.isInEnable()
+                && stationProtocol.getTaskNo() > 0)) {
+            logTraceLimited("generate_wait_condition_" + stationId, 5,
+                    "[WCS Trace][鏉$爜绔欏叆搴揮 鏉$爜绔欐殏鏈弧瓒崇敓鎴愭潯浠躲�俿tationId={}锛宎utoing={}锛宭oading={}锛宨nEnable={}锛宔nableIn={}锛宼askNo={}锛宼argetStaNo={}锛宐arcode={}锛宔rror={}锛寃arning={}",
+                    stationId, stationProtocol.isAutoing(), stationProtocol.isLoading(),
+                    stationProtocol.isInEnable(), stationProtocol.isEnableIn(), stationProtocol.getTaskNo(),
+                    stationProtocol.getTargetStaNo(), stationProtocol.getBarcode(),
+                    stationProtocol.getError(), stationProtocol.getSystemWarning());
+            return;
+        }
+        if (Cools.isEmpty(stationProtocol.getBarcode())) {
+            logTraceLimited("generate_wait_barcode_" + stationId, 5,
+                    "[WCS Trace][鏉$爜绔欏叆搴揮 鏉$爜绔欏凡鍒颁綅浣嗚繕娌℃湁鏉$爜銆俿tationId={}锛宼askNo={}锛宼argetStaNo={}锛宲alletHeight={}锛寃eight={}锛宔rror={}锛寃arning={}",
+                    stationId, stationProtocol.getTaskNo(), stationProtocol.getTargetStaNo(),
+                    stationProtocol.getPalletHeight(), stationProtocol.getWeight(),
+                    stationProtocol.getError(), stationProtocol.getSystemWarning());
+            return;
+        }
+
+        if (stationProtocol.getError() > 0) {
+            Object backLock = redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo());
+            if (backLock != null) {
+                return;
+            }
+            StationObjModel backStation = entity.getBackStation();
+            StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.STATION_BACK.id), stationId, backStation.getStationId(), 0);
+            if (command == null) {
+                News.taskInfo(stationProtocol.getTaskNo(), "{}宸ヤ綔,鑾峰彇杈撻�佺嚎鍛戒护澶辫触", stationProtocol.getTaskNo());
+                return;
+            }
+            MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
+            News.taskInfo(stationProtocol.getTaskNo(), "{}鎵爜寮傚父锛屽凡閫�鍥炶嚦{}", backStation.getStationId());
+            redisUtil.set(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo(), "lock", 10);
+            return;
+        }
+
+        List<WrkMast> wrkMasts = wrkMastService
+                .selectList(new EntityWrapper<WrkMast>()
+                        .eq("barcode", stationProtocol.getBarcode()));
+        if (!wrkMasts.isEmpty()) {
+            WrkMast firstWrkMast = wrkMasts.get(0);
+            News.info("[WCS Debug][鏉$爜绔欏叆搴揮 鏉$爜宸叉湁宸ヤ綔妗o紝璺宠繃鐢熸垚銆俿tationId={}锛宐arcode={}锛屽綋鍓嶇珯鐐箃askNo={}锛屽凡瀛樺湪鏁伴噺={}锛岄涓伐浣滃彿={}锛岀姸鎬�={}锛宭ocNo={}",
+                    stationId, stationProtocol.getBarcode(), stationProtocol.getTaskNo(),
+                    wrkMasts.size(), firstWrkMast.getWrkNo(), firstWrkMast.getWrkSts(),
+                    firstWrkMast.getLocNo());
+            for (WrkMast wrkMast : wrkMasts) {
+                if (wrkMast.getIoType().equals(WrkIoType.OUT.id)) {
+                    if (wrkMast.getWrkSts().equals(WrkStsType.STATION_RUN.sts) || wrkMast.getWrkSts().equals(WrkStsType.STATION_RUN_COMPLETE.sts)) {
+                        wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts);
+                        wrkMast.setModiTime(new Date());
+                        wrkMastService.updateById(wrkMast);
                     }
                 }
             }
-        } catch (Exception e) {
-            e.printStackTrace();
+            return;
         }
+
+        Object generateLock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
+        if (generateLock != null) {
+            logTraceLimited("generate_wait_lock_" + stationId, 3,
+                    "[WCS Trace][鏉$爜绔欏叆搴揮 鏉$爜绔欑敓鎴愪换鍔″懡涓檺娴侀攣銆俿tationId={}锛宼askNo={}锛宐arcode={}锛寃arning={}",
+                    stationId, stationProtocol.getTaskNo(), stationProtocol.getBarcode(), stationProtocol.getSystemWarning());
+            return;
+        }
+
+        String barcode = stationProtocol.getBarcode();
+        Integer stationIdVal = stationProtocol.getStationId();
+
+        long applyStartMs = System.currentTimeMillis();
+        News.info("[WCS Debug][鏉$爜绔欏叆搴揮 鍑嗗璇锋眰WMS鐢熸垚鍏ュ簱浠诲姟銆俿tationId={}锛宐arcode={}锛宻tationTaskNo={}锛宲alletHeight={}锛宨sInEnable={}",
+                stationIdVal, barcode, stationProtocol.getTaskNo(),
+                stationProtocol.getPalletHeight(), stationProtocol.isInEnable());
+        String response = wmsOperateUtils.applyInTask(barcode, stationIdVal,
+                stationProtocol.getPalletHeight());
+        News.info("[WCS Debug][鏉$爜绔欏叆搴揮 WMS鐢熸垚鍏ュ簱浠诲姟杩斿洖銆俿tationId={}锛宐arcode={}锛宻tationTaskNo={}锛宑ostMs={}锛宺esponse={}",
+                stationIdVal, barcode, stationProtocol.getTaskNo(),
+                System.currentTimeMillis() - applyStartMs, response);
+        if (response == null) {
+            News.error("WMS鍏ュ簱鍚屾璇锋眰澶辫触锛屾帴鍙f湭鍝嶅簲锛宐arcode={}锛宻tationId={}", barcode, stationIdVal);
+            redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
+            stationProtocol.setSystemWarning("璇锋眰鍏ュ簱澶辫触锛學MS鏃犺繑鍥�");
+            return;
+        }
+
+        JSONObject jsonObject = JSON.parseObject(response);
+        Integer code = jsonObject.getInteger("code");
+        if (code != null && code.equals(200)) {
+            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
+            if (dto == null || Cools.isEmpty(dto.getLocNo())) {
+                News.warn("[WCS Debug][鏉$爜绔欏叆搴揮 WMS杩斿洖鎴愬姛浣嗗簱浣嶄负绌猴紝绛夊緟涓嬩竴杞敓鎴愩�俿tationId={}锛宐arcode={}锛宻tationTaskNo={}锛宺esponse={}",
+                        stationIdVal, barcode, stationProtocol.getTaskNo(), response);
+                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
+                stationProtocol.setSystemWarning("WMS宸茶繑鍥炰换鍔′絾搴撲綅涓虹┖");
+                return;
+            }
+
+            CreateInTaskParam taskParam = new CreateInTaskParam();
+            taskParam.setTaskNo(dto.getTaskNo());
+            taskParam.setLocNo(dto.getLocNo());
+            taskParam.setTaskPri(dto.getTaskPri());
+            taskParam.setBarcode(barcode);
+            News.info("[WCS Debug][鏉$爜绔欏叆搴揮 鍑嗗鍒涘缓鍏ュ簱宸ヤ綔妗c�俿tationId={}锛宐arcode={}锛寃msTaskNo={}锛宭ocNo={}锛宼askPri={}",
+                    stationIdVal, barcode, dto.getTaskNo(), dto.getLocNo(), dto.getTaskPri());
+            WrkMast wrkMast = commonService.createInTask(taskParam);
+            News.info("[WCS Debug][鏉$爜绔欏叆搴揮 鍏ュ簱宸ヤ綔妗e垱寤哄畬鎴愩�俿tationId={}锛宐arcode={}锛寃msTaskNo={}锛寃rkNo={}锛宭ocNo={}",
+                    stationIdVal, barcode, dto.getTaskNo(),
+                    wrkMast == null ? null : wrkMast.getWrkNo(), dto.getLocNo());
+            stationProtocol.setSystemWarning("");
+        } else {
+            News.error("WMS鍏ュ簱鍚屾璇锋眰澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛宐arcode={}锛宻tationId={}锛宺esponse={}",
+                    barcode, stationIdVal, response);
+            redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
+            stationProtocol.setSystemWarning("璇锋眰鍏ュ簱澶辫触锛學MS杩斿洖=" + response);
+        }
+    }
+
+    private void logTraceLimited(String lockKey, int seconds, String format, Object... arguments) {
+        String redisKey = RedisKeyType.LOG_LIMIT.key + "wcs_trace_" + lockKey;
+        try {
+            Object lock = redisUtil.get(redisKey);
+            if (lock != null) {
+                return;
+            }
+            redisUtil.set(redisKey, "lock", seconds);
+        } catch (Exception e) {
+            // 璇婃柇鏃ュ織涓嶈兘褰卞搷涓绘祦绋嬨��
+        }
+        News.info(format, arguments);
     }
 
     //妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞跺惎鍔ㄥ叆搴�

--
Gitblit v1.9.1