From e14a4372b6bd4a38e40a3a68bde32350d96071ab Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期四, 15 一月 2026 13:11:56 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/plugin/FakeProcess.java |  328 ++++++++++++++++++++++++++++++++----------------------
 1 files changed, 195 insertions(+), 133 deletions(-)

diff --git a/src/main/java/com/zy/core/plugin/FakeProcess.java b/src/main/java/com/zy/core/plugin/FakeProcess.java
index b901478..16a90f8 100644
--- a/src/main/java/com/zy/core/plugin/FakeProcess.java
+++ b/src/main/java/com/zy/core/plugin/FakeProcess.java
@@ -50,10 +50,10 @@
 @Component
 public class FakeProcess implements MainProcessPluginApi {
 
-    private static final long METHOD_TIMEOUT_MS = 5000; // 5绉掕秴鏃�
+    private static final long METHOD_TIMEOUT_MS = 15000; // 15绉掕秴鏃�
     private static final ExecutorService timeoutExecutor = Executors.newCachedThreadPool();
 
-    private static Map<Integer,Long> stationStayTimeMap = new ConcurrentHashMap<>();
+    private static Map<Integer, Long> stationStayTimeMap = new ConcurrentHashMap<>();
     private static volatile String enableFake = "N";
     private static volatile String fakeRealTaskRequestWms = "N";
     private static volatile String fakeGenerateInTask = "Y";
@@ -88,8 +88,9 @@
 
     /**
      * 甯﹁秴鏃朵繚鎶ゆ墽琛屾柟娉�
+     * 
      * @param taskName 浠诲姟鍚嶇О锛堢敤浜庢棩蹇楋級
-     * @param task 瑕佹墽琛岀殑浠诲姟
+     * @param task     瑕佹墽琛岀殑浠诲姟
      */
     private void executeWithTimeout(String taskName, Runnable task) {
         Future<?> future = timeoutExecutor.submit(task);
@@ -110,23 +111,23 @@
         long startTime = System.currentTimeMillis();
         asyncFakeRun();
 
-        //璇锋眰鐢熸垚鍏ュ簱浠诲姟
+        // 璇锋眰鐢熸垚鍏ュ簱浠诲姟
         executeWithTimeout("generateStoreWrkFile", this::generateStoreWrkFile);
 
-        //鎵ц鍫嗗灈鏈轰换鍔�
+        // 鎵ц鍫嗗灈鏈轰换鍔�
         executeWithTimeout("crnIoExecute", crnOperateUtils::crnIoExecute);
-        //鍫嗗灈鏈轰换鍔℃墽琛屽畬鎴�-鍏峰浠跨湡鑳藉姏
+        // 鍫嗗灈鏈轰换鍔℃墽琛屽畬鎴�-鍏峰浠跨湡鑳藉姏
         executeWithTimeout("crnIoExecuteFinish", this::crnIoExecuteFinish);
-        //鎵ц杈撻�佺珯鐐瑰叆搴撲换鍔�
+        // 鎵ц杈撻�佺珯鐐瑰叆搴撲换鍔�
         executeWithTimeout("stationInExecute", stationOperateProcessUtils::stationInExecute);
-        //鎵ц杈撻�佺珯鐐瑰嚭搴撲换鍔�
+        // 鎵ц杈撻�佺珯鐐瑰嚭搴撲换鍔�
         executeWithTimeout("stationOutExecute", stationOperateProcessUtils::stationOutExecute);
-        //妫�娴嬭緭閫佺珯鐐瑰嚭搴撲换鍔℃墽琛屽畬鎴�
+        // 妫�娴嬭緭閫佺珯鐐瑰嚭搴撲换鍔℃墽琛屽畬鎴�
         executeWithTimeout("stationOutExecuteFinish", stationOperateProcessUtils::stationOutExecuteFinish);
 
-        //鎵ц鍙屽伐浣嶅爢鍨涙満浠诲姟
+        // 鎵ц鍙屽伐浣嶅爢鍨涙満浠诲姟
         executeWithTimeout("dualCrnIoExecute", dualCrnOperateProcessUtils::dualCrnIoExecute);
-        //鍙屽伐浣嶅爢鍨涙満浠诲姟鎵ц瀹屾垚
+        // 鍙屽伐浣嶅爢鍨涙満浠诲姟鎵ц瀹屾垚
         executeWithTimeout("dualCrnIoExecuteFinish", dualCrnOperateProcessUtils::dualCrnIoExecuteFinish);
 
         News.info("[WCS Debug] 涓荤嚎绋婻un鎵ц瀹屾垚,鑰楁椂:{}ms", System.currentTimeMillis() - startTime);
@@ -140,22 +141,26 @@
         asyncFakeRunThread = new Thread(() -> {
             while (!Thread.currentThread().isInterrupted()) {
                 try {
-                    Config enableFakeConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "enableFake"));
+                    Config enableFakeConfig = configService
+                            .selectOne(new EntityWrapper<Config>().eq("code", "enableFake"));
                     if (enableFakeConfig != null) {
                         enableFake = enableFakeConfig.getValue();
                     }
 
-                    Config fakeRealTaskRequestWmsConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeRealTaskRequestWms"));
+                    Config fakeRealTaskRequestWmsConfig = configService
+                            .selectOne(new EntityWrapper<Config>().eq("code", "fakeRealTaskRequestWms"));
                     if (fakeRealTaskRequestWmsConfig != null) {
                         fakeRealTaskRequestWms = fakeRealTaskRequestWmsConfig.getValue();
                     }
 
-                    Config fakeGenerateInTaskConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateInTask"));
+                    Config fakeGenerateInTaskConfig = configService
+                            .selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateInTask"));
                     if (fakeGenerateInTaskConfig != null) {
                         fakeGenerateInTask = fakeGenerateInTaskConfig.getValue();
                     }
 
-                    Config fakeGenerateOutTaskConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateOutTask"));
+                    Config fakeGenerateOutTaskConfig = configService
+                            .selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateOutTask"));
                     if (fakeGenerateOutTaskConfig != null) {
                         fakeGenerateOutTask = fakeGenerateOutTaskConfig.getValue();
                     }
@@ -165,20 +170,20 @@
                         continue;
                     }
 
-                    //妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
+                    // 妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
                     checkInStationHasTask();
-                    //鐢熸垚浠跨湡妯℃嫙鍏ュ簱浠诲姟
+                    // 鐢熸垚浠跨湡妯℃嫙鍏ュ簱浠诲姟
                     generateFakeInTask();
-                    //鐢熸垚浠跨湡妯℃嫙鍑哄簱浠诲姟
+                    // 鐢熸垚浠跨湡妯℃嫙鍑哄簱浠诲姟
                     generateFakeOutTask();
-                    //璁$畻鎵�鏈夌珯鐐瑰仠鐣欐椂闂�
+                    // 璁$畻鎵�鏈夌珯鐐瑰仠鐣欐椂闂�
                     calcAllStationStayTime();
-                    //妫�娴嬪嚭搴撶珯鐐瑰仠鐣欐槸鍚﹁秴鏃�
+                    // 妫�娴嬪嚭搴撶珯鐐瑰仠鐣欐槸鍚﹁秴鏃�
                     checkOutStationStayTimeOut();
-                    //妫�娴嬪叆搴撶珯鐐瑰爢鍨涙満鏄惁鍙栬蛋璐х墿
+                    // 妫�娴嬪叆搴撶珯鐐瑰爢鍨涙満鏄惁鍙栬蛋璐х墿
                     checkInStationCrnTake();
 
-                    //妫�娴嬭緭閫佺珯鐐规槸鍚﹁繍琛屽牭濉�
+                    // 妫�娴嬭緭閫佺珯鐐规槸鍚﹁繍琛屽牭濉�
                     stationOperateProcessUtils.checkStationRunBlock();
 
                     // 闂撮殧
@@ -196,8 +201,8 @@
         asyncFakeRunThread.start();
     }
 
-    //妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
-    private void checkInStationHasTask() {
+    // 妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
+    private synchronized void checkInStationHasTask() {
         if (!enableFake.equals("Y")) {
             return;
         }
@@ -209,7 +214,7 @@
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-            if(stationThread == null){
+            if (stationThread == null) {
                 continue;
             }
 
@@ -218,7 +223,7 @@
             List<StationObjModel> list = basDevp.getInStationList$();
             for (StationObjModel entity : list) {
                 Integer stationId = entity.getStationId();
-                if(!stationMap.containsKey(stationId)){
+                if (!stationMap.containsKey(stationId)) {
                     continue;
                 }
 
@@ -228,16 +233,17 @@
                 }
 
                 Object lock = redisUtil.get(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId);
-                if(lock != null){
+                if (lock != null) {
                     continue;
                 }
 
-                //婊¤冻鑷姩銆佹棤鐗┿�佸伐浣滃彿0锛岀敓鎴愬叆搴撴暟鎹�
+                // 婊¤冻鑷姩銆佹棤鐗┿�佸伐浣滃彿0锛岀敓鎴愬叆搴撴暟鎹�
                 if (stationProtocol.isAutoing()
                         && !stationProtocol.isLoading()
-                        && stationProtocol.getTaskNo() == 0
-                ) {
-                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId, entity.getBarcodeStation().getStationId(), 0);
+                        && stationProtocol.getTaskNo() == 0) {
+                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE,
+                            commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId,
+                            entity.getBarcodeStation().getStationId(), 0);
                     MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                     redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 5);
                 }
@@ -245,8 +251,8 @@
         }
     }
 
-    //鐢熸垚浠跨湡妯℃嫙鍏ュ簱浠诲姟
-    private void generateFakeInTask() {
+    // 鐢熸垚浠跨湡妯℃嫙鍏ュ簱浠诲姟
+    private synchronized void generateFakeInTask() {
         if (!enableFake.equals("Y")) {
             return;
         }
@@ -262,7 +268,7 @@
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-            if(stationThread == null){
+            if (stationThread == null) {
                 continue;
             }
 
@@ -271,7 +277,7 @@
             List<StationObjModel> list = basDevp.getBarcodeStationList$();
             for (StationObjModel model : list) {
                 Integer stationId = model.getStationId();
-                if(!stationMap.containsKey(stationId)){
+                if (!stationMap.containsKey(stationId)) {
                     continue;
                 }
 
@@ -285,22 +291,23 @@
                     continue;
                 }
 
-                //婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
+                // 婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
                 if (stationProtocol.isAutoing()
                         && stationProtocol.isLoading()
-                        && stationProtocol.getTaskNo() > 0
-                ) {
+                        && stationProtocol.getTaskNo() > 0) {
                     if (Cools.isEmpty(stationProtocol.getBarcode())) {
                         continue;
                     }
 
-                    //妫�娴嬩换鍔℃槸鍚︾敓鎴�
-                    List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
+                    // 妫�娴嬩换鍔℃槸鍚︾敓鎴�
+                    List<WrkMast> wrkMasts = wrkMastService
+                            .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                     if (!wrkMasts.isEmpty()) {
                         continue;
                     }
 
-                    List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.O)));
+                    List<LocMast> locMastList = locMastService
+                            .selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.O)));
                     if (locMastList.isEmpty()) {
                         continue;
                     }
@@ -326,8 +333,9 @@
                     taskParam.setBarcode(stationProtocol.getBarcode());
                     WrkMast wrkMast = commonService.createInTask(taskParam);
 
-                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationId, stationId, 0);
-                    if(command == null){
+                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(),
+                            stationId, stationId, 0);
+                    if (command == null) {
                         News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
                         continue;
                     }
