From 38e67bc036cbd9625bebd923c6754622c65f39fc Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@gmail.com>
Date: 星期二, 18 三月 2025 10:46:25 +0800
Subject: [PATCH] #

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java |  100 ++++++++++++++++++++++++++++++++------------------
 1 files changed, 64 insertions(+), 36 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 8a1f948..efc79ab 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
@@ -250,7 +250,7 @@
         try {
             // valid -----------------------------------------------
             Agv agv = agvService.getById(agvId);
-            if (!agvService.judgeEnable(agv.getId(), true)) {
+            if (!agvService.judgeEnable(agv.getId(), false)) {
                 return;
             }
             if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) {
@@ -301,8 +301,8 @@
                         oriLoc = locService.getById(task.getOriLoc());
                         destLoc = locService.getById(task.getDestLoc());
 
-                        startCode = codeService.getById(oriLoc.getCode());
-                        endCode = codeService.getById(destLoc.getCode());
+                        startCode = codeService.getCacheById(oriLoc.getCode());
+                        endCode = codeService.getCacheById(destLoc.getCode());
 
                         TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_LOC, sameGroupXy);
                         TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_LOC, sameGroupXy);
@@ -311,8 +311,8 @@
                         oriLoc = locService.getById(task.getOriLoc());
                         destSta = staService.getById(task.getDestSta());
 
-                        startCode = codeService.getById(oriLoc.getCode());
-                        endCode = codeService.getById(destSta.getCode());
+                        startCode = codeService.getCacheById(oriLoc.getCode());
+                        endCode = codeService.getCacheById(destSta.getCode());
 
                         TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_LOC, sameGroupXy);
                         TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_STA, sameGroupXy);
@@ -321,8 +321,8 @@
                         oriSta = staService.getById(task.getOriSta());
                         destLoc = locService.getById(task.getDestLoc());
 
-                        startCode = codeService.getById(oriSta.getCode());
-                        endCode = codeService.getById(destLoc.getCode());
+                        startCode = codeService.getCacheById(oriSta.getCode());
+                        endCode = codeService.getCacheById(destLoc.getCode());
 
                         TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_STA, sameGroupXy);
                         TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_LOC, sameGroupXy);
@@ -331,8 +331,8 @@
                         oriSta = staService.getById(task.getOriSta());
                         destSta = staService.getById(task.getDestSta());
 
-                        startCode = codeService.getById(oriSta.getCode());
-                        endCode = codeService.getById(destSta.getCode());
+                        startCode = codeService.getCacheById(oriSta.getCode());
+                        endCode = codeService.getCacheById(destSta.getCode());
 
                         TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_STA, sameGroupXy);
                         TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_STA, sameGroupXy);
@@ -397,7 +397,7 @@
             }
 
             // re-order by agv current position
-            Code currCode = codeService.getById(agvDetail.getRecentCode());
+            Code currCode = codeService.getCacheById(agvDetail.getRecentCode());
             Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()};
 
             List<List<TaskPosDto>> pickGroups = new ArrayList<>();
@@ -497,7 +497,6 @@
         if (Cools.isEmpty(agvId, taskType)) { return false; }
         try {
             String agvNo = agvService.getAgvNo(agvId);
-            AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId);
             if (!agvService.judgeEnable(agvId)) {
                 return false;
             }
@@ -510,6 +509,7 @@
             }
 
             Date now = new Date();
