#
zjj
2025-04-08 3df03c486fde77ab36b9298a94bdbb0aa065a7e2
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/LiftAction.java
@@ -6,18 +6,23 @@
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.LiftDispatcher;
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.BasLiftOpt;
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.model.CommandResponse;
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.service.BasLiftOptService;
import com.zy.asrs.wcs.rcs.thread.LiftThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
@Component
@@ -27,6 +32,10 @@
    private RedisUtil redisUtil;
    @Autowired
    private TaskService taskService;
    @Autowired
    private BasLiftOptService basLiftOptService;
    @Autowired
    private LiftDispatcher liftDispatcher;
    public synchronized boolean assignWork(Device device, LiftAssignCommand assignCommand) {
        LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getId().intValue());
@@ -95,7 +104,8 @@
            LiftCommand command = commands.get(commandStep - 1);
            if (command.getMode() == LiftCommandModeType.MOVE.id) {
                //提升机升降
                if (liftProtocol.getLev() == command.getTargetLev()) {
                Integer target = liftDispatcher.getLiftLevLogic(liftThread.getDevice().getId().intValue(), command.getTargetLev());
                if (liftProtocol.getLev() == target) {
                    command.setComplete(true);
                }
            } else if (command.getMode() == LiftCommandModeType.MOVE_CAR.id) {
@@ -103,29 +113,37 @@
                if (liftProtocol.getLev() == command.getTargetLev()) {
                    command.setComplete(true);
                }
            } else if (command.getMode() == LiftCommandModeType.PALLET_INOUT.id) {
                //托盘出入
                if (liftProtocol.getLev() == command.getTargetLev()) {
            } else if (command.getMode() == LiftCommandModeType.PALLET_IN.id) {
                //托盘入
                Integer target = liftDispatcher.getLiftLevLogic(liftThread.getDevice().getId().intValue(), command.getTargetLev());
                if (liftProtocol.getLev() == target) {
                    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;
                    }
                //判断提升机托盘是否存在
                if (!liftProtocol.getHasTray()) {
                    return false;
                }
            } else if (command.getMode() == LiftCommandModeType.PALLET_OUT.id) {
                //托盘出
                Integer target = liftDispatcher.getLiftLevLogic(liftThread.getDevice().getId().intValue(), command.getTargetLev());
                if (liftProtocol.getLev() == target) {
                    command.setComplete(true);
                }
                //判断提升机托盘是否存在
                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);
            }
@@ -151,8 +169,26 @@
        //取出命令
        LiftCommand command = commands.get(commandStep);
        boolean result = write(command, device);
        if (!result) {
        // 下发命令
        CommandResponse response = write(command, device);
        //保存命令日志
        BasLiftOpt basLiftOpt = new BasLiftOpt();
        basLiftOpt.setTaskNo(taskNo);
        basLiftOpt.setLiftNo(liftProtocol.getLiftNo());
        basLiftOpt.setMode(LiftCommandModeType.get(command.getMode()).desc);
        basLiftOpt.setCommand(JSON.toJSONString(command));
        basLiftOpt.setSystemStatus(JSON.toJSONString(liftProtocol));
        basLiftOpt.setDeviceId(device.getId());
        basLiftOpt.setDeviceWrk(String.valueOf(command.getTaskNo()));
        basLiftOpt.setResponse(response.getMessage());//获取响应
        basLiftOpt.setSendTime(new Date());//指令下发时间
        basLiftOpt.setSend(response.getResult() ? 1 : 0);
        basLiftOpt.setHostId(device.getHostId());
        //保存命令流水
        basLiftOptService.save(basLiftOpt);
        if (!response.getResult()) {
            News.error("提升机命令下发失败,提升机号={},任务数据={}", command.getLiftNo(), JSON.toJSON(command));
            return false;
        } else {
@@ -168,30 +204,31 @@
        return true;
    }
    private synchronized boolean write(LiftCommand command, Device device) {
    private synchronized CommandResponse write(LiftCommand command, Device device) {
        CommandResponse response = new CommandResponse(false);
        if (null == command) {
            News.error("提升机写入命令为空");
            return false;
            response.setMessage("提升机写入命令为空");
            return response;
        }
        LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getId().intValue());
        if (liftThread == null) {
            return false;
            return response;
        }
        boolean result = false;
        if (command.getMode() == LiftCommandModeType.MOVE.id) {
            result = liftThread.move(command);
        } else if (command.getMode() == LiftCommandModeType.PALLET_INOUT.id) {
            result = liftThread.palletInOut(command);
            response = liftThread.move(command);
        } else if (command.getMode() == LiftCommandModeType.PALLET_IN.id || command.getMode() == LiftCommandModeType.PALLET_OUT.id) {
            response = liftThread.palletInOut(command);
        } else if (command.getMode() == LiftCommandModeType.LOCK.id) {
            result = liftThread.lock(command);
            response = liftThread.lock(command);
        } else if (command.getMode() == LiftCommandModeType.UNLOCK.id) {
            result = liftThread.unlock(command);
            response = liftThread.unlock(command);
        } else if (command.getMode() == LiftCommandModeType.RESET.id) {
            result = liftThread.reset(command);
            response = liftThread.reset(command);
        }
        return result;
        return response;
    }
}