#
luxiaotao1123
2024-11-20 c514b7d8ad8a3f89b81c949e265446b4f09a4bb5
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -22,7 +22,6 @@
import com.zy.acs.manager.common.domain.TaskDto;
import com.zy.acs.manager.common.domain.param.HandlerPublishParam;
import com.zy.acs.manager.common.exception.BusinessException;
import com.zy.acs.manager.common.utils.CommonUtil;
import com.zy.acs.manager.core.domain.AgvBackpackDto;
import com.zy.acs.manager.core.domain.Lane;
import com.zy.acs.manager.core.domain.TaskPosDto;
@@ -221,7 +220,7 @@
            for (Task task : taskList) {
                Agv agv = allocateService.execute(task);
                if (null == agv) {
                    log.warn("Task[{}] has an issue, because it failed to checkout agv which is idle...", task.getSeqNum());
//                    log.warn("Task[{}] has an issue, because it failed to checkout agv which is idle...", task.getSeqNum());
                    continue;
                }
                task.setAgvId(agv.getId());
@@ -249,10 +248,15 @@
            // valid -----------------------------------------------
            Agv agv = agvService.getById(agvId);
            if (!agvService.judgeEnable(agv.getId(), true)) {
                throw new CoolException("AGV[" + agv.getUuid() + "]当前不可用...");
                return;
//                throw new CoolException("AGV[" + agv.getUuid() + "]当前不可用...");
            }
            if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) {
                throw new CoolException("AGV[" + agv.getUuid() + "]分配任务失败,已存在执行任务...");
            }
            if (!Cools.isEmpty(segmentService.getByAgvAndState(agv.getId(), SegmentStateType.WAITING.toString()))
                    || !Cools.isEmpty(segmentService.getByAgvAndState(agv.getId(), SegmentStateType.RUNNING.toString()))) {
                throw new CoolException("AGV[" + agv.getUuid() + "] failed to assign,because already has the segment in running...");
            }
            // execute ----------------------------------------------------
@@ -383,48 +387,48 @@
            }
            // re-order by agv current position
            Code currCode = codeService.getById(agvDetail.getRecentCode());
            Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()};
            List<TaskPosDto> theFirstOne = list.get(0);
            List<TaskPosDto> theLastOne = list.get(list.size() - 1);
            if (list.size() == 1) {
                TaskPosDto head = theFirstOne.get(0);
                TaskPosDto tail = theFirstOne.get(theFirstOne.size() - 1);
                int distanceByHead = CommonUtil.calcDistance(currPosition, head.getXy());
                int distanceByTail = CommonUtil.calcDistance(currPosition, tail.getXy());
                if (distanceByTail < distanceByHead) {
                    Collections.reverse(theFirstOne);
                }
            } else {
                TaskPosDto headOfFirst = theFirstOne.get(0);
                TaskPosDto tailOfFirst = theFirstOne.get(theFirstOne.size() - 1);
                TaskPosDto headOfLast = theLastOne.get(0);
                TaskPosDto tailOfLast = theLastOne.get(theLastOne.size() - 1);
                int distanceByHeadOfFirst = CommonUtil.calcDistance(currPosition, headOfFirst.getXy());
                int distanceByTailOfFirst = CommonUtil.calcDistance(currPosition, tailOfFirst.getXy());
                int distanceByHeadOfLast = CommonUtil.calcDistance(currPosition, headOfLast.getXy());
                int distanceByTailOfLast = CommonUtil.calcDistance(currPosition, tailOfLast.getXy());
                if (Math.min(distanceByHeadOfLast, distanceByTailOfLast) < Math.min(distanceByHeadOfFirst, distanceByTailOfFirst)) {
                    Collections.reverse(list);
                    if (distanceByTailOfLast < distanceByHeadOfLast) {
                        Collections.reverse(theLastOne);
                    }
                } else {
                    if (distanceByTailOfFirst < distanceByHeadOfFirst) {
                        Collections.reverse(theFirstOne);
                    }
                }
            }
//            Code currCode = codeService.getById(agvDetail.getRecentCode());
//            Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()};
//
//            List<TaskPosDto> theFirstOne = list.get(0);
//            List<TaskPosDto> theLastOne = list.get(list.size() - 1);
//
//            if (list.size() == 1) {
//                TaskPosDto head = theFirstOne.get(0);
//                TaskPosDto tail = theFirstOne.get(theFirstOne.size() - 1);
//
//                int distanceByHead = CommonUtil.calcDistance(currPosition, head.getXy());
//                int distanceByTail = CommonUtil.calcDistance(currPosition, tail.getXy());
//
//                if (distanceByTail < distanceByHead) {
//                    Collections.reverse(theFirstOne);
//                }
//
//            } else {
//                TaskPosDto headOfFirst = theFirstOne.get(0);
//                TaskPosDto tailOfFirst = theFirstOne.get(theFirstOne.size() - 1);
//
//                TaskPosDto headOfLast = theLastOne.get(0);
//                TaskPosDto tailOfLast = theLastOne.get(theLastOne.size() - 1);
//
//                int distanceByHeadOfFirst = CommonUtil.calcDistance(currPosition, headOfFirst.getXy());
//                int distanceByTailOfFirst = CommonUtil.calcDistance(currPosition, tailOfFirst.getXy());
//
//                int distanceByHeadOfLast = CommonUtil.calcDistance(currPosition, headOfLast.getXy());
//                int distanceByTailOfLast = CommonUtil.calcDistance(currPosition, tailOfLast.getXy());
//
//                if (Math.min(distanceByHeadOfLast, distanceByTailOfLast) < Math.min(distanceByHeadOfFirst, distanceByTailOfFirst)) {
//                    Collections.reverse(list);
//
//                    if (distanceByTailOfLast < distanceByHeadOfLast) {
//                        Collections.reverse(theLastOne);
//                    }
//                } else {
//                    if (distanceByTailOfFirst < distanceByHeadOfFirst) {
//                        Collections.reverse(theFirstOne);
//                    }
//                }
//            }
            // generate travel
            Travel travel = new Travel();
@@ -491,17 +495,19 @@
     * 充电 回待机位任务
     */
    @Transactional(propagation = Propagation.REQUIRES_NEW) // although there is a Transactional here that the lock is isolated, but we can't join the caller's Transactional
    public boolean buildMinorTask(Agv agv, AgvDetail agvDetail, TaskTypeType taskType, String destination) {
    public boolean buildMinorTask(Agv agv, TaskTypeType taskType, String destination, Jam jam) {
        if (Cools.isEmpty(agv, taskType)) { return false; }
        try {
            if (null == agvDetail) {
                agvDetail = agvDetailService.selectByAgvId(agv.getId());
            }
            AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
            if (!agvService.judgeEnable(agv.getId())) {
                return false;
            }
            if (!Cools.isEmpty(taskService.selectInSts(agv.getId(), TaskStsType.ASSIGN, TaskStsType.PROGRESS))) {
                throw new CoolException("AGV[" + agv.getUuid() + "] failed to assign,because already has the task in running...");
            }
            if (!Cools.isEmpty(segmentService.getByAgvAndState(agv.getId(), SegmentStateType.WAITING.toString()))
                    || !Cools.isEmpty(segmentService.getByAgvAndState(agv.getId(), SegmentStateType.RUNNING.toString()))) {
                throw new CoolException("AGV[" + agv.getUuid() + "] failed to assign,because already has the segment in running...");
            }
            Date now = new Date();
@@ -602,6 +608,10 @@
                }
                if (!segmentService.save(next)) {
                    throw new BusinessException("segment failed to save");
                } else {
                    if (null != jam && i == 0) {
                        jam.setAvoSeg(next.getId());
                    }
                }
            }
@@ -621,10 +631,6 @@
                default:
                    break;
            }
//            if (taskType.equals(TaskTypeType.TO_STANDBY)) {
//                redis.setObject(RedisConstant.AGV_TO_STANDBY_FLAG, agv.getUuid(), false);
//            }
            return true;
        } catch (Exception e) {