#
luxiaotao1123
2025-01-08 aa6f20d98b5d8e18ae56f9562a78d403a5417b48
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -1,7 +1,6 @@
package com.zy.acs.manager.core.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.acs.common.domain.AgvAction;
import com.zy.acs.common.domain.AgvActionItem;
@@ -521,7 +520,7 @@
                    }
                    break;
                case MOVE:
                    endCode = codeService.selectByData(destination);
                    endCode = codeService.getCacheByData(destination);
                    break;
                default:
                    return false;
@@ -646,29 +645,31 @@
        try {
            if (Cools.isEmpty(agvId, segmentList)) { return; }
            Date now = new Date();
            JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class);
            Agv agv = agvService.getById(agvId);
            if (!agvService.judgeEnable(agv.getId())) {
                throw new CoolException("AGV[" + agv.getUuid() + "]当前不可用...");
            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.getById(agv.getAgvModel());
            AgvModel agvModel = agvModelService.getByAgvId(agvId);
            Double workDirection = agvModel.getWorkDirection();
            AgvSpeedType agvSpeedType = AgvSpeedType.query(agvModel.getTravelSpeed());
            assert agvSpeedType != null;
            AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId);
            assert agvDetail != null;
            AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId);
            List<Action> actionList = new ArrayList<>();
            // start node
            Code lastCode = codeService.getById(agvDetail.getRecentCode());
            Double lastDirection = agvDetail.getAgvAngle();
            if (!lastCode.getData().equals(pathList.get(0))) {
                throw new CoolException("AGV[" + agv.getUuid() + "]定位偏移...");
                throw new CoolException("AGV[" + agvNo + "]定位偏移...");
            }
            boolean first = true;
            long startTime = System.currentTimeMillis();
            for (Segment segment : segmentList) {
                // 分段所属的Task
@@ -689,15 +690,15 @@
                        String next = pathListPart.get(i);
                        Code nextCode = codeService.selectByData(next);
                        Double nextDirection = mapService.calculateDirection(lastCode, nextCode);
                        Code nextCode = codeService.getCacheByData(next);
                        Double nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal);
                        boolean reverse = false;
                        if (nextDirection.equals((workDirection + 180) % 360)) {
                            nextDirection = workDirection;
                            reverse = true;
                        }
                        if (!lastDirection.equals(nextDirection) || actionList.size() == 0) {
                        if (!lastDirection.equals(nextDirection) || actionList.isEmpty()) {
                            // turn
                            actionList.add(new Action(
                                    null,    // 编号
@@ -710,7 +711,7 @@
                                    lastCode.getData(),    // 地面码
                                    String.valueOf(nextDirection),   // 动作参数
                                    ActionTypeType.TurnCorner.val(),    // 动作类型
                                    ActionStsType.PREPARE.val(),    // 动作进度
                                    actionPrepareSts,    // 动作进度
                                    agvId,    // AGV
                                    now    // 工作时间
                            ));
@@ -736,7 +737,7 @@
                                lastCode.getData(),    // 地面码
                                String.valueOf(gap.getDistance()),   // 动作参数
                                actionType.val(),    // 动作类型
                                ActionStsType.PREPARE.val(),    // 动作进度
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
                                now    // 工作时间
                        ));
@@ -762,7 +763,7 @@
                                lastCode.getData(),    // 地面码
                                String.valueOf(workDirection),   // 动作参数
                                ActionTypeType.TurnCorner.val(),    // 动作类型
                                ActionStsType.PREPARE.val(),    // 动作进度
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
                                now    // 工作时间
                        ));
@@ -793,7 +794,7 @@
                                    lastCode.getData(),    // 地面码
                                    String.valueOf(workDirection),   // 动作参数
                                    ActionTypeType.TurnCorner.val(),    // 动作类型
                                    ActionStsType.PREPARE.val(),    // 动作进度
                                    actionPrepareSts,    // 动作进度
                                    agvId,    // AGV
                                    now    // 工作时间
                            ));
@@ -802,7 +803,7 @@
                        // 货架取货
                        Loc oriLoc = locService.getById(task.getOriLoc());
                        // 计算左右方向
                        agvDirectionType = mapService.calculateAgvWorkDirection(storeDirection, oriLoc, lastCode);
                        agvDirectionType = mapService.calculateAgvWorkDirection(oriLoc, lastCode);
                        actionList.add(new Action(
                                null,    // 编号
                                task.getBusId(),    // 总线
@@ -814,7 +815,7 @@
                                lastCode.getData(),    // 地面码
                                String.valueOf(oriLoc.getOffset()),   // 动作参数
                                ActionTypeType.ReadyTakeFromShelvesLoc.val(),    // 动作类型
                                ActionStsType.PREPARE.val(),    // 动作进度
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
                                now    // 工作时间
                        ));
