From e286f7e2b9e80162e132311fb02402d8a3a951f4 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期一, 13 一月 2025 14:22:58 +0800
Subject: [PATCH] #

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/PatrolService.java |   81 +++++++++++++++++++---------------------
 1 files changed, 39 insertions(+), 42 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/PatrolService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/PatrolService.java
index 07399a5..b0497c5 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/PatrolService.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/PatrolService.java
@@ -2,6 +2,7 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.acs.common.utils.RedisSupport;
+import com.zy.acs.framework.common.Cools;
 import com.zy.acs.framework.common.R;
 import com.zy.acs.manager.manager.entity.*;
 import com.zy.acs.manager.manager.enums.StatusType;
@@ -16,11 +17,9 @@
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.*;
+import java.util.stream.Collectors;
 
 /**
  * Created by vincent on 11/9/2024
@@ -36,6 +35,8 @@
     private final RedisSupport redis = RedisSupport.defaultRedisSupport;
 
     private ScheduledExecutorService scheduler = null;
+
+    private List<String> CODE_DATA_CACHE = new ArrayList<>();
 
     @Autowired
     private AgvService agvService;
@@ -67,21 +68,15 @@
                 .eq(Travel::getState, TravelStateType.RUNNING.toString()))) {
             return;
         }
-//        if (taskService.count(new LambdaQueryWrapper<Task>()
-//                .eq(Task::getAgvId, agvId)
-//                .in(Task::getTaskSts, TaskStsType.ASSIGN.val(), TaskStsType.PROGRESS.val())
-//                ) > 0) {
-//            return;
-//        }
         if (!agvService.judgeEnable(agvId)) {
             return;
         }
         AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId);
-        Code destinationCode = this.getDestinationCode(agvNo, agvDetail);
-        if (null == destinationCode) {
+        String destinationCodeData = this.getDestinationCode(agvNo, agvDetail);
+        if (Cools.isEmpty(destinationCodeData)) {
             return;
         }
-        if (mainLockWrapService.buildMinorTask(agvId, TaskTypeType.MOVE, destinationCode.getData(), null)) {
+        if (mainLockWrapService.buildMinorTask(agvId, TaskTypeType.MOVE, destinationCodeData, null)) {
             log.info(agvNo + "寮�濮嬭蛋琛屾紨绀�...");
         }
     }
@@ -89,43 +84,44 @@
     /**
      * 4涓湴鏂硅皟鐢ㄤ簡buildMinorTask锛屽湪浠�涔堟椂鍊欍�佸摢閲岃缃畉ask鐨刲ane
      * (
-         * HandlerController, 鎵嬪姩  锛堟墜鍔ㄦ槸鍚﹂渶瑕佸垽鏂璴ane锛�
-         * MaintainScheduler, 鑷姩  锛堜竴鑸笉闇�瑕佽�冭檻 lane锛�
-         * PatrolService,     鑷姩  锛堥渶瑕侀澶勭悊 lane锛� 鉁�
-         * TrafficService,    鑷姩  锛堝鍧�鏃跺凡缁忓鐞嗚繃 lane锛� 鉁�
+     * HandlerController, 鎵嬪姩  锛堟墜鍔ㄦ槸鍚﹂渶瑕佸垽鏂璴ane锛�
+     * MaintainScheduler, 鑷姩  锛堜竴鑸笉闇�瑕佽�冭檻 lane锛�
+     * PatrolService,     鑷姩  锛堥渶瑕侀澶勭悊 lane锛� 鉁�
+     * TrafficService,    鑷姩  锛堝鍧�鏃跺凡缁忓鐞嗚繃 lane锛� 鉁�
      * )
      * 璇勪及HandlerController娌℃湁璋冪敤buildMajorTask锛屾墜鍔ㄥ垱寤簍ask鐨勫彲琛屾��
      * agv鍦板浘鍥炬爣鍙樺寲
      */
-    public Code getDestinationCode(String agvNo, AgvDetail agvDetail) {
-        Integer maxAgvCountInLane = configService.getVal("maxAgvCountInLane", Integer.class);
+    public String getDestinationCode(String agvNo, AgvDetail agvDetail) {
 
         Code startCode = codeService.getCacheById(agvDetail.getRecentCode());
 
-        List<String> notInCodeList = new ArrayList<>();
-        notInCodeList.add("00000301");
-        notInCodeList.add("00000302");
-        notInCodeList.add("00000303");
-        notInCodeList.add("00000351");
-        notInCodeList.add("00000353");
-        notInCodeList.add("00000401");
-        notInCodeList.add("00000402");
+        Set<String> notInCodeSet = new HashSet<>();
+        notInCodeSet.add("00000301");
+        notInCodeSet.add("00000302");
+        notInCodeSet.add("00000303");
+        notInCodeSet.add("00000351");
+        notInCodeSet.add("00000353");
+        notInCodeSet.add("00000401");
+        notInCodeSet.add("00000402");
 
-        notInCodeList.add("00000311");
-        notInCodeList.add("00000312");
-        notInCodeList.add("00000313");
-        notInCodeList.add("00000361");
-        notInCodeList.add("00000363");
-        notInCodeList.add("00000411");
-        notInCodeList.add("00000412");
+        notInCodeSet.add("00000311");
+        notInCodeSet.add("00000312");
+        notInCodeSet.add("00000313");
+        notInCodeSet.add("00000361");
+        notInCodeSet.add("00000363");
+        notInCodeSet.add("00000411");
+        notInCodeSet.add("00000412");
 
-        notInCodeList.add("00000046");
-        notInCodeList.add("00000047");
-        List<Code> list = codeService.list(new LambdaQueryWrapper<Code>().notIn(Code::getData, notInCodeList));
+        notInCodeSet.add("00000046");
+        notInCodeSet.add("00000047");
 
-        Collections.shuffle(list);
+        Collections.shuffle(CODE_DATA_CACHE);
 
-        for (Code endCode : list) {
+        for (String endCodeData : CODE_DATA_CACHE) {
+            if (notInCodeSet.contains(endCodeData)) { continue; }
+            Code endCode = codeService.getCacheByData(endCodeData);
+
             // valid lane
             if (!allocateService.validCapacityOfLane(agvNo, endCode)) {
                 continue;
@@ -134,13 +130,12 @@
             // valid path length
             List<String> pathList = mapService.validFeasibility(startCode, endCode);
             if (pathList.size() >= 5) {
-                return endCode;
+                return endCodeData;
             }
         }
 
-        return list.stream().findFirst().orElse(null);
+        return CODE_DATA_CACHE.stream().findFirst().orElse(null);
     }
-
 
     // ---------------------------------------------------------------------------
 
@@ -197,6 +192,8 @@
         if (count > 0) {
             this.scheduler = Executors.newScheduledThreadPool(count);
         }
+        List<Code> codeList = codeService.list(new LambdaQueryWrapper<Code>().eq(Code::getStatus, StatusType.ENABLE.val));
+        this.CODE_DATA_CACHE = codeList.stream().map(Code::getData).distinct().collect(Collectors.toList());
     }
 
     @PreDestroy

--
Gitblit v1.9.1