#
zjj
2024-06-22 8a830f3e5f9ff3bca3161b5bf800abeb1a64e866
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
@@ -10,10 +10,7 @@
import com.zy.asrs.wcs.core.entity.BasShuttle;
import com.zy.asrs.wcs.core.entity.Loc;
import com.zy.asrs.wcs.core.model.NavigateNode;
import com.zy.asrs.wcs.core.model.command.LiftAssignCommand;
import com.zy.asrs.wcs.core.model.command.LiftCommand;
import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand;
import com.zy.asrs.wcs.core.model.command.ShuttleCommand;
import com.zy.asrs.wcs.core.model.command.*;
import com.zy.asrs.wcs.core.model.enums.*;
import com.zy.asrs.wcs.core.service.BasShuttleService;
import com.zy.asrs.wcs.core.service.LocService;
@@ -22,7 +19,6 @@
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.core.entity.Motion;
import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
@@ -61,6 +57,8 @@
    private ShuttleAction shuttleAction;
    @Autowired
    private LiftAction liftAction;
    @Autowired
    private LiftDispatcher liftDispatcher;
    // 计算
    public Boolean accept(Motion motion) {
@@ -141,11 +139,11 @@
                }
                // 判断提升机是否空闲
                if (!liftThread.isIdle()) {
                if (!liftThread.isIdle(MotionCtgType.SHUTTLE_MOVE_FROM_LIFT)) {
                    return false;
                }
                if (liftProtocol.getLev() != Utils.getLev(motion.getTarget())) {//判断提升机是否达到目标层
                if (liftProtocol.getLev() != liftDispatcher.getLiftLevOffset(liftThread.getDevice().getId().intValue(), Utils.getLev(motion.getTarget()))) {//判断提升机是否达到目标层
                    return false;
                }
@@ -156,24 +154,13 @@
                        return true;
                    }
                })) {
                    //锁定提升机
                    List<LiftCommand> lockCommand = liftThread.getLockCommand(motion.getTaskNo(), true);//获取提升机锁定命令
                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
                    liftAssignCommand.setTaskNo(motion.getTaskNo());
                    ArrayList<LiftCommand> list = new ArrayList<>();
                    list.addAll(lockCommand);
                    liftAssignCommand.setCommands(list);
                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
                    return false;//等待下一次轮询
                }
                //判断提升机工作号是否和当前任务相同
                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
                    return false;
                }
//                //判断提升机工作号是否和当前任务相同
//                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
//                    return false;
//                }
                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
@@ -189,11 +176,11 @@
                    return false;
                }
                // 判断提升机是否空闲
                if (!liftThread.isIdle()) {
                if (!liftThread.isIdle(MotionCtgType.SHUTTLE_MOVE_TO_LIFT)) {
                    return false;
                }
                if (liftProtocol.getLev() != Utils.getLev(motion.getTarget())) {//判断提升机是否达到目标层
                if (liftProtocol.getLev() != liftDispatcher.getLiftLevOffset(liftThread.getDevice().getId().intValue(), Utils.getLev(motion.getTarget()))) {//判断提升机是否达到目标层
                    return false;
                }
@@ -201,30 +188,16 @@
                if (!liftThread.isLock(new ExecuteSupport() {
                    @Override
                    public Boolean judgement() {
                        return true;
                        return true;//牛眼没有提升机锁,直接返回true
                    }
                })) {
                    //锁定提升机
                    List<LiftCommand> lockCommand = liftThread.getLockCommand(motion.getTaskNo(), true);//获取提升机锁定命令
                    if (lockCommand == null) {
                        return false;
                    }
                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
                    liftAssignCommand.setTaskNo(motion.getTaskNo());
                    ArrayList<LiftCommand> list = new ArrayList<>();
                    list.addAll(lockCommand);
                    liftAssignCommand.setCommands(list);
                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
                    return false;//等待下一次轮询
                }
                //判断提升机工作号是否和当前任务相同
                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
                    return false;
                }
//                //判断提升机工作号是否和当前任务相同
//                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
//                    return false;
//                }
                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
@@ -247,6 +220,10 @@
                shuttleTaskModeType = ShuttleTaskModeType.PALLET_DOWN;
                shuttleCommands.add(shuttleThread.getLiftCommand(motion.getTaskNo(), false));
                break;
            case SHUTTLE_UPDATE_LOCATION://小车坐标更新
                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_UPDATE_LOCATION;
                shuttleCommands.add(shuttleThread.getUpdateLocationCommand(motion.getTaskNo(), motion.getTarget()));
                break;
            default:
                throw new CoolException(motion.getMotionCtgEl() + "没有指定任务作业流程!!!");
        }
@@ -261,7 +238,7 @@
        if (motion.getOrigin() != null && motion.getTarget() != null) {
            //所使用的路径进行锁定禁用
            boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), shuttleProtocol.getShuttleNo(), assignCommand.getNodes(), true);//所使用的路径进行锁定禁用
            boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), shuttleProtocol.getShuttleNo(), assignCommand.getNodesDeepCopy(), true);//所使用的路径进行锁定禁用
            if (!lockResult) {
                return false;//锁定失败
            }
