From 14b2ffb34b85c725a379dd6e763e8b1028ce9db3 Mon Sep 17 00:00:00 2001
From: zc <zyzc>
Date: 星期六, 18 十月 2025 18:38:05 +0800
Subject: [PATCH] 希日AGV修改

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java |  208 +++++++++++++++++++++++++++++++--------------------
 1 files changed, 127 insertions(+), 81 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 1ea8950..753675a 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
@@ -789,7 +789,11 @@
                         boolean reverse = false;
                         if (nextDirection.equals((workDirection + 180) % 360)) {
                             nextDirection = workDirection;
-                            reverse = true;
+                            if (Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType())).equals(TaskPosDto.PosType.ORI_STA)) {
+                                reverse = false;
+                            } else {
+                                reverse = true;
+                            }
                         }
 
                         // 绗簩姝ワ細鍒ゆ柇褰撳墠鑺傜偣鏄惁鍙互鏃嬭浆
@@ -810,22 +814,42 @@
                                     nextDirection = lastDirection;
                                     reverse = true;
                                 } else {
-                                    // turn
-                                    actionList.add(new Action(
-                                            null,    // 缂栧彿s
-                                            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    // 宸ヤ綔鏃堕棿
-                                    ));
+                                    if (Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType()))
+                                            .equals(TaskPosDto.PosType.ORI_STA)) {
+                                        // turn
+                                        actionList.add(new Action(
+                                                null,    // 缂栧彿s
+                                                task.getBusId(),    // 鎬荤嚎
+                                                task.getId(),    // 浠诲姟
+                                                null,    // 鍔ㄤ綔鍙�
+                                                null,    // 浼樺厛绾�
+                                                ActionTypeType.TurnCorner.desc,    // 鍚嶇О
+                                                mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 灞炴�у��
+                                                lastCode.getData(),    // 鍦伴潰鐮�
+                                                String.valueOf(180),   // 鍔ㄤ綔鍙傛暟
+                                                ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
+                                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                                agvId,    // AGV
+                                                now    // 宸ヤ綔鏃堕棿
+                                        ));
+                                    } else {
+                                        // turn
+                                        actionList.add(new Action(
+                                                null,    // 缂栧彿s
+                                                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;
                                 }
@@ -1003,28 +1027,28 @@
                         Sta oriSta = staService.getById(task.getOriSta());
                         Double oriStaWorkDirection = mapService.getStaAngle(oriSta, workDirection);
                         // 妫�楠屾柟鍚�
-                        if (!lastDirection.equals(oriStaWorkDirection)) {
-                            if (!lastCode.getCornerBool()) {
-                                throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣");
-                            }
-                            // 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(oriStaWorkDirection),   // 鍔ㄤ綔鍙傛暟
-                                    ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
-                                    actionPrepareSts,    // 鍔ㄤ綔杩涘害
-                                    agvId,    // AGV
-                                    now    // 宸ヤ綔鏃堕棿
-                            ));
-                            lastDirection = oriStaWorkDirection;
-                        }
+//                        if (!lastDirection.equals(oriStaWorkDirection)) {
+//                            if (!lastCode.getCornerBool()) {
+//                                throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣");
+//                            }
+//                            // 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(oriStaWorkDirection),   // 鍔ㄤ綔鍙傛暟
+//                                    ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
+//                                    actionPrepareSts,    // 鍔ㄤ綔杩涘害
+//                                    agvId,    // AGV
+//                                    now    // 宸ヤ綔鏃堕棿
+//                            ));
+//                            lastDirection = oriStaWorkDirection;
+//                        }
                         // 璁$畻璐у弶宸ヤ綔鏂瑰悜
                         staWorkDirection = mapService.calculateAgvWorkDirectionByStation(oriStaWorkDirection, lastDirection);
                         actionList.add(new Action(
@@ -1033,11 +1057,11 @@
                                 task.getId(),    // 浠诲姟
                                 null,    // 鍔ㄤ綔鍙�
                                 null,    // 浼樺厛绾�
-                                ActionTypeType.ReadyTakeFromConveyorSta.desc,    // 鍚嶇О
-                                staWorkDirection,    // 灞炴�у��
+                                ActionTypeType.ReadyTakeFromShelvesLoc.desc,    // 鍚嶇О
+                                Double.parseDouble("0"),    // 灞炴�у��
                                 lastCode.getData(),    // 鍦伴潰鐮�
                                 String.valueOf(oriSta.getOffset()),   // 鍔ㄤ綔鍙傛暟
-                                ActionTypeType.ReadyTakeFromConveyorSta.val(),    // 鍔ㄤ綔绫诲瀷
+                                ActionTypeType.ReadyTakeFromShelvesLoc.val(),    // 鍔ㄤ綔绫诲瀷
                                 actionPrepareSts,    // 鍔ㄤ綔杩涘害
                                 agvId,    // AGV
                                 now,    // 宸ヤ綔鏃堕棿
@@ -1066,29 +1090,47 @@
                         // 绔欑偣鏀捐揣
                         Sta destSta = staService.getById(task.getDestSta());
                         Double destStaWorkDirection = mapService.getStaAngle(destSta, workDirection);
+//                        CodeGap gap = codeGapService.findByCodeOfBoth(lastCode.getId(), nextCode.getId());
+
                         // 妫�楠屾柟鍚�
-                        if (!lastDirection.equals(destStaWorkDirection)) {
-                            if (!lastCode.getCornerBool()) {
-                                throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣");
-                            }
-                            // 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(destStaWorkDirection),   // 鍔ㄤ綔鍙傛暟
-                                    ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
-                                    actionPrepareSts,    // 鍔ㄤ綔杩涘害
-                                    agvId,    // AGV
-                                    now   // 宸ヤ綔鏃堕棿
-                            ));
-                            lastDirection = destStaWorkDirection;
-                        }
+//                        if (!lastDirection.equals(destStaWorkDirection)) {
+//                            if (!lastCode.getCornerBool()) {
+//                                throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣");
+//                            }
+//
+////                            actionList.add(new Action(
+////                                    null,    // 缂栧彿
+////                                    task.getBusId(),    // 鎬荤嚎
+////                                    task.getId(),    // 浠诲姟
+////                                    null,    // 鍔ㄤ綔鍙�
+////                                    null,    // 浼樺厛绾�
+////                                    actionType.desc,    // 鍚嶇О
+////                                    (double) agvSpeedType.val,    // 灞炴�у��
+////                                    lastCode.getData(),    // 鍦伴潰鐮�
+////                                    String.valueOf(gap.getDistance()),   // 鍔ㄤ綔鍙傛暟
+////                                    actionType.val(),    // 鍔ㄤ綔绫诲瀷
+////                                    actionPrepareSts,    // 鍔ㄤ綔杩涘害
+////                                    agvId,    // AGV
+////                                    now    // 宸ヤ綔鏃堕棿
+////                            ));
+//                            // 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(destStaWorkDirection),   // 鍔ㄤ綔鍙傛暟
+//                                    ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
+//                                    actionPrepareSts,    // 鍔ㄤ綔杩涘害
+//                                    agvId,    // AGV
+//                                    now   // 宸ヤ綔鏃堕棿
+//                            ));
+//                            lastDirection = destStaWorkDirection;
+//                        }
                         // 鏆傚瓨鐐瑰彇璐�
                         assert backpackType != null;
                         actionList.add(new Action(
@@ -1131,7 +1173,7 @@
                         // 妫�楠屾柟鍚�
                         FuncSta chargeFuncSta = funcStaService.query(lastCode.getId(), FuncStaType.CHARGE.toString());
                         Double chargeDirection = Double.parseDouble(chargeFuncSta.getAngle());
-                        if (!lastDirection.equals(chargeDirection)) {
+                        if (!lastDirection.equals(chargeDirection)&&lastCode.getCornerBool()) {
                             actionList.add(new Action(
                                     null,    // 缂栧彿
                                     null,    // 鎬荤嚎
@@ -1288,7 +1330,6 @@
     }
 
 
-
     /**
      * 鏍规嵁鍒嗙墖鐢熸垚鍔ㄤ綔 ( 杞﹁締鍙兘宸茬粡鍋氳繃涓�浜涗换鍔′簡,姝e湪绛夊緟涓嬩竴娈典换鍔� )
      */
@@ -1322,11 +1363,14 @@
                 throw new CoolException("AGV[" + agvNo + "]瀹氫綅鍋忕Щ...");
             }
 
-            String lastCorner = null;
-            for (int i =  pathList.size(); i <0; i++) {
-                Code nextCode = codeService.getCacheByData(pathList.get(i - 1));
-                if (nextCode!=null&&nextCode.getCornerBool()){
-                    lastCorner =pathList.get(i - 1);
+            //String lastCorner = null;
+            Integer index = -1;
+            boolean corner = false;
+            for (int i = pathList.size(); i < 0; i++) {
+                Code nextCode = codeService.getCacheByData(pathList.get(i));
+                if (nextCode != null && nextCode.getCornerBool()) {
+                    //lastCorner = pathList.get(i);
+                    index = i;
                 }
             }
 
@@ -1350,19 +1394,21 @@
                         if (i == 0) {
                             continue;
                         }
-
                         String next = pathListPart.get(i);
-
                         Code nextCode = codeService.getCacheByData(next);
-                        Double nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal);
+                        Double nextDirection;
 
                         boolean reverse = false;
-                        if (lastCorner.equals(lastCode)){
-                            // DOTO
+                        if (index >= i) {
+                            // DOTO 娣诲姞杞集
+                            Code endCode = codeService.getCacheByData(pathList.get(pathList.size() - 1));
+                            nextDirection = mapService.calculateDirection(lastCode, endCode, angleOffsetVal);
+                            reverse = true;
+                        } else {
+                            nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal);
 
-                        }else {
                             // 绗竴姝ワ細濡傛灉涓嬩竴涓柟鍚戞濂芥槸浣滀笟鏂瑰悜鐨勭浉鍙嶆柟鍚戯紝鍒欓噸缃笅涓�涓柟鍚戜负浣滀笟鏂瑰悜锛屾爣璁� reverse = true
-                            if (nextDirection.equals((workDirection + 180) % 360)) {
+                            if (!nextDirection.equals((workDirection+180) % 360)) {
                                 nextDirection = workDirection;
                                 reverse = true;
                             }
@@ -1708,7 +1754,7 @@
                         // 妫�楠屾柟鍚�
                         FuncSta chargeFuncSta = funcStaService.query(lastCode.getId(), FuncStaType.CHARGE.toString());
                         Double chargeDirection = Double.parseDouble(chargeFuncSta.getAngle());
-                        if (!lastDirection.equals(chargeDirection)) {
+                        if (!lastDirection.equals(chargeDirection) && lastCode.getCornerBool()) {
                             actionList.add(new Action(
                                     null,    // 缂栧彿
                                     null,    // 鎬荤嚎
@@ -1851,7 +1897,7 @@
 
             log.info("{}鍙稟gv鍔ㄤ綔缁勮瀹屾垚锛屾寚浠ゆ暟閲忥細{}", agvNo, newActionList.size());
         } catch (Exception e) {
-            log.error("mainService.generateAction", e);
+            log.error("mainService.generateActionV2", e);
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 
             if (!Cools.isEmpty(pathList)) {
@@ -1860,7 +1906,7 @@
                 mapDataDispatcher.clearDynamicMatrixByCodeList(null, codeMatrixIdxList);
             }
 
-            throw new RuntimeException("generateAction method caught an exception, rolling back transaction.", e);
+            throw new RuntimeException("generateActionV2 method caught an exception, rolling back transaction.", e);
         }
     }
 

--
Gitblit v1.9.1