+            AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId);
             Code endCode = null;
             switch (taskType) {
                 case TO_CHARGE:
@@ -517,7 +517,7 @@
                     List<FuncSta> idleFunStaList = funcStaService.findInIdleStatus(FuncStaType.query(taskType), agvId);
                     if (!Cools.isEmpty(idleFunStaList)) {
                         FuncSta funcSta = funcStaService.checkoutClosestFunSta(agvDetail.getRecentCode(), idleFunStaList);
-                        endCode = codeService.getById(funcSta.getCode());
+                        endCode = codeService.getCacheById(funcSta.getCode());
                     }
                     if (null == endCode) {
                         log.warn("AGV[{}] failed to search destination锛宼here hadn't any idle funSta锛孴askTypeType锛歿}", agvNo, taskType.toString());
@@ -653,9 +653,9 @@
 //            JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class);
             int angleOffsetVal = configService.getVal("mapAngleOffsetVal", Integer.class);
             String agvNo = agvService.getAgvNo(agvId);
-            if (!agvService.judgeEnable(agvId)) {
-                throw new CoolException("AGV[" + agvNo + "]褰撳墠涓嶅彲鐢�...");
-            }
+//            if (!agvService.judgeEnable(agvId)) {
+//                throw new CoolException("AGV[" + agvNo + "]褰撳墠涓嶅彲鐢�...");
+//            }
 
             AgvModel agvModel = agvModelService.getByAgvId(agvId);
             Double workDirection = agvModel.getWorkDirection();
@@ -666,7 +666,7 @@
 
             List<Action> actionList = new ArrayList<>();
             // start node
-            Code lastCode = codeService.getById(agvDetail.getRecentCode());
+            Code lastCode = codeService.getCacheById(agvDetail.getRecentCode());
             Double lastDirection = agvDetail.getAgvAngle();
             if (!lastCode.getData().equals(pathList.get(0))) {
                 throw new CoolException("AGV[" + agvNo + "]瀹氫綅鍋忕Щ...");
@@ -679,7 +679,7 @@
                 Task task = taskService.getById(segment.getTaskId());
 
                 // 鑺傜偣鏉$爜
-                Code code = codeService.getById(segment.getEndNode());
+                Code code = codeService.getCacheById(segment.getEndNode());
 
                 // 闇�瑕佽蛋琛�
                 if (!lastCode.getData().equals(code.getData())) {
@@ -696,12 +696,48 @@
                         Code nextCode = codeService.getCacheByData(next);
                         Double nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal);
 
+                        // 濡傛灉鍘讳笅涓妭鐐圭殑鏂瑰悜涓庡綋鍓嶆柟鍚戝樊180搴︼紝鍒欎笉闇�瑕佹棆杞紝鏀逛负鍙嶆柟鍚戣璧帮紝nextDirection缁х画璧嬪�兼槸涓轰簡閬垮厤 鈥樼涓�涓姩浣滀竴瀹氭槸 turn鈥� 鐨勫垽鏂�
                         boolean reverse = false;
                         if (nextDirection.equals((workDirection + 180) % 360)) {
                             nextDirection = workDirection;
                             reverse = true;
                         }
-                        if (!lastDirection.equals(nextDirection) || actionList.isEmpty()) {
+
+                        if (!lastCode.getCornerBool()) {
+                            if (nextDirection.equals((lastDirection + 180) % 360)) {
+                                nextDirection = lastDirection;
+                                reverse = true;
+                            }
+                        } else {
+                            if (!lastDirection.equals(nextDirection)) {
+                                if (lastDirection.equals((nextDirection + 180) % 360)) {
+                                    nextDirection = lastDirection;
+                                    reverse = true;
+                                } else {
+                                    // turn
+                                    actionList.add(new Action(
+                                            null,    // 缂栧彿
+                                            task.getBusId(),    // 鎬荤嚎
+                                            task.getId(),    // 浠诲姟
+                                            null,    // 鍔ㄤ綔鍙�
+                                            null,    // 浼樺厛绾�
+                                            ActionTypeType.TurnCorner.desc,    // 鍚嶇О
+                                            mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 灞炴�у��
+                                            lastCode.getData(),    // 鍦伴潰鐮�
+                                            String.valueOf(nextDirection),   // 鍔ㄤ綔鍙傛暟
+                                            ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
+                                            actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                            agvId,    // AGV
+                                            now    // 宸ヤ綔鏃堕棿
+                                    ));
+
+                                    lastDirection = nextDirection;
+                                }
+                            }
+                        }
+
+                        // 绗竴涓姩浣滀竴瀹氭槸 turn
+                        if (actionList.isEmpty()) {
                             // turn
                             actionList.add(new Action(
                                     null,    // 缂栧彿
@@ -720,7 +756,6 @@
                             ));
 
                             lastDirection = nextDirection;
-
                         }
 
                         // run
@@ -989,26 +1024,19 @@
                     now    // 宸ヤ綔鏃堕棿
             ));
 
-//            List<Action> newActionList = new ArrayList<>(actionList);
-
-//            List<Action> optimizeList = actionService.optimizeSort(actionList);
-
-            List<Action> optimizeList = actionSorter.optimizeSort(actionList);
-            List<Action> newActionList = new ArrayList<>(optimizeList);
-
-
+            List<Action> newActionList = actionSorter.optimizeSort(actionList);
             String groupId = String.valueOf(snowflakeIdWorker.nextId()).substring(3);
 
             // save action
             int i = newActionList.size();
             for (Action action : newActionList) {
-                action.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
+//                action.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
                 action.setGroupId(groupId);
                 action.setPriority(i);
-                if (!actionService.save(action)) {
-                    throw new BusinessException(action.getName() + "鍔ㄤ綔淇濆瓨澶辫触");
-                }
                 i -= 1;
+            }
+            if (!actionService.saveBatch(newActionList)) {
+                throw new BusinessException("group[" + groupId + "] 鍔ㄤ綔淇濆瓨澶辫触");
             }
 
             // update segment
@@ -1057,9 +1085,9 @@
                 action.setStartTime(now);
                 action.setIoTime(now);
                 action.setUpdateTime(now);
-                if (!actionService.updateById(action)) {
-                    throw new BusinessException(action.getPriority() + " - " + action.getName() + "鍔ㄤ綔鏇存柊澶辫触");
-                }
+            }
+            if (!actionService.updateBatchById(actionList)) {
+                throw new BusinessException("failed to update action batch !!!");
             }
 
             // task
@@ -1077,8 +1105,8 @@
                 }
             }
 
-            Agv agv = agvService.getById(actionList.get(0).getAgvId());
-            AgvAction agvAction = new AgvAction(agv.getUuid(), actionGroupId);
+            String agvNo = agvService.getAgvNo(actionList.get(0).getAgvId());
+            AgvAction agvAction = new AgvAction(agvNo, actionGroupId);
             for (Action action : actionList) {
 
                 switch (Objects.requireNonNull(ActionTypeType.get(action.getActionTypeEl()))) {

--
Gitblit v1.9.1