自动化立体仓库 - WCS系统
#
Junjie
2023-09-20 cb757218ff35e8b302de2d6cc5a95b842acd8ea2
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
@@ -69,6 +70,8 @@
    @Autowired
    private BasShuttleErrLogService basShuttleErrLogService;
    @Autowired
    private BasLiftErrLogService basLiftErrLogService;
    @Autowired
    private BasShuttleErrService basShuttleErrService;
    @Autowired
    private BasCrnErrorMapper basCrnErrorMapper;
@@ -96,6 +99,9 @@
    private ShuttleDispatchUtils shuttleDispatchUtils;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private WrkMastLocMapper wrkMastLocMapper;
    /**
     * 组托
@@ -635,11 +641,11 @@
                }
                Short shuttleNo = redisCommand.getShuttleNo();
                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo.intValue());
                NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo.intValue());
                if (shuttleThread == null) {
                    continue;
                }
                ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
                NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
                if (shuttleProtocol == null) {
                    continue;
                }
@@ -648,7 +654,7 @@
                }
                //四向穿梭车处于空闲状态,进行任务的恢复
                shuttleProtocol.setTaskNo(redisCommand.getWrkNo());//将四向穿梭车线程分配任务号
                shuttleProtocol.setTaskNo(redisCommand.getWrkNo().intValue());//将四向穿梭车线程分配任务号
                shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);//工作状态
            }
        }
@@ -721,6 +727,10 @@
            if (!shuttleProtocol.isIdle()) {
                return false;
            }
            //判断小车令牌是否未被占领
            if (shuttleProtocol.getToken() != 0) {
                return false;//小车已被独占,禁止再派发任务
            }
            //判断小车是否到达输送站点库位
            if (!shuttleProtocol.getCurrentLocNo().equals(basDevp.getLocNo())) {
@@ -746,6 +756,7 @@
            wrkMast.setWrkSts(5L);//4.提升机搬运完成 => 5.小车搬运中
            wrkMast.setModiTime(new Date());
            shuttleProtocol.setToken(wrkMast.getWrkNo());//独占小车令牌
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
@@ -776,6 +787,45 @@
    public boolean shuttleOutExecuteStep1(WrkMast wrkMast) {
        //21.生成出库任务 => 22.小车搬运中
        if (wrkMast.getWrkSts() == 21) {
            EntityWrapper<StaDesc> wrapper = new EntityWrapper<>();
            wrapper.eq("type_no", wrkMast.getIoType());//路径类型
            wrapper.eq("stn_no", wrkMast.getStaNo());//出库站点编号
            StaDesc staDesc = staDescService.selectOne(wrapper);
            if (staDesc == null) {
                return false;//出库路径不存在
            }
            //获取出库站点
            BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
            if (basDevp == null) {
                return false;//出库站点不存在
            }
            if (!basDevp.getOutEnable().equals("Y")) {
                return false;//出库站点不可出
            }
            //判断各楼层内部输送站点是否空闲无物
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basDevp.getLiftNo());
            if (liftThread == null) {
                return false;
            }
            //获取提升机站点list
            List<LiftStaProtocol> liftStaProtocols = liftThread.getLiftStaProtocols();
            if (liftStaProtocols.isEmpty()) {
                return false;
            }
            for (LiftStaProtocol liftStaProtocol : liftStaProtocols) {
                //判断当前出库任务对应楼层的提升机站点状态
                if (liftStaProtocol.getLev() == Utils.getLev(wrkMast.getSourceLocNo())) {
                    if (liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && !liftStaProtocol.getHasTray()) {
                        return false;//站点必须自动、空闲、没有托盘
                    }
                }
            }
            if (wrkMast.getShuttleNo() == null) {//没有绑定小车,进行调度
                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//调度小车到货物所在库位进行取货
                return false;
@@ -793,11 +843,9 @@
            if (!shuttleProtocol.isIdle()) {
                return false;
            }
            //获取目标站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getLiftNo());
            if (targetBasDevp == null) {
                return false;//缺少站点信息
            //判断小车令牌是否未被占领
            if (shuttleProtocol.getToken() != 0) {
                return false;//小车已被独占,禁止再派发任务
            }
            //判断小车是否到达货物库位
@@ -808,7 +856,7 @@
            }
            //小车已抵达货物位置,进行搬运货物
            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), targetBasDevp.getLocNo());
            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), null);
            if (result == null) {//出库路径计算失败
                return false;
            }
@@ -824,6 +872,7 @@
            wrkMast.setWrkSts(22L);//21.生成出库任务 => 22.小车搬运中
            wrkMast.setModiTime(new Date());
            shuttleProtocol.setToken(wrkMast.getWrkNo());//独占小车令牌
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
@@ -851,30 +900,55 @@
                    && shuttleProtocol.getFree() == ShuttleStatusType.IDLE.id
            ) {
                //将任务档标记为完成
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(shuttleProtocol.getTaskNo().intValue());
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(shuttleProtocol.getTaskNo());
                if (wrkMast != null) {
                    switch (wrkMast.getWrkSts().intValue()) {
                        case 5://5.小车搬运中 ==> 9.入库完成
                            wrkMast.setWrkSts(9L);
                            //任务号清零
                            shuttleProtocol.setTaskNo(0);
                            if (shuttleProtocol.getToken() == wrkMast.getWrkNo()) {
                                //释放小车令牌
                                shuttleProtocol.setToken(0);
                            }
                            break;
                        case 22://22.小车搬运中 ==> 23.小车搬运完成
                            wrkMast.setWrkSts(23L);
                            if (shuttleProtocol.getToken() == wrkMast.getWrkNo()) {
                                //释放小车令牌
                                shuttleProtocol.setToken(0);
                            }
                            break;
                        case 102://102.小车到提升机中 ==> 103.小车到提升机完成
                        case 102://102.小车移动至站点 ==> 103.小车移动至站点完成
                            wrkMast.setWrkSts(103L);
                            break;
                        case 106://106.小车迁出提升机中 ==> 107.小车迁出提升机完成
                            wrkMast.setWrkSts(107L);
                        case 104://104.小车迁入提升机中 ==> 105.小车迁入提升机完成
                            wrkMast.setWrkSts(105L);
                            break;
                        case 108://108.小车移动中 ==> 109.小车移动完成
                        case 108://108.小车迁出提升机中 ==> 109.小车迁出提升机完成
                            wrkMast.setWrkSts(109L);
                            break;
                        case 110://110.小车移动中 ==> 111.小车移动完成
                            wrkMast.setWrkSts(111L);
                            shuttleProtocol.setTaskNo(0);
                            if (shuttleProtocol.getToken() == wrkMast.getWrkNo()) {
                                //释放小车令牌
                                shuttleProtocol.setToken(0);
                            }
                            break;
                        default:
                    }
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        if (wrkMast.getWrkSts() == 111) {
                            // 保存工作主档历史档
                            if (wrkMastLocMapper.save(wrkMast.getWrkNo()) <= 0) {
                                log.info("保存工作历史档[workNo={0}]失败", wrkMast.getWrkNo());
                            }
                            // 删除工作主档
                            if (!wrkMastService.deleteById(wrkMast)) {
                                log.info("删除工作主档[workNo={0}]失败", wrkMast.getWrkNo());
                            }
                        }
                        //设置四向穿梭车为空闲状态
                        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                        //源库位清零
@@ -886,6 +960,24 @@
                        News.info("四向穿梭车已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
                    } else {
                        News.error("四向穿梭车已确认且任务完成状态,复位失败,但未找到工作档。四向穿梭车号={},工作号={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo());
                    }
                }else {
                    ShuttleAssignCommand assignCommand = shuttleProtocol.getAssignCommand();
                    if (!assignCommand.getAuto()) {
                        //手动模式
                        //工作号清零
                        shuttleProtocol.setTaskNo(0);
                        //设置四向穿梭车为空闲状态
                        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                        //源库位清零
                        shuttleProtocol.setSourceLocNo(null);
                        //目标库位清零
                        shuttleProtocol.setLocNo(null);
                        //任务指令清零
                        shuttleProtocol.setAssignCommand(null);
                        //清零令牌
                        shuttleProtocol.setToken(0);
                        News.info("四向穿梭车已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
                    }
                }
@@ -909,6 +1001,11 @@
            }
            if (!liftProtocol.isIdle()) {
                continue;
            }
            //判断提升机令牌是否被占用
            if (liftProtocol.getToken() != 0) {
                continue;
            }
@@ -961,6 +1058,10 @@
            if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                return false;
            }
            //判断提升机令牌是否未被占领
            if (liftProtocol.getToken() != 0) {
                return false;//提升机已被独占,禁止再派发任务
            }
            //判断提升机是否有其他任务
            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId());
            if (liftWrkMast != null) {
@@ -969,15 +1070,25 @@
            //获取源站对应的输送站点
            BasDevp sourceBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo());
            //获取目标站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getStaNo());
            if (sourceBasDevp == null || targetBasDevp == null) {
                return false;//缺少站点信息
            if (sourceBasDevp == null) {
                return false;//站点不存在
            }
            //获取源站对应的牛眼提升机站点编号(起点编号)
            Integer startSta = Integer.parseInt(sourceBasDevp.getQrCodeValue());
            Integer targetSta = null;
            //获取牛眼提升机站点编号(目标编号)
            for (LiftStaProtocol liftStaProtocol : liftThread.getLiftStaProtocols()) {
                if (liftStaProtocol.getLev() == Utils.getLev(wrkMast.getLocNo())) {
                    targetSta = liftStaProtocol.getStaNo();
                }
            }
            if (targetSta == null) {
                return false;//站点编号不存在
            }
            //获取提升机命令
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo());
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo());
            ArrayList<NyLiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
@@ -991,6 +1102,7 @@
            wrkMast.setWrkSts(3L);//2.设备上走 ==> 3.提升机搬运中
            wrkMast.setLiftNo(liftThread.getSlave().getId());//任务档绑定提升机号
            wrkMast.setModiTime(now);
            liftProtocol.setToken(wrkMast.getWrkNo());//独占提升机令牌
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
@@ -1023,22 +1135,38 @@
            if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                return false;
            }
            //判断提升机令牌是否未被占领
            if (liftProtocol.getToken() != 0) {
                return false;//提升机已被独占,禁止再派发任务
            }
            //判断提升机是否有其他任务
            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId());
            if (liftWrkMast != null) {
                return false;//当前提升机存在未完成任务,等待下一次轮询
            }
            //获取源站对应的输送站点
            BasDevp sourceBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), liftProtocol.getLiftNo().intValue());
            //获取目标站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo());
            if (sourceBasDevp == null || targetBasDevp == null) {
                return false;//缺少站点信息
            //获取源站对应的牛眼提升机站点编号(起点编号)
            Integer startSta = null;
            for (LiftStaProtocol liftStaProtocol : liftThread.getLiftStaProtocols()) {
                if (liftStaProtocol.getLev() == Utils.getLev(wrkMast.getLocNo())) {
                    startSta = liftStaProtocol.getStaNo();
                }
            }
            if (startSta == null) {
                return false;//站点编号不存在
            }
            //获目标站源站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getStaNo());
            if (targetBasDevp == null) {
                return false;//站点不存在
            }
            //获取牛眼提升机站点编号(目标编号)
            Integer targetSta = Integer.parseInt(targetBasDevp.getQrCodeValue());
            //获取提升机命令
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo());
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo());
            ArrayList<NyLiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
@@ -1053,6 +1181,7 @@
            wrkMast.setWrkSts(24L);//23.小车搬运完成 ==> 24.提升机搬运中
            wrkMast.setLiftNo(liftThread.getSlave().getId());//任务档绑定提升机号
            wrkMast.setModiTime(now);
            liftProtocol.setToken(wrkMast.getWrkNo());//独占提升机令牌
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
@@ -1088,12 +1217,23 @@
                        case 3://3.提升机搬运中 ==> 4.提升机搬运完成
                            wrkMast.setWrkSts(4L);
                            wrkMast.setLiftNo(null);//释放提升机
                            if (liftProtocol.getToken() == wrkMast.getWrkNo()) {
                                //释放提升机令牌
                                liftProtocol.setToken(0);
                            }
                            break;
                        case 24://24.提升机搬运中 ==> 25.提升机搬运完成
                            wrkMast.setWrkSts(25L);
                            if (wrkMast.getIoType() == 11) {//库位移转
                                wrkMast.setWrkSts(4L);//4.提升机搬运完成
                            }
                            if (liftProtocol.getToken() == wrkMast.getWrkNo()) {
                                //释放提升机令牌
                                liftProtocol.setToken(0);
                            }
                            break;
                        case 104://104.提升机搬运中 ==> 105.提升机搬运完成
                            wrkMast.setWrkSts(105L);
                        case 106://106.提升机搬运中 ==> 107.提升机搬运完成
                            wrkMast.setWrkSts(107L);
                            break;
                        default:
                    }
@@ -1127,67 +1267,288 @@
        //查询库位移转工作档
        List<WrkMast> wrkMasts1 = wrkMastMapper.selectLocToLocWrkMast();
        for (WrkMast wrkMast : wrkMasts1) {
            boolean step1 = this.locToLocExecuteStep1(wrkMast);//库位移转
            if (!step1) {
                continue;
            if (Utils.getLev(wrkMast.getSourceLocNo()) == Utils.getLev(wrkMast.getLocNo())) {
                boolean step1 = this.locToLocExecuteStep1(wrkMast);//同楼层库位移转
                if (!step1) {
                    continue;
                }
            }else {
                //跨楼层库位移转
                boolean step2 = this.locToLocExecuteStep2(wrkMast);//调度车辆取货并运送到出库口
                if (!step2) {
                    continue;
                }
                boolean step3 = this.locToLocExecuteStep3(wrkMast);//提升机搬运货物
                if (!step3) {
                    continue;
                }
                boolean step4 = this.locToLocExecuteStep4(wrkMast);//调度车辆取货并运送到出库口
                if (!step4) {
                    continue;
                }
            }
        }
    }
    /**
     * 库位移转
     * 同楼层库位移转
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean locToLocExecuteStep1(WrkMast wrkMast) {
        if (wrkMast.getShuttleNo() == null) {
            shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//调度小车到源库位进行取货
        if (wrkMast.getWrkSts() == 21) {//21.生成出库任务
            if (wrkMast.getShuttleNo() == null) {
                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//调度小车到源库位进行取货
                return false;
            }
            //获取四向穿梭车线程
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                return false;
            }
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                return false;
            }
            if (!shuttleProtocol.isIdle()) {
                return false;
            }
            //判断小车是否到达源库位
            if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
                //小车不在源库位位置
                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//调度小车到源库位进行取货
                return false;
            }
            //小车已抵达源库位,进行搬运货物
            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), wrkMast.getLocNo());
            if (result == null) {//路径计算失败
                return false;
            }
            //创建分配命令
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号
            assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//入库模式
            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
            assignCommand.setCommands(result.getCommands());//运行命令
            assignCommand.setNodes(result.getNodes());//路径节点
            wrkMast.setWrkSts(5L);//21.生成出库任务 => 5.小车搬运中
            wrkMast.setModiTime(new Date());
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
            }
            return false;
        }
        return true;
    }
        //获取四向穿梭车线程
        NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
        if (shuttleThread == null) {
    /**
     * 跨楼层库位移转-调度车辆取货并运送到出库口
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean locToLocExecuteStep2(WrkMast wrkMast) {
        if (wrkMast.getWrkSts() == 21) {//21.生成出库任务
            if (wrkMast.getShuttleNo() == null) {
                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//调度小车到源库位进行取货
                return false;
            }
            //获取四向穿梭车线程
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                return false;
            }
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                return false;
            }
            if (!shuttleProtocol.isIdle()) {
                return false;
            }
            //判断小车是否到达源库位
            if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
                //小车不在源库位位置
                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//调度小车到源库位进行取货
                return false;
            }
            //获取穿梭车最近且空闲的提升机输送站点
            LiftStaProtocol liftSta = shuttleDispatchUtils.getRecentLiftSta(shuttleThread.getSlave().getId());
            if (liftSta == null) {
                return false;//没有可用且空闲的输送站点
            }
            //源站
            Integer sourceStaNo = liftSta.getStaNo();
            //提升机号*100+目标楼层=目标站点
            Integer staNo = liftSta.getLiftNo() * 100 + Utils.getLev(wrkMast.getLocNo());//目标站
            //小车已抵达源库位,将货物搬运到输送站点
            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), liftSta.getLocNo());
            if (result == null) {//路径计算失败
                return false;
            }
            //创建分配命令
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号
            assignCommand.setTaskMode(ShuttleTaskModeType.SHUTTLE_LOC_TO_LOC.id.shortValue());//库位移转模式
            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
            assignCommand.setCommands(result.getCommands());//运行命令
            assignCommand.setNodes(result.getNodes());//路径节点
            wrkMast.setWrkSts(22L);//21.生成出库任务 => 22.小车搬运中
            wrkMast.setSourceStaNo(sourceStaNo);//源站
            wrkMast.setStaNo(staNo);//目标站
            wrkMast.setModiTime(new Date());
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
            }
            return false;
        }
        NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
        if (shuttleProtocol == null) {
        return true;
    }
    /**
     * 跨楼层库位移转-提升机搬运货物
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean locToLocExecuteStep3(WrkMast wrkMast) {
        Date now = new Date();
        if (wrkMast.getWrkSts() == 23) {//23.小车搬运完成
            //获取提升机线程
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
            if (liftThread == null) {
                return false;
            }
            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
            if (liftProtocol == null) {
                return false;
            }
            if (!liftProtocol.isIdle()) {
                return false;
            }
            //搜索是否有其他任务占用了提升机,如果占用提升机的任务和当前任务相同,则运行执行
            WrkMast wrkMast1 = wrkMastMapper.selectLiftWrkMast(liftProtocol.getLiftNo().intValue());
            if (wrkMast1 != null && wrkMast1.getWrkNo().intValue() != wrkMast.getWrkNo().intValue()) {
                return false;
            }
            //源站
            Integer sourceStaNo = wrkMast.getSourceStaNo();
            //目标站
            Integer staNo = wrkMast.getStaNo();
            if (sourceStaNo == null || staNo == null) {
                return false;//源站或目标站为空
            }
            //获取提升机命令
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceStaNo, staNo, wrkMast.getWrkNo());
            ArrayList<NyLiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(liftProtocol.getLiftNo());
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
            assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_TRAY.id.shortValue());
            wrkMast.setWrkSts(24L);//23.小车搬运完成 ==> 24.提升机搬运中
            wrkMast.setLiftNo(liftThread.getSlave().getId());//任务档绑定提升机号
            wrkMast.setShuttleNo(null);//清空小车号,等货物搬运完成后,到目标楼层重新搜索小车
            wrkMast.setModiTime(now);
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
            }
            return false;
        }
        if (!shuttleProtocol.isIdle()) {
        return true;
    }
    /**
     * 跨楼层库位移转-调度车辆取货并运送到目标枯萎
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean locToLocExecuteStep4(WrkMast wrkMast) {
        if (wrkMast.getWrkSts() == 4) {//4.提升机搬运完成
            //获取目标站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), wrkMast.getLiftNo());
            if (targetBasDevp == null) {
                return false;//缺少站点信息
            }
            if (wrkMast.getShuttleNo() == null) {
                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), targetBasDevp.getLocNo());//调度小车到目标输送站点进行取货
                return false;
            }
            //获取四向穿梭车线程
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                return false;
            }
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                return false;
            }
            if (!shuttleProtocol.isIdle()) {
                return false;
            }
            //判断小车是否到达目标输送站点
            if (!shuttleProtocol.getCurrentLocNo().equals(targetBasDevp.getLocNo())) {
                //小车不在目标输送站点
                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), targetBasDevp.getLocNo(), wrkMast.getShuttleNo());//调度小车到目标输送站点进行取货
                return false;
            }
            //小车已抵达目标输送站点,将货物搬运到目标库位
            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), targetBasDevp.getLocNo(), wrkMast.getLocNo());
            if (result == null) {//路径计算失败
                return false;
            }
            //创建分配命令
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号
            assignCommand.setTaskMode(ShuttleTaskModeType.SHUTTLE_LOC_TO_LOC.id.shortValue());//库位移转模式
            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
            assignCommand.setCommands(result.getCommands());//运行命令
            assignCommand.setNodes(result.getNodes());//路径节点
            wrkMast.setWrkSts(5L);//4.提升机搬运完成 => 5.小车搬运中
            wrkMast.setLiftNo(null);//释放提升机
            wrkMast.setModiTime(new Date());
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
            }
            return false;
        }
        //判断小车是否到达源库位
        if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
            //小车不在源库位位置
            shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//调度小车到源库位进行取货
            return false;
        }
        //小车已抵达源库位,进行搬运货物
        NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), wrkMast.getLocNo());
        if (result == null) {//路径计算失败
            return false;
        }
        //创建分配命令
        ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
        assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
        assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号
        assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//入库模式
        assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
        assignCommand.setCommands(result.getCommands());//运行命令
        assignCommand.setNodes(result.getNodes());//路径节点
        wrkMast.setWrkSts(5L);//1.生成入库任务 => 5.小车搬运中
        wrkMast.setModiTime(new Date());
        if (wrkMastMapper.updateById(wrkMast) > 0) {
            //下发任务
            MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
        }
        return true;
    }
@@ -1197,6 +1558,7 @@
    public void recErr() {
        try {
            this.recShuttleErr();
            this.recLiftErr();
        } catch (Exception e) {
            News.error("recErr fail", e);
        }
@@ -1228,7 +1590,7 @@
                        if (wrkMast == null) {
                            continue;
                        }
                        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getErrCode().get(0));
                        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getErrCode());
                        String errName = basShuttleErr==null? "未知异常":basShuttleErr.getErrName();
                        BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog(
                                null,    // 编号
@@ -1244,14 +1606,15 @@
                                wrkMast.getSourceStaNo(),    // 源站
                                wrkMast.getSourceLocNo(),    // 源库位
                                wrkMast.getBarcode(),    // 条码
                                shuttleProtocol.getErrCode().get(0),    // 异常码
                                shuttleProtocol.getErrCode(),    // 异常码
                                errName,    // 异常
                                1,    // 异常情况
                                now,    // 添加时间
                                null,    // 添加人员
                                now,    // 修改时间
                                null,    // 修改人员
                                "任务中异常"    // 备注
                                "任务中异常",    // 备注
                                JSON.toJSONString(shuttleProtocol)    // 系统状态数据
                        );
                        if (!basShuttleErrLogService.insert(basShuttleErrLog)) {
                            News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName);
@@ -1316,6 +1679,91 @@
//                        }
//                    }
//                }
            }
        }
    }
    /**
     * 提升机异常信息记录
     */
    private void recLiftErr() {
        Date now = new Date();
        for (LiftSlave liftSlave : slaveProperties.getLift()) {
            // 获取提升机信息
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId());
            if (liftThread == null) {
                continue;
            }
            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
            if (liftProtocol == null) {
                continue;
            }
            if (liftProtocol.getTaskNo() != 0) {
                //有任务
                BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(liftSlave.getId(), liftProtocol.getTaskNo().intValue());
                // 有异常
                if (latest == null) {
                    if (liftProtocol.getDeviceError() != null && liftProtocol.getDeviceError()) {
                        WrkMast wrkMast = wrkMastMapper.selectById(liftProtocol.getTaskNo());
                        if (wrkMast == null) {
                            continue;
                        }
                        String errName = "";
                        if (liftProtocol.getFrontOverrun()) {
                            errName = "前超限";
                        } else if (liftProtocol.getBackOverrun()) {
                            errName = "后超限";
                        } else if (liftProtocol.getLeftOverrun()) {
                            errName = "左超限";
                        } else if (liftProtocol.getRightOverrun()) {
                            errName = "右超限";
                        } else if (liftProtocol.getOverHeight()) {
                            errName = "超高";
                        } else if (liftProtocol.getOverWeight()) {
                            errName = "超重";
                        }
                        BasLiftErrLog basLiftErrLog = new BasLiftErrLog(
                                null,    // 编号
                                wrkMast.getWrkNo(),    // 工作号
                                now,    // 发生时间
                                null,    // 结束时间
                                wrkMast.getWrkSts(),    // 工作状态
                                wrkMast.getIoType(),    // 入出库类型
                                liftSlave.getId(),    // 提升机
                                null,    // plc
                                wrkMast.getLocNo(),    // 目标库位
                                wrkMast.getStaNo(),    // 目标站
                                wrkMast.getSourceStaNo(),    // 源站
                                wrkMast.getSourceLocNo(),    // 源库位
                                wrkMast.getBarcode(),    // 条码
                                null,    // 异常码
                                errName,    // 异常
                                1,    // 异常情况
                                now,    // 添加时间
                                null,    // 添加人员
                                now,    // 修改时间
                                null,    // 修改人员
                                "任务中异常",    // 备注
                                JSON.toJSONString(liftProtocol)    // 系统状态数据
                        );
                        if (!basLiftErrLogService.insert(basLiftErrLog)) {
                            News.error("提升机plc异常记录失败 ===>> [id:{}] [error:{}]", liftSlave.getId(), errName);
                        }
                    }
                } else {
                    // 异常修复
                    if (liftProtocol.getDeviceError() == null || !liftProtocol.getDeviceError()) {
                        latest.setEndTime(now);
                        latest.setUpdateTime(now);
                        latest.setStatus(2);
                        if (!basLiftErrLogService.updateById(latest)) {
                            News.error("提升机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", liftSlave.getId(), latest.getId());
                        }
                    }
                }
            }
        }
    }
