|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.action.LiftAction; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.action.ShuttleAction; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.entity.Loc; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.NavigateNode; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.utils.*; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.News; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.entity.Motion; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.entity.Motion; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.service.MotionService; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.service.MotionService; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.thread.LiftThread; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.thread.ShuttleThread; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | 
|---|
|  |  |  | private LocService locService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NavigateMapUtils navigateMapUtils; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShuttleAction shuttleAction; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LiftAction liftAction; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 计算 | 
|---|
|  |  |  | public Boolean accept(Motion motion) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); | 
|---|
|  |  |  | assignCommand.setShuttleNo(deviceNo.shortValue()); | 
|---|
|  |  |  | assignCommand.setTaskNo(motion.getWrkNo().shortValue()); | 
|---|
|  |  |  | assignCommand.setShuttleNo(deviceNo); | 
|---|
|  |  |  | assignCommand.setTaskNo(motion.getWrkNo()); | 
|---|
|  |  |  | assignCommand.setSourceLocNo(motion.getOrigin()); | 
|---|
|  |  |  | assignCommand.setLocNo(motion.getTarget()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ShuttleCommand> shuttleCommands = new ArrayList<>(); | 
|---|
|  |  |  | ShuttleTaskModeType shuttleTaskModeType = null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        SiemensLiftThread liftThread = null; | 
|---|
|  |  |  | //        LiftProtocol liftProtocol = null; | 
|---|
|  |  |  | LiftThread liftThread = null; | 
|---|
|  |  |  | LiftProtocol liftProtocol = null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断小车状态 | 
|---|
|  |  |  | if (shuttleProtocol.getIdle() | 
|---|
|  |  |  | 
|---|
|  |  |  | shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | //            case SHUTTLE_MOVE_LIFT_PALLET://穿梭车顶升并移动 | 
|---|
|  |  |  | //                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | //                shuttleTaskModeType = ShuttleTaskModeType.PAK_IN; | 
|---|
|  |  |  | //                shuttleCommands.add(0, shuttleThread.getPalletCommand((short) 1)); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case SHUTTLE_MOVE_DOWN_PALLET://穿梭车移动并托盘下降 | 
|---|
|  |  |  | //                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | //                shuttleTaskModeType = ShuttleTaskModeType.PAK_IN; | 
|---|
|  |  |  | //                shuttleCommands.add(shuttleCommands.size(), shuttleThread.getPalletCommand((short) 2)); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case SHUTTLE_MOVE_FROM_LIFT://出提升机 | 
|---|
|  |  |  | //                // 判断提升机状态 | 
|---|
|  |  |  | //                liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp())); | 
|---|
|  |  |  | //                if (liftThread == null) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                liftProtocol = liftThread.getLiftProtocol(); | 
|---|
|  |  |  | //                // 判断提升机是否自动、空闲、准备就绪、链条没有转动、没有未就绪报错 | 
|---|
|  |  |  | //                if (!liftProtocol.getMode() | 
|---|
|  |  |  | //                        || liftProtocol.getRunning() | 
|---|
|  |  |  | //                        || !liftProtocol.getReady() | 
|---|
|  |  |  | //                        || liftProtocol.getForwardRotationFeedback() | 
|---|
|  |  |  | //                        || liftProtocol.getReverseFeedback() | 
|---|
|  |  |  | //                        || liftProtocol.getNotReady().intValue() != 0 | 
|---|
|  |  |  | //                ) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | case SHUTTLE_MOVE_LIFT_PALLET://穿梭车顶升并移动 | 
|---|
|  |  |  | shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | shuttleTaskModeType = ShuttleTaskModeType.PAK_IN; | 
|---|
|  |  |  | shuttleCommands.add(0, shuttleThread.getLiftCommand(motion.getWrkNo(), true)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case SHUTTLE_MOVE_DOWN_PALLET://穿梭车移动并托盘下降 | 
|---|
|  |  |  | shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | shuttleTaskModeType = ShuttleTaskModeType.PAK_IN; | 
|---|
|  |  |  | shuttleCommands.add(shuttleCommands.size(), shuttleThread.getLiftCommand(motion.getWrkNo(), false)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case SHUTTLE_MOVE_FROM_LIFT://出提升机 | 
|---|
|  |  |  | // 判断提升机状态 | 
|---|
|  |  |  | liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp())); | 
|---|
|  |  |  | if (liftThread == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | liftProtocol = liftThread.getStatus(); | 
|---|
|  |  |  | if (liftProtocol == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 判断提升机是否空闲 | 
|---|
|  |  |  | if (!liftThread.isIdle()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (liftProtocol.getLev() != Utils.getLev(motion.getTarget())) {//判断提升机是否达到目标层 | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                //判断提升机是否被锁定 | 
|---|
|  |  |  | //                if (!liftProtocol.getLock()) { | 
|---|
|  |  |  | //                    //锁定提升机 | 
|---|
|  |  |  | //                    LiftCommand lockCommand = liftThread.getLockCommand(motion.getWrkNo(), true);//获取提升机锁定命令 | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                if (liftProtocol.getLev().intValue() != Utils.getLev(motion.getTarget())) {//判断提升机是否达到目标层 | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                    LiftAssignCommand liftAssignCommand = new LiftAssignCommand(); | 
|---|
|  |  |  | //                    liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo()); | 
|---|
|  |  |  | //                    liftAssignCommand.setTaskNo(motion.getWrkNo()); | 
|---|
|  |  |  | //                    ArrayList<LiftCommand> list = new ArrayList<>(); | 
|---|
|  |  |  | //                    list.add(lockCommand); | 
|---|
|  |  |  | //                    liftAssignCommand.setCommands(list); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                    liftAction.assignWork(liftThread.getDevice(), liftAssignCommand); | 
|---|
|  |  |  | //                    return false;//等待下一次轮询 | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case SHUTTLE_MOVE_TO_LIFT://进提升机 | 
|---|
|  |  |  | // 判断提升机状态 | 
|---|
|  |  |  | liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp())); | 
|---|
|  |  |  | if (liftThread == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | liftProtocol = liftThread.getStatus(); | 
|---|
|  |  |  | if (liftProtocol == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 判断提升机是否空闲 | 
|---|
|  |  |  | if (!liftThread.isIdle()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (liftProtocol.getLev() != Utils.getLev(motion.getTarget())) {//判断提升机是否达到目标层 | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                //判断提升机是否被锁定 | 
|---|
|  |  |  | //                if (!liftProtocol.getLiftLock()) { | 
|---|
|  |  |  | //                    //锁定提升机 | 
|---|
|  |  |  | 
|---|
|  |  |  | //                    liftThread.assignWork(lockCommand); | 
|---|
|  |  |  | //                    return false;//等待下一次轮询 | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | //                if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | //                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case SHUTTLE_MOVE_TO_LIFT://进提升机 | 
|---|
|  |  |  | //                // 判断提升机状态 | 
|---|
|  |  |  | //                liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp())); | 
|---|
|  |  |  | //                if (liftThread == null) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                liftProtocol = liftThread.getLiftProtocol(); | 
|---|
|  |  |  | //                // 判断提升机是否自动、空闲、准备就绪、链条没有转动、没有未就绪报错 | 
|---|
|  |  |  | //                if (!liftProtocol.getMode() | 
|---|
|  |  |  | //                        || liftProtocol.getRunning() | 
|---|
|  |  |  | //                        || !liftProtocol.getReady() | 
|---|
|  |  |  | //                        || liftProtocol.getForwardRotationFeedback() | 
|---|
|  |  |  | //                        || liftProtocol.getReverseFeedback() | 
|---|
|  |  |  | //                        || liftProtocol.getNotReady().intValue() != 0 | 
|---|
|  |  |  | //                ) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                if (liftProtocol.getLev().intValue() != Utils.getLev(motion.getTarget())) {//判断提升机是否达到目标层 | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                //判断提升机是否被锁定 | 
|---|
|  |  |  | //                if (!liftProtocol.getLiftLock()) { | 
|---|
|  |  |  | //                    //锁定提升机 | 
|---|
|  |  |  | //                    LiftCommand lockCommand = liftThread.getLockCommand(true);//获取提升机锁定命令 | 
|---|
|  |  |  | //                    lockCommand.setLiftNo(liftProtocol.getLiftNo()); | 
|---|
|  |  |  | //                    lockCommand.setTaskNo(motion.getWrkNo().shortValue());//获取任务号 | 
|---|
|  |  |  | //                    liftThread.assignWork(lockCommand); | 
|---|
|  |  |  | //                    return false;//等待下一次轮询 | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | //                if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | //                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断提升机工作号是否和当前任务相同 | 
|---|
|  |  |  | if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | //            case SHUTTLE_MOVE_FROM_CONVEYOR: | 
|---|
|  |  |  | //                shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); | 
|---|
|  |  |  | //                shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | assert null != shuttleTaskModeType; | 
|---|
|  |  |  | assignCommand.setTaskMode(shuttleTaskModeType.id.shortValue());//入出库模式 | 
|---|
|  |  |  | assignCommand.setTaskMode(shuttleTaskModeType.id);//入出库模式 | 
|---|
|  |  |  | assignCommand.setCommands(shuttleCommands); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (motion.getOrigin() != null && motion.getTarget() != null) { | 
|---|
|  |  |  | //所使用的路径进行锁定禁用 | 
|---|
|  |  |  | boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), Integer.parseInt(shuttleProtocol.getShuttleNo()), assignCommand.getNodes(), true);//所使用的路径进行锁定禁用 | 
|---|
|  |  |  | boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), shuttleProtocol.getShuttleNo(), assignCommand.getNodes(), true);//所使用的路径进行锁定禁用 | 
|---|
|  |  |  | if (!lockResult) { | 
|---|
|  |  |  | return false;//锁定失败 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            shuttleThread.assignWork(assignCommand); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | //            shuttleThread.assignWork(assignCommand); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return Boolean.TRUE; | 
|---|
|  |  |  | boolean result = shuttleAction.assignWork(shuttleThread.getDevice(), assignCommand); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Boolean finish(Motion motion) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!shuttleProtocol.getIdle()) { | 
|---|
|  |  |  | //判断设备是否空闲 | 
|---|
|  |  |  | if (!shuttleThread.isIdle()) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|