From 3c9b9886fc9e9a26dac4e8b5dd4cc0db0b8fce82 Mon Sep 17 00:00:00 2001
From: zc <zyzc>
Date: 星期四, 16 十月 2025 09:53:23 +0800
Subject: [PATCH] 创建分支

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java |  649 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 617 insertions(+), 32 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 1a2bf2a..1ea8950 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
@@ -1288,6 +1288,583 @@
     }
 
 
+
+    /**
+     * 鏍规嵁鍒嗙墖鐢熸垚鍔ㄤ綔 ( 杞﹁締鍙兘宸茬粡鍋氳繃涓�浜涗换鍔′簡,姝e湪绛夊緟涓嬩竴娈典换鍔� )
+     */
+    @Transactional
+    public synchronized void generateActionV2(Long agvId, List<Segment> segmentList, List<String> pathList, Date algoStartTime) {
+        try {
+            if (Cools.isEmpty(agvId, segmentList)) {
+                return;
+            }
+            Date now = new Date();
+            long actionPrepareSts = ActionStsType.PREPARE.val();
+//            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 + "]褰撳墠涓嶅彲鐢�...");
+//            }
+
+            AgvModel agvModel = agvModelService.getByAgvId(agvId);
+            Double workDirection = agvModel.getWorkDirection();
+            AgvSpeedType agvSpeedType = AgvSpeedType.query(agvModel.getTravelSpeed());
+            assert agvSpeedType != null;
+
+            AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId);
+
+            List<Action> actionList = new ArrayList<>();
+            // start node
+            Code lastCode = codeService.getCacheById(agvDetail.getRecentCode());
+            Double lastDirection = MapService.mapToNearest(agvDetail.getAgvAngle());
+            if (!lastCode.getData().equals(pathList.get(0))) {
+                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);
+                }
+            }
+
+            boolean first = true;
+            for (Segment segment : segmentList) {
+
+                // 鍒嗘鎵�灞炵殑Task
+                Task task = taskService.getById(segment.getTaskId());
+
+                // 鑺傜偣鏉$爜
+                Code code = codeService.getCacheById(segment.getEndNode());
+
+                // 闇�瑕佽蛋琛�
+                if (!lastCode.getData().equals(code.getData())) {
+
+                    // 璧拌璺緞鑺傜偣
+//                    List<String> pathList = mapService.checkoutPath(agv.getUuid(), lastCode, code);
+                    List<String> pathListPart = pathList.subList(pathList.indexOf(lastCode.getData()), pathList.indexOf(code.getData()) + 1);
+
+                    for (int i = 0; i < pathListPart.size(); i++) {
+                        if (i == 0) {
+                            continue;
+                        }
+
+                        String next = pathListPart.get(i);
+
+                        Code nextCode = codeService.getCacheByData(next);
+                        Double nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal);
+
+                        boolean reverse = false;
+                        if (lastCorner.equals(lastCode)){
+                            // DOTO
+
+                        }else {
+                            // 绗竴姝ワ細濡傛灉涓嬩竴涓柟鍚戞濂芥槸浣滀笟鏂瑰悜鐨勭浉鍙嶆柟鍚戯紝鍒欓噸缃笅涓�涓柟鍚戜负浣滀笟鏂瑰悜锛屾爣璁� reverse = true
+                            if (nextDirection.equals((workDirection + 180) % 360)) {
+                                nextDirection = workDirection;
+                                reverse = true;
+                            }
+
+                            // 绗簩姝ワ細鍒ゆ柇褰撳墠鑺傜偣鏄惁鍙互鏃嬭浆
+                            if (!lastCode.getCornerBool()) {
+                                // 濡傛灉鏄綔涓氭柟鍚戯紝浣嗘槸灏忚溅鍦ㄥ贩閬撳唴鏂瑰悜閿欒锛屽垯鍋滄
+                                if (reverse && !lastDirection.equals(nextDirection)) {
+//                                throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣");
+                                }
+                                // 濡傛灉涓嶆槸浣滀笟鏂瑰悜锛屽垽鏂槸鍚︾浉鍙嶆柟鍚戯紝濡傛灉鍙嶆柟鍚戝垯鍊掗��琛岃蛋
+                                if (nextDirection.equals((lastDirection + 180) % 360)) {
+                                    nextDirection = lastDirection;
+                                    reverse = true;
+                                }
+                            } else {
+                                if (!lastDirection.equals(nextDirection)) {
+                                    // 濡傛灉涓嬩釜鑺傜偣鏂瑰悜涓庡綋鍓峚gv鏂瑰悜鐩稿弽锛屽垯鍊掗��琛岃蛋锛屼絾鏄鏋滃綋鍓峚gv鏂瑰悜姝eソ涓庡伐浣滄柟鍚戠浉鍙嶏紝鍒欐棆杞嚦宸ヤ綔鏂瑰悜
+                                    if (nextDirection.equals((lastDirection + 180) % 360) && !workDirection.equals((lastDirection + 180) % 360)) {
+                                        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    // 宸ヤ綔鏃堕棿
+                                        ));
+
+                                        lastDirection = nextDirection;
+                                    }
+                                }
+                            }
+                        }
+
+
+                        // 绗竴涓姩浣滀竴瀹氭槸 turn
+                        if (actionList.isEmpty()) {
+                            // 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;
+                        }
+
+                        // run
+                        ActionTypeType actionType = ActionTypeType.StraightAheadTurnable;
+                        if (reverse) {
+                            actionType = ActionTypeType.StraightBackTurnable;
+                        }
+                        CodeGap gap = codeGapService.findByCodeOfBoth(lastCode.getId(), nextCode.getId());
+                        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    // 宸ヤ綔鏃堕棿
+                        ));
+
+                        lastCode = nextCode;
+
+                    }
+
+                }
+
+                // 鍒濆鏂瑰悜鍊艰ˉ涓�
+                if (first) {
+                    if (Cools.isEmpty(actionList) || !actionList.get(0).getActionType().equals(ActionTypeType.TurnCorner.val())) {
+                        // 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(workDirection),   // 鍔ㄤ綔鍙傛暟
+                                ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
+                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                agvId,    // AGV
+                                now    // 宸ヤ綔鏃堕棿
+                        ));
+
+                        lastDirection = workDirection;
+
+                    }
+                    first = false;
+                }
+
+                // 浣滀笟鐐瑰姩浣�
+                AgvDirectionType agvDirectionType;
+                Double staWorkDirection;
+                AgvBackpackType backpackType = AgvBackpackType.query(segment.getBackpack());
+                switch (Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType()))) {
+                    case ORI_LOC:
+                        assert backpackType != null;
+                        // 妫�楠屾柟鍚�
+                        if (!lastDirection.equals(workDirection)) {
+                            throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣");
+                        }
+                        // 璐ф灦鍙栬揣
+                        Loc oriLoc = locService.getById(task.getOriLoc());
+                        // 璁$畻宸﹀彸鏂瑰悜
+                        agvDirectionType = mapService.calculateAgvWorkDirectionByShelf(oriLoc, lastCode);
+                        actionList.add(new Action(
+                                null,    // 缂栧彿
+                                task.getBusId(),    // 鎬荤嚎
+                                task.getId(),    // 浠诲姟
+                                null,    // 鍔ㄤ綔鍙�
+                                null,    // 浼樺厛绾�
+                                ActionTypeType.ReadyTakeFromShelvesLoc.desc,    // 鍚嶇О
+                                (double) agvDirectionType.val,    // 灞炴�у��
+                                lastCode.getData(),    // 鍦伴潰鐮�
+                                String.valueOf(oriLoc.getOffset()),   // 鍔ㄤ綔鍙傛暟
+                                ActionTypeType.ReadyTakeFromShelvesLoc.val(),    // 鍔ㄤ綔绫诲瀷
+                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                agvId,    // AGV
+                                now    // 宸ヤ綔鏃堕棿
+                        ));
+                        // 鏆傚瓨鐐规斁璐�
+                        actionList.add(new Action(
+                                null,    // 缂栧彿
+                                task.getBusId(),    // 鎬荤嚎
+                                task.getId(),    // 浠诲姟
+                                null,    // 鍔ㄤ綔鍙�
+                                null,    // 浼樺厛绾�
+                                ActionTypeType.ReadyReleaseToAgvSite.desc,    // 鍚嶇О
+                                (double) backpackType.lev,    // 灞炴�у��
+                                lastCode.getData(),    // 鍦伴潰鐮�
+                                String.valueOf(backpackType.height),   // 鍔ㄤ綔鍙傛暟
+                                ActionTypeType.ReadyReleaseToAgvSite.val(),    // 鍔ㄤ綔绫诲瀷
+                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                agvId,    // AGV
+                                now    // 宸ヤ綔鏃堕棿
+                        ));
+                        break;
+                    case DEST_LOC:
+                        assert backpackType != null;
+                        // 妫�楠屾柟鍚�
+                        if (!lastDirection.equals(workDirection)) {
+                            throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣");
+                        }
+                        // 鏆傚瓨鐐瑰彇璐ц揣
+                        actionList.add(new Action(
+                                null,    // 缂栧彿
+                                task.getBusId(),    // 鎬荤嚎
+                                task.getId(),    // 浠诲姟
+                                null,    // 鍔ㄤ綔鍙�
+                                null,    // 浼樺厛绾�
+                                ActionTypeType.ReadyTakeFromAgvSite.desc,    // 鍚嶇О
+                                (double) backpackType.lev,    // 灞炴�у��
+                                lastCode.getData(),    // 鍦伴潰鐮�
+                                String.valueOf(backpackType.height),   // 鍔ㄤ綔鍙傛暟
+                                ActionTypeType.ReadyTakeFromAgvSite.val(),    // 鍔ㄤ綔绫诲瀷
+                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                agvId,    // AGV
+                                now    // 宸ヤ綔鏃堕棿
+                        ));
+
+                        // 璐ф灦鏀捐揣
+                        Loc destLoc = locService.getById(task.getDestLoc());
+                        // 璁$畻宸﹀彸鏂瑰悜
+                        agvDirectionType = mapService.calculateAgvWorkDirectionByShelf(destLoc, lastCode);
+                        actionList.add(new Action(
+                                null,    // 缂栧彿
+                                task.getBusId(),    // 鎬荤嚎
+                                task.getId(),    // 浠诲姟
+                                null,    // 鍔ㄤ綔鍙�
+                                null,    // 浼樺厛绾�
+                                ActionTypeType.ReadyReleaseToShelvesLoc.desc,    // 鍚嶇О
+                                (double) agvDirectionType.val,    // 灞炴�у��
+                                lastCode.getData(),    // 鍦伴潰鐮�
+                                String.valueOf(destLoc.getOffset()),   // 鍔ㄤ綔鍙傛暟
+                                ActionTypeType.ReadyReleaseToShelvesLoc.val(),    // 鍔ㄤ綔绫诲瀷
+                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                agvId,    // AGV
+                                now    // 宸ヤ綔鏃堕棿
+                        ));
+                        break;
+                    case ORI_STA:
+                        // 绔欑偣鍙栬揣
+                        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;
+                        }
+                        // 璁$畻璐у弶宸ヤ綔鏂瑰悜
+                        staWorkDirection = mapService.calculateAgvWorkDirectionByStation(oriStaWorkDirection, lastDirection);
+                        actionList.add(new Action(
+                                null,    // 缂栧彿
+                                task.getBusId(),    // 鎬荤嚎
+                                task.getId(),    // 浠诲姟
+                                null,    // 鍔ㄤ綔鍙�
+                                null,    // 浼樺厛绾�
+                                ActionTypeType.ReadyTakeFromConveyorSta.desc,    // 鍚嶇О
+                                staWorkDirection,    // 灞炴�у��
+                                lastCode.getData(),    // 鍦伴潰鐮�
+                                String.valueOf(oriSta.getOffset()),   // 鍔ㄤ綔鍙傛暟
+                                ActionTypeType.ReadyTakeFromConveyorSta.val(),    // 鍔ㄤ綔绫诲瀷
+                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                agvId,    // AGV
+                                now,    // 宸ヤ綔鏃堕棿
+                                oriSta.getStaTypeIsCheck() == 1 ? 1 : 0,
+                                oriSta.getStaNo()
+                        ));
+                        // 鏆傚瓨鐐规斁璐�
+                        assert backpackType != null;
+                        actionList.add(new Action(
+                                null,    // 缂栧彿
+                                task.getBusId(),    // 鎬荤嚎
+                                task.getId(),    // 浠诲姟
+                                null,    // 鍔ㄤ綔鍙�
+                                null,    // 浼樺厛绾�
+                                ActionTypeType.ReadyReleaseToAgvSite.desc,    // 鍚嶇О
+                                (double) backpackType.lev,    // 灞炴�ш皰
+                                lastCode.getData(),    // 鍦伴潰鐮�
+                                String.valueOf(backpackType.height),   // 鍔ㄤ綔鍙傛暟
+                                ActionTypeType.ReadyReleaseToAgvSite.val(),    // 鍔ㄤ綔绫诲瀷
+                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                agvId,    // AGV
+                                now    // 宸ヤ綔鏃堕棿
+                        ));
+                        break;
+                    case DEST_STA:
+                        // 绔欑偣鏀捐揣
+                        Sta destSta = staService.getById(task.getDestSta());
+                        Double destStaWorkDirection = mapService.getStaAngle(destSta, workDirection);
+                        // 妫�楠屾柟鍚�
+                        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;
+                        }
+                        // 鏆傚瓨鐐瑰彇璐�
+                        assert backpackType != null;
+                        actionList.add(new Action(
+                                null,    // 缂栧彿
+                                task.getBusId(),    // 鎬荤嚎
+                                task.getId(),    // 浠诲姟
+                                null,    // 鍔ㄤ綔鍙�
+                                null,    // 浼樺厛绾�
+                                ActionTypeType.ReadyTakeFromAgvSite.desc,    // 鍚嶇О
+                                (double) backpackType.lev,    // 灞炴�ш皰
+                                lastCode.getData(),    // 鍦伴潰鐮�
+                                String.valueOf(backpackType.height),   // 鍔ㄤ綔鍙傛暟
+                                ActionTypeType.ReadyTakeFromAgvSite.val(),    // 鍔ㄤ綔绫诲瀷
+                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                agvId,    // AGV
+                                now    // 宸ヤ綔鏃堕棿
+
+                        ));
+                        // 璁$畻璐у弶宸ヤ綔鏂瑰悜
+                        staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, lastDirection);
+                        actionList.add(new Action(
+                                null,    // 缂栧彿
+                                task.getBusId(),    // 鎬荤嚎
+                                task.getId(),    // 浠诲姟
+                                null,    // 鍔ㄤ綔鍙�
+                                null,    // 浼樺厛绾�
+                                ActionTypeType.ReadyReleaseToConveyorSta.desc,    // 鍚嶇О
+                                staWorkDirection,    // 灞炴�ш皰
+                                lastCode.getData(),    // 鍦伴潰鐮�
+                                String.valueOf(destSta.getOffset()),   // 鍔ㄤ綔鍙傛暟
+                                ActionTypeType.ReadyReleaseToConveyorSta.val(),    // 鍔ㄤ綔绫诲瀷
+                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                agvId,    // AGV
+                                now,    // 宸ヤ綔鏃堕棿
+                                destSta.getStaTypeIsCheck() == 1 ? 2 : 0,
+                                destSta.getStaNo()
+                        ));
+                        break;
+                    case TO_CHARGE:
+                        // 妫�楠屾柟鍚�
+                        FuncSta chargeFuncSta = funcStaService.query(lastCode.getId(), FuncStaType.CHARGE.toString());
+                        Double chargeDirection = Double.parseDouble(chargeFuncSta.getAngle());
+                        if (!lastDirection.equals(chargeDirection)) {
+                            actionList.add(new Action(
+                                    null,    // 缂栧彿
+                                    null,    // 鎬荤嚎
+                                    task.getId(),    // 浠诲姟
+                                    null,    // 鍔ㄤ綔鍙�
+                                    null,    // 浼樺厛绾�
+                                    ActionTypeType.TurnCorner.desc,    // 鍚嶇О
+                                    mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D,    // 灞炴�ш皰
+                                    lastCode.getData(),    // 鍦伴潰鐮�
+                                    String.valueOf(chargeDirection),   // 鍔ㄤ綔鍙傛暟
+                                    ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
+                                    actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                    agvId,    // AGV
+                                    now    // 宸ヤ綔鏃堕棿
+                            ));
+                            lastDirection = chargeDirection;
+                        }
+
+                        // charge
+                        actionList.add(new Action(
+                                null,    // 缂栧彿
+                                null,    // 鎬荤嚎
+                                task.getId(),    // 浠诲姟
+                                null,    // 鍔ㄤ綔鍙�
+                                null,    // 浼樺厛绾�
+                                ActionTypeType.DockingCharge.desc,    // 鍚嶇О
+                                null,    // 灞炴�ш皰
+                                lastCode.getData(),    // 鍦伴潰鐮�
+                                null,   // 鍔ㄤ綔鍙傛暟
+                                ActionTypeType.DockingCharge.val(),    // 鍔ㄤ綔绫诲瀷
+                                actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                agvId,    // AGV
+                                now    // 宸ヤ綔鏃堕棿
+                        ));
+                        break;
+                    case TO_STANDBY:
+//                        FuncSta standByFuncSta = funcStaService.query(agvId, lastCode.getId(), 2);
+//                        Double standByDirection = Double.parseDouble(standByFuncSta.getAngle());
+//                        if (!lastDirection.equals(standByDirection)) {
+//                            actionList.add(new Action(
+//                                    null,    // 缂栧彿
+//                                    null,    // 鎬荤嚎
+//                                    task.getId(),    // 浠诲姟
+//                                    null,    // 鍔ㄤ綔鍙�
+//                                    null,    // 浼樺厛绾�
+//                                    ActionTypeType.TurnCorner.desc,    // 鍚嶇О
+//                                    null,    // 灞炴�ш皰
+//                                    lastCode.getData(),    // 鍦伴潰鐮�
+//                                    String.valueOf(standByDirection),   // 鍔ㄤ綔鍙傛暟
+//                                    ActionTypeType.TurnCorner.val(),    // 鍔ㄤ綔绫诲瀷
+//                                    actionPrepareSts,    // 鍔ㄤ綔杩涘害
+//                                    agvId,    // AGV
+//                                    now    // 宸ヤ綔鏃堕棿
+//                            ));
+//                            lastDirection = standByDirection;
+//                        }
+                        String runToWaitHeightFlag = configService.getVal("RunToWaitHeightFlag", String.class);
+                        if (!Cools.isEmpty(runToWaitHeightFlag) && runToWaitHeightFlag.contains(agvId.toString())) {
+                            String runToWaitHeight = configService.getVal("RunToWaitHeight", String.class);
+                            if (Cools.isEmpty(runToWaitHeight)) {
+                                runToWaitHeight = "800";
+                            }
+                            Double runToWaitHeightValue = configService.getVal("RunToWaitHeightValue", Double.class);
+                            if (runToWaitHeightValue == 0) {
+                                runToWaitHeightValue = 1D;
+                            }
+                            // 淇绌烘寚閽堝紓甯革細妫�鏌astCode鏄惁涓簄ull
+                            if (lastCode == null) {
+                                throw new BusinessException("AGV瀹氫綅淇℃伅寮傚父锛屾棤娉曠敓鎴愬緟鏈哄姩浣�");
+                            }
+                            actionList.add(new Action(
+                                    null,    // 缂栧彿
+                                    task.getBusId(),    // 鎬荤嚎
+                                    task.getId(),    // 浠诲姟
+                                    null,    // 鍔ㄤ綔鍙�
+                                    null,    // 浼樺厛绾�
+                                    ActionTypeType.RunToWaitHeight.desc,    // 鍚嶇О
+                                    runToWaitHeightValue,    // 灞炴�ш皰
+                                    lastCode.getData(),    // 鍦伴潰鐮�
+                                    runToWaitHeight,   // 鍔ㄤ綔鍙傛暟
+                                    ActionTypeType.RunToWaitHeight.val(),    // 鍔ㄤ綔绫诲瀷
+                                    actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                                    agvId,    // AGV
+                                    now    // 宸ヤ綔鏃堕棿
+                            ));
+                        }
+                        break;
+                    case MOVE:
+                        break;
+                    default:
+                        break;
+                }
+
+            }
+
+            // finish
+            actionList.add(new Action(
+                    null,    // 缂栧彿
+                    null,    // 鎬荤嚎
+                    null,    // 浠诲姟
+                    null,    // 鍔ㄤ綔鍙�
+                    null,    // 浼樺厛绾�
+                    ActionTypeType.FinishPath.desc,    // 鍚嶇О
+                    null,    // 灞炴�у��
+                    lastCode.getData(),    // 鍦伴潰鐮�
+                    null,   // 鍔ㄤ綔鍙傛暟
+                    ActionTypeType.FinishPath.val(),    // 鍔ㄤ綔绫诲瀷
+                    actionPrepareSts,    // 鍔ㄤ綔杩涘害
+                    agvId,    // AGV
+                    now    // 宸ヤ綔鏃堕棿
+            ));
+
+            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.setGroupId(groupId);
+                action.setPriority(i);
+                i -= 1;
+            }
+            if (!actionService.saveBatch(newActionList)) {
+                throw new BusinessException("group[" + groupId + "] 鍔ㄤ綔淇濆瓨澶辫触");
+            }
+
+            // update segment
+            for (Segment item : segmentList) {
+                item.setGroupId(groupId);
+                item.setState(SegmentStateType.RUNNING.toString());
+                item.setUpdateTime(now);
+                if (null != algoStartTime) {
+                    item.setAlgoTime((int) (now.getTime() - algoStartTime.getTime()));
+                }
+                if (!segmentService.updateById(item)) {
+                    throw new CoolException("鏇存柊Segment澶辫触");
+                }
+            }
+
+            log.info("{}鍙稟gv鍔ㄤ綔缁勮瀹屾垚锛屾寚浠ゆ暟閲忥細{}", agvNo, newActionList.size());
+        } catch (Exception e) {
+            log.error("mainService.generateAction", e);
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+
+            if (!Cools.isEmpty(pathList)) {
+                pathList.remove(0);
+                List<int[]> codeMatrixIdxList = mapDataDispatcher.getCodeMatrixIdxList(null, pathList);
+                mapDataDispatcher.clearDynamicMatrixByCodeList(null, codeMatrixIdxList);
+            }
+
+            throw new RuntimeException("generateAction method caught an exception, rolling back transaction.", e);
+        }
+    }
+
+
     @Transactional
     public void publishAction(String actionGroupId) {
         try {
@@ -1502,11 +2079,11 @@
 //                    }
 //                }
 
-                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
-                for (Long taskId : taskIds) {
-                    Task task = taskService.getById(taskId);
-                    report(task, agv_11_up.getQrCode(), TaskReportStsType.END);
-                }
+//                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
+//                for (Long taskId : taskIds) {
+//                    Task task = taskService.getById(taskId);
+//                    report(task, agv_11_up.getQrCode(), TaskReportStsType.END);
+//                }
             }
 
             // 鍑哄簱鍙栬揣
@@ -1540,31 +2117,31 @@
 //                        }
 //                    }
 //                }
-                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
-                for (Long taskId : taskIds) {
-                    Task task = taskService.getById(taskId);
-                    report(task, agv_11_up.getQrCode(), TaskReportStsType.OTBIN);
-                }
+//                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
+//                for (Long taskId : taskIds) {
+//                    Task task = taskService.getById(taskId);
+//                    report(task, agv_11_up.getQrCode(), TaskReportStsType.OTBIN);
+//                }
 
             }
             //浠庤緭閫佺嚎鍙栬揣瀹屾垚
-            if (agv_11_up.getCompleteType().equals(AgvCompleteType.TAKE_FROM_STA_COMPLETE)) {
-                WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode();
-                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
-                for (Long taskId : taskIds) {
-                    Task task = taskService.getById(taskId);
-                    report(task, agv_11_up.getQrCode(), TaskReportStsType.OTBIN);
-                }
-            }
+//            if (agv_11_up.getCompleteType().equals(AgvCompleteType.TAKE_FROM_STA_COMPLETE)) {
+//                WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode();
+//                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
+//                for (Long taskId : taskIds) {
+//                    Task task = taskService.getById(taskId);
+//                    report(task, agv_11_up.getQrCode(), TaskReportStsType.OTBIN);
+//                }
+//            }
             //寰�杈撻�佺嚎鏀捐揣瀹屾垚
-            if (agv_11_up.getCompleteType().equals(AgvCompleteType.RELEASE_FROM_STA_COMPLETE)) {
-                WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode();
-                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
-                for (Long taskId : taskIds) {
-                    Task task = taskService.getById(taskId);
-                    report(task, agv_11_up.getQrCode(), TaskReportStsType.END);
-                }
-            }
+//            if (agv_11_up.getCompleteType().equals(AgvCompleteType.RELEASE_FROM_STA_COMPLETE)) {
+//                WebsocketServiceImpl.taskShelfBarcode = agv_11_up.getLocCode();
+//                List<Long> taskIds = actionService.selectTaskIdsByGroupId(serialNo);
+//                for (Long taskId : taskIds) {
+//                    Task task = taskService.getById(taskId);
+//                    report(task, agv_11_up.getQrCode(), TaskReportStsType.END);
+//                }
+//            }
 
             // 璺緞瀹屾垚 || 鍏呯數瀹屾垚
             if (agv_11_up.getCompleteType().equals(AgvCompleteType.ENTIRE_PATH_COMPLETE)
@@ -1604,6 +2181,8 @@
         // task
         for (Segment segment : segmentList) {
             boolean taskComplete = false;
+            boolean otbin = false;
+
 
             Task task = taskService.getById(segment.getTaskId());
             assert null != task;
@@ -1614,6 +2193,7 @@
             switch (Objects.requireNonNull(posType)) {
                 case ORI_STA:
                 case ORI_LOC:
+                    otbin = true;
                     break;
                 case DEST_STA:
                 case DEST_LOC:
@@ -1634,19 +2214,24 @@
                     break;
             }
 
+            if (otbin) {
+                locService.taskCallBackOtbin(task);
+                report(task, null, TaskReportStsType.OTBIN);
+            }
+
+
             if (taskComplete) {
-                locService.taskCallBack(task);
+                locService.taskCallBackEnd(task);
 
                 task.setTaskSts(TaskStsType.COMPLETE.val());
                 task.setEndTime(now);
                 task.setUpdateTime(now);
                 if (!taskService.updateById(task)) {
                     log.error("Task [{}] 鏇存柊澶辫触 锛侊紒锛�", task.getSeqNum());
-                } else {
-                    report(task, null, TaskReportStsType.END);
-                    if (task.getSeqNum() != null && task.getSeqNum().contains("SSX-CK")) {
-                        report(task, "1001", TaskReportStsType.COMPLETED);
-                    }
+                }
+                report(task, null, TaskReportStsType.END);
+                if (task.getSeqNum() != null && task.getSeqNum().contains("SSX-CK")) {
+                    report(task, "1001", TaskReportStsType.COMPLETED);
                 }
             }
         }

--
Gitblit v1.9.1