@@ -830,7 +831,7 @@
                                lastCode.getData(),    // 地面码
                                String.valueOf(backpackType.height),   // 动作参数
                                ActionTypeType.ReadyReleaseToAgvSite.val(),    // 动作类型
                                ActionStsType.PREPARE.val(),    // 动作进度
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
                                now    // 工作时间
                        ));
@@ -851,7 +852,7 @@
                                    lastCode.getData(),    // 地面码
                                    String.valueOf(workDirection),   // 动作参数
                                    ActionTypeType.TurnCorner.val(),    // 动作类型
                                    ActionStsType.PREPARE.val(),    // 动作进度
                                    actionPrepareSts,    // 动作进度
                                    agvId,    // AGV
                                    now    // 工作时间
                            ));
@@ -869,7 +870,7 @@
                                lastCode.getData(),    // 地面码
                                String.valueOf(backpackType.height),   // 动作参数
                                ActionTypeType.ReadyTakeFromAgvSite.val(),    // 动作类型
                                ActionStsType.PREPARE.val(),    // 动作进度
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
                                now    // 工作时间
                        ));
@@ -877,7 +878,7 @@
                        // 货架放货
                        Loc destLoc = locService.getById(task.getDestLoc());
                        // 计算左右方向
                        agvDirectionType = mapService.calculateAgvWorkDirection(storeDirection, destLoc, lastCode);
                        agvDirectionType = mapService.calculateAgvWorkDirection(destLoc, lastCode);
                        actionList.add(new Action(
                                null,    // 编号
                                task.getBusId(),    // 总线
@@ -889,7 +890,7 @@
                                lastCode.getData(),    // 地面码
                                String.valueOf(destLoc.getOffset()),   // 动作参数
                                ActionTypeType.ReadyReleaseToShelvesLoc.val(),    // 动作类型
                                ActionStsType.PREPARE.val(),    // 动作进度
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
                                now    // 工作时间
                        ));
@@ -914,7 +915,7 @@
                                    lastCode.getData(),    // 地面码
                                    String.valueOf(chargeDirection),   // 动作参数
                                    ActionTypeType.TurnCorner.val(),    // 动作类型
                                    ActionStsType.PREPARE.val(),    // 动作进度
                                    actionPrepareSts,    // 动作进度
                                    agvId,    // AGV
                                    now    // 工作时间
                            ));
@@ -933,7 +934,7 @@
                                lastCode.getData(),    // 地面码
                                null,   // 动作参数
                                ActionTypeType.DockingCharge.val(),    // 动作类型
                                ActionStsType.PREPARE.val(),    // 动作进度
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
                                now    // 工作时间
                        ));
@@ -953,7 +954,7 @@
//                                    lastCode.getData(),    // 地面码
//                                    String.valueOf(standByDirection),   // 动作参数
//                                    ActionTypeType.TurnCorner.val(),    // 动作类型
//                                    ActionStsType.PREPARE.val(),    // 动作进度
//                                    actionPrepareSts,    // 动作进度
//                                    agvId,    // AGV
//                                    now    // 工作时间
//                            ));
@@ -967,6 +968,7 @@
                }
            }
            System.out.println("save data: " + (System.currentTimeMillis() - startTime));
            // finish
            actionList.add(new Action(
@@ -980,7 +982,7 @@
                    lastCode.getData(),    // 地面码
                    null,   // 动作参数
                    ActionTypeType.FinishPath.val(),    // 动作类型
                    ActionStsType.PREPARE.val(),    // 动作进度
                    actionPrepareSts,    // 动作进度
                    agvId,    // AGV
                    now    // 工作时间
            ));
@@ -1019,14 +1021,15 @@
                }
            }
            log.info(agv.getUuid() + "号Agv动作组装完成,指令数量:" + newActionList.size());
            log.info(agvNo + "号Agv动作组装完成,指令数量:" + newActionList.size());
        } catch (Exception e) {
            log.error("mainService.generateAction", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            if (!Cools.isEmpty(pathList)) {
                pathList.remove(0);
                mapDataDispatcher.clearDynamicMatrixByCodeList(null, pathList);
                List<int[]> codeMatrixIdxList = mapDataDispatcher.getCodeMatrixIdxList(null, pathList);
                mapDataDispatcher.clearDynamicMatrixByCodeList(null, codeMatrixIdxList);
            }
            throw new RuntimeException("generateAction method caught an exception, rolling back transaction.", e);