@@ -338,8 +346,8 @@
         }
     }
 
-    //鐢熸垚浠跨湡妯℃嫙鍑哄簱浠诲姟
-    private void generateFakeOutTask() {
+    // 鐢熸垚浠跨湡妯℃嫙鍑哄簱浠诲姟
+    private synchronized void generateFakeOutTask() {
         if (!enableFake.equals("Y")) {
             return;
         }
@@ -355,7 +363,7 @@
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-            if(stationThread == null){
+            if (stationThread == null) {
                 continue;
             }
 
@@ -364,7 +372,7 @@
             List<StationObjModel> list = basDevp.getOutStationList$();
             for (StationObjModel entity : list) {
                 Integer stationId = entity.getStationId();
-                if(!stationMap.containsKey(stationId)){
+                if (!stationMap.containsKey(stationId)) {
                     continue;
                 }
 
@@ -374,16 +382,16 @@
                 }
 
                 Object object = redisUtil.get(RedisKeyType.GENERATE_FAKE_OUT_TASK_LIMIT.key + stationId);
-                if(object != null){
+                if (object != null) {
                     return;
                 }
 
-                //婊¤冻鑷姩銆佹棤鐗┿�佸伐浣滃彿0锛岀敓鎴愬嚭搴撴暟鎹�
+                // 婊¤冻鑷姩銆佹棤鐗┿�佸伐浣滃彿0锛岀敓鎴愬嚭搴撴暟鎹�
                 if (stationProtocol.isAutoing()
                         && !stationProtocol.isLoading()
-                        && stationProtocol.getTaskNo() == 0
-                ) {
-                    List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.F)));
+                        && stationProtocol.getTaskNo() == 0) {
+                    List<LocMast> locMastList = locMastService
+                            .selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.F)));
                     if (locMastList.isEmpty()) {
                         continue;
                     }
