From 8280c9eee52dd9fa3501305dfd4d1cab1564a73b Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期六, 20 十二月 2025 15:01:20 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java |    6 -
 src/main/java/com/zy/common/config/MethodTimingAspect.java       |   46 +++++++++++
 src/main/java/com/zy/asrs/utils/Utils.java                       |    8 +-
 src/main/java/com/zy/core/utils/WmsOperateUtils.java             |    2 
 src/main/resources/application.yml                               |    6 +
 src/main/java/com/zy/core/plugin/FakeProcess.java                |  149 ++++++++++++++++++++++++++----------
 6 files changed, 166 insertions(+), 51 deletions(-)

diff --git a/src/main/java/com/zy/asrs/utils/Utils.java b/src/main/java/com/zy/asrs/utils/Utils.java
index 5d44238..1222a32 100644
--- a/src/main/java/com/zy/asrs/utils/Utils.java
+++ b/src/main/java/com/zy/asrs/utils/Utils.java
@@ -141,11 +141,11 @@
 
     //鑾峰彇鍏ュ簱浠诲姟鍙敤鎺�
     public static List<Integer> getInTaskEnableRow() {
-        return getInTaskEnableRow(new ArrayList<>());
+        return getInTaskEnableRow(new ArrayList<>(), true);
     }
 
     //鑾峰彇鍏ュ簱浠诲姟鍙敤鎺�
-    public static List<Integer> getInTaskEnableRow(List<Integer> excludeCrnList) {
+    public static List<Integer> getInTaskEnableRow(List<Integer> excludeCrnList, boolean maxInTaskControl) {
         List<Integer> list = new ArrayList<>();
         try {
             RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
@@ -202,7 +202,7 @@
                         .eq("io_type", WrkIoType.IN.id)
                 );
                 // 妫�鏌ユ槸鍚﹁秴杩囨渶澶у叆搴撲换鍔℃暟
-                if(inWrkMasts.size() >= basCrnp.getMaxInTask()){
+                if (maxInTaskControl && inWrkMasts.size() >= basCrnp.getMaxInTask()) {
                     News.info("鍫嗗灈鏈�:{} 宸茶揪鏈�澶у叆搴撲换鍔℃暟锛屽綋鍓嶄换鍔℃暟:{}", basCrnp.getCrnNo(), inWrkMasts.size());
                     continue;
                 }
@@ -220,7 +220,7 @@
                     list.addAll(rows);
                 }
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
         }
         return list;
diff --git a/src/main/java/com/zy/common/config/MethodTimingAspect.java b/src/main/java/com/zy/common/config/MethodTimingAspect.java
new file mode 100644
index 0000000..a0cbbf4
--- /dev/null
+++ b/src/main/java/com/zy/common/config/MethodTimingAspect.java
@@ -0,0 +1,46 @@
+package com.zy.common.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+@Component
+@Aspect
+@Slf4j
+@Order(Ordered.LOWEST_PRECEDENCE)
+@ConditionalOnProperty(prefix = "perf.methodTiming", name = "enabled", havingValue = "true")
+public class MethodTimingAspect {
+
+    @Value("${perf.methodTiming.thresholdMs:50}")
+    private long thresholdMs;
+
+    @Value("${perf.methodTiming.sampleRate:1.0}")
+    private double sampleRate;
+
+    @Around("execution(public * com.zy.core..*(..))")
+    public Object timeCorePublicMethods(ProceedingJoinPoint joinPoint) throws Throwable {
+        if (sampleRate < 1.0d && ThreadLocalRandom.current().nextDouble() > sampleRate) {
+            return joinPoint.proceed();
+        }
+
+        long startNs = System.nanoTime();
+        try {
+            return joinPoint.proceed();
+        } finally {
+            long costMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
+            if (costMs >= thresholdMs) {
+                log.warn("SLOW {} took {} ms (thread={})", joinPoint.getSignature().toShortString(), costMs, Thread.currentThread().getName());
+            }
+        }
+    }
+}
+
diff --git a/src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java b/src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java
index 55e1371..dbb8346 100644
--- a/src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java
+++ b/src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java
@@ -4,14 +4,12 @@
 import com.alibaba.fastjson.JSONObject;
 import com.core.common.SpringUtils;
 import com.zy.asrs.entity.DeviceConfig;
-import com.zy.asrs.service.BasDevpService;
 import com.zy.common.model.NavigateNode;
 import com.zy.common.utils.NavigateUtils;
 import com.zy.common.utils.RedisUtil;
 import com.zy.core.News;
 import com.zy.core.enums.RedisKeyType;
 import com.zy.core.model.CommandResponse;
-import com.zy.core.model.StationObjModel;
 import com.zy.core.model.command.StationCommand;
 import com.zy.core.network.api.ZyStationConnectApi;
 import com.zy.core.network.entity.ZyStationStatusEntity;
@@ -624,7 +622,7 @@
         return executeResult;
     }
 