@@ -1648,6 +2096,10 @@
            }
            if (wrkCharge.getWrkSts() == 51) {
                if (!shuttleProtocol.isIdleNoCharge()) {
                    continue;
                }
                if (!shuttleProtocol.getCurrentLocNo().equals(wrkCharge.getLocNo())) {
                    //小车不在充电桩位置
                    shuttleDispatchUtils.dispatchShuttle(wrkCharge.getWrkNo(), wrkCharge.getLocNo(), shuttle.getId());//调度小车去充电桩
@@ -1718,38 +2170,46 @@
        //查询小车移库任务
        List<WrkMast> wrkMasts = wrkMastMapper.selectShuttleMoveWrk();
        for (WrkMast wrkMast : wrkMasts) {
            boolean step1 = this.shuttleMoveExecuteStep1(wrkMast);//小车移动到提升机中
            if (!step1) {
            boolean stepMoveSta = this.shuttleMoveExecuteStepMoveSta(wrkMast);//小车移动到站点
            if (!stepMoveSta) {
                continue;
            }
            boolean step2 = this.shuttleMoveExecuteStep2(wrkMast);//提升机搬运中
            if (!step2) {
            boolean stepIntoLift = this.shuttleMoveExecuteStepIntoLift(wrkMast);//小车迁入提升机
            if (!stepIntoLift) {
                continue;
            }
            boolean step3 = this.shuttleMoveExecuteStep3(wrkMast);//小车迁出提升机中
            if (!step3) {
            boolean stepLiftMove = this.shuttleMoveExecuteStepLiftMove(wrkMast);//提升机搬运中
            if (!stepLiftMove) {
                continue;
            }
            boolean step4 = this.shuttleMoveExecuteStep4(wrkMast);//小车移动到目标库位中
            if (!step4) {
            boolean stepOutLift = this.shuttleMoveExecuteStepOutLift(wrkMast);//小车迁出提升机
            if (!stepOutLift) {
                continue;
            }
            boolean stepMoveLoc = this.shuttleMoveExecuteStepMoveLoc(wrkMast);//小车移动到目标库位中
            if (!stepMoveLoc) {
                continue;
            }
//            this.shuttleMoveExecuteStepClearWrkMast(wrkMast);//清理111.小车移动完成
        }
    }
    /**
     * 小车迁移-小车移动到提升机中
     * 小车迁移-小车移动到站点
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean shuttleMoveExecuteStep1(WrkMast wrkMast) {
        //--------------------------------------小车移动到提升机中-----------------------------------------//
    private boolean shuttleMoveExecuteStepMoveSta(WrkMast wrkMast) {
        //--------------------------------------小车移动至站点-----------------------------------------//
        Date now = new Date();
        //小车移动到提升机中  101.生成小车移库任务 ==> 102.小车到提升机中
        //小车移动至站点  101.生成小车移库任务 ==> 102.小车移动至站点中
        if (wrkMast.getWrkSts() == 101) {
            //获取四向穿梭车线程
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
@@ -1762,76 +2222,36 @@
            }
            //小车处于空闲状态
            if (!shuttleProtocol.isIdleNoCharge()) {
            if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) {
                return false;
            }
            //判断小车令牌是否未被占领
            if (shuttleProtocol.getToken() != 0) {
                return false;//小车已被独占,禁止再派发任务
            }
            if (Utils.getLev(wrkMast.getLocNo()) == shuttleProtocol.getPoint().getZ()) {
                //目标库位和小车库位处于同一楼层,需要通过提升机调度
                return true;//直接进入108.小车移动中
                //目标库位和小车库位处于同一楼层,不需要通过提升机调度
                wrkMast.setWrkSts(109L);// 109.小车迁出提升机完成 ==> 110.小车移动中
                wrkMast.setModiTime(now);
                shuttleProtocol.setToken(wrkMast.getWrkNo());//独占该小车令牌
                if (wrkMastMapper.updateById(wrkMast) > 0) {
                    //下发任务
                    return true;//直接进入109.小车迁出提升机完成 ==> 110.小车移动中
                }
                return false;
            }
            //计算距离小车最近的提升机站点
            //查询小车所在楼层提升机输送站点
            int recentAllDistance = 9999999;//默认最近距离
            BasDevp recentDevp = null;//最近站点
            List<BasDevp> basDevps = basDevpService.selectHasLiftNoByLev(shuttleProtocol.getPoint().getZ());
            for (BasDevp basDevp : basDevps) {
                LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basDevp.getLiftNo());
                if (liftThread == null) {
                    continue;
                }
                LiftProtocol liftProtocol = liftThread.getLiftProtocol();
                if (liftProtocol == null) {
                    continue;
                }
                if (!liftProtocol.isIdle()) {
                    continue;
                }
                //计算路径
                List<NavigateNode> calc = NavigateUtils.calc(shuttleProtocol.getCurrentLocNo(), basDevp.getLocNo(), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(shuttleProtocol.getCurrentLocNo())));
                if (calc == null) {
                    continue;//计算失败,找下一个站点
                }
                Integer allDistance = NavigateUtils.getOriginPathAllDistance(calc);//根据原始节点结果,计算总行走距离
                if (recentAllDistance > allDistance) {
                    recentAllDistance = allDistance;//更新距离
                    recentDevp = basDevp;//更新输送站点
                }
            //获取源输送站
            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            if (liftSta == null) {
                return false;//找不到站点
            }
            if (recentDevp == null) {
                //没有找到可用输送站点
                return false;//等待下一次轮询
            }
            //获取提升机数据
            BasLift basLift = basLiftService.selectById(recentDevp.getLiftNo());
            if (basLift == null) {
                return false;//没有提升机数据
            }
            if (basLift.getPoint() == null) {
                return false;//没有设置提升机点位坐标
            }
            //判断提升机是否有其他任务
            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(basLift.getLiftNo());
            if (liftWrkMast != null) {
                return false;//当前提升机存在未完成任务,等待下一次轮询
            }
            NavigateNode liftNode = new NavigateNode(basLift.getPoint().getX(), basLift.getPoint().getY());
            liftNode.setZ(basLift.getPoint().getZ());
            //获取小车到输送站点行走命令
            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), recentDevp.getLocNo());
            //获取小车进提升机行走命令
            NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), NavigatePositionConvert.locNoToNode(recentDevp.getLocNo()), liftNode, true);
            if (result.getCommands() == null) {
                return false;//路径计算失败
            }
            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo());
            List<NyShuttleHttpCommand> commands = result.getCommands();
            commands.add(moveCommand);//添加小车迁入提升机命令
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号
@@ -1841,30 +2261,59 @@
            assignCommand.setCommands(commands);
            assignCommand.setNodes(result.getNodes());
            wrkMast.setWrkSts(102L);//小车移动到提升机中  101.生成小车移库任务 ==> 102.小车到提升机中
            wrkMast.setLiftNo(basLift.getLiftNo());//提升机号(锁定提升机防止被其他任务抢占)
            wrkMast.setWrkSts(102L);//小车移动到提升机中  101.生成小车移库任务 ==> 102.小车移动至站点
            wrkMast.setModiTime(now);
            shuttleProtocol.setToken(wrkMast.getWrkNo());//独占该小车令牌
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                return false;
            }
            return false;
        }
        return true;
    }
    /**
     * 小车迁移-提升机搬运中
     * 小车迁移-小车迁入提升机
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean shuttleMoveExecuteStep2(WrkMast wrkMast) {
        //--------------------------------------提升机搬运中-----------------------------------------//
    private boolean shuttleMoveExecuteStepIntoLift(WrkMast wrkMast) {
        //--------------------------------------小车迁入提升机-----------------------------------------//
        Date now = new Date();
        //提升机搬运中  103.小车到提升机完成 ==> 104.提升机搬运中
        //小车移动到提升机中  103.小车移动至站点完成 ==> 104.小车迁入提升机中
        if (wrkMast.getWrkSts() == 103) {
            //获取源站
            LiftStaProtocol sourceLiftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            if (sourceLiftSta == null) {
                return false;//找不到站点
            }
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
            //获取目标输送站
            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            if (liftSta == null) {
                return false;//找不到站点
            }
            //获取提升机数据
            BasLift basLift = basLiftService.selectById(liftSta.getLiftNo());
            if (basLift == null) {
                return false;//没有提升机数据
            }
            if (basLift.getPoint() == null) {
                return false;//没有设置提升机点位坐标
            }
            //判断提升机是否有其他任务
            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(basLift.getLiftNo());
            if (liftWrkMast != null) {
                return false;//当前提升机存在未完成任务,等待下一次轮询
            }
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSta.getLiftNo());
            if (liftThread == null) {
                return false;
            }
@@ -1891,49 +2340,92 @@
                return false;
            }
            //获取源站对应的输送站点
            BasDevp sourceBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), liftProtocol.getLiftNo().intValue());
            //获取目标站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), liftProtocol.getLiftNo().intValue());
            if (sourceBasDevp == null || targetBasDevp == null) {
                return false;//缺少站点信息
            //判断提升机楼层
            if (liftProtocol.getLev().intValue() != shuttleProtocol.getPoint().getZ()) {
                //提升机不在小车楼层
                //调度提升机
                //获取提升机命令,调度提升机到源站位置
                NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceLiftSta.getStaNo(), sourceLiftSta.getStaNo(), wrkMast.getWrkNo());
                ArrayList<NyLiftCommand> commands = new ArrayList<>();
                commands.add(liftCommand);
                //提交到线程去工作
                LiftAssignCommand assignCommand = new LiftAssignCommand();
                assignCommand.setCommands(commands);
                assignCommand.setLiftNo(liftProtocol.getLiftNo());
                assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
                assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue());
                wrkMast.setLiftNo(liftThread.getSlave().getId());//锁定提升机防止被占用
                wrkMast.setModiTime(now);
                liftProtocol.setToken(wrkMast.getShuttleNo());//提升机令牌绑定当前小车
                if (wrkMastMapper.updateById(wrkMast) > 0) {
                    //下发任务
                    MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
                }
                return false;//等待提升机到小车楼层
            }
            //获取提升机命令
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo());
            //判断提升机令牌是否为当前小车
            if (liftProtocol.getToken() != wrkMast.getShuttleNo()) {
                return false;//提升机已被独占,禁止再派发任务
            }
            ArrayList<NyLiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
            //判断小车是否为当前任务独占
            if (shuttleProtocol.getToken() != wrkMast.getWrkNo()) {
                return false;
            }
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
            //站点节点
            NavigateNode staNode = NavigatePositionConvert.locNoToNode(sourceLiftSta.getLocNo());
            //提升机节点
            NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
            liftNode.setZ(basLift.getPoint$().getZ());
            //获取小车进提升机行走命令
            NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), staNode, liftNode, true);
            List<NyShuttleHttpCommand> commands = new ArrayList<>();
            commands.add(moveCommand);
            List<NavigateNode> nodes = new ArrayList<>();//行走节点路径
            nodes.add(staNode);
            nodes.add(liftNode);
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号
            assignCommand.setTaskMode(ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id.shortValue());//小车移库任务
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号
            assignCommand.setAuto(true);//自动模式
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(liftProtocol.getLiftNo());
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
            assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue());
            assignCommand.setNodes(nodes);
            wrkMast.setWrkSts(104L);//提升机搬运中  103.小车到提升机完成 ==> 104.提升机搬运中
            wrkMast.setLiftNo(liftThread.getSlave().getId());//锁定提升机防止被占用
            wrkMast.setWrkSts(104L);//小车移动到提升机中  103.小车移动至站点完成 ==> 104.小车迁入提升机中
            wrkMast.setModiTime(now);
            wrkMast.setLiftNo(liftThread.getSlave().getId());//锁定提升机防止被占用
            liftProtocol.setToken(wrkMast.getShuttleNo());//提升机令牌绑定当前小车
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                return false;
            }
            return false;
        }
        return true;
    }
    /**
     * 小车迁移-小车迁出提升机中
     * 小车迁移-提升机搬运中
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean shuttleMoveExecuteStep3(WrkMast wrkMast) {
        //--------------------------------------小车迁出提升机中-----------------------------------------//
    private boolean shuttleMoveExecuteStepLiftMove(WrkMast wrkMast) {
        //--------------------------------------提升机搬运中-----------------------------------------//
        Date now = new Date();
        //小车迁出提升机中  105.提升机搬运完成 ==> 106.小车迁出提升机中
        //提升机搬运中  105.小车迁入提升机完成 ==> 106.提升机搬运中
        if (wrkMast.getWrkSts() == 105) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
@@ -1947,6 +2439,15 @@
            if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                return false;
            }
            //判断提升机令牌是否为当前小车
            if (liftProtocol.getToken() != wrkMast.getShuttleNo()) {
                return false;//提升机令牌和当前小车不一致,禁止派发
            }
            //判断提升机内是否有小车
            if (!liftProtocol.getHasCar()) {
                return false;//提升机内无小车
            }
            //获取四向穿梭车线程
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
@@ -1963,26 +2464,112 @@
                return false;
            }
            //获取目标站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), liftProtocol.getLiftNo().intValue());
            if (targetBasDevp == null) {
            //判断小车是否为当前任务独占
            if (shuttleProtocol.getToken() != wrkMast.getWrkNo()) {
                return false;
            }
            //获取源站
            LiftStaProtocol sourceLiftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
            //获取目标站
            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            if (sourceLiftSta == null || liftSta == null) {
                return false;//缺少站点信息
            }
            //获取提升机命令
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceLiftSta.getStaNo(), liftSta.getStaNo(), wrkMast.getWrkNo());
            ArrayList<NyLiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
            //提交到线程去工作
            LiftAssignCommand assignCommand = new LiftAssignCommand();
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(liftProtocol.getLiftNo());
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
            assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue());
            wrkMast.setWrkSts(106L);//提升机搬运中  105.小车迁入提升机完成 ==> 106.提升机搬运中
            wrkMast.setLiftNo(liftThread.getSlave().getId());//锁定提升机防止被占用
            wrkMast.setModiTime(now);
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
            }
        }
        return true;
    }
    /**
     * 小车迁移-小车迁出提升机
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean shuttleMoveExecuteStepOutLift(WrkMast wrkMast) {
        //--------------------------------------小车迁出提升机-----------------------------------------//
        Date now = new Date();
        //小车移动到提升机中  107.提升机搬运完成 ==> 108.小车迁出提升机中
        if (wrkMast.getWrkSts() == 107) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
            if (liftThread == null) {
                return false;
            }
            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
            if (liftProtocol == null) {
                return false;
            }
            if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                return false;
            }
            //判断提升机令牌是否为当前小车
            if (liftProtocol.getToken() != wrkMast.getShuttleNo()) {
                return false;//提升机令牌和当前小车不一致,禁止派发
            }
            //获取四向穿梭车线程
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                return false;
            }
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                return false;
            }
            //小车处于空闲状态
            if (!shuttleProtocol.isIdleNoCharge()) {
                return false;
            }
            //判断小车是否为当前任务独占
            if (shuttleProtocol.getToken() != wrkMast.getWrkNo()) {
                return false;
            }
            //获取目标站
            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            if (liftSta == null) {
                return false;//找不到站点
            }
            //获取提升机数据
            BasLift basLift = basLiftService.selectById(targetBasDevp.getLiftNo());
            BasLift basLift = basLiftService.selectById(liftProtocol.getLiftNo().intValue());
            if (basLift == null) {
                return false;//没有提升机数据
            }
            if (basLift.getPoint() == null) {
                return false;//没有设置提升机点位坐标
            }
            NavigateNode liftNode = new NavigateNode(basLift.getPoint().getX(), basLift.getPoint().getY());
            liftNode.setZ(basLift.getPoint().getZ());
            NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
            liftNode.setZ(basLift.getPoint$().getZ());
            List<NyShuttleHttpCommand> commands = new ArrayList<>();
            //获取小车出提升机行走命令
            NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), liftNode, NavigatePositionConvert.locNoToNode(targetBasDevp.getLocNo()), false);
            NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), liftNode, NavigatePositionConvert.locNoToNode(liftSta.getLocNo()), false);
            commands.add(moveCommand);//添加小车迁出提升机命令
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
@@ -1993,12 +2580,14 @@
            assignCommand.setCommands(commands);
            assignCommand.setNodes(null);
            wrkMast.setWrkSts(106L);//小车迁出提升机中  105.提升机搬运完成 ==> 106.小车迁出提升机中
            wrkMast.setWrkSts(108L);//小车迁出提升机中  107.提升机搬运完成 ==> 108.小车迁出提升机中
            wrkMast.setModiTime(now);
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                return false;
            }
            return false;
        }
        return true;
    }
@@ -2008,12 +2597,12 @@
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean shuttleMoveExecuteStep4(WrkMast wrkMast) {
    private boolean shuttleMoveExecuteStepMoveLoc(WrkMast wrkMast) {
        //--------------------------------------小车移动到目标库位中-----------------------------------------//
        Date now = new Date();
        //小车移动到目标库位中  107.小车迁出提升机完成 ==> 108.小车移动中
        if (wrkMast.getWrkSts() == 107) {
        //小车移动到目标库位中  109.小车迁出提升机完成 ==> 110.小车移动中
        if (wrkMast.getWrkSts() == 109) {
            //获取四向穿梭车线程
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
@@ -2026,30 +2615,35 @@
            }
            //小车处于空闲状态
            if (!shuttleProtocol.isIdleNoCharge()) {
            if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) {
                return false;
            }
            //获取目标站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), wrkMast.getLiftNo());
            if (targetBasDevp == null) {
                return false;//缺少站点信息
            //判断小车令牌是否为当前任务
            if (shuttleProtocol.getToken() != 0 && shuttleProtocol.getToken() != wrkMast.getWrkNo()) {
                return false;
            }
            //获取提升机数据
            BasLift basLift = basLiftService.selectById(targetBasDevp.getLiftNo());
            if (basLift == null) {
                return false;//没有提升机数据
            }
            if (basLift.getPoint() == null) {
                return false;//没有设置提升机点位坐标
            }
            NavigateNode liftNode = new NavigateNode(basLift.getPoint().getX(), basLift.getPoint().getY());
            liftNode.setZ(basLift.getPoint().getZ());
//            //获取目标站对应的输送站点
//            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), wrkMast.getLiftNo());
//            if (targetBasDevp == null) {
//                return false;//缺少站点信息
//            }
//
//            //获取提升机数据
//            BasLift basLift = basLiftService.selectById(targetBasDevp.getLiftNo());
//            if (basLift == null) {
//                return false;//没有提升机数据
//            }
//            if (basLift.getPoint() == null) {
//                return false;//没有设置提升机点位坐标
//            }
//            NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
//            liftNode.setZ(basLift.getPoint$().getZ());
            //获取小车从输送站到目标库位命令
            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), targetBasDevp.getLocNo(), wrkMast.getLocNo());
            if (result.getCommands() == null) {
            //获取小车到目标库位命令
            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo());
            if (result == null) {
                return false;//路径计算失败
            }
            List<NyShuttleHttpCommand> commands = result.getCommands();
@@ -2062,9 +2656,23 @@
            assignCommand.setCommands(commands);
            assignCommand.setNodes(result.getNodes());
            wrkMast.setWrkSts(108L);//小车移动到目标库位中  107.小车迁出提升机完成 ==> 108.小车移动中
            wrkMast.setWrkSts(110L);//小车移动到目标库位中  109.小车迁出提升机完成 ==> 110.小车移动中
            wrkMast.setLiftNo(null);//释放提升机
            wrkMast.setModiTime(now);
            if (wrkMast.getLiftNo() != null) {
                LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
                if (liftThread == null) {
                    return false;
                }
                LiftProtocol liftProtocol = liftThread.getLiftProtocol();
                if (liftProtocol == null) {
                    return false;
                }
                if (liftProtocol.getToken() == shuttleProtocol.getShuttleNo().intValue()) {
                    liftProtocol.setToken(0);//释放提升机令牌
                }
            }
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
@@ -2074,6 +2682,69 @@
    }
    /**
     * 小车迁移-清理111.小车移动完成
     */
    private boolean shuttleMoveExecuteStepClearWrkMast(WrkMast wrkMast) {
        if (wrkMast.getWrkSts() == 111) {
            //获取四向穿梭车线程
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                return false;
            }
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                return false;
            }
            //小车处于空闲状态
            if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) {
                return false;
            }
            Object o = redisUtil.get("shuttle_wrk_no_" + shuttleProtocol.getTaskNo());
            if (o != null) {
                ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
                ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
                int size = assignCommand.getCommands().size();
                NyShuttleHttpCommand command = assignCommand.getCommands().get(size - 1);//获取最后一段命令
                if (!command.getComplete()) {
                    return false;//最后一段命令还未完成,不做操作
                }
                NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(shuttleProtocol.getCurrentLocNo()));
                navigateMapData.writeNavigateNodeToRedisMap(assignCommand.getNodes(), false);//解锁路径
                //删除redis
                redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo());
            }
            // 保存工作主档历史档
            if (wrkMastLocMapper.save(wrkMast.getWrkNo()) <= 0) {
                log.info("保存工作历史档[workNo={0}]失败", wrkMast.getWrkNo());
            }
            // 删除工作主档
            if (!wrkMastService.deleteById(wrkMast)) {
                log.info("删除工作主档[workNo={0}]失败", wrkMast.getWrkNo());
            }
            //设置四向穿梭车为空闲状态
            shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
            //源库位清零
            shuttleProtocol.setSourceLocNo(null);
            //目标库位清零
            shuttleProtocol.setLocNo(null);
            //任务指令清零
            shuttleProtocol.setAssignCommand(null);
            //工作号清零
            shuttleProtocol.setTaskNo(0);
            //清除令牌
            shuttleProtocol.setToken(0);
            News.info("四向穿梭车已确认且移动任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
        }
        return true;
    }
    /**
     * 出入库模式切换
     */
    public synchronized void outAndIn() {