@@ -419,7 +427,7 @@
 
             int conveyorStationTaskLimit = 30;
             String conveyorStationTaskLimitStr = systemConfigMap.get("conveyorStationTaskLimit");
-            if(conveyorStationTaskLimitStr != null){
+            if (conveyorStationTaskLimitStr != null) {
                 conveyorStationTaskLimit = Integer.parseInt(conveyorStationTaskLimitStr);
             }
             int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
@@ -449,17 +457,17 @@
                         continue;
                     }
 
-                    //婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
+                    // 婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
                     if (stationProtocol.isAutoing()
                             && stationProtocol.isLoading()
-                            && stationProtocol.getTaskNo() > 0
-                    ) {
+                            && stationProtocol.getTaskNo() > 0) {
                         if (Cools.isEmpty(stationProtocol.getBarcode())) {
                             continue;
                         }
 
-                        //妫�娴嬩换鍔℃槸鍚︾敓鎴�
-                        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
+                        // 妫�娴嬩换鍔℃槸鍚︾敓鎴�
+                        List<WrkMast> wrkMasts = wrkMastService
+                                .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                         if (!wrkMasts.isEmpty()) {
                             continue;
                         }
@@ -468,30 +476,62 @@
                         if (lock != null) {
                             continue;
                         }
-                        redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
 
-                        String response = wmsOperateUtils.applyInTask(stationProtocol.getBarcode(), stationProtocol.getStationId(), stationProtocol.getPalletHeight());
-                        if (response == null) {
-                            News.error("璇锋眰WMS鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乺esponse锛歿}", response);
-                            continue;
-                        }
-                        JSONObject jsonObject = JSON.parseObject(response);
-                        if (jsonObject.getInteger("code").equals(200)) {
-                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
+                        String barcode = stationProtocol.getBarcode();
+                        Integer stationIdVal = stationProtocol.getStationId();
 
-                            CreateInTaskParam taskParam = new CreateInTaskParam();
-                            taskParam.setTaskNo(dto.getTaskNo());
-                            taskParam.setLocNo(dto.getLocNo());
-                            taskParam.setTaskPri(dto.getTaskPri());
-                            taskParam.setBarcode(stationProtocol.getBarcode());
-                            WrkMast wrkMast = commonService.createInTask(taskParam);
+                        // 1. 棣栧厛鏌ヨ鏄惁鏈夊凡瀹屾垚鐨勫紓姝ュ搷搴�
+                        String response = wmsOperateUtils.queryAsyncInTaskResponse(barcode, stationIdVal);
 
-                            StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, wrkMast.getWrkNo(), stationId, stationId, 0);
-                            if (command == null) {
-                                News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
+                        if (response != null) {
+                            // 2. 鏈夊搷搴旂粨鏋滐紝澶勭悊鍝嶅簲
+                            if (response.equals("FAILED") || response.startsWith("ERROR:")) {
+                                // 璇锋眰澶辫触锛岄噸鏂板彂璧峰紓姝ヨ姹�
+                                News.error("WMS鍏ュ簱璇锋眰澶辫触锛岄噸鏂板彂璧疯姹傦紝barcode={}锛宻tationId={}锛宺esponse={}", barcode,
+                                        stationIdVal, response);
+                                wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal,
+                                        stationProtocol.getPalletHeight());
+                                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
                                 continue;
                             }
-                            MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
+
+                            // 瑙f瀽鍝嶅簲
+                            JSONObject jsonObject = JSON.parseObject(response);
+                            if (jsonObject.getInteger("code").equals(200)) {
+                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
+
+                                CreateInTaskParam taskParam = new CreateInTaskParam();
+                                taskParam.setTaskNo(dto.getTaskNo());
+                                taskParam.setLocNo(dto.getLocNo());
+                                taskParam.setTaskPri(dto.getTaskPri());
+                                taskParam.setBarcode(barcode);
+                                WrkMast wrkMast = commonService.createInTask(taskParam);
+
+                                StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO,
+                                        wrkMast.getWrkNo(), stationId, stationId, 0);
+                                if (command == null) {
+                                    News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
+                                    continue;
+                                }
+                                MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
+                            } else {
+                                // 鎺ュ彛杩斿洖闈�200锛岄噸鏂板彂璧疯姹�
+                                News.error("WMS鍏ュ簱鎺ュ彛杩斿洖闈�200锛岄噸鏂板彂璧疯姹傦紝barcode={}锛宻tationId={}锛宺esponse={}", barcode,
+                                        stationIdVal, response);
+                                wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal,
+                                        stationProtocol.getPalletHeight());
+                                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
+                            }
+                        } else {
+                            // 3. 娌℃湁鍝嶅簲缁撴灉锛屾鏌ユ槸鍚︽湁璇锋眰姝e湪杩涜涓�
+                            if (!wmsOperateUtils.isAsyncRequestInProgress(barcode, stationIdVal)) {
+                                // 娌℃湁璇锋眰杩涜涓紝鍙戣捣鏂扮殑寮傛璇锋眰
+                                News.info("鍙戣捣寮傛WMS鍏ュ簱璇锋眰锛宐arcode={}锛宻tationId={}", barcode, stationIdVal);
+                                wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal,
+                                        stationProtocol.getPalletHeight());
+                                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
+                            }
+                            // 濡傛灉鏈夎姹傝繘琛屼腑锛岀瓑寰呬笅娆″惊鐜啀妫�鏌�
                         }
                     }
                 }