-    public synchronized boolean lockExecute(Integer taskNo, Supplier<Boolean> function) {
+    public boolean lockExecute(Integer taskNo, Supplier<Boolean> function) {
         if (!setLockStation(taskNo)) {
             return false;
         }
@@ -634,7 +632,7 @@
         return result;
     }
 
-    private synchronized boolean checkTaskNoInArea(Integer taskNo) {
+    private boolean checkTaskNoInArea(Integer taskNo) {
         Object fakeTaskNoAreaObj = redisUtil.get(RedisKeyType.FAKE_TASK_NO_AREA.key);
         if (fakeTaskNoAreaObj == null) {
             return false;
diff --git a/src/main/java/com/zy/core/plugin/FakeProcess.java b/src/main/java/com/zy/core/plugin/FakeProcess.java
index 8e38861..f202acc 100644
--- a/src/main/java/com/zy/core/plugin/FakeProcess.java
+++ b/src/main/java/com/zy/core/plugin/FakeProcess.java
@@ -21,6 +21,7 @@
 import com.zy.core.model.command.StationCommand;
 import com.zy.core.model.protocol.CrnProtocol;
 import com.zy.core.model.protocol.StationProtocol;
+import com.zy.core.properties.SystemProperties;
 import com.zy.core.thread.CrnThread;
 import com.zy.core.thread.StationThread;
 import com.zy.core.utils.CrnOperateProcessUtils;
@@ -43,6 +44,9 @@
     private static String fakeRealTaskRequestWms = "N";
     private static String fakeGenerateInTask = "Y";
     private static String fakeGenerateOutTask = "Y";
+
+    private Thread asyncRunThread = null;
+    private Thread asyncFakeRunThread = null;
 
     @Autowired
     private WrkMastService wrkMastService;
@@ -67,41 +71,9 @@
 
     @Override
     public void run() {
-        Config enableFakeConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "enableFake"));
-        if (enableFakeConfig != null) {
-            enableFake = enableFakeConfig.getValue();
-        }
+        asyncRun();
+        asyncFakeRun();
 
-        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"));
-        if (fakeGenerateInTaskConfig != null) {
-            fakeGenerateInTask = fakeGenerateInTaskConfig.getValue();
-        }
-
-        Config fakeGenerateOutTaskConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateOutTask"));
-        if (fakeGenerateOutTaskConfig != null) {
-            fakeGenerateOutTask = fakeGenerateOutTaskConfig.getValue();
-        }
-
-        //妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
-        checkInStationHasTask();
-        //鐢熸垚浠跨湡妯℃嫙鍏ュ簱浠诲姟
-        generateFakeInTask();
-        //鐢熸垚浠跨湡妯℃嫙鍑哄簱浠诲姟
-        generateFakeOutTask();
-        //璁$畻鎵�鏈夌珯鐐瑰仠鐣欐椂闂�
-        calcAllStationStayTime();
-        //妫�娴嬪嚭搴撶珯鐐瑰仠鐣欐槸鍚﹁秴鏃�
-        checkOutStationStayTimeOut();
-        //妫�娴嬪叆搴撶珯鐐瑰爢鍨涙満鏄惁鍙栬蛋璐х墿
-        checkInStationCrnTake();
-
-        //璇锋眰鐢熸垚鍏ュ簱浠诲姟
-        generateStoreWrkFile();
         //鎵ц鍫嗗灈鏈轰换鍔�
         crnOperateUtils.crnIoExecute();
         //鍫嗗灈鏈轰换鍔℃墽琛屽畬鎴�-鍏峰浠跨湡鑳藉姏
@@ -112,8 +84,101 @@
         stationOperateProcessUtils.stationOutExecute();
         //妫�娴嬭緭閫佺珯鐐瑰嚭搴撲换鍔℃墽琛屽畬鎴�
         stationOperateProcessUtils.stationOutExecuteFinish();
-        //妫�娴嬭緭閫佺珯鐐规槸鍚﹁繍琛屽牭濉�
-        stationOperateProcessUtils.checkStationRunBlock();
+    }
+
+    public void asyncRun() {
+        if (asyncRunThread != null) {
+            return;
+        }
+
+        asyncRunThread = new Thread(() -> {
+            while (!Thread.currentThread().isInterrupted()) {
+                try {
+                    // 绯荤粺杩愯鐘舵�佸垽鏂�
+                    if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
+                        continue;
+                    }
+
+                    //璇锋眰鐢熸垚鍏ュ簱浠诲姟
+                    generateStoreWrkFile();
+
+                    // 闂撮殧
+                    Thread.sleep(50);
+                } catch (InterruptedException ie) {
+                    Thread.currentThread().interrupt();
+                    break;
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+        asyncRunThread.setName("asyncRunProcess");
+        asyncRunThread.setDaemon(true);
+        asyncRunThread.start();
+    }
+
+    public void asyncFakeRun() {
+        if (asyncFakeRunThread != null) {
+            return;
+        }
+
+        asyncFakeRunThread = new Thread(() -> {
+            while (!Thread.currentThread().isInterrupted()) {
+                try {
+                    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"));
+                    if (fakeRealTaskRequestWmsConfig != null) {
+                        fakeRealTaskRequestWms = fakeRealTaskRequestWmsConfig.getValue();
+                    }
+
+                    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"));
+                    if (fakeGenerateOutTaskConfig != null) {
+                        fakeGenerateOutTask = fakeGenerateOutTaskConfig.getValue();
+                    }
+
+                    // 绯荤粺杩愯鐘舵�佸垽鏂�
+                    if (!SystemProperties.WCS_RUNNING_STATUS.get()) {
+                        continue;
+                    }
+
+                    //妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
+                    checkInStationHasTask();
+                    //鐢熸垚浠跨湡妯℃嫙鍏ュ簱浠诲姟
+                    generateFakeInTask();
+                    //鐢熸垚浠跨湡妯℃嫙鍑哄簱浠诲姟
+                    generateFakeOutTask();
+                    //璁$畻鎵�鏈夌珯鐐瑰仠鐣欐椂闂�
+                    calcAllStationStayTime();
+                    //妫�娴嬪嚭搴撶珯鐐瑰仠鐣欐槸鍚﹁秴鏃�
+                    checkOutStationStayTimeOut();
+                    //妫�娴嬪叆搴撶珯鐐瑰爢鍨涙満鏄惁鍙栬蛋璐х墿
+                    checkInStationCrnTake();
+
+                    //妫�娴嬭緭閫佺珯鐐规槸鍚﹁繍琛屽牭濉�
+                    stationOperateProcessUtils.checkStationRunBlock();
+
+                    // 闂撮殧
+                    Thread.sleep(50);
+                } catch (InterruptedException ie) {
+                    Thread.currentThread().interrupt();
+                    break;
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+        asyncFakeRunThread.setName("asyncFakeRunProcess");
+        asyncFakeRunThread.setDaemon(true);
+        asyncFakeRunThread.start();
     }
 
     //妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
@@ -202,7 +267,7 @@
 
                 Object object = redisUtil.get(RedisKeyType.GENERATE_FAKE_IN_TASK_LIMIT.key + stationId);
                 if (object != null) {
-                    return;
+                    continue;
                 }
 
                 //婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
@@ -375,7 +440,7 @@
                     if (lock != null) {
                         continue;
                     }
-                    redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 5);
+                    redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
 
                     String response = wmsOperateUtils.applyInTask(stationProtocol.getBarcode(), stationProtocol.getStationId(), stationProtocol.getPalletHeight());
                     if (response == null) {
@@ -461,7 +526,7 @@
 
                     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));
+                    News.info("杈撻�佺珯鐐瑰嚭搴撻噸缃懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
                 }
             }
         }
@@ -504,7 +569,7 @@
                     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("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
+                        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();
@@ -513,13 +578,13 @@
                                 continue;
                             }
                             CrnProtocol crnProtocol = crnThread.getStatus();
-                            if (crnProtocol.getStatusType().equals(CrnStatusType.FETCH_MOVING) || crnProtocol.getStatusType().equals(CrnStatusType.FETCHING)) {
+                            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("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
+                            News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(crn_fetch)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
                         }
                     }
                 }
diff --git a/src/main/java/com/zy/core/utils/WmsOperateUtils.java b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
index 78e193b..07da8b9 100644
--- a/src/main/java/com/zy/core/utils/WmsOperateUtils.java
+++ b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
@@ -127,7 +127,7 @@
         String response = null;
         try {
             requestParam.put("taskNo", wrkMast.getWmsWrkNo());
-            requestParam.put("row", Utils.getInTaskEnableRow(new ArrayList<>(wrkMast.getCrnNo())));
+            requestParam.put("row", Utils.getInTaskEnableRow(new ArrayList<>(wrkMast.getCrnNo()), false));
 
             response = new HttpHandler.Builder()
                     .setUri(wmsUrl)
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 7f8fe23..41d4c4c 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -87,3 +87,9 @@
 #  base-url: http://34.2.134.223:3000/v1
 #  api-key: sk-WabrmtOezCFwVo7XvVOrO3QkmfcKG7T7jy0BaVnmQTWm5GXh
 #  model: gemini-3-pro-preview
+
+perf:
+  methodTiming:
+    enabled: false
+    thresholdMs: 50
+    sampleRate: 1.0
\ No newline at end of file

--
Gitblit v1.9.1