|  |  | 
 |  |  |  | 
 |  |  |                                 //判断提升机是否空闲 | 
 |  |  |                                 if (!liftProtocol.isIdle()) { | 
 |  |  |                                     try { | 
 |  |  |                                         Thread.sleep(1000);//休眠1s | 
 |  |  |                                     } catch (InterruptedException e) { | 
 |  |  |                                         throw new RuntimeException(e); | 
 |  |  |                                     } | 
 |  |  |                                     continue;//提升机忙 | 
 |  |  |                                 } | 
 |  |  |  | 
 |  |  | 
 |  |  |  | 
 |  |  |                         //判断提升机是否空闲 | 
 |  |  |                         if (!liftProtocol.isIdle()) { | 
 |  |  |                             try { | 
 |  |  |                                 Thread.sleep(1000);//休眠1s | 
 |  |  |                             } catch (InterruptedException e) { | 
 |  |  |                                 throw new RuntimeException(e); | 
 |  |  |                             } | 
 |  |  |                             continue;//提升机忙 | 
 |  |  |                         } | 
 |  |  |  | 
 |  |  | 
 |  |  |                             continue;//提升机不在目标楼层跳过 | 
 |  |  |                         } | 
 |  |  |  | 
 |  |  |                         Integer staNo = Utils.levToOutInStaNo(lev); | 
 |  |  |                         Integer staNo = Utils.levToOutInStaNo(lev >= 2 ? lev + 1 : lev); | 
 |  |  |                         DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1); | 
 |  |  |                         //获取目标站信息 | 
 |  |  |                         StaProtocol staProtocol1 = devpThread.getStation().get(staNo); | 
 |  |  | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     wrkMast.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());//给工作档分配四向穿梭车号 | 
 |  |  |                     //源库位(小车当前位置) | 
 |  |  |                     String currentLocNo = shuttleProtocol.getCurrentLocNo(); | 
 |  |  |  | 
 |  |  |                     //小车当前层高 | 
 |  |  |                     Integer currentLev = Utils.getLev(currentLocNo); | 
 |  |  |                     //获取提升机 | 
 |  |  |                     LiftSlave liftSlave = slaveProperties.getLift().get(0); | 
 |  |  |                     //当前楼层提升机输送站点库位号 | 
 |  |  |                     String liftSiteLocNo = Utils.levToOutInStaLocNo(currentLev); | 
 |  |  |  | 
 |  |  |                     //分配任务号 | 
 |  |  |                     shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue()); | 
 |  |  |                     //分配源库位 | 
 |  |  |                     shuttleProtocol.setSourceLocNo(currentLocNo); | 
 |  |  |  | 
 |  |  |                     ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); | 
 |  |  |                     //四向穿梭车号 | 
 |  |  |                     assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); | 
 |  |  |                     //任务号 | 
 |  |  |                     assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); | 
 |  |  |                     //入出库模式 | 
 |  |  |                     assignCommand.setTaskMode(ShuttleTaskModeType.PAK_OUT.id.shortValue()); | 
 |  |  |                     assignCommand.setSourceLocNo(currentLocNo); | 
 |  |  |  | 
 |  |  |                     if (wrkMast.getWrkSts() == 21) { | 
 |  |  |  | 
 |  |  |                         wrkMast.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());//给工作档分配四向穿梭车号 | 
 |  |  |                         //源库位(小车当前位置) | 
 |  |  |                         String currentLocNo = shuttleProtocol.getCurrentLocNo(); | 
 |  |  |  | 
 |  |  |                         //小车当前层高 | 
 |  |  |                         Integer currentLev = Utils.getLev(currentLocNo); | 
 |  |  |                         //当前楼层提升机输送站点库位号 | 
 |  |  |                         String liftSiteLocNo = Utils.levToOutInStaLocNo(currentLev); | 
 |  |  |  | 
 |  |  |                         ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); | 
 |  |  |                         //四向穿梭车号 | 
 |  |  |                         assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); | 
 |  |  |                         //任务号 | 
 |  |  |                         assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); | 
 |  |  |                         //入出库模式 | 
 |  |  |                         assignCommand.setTaskMode(ShuttleTaskModeType.PAK_OUT.id.shortValue()); | 
 |  |  |                         assignCommand.setSourceLocNo(currentLocNo); | 
 |  |  |  | 
 |  |  |                         //判断小车和库位是否在同一层 | 
 |  |  |                         if (Boolean.parseBoolean(searchIdleShuttle.get("sameLay").toString())) { | 
 |  |  |                             //同一层(将小车移动到货物位置) | 
 |  |  | 
 |  |  |                             } | 
 |  |  |                             //分配目标库位 | 
 |  |  |                             shuttleProtocol.setLocNo(wrkMast.getSourceLocNo()); | 
 |  |  |                             //分配任务号 | 
 |  |  |                             shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue()); | 
 |  |  |                             //分配源库位 | 
 |  |  |                             shuttleProtocol.setSourceLocNo(currentLocNo); | 
 |  |  |                             //目标库位 | 
 |  |  |                             assignCommand.setLocNo(wrkMast.getSourceLocNo()); | 
 |  |  |                             assignCommand.setCommands(commands); | 
 |  |  |                             wrkMast.setWrkSts(26L);//小车搬运中 | 
 |  |  |  | 
 |  |  |                             if (wrkMastMapper.updateById(wrkMast) > 0) { | 
 |  |  |                                 //下发任务 | 
 |  |  |                                 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); | 
 |  |  |                             } | 
 |  |  |                         }else { | 
 |  |  |                             //不同层,将目标库位分配成提升机库位号(将小车移动到提升机位置) | 
 |  |  |  | 
 |  |  |                             //小车到提升机口指令 | 
 |  |  |                             List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftSiteLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand, shuttleThread); | 
 |  |  |                             if (commands == null) { | 
 |  |  |                                 continue;//未找到路径 | 
 |  |  |                                 if (!currentLocNo.equals(liftSiteLocNo)) {//当前位置也不在提升机口 | 
 |  |  |                                     continue;//未找到路径 | 
 |  |  |                                 } | 
 |  |  |                                 commands = new ArrayList<>(); | 
 |  |  |                             } | 
 |  |  |                             shuttleProtocol.setLocNo(liftSiteLocNo); | 
 |  |  |                             //分配任务号 | 
 |  |  |                             shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue()); | 
 |  |  |                             //分配源库位 | 
 |  |  |                             shuttleProtocol.setSourceLocNo(currentLocNo); | 
 |  |  |  | 
 |  |  |                             //获取当前小车所在楼层的站点信息 | 
 |  |  |                             BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo); | 
 |  |  | 
 |  |  |                             assignCommand.setLocNo(liftSiteLocNo); | 
 |  |  |                             assignCommand.setCommands(commands); | 
 |  |  |                             wrkMast.setWrkSts(22L);//小车迁移状态 | 
 |  |  |  | 
 |  |  |                             if (wrkMastMapper.updateById(wrkMast) > 0) { | 
 |  |  |                                 //下发任务 | 
 |  |  |                                 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                     } else if (wrkMast.getWrkSts() == 25) { | 
 |  |  |                         List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), liftSiteLocNo, assignCommand, shuttleThread); | 
 |  |  |  | 
 |  |  |                         wrkMast.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());//给工作档分配四向穿梭车号 | 
 |  |  |  | 
 |  |  |                         //当前楼层提升机输送站点库位号 | 
 |  |  |                         String liftSiteLocNo = Utils.levToOutInStaLocNo(liftProtocol.getLev().intValue()); | 
 |  |  |  | 
 |  |  |                         ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); | 
 |  |  |                         //四向穿梭车号 | 
 |  |  |                         assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); | 
 |  |  |                         //任务号 | 
 |  |  |                         assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); | 
 |  |  |                         //入出库模式 | 
 |  |  |                         assignCommand.setTaskMode(ShuttleTaskModeType.PAK_OUT.id.shortValue()); | 
 |  |  |                         assignCommand.setSourceLocNo(liftSiteLocNo); | 
 |  |  |  | 
 |  |  |                         List<ShuttleCommand> commands = this.shuttleAssignCommand(liftSiteLocNo, wrkMast.getSourceLocNo(), liftSiteLocNo, assignCommand, shuttleThread); | 
 |  |  |                         if (commands == null) { | 
 |  |  |                             continue;//未找到路径 | 
 |  |  |                         } | 
 |  |  |                         //此时车在提升机内部,需要多下达一步指令让车移动到提升机口 | 
 |  |  |                         BasDevp basDevp = basDevpService.selectById(109);//获取提升机信息 | 
 |  |  |                         short startCode = Short.parseShort(basDevp.getQrCodeValue());//提升机二维码 | 
 |  |  |                         short startCode = liftProtocol.getBarcode();//提升机内部二维码 | 
 |  |  |                         Short distCode = commands.get(0).getStartCodeNum();//目标二维码 | 
 |  |  |                         //获取移动命令 | 
 |  |  |                         ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1300, commands.get(0).getRunDirection(), (short) 1, 0); | 
 |  |  |                         ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1400, commands.get(0).getRunDirection(), startCode, 1400, 500); | 
 |  |  |                         commands.add(0, moveCommand);//将该指令添加到队头 | 
 |  |  |  | 
 |  |  |                         //分配目标库位 | 
 |  |  |                         shuttleProtocol.setLocNo(wrkMast.getSourceLocNo()); | 
 |  |  |                         //分配任务号 | 
 |  |  |                         shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue()); | 
 |  |  |                         //分配源库位 | 
 |  |  |                         shuttleProtocol.setSourceLocNo(liftSiteLocNo); | 
 |  |  |                         //目标库位 | 
 |  |  |                         assignCommand.setLocNo(wrkMast.getSourceLocNo()); | 
 |  |  |                         assignCommand.setCommands(commands); | 
 |  |  |                         wrkMast.setWrkSts(26L);//小车搬运中 | 
 |  |  |  | 
 |  |  |                         if (wrkMastMapper.updateById(wrkMast) > 0) { | 
 |  |  |                             //下发任务 | 
 |  |  |                             MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     if (wrkMastMapper.updateById(wrkMast) > 0) { | 
 |  |  |                         //下发任务 | 
 |  |  |                         MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             //给提升机分配任务 | 
 |  |  |             liftProtocol.setLiftLock(true);//锁定提升机 | 
 |  |  |             liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号 | 
 |  |  |             liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中 | 
 |  |  |  | 
 |  |  |             //命令list | 
 |  |  |             ArrayList<LiftCommand> commands = new ArrayList<>(); | 
 |  |  |  | 
 |  |  | 
 |  |  |                 //工作档目标库位楼层 | 
 |  |  |                 int wrkMastLocNoLey = Utils.getLev(wrkMastLocNo); | 
 |  |  |  | 
 |  |  |                 //提升机当前楼层 | 
 |  |  |                 int liftLev = liftProtocol.getLev().intValue(); | 
 |  |  |                 if (liftLev == 0) {//提升机当前楼层为0,提升机失去位置信息,让提升机前往一楼 | 
 |  |  |                     LiftCommand command = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), LiftLevType.ONE.lev); | 
 |  |  |                     commands.add(command);//将命令添加进list | 
 |  |  |                 Integer levTmp = wrkMastLocNoLey; | 
 |  |  |                 if (wrkMastLocNoLey >= 2) { | 
 |  |  |                     levTmp += 1; | 
 |  |  |                 } | 
 |  |  |                 Integer distStaNo = Utils.levToOutInStaNo(levTmp); | 
 |  |  |  | 
 |  |  |                 if (liftLev != LiftLevType.TWO.realLev) { | 
 |  |  |                 if (liftProtocol.getPositionArrivalFeedback().intValue() != LiftLevType.TWO.realLev.intValue()) { | 
 |  |  |                     //提升机不在输送线楼层,获取到输送线层的提升机命令 | 
 |  |  |                     LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), LiftLevType.TWO.lev); | 
 |  |  |                     commands.add(command1);//将命令添加进list | 
 |  |  | 
 |  |  |                 command2.setOperaStaNo((short) 102);//操作102站 | 
 |  |  |                 command2.setRotationDire(1);//给输送线下发链条转动信号,正转 | 
 |  |  |                 command2.setDevpId(devpId); | 
 |  |  |                 command2.setStaNo(distStaNo.shortValue());//设置目标站 | 
 |  |  |                 commands.add(command2);//将命令添加进list | 
 |  |  |  | 
 |  |  |                 Integer levTmp = wrkMastLocNoLey; | 
 |  |  |                 if (wrkMastLocNoLey >= 2) { | 
 |  |  |                     levTmp += 1; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 //提升机前往目标楼层(工作档目标楼层) | 
 |  |  |                 LiftCommand command3 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), levTmp); | 
 |  |  | 
 |  |  |                 //提升机到达指定楼层,输送线将货物移出去(正转) | 
 |  |  |                 //输送线将货物移出去 | 
 |  |  |                 LiftCommand command4 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 1); | 
 |  |  |                 Integer distStaNo = Utils.levToOutInStaNo(levTmp); | 
 |  |  |                 command4.setOperaStaNo(distStaNo.shortValue());//操作目标楼层站点 | 
 |  |  |                 command4.setRotationDire(1);//给输送线下发链条转动信号,正转 | 
 |  |  |                 command4.setDevpId(devpId); | 
 |  |  |                 command4.setStaNo(distStaNo.shortValue());//设置目标站 | 
 |  |  |                 commands.add(command4);//将命令添加进list | 
 |  |  |  | 
 |  |  |                 //给提升机分配任务 | 
 |  |  |                 liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号 | 
 |  |  |                 liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中 | 
 |  |  |  | 
 |  |  |                 wrkMast.setWrkSts(3L);//3.提升机搬运中 | 
 |  |  |             } else if (wrkMast.getWrkSts() == 6) {//6.迁移小车至提升机口完成 => 7.提升机迁移小车中 | 
 |  |  | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 //工作档目标库位号 | 
 |  |  |                 String wrkMastLocNo = wrkMast.getIoType() == 101 ? wrkMast.getSourceLocNo() : wrkMast.getLocNo(); | 
 |  |  |                 String wrkMastLocNo = wrkMast.getLocNo(); | 
 |  |  |                 //工作档目标库位楼层 | 
 |  |  |                 int wrkMastLocNoLey = Utils.getLev(wrkMastLocNo); | 
 |  |  |                 if (wrkMastLocNoLey >= 2) { | 
 |  |  | 
 |  |  |                 //提升机前往目标楼层(工作档目标楼层) | 
 |  |  |                 LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), wrkMastLocNoLey); | 
 |  |  |                 commands.add(command1);//将命令添加进list | 
 |  |  |  | 
 |  |  |                 //给提升机分配任务 | 
 |  |  |                 liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号 | 
 |  |  |                 liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中 | 
 |  |  |  | 
 |  |  |                 wrkMast.setWrkSts(7L);//6.迁移小车至提升机口完成 => 7.提升机迁移小车中 | 
 |  |  |             } else if(wrkMast.getWrkSts() == 23) {//23.迁移小车至提升机口完成 => 24.提升机迁移小车中 | 
 |  |  | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 //工作档目标库位号 | 
 |  |  |                 String wrkMastLocNo = wrkMast.getIoType() == 101 ? wrkMast.getSourceLocNo() : wrkMast.getLocNo(); | 
 |  |  |                 String wrkMastLocNo = wrkMast.getSourceLocNo(); | 
 |  |  |                 //工作档目标库位楼层 | 
 |  |  |                 int wrkMastLocNoLey = Utils.getLev(wrkMastLocNo); | 
 |  |  |                 if (wrkMastLocNoLey >= 2) { | 
 |  |  | 
 |  |  |                 LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), wrkMastLocNoLey); | 
 |  |  |                 commands.add(command1);//将命令添加进list | 
 |  |  |  | 
 |  |  |                 //给提升机分配任务 | 
 |  |  |                 liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号 | 
 |  |  |                 liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中 | 
 |  |  |  | 
 |  |  |                 wrkMast.setWrkSts(24L);//23.迁移小车至提升机口完成 => 24.提升机迁移小车中 | 
 |  |  |             } else if (wrkMast.getWrkSts() == 27) {//27.小车出库搬运完成 | 
 |  |  |                 //工作档源库位号 | 
 |  |  | 
 |  |  |  | 
 |  |  |                 //提升机当前楼层 | 
 |  |  |                 int liftLev = liftProtocol.getLev().intValue(); | 
 |  |  |                 if (liftLev == 0) {//提升机当前楼层为0,提升机失去位置信息,让提升机前往一楼 | 
 |  |  |                     LiftCommand command = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), LiftLevType.ONE.lev); | 
 |  |  |                     commands.add(command);//将命令添加进list | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 //判断提升机是否到位 | 
 |  |  |                 StaProtocol staProtocol = devpThread.getStation().get(Utils.levToOutInStaNo(wrkMastLocNoLey));//起始站点 | 
 |  |  |                 if (liftLev != wrkMastLocNoLey && wrkMastLocNoLey != 1 || !staProtocol.isLiftArrival()) { | 
 |  |  |                 StaProtocol staProtocol = devpThread.getStation().get(Utils.levToOutInStaNo(wrkMastLocNoLey >= 2 ? wrkMastLocNoLey + 1 : wrkMastLocNoLey));//起始站点 | 
 |  |  |                 if (liftLev != wrkMastLocNoLey && !staProtocol.isLiftArrival()) { | 
 |  |  |                     //提升机不在工作档源库位楼层,调度提升机 | 
 |  |  |                     LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), wrkMastLocNoLey); | 
 |  |  |                     commands.add(command1);//将命令添加进list | 
 |  |  | 
 |  |  |                 command5.setRotationDire(0);//链条转动停止 | 
 |  |  |                 commands.add(command5); | 
 |  |  |  | 
 |  |  |                 //给提升机分配任务 | 
 |  |  |                 liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号 | 
 |  |  |                 liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中 | 
 |  |  |  | 
 |  |  |                 wrkMast.setWrkSts(28L);//28.提升机搬运中 | 
 |  |  |             } | 
 |  |  |  |