@@ -501,8 +541,8 @@
         }
     }
 
-    //璁$畻鎵�鏈夌珯鐐瑰仠鐣欐椂闂�
-    public void calcAllStationStayTime() {
+    // 璁$畻鎵�鏈夌珯鐐瑰仠鐣欐椂闂�
+    public synchronized void calcAllStationStayTime() {
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
@@ -512,30 +552,33 @@
 
             List<StationProtocol> list = stationThread.getStatus();
             for (StationProtocol stationProtocol : list) {
-                if (stationProtocol.getTaskNo() > 0 && !stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
+                if (stationProtocol.getTaskNo() > 0
+                        && !stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
                     stationStayTimeMap.put(stationProtocol.getStationId(), System.currentTimeMillis());
                 }
 
-                if(stationProtocol.getTaskNo() <= 0 && stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
+                if (stationProtocol.getTaskNo() <= 0
+                        && stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
                     stationStayTimeMap.remove(stationProtocol.getStationId());
                 }
             }
         }
     }
 
-    //妫�娴嬪嚭搴撶珯鐐瑰仠鐣欐槸鍚﹁秴鏃�
-    public void checkOutStationStayTimeOut() {
+    // 妫�娴嬪嚭搴撶珯鐐瑰仠鐣欐槸鍚﹁秴鏃�
+    public synchronized void checkOutStationStayTimeOut() {
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             List<StationObjModel> outStationList = basDevp.getOutStationList$();
-            if(outStationList.isEmpty()){
+            if (outStationList.isEmpty()) {
                 News.info("杈撻�佺嚎:{} 鍑哄簱绔欑偣鏈缃�", basDevp.getDevpNo());
                 continue;
             }
 
             for (StationObjModel stationObjModel : outStationList) {
-                Object lock = redisUtil.get(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
-                if(lock != null){
+                Object lock = redisUtil
+                        .get(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
+                if (lock != null) {
                     continue;
                 }
 
@@ -544,31 +587,36 @@
                     continue;
                 }
 
-                if(System.currentTimeMillis() - stayTime > 1000 * 15) {
-                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
-                    if(stationThread == null){
+                if (System.currentTimeMillis() - stayTime > 1000 * 15) {
+                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
+                            stationObjModel.getDeviceNo());
+                    if (stationThread == null) {
                         continue;
                     }
 
-                    StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, stationObjModel.getStationId(), 0, 0);
-                    if(command == null){
+                    StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0,
+                            stationObjModel.getStationId(), 0, 0);
+                    if (command == null) {
                         continue;
                     }
 
                     MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
-                    redisUtil.set(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
-                    News.info("杈撻�佺珯鐐瑰嚭搴撻噸缃懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
+                    redisUtil.set(
+                            RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(),
+                            "lock", 10);
+                    News.info("杈撻�佺珯鐐瑰嚭搴撻噸缃懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(),
+                            JSON.toJSONString(command));
                 }
             }
         }
     }
 
-    //妫�娴嬪叆搴撶珯鐐瑰爢鍨涙満鏄惁鍙栬蛋璐х墿
-    public void checkInStationCrnTake() {
+    // 妫�娴嬪叆搴撶珯鐐瑰爢鍨涙満鏄惁鍙栬蛋璐х墿
+    public synchronized void checkInStationCrnTake() {
         List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
         for (BasCrnp basCrnp : basCrnps) {
             List<StationObjModel> inStationList = basCrnp.getInStationList$();
-            if(inStationList.isEmpty()){
+            if (inStationList.isEmpty()) {
                 News.info("鍫嗗灈鏈�:{} 鍏ュ簱绔欑偣鏈缃�", basCrnp.getCrnNo());
                 continue;
             }
@@ -578,7 +626,7 @@
         List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<>());
         for (BasDualCrnp basDualCrnp : basDualCrnps) {
             List<StationObjModel> inStationList = basDualCrnp.getInStationList$();
-            if(inStationList.isEmpty()){
+            if (inStationList.isEmpty()) {
                 News.info("鍙屽伐浣嶅爢鍨涙満:{} 鍏ュ簱绔欑偣鏈缃�", basDualCrnp.getCrnNo());
                 continue;
             }
@@ -586,15 +634,17 @@
         }
     }
 
-    private void checkInStationListCrnTake(List<StationObjModel> inStationList) {
+    private synchronized void checkInStationListCrnTake(List<StationObjModel> inStationList) {
         for (StationObjModel stationObjModel : inStationList) {
-            Object lock = redisUtil.get(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
-            if(lock != null){
+            Object lock = redisUtil
+                    .get(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
+            if (lock != null) {
                 continue;
             }
 
-            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
-            if(stationThread == null){
+            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
+                    stationObjModel.getDeviceNo());
+            if (stationThread == null) {
                 continue;
             }
 
@@ -604,19 +654,24 @@
                 continue;
             }
 
-            if(stationProtocol.getTaskNo() > 0) {
-                StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, stationObjModel.getStationId(), 0, 0);
-                if(command == null){
+            if (stationProtocol.getTaskNo() > 0) {
+                StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0,
+                        stationObjModel.getStationId(), 0, 0);
+                if (command == null) {
                     continue;
                 }
 
                 WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
                 if (wrkMast == null) {
                     MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
-                    redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
-                    News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(task_over)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
-                }else {
-                    if (wrkMast.getWrkSts() != WrkStsType.NEW_INBOUND.sts && wrkMast.getWrkSts() != WrkStsType.INBOUND_DEVICE_RUN.sts) {
+                    redisUtil.set(
+                            RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(),
+                            "lock", 10);
+                    News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(task_over)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(),
+                            JSON.toJSONString(command));
+                } else {
+                    if (wrkMast.getWrkSts() != WrkStsType.NEW_INBOUND.sts
+                            && wrkMast.getWrkSts() != WrkStsType.INBOUND_DEVICE_RUN.sts) {
                         Integer crnNo = wrkMast.getCrnNo();
                         if (crnNo != null) {
                             CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnNo);
@@ -624,16 +679,20 @@
                                 continue;
                             }
                             CrnProtocol crnProtocol = crnThread.getStatus();
-                            if (!crnProtocol.getStatusType().equals(CrnStatusType.PUT_MOVING) && !crnProtocol.getStatusType().equals(CrnStatusType.PUTTING)) {
+                            if (!crnProtocol.getStatusType().equals(CrnStatusType.PUT_MOVING)
+                                    && !crnProtocol.getStatusType().equals(CrnStatusType.PUTTING)) {
                                 continue;
                             }
 
                             MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
-                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
-                            News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(crn_fetch)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
-                        }else {
+                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key
+                                    + stationObjModel.getStationId(), "lock", 10);
+                            News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(crn_fetch)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(),
+                                    JSON.toJSONString(command));
+                        } else {
                             Integer dualCrnNo = wrkMast.getDualCrnNo();
-                            DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, dualCrnNo);
+                            DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn,
+                                    dualCrnNo);
                             if (dualCrnThread == null) {
                                 continue;
                             }
@@ -653,8 +712,10 @@
                             }
 
                             MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
-                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
-                            News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(crn_fetch)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
+                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key
+                                    + stationObjModel.getStationId(), "lock", 10);
+                            News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(crn_fetch)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(),
+                                    JSON.toJSONString(command));
                         }
                     }
                 }
@@ -662,26 +723,25 @@
         }
     }
 
-    //鍫嗗灈鏈轰换鍔℃墽琛屽畬鎴�
-    public void crnIoExecuteFinish() {
+    // 鍫嗗灈鏈轰换鍔℃墽琛屽畬鎴�
+    public synchronized void crnIoExecuteFinish() {
         List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
         for (BasCrnp basCrnp : basCrnps) {
             CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
-            if(crnThread == null){
+            if (crnThread == null) {
                 continue;
             }
 
             CrnProtocol crnProtocol = crnThread.getStatus();
-            if(crnProtocol == null){
+            if (crnProtocol == null) {
                 continue;
             }
 
             if (crnProtocol.getMode() == CrnModeType.AUTO.id
                     && crnProtocol.getTaskNo() > 0
-                    && crnProtocol.getStatus() == CrnStatusType.WAITING.id
-            ) {
+                    && crnProtocol.getStatus() == CrnStatusType.WAITING.id) {
                 Object lock = redisUtil.get(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo());
-                if(lock != null){
+                if (lock != null) {
                     continue;
                 }
 
@@ -693,14 +753,14 @@
                 }
 
                 Long updateWrkSts = null;
-                if(wrkMast.getWrkSts() == WrkStsType.INBOUND_RUN.sts){
+                if (wrkMast.getWrkSts() == WrkStsType.INBOUND_RUN.sts) {
                     updateWrkSts = WrkStsType.COMPLETE_INBOUND.sts;
-                }else if(wrkMast.getWrkSts() == WrkStsType.OUTBOUND_RUN.sts){
+                } else if (wrkMast.getWrkSts() == WrkStsType.OUTBOUND_RUN.sts) {
                     updateWrkSts = WrkStsType.OUTBOUND_RUN_COMPLETE.sts;
 
-                    //鐢熸垚浠跨湡绔欑偣鏁版嵁
+                    // 鐢熸垚浠跨湡绔欑偣鏁版嵁
                     List<StationObjModel> outStationList = basCrnp.getOutStationList$();
-                    if(outStationList.isEmpty()){
+                    if (outStationList.isEmpty()) {
                         News.info("鍫嗗灈鏈�:{} 鍑哄簱绔欑偣鏈缃�", basCrnp.getCrnNo());
                         continue;
                     }
@@ -710,17 +770,19 @@
                             continue;
                         }
 
-                        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
+                        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
+                                stationObjModel.getDeviceNo());
                         if (stationThread == null) {
                             continue;
                         }
-                        //鐢熸垚浠跨湡绔欑偣鏁版嵁
-                        StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9998, wrkMast.getSourceStaNo(), 0, 0);
+                        // 鐢熸垚浠跨湡绔欑偣鏁版嵁
+                        StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9998,
+                                wrkMast.getSourceStaNo(), 0, 0);
                         MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                     }
-                }else if(wrkMast.getWrkSts() == WrkStsType.LOC_MOVE_RUN.sts){
+                } else if (wrkMast.getWrkSts() == WrkStsType.LOC_MOVE_RUN.sts) {
                     updateWrkSts = WrkStsType.COMPLETE_LOC_MOVE.sts;
-                }else{
+                } else {
                     News.error("鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗗伐浣滅姸鎬佸紓甯搞�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
                     continue;
                 }
@@ -734,7 +796,7 @@
                     News.info("鍫嗗灈鏈轰换鍔$姸鎬佹洿鏂版垚鍔燂紝鍫嗗灈鏈哄彿={}锛屽伐浣滃彿={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
                 }
 
-                redisUtil.set(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo(), "lock",10);
+                redisUtil.set(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo(), "lock", 10);
             }
         }
     }

--
Gitblit v1.9.1