From ab886689e2c4ef8db2b0767717d69ebbaf10326c Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 29 十一月 2024 16:37:20 +0800
Subject: [PATCH] #

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java |   77 ++++++++++++++++++--------------------
 1 files changed, 36 insertions(+), 41 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
index 7329135..3b6ad34 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -22,7 +22,6 @@
 import com.zy.acs.manager.common.domain.TaskDto;
 import com.zy.acs.manager.common.domain.param.HandlerPublishParam;
 import com.zy.acs.manager.common.exception.BusinessException;
-import com.zy.acs.manager.common.utils.CommonUtil;
 import com.zy.acs.manager.core.domain.AgvBackpackDto;
 import com.zy.acs.manager.core.domain.Lane;
 import com.zy.acs.manager.core.domain.TaskPosDto;
@@ -221,7 +220,7 @@
             for (Task task : taskList) {
                 Agv agv = allocateService.execute(task);
                 if (null == agv) {
-                    log.warn("Task[{}] has an issue锛� because it failed to checkout agv which is idle...", task.getSeqNum());
+//                    log.warn("Task[{}] has an issue锛� because it failed to checkout agv which is idle...", task.getSeqNum());
                     continue;
                 }
                 task.setAgvId(agv.getId());
@@ -249,7 +248,8 @@
             // valid -----------------------------------------------
             Agv agv = agvService.getById(agvId);
             if (!agvService.judgeEnable(agv.getId(), true)) {
-                throw new CoolException("AGV[" + agv.getUuid() + "]褰撳墠涓嶅彲鐢�...");
+                return;
+//                throw new CoolException("AGV[" + agv.getUuid() + "]褰撳墠涓嶅彲鐢�...");
             }
             if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) {
                 throw new CoolException("AGV[" + agv.getUuid() + "]鍒嗛厤浠诲姟澶辫触锛屽凡瀛樺湪鎵ц浠诲姟...");
@@ -350,13 +350,19 @@
             /**
              * 1.Map<String, List<TaskPosDto>> groups
              *
-             * key: 1000 + ORI_LOC
+             * key: 1000 + ORIGIN
              * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...]
              *
-             * key: 3000 + ORI_LOC
+             * key: 3000 + ORIGIN
              * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...]
              *
-             * key: 2000 + ORI_LOC
+             * key: 2000 + ORIGIN
+             * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...]
+             *
+             * key: 1000 + DESTINATION
+             * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...]
+             *
+             * key: 2000 + DESTINATION
              * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...]
              *
              * ......
@@ -374,6 +380,8 @@
              * 瀵规墍鏈夊贩閬撹繘琛屾湁搴忔帓搴忥紝鍏堟槸閽堝List涓轰竴涓崟浣嶏紝瀵逛粬浠繘琛孎irstWeight鎺掑簭锛岀浉褰撲簬琛�1鐨刱ey鐨勬暟鍊艰繘琛屾湁搴忔帓搴�
              *  List<TaskPosDto>: task list on the same lane
              *  ArrayList<List<TaskPosDto>>: all the task list by one agv
+             *
+             *  tip: ORI 鍜� DEST 姘歌繙涓嶄細瀛樺湪鍚屼竴涓� List
              */
             ArrayList<List<TaskPosDto>> list = new ArrayList<>(groups.values());
             list.sort((o1, o2) -> {
@@ -390,46 +398,33 @@
             Code currCode = codeService.getById(agvDetail.getRecentCode());
             Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()};
 
-            List<TaskPosDto> theFirstOne = list.get(0);
-            List<TaskPosDto> theLastOne = list.get(list.size() - 1);
+            List<List<TaskPosDto>> pickGroups = new ArrayList<>();
+            List<List<TaskPosDto>> dropGroups = new ArrayList<>();
 
-            if (list.size() == 1) {
-                TaskPosDto head = theFirstOne.get(0);
-                TaskPosDto tail = theFirstOne.get(theFirstOne.size() - 1);
-
-                int distanceByHead = CommonUtil.calcDistance(currPosition, head.getXy());
-                int distanceByTail = CommonUtil.calcDistance(currPosition, tail.getXy());
-
-                if (distanceByTail < distanceByHead) {
-                    Collections.reverse(theFirstOne);
-                }
-
-            } else {
-                TaskPosDto headOfFirst = theFirstOne.get(0);
-                TaskPosDto tailOfFirst = theFirstOne.get(theFirstOne.size() - 1);
-
-                TaskPosDto headOfLast = theLastOne.get(0);
-                TaskPosDto tailOfLast = theLastOne.get(theLastOne.size() - 1);
-
-                int distanceByHeadOfFirst = CommonUtil.calcDistance(currPosition, headOfFirst.getXy());
-                int distanceByTailOfFirst = CommonUtil.calcDistance(currPosition, tailOfFirst.getXy());
-
-                int distanceByHeadOfLast = CommonUtil.calcDistance(currPosition, headOfLast.getXy());
-                int distanceByTailOfLast = CommonUtil.calcDistance(currPosition, tailOfLast.getXy());
-
-                if (Math.min(distanceByHeadOfLast, distanceByTailOfLast) < Math.min(distanceByHeadOfFirst, distanceByTailOfFirst)) {
-                    Collections.reverse(list);
-
-                    if (distanceByTailOfLast < distanceByHeadOfLast) {
-                        Collections.reverse(theLastOne);
-                    }
+            for (List<TaskPosDto> group : list) {
+                // Assume 涓�涓换鍔$粍涓墍鏈塗askPosDto鐨凱osType.brief鐩稿悓
+                TaskPosDto.PosType posType = group.get(0).getPosType();
+                if (posType == TaskPosDto.PosType.ORI_LOC || posType == TaskPosDto.PosType.ORI_STA) {
+                    pickGroups.add(group);
+                } else if (posType == TaskPosDto.PosType.DEST_LOC || posType == TaskPosDto.PosType.DEST_STA) {
+                    dropGroups.add(group);
                 } else {
-                    if (distanceByTailOfFirst < distanceByHeadOfFirst) {
-                        Collections.reverse(theFirstOne);
-                    }
+                    // import tip: the list must only contain ORIGIN and DESTINATION
+                    log.error("the list must only contain ORIGIN and DESTINATION");
                 }
             }
 
+            currPosition = allocateService.pac(currPosition, pickGroups);
+            currPosition = allocateService.pac(currPosition, dropGroups);
+
+            List<List<TaskPosDto>> reorderedList = new ArrayList<>();
+            reorderedList.addAll(pickGroups);
+            reorderedList.addAll(dropGroups);
+
+            list.clear();
+            list.addAll(reorderedList);
+
+
             // generate travel
             Travel travel = new Travel();
             travel.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));

--
Gitblit v1.9.1