#
Junjie
2024-09-26 a032e83b86f182f2939454949129adfece45ebed
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/timer/MotionTimer.java
@@ -1,5 +1,6 @@
package com.zy.asrs.wcs.core.timer;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.kernel.command.*;
@@ -40,6 +41,8 @@
    private LiftCommandService liftCommandService;
    @Autowired
    private ShuttleCommandService shuttleCommandService;
    @Autowired
    private MapCommandService mapCommandService;
    @Scheduled(cron = "0/1 * * * * ? ")
    public synchronized void executeTask() {
@@ -48,7 +51,17 @@
        for (Task task : taskService.selectByAnalyzeSts()) {
            Motion executingMotion = motionService.selectOfTop1(task.getUuid(), MotionStsType.EXECUTING.val(), task.getHostId());
            if (executingMotion != null) {//存在正在执行的motion
                continue;
                if (executingMotion.getSync() == 1) {//当前执行中的动作是同步动作,等待执行完成后再执行下一个动作
                    continue;
                }
                //异步动作,只允许下一条动作被执行
                Motion nextMotion = motionService.getOne(new LambdaQueryWrapper<Motion>().eq(Motion::getUuid, executingMotion.getUuid()).eq(Motion::getPriority, executingMotion.getPriority() - 1));
                if (nextMotion != null) {
                    if (!(nextMotion.getMotionSts() == MotionStsType.INIT.val() || nextMotion.getMotionSts() == MotionStsType.WAITING.val())) {
                        continue;//下一条动作已经被执行,不允许再执行后续动作
                    }
                }
            }
            Motion motion = motionService.selectOfTop1(task.getUuid(), MotionStsType.INIT.val(), task.getHostId());
@@ -112,7 +125,17 @@
        for (Task taskCharge : taskService.selectChargeByAnalyzeSts()) {
            Motion executingMotion = motionService.selectOfTop1(taskCharge.getUuid(), MotionStsType.EXECUTING.val(), taskCharge.getHostId());
            if (executingMotion != null) {//存在正在执行的motion
                continue;
                if (executingMotion.getSync() == 1) {//当前执行中的动作是同步动作,等待执行完成后再执行下一个动作
                    continue;
                }
                //异步动作,只允许下一条动作被执行
                Motion nextMotion = motionService.getOne(new LambdaQueryWrapper<Motion>().eq(Motion::getUuid, executingMotion.getUuid()).eq(Motion::getPriority, executingMotion.getPriority() - 1));
                if (nextMotion != null) {
                    if (!(nextMotion.getMotionSts() == MotionStsType.INIT.val() || nextMotion.getMotionSts() == MotionStsType.WAITING.val())) {
                        continue;//下一条动作已经被执行,不允许再执行后续动作
                    }
                }
            }
            Motion motion = motionService.selectOfTop1(taskCharge.getUuid(), MotionStsType.INIT.val(), taskCharge.getHostId());
@@ -169,13 +192,90 @@
    }
    @Scheduled(cron = "0/1 * * * * ? ")
    public synchronized void executeLadenMoveTask() {
        Date now = new Date();
        // ANALYZE_CHARGE
        for (Task taskCharge : taskService.selectLadenMoveByAnalyzeSts()) {
            Motion executingMotion = motionService.selectOfTop1(taskCharge.getUuid(), MotionStsType.EXECUTING.val(), taskCharge.getHostId());
            if (executingMotion != null) {//存在正在执行的motion
                if (executingMotion.getSync() == 1) {//当前执行中的动作是同步动作,等待执行完成后再执行下一个动作
                    continue;
                }
                //异步动作,只允许下一条动作被执行
                Motion nextMotion = motionService.getOne(new LambdaQueryWrapper<Motion>().eq(Motion::getUuid, executingMotion.getUuid()).eq(Motion::getPriority, executingMotion.getPriority() - 1));
                if (nextMotion != null) {
                    if (!(nextMotion.getMotionSts() == MotionStsType.INIT.val() || nextMotion.getMotionSts() == MotionStsType.WAITING.val())) {
                        continue;//下一条动作已经被执行,不允许再执行后续动作
                    }
                }
            }
            Motion motion = motionService.selectOfTop1(taskCharge.getUuid(), MotionStsType.INIT.val(), taskCharge.getHostId());
            if (null != motion) {
                boolean result = this.executeMotion(motion);
                if (!result) {
                    continue;
                }
                // 更新Task
                switch (TaskStsType.query(taskCharge.getTaskSts())) {
                    case ANALYZE_LADEN_MOVE:
                        taskCharge.setTaskSts(TaskStsType.EXECUTE_LADEN_MOVE.sts);
                        break;
                }
                taskCharge.setUpdateTime(now);
                if (!taskService.updateById(taskCharge)) {
                    log.error("{}其他工作档更新状态失败!", taskCharge.getTaskNo());
                }
            }
        }
        // EXECUTE_CHARGE
        for (Task taskCharge : taskService.selectLadenMoveByExecuteSts()) {
            if (!motionService.hasRunningMotion(taskCharge.getUuid(), taskCharge.getHostId())) {
                Motion motion = motionService.selectOfTop1(taskCharge.getUuid(), MotionStsType.WAITING.val(), taskCharge.getHostId());
                if (null != motion) {
                    boolean result = this.executeMotion(motion);
                    if (!result) {
                        continue;
                    }
                } else {
                    if (motionService.selectOfTop1(taskCharge.getUuid(), MotionStsType.EXECUTING.val(), taskCharge.getHostId()) != null) {
                        continue;
                    }
                    // 更新Task
                    switch (TaskStsType.query(taskCharge.getTaskSts())) {
                        case EXECUTE_LADEN_MOVE:
                            taskCharge.setTaskSts(TaskStsType.COMPLETE_LADEN_MOVE.sts);
                            break;
                    }
                    taskCharge.setUpdateTime(now);
                    if (!taskService.updateById(taskCharge)) {
                        log.error("{}他工作档更新状态失败!", taskCharge.getTaskNo());
                    }
                }
            }
        }
    }
    @Scheduled(cron = "0/1 * * * * ? ")
    public synchronized void executeManualTask() {
        Date now = new Date();
        // ANALYZE_MANUAL
        for (Task task : taskService.selectManualByAnalyzeSts()) {
            Motion executingMotion = motionService.selectOfTop1(task.getUuid(), MotionStsType.EXECUTING.val(), task.getHostId());
            if (executingMotion != null) {//存在正在执行的motion
                continue;
                if (executingMotion.getSync() == 1) {//当前执行中的动作是同步动作,等待执行完成后再执行下一个动作
                    continue;
                }
                //异步动作,只允许下一条动作被执行
                Motion nextMotion = motionService.getOne(new LambdaQueryWrapper<Motion>().eq(Motion::getUuid, executingMotion.getUuid()).eq(Motion::getPriority, executingMotion.getPriority() - 1));
                if (nextMotion != null) {
                    if (!(nextMotion.getMotionSts() == MotionStsType.INIT.val() || nextMotion.getMotionSts() == MotionStsType.WAITING.val())) {
                        continue;//下一条动作已经被执行,不允许再执行后续动作
                    }
                }
            }
            Motion motion = motionService.selectOfTop1(task.getUuid(), MotionStsType.INIT.val(), task.getHostId());
@@ -232,7 +332,17 @@
        for (Task task : taskService.selectMoveByAnalyzeSts()) {
            Motion executingMotion = motionService.selectOfTop1(task.getUuid(), MotionStsType.EXECUTING.val(), task.getHostId());
            if (executingMotion != null) {//存在正在执行的motion
                continue;
                if (executingMotion.getSync() == 1) {//当前执行中的动作是同步动作,等待执行完成后再执行下一个动作
                    continue;
                }
                //异步动作,只允许下一条动作被执行
                Motion nextMotion = motionService.getOne(new LambdaQueryWrapper<Motion>().eq(Motion::getUuid, executingMotion.getUuid()).eq(Motion::getPriority, executingMotion.getPriority() - 1));
                if (nextMotion != null) {
                    if (!(nextMotion.getMotionSts() == MotionStsType.INIT.val() || nextMotion.getMotionSts() == MotionStsType.WAITING.val())) {
                        continue;//下一条动作已经被执行,不允许再执行后续动作
                    }
                }
            }
            Motion motion = motionService.selectOfTop1(task.getUuid(), MotionStsType.INIT.val(), task.getHostId());
@@ -308,6 +418,9 @@
            case AGV:
                executeRes = agvCommandService.accept(motion);
                break;
            case MAP:
                executeRes = mapCommandService.accept(motion);
                break;
            default:
                break;
        }
@@ -343,6 +456,9 @@
            case CONVEYOR:
                executeRes = conveyorCommandService.finish(motion);
                break;
            case MAP:
                executeRes = mapCommandService.finish(motion);
                break;
            default:
                break;
        }