@@ -330,53 +307,24 @@
                }
                //判断提升机是否被锁定
                if (liftThread.isLock(new ExecuteSupport() {
                if (!liftThread.isLock(new ExecuteSupport() {
                    @Override
                    public Boolean judgement() {
                        return false;
                    }
                })) {
                    //解锁提升机
                    List<LiftCommand> lockCommand = liftThread.getLockCommand(motion.getTaskNo(), false);//获取提升机解锁命令
                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
                    liftAssignCommand.setTaskNo(motion.getTaskNo());
                    ArrayList<LiftCommand> list = new ArrayList<>();
                    list.addAll(lockCommand);
                    liftAssignCommand.setCommands(list);
                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
                    return false;//等待下一次轮询
                }
                //判断小车是否已到位
                if (liftProtocol.getHasCar()) {
                    List<LiftCommand> signalCommand = liftThread.getShuttleSignalCommand(motion.getTaskNo(), true);//获取小车已到位命令
                    if(signalCommand != null) {
                        boolean hasKey = redisUtil.hasKey(DeviceRedisConstant.COMMAND_TMP + motion.getTaskNo());
                        if (!hasKey) {
                            LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
                            liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
                            liftAssignCommand.setTaskNo(motion.getTaskNo());
                            ArrayList<LiftCommand> list = new ArrayList<>();
                            list.addAll(signalCommand);
                            liftAssignCommand.setCommands(list);
                            liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
                            return false;
                        }
                    }
                }
                //判断提升机工作号是否和当前任务相同
                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
                    return false;
                }
                if (liftProtocol.getTaskNo() != 0) {
                    //清空提升机号
                    liftThread.setSyncTaskNo(0);
                //判断小车是否已到位
                if (!liftProtocol.getHasCar()) {
                    return false;
                }
//                //判断提升机工作号是否和当前任务相同
//                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
//                    return false;
//                }
                break;
            case SHUTTLE_MOVE_FROM_LIFT:
                liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp()));
@@ -390,54 +338,24 @@
                }
                //判断提升机是否被锁定
                if (liftThread.isLock(new ExecuteSupport() {
                if (!liftThread.isLock(new ExecuteSupport() {
                    @Override
                    public Boolean judgement() {
                        return false;
                    }
                })) {
                    //解锁提升机
                    List<LiftCommand> lockCommand = liftThread.getLockCommand(motion.getTaskNo(), false);//获取提升机解锁命令
                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
                    liftAssignCommand.setTaskNo(motion.getTaskNo());
                    ArrayList<LiftCommand> list = new ArrayList<>();
                    list.addAll(lockCommand);
                    liftAssignCommand.setCommands(list);
                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
                    return false;//等待下一次轮询
                }
                //判断小车是否已离开
                if (!liftProtocol.getHasCar()) {
                    List<LiftCommand> signalCommand = liftThread.getShuttleSignalCommand(motion.getTaskNo(), false);//获取小车已驾离命令
                    if(signalCommand != null) {
                        boolean hasKey = redisUtil.hasKey(DeviceRedisConstant.COMMAND_TMP + motion.getTaskNo());
                        if (!hasKey) {
                            redisUtil.set(DeviceRedisConstant.COMMAND_TMP + motion.getTaskNo(), JSON.toJSONString(signalCommand), 120);
                            LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
                            liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
                            liftAssignCommand.setTaskNo(motion.getTaskNo());
                            ArrayList<LiftCommand> list = new ArrayList<>();
                            list.addAll(signalCommand);
                            liftAssignCommand.setCommands(list);
                            liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
                            return false;
                        }
                    }
                }
                //判断提升机工作号是否和当前任务相同
                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
                    return false;
                }
                if (liftProtocol.getTaskNo() != 0) {
                    //清空提升机号
                    liftThread.setSyncTaskNo(0);
                //判断小车是否已离开
                if (liftProtocol.getHasCar()) {
                    return false;
                }
//                //判断提升机工作号是否和当前任务相同
//                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
//                    return false;
//                }
                break;
            case SHUTTLE_TRANSPORT_FROM_LIFT:
            case SHUTTLE_TRANSPORT_TO_LIFT:
@@ -459,28 +377,24 @@
                        return false;
                    }
                })) {
                    //解锁提升机
                    List<LiftCommand> lockCommand = liftThread.getLockCommand(motion.getTaskNo(), false);//获取提升机解锁命令
                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
                    liftAssignCommand.setTaskNo(motion.getTaskNo());
                    ArrayList<LiftCommand> list = new ArrayList<>();
                    list.addAll(lockCommand);
                    liftAssignCommand.setCommands(list);
                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
                    return false;//等待下一次轮询
                    return false;
                }
                //判断提升机工作号是否和当前任务相同
                if (liftProtocol.getTaskNo().intValue() != motion.getTaskNo()) {
                    return false;
                }
                if (liftProtocol.getTaskNo() != 0) {
                    //清空提升机号
                    liftThread.setSyncTaskNo(0);
                break;
            case SHUTTLE_UPDATE_LOCATION://小车坐标更新
                break;
            case SHUTTLE_PALLET_LIFT://托盘顶升
                if (!shuttleProtocol.getHasLift()) {
                    return false;
                }
                break;
            case SHUTTLE_PALLET_DOWN://托盘下降
                if (shuttleProtocol.getHasLift()) {
                    return false;
                }
                break;
            default: