zhang
2025-07-23 b3814333d786324bb81cca7d1bcf5ac8f2f1a7cf
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -96,6 +96,10 @@
    private LaneService laneService;
    @Autowired
    private ActionSorter actionSorter;
    @Autowired
    private TaskReportService taskReportService;
    @Autowired
    private AgvDurationService agvDurationService;
    @SuppressWarnings("all")
    @Transactional
@@ -249,10 +253,12 @@
            );
            if (Cools.isEmpty(taskList)) {
                bus.setBusSts(BusStsType.PROGRESS.val());
                bus.setUpdateTime(now);
                if (!busService.updateById(bus)) {
                    log.error("Bus [{}] failed to Update !!!", bus.getUuid());
                if (bus.getBusSts().equals(BusStsType.RECEIVE.val())) {
                    bus.setBusSts(BusStsType.PROGRESS.val());
                    bus.setUpdateTime(now);
                    if (!busService.updateById(bus)) {
                        log.error("Bus [{}] failed to Update !!!", bus.getUuid());
                    }
                }
                return;
            }
@@ -284,7 +290,9 @@
     */
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void buildMajorTask(Long agvId, List<Task> taskList) {
        if (Cools.isEmpty(agvId, taskList)) { return; }
        if (Cools.isEmpty(agvId, taskList)) {
            return;
        }
        try {
            // valid -----------------------------------------------
            Agv agv = agvService.getById(agvId);
@@ -324,16 +332,18 @@
             * val: new TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType)
             */
            Map<String, List<TaskPosDto>> groups = new HashMap<>();
            final String sameGroupXy = configService.getVal( "sameGroupXy", String.class);
            final String sameGroupXy = configService.getVal("sameGroupXy", String.class);
            int backpackLev = 0;
            for (Task task : taskList) {
                backpackLev ++;
                backpackLev++;
                Code startCode = null;
                Code endCode = null;
                Loc oriLoc = null; Loc destLoc = null;
                Sta oriSta = null; Sta destSta = null;
                Loc oriLoc = null;
                Loc destLoc = null;
                Sta oriSta = null;
                Sta destSta = null;
                switch (Objects.requireNonNull(TaskTypeType.get(task.getTaskTypeEl()))) {
                    case LOC_TO_LOC:
                        oriLoc = locService.getById(task.getOriLoc());
@@ -436,7 +446,7 @@
            // re-order by agv current position
            Code currCode = codeService.getCacheById(agvDetail.getRecentCode());
            Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()};
            Double[] currPosition = new Double[]{currCode.getX(), currCode.getY()};
            List<List<TaskPosDto>> pickGroups = new ArrayList<>();
            List<List<TaskPosDto>> dropGroups = new ArrayList<>();
@@ -482,7 +492,7 @@
            List<Segment> segmentList = new ArrayList<>();
            for (List<TaskPosDto> dtoList : list) {
                for (TaskPosDto taskPosDto : dtoList) {
                    segSerial ++;
                    segSerial++;
                    AgvBackpackType backpackType = AgvBackpackDto.find(backpackDtoList, taskPosDto.getTaskId());
                    assert null != backpackType;
@@ -530,9 +540,12 @@
    /**
     * 充电 回待机位任务
     */
    @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
    @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(Long agvId, TaskTypeType taskType, String destination, Jam jam) {
        if (Cools.isEmpty(agvId, taskType)) { return false; }
        if (Cools.isEmpty(agvId, taskType)) {
            return false;
        }
        try {
            String agvNo = agvService.getAgvNo(agvId);
            if (!agvService.judgeEnable(agvId)) {
@@ -579,7 +592,7 @@
            task.setAgvId(agvId);
            task.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
            List<Task> lastTasks = taskService.list(new LambdaQueryWrapper<Task>().orderByDesc(Task::getId));
            task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks)?null:lastTasks.get(0).getSeqNum()));
            task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks) ? null : lastTasks.get(0).getSeqNum()));
            task.setOriCode(agvDetail.getCode());
            task.setDestCode(endCode.getId());
            // lane
@@ -587,7 +600,7 @@
            if (null != destLane) {
                task.setDestLaneHash(destLane.getHashCode());
            }
            task.setPriority(taskType.equals(TaskTypeType.TO_CHARGE)?2:1);
            task.setPriority(taskType.equals(TaskTypeType.TO_CHARGE) ? 2 : 1);
            task.setTaskSts(TaskStsType.ASSIGN.val());
            task.setTaskType(taskType.val());
            task.setIoTime(now);
@@ -595,6 +608,7 @@
            if (!taskService.save(task)) {
                throw new BusinessException(task.getSeqNum() + " failed to save");
            }
            // generate travel
            Travel travel = new Travel();
@@ -609,13 +623,20 @@
            }
            // generate segment
            int segSerial = 0;     segSerial ++;
            int segSerial = 0;
            segSerial++;
            List<Segment> segmentList = new ArrayList<>();
            String posType = "";
            switch (taskType){
            switch (taskType) {
                case TO_CHARGE:
                    posType = TaskPosDto.PosType.TO_CHARGE.toString();
                    //插入充电任务
                    AgvDuration agvDuration = new AgvDuration();
                    agvDuration.setHappenTime(now);
                    agvDuration.setAgvId(agvId);
                    agvDuration.setTaskNo(task.getId());
                    agvDurationService.save(agvDuration);
                    break;
                case TO_STANDBY:
                    posType = TaskPosDto.PosType.TO_STANDBY.toString();
@@ -685,7 +706,9 @@
    @Transactional
    public synchronized void generateAction(Long agvId, List<Segment> segmentList, List<String> pathList, Date algoStartTime) {
        try {
            if (Cools.isEmpty(agvId, segmentList)) { return; }
            if (Cools.isEmpty(agvId, segmentList)) {
                return;
            }
            Date now = new Date();
            long actionPrepareSts = ActionStsType.PREPARE.val();
//            JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class);
@@ -727,7 +750,9 @@
                    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; }
                        if (i == 0) {
                            continue;
                        }
                        String next = pathListPart.get(i);
@@ -936,7 +961,7 @@
                                task.getBusId(),    // 总线
                                task.getId(),    // 任务
                                null,    // 动作号
                                 null,    // 优先级
                                null,    // 优先级
                                ActionTypeType.ReadyReleaseToShelvesLoc.desc,    // 名称
                                (double) agvDirectionType.val,    // 属性值
                                lastCode.getData(),    // 地面码
@@ -1213,6 +1238,13 @@
            if (Cools.isEmpty(actionList)) {
                return;
            }
            Long agvId = actionList.get(0).getAgvId();
            String agvNo = agvService.getAgvNo(agvId);
            if (!agvService.judgeOnline(agvId)) {
                return;
            }
            long actionIssuedSts = ActionStsType.ISSUED.val();
            for (Action action : actionList) {
                action.setActionSts(actionIssuedSts);
@@ -1239,7 +1271,6 @@
                }
            }
            String agvNo = agvService.getAgvNo(actionList.get(0).getAgvId());
            AgvAction agvAction = new AgvAction(agvNo, actionGroupId);
            for (Action action : actionList) {
                switch (Objects.requireNonNull(ActionTypeType.get(action.getActionTypeEl()))) {
@@ -1431,9 +1462,9 @@
                // segment list
                List<Segment> segmentList = segmentService.list(new LambdaQueryWrapper<Segment>()
                        .eq(Segment::getGroupId, serialNo)
                                .eq(Segment::getGroupId, serialNo)
//                        .eq(Segment::getState, SegmentStateType.RUNNING.toString())
                        .orderByAsc(Segment::getSerial)
                                .orderByAsc(Segment::getSerial)
                );
                // settlement
@@ -1463,8 +1494,10 @@
        for (Segment segment : segmentList) {
            boolean taskComplete = false;
            Task task = taskService.getById(segment.getTaskId());   assert null != task;
            TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl());     assert null != typeType;
            Task task = taskService.getById(segment.getTaskId());
            assert null != task;
            TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl());
            assert null != typeType;
            TaskPosDto.PosType posType = TaskPosDto.queryPosType(segment.getPosType());
            switch (Objects.requireNonNull(posType)) {
@@ -1500,6 +1533,21 @@
                    log.error("Task [{}] 更新失败 !!!", task.getSeqNum());
                } else {
                    log.info("Task [{}] 作业完毕 ==========>> ", task.getSeqNum());
                    // TODO 插入一条上报记录
                    TaskReport taskReport = new TaskReport();
                    taskReport.setAgvId(task.getAgvId());
                    taskReport.setBusNo(task.getBusId$());
                    taskReport.setCreateTime(new Date());
                    taskReport.setDestLoc(task.getDestLoc());
                    taskReport.setDestSta(task.getDestSta());
                    taskReport.setSeqNum(task.getSeqNum());
                    taskReport.setTaskSts(task.getTaskSts());
                    taskReport.setOriLoc(task.getOriLoc());
                    taskReport.setOriSta(task.getOriSta());
                    taskReport.setZpallet(task.getZpallet());
                    if (!taskReportService.save(taskReport)) {
                        log.info("TaskReport [{}] 插入失败 ==========>> ", JSON.toJSONString(taskReport));
                    }
                }
            }