#
Junjie
2025-07-06 0d04bc5d8080b82338302fba0a59fccff2eaedfc
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/LiftAction.java
@@ -1,14 +1,17 @@
package com.zy.asrs.wcs.core.action;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.model.command.*;
import com.zy.asrs.wcs.core.model.enums.LiftCommandModeType;
import com.zy.asrs.wcs.core.service.TaskService;
import com.zy.asrs.wcs.core.utils.RedisUtil;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType;
import com.zy.asrs.wcs.rcs.model.enums.LiftProtocolStatusType;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
import com.zy.asrs.wcs.rcs.thread.LiftThread;
@@ -22,6 +25,8 @@
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private TaskService taskService;
    public synchronized boolean assignWork(Device device, LiftAssignCommand assignCommand) {
        LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getId().intValue());
@@ -41,7 +46,7 @@
        redisCommand.setAssignCommand(assignCommand);//命令
        //任务数据保存到redis
        if (redisUtil.set(DeviceRedisConstant.LIFT_WORK_FLAG + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand))) {
            liftProtocol.setTaskNo(assignCommand.getTaskNo());
            liftThread.setSyncTaskNo(assignCommand.getTaskNo());
            return true;
        }
        return false;
@@ -50,6 +55,11 @@
    public synchronized boolean executeWork(Device device, Integer taskNo) {
        Object obj = redisUtil.get(DeviceRedisConstant.LIFT_WORK_FLAG + taskNo);
        if (obj == null) {
            return false;
        }
        Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getTaskNo, taskNo));
        if (task == null) {
            return false;
        }
@@ -68,11 +78,8 @@
            return false;
        }
        //提升机处于自动、就绪、空闲
        if (!(liftProtocol.getModel()
                && liftProtocol.getReady()
                && !liftProtocol.getRun())
        ) {
        //判断提升机是否空闲
        if (!liftThread.isDeviceIdle()) {
            return false;
        }
@@ -86,22 +93,57 @@
        if (commandStep != 0) {
            LiftCommand command = commands.get(commandStep - 1);
            if (command.getMode() == LiftCommandModeType.MOVE.id) {
                //提升机升降
                if (liftProtocol.getLev() == command.getTargetLev()) {
                    command.setComplete(true);
                }
            } else if (command.getMode() == LiftCommandModeType.MOVE_CAR.id) {
                //提升机升降小车
                if (liftProtocol.getLev() == command.getTargetLev()) {
                    command.setComplete(true);
                }
            } else if (command.getMode() == LiftCommandModeType.PALLET_INOUT.id) {
                //托盘出入
                if (liftProtocol.getLev() == command.getTargetLev()) {
                    command.setComplete(true);
                }
            //目前没有判断,直接判定上一条指令完成
            command.setComplete(true);
                if (task.getTaskSts() < 100) {//入库判断托盘是否进入提升机
                    if (!liftProtocol.getHasTray()) {
                        return false;
                    }
                } else if (task.getTaskSts() >= 100 && task.getTaskSts() < 200) {//出库判断托盘是否离开提升机
                    if (liftProtocol.getHasTray()) {
                        return false;
                    }
                }
            } else if (command.getMode() == LiftCommandModeType.RESET.id) {
                //复位
                command.setComplete(true);
            } else if (command.getMode() == LiftCommandModeType.LOCK.id) {
                //复位
                command.setComplete(true);
            } else if (command.getMode() == LiftCommandModeType.UNLOCK.id) {
                //复位
                command.setComplete(true);
            }
            // 更新redis数据
            redisUtil.set(DeviceRedisConstant.LIFT_WORK_FLAG + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
            redisUtil.set(DeviceRedisConstant.LIFT_WORK_FLAG + taskNo, JSON.toJSONString(redisCommand));
            if (!command.getComplete()) {
                return false;
            }
            //判断是否为最后一条命令且命令执行完成,抛出等待确认状态
            LiftCommand endCommand = commands.get(commands.size() - 1);
            if (endCommand.getComplete()) {
                News.info("提升机任务执行下发完成等待执行结束,提升机号={},任务数据={}", liftProtocol.getLiftNo(), JSON.toJSON(commands));
                //对主线程抛出等待确认状态waiting
                liftThread.setProtocolStatus(LiftProtocolStatusType.WAITING);
                redisUtil.del(DeviceRedisConstant.LIFT_WORK_FLAG + taskNo);
                return false;//禁止再下发命令
            }
        }
@@ -117,7 +159,12 @@
            News.info("提升机命令下发成功,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command));
        }
        redisUtil.del(DeviceRedisConstant.LIFT_WORK_FLAG + command.getTaskNo());
        liftThread.setProtocolStatus(LiftProtocolStatusType.WORKING);
        commandStep++;
        //更新redis数据
        redisCommand.setCommandStep(commandStep);
        // 更新redis数据
        redisUtil.set(DeviceRedisConstant.LIFT_WORK_FLAG + taskNo, JSON.toJSONString(redisCommand));
        return true;
    }