#
Junjie
2024-04-08 79603e53c78e535dba4bfbc69b8c3b5c184012c5
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/timer/MotionTimer.java
@@ -4,14 +4,15 @@
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.kernel.command.AgvCommandService;
import com.zy.asrs.wcs.core.kernel.command.CraneCommandService;
import com.zy.asrs.wcs.core.kernel.command.LiftCommandService;
import com.zy.asrs.wcs.core.kernel.command.ShuttleCommandService;
import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
import com.zy.asrs.wcs.core.model.enums.MotionStsType;
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
import com.zy.asrs.wcs.core.service.TaskService;
import com.zy.asrs.wcs.rcs.entity.Motion;
import com.zy.asrs.wcs.rcs.service.MotionService;
import com.zy.asrs.wcs.core.entity.Motion;
import com.zy.asrs.wcs.core.service.MotionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@@ -38,13 +39,13 @@
//    private ConveyorCommandService conveyorCommandService;
    @Autowired
    private CraneCommandService craneCommandService;
//    @Autowired
//    private LiftCommandService liftCommandService;
    @Autowired
    private LiftCommandService liftCommandService;
    @Autowired
    private ShuttleCommandService shuttleCommandService;
    @Scheduled(cron = "0/1 * * * * ? ")
    public synchronized void executeWrkMast() {
//    @Scheduled(cron = "0/1 * * * * ? ")
    public synchronized void executeTask() {
        Date now = new Date();
        // ANALYZE_INBOUND
        for (Task task : taskService.selectByAnalyzeSts()) {
@@ -60,13 +61,13 @@
                    continue;
                }
                // 更新wrkMast
                switch (TaskStsType.query(task.getTaskSts())) {
                // 更新Task
                switch (TaskStsType.queryById(task.getTaskSts())) {
                    case ANALYZE_INBOUND:
                        task.setTaskSts(TaskStsType.EXECUTE_INBOUND.sts);
                        task.setTaskSts(TaskStsType.EXECUTE_INBOUND.getId());
                        break;
                    case ANALYZE_OUTBOUND:
                        task.setTaskSts(TaskStsType.EXECUTE_OUTBOUND.sts);
                        task.setTaskSts(TaskStsType.EXECUTE_OUTBOUND.getId());
                        break;
                }
                task.setUpdateTime(now);
@@ -89,13 +90,13 @@
                        continue;
                    }
                    // 更新wrkMast
                    switch (TaskStsType.query(task.getTaskSts())) {
                    // 更新Task
                    switch (TaskStsType.queryById(task.getTaskSts())) {
                        case EXECUTE_INBOUND:
                            task.setTaskSts(TaskStsType.COMPLETE_INBOUND.sts);
                            task.setTaskSts(TaskStsType.COMPLETE_INBOUND.getId());
                            break;
                        case EXECUTE_OUTBOUND:
                            task.setTaskSts(TaskStsType.COMPLETE_OUTBOUND.sts);
                            task.setTaskSts(TaskStsType.COMPLETE_OUTBOUND.getId());
                            break;
                    }
                    task.setUpdateTime(now);
@@ -170,6 +171,63 @@
//        }
//    }
//    @Scheduled(cron = "0/1 * * * * ? ")
    public synchronized void executeManualTask() {
        Date now = new Date();
        // ANALYZE_MANUAL
        for (Task task : taskService.selectByAnalyzeSts()) {
            Motion executingMotion = motionService.selectOfTop1(task.getUuid(), MotionStsType.EXECUTING.val(), task.getHostId());
            if (executingMotion != null) {//存在正在执行的motion
                continue;
            }
            Motion motion = motionService.selectOfTop1(task.getUuid(), MotionStsType.INIT.val(), task.getHostId());
            if (null != motion) {
                boolean result = this.executeMotion(motion);
                if (!result) {
                    continue;
                }
                // 更新Task
                switch (TaskStsType.queryById(task.getTaskSts())) {
                    case ANALYZE_MANUAL:
                        task.setTaskSts(TaskStsType.EXECUTE_MANUAL.getId());
                        break;
                }
                task.setUpdateTime(now);
                if (!taskService.updateById(task)) {
                    log.error("{}其他工作档更新状态失败!", task.getTaskNo());
                }
            }
        }
        // EXECUTE_MANUAL
        for (Task task : taskService.selectManualByExecuteSts()) {
            if (!motionService.hasRunningMotion(task.getUuid(), task.getHostId())) {
                Motion motion = motionService.selectOfTop1(task.getUuid(), MotionStsType.WAITING.val(), task.getHostId());
                if (null != motion) {
                    boolean result = this.executeMotion(motion);
                    if (!result) {
                        continue;
                    }
                } else {
                    if (motionService.selectOfTop1(task.getUuid(), MotionStsType.EXECUTING.val(), task.getHostId()) != null) {
                        continue;
                    }
                    // 更新Task
                    switch (TaskStsType.queryById(task.getTaskSts())) {
                        case EXECUTE_MANUAL:
                            task.setTaskSts(TaskStsType.COMPLETE_MANUAL.getId());
                            break;
                    }
                    task.setUpdateTime(now);
                    if (!taskService.updateById(task)) {
                        log.error("{}他工作档更新状态失败!", task.getTaskNo());
                    }
                }
            }
        }
    }
    @Scheduled(cron = "0/1 * * * * ? ")
    public void scanMotionByExecuting() {
        List<Motion> motionList = motionService.selectBySts(MotionStsType.EXECUTING.val());
@@ -191,7 +249,7 @@
                executeRes = shuttleCommandService.accept(motion);
                break;
            case LIFT:
//                executeRes = liftCommandService.accept(motion);
                executeRes = liftCommandService.accept(motion);
                break;
            case AGV:
                executeRes = agvCommandService.accept(motion);
@@ -223,7 +281,7 @@
            case CRANE:
                break;
            case LIFT:
//                executeRes = liftCommandService.finish(motion);
                executeRes = liftCommandService.finish(motion);
                break;
            case SHUTTLE:
                executeRes = shuttleCommandService.finish(motion);