From ebd2f4397a92c6a5096de1b86d59154363344720 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期二, 13 五月 2025 08:48:15 +0800
Subject: [PATCH] #

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java |   61 +++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java
index e9307d8..b5c2bf0 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java
@@ -5,6 +5,7 @@
 import com.zy.acs.common.enums.AgvStatusType;
 import com.zy.acs.framework.common.Cools;
 import com.zy.acs.manager.common.utils.CommonUtil;
+import com.zy.acs.manager.core.constant.AgvAreaDispatcher;
 import com.zy.acs.manager.manager.entity.*;
 import com.zy.acs.manager.manager.enums.FuncStaType;
 import com.zy.acs.manager.manager.enums.StatusType;
@@ -31,6 +32,8 @@
     private AgvModelService agvModelService;
     @Autowired
     private TaskService taskService;
+    @Autowired
+    private AgvAreaDispatcher agvAreaDispatcher;
 
     @Override
     public FuncSta getByCodeAndType(Long codeId, String type) {
@@ -60,7 +63,22 @@
             return new ArrayList<>();
         }
 
-        Collections.shuffle(funcStaList);
+        // area limit
+        List<String> areaCodeList = agvAreaDispatcher.getAreaCodeListByAgvNo(agvService.getAgvNo(agvId));
+        if (Cools.isEmpty(areaCodeList)) {
+            funcStaList.clear();
+        } else {
+            funcStaList.removeIf(funcSta -> {
+                Code code = codeService.getCacheById(funcSta.getCode());
+                if (Cools.isEmpty(code, code.getData())) { return true; }
+                return !areaCodeList.contains(code.getData());
+            });
+        }
+
+        if (!Cools.isEmpty(funcStaList)) {
+            Collections.shuffle(funcStaList);
+        }
+
         // filter idle
         funcStaList = funcStaList.stream().filter(funcSta -> {
 
@@ -74,7 +92,7 @@
             if (funcSta.getType().equals(FuncStaType.CHARGE.toString())) {
                 // if the type of this funSta is charge and the existing agv is in charge status, then that means this funSta is occupied
                 if (null != agv && !agv.getId().equals(agvId)) {
-                    AgvModel agvModel = agvModelService.getById(agv.getAgvModel());
+                    AgvModel agvModel = agvModelService.getByAgvId(agv.getId());
                     AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
                     if (agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) {
                         if (agvDetail.getVol() < agvModel.getQuaBattery()) {
@@ -146,7 +164,7 @@
         }
 
         if (null != codeId) {
-            Code currCode = codeService.getById(codeId);
+            Code currCode = codeService.getCacheById(codeId);
             Double[] startPos = new Double[]{currCode.getX(), currCode.getY()};
 
             // checkout one funSta which is the closest
@@ -155,13 +173,44 @@
             funcStaList.sort(new Comparator<FuncSta>() {
                 @Override
                 public int compare(FuncSta o1, FuncSta o2) {
-                    Code o1Code = codeService.getById(o1.getCode());
+                    Code o1Code = codeService.getCacheById(o1.getCode());
                     int o1Distance = CommonUtil.calcDistance(startPos, new Double[]{o1Code.getX(), o1Code.getY()});
 
-                    Code o2Code = codeService.getById(o2.getCode());
+                    Code o2Code = codeService.getCacheById(o2.getCode());
                     int o2Distance = CommonUtil.calcDistance(startPos, new Double[]{o2Code.getX(), o2Code.getY()});
 
                     return o1Distance - o2Distance;
+                }
+            });
+
+        }
+
+        return funcStaList.stream().findFirst().orElse(null);
+    }
+
+    @Override
+    public FuncSta checkoutFurthestFunSta(Long codeId, List<FuncSta> funcStaList) {
+        if (Cools.isEmpty(funcStaList)) {
+            return null;
+        }
+
+        if (null != codeId) {
+            Code currCode = codeService.getCacheById(codeId);
+            Double[] startPos = new Double[]{currCode.getX(), currCode.getY()};
+
+            // checkout one funSta which is the closest
+
+            // compare => compare杩斿洖璐熸暟锛屽垯鎺掑湪闆嗗悎鍓嶉潰 锛坅sc锛�
+            funcStaList.sort(new Comparator<FuncSta>() {
+                @Override
+                public int compare(FuncSta o1, FuncSta o2) {
+                    Code o1Code = codeService.getCacheById(o1.getCode());
+                    int o1Distance = CommonUtil.calcDistance(startPos, new Double[]{o1Code.getX(), o1Code.getY()});
+
+                    Code o2Code = codeService.getCacheById(o2.getCode());
+                    int o2Distance = CommonUtil.calcDistance(startPos, new Double[]{o2Code.getX(), o2Code.getY()});
+
+                    return o2Distance - o1Distance;
                 }
             });
 
@@ -189,7 +238,7 @@
 
                 agv = agvService.findByPosition(funcSta.getCode());
                 if (null != agv) {
-                    AgvModel agvModel = agvModelService.getById(agv.getAgvModel());
+                    AgvModel agvModel = agvModelService.getByAgvId(agv.getId());
                     AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
                     if (agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) {
                         return false;

--
Gitblit v1.9.1