#
luxiaotao1123
2024-10-23 b6bad62d8839cc50d1a82e9ffecbbf666efb780e
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -251,33 +251,25 @@
     * 解析取放货集合任务,进行最优的排列组合顺序 ( 车辆此时是空闲且静止的 )
     */
    @Transactional
    public synchronized void mergeMajorTask(Long agvId, List<Task> taskList) {
    public synchronized void buildMajorTask(Long agvId, List<Task> taskList) {
        if (Cools.isEmpty(taskList)) { return; }
        boolean lockAcquired = false;
        try {
            if (!(lockAcquired = this.lock.tryLock(LOCK_TIMEOUT, TimeUnit.SECONDS))) {
                throw new CoolException("generate [task] action fail, cause can not acquire lock ...");
            }
            Date now = new Date();
            final String sameGroupXy = configService.getVal( "sameGroupXy", String.class);
            // valid -----------------------------------------------
            Agv agv = agvService.getById(agvId);
            if (!agvService.judgeEnable(agv.getId(), agvDetail -> agvDetail.getVol() > agv.getChargeLine())) {
                throw new CoolException("AGV[" + agv.getUuid() + "]当前不可用...");
            }
            if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) {
                throw new CoolException("AGV[" + agv.getUuid() + "]分配任务失败,已存在执行任务...");
            }
            AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId);
            assert agvDetail != null;
            if (agvDetail.getPos() == 0) {
                if (!agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) {
                    throw new CoolException("AGV[" + agv.getUuid() + "]当前不在定位...");
                }
            }
            // execute ----------------------------------------------------
            Date now = new Date();
            // sort and sub
            taskList.sort(new Comparator<Task>() {
                @Override
@@ -290,15 +282,17 @@
                taskList = taskList.subList(0, backpack);
            }
            List<AgvBackpackDto> backpackDtoList = new ArrayList<>();
            /**
             * single agvId
             * 同巷道归类
             * same lane for every single agvId
             *
             * key: y + TaskPosDto.PosType.ORI_LOC / ORI_STA / DEST_LOC / DEST_STA
             * key: y(val) + TaskPosDto.PosType.ORI_LOC / ORI_STA / DEST_LOC / DEST_STA
             * val: new TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType)
             */
            Map<String, List<TaskPosDto>> groups = new HashMap<>();
            List<AgvBackpackDto> backpackDtoList = new ArrayList<>();
            final String sameGroupXy = configService.getVal( "sameGroupXy", String.class);
            int backpackLev = 0;
            for (Task task : taskList) {
@@ -362,7 +356,31 @@
            }
            /**
             *  List<TaskPosDto>: task list on the same channel
             * 1.Map<String, List<TaskPosDto>> groups
             *
             * key: 1000 + ORI_LOC
             * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...]
             *
             * key: 3000 + ORI_LOC
             * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...]
             *
             * key: 2000 + ORI_LOC
             * val: [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...]
             *
             * ......
             *
             * 2.ArrayList<List<TaskPosDto>> list
             * [
             *  [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...],
             *  [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...],
             *  [TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType), TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType),...],
             *  ......
             * ]
             */
            /**
             * 对所有巷道进行有序排序,先是针对List为一个单位,对他们进行FirstWeight排序,相当于表1的key的数值进行有序排序
             *  List<TaskPosDto>: task list on the same lane
             *  ArrayList<List<TaskPosDto>>: all the task list by one agv
             */
            ArrayList<List<TaskPosDto>> list = new ArrayList<>(groups.values());
@@ -371,7 +389,7 @@
                double o2CompVal = (o2.get(0).getFirstWeight(sameGroupXy) * 100) + o2.get(0).getPosType().compOffset;
                return (int) (o1CompVal - o2CompVal);
            });
            // 针对Dto,按照SecondWeight进行排序
            for (List<TaskPosDto> taskPosDtoList : list) {
                taskPosDtoList.sort((o1, o2) -> (int) (o1.getSecondWeight(sameGroupXy) * 100 - o2.getSecondWeight(sameGroupXy) * 100));
            }
@@ -608,11 +626,6 @@
            AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId);
            assert agvDetail != null;
            if (agvDetail.getPos() == 0) {
                if (!agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) {
                    throw new CoolException("AGV[" + agv.getUuid() + "]当前不在定位...");
                }
            }
            List<Action> actionList = new ArrayList<>();
            // start node