自动化立体仓库 - WCS系统
Junjie
2023-08-01 2e84db729d434524c7b35939c76c4d7020126167
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
@@ -27,6 +28,7 @@
import com.zy.core.model.protocol.*;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.*;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -94,6 +96,8 @@
    private OrderMapper orderMapper;
    @Autowired
    private OrderDetlMapper orderDetlMapper;
    @Autowired
    private BasLiftService basLiftService;
    @Autowired
    private RedisUtil redisUtil;
@@ -200,16 +204,17 @@
                    }
                    // 过滤盘点/拣料/并板任务
//                    if (null != wrkMastMapper.selectPickStepByBarcode(barcode)) {
//                        continue;
//                    }
                    WrkMast wrkMast1 = wrkMastMapper.selectPickStepByBarcode(barcode);
                    if (null != wrkMast1) {
                        continue;
                    }
                    // 判断重复工作档
//                    WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
//                    if (wrkMast != null) {
//                        News.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast.getWrkNo());
//                        continue;
//                    }
                    WrkMast wrkMast2 = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
                    if (wrkMast2 != null) {
                        News.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast2.getWrkNo());
                        continue;
                    }
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
@@ -382,6 +387,7 @@
    /**
     * 拣料、并板、盘点再入库
     */
    @Transactional
    public synchronized void stnToCrnStnPick(){
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历拣料入库口
@@ -397,24 +403,20 @@
                }
                if (staProtocol.isAutoing()
                        && staProtocol.isLoading()
                        // 0 - 9990 或者 9996
                        && (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9990)
                        && (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9999)
                        && staProtocol.getStaNo().equals(staProtocol.getSiteId().shortValue())
                        && staProtocol.isPakMk()){
                    // 获取条码扫描仪信息
//                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
//                    if (barcodeThread == null) {
//                        continue;
//                    }
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
                    if (barcodeThread == null) {
                        continue;
                    }
                    String barcode = barcodeThread.getBarcode();
                    WrkMast wrkMast = null;
                    if (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9990) {
                        wrkMast = wrkMastMapper.selectPickStep(staProtocol.getWorkNo());
                        if (null == wrkMast) {
                            continue;
                        }
                    } else {
                    wrkMast = wrkMastMapper.selectPickStepByBarcode(barcode);
                    if (wrkMast == null) {
                        continue;
                    }
//                    if (staProtocol.getWorkNo() == 9996) {
@@ -454,6 +456,7 @@
//                            News.error("{}条码错误,暂无拣料任务!", barcode);
//                        }
//                    }
                    if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107)
                        || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo()) ) {
                        continue;
@@ -465,7 +468,7 @@
                        SearchLocParam param = new SearchLocParam();
                        param.setWrkNo(wrkMast.getWrkNo());
                        param.setIoType(wrkMast.getIoType());
                        param.setSourceStaNo(wrkMast.getSourceStaNo());
                        param.setSourceStaNo(pickSta.getStaNo());
//                        param.setLocType1(locTypeDto.getLocType1());
                        String response = new HttpHandler.Builder()
                                .setUri(wmsUrl)
@@ -508,14 +511,22 @@
                            wrkMast.setSourceStaNo(pickSta.getStaNo()); // 源站
                            wrkMast.setStaNo(dto.getStaNo()); // 目标站
                            wrkMast.setCrnNo(dto.getCrnNo());
                            wrkMast.setLocNo(dto.getLocNo()); // 目标库位 = 出库时的源库位
                            wrkMast.setSourceLocNo(""); // 源库位清空
                            wrkMast.setLocNo(sourceLocNo); // 目标库位 = 出库时的源库位
                            wrkMast.setShuttleNo(null); // 穿梭车清空
                            wrkMast.setModiTime(new Date());
                            if (wrkMastMapper.updateById(wrkMast) == 0) {
                                throw new CoolException(wrkMast.getWrkNo() + "更新工作档数据状态失败");
                            }
                            if (wrkMastMapper.setSteEmpty(wrkMast.getWrkNo()) == 0) {
                                throw new CoolException(wrkMast.getWrkNo() + "更新工作档数据状态失败");
                            }
                            // 修改库位状态 Q.拣料/盘点/并板再入库
                            LocMast locMast = locMastService.selectById(sourceLocNo);
                            locMast.setLocSts("Q");
                            locMast.setModiTime(new Date());
                            if (!locMastService.updateById(locMast)) {
                                throw new CoolException("修改库位状态失败");
                            }
                            // 更新站点信息 且 下发plc命令
@@ -564,7 +575,7 @@
     * 初始化实时地图
     */
    public synchronized void initRealtimeBasMap() {
        for (int i = 1; i <= 4; i++) {//总共四层楼
        for (int i = 1; i <= 10; i++) {//总共四层楼
            Object data = redisUtil.get("realtimeBasMap_" + i);
            if (data == null) {//redis地图数据为空,从数据库中获取
                BasMap basMap = basMapService.selectLatestMap(i);
@@ -651,7 +662,7 @@
    /**
     * 入库  ===>>  四向穿梭车入库作业下发
     */
    public synchronized void shuttleIoInExecute() {
    public synchronized void shuttleInExecute() {
        // 根据输送线plc遍历
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历入库站
@@ -665,230 +676,24 @@
                    staProtocol = staProtocol.clone();
                }
                Short workNo = staProtocol.getWorkNo();
                BasDevp basDevp = basDevpService.selectById(staProtocol.getSiteId());
                if (basDevp == null) {
                    continue;//站点信息不存在
                }
                // 判断是否满足入库条件,自动、有物、四向穿梭车可取信号
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isShuttleTakeEnable()) {
                    WrkMast wrkMast = wrkMastMapper.selectRackInStep48(workNo, staProtocol.getSiteId());
                    if (wrkMast != null) {
                        if (wrkMast.getWrkSts() == 4 || wrkMast.getWrkSts() == 8) {
                            ShuttleThread shuttleThread = null;
                            ShuttleProtocol shuttleProtocol = null;
                            HashMap<String, Object> searchIdleShuttle = null;
                if (!(staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isShuttleTakeEnable())) {
                    continue;
                }
                            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
                            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
                WrkMast wrkMast = wrkMastMapper.selectRackInStep4(workNo, staProtocol.getSiteId());
                if (wrkMast == null) {
                    continue;
                }
                            if (wrkMast.getWrkSts() == 4) {
                                if (wrkMast.getShuttleNo() == null) {
                                    //寻找最近且空闲的四向穿梭车
                                    searchIdleShuttle = this.searchIdleShuttle(wrkMast);
                                    shuttleThread = (ShuttleThread) searchIdleShuttle.get("result");
                                    wrkMast.setShuttleNo(shuttleThread.getSlave().getId());//给工作档分配四向穿梭车号
                                    wrkMastMapper.updateById(wrkMast);
                                    shuttleProtocol = shuttleThread.getShuttleProtocol();
                                    if (!shuttleProtocol.isIdle()) {
                                        continue;
                                    }
                                }else {
                                    //直接使用任务保存中的小车
                                    shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
                                    shuttleProtocol = shuttleThread.getShuttleProtocol();
                                    if (!shuttleProtocol.isIdle(workNo)) {
                                        continue;
                                    }
                                }
                            }else if(wrkMast.getWrkSts() == 8){//状态8,需要向小车下发命令从提升机移动出去,需要判断提升机状是否空闲、提升机是否到达目标楼层、目标楼层站点是否存在、目标楼层站点是否给出提升机到位信号
                                //状态8,等待命令进行入库搬运动作
                                //判断提升机是否空闲
                                if (!liftProtocol.isIdleNoTask()) {
                                    try {
                                        Thread.sleep(1000);//休眠1s
                                    } catch (InterruptedException e) {
                                        throw new RuntimeException(e);
                                    }
                                    continue;//提升机忙
                                }
                                //判断提升机任务号和当前工作档任务号是否一致
                                if (liftProtocol.getTaskNo().intValue() != 0 && liftProtocol.getTaskNo().intValue() != wrkMast.getWrkNo()) {
                                    continue;
                                }
                                //判断提升机楼层是否到位,判断站点是否给出提升机到位信号
                                String locNo = wrkMast.getLocNo();
                                int lev = Utils.getLev(locNo);//目标二维码所在楼层
                                int liftLev = liftProtocol.getLev().intValue();//提升机所在楼层
                                if (liftLev != lev) {
                                    continue;//提升机不在目标楼层跳过
                                }
                                Integer staNo = Utils.levToOutInStaNo(lev >= 2 ? lev + 1 : lev);
                                //获取目标站信息
                                StaProtocol staProtocol1 = devpThread.getStation().get(staNo);
                                if (staProtocol1 == null) {
                                    continue;//站点信息不存在
                                }
                                if (!staProtocol1.isLiftArrival()) {
                                    continue;//站点提升机到位信号false
                                }
                                Integer shuttleNo = wrkMast.getShuttleNo();//四向穿梭车号
                                shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
                                shuttleProtocol = shuttleThread.getShuttleProtocol();
                                if (!shuttleProtocol.isIdle(workNo)) {
                                    continue;
                                }
                            }
                            if (shuttleThread == null) {
                                continue;
                            }
                            if (shuttleProtocol == null) {
                                continue;
                            }
                            wrkMast.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());//给工作档分配四向穿梭车号
                            //分配任务号
                            shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());
                            //分配源库位
                            shuttleProtocol.setSourceLocNo(wrkMast.getSourceLocNo());
                            //创建分配命令
                            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
                            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
                            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号
                            assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//入出库模式
                            String currentLocNo = shuttleProtocol.getCurrentLocNo();
                            assignCommand.setSourceLocNo(currentLocNo);//源库位(小车当前位置)
                            String locNo = wrkMast.getLocNo();//当前工作档库位号
                            Integer currentLev = wrkMast.getWrkSts() == 4 ? Utils.getLev(currentLocNo) : liftProtocol.getLev();//小车当前层高
                            //提升机口站点库位号
                            String liftSiteLocNo = Utils.levToOutInStaLocNo(currentLev);
                            if (wrkMast.getWrkSts() == 4) {
                                if (currentLev == Utils.getLev(locNo)) {
                                    //小车和目标在同一楼层
                                    //直接计算车到提升机取货再到库位路径指令
                                    List<ShuttleCommand> commands = this.shuttleAssignCommand(wrkMast.getWrkSts() == 4 ? currentLocNo : liftSiteLocNo, liftSiteLocNo, locNo, assignCommand, shuttleThread);
                                    if (commands == null) {
                                        continue;//找不到路径等待下一次
                                    }
                                    assignCommand.setCommands(commands);
                                    //分配目标库位
                                    shuttleProtocol.setLocNo(wrkMast.getLocNo());
                                    //目标库位
                                    assignCommand.setLocNo(wrkMast.getLocNo());
                                    wrkMast.setWrkSts(9L);//小车入库中
                                }else {
                                    //小车和目标不在同一楼层
                                    //小车移动到提升机口,计算路径
                                    List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftSiteLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread);
                                    if (commands == null) {
                                        continue;//未找到路径
                                    }
                                    //获取当前小车所在楼层的站点信息
                                    BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo);
                                    Short endStartCode = Short.parseShort(basDevp.getQrCodeValue());//站点二维码
                                    //增加移动进提升机命令
                                    ShuttleCommand moveCommand = shuttleThread.getMoveCommand(endStartCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, null, null, 500);
                                    commands.add(moveCommand);
                                    //分配目标库位
                                    shuttleProtocol.setLocNo(liftSiteLocNo);
                                    //目标库位
                                    assignCommand.setLocNo(liftSiteLocNo);
                                    assignCommand.setCommands(commands);
                                    wrkMast.setWrkSts(5L);//小车迁移状态
                                }
                            } else if (wrkMast.getWrkSts() == 8) {
                                //直接计算车到提升机取货再到库位路径指令
                                List<ShuttleCommand> commands = this.shuttleAssignCommand(wrkMast.getWrkSts() == 4 ? currentLocNo : liftSiteLocNo, liftSiteLocNo, locNo, assignCommand, shuttleThread);
                                if (commands == null) {
                                    continue;//找不到路径等待下一次
                                }
                                //此时车在提升机内部,下达一步指令让车移动到提升机口
                                Integer staNo = Utils.levToOutInStaNo(currentLev >= 2 ? currentLev + 1 : currentLev);//站点号
                                BasDevp basDevp = basDevpService.selectById(staNo);
                                short startCode = liftProtocol.getBarcode();//提升机内部二维码
                                Short distCode = Short.parseShort(basDevp.getQrCodeValue());//提升机口站点二维码
                                Short runDirection = ShuttleRunDirection.BOTTOM.id;//运行方向
                                //获取命令
                                ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, null, null, 500);
                                commands.add(0, moveCommand);//将该指令添加到队头
                                assignCommand.setCommands(commands);
                                //分配目标库位
                                shuttleProtocol.setLocNo(wrkMast.getLocNo());
                                //目标库位
                                assignCommand.setLocNo(wrkMast.getLocNo());
                                wrkMast.setWrkSts(9L);//小车入库中
                            }
//                            if (wrkMast.getWrkSts() == 8 || Boolean.parseBoolean(searchIdleShuttle.get("sameLay").toString())) {
//                                //同一层直接取货无需经过提升机
//                                //直接计算车到提升机取货再到库位路径指令
//                                List<ShuttleCommand> commands = this.shuttleAssignCommand(wrkMast.getWrkSts() == 4 ? currentLocNo : liftSiteLocNo, liftSiteLocNo, locNo, assignCommand, shuttleThread);
//                                if (commands == null) {
//                                    continue;//找不到路径等待下一次
//                                }
//                                if (wrkMast.getWrkSts() == 8) {
//                                    //此时车在提升机内部,下达一步指令让车移动到提升机口
//                                    Integer staNo = Utils.levToOutInStaNo(currentLev >= 2 ? currentLev + 1 : currentLev);//站点号
//                                    BasDevp basDevp = basDevpService.selectById(staNo);
//
//                                    short startCode = liftProtocol.getBarcode();//提升机内部二维码
//                                    Short distCode = Short.parseShort(basDevp.getQrCodeValue());//提升机口站点二维码
//                                    Short runDirection = ShuttleRunDirection.BOTTOM.id;//运行方向
//                                    //获取命令
//                                    ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, startCode, 1600, 500);
//                                    commands.add(0, moveCommand);//将该指令添加到队头
//                                }
//                                assignCommand.setCommands(commands);
//                                //分配目标库位
//                                shuttleProtocol.setLocNo(wrkMast.getLocNo());
//                                //目标库位
//                                assignCommand.setLocNo(wrkMast.getLocNo());
//                                wrkMast.setWrkSts(9L);//小车入库中
//                            }else {
//                                //不同层,将目标库位分配成提升机库位号
//
//                                //小车移动到提升机口,计算路径
//                                List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftSiteLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread);
//                                if (commands == null) {
//                                    continue;//未找到路径
//                                }
//
//                                //获取当前小车所在楼层的站点信息
//                                BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo);
//                                Short endStartCode = Short.parseShort(basDevp.getQrCodeValue());//站点二维码
//
//                                //增加移动进提升机命令
//                                ShuttleCommand moveCommand = shuttleThread.getMoveCommand(endStartCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, endStartCode, 1600, 500);
//                                commands.add(moveCommand);
//
//                                //分配目标库位
//                                shuttleProtocol.setLocNo(liftSiteLocNo);
//                                //目标库位
//                                assignCommand.setLocNo(liftSiteLocNo);
//                                assignCommand.setCommands(commands);
//                                wrkMast.setWrkSts(5L);//小车迁移状态
//                            }
                            if (wrkMastMapper.updateById(wrkMast) > 0) {
                                //下发任务
                                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                            }
                        }
                    }
                boolean step1 = this.shuttleInExecuteStep1(wrkMast, basDevp);//小车搬入库中
                if (!step1) {
                    continue;
                }
            }
@@ -896,17 +701,76 @@
    }
    /**
     * 入库-小车搬入库中
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    public boolean shuttleInExecuteStep1(WrkMast wrkMast, BasDevp basDevp) {
        if (wrkMast.getWrkSts() == 4) {
            if (wrkMast.getShuttleNo() == null) {//没有绑定小车,进行调度
                dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo());//调度小车到货物所在输送站点进行取货
                return false;
            }
            //获取四向穿梭车线程
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                return false;
            }
            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                return false;
            }
            if (!shuttleProtocol.isIdle()) {
                return false;
            }
            //判断小车是否到达输送站点库位
            if (!shuttleProtocol.getCurrentLocNo().equals(basDevp.getLocNo())) {
                //小车不在输送站点位置
                dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo());//调度小车到货物所在输送站点进行取货
                return false;
            }
            //小车已抵达输送站点位置,进行搬运货物
            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), basDevp.getLocNo(), 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);//4.提升机搬运完成 => 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;
    }
    //获取起点-终点指令
    public synchronized List<ShuttleCommand> shuttleAssignCommand(String startLocNo, String locNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
        //获取小车移动速度
        BasShuttle basShuttle = basShuttleService.selectById(assignCommand.getShuttleNo());
        Integer runSpeed = 1000;
        if (basShuttle != null) {
            Integer runSpeed1 = basShuttle.getRunSpeed();
            if (runSpeed1 != null) {
                runSpeed = runSpeed1;
            }
        }
//        if (basShuttle != null) {
//            Integer runSpeed1 = basShuttle.getRunSpeed();
//            if (runSpeed1 != null) {
//                runSpeed = runSpeed1;
//            }
//        }
        //计算小车起点到中点所需命令
        List<NavigateNode> calc = NavigateUtils.calc(startLocNo, locNo, mapType, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(startLocNo)));
@@ -971,12 +835,12 @@
        //获取小车移动速度
        BasShuttle basShuttle = basShuttleService.selectById(assignCommand.getShuttleNo());
        Integer runSpeed = 1000;
        if (basShuttle != null) {
            Integer runSpeed1 = basShuttle.getRunSpeed();
            if (runSpeed1 != null) {
                runSpeed = runSpeed1;
            }
        }
//        if (basShuttle != null) {
//            Integer runSpeed1 = basShuttle.getRunSpeed();
//            if (runSpeed1 != null) {
//                runSpeed = runSpeed1;
//            }
//        }
        List<NavigateNode> allNode = new ArrayList<>();
@@ -1094,237 +958,78 @@
    /**
     * 出库  ===>>  四向穿梭车出库作业下发
     */
    public synchronized void shuttleIoOutExecute() {
    public synchronized void shuttleOutExecute() {
        for (WrkMast wrkMast : wrkMastMapper.selectBy2125()) {
            //提取一条待出库任务
            if (wrkMast != null) {
                String outStaLocNo = null;//出库站点库位号
                //获取出库站点
                for (DevpSlave devpSlave : slaveProperties.getDevp()) {
                    for (DevpSlave.StaRack staOutRack : devpSlave.getRackOutStn()) {
                        if (staOutRack.getStaNo().equals(wrkMast.getStaNo())) {
                            //出库站点和工作档出库站点一致
                            outStaLocNo = CommonUtils.getLocNoFromRBL(staOutRack.getRow(), staOutRack.getBay(), staOutRack.getLev());
                        }
                    }
                }
                if (wrkMast.getWrkSts() == 21
                        || wrkMast.getWrkSts() == 25
                        || wrkMast.getWrkSts() == 31) {
                    ShuttleThread shuttleThread = null;
                    HashMap<String, Object> searchIdleShuttle = null;
                    LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
                    LiftProtocol liftProtocol = liftThread.getLiftProtocol();
                    if (wrkMast.getWrkSts() == 21) {
                        if (wrkMast.getShuttleNo() == null) {
                            //寻找最近且空闲的四向穿梭车
                            searchIdleShuttle = this.searchIdleShuttle(wrkMast);
                            shuttleThread = (ShuttleThread) searchIdleShuttle.get("result");
                            if (shuttleThread == null) {
                                continue;
                            }
                            wrkMast.setShuttleNo(shuttleThread.getSlave().getId());//给工作档分配四向穿梭车号
                            wrkMastMapper.updateById(wrkMast);
                        }else {
                            //直接使用任务保存中的小车
                            shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
                        }
                    }else if(wrkMast.getWrkSts() == 25) {//状态25,需要向小车下发命令从提升机移动出去,需要判断提升机状是否空闲、提升机是否到达目标楼层、目标楼层站点是否存在、目标楼层站点是否给出提升机到位信号
                        //判断提升机是否空闲
                        if (!liftProtocol.isIdleNoTask()) {
                            try {
                                Thread.sleep(1000);//休眠1s
                            } catch (InterruptedException e) {
                                throw new RuntimeException(e);
                            }
                            continue;//提升机忙
                        }
                        //判断提升机任务号和当前工作档任务号是否一致
                        if (liftProtocol.getTaskNo().intValue() != 0 && liftProtocol.getTaskNo().intValue() != wrkMast.getWrkNo()) {
                            continue;
                        }
                        //判断提升机楼层是否到位,判断站点是否给出提升机到位信号
                        String locNo = wrkMast.getSourceLocNo();
                        int lev = Utils.getLev(locNo);//目标二维码所在楼层
                        Short liftLev = liftProtocol.getLev();//提升机所在楼层
                        if (liftLev == null) {//提升机可能在输送线楼层
                            continue;
                        }
                        if (liftLev.intValue() != lev) {
                            continue;//提升机不在目标楼层跳过
                        }
                        Integer staNo = Utils.levToOutInStaNo(lev >= 2 ? lev + 1 : lev);
                        DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
                        //获取目标站信息
                        StaProtocol staProtocol1 = devpThread.getStation().get(staNo);
                        if (staProtocol1 == null) {
                            continue;//站点信息不存在
                        }
                        if (!staProtocol1.isLiftArrival()) {
                            continue;//站点提升机到位信号false
                        }
                        //继续完成之前小车未完成的任务
                        shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
                    } else if (wrkMast.getWrkSts() == 31) {
                        //继续完成之前小车未完成的任务
                        shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
                    }
                    if (shuttleThread == null) {
                        continue;
                    }
                    ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
                    if (shuttleProtocol == null) {
                        continue;
                    }
                    if (outStaLocNo == null) {
                        continue;
                    }
                    if (wrkMast.getWrkSts() == 21) {
                        if (!shuttleProtocol.isIdle()) {
                            continue;
                        }
                        //源库位(小车当前位置)
                        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 (currentLev == Utils.getLev(wrkMast.getSourceLocNo())) {
                            //同一层(将小车移动到货物位置)
                            List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), liftSiteLocNo, assignCommand, shuttleThread);
                            if (commands == null) {
                                //未找到路径,等待下一次
                                continue;
                            }
                            //分配目标库位
                            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) {
                                if (!currentLocNo.equals(liftSiteLocNo)) {//当前位置也不在提升机口
                                    continue;//未找到路径
                                }
                                commands = new ArrayList<>();
                            }
                            shuttleProtocol.setLocNo(liftSiteLocNo);
                            //分配任务号
                            shuttleProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());
                            //分配源库位
                            shuttleProtocol.setSourceLocNo(currentLocNo);
                            //获取当前小车所在楼层的站点信息
                            BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo);
                            Short endStartCode = Short.parseShort(basDevp.getQrCodeValue());//站点二维码
                            //增加移动进提升机命令
                            ShuttleCommand moveCommand = shuttleThread.getMoveCommand(endStartCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, null, null, 500);
                            commands.add(moveCommand);
                            //目标库位
                            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) {
                        if (!shuttleProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                            continue;
                        }
                        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;//未找到路径
                        }
                        //此时车在提升机内部,需要多下达一步指令让车移动到提升机口
                        short startCode = liftProtocol.getBarcode();//提升机内部二维码
                        Short distCode = commands.get(0).getStartCodeNum();//目标二维码
                        //获取移动命令
                        ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, commands.get(0).getRunDirection(), null, null, 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));
                        }
                    }
                }
            boolean step1 = this.shuttleOutExecuteStep1(wrkMast);//小车搬出库中
            if (!step1) {
                continue;
            }
        }
    }
    /**
     * 出库-小车搬出库中
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    public boolean shuttleOutExecuteStep1(WrkMast wrkMast) {
        //21.生成出库任务 => 22.小车搬运中
        if (wrkMast.getWrkSts() == 21) {
            if (wrkMast.getShuttleNo() == null) {//没有绑定小车,进行调度
                dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//调度小车到货物所在库位进行取货
                return false;
            }
            //获取四向穿梭车线程
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                return false;
            }
            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                return false;
            }
            if (!shuttleProtocol.isIdle()) {
                return false;
            }
            //获取目标站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getLiftNo());
            if (targetBasDevp == null) {
                return false;//缺少站点信息
            }
            //判断小车是否到达货物库位
            if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
                //小车不在输送站点位置
                dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//调度小车到货物所在输送站点进行取货
                return false;
            }
            //小车已抵达货物位置,进行搬运货物
            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), targetBasDevp.getLocNo());
            if (result == null) {//出库路径计算失败
                return false;
            }
            //创建分配命令
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//任务号
            assignCommand.setTaskMode(ShuttleTaskModeType.PAK_OUT.id.shortValue());//出库模式
            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
            assignCommand.setCommands(result.getCommands());//运行命令
            assignCommand.setNodes(result.getNodes());//路径节点
            wrkMast.setWrkSts(22L);//21.生成出库任务 => 22.小车搬运中
            wrkMast.setModiTime(new Date());
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
            }
            return false;
        }
        return true;
    }
    /**
@@ -1342,10 +1047,10 @@
        //判断其他空闲穿梭车是否离任务最近
        String distLocNo = null;//目标地点,入库=》提升机口,出库=》货物库位号
        if (wrkMast.getIoType() == 1 || wrkMast.getIoType() == 10) {
        if (wrkMast.getIoType() < 101 && wrkMast.getIoType() != 11) {
            //入库
            distLocNo = Utils.levToOutInStaLocNo(lev);
        }else if(wrkMast.getIoType() == 101 || wrkMast.getIoType() == 103){
        }else if(wrkMast.getIoType() >= 101){
            //出库
            distLocNo = locNo;
        } else if (wrkMast.getIoType() == 11) {
@@ -1470,40 +1175,26 @@
                    && shuttleProtocol.getTaskNo() != 0
                    && shuttleProtocol.getBusyStatus() == 0
            ) {
                //标记复位
                shuttleProtocol.setPakMk(true);
                ShuttleAssignCommand assignCommand = shuttleProtocol.getAssignCommand();
                //将任务档标记为完成
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(shuttleProtocol.getTaskNo().intValue());
                ShuttleAssignCommand moveAssignCommand = null;//避让命令
                if (wrkMast != null) {
                    switch (wrkMast.getWrkSts().intValue()) {
                        case 9://9.小车入库搬运中 ==> 14.入库完成
                            wrkMast.setWrkSts(14L);
                        case 5://5.小车搬运中 ==> 9.入库完成
                            wrkMast.setWrkSts(9L);
                            //任务号清零
                            shuttleProtocol.setTaskNo((short) 0);
                            break;
                        case 5://5.迁移小车至提升机口 ==> 6.迁移小车至提升机口完成
                            wrkMast.setWrkSts(6L);
                            break;
                        case 22://22.迁移小车至提升机口 ==> 23.迁移小车至提升机口完成
                        case 22://22.小车搬运中 ==> 23.小车搬运完成
                            wrkMast.setWrkSts(23L);
                            break;
                        case 26://26.小车出库搬运中 ==> 27.小车出库搬运完成
                            //任务执行完后,小车进入移开提升机口站点位置,以免坠落
                            //搜索一条没有小车的空巷道,并调度小车
                            int distLev = Utils.getLev(wrkMast.getSourceLocNo());//避让楼层
                            String startLocNo = "180020" + distLev;
                            moveAssignCommand = Utils.searchEmptyGroupToMoveShuttle(distLev, shuttleThread.getSlave().getId(), shuttleThread, startLocNo);
                            if (moveAssignCommand == null) {//调度小车命令为空
                                continue;
                            }
                            wrkMast.setWrkSts(27L);
                            //任务号清零
                            shuttleProtocol.setTaskNo((short) 0);
                        case 102://102.小车到提升机中 ==> 103.小车到提升机完成
                            wrkMast.setWrkSts(103L);
                            break;
                        case 106://106.小车迁出提升机中 ==> 107.小车迁出提升机完成
                            wrkMast.setWrkSts(107L);
                            break;
                        case 108://108.小车移动中 ==> 109.小车移动完成
                            wrkMast.setWrkSts(109L);
                            break;
                        default:
                    }
@@ -1518,83 +1209,11 @@
                        //任务指令清零
                        shuttleProtocol.setAssignCommand(null);
                        News.info("四向穿梭车已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
                        if (wrkMast.getWrkSts() == 27) {
                            if (moveAssignCommand != null) {
                                try {
                                    Thread.sleep(4000);
                                    //下发任务
                                    shuttleProtocol.setPakMk(true);
                                    MessageQueue.offer(SlaveType.Shuttle, shuttleThread.getSlave().getId(), new Task(3, moveAssignCommand));
                                } catch (InterruptedException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                        }
                    } else {
                        News.error("四向穿梭车已确认且任务完成状态,复位失败,但未找到工作档。四向穿梭车号={},工作号={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo());
                    }
                }
                if (assignCommand != null) {
                    if (assignCommand.getTaskMode().intValue() == ShuttleTaskModeType.AVOID.id) {
                        //避让任务
                        //设置四向穿梭车为空闲状态
                        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                        //任务号清零
                        shuttleProtocol.setTaskNo((short) 0);
                        //源库位清零
                        shuttleProtocol.setSourceLocNo(null);
                        //目标库位清零
                        shuttleProtocol.setLocNo(null);
                        //任务指令清零
                        shuttleProtocol.setAssignCommand(null);
                        News.info("四向穿梭车避让任务已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
                    }
                }
            }
            //四向穿梭车状态为充电状态
            if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.CHARGING_WAITING.id  //充电标识
                    && shuttleProtocol.getTaskNo() != 0) {
                //查询是否有充电任务
                WrkCharge wrkCharge = wrkChargeMapper.selectByWorkNo(shuttleProtocol.getTaskNo().intValue());
                if (wrkCharge != null) {
                    switch (wrkCharge.getWrkSts().intValue()) {
                        case 52://四向穿梭车迁移到提升机口
                            wrkCharge.setWrkSts(53L);//迁移完成
                            shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING);
                            break;
                        case 56://小车去充电桩中
                            wrkCharge.setWrkSts(57L);//到达充电桩
                            break;
                        default:
                    }
                    if (wrkChargeMapper.updateById(wrkCharge) > 0) {
                        if (wrkCharge.getWrkSts() == 60) {
                            //设置四向穿梭车为空闲状态
                            shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                        }
                        if (wrkCharge.getWrkSts() != 57) {
                            //任务号清零
                            shuttleProtocol.setTaskNo((short) 0);
                            //源库位清零
                            shuttleProtocol.setSourceLocNo(null);
                            //目标库位清零
                            shuttleProtocol.setLocNo(null);
                            //标记复位
                            shuttleProtocol.setPakMk(true);
                            //任务指令清零
                            shuttleProtocol.setAssignCommand(null);
                        }
                        News.info("四向穿梭车已确认且任务完成状态,复位。四向穿梭车号={}", shuttleProtocol.getShuttleNo());
                    } else {
                        News.error("四向穿梭车已确认且任务完成状态,复位失败,但未找到工作档。四向穿梭车号={},工作号={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo());
                    }
                }
            }
        }
@@ -1614,19 +1233,13 @@
                continue;
            }
//            if (!liftProtocol.isIdle()) {
//                continue;
//            }
            //判断提升机是否处于空闲状态,没有判断任务号,可能提升机处于空闲,但是还有任务未完成
            if (!liftProtocol.isIdleNoTask()) {
            if (!liftProtocol.isIdle()) {
                continue;
            }
            //搜索是否有待处理的任务
            List<WrkMast> wrkMasts = wrkMastMapper.selectLiftStep262327();
            if (wrkMasts.size() == 0) {
            List<WrkMast> wrkMasts = wrkMastMapper.selectLiftStep223103();
            if (wrkMasts.isEmpty()) {
                continue;
            }
@@ -1637,243 +1250,142 @@
                    continue;
                }
                //命令list
                ArrayList<LiftCommand> commands = new ArrayList<>();
                DevpThread devpThread = null;
                Integer devpId = null;
                for (DevpSlave devp : slaveProperties.getDevp()){
                    // 获取入库站信息
                    devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    devpId = devp.getId();
                boolean stepIn = this.liftIoExecuteStepIn(wrkMast);//提升机入库
                if (!stepIn) {
                    continue;
                }
                if (wrkMast.getWrkSts() == 2) {//2.设备上走
                    if (liftProtocol.getTaskNo().intValue() != 0) {
                        //存在未完成任务号
                        continue;
                    }
                    if (liftProtocol.getPlatShuttleCheck()) {
                        //提升机此时有四向车,可能有未完成的任务,禁止分配新任务
                        continue;
                    }
                    //获取目标站
                    StaProtocol staProtocol = devpThread.getStation().get(wrkMast.getStaNo());
                    if (staProtocol.isLoading() || !staProtocol.isInEnable()) {//目标站有物,不可入,禁止分配任务
                        continue;
                    }
                    //工作档目标库位号
                    String wrkMastLocNo = wrkMast.getLocNo();
                    //工作档目标库位楼层
                    int wrkMastLocNoLey = Utils.getLev(wrkMastLocNo);
                    Integer levTmp = wrkMastLocNoLey;
                    if (wrkMastLocNoLey >= 2) {
                        levTmp += 1;
                    }
                    Integer distStaNo = Utils.levToOutInStaNo(levTmp);
                    if (liftProtocol.getPositionArrivalFeedback().intValue() != LiftLevType.TWO.realLev.intValue()) {
                        //提升机不在输送线楼层,获取到输送线层的提升机命令
                        LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), LiftLevType.TWO.lev);
                        commands.add(command1);//将命令添加进list
                    }
                    //输送线将货物运进来(无货正转)
                    LiftCommand command2 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 3);
                    command2.setOperaStaNo((short) 102);//操作102站
                    command2.setRotationDire(1);//给输送线下发链条转动信号,正转
                    command2.setDevpId(devpId);
                    command2.setStaNo(distStaNo.shortValue());//设置目标站
                    commands.add(command2);//将命令添加进list
                    //提升机前往目标楼层(工作档目标楼层)
                    LiftCommand command3 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), levTmp);
                    commands.add(command3);//将命令添加进list
                    //提升机到达指定楼层,输送线将货物移出去(正转)
                    //输送线将货物移出去
                    LiftCommand command4 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 1);
                    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.setLiftNo(liftProtocol.getLiftNo().intValue());//设置提升机号用于锁定提升机防止被其他任务占用
                    wrkMast.setWrkSts(3L);//3.提升机搬运中
                } else if (wrkMast.getWrkSts() == 6) {//6.迁移小车至提升机口完成 => 7.提升机迁移小车中
                    if (liftProtocol.getTaskNo().intValue() != 0 && liftProtocol.getTaskNo().intValue() != wrkMast.getWrkNo()) {
                        //提升机存在未完成任务,且提升机任务号和当前工作档任务号不一致
                        continue;
                    }
                    liftProtocol.setShuttleNo(wrkMast.getShuttleNo().shortValue());//设置四向穿梭车号
                    //判断小车是否在提升机内,且处于空闲状态
                    ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
                    if (shuttleThread == null) {
                        continue;
                    }
                    ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
                    if (shuttleProtocol == null) {
                        continue;
                    }
                    if (!shuttleProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                        continue;//小车状态忙
                    }
                    if (shuttleProtocol.getCurrentCode().intValue() != liftProtocol.getBarcode().intValue()) {
                        continue;//小车当前二维码和提升机内部二维码不一致,不允许执行
                    }
                    if (!liftProtocol.getPlatShuttleCheck()) {
                        //提升机未检测到小车,禁止执行
                        continue;
                    }
                    //工作档目标库位号
                    String wrkMastLocNo = wrkMast.getLocNo();
                    //工作档目标库位楼层
                    int wrkMastLocNoLey = Utils.getLev(wrkMastLocNo);
                    if (wrkMastLocNoLey >= 2) {
                        wrkMastLocNoLey++;
                    }
                    //提升机前往目标楼层(工作档目标楼层)
                    LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), wrkMastLocNoLey);
                    commands.add(command1);//将命令添加进list
                    //给提升机分配任务
                    liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号
                    liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中
                    wrkMast.setLiftNo(liftProtocol.getLiftNo().intValue());//设置提升机号用于锁定提升机防止被其他任务占用
                    wrkMast.setWrkSts(7L);//6.迁移小车至提升机口完成 => 7.提升机迁移小车中
                } else if(wrkMast.getWrkSts() == 23) {//23.迁移小车至提升机口完成 => 24.提升机迁移小车中
                    if (liftProtocol.getTaskNo().intValue() != 0 && liftProtocol.getTaskNo().intValue() != wrkMast.getWrkNo()) {
                        //提升机存在未完成任务,且提升机任务号和当前工作档任务号不一致
                        continue;
                    }
                    liftProtocol.setShuttleNo(wrkMast.getShuttleNo().shortValue());//设置四向穿梭车号
                    //判断小车是否在提升机内,且处于空闲状态
                    ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
                    if (shuttleThread == null) {
                        continue;
                    }
                    ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
                    if (shuttleProtocol == null) {
                        continue;
                    }
                    if (!shuttleProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                        continue;//小车状态忙
                    }
                    if (shuttleProtocol.getCurrentCode().intValue() != liftProtocol.getBarcode().intValue()) {
                        continue;//小车当前二维码和提升机内部二维码不一致,不允许执行
                    }
                    if (!liftProtocol.getPlatShuttleCheck()) {
                        //提升机未检测到小车,禁止执行
                        continue;
                    }
                    //工作档目标库位号
                    String wrkMastLocNo = wrkMast.getSourceLocNo();
                    //工作档目标库位楼层
                    int wrkMastLocNoLey = Utils.getLev(wrkMastLocNo);
                    if (wrkMastLocNoLey >= 2) {
                        wrkMastLocNoLey++;
                    }
                    //提升机前往目标楼层(工作档目标楼层)
                    LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), wrkMastLocNoLey);
                    commands.add(command1);//将命令添加进list
                    //给提升机分配任务
                    liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号
                    liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中
                    wrkMast.setLiftNo(liftProtocol.getLiftNo().intValue());//设置提升机号用于锁定提升机防止被其他任务占用
                    wrkMast.setWrkSts(24L);//23.迁移小车至提升机口完成 => 24.提升机迁移小车中
                } else if (wrkMast.getWrkSts() == 27) {//27.小车出库搬运完成
                    if (liftProtocol.getTaskNo().intValue() != 0 && liftProtocol.getTaskNo().intValue() != wrkMast.getWrkNo()) {
                        //提升机存在未完成任务,且提升机任务号和当前工作档任务号不一致
                        continue;
                    }
                    if (liftProtocol.getPlatShuttleCheck()) {
                        //提升机此时有四向车,可能有未完成的任务,禁止分配新任务
                        continue;
                    }
                    //工作档源库位号
                    String wrkMastLocNo = wrkMast.getSourceLocNo();
                    //工作档源库位楼层
                    int wrkMastLocNoLey = Utils.getLev(wrkMastLocNo);
                    //提升机当前楼层
                    int liftLev = liftProtocol.getLev().intValue();
                    //判断提升机是否到位
                    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
                    }
                    //输送线将货物运进来(无货反转)
                    LiftCommand command2 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 4);
                    command2.setOperaStaNo(staProtocol.getSiteId().shortValue());//输送线操作站点号
                    command2.setRotationDire(2);//给输送线下发链条转动信号,反转
                    command2.setDevpId(devpId);//输送线ID
                    command2.setStaNo((short) 104);//写入出库目标站104
                    commands.add(command2);//将命令添加进list
                    //提升机前往出库口,输送线楼层
                    LiftCommand command3 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), LiftLevType.TWO.lev);
                    command3.setDevpId(devpId);//输送线ID
                    commands.add(command3);//将命令添加进list
                    //提升机到达指定楼层,输送线将货物移出去(反转)
                    //输送线将货物移出去
                    LiftCommand command4 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 2);
                    command4.setOperaStaNo((short) 102);//操作102站
                    command4.setRotationDire(2);//给输送线下发链条转动信号,反转
                    command4.setDevpId(devpId);//输送线ID
                    commands.add(command4);//将命令添加进list
                    //提升机链条执行完毕后,给102站写入资料
                    LiftCommand command5 = liftThread.getResetCommand();
                    command5.setDevpId(devpId);//输送线ID
                    command5.setOperaStaNo((short) 102);//操作102站
                    command5.setStaNo((short) 104);//写入出库目标站104
                    command5.setRotationDire(0);//链条转动停止
                    commands.add(command5);
                    //给提升机分配任务
                    liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//设置任务号
                    liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中
                    wrkMast.setLiftNo(liftProtocol.getLiftNo().intValue());//设置提升机号用于锁定提升机防止被其他任务占用
                    wrkMast.setWrkSts(28L);//28.提升机搬运中
                }
                //所需命令组合完毕,更新数据库,提交到线程去工作
                LiftAssignCommand assignCommand = new LiftAssignCommand();
                assignCommand.setCommands(commands);
                assignCommand.setLiftNo(liftProtocol.getLiftNo());
                assignCommand.setTaskNo(liftProtocol.getTaskNo());
                if (wrkMastMapper.updateById(wrkMast) > 0) {
                    //下发任务
                    MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
                boolean stepOut = this.liftIoExecuteStepOut(wrkMast);//提升机出库
                if (!stepOut) {
                    continue;
                }
            }
        }
    }
    /**
     * 提升机入库
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean liftIoExecuteStepIn(WrkMast wrkMast) {
        //--------------------------------------提升机入库-----------------------------------------//
        Date now = new Date();
        //2.设备上走 ==> 3.提升机搬运中
        if (wrkMast.getWrkSts() == 2) {
            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;
            }
            //判断提升机是否有其他任务
            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId());
            if (liftWrkMast != null) {
                return false;//当前提升机存在未完成任务,等待下一次轮询
            }
            //获取源站对应的输送站点
            BasDevp sourceBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo());
            //获取目标站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getStaNo());
            if (sourceBasDevp == null || targetBasDevp == null) {
                return false;//缺少站点信息
            }
            //获取提升机命令
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), 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(3L);//2.设备上走 ==> 3.提升机搬运中
            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 false;
        }
        return true;
    }
    /**
     * 提升机出库
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean liftIoExecuteStepOut(WrkMast wrkMast) {
        //--------------------------------------提升机出库-----------------------------------------//
        Date now = new Date();
        //23.小车搬运完成 ==> 24.提升机搬运中
        if (wrkMast.getWrkSts() == 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(wrkMast.getWrkNo().shortValue())) {
                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;//缺少站点信息
            }
            //获取提升机命令
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), 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.setModiTime(now);
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
            }
            return false;
        }
        return true;
    }
    /**
@@ -1891,66 +1403,22 @@
            //提升机为等待确认且空闲
            if (liftProtocol.getProtocolStatus() == LiftProtocolStatusType.WAITING.id
                    && liftProtocol.getTaskNo() != 0
                    && !liftProtocol.getRunning()
                    && !liftProtocol.getBusy()
            ) {
                DevpThread devpThread = null;
                Integer devpId = null;
                for (DevpSlave devp : slaveProperties.getDevp()){
                    // 获取入库站信息
                    devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    devpId = devp.getId();
                }
                //将任务档标记为完成
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo372428(liftProtocol.getTaskNo().intValue());
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo324104(liftProtocol.getTaskNo().intValue());
                if (wrkMast != null) {
                    //判断提升机是否到达任务楼层
                    String locNo = wrkMast.getIoType() < 101 ? wrkMast.getLocNo() : wrkMast.getSourceLocNo();
                    int lev = Utils.getLev(locNo);//任务目标楼层
                    //标记复位
                    liftProtocol.setPakMk(true);
                    switch (wrkMast.getWrkSts().intValue()) {
                        case 3://3.提升机搬运中 ==> 4.提升机搬运完成
                            if (liftProtocol.getLev().intValue() != lev) {
                                continue;//提升机没有到达目标
                            }
                            //给目标站设置工作号
                            StaProtocol staProtocol = devpThread.getStation().get(wrkMast.getStaNo());//目标站
                            staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                            staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                            boolean result = MessageQueue.offer(SlaveType.Devp, devpId, new Task(2, staProtocol));
                            if (!result) {
                                throw new CoolException("更新plc站点信息失败");
                            }
                            wrkMast.setWrkSts(4L);
                            //任务号清零
                            liftProtocol.setTaskNo((short) 0);
                            wrkMast.setLiftNo(null);//提升机解锁
                            wrkMast.setLiftNo(null);//释放提升机
                            break;
                        case 7://7.提升机迁移小车中 ==> 8.提升机迁移小车完成
                            if (liftProtocol.getLev().intValue() != lev) {
                                continue;//提升机没有到达目标
                            }
                            wrkMast.setWrkSts(8L);
                            break;
                        case 24://24.提升机迁移小车中 ==> 25.提升机迁移小车完成
                            if (liftProtocol.getLev().intValue() != lev) {
                                continue;//提升机没有到达目标
                            }
                        case 24://24.提升机搬运中 ==> 25.提升机搬运完成
                            wrkMast.setWrkSts(25L);
                            break;
                        case 28://28.提升机搬运中 ==> 29.提升机搬运完成
                            if (liftProtocol.getPositionArrivalFeedback().intValue() != 2) {
                                continue;//提升机是否达到输送线楼层
                            }
                            wrkMast.setWrkSts(29L);
                            wrkMast.setWrkSts(34L);//34.出库完成,暂时先直接完成出库工作档,后续需要根据输送线给出的状态来确定34.出库完成状态
                            //任务号清零
                            liftProtocol.setTaskNo((short) 0);
                            wrkMast.setLiftNo(null);//提升机解锁
                        case 104://104.提升机搬运中 ==> 105.提升机搬运完成
                            wrkMast.setWrkSts(105L);
                            break;
                        default:
                    }
@@ -1964,50 +1432,6 @@
                    } else {
                        News.error("提升机已确认且任务完成状态,复位失败,但未找到工作档。提升机号={},工作号={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo());
                    }
                }
                //查询是否有充电任务
                WrkCharge wrkCharge = wrkChargeMapper.selectByWorkNo(liftProtocol.getTaskNo().intValue());
                if (wrkCharge != null) {
                    //标记复位
                    liftProtocol.setPakMk(true);
                    switch (wrkCharge.getWrkSts().intValue()) {
                        case 54://提升机搬运中
                            wrkCharge.setWrkSts(55L);//提升机搬运完成
                            break;
                        default:
                    }
                    if (wrkChargeMapper.updateById(wrkCharge) > 0) {
                        //设置提升机为空闲状态
                        liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
                        //任务号清零
                        liftProtocol.setTaskNo((short) 0);
                        //标记复位
                        liftProtocol.setPakMk(true);
                        //任务指令清零
                        liftProtocol.setAssignCommand(null);
                        News.info("提升机已确认且任务完成状态,复位。提升机号={}", liftProtocol.getLiftNo());
                    } else {
                        News.error("提升机已确认且任务完成状态,复位失败,但未找到工作档。提升机号={},工作号={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo());
                    }
                }
                //不是入出库调度任务、工作档任务,进行提升机的复位
                if (liftProtocol.getAssignCommand() != null) {
                    //设置提升机为空闲状态
                    liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
                    //判断是否为四向穿梭车调度提升机,如是则无需清理任务号
                    if (!liftProtocol.getSecurityMk()) {
                        //任务号清零
                        liftProtocol.setTaskNo((short) 0);
                    }
                    //标记复位
                    liftProtocol.setPakMk(true);
                    //任务指令清零
                    liftProtocol.setAssignCommand(null);
                    News.info("提升机已确认且任务完成状态,复位。提升机号={}", liftProtocol.getLiftNo());
                }
            }
@@ -2110,15 +1534,15 @@
                BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo);
                Short endStartCode = Short.parseShort(basDevp.getQrCodeValue());//站点二维码
                //增加移动进提升机命令
                ShuttleCommand moveCommand = shuttleThread.getMoveCommand(endStartCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, null, null, 500);
                commands.add(moveCommand);
//                //增加移动进提升机命令
//                ShuttleCommand moveCommand = shuttleThread.getMoveCommand(endStartCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, null, null, 500);
//                commands.add(moveCommand);
                //分配目标库位
                shuttleProtocol.setLocNo(liftSiteLocNo);
                //目标库位
                assignCommand.setLocNo(liftSiteLocNo);
                assignCommand.setCommands(commands);
//                assignCommand.setCommands(commands);
                wrkMast.setWrkSts(5L);//小车迁移状态
                if (wrkMastMapper.updateById(wrkMast) > 0) {
@@ -2202,15 +1626,15 @@
                    return false;//站点提升机到位信号false
                }
                BasDevp basDevp = basDevpService.selectById(staNo);
                short startCode = liftProtocol.getBarcode();//提升机内部二维码
                Short distCode = Short.parseShort(basDevp.getQrCodeValue());//提升机口站点二维码
                Short runDirection = ShuttleRunDirection.BOTTOM.id;//运行方向
                //获取命令
                ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, null, null, 500);
                commands.add(0, moveCommand);//将该指令添加到队头
//                BasDevp basDevp = basDevpService.selectById(staNo);
//                short startCode = liftProtocol.getBarcode();//提升机内部二维码
//                Short distCode = Short.parseShort(basDevp.getQrCodeValue());//提升机口站点二维码
//                Short runDirection = ShuttleRunDirection.BOTTOM.id;//运行方向
//                //获取命令
//                ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, null, null, 500);
//                commands.add(0, moveCommand);//将该指令添加到队头
                currentLocNo = basDevp.getLocNo();//使用输送站点口作为起点坐标
//                currentLocNo = basDevp.getLocNo();//使用输送站点口作为起点坐标
            }
            //直接计算车到源库位到目标库位路径
@@ -2225,7 +1649,7 @@
            //分配源库位
            shuttleProtocol.setSourceLocNo(wrkMast.getSourceLocNo());
            assignCommand.setCommands(commands);
//            assignCommand.setCommands(commands);
            //分配目标库位
            shuttleProtocol.setLocNo(wrkMast.getLocNo());
            //目标库位
@@ -2743,7 +2167,7 @@
                    commands.add(command);
                    //指令集分配
                    assignCommand.setCommands(commands);
//                    assignCommand.setCommands(commands);
                    wrkCharge.setWrkSts(56L);//充电中状态
                    if (wrkChargeMapper.updateById(wrkCharge) > 0) {
@@ -2771,9 +2195,9 @@
                    }
                    Short basDevpQrCode = Short.parseShort(basDevp.getQrCodeValue());//站点二维码
                    //增加移动进提升机命令
                    ShuttleCommand moveCommand = shuttleThread.getMoveCommand(basDevpQrCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, basDevpQrCode, 1600, 500);
                    commands.add(moveCommand);
//                    //增加移动进提升机命令
//                    ShuttleCommand moveCommand = shuttleThread.getMoveCommand(basDevpQrCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, basDevpQrCode, 1600, 500);
//                    commands.add(moveCommand);
                    //分配目标库位
                    shuttleProtocol.setLocNo(chargeLocNo);
@@ -2785,7 +2209,7 @@
                    assignCommand.setLocNo(chargeLocNo);
                    //源库位
                    assignCommand.setSourceLocNo(currentLocNo);
                    assignCommand.setCommands(commands);
//                    assignCommand.setCommands(commands);
                    wrkCharge.setWrkSts(52L);//小车迁移状态
                    if (wrkChargeMapper.updateById(wrkCharge) > 0) {
                        //下发任务
@@ -2801,11 +2225,11 @@
                    continue;
                }
                //判断小车是否在提升机内
                if (shuttleProtocol.getCurrentCode().intValue() != liftProtocol.getBarcode().intValue()) {
                    //小车不在提升机内
                    continue;
                }
//                //判断小车是否在提升机内
//                if (shuttleProtocol.getCurrentCode().intValue() != liftProtocol.getBarcode().intValue()) {
//                    //小车不在提升机内
//                    continue;
//                }
                //给提升机分配任务
                liftProtocol.setTaskNo(wrkCharge.getWrkNo().shortValue());//设置任务号
@@ -2815,15 +2239,15 @@
                //命令list
                ArrayList<LiftCommand> commands = new ArrayList<>();
                //提升机前往目标楼层
                //获取充电库位目标楼层命令
                LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), chargeLocNoLev >= 2 ? chargeLocNoLev + 1 : chargeLocNoLev);
                commands.add(command1);//将命令添加进list
//                //提升机前往目标楼层
//                //获取充电库位目标楼层命令
//                LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), chargeLocNoLev >= 2 ? chargeLocNoLev + 1 : chargeLocNoLev);
//                commands.add(command1);//将命令添加进list
                wrkCharge.setWrkSts(54L);//提升机搬运中
                //所需命令组合完毕,更新数据库,提交到线程去工作
                LiftAssignCommand assignCommand = new LiftAssignCommand();
                assignCommand.setCommands(commands);
//                assignCommand.setCommands(commands);
                assignCommand.setLiftNo(liftProtocol.getLiftNo());
                assignCommand.setTaskNo(liftProtocol.getTaskNo());
                if (wrkChargeMapper.updateById(wrkCharge) > 0) {
@@ -2858,12 +2282,12 @@
                    continue;//未找到路径
                }
                short startCode = liftProtocol.getBarcode();//提升机内部二维码
                Short distCode = Short.parseShort(basDevp.getQrCodeValue());//提升机口站点二维码
                Short runDirection = ShuttleRunDirection.BOTTOM.id;//运行方向
                //获取命令
                ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, startCode, 1600, 500);
                commands.add(0, moveCommand);//将该指令添加到队头
//                short startCode = liftProtocol.getBarcode();//提升机内部二维码
//                Short distCode = Short.parseShort(basDevp.getQrCodeValue());//提升机口站点二维码
//                Short runDirection = ShuttleRunDirection.BOTTOM.id;//运行方向
//                //获取命令
//                ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, startCode, 1600, 500);
//                commands.add(0, moveCommand);//将该指令添加到队头
                //进行充电中
                shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING);
@@ -2878,7 +2302,7 @@
                commands.add(command);
                //指令集分配
                assignCommand.setCommands(commands);
//                assignCommand.setCommands(commands);
                wrkCharge.setWrkSts(56L);//充电中状态
                if (wrkChargeMapper.updateById(wrkCharge) > 0) {
@@ -2930,6 +2354,539 @@
    }
    /**
     * 调度车辆-调度指定穿梭车
     */
    public void dispatchShuttle(Integer wrkNo, String locNo, Integer shuttleNo) {
        shuttleMoveGenerate(wrkNo, locNo, shuttleNo);
    }
    /**
     * 调度车辆
     */
    public void dispatchShuttle(Integer wrkNo, String locNo) {
        ArrayList<NyShuttleThread> sameLev = new ArrayList<>();//相同楼层的穿梭车
        ArrayList<NyShuttleThread> diffLev = new ArrayList<>();//不同楼层的穿梭车
        for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
            //获取四向穿梭车线程
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
                continue;
            }
            if (!shuttleProtocol.isIdle()) {
                continue;
            }
            int currentLev = shuttleProtocol.getPoint().getZ();//小车当前层高
            String currentLocNo = shuttleProtocol.getCurrentLocNo();//小车当前库位号
            if (currentLocNo.equals(locNo)) {
                //车辆当前位置已经是目标库位,调度该车
                shuttleMoveGenerate(wrkNo, locNo, shuttleProtocol.getShuttleNo().intValue());
                break;
            }
            if (currentLev == Utils.getLev(locNo)) {
                //工作档楼层相同的穿梭车
                sameLev.add(shuttleThread);
            }else {
                //工作档不同楼层的穿梭车
                diffLev.add(shuttleThread);
            }
        }
        Integer recentAllDistance = 9999999;
        NyShuttleThread recentShuttle = null;//当前距离最近的四向穿梭车线程
        if (sameLev.size() > 0) {
            //同一楼层有空闲穿梭车,则只在工作档楼层寻找
            //寻找离任务最近的穿梭车
            for (NyShuttleThread shuttleThread : sameLev) {
                //当前穿梭车库位号
                String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo();
                //当前穿梭车线程到目标地点距离
                List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(currentLocNo)));//搜索空闲穿梭车,使用正常通道地图
                if (currentShuttlePath == null) {
                    continue;
                }
                Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离
                if (currentAllDistance < recentAllDistance) {
                    //如果当前楼层的车路径更小,则更新最近穿梭车
                    recentShuttle = shuttleThread;
                }
            }
        }else {
            //同一楼层,没有空闲穿梭车,只能从其他楼层调度
            //寻找离任务最近的穿梭车
            for (NyShuttleThread shuttleThread : diffLev) {
                //当前穿梭车库位号
                String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo();
                int currentLev = Utils.getLev(currentLocNo);
                List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//判断当前穿梭车楼层是否有待分配车辆的任务,如果有则不分配这辆车
                if (wrkMasts1.size() > 0) {
                    //存在其他任务,跳过这辆车
                    continue;
                }
                //当前穿梭车线程到当前车子所在楼层的提升机口距离
                List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, Utils.levToOutInStaLocNo(currentLev), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), currentLev));//搜索空闲穿梭车,使用正常通道地图
                if (currentShuttlePath == null) {
                    continue;
                }
                Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//计算当前路径行走总距离
                if (currentAllDistance < recentAllDistance) {
                    //如果当前楼层的车路径更小,则更新最近穿梭车
                    recentShuttle = shuttleThread;
                }
            }
        }
        if (recentShuttle == null) {//没有搜索到可用穿梭车
            return;
        }
        //搜索到可用穿梭车,调度该车
        shuttleMoveGenerate(wrkNo, locNo, recentShuttle.getSlave().getId());
    }
    /**
     * 小车迁移任务生成
     */
    @Transactional
    public boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) {
        Date now = new Date();
        //获取四向穿梭车线程
        NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
        if (shuttleThread == null) {
            return false;
        }
        NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
        if (shuttleProtocol == null) {
            return false;
        }
        //小车处于空闲状态
        if (!shuttleProtocol.isIdleNoCharge()) {
            return false;
        }
        //判断穿梭车是否存在未完成的小车移库任务
        WrkMast hasMoveWorking = wrkMastMapper.selectShuttleHasMoveWorking(shuttleNo);
        if (hasMoveWorking != null) {//小车存在移库任务,等待执行完成后再生成新的任务
            return false;
        }
        //判断是否有其他任务正在使用穿梭车
        WrkMast wrkMast2 = wrkMastMapper.selectShuttleWorking(shuttleNo);
        if (wrkMast2 != null) {//小车存在其他工作档任务,等待执行完成后再生成新的任务
            return false;
        }
        //判断是否有充电任务正在使用穿梭车
        WrkCharge wrkCharge = wrkChargeMapper.selectWorking(shuttleNo);
        if (wrkCharge != null) {//小车存在充电任务,等待执行完成后再生成新的任务
            return false;
        }
        // 获取工作号
        int workNo = commonService.getWorkNo(0);
        // 保存工作档
        WrkMast wrkMast = new WrkMast();
        wrkMast.setWrkNo(workNo);
        wrkMast.setIoTime(now);
        wrkMast.setWrkSts(101L); // 工作状态:101.移动到近点等待迁出
        wrkMast.setIoType(200); // 入出库状态: 200.小车移库
        wrkMast.setIoPri(20D);
        wrkMast.setShuttleNo(shuttleNo);//穿梭车号
        wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 源库位 => 小车当前库位号
        wrkMast.setLocNo(locNo); // 目标库位
        wrkMast.setPicking("N"); // 拣料
        wrkMast.setExitMk("N"); // 退出
        wrkMast.setLinkMis("N");
        wrkMast.setAppeTime(now);
        wrkMast.setModiTime(now);
        int res = wrkMastMapper.insert(wrkMast);
        if (res == 0) {
            News.error("小车迁移 --- 保存工作档失败! 穿梭车号:" + shuttleNo);
            throw new CoolException("保存工作档失败");
        }
        //给工作档绑定小车号
        WrkMast wrkMast1 = wrkMastMapper.selectByWorkNo(wrkNo);
        if (wrkMast1 != null) {
            wrkMast1.setShuttleNo(shuttleNo);
            wrkMastMapper.updateById(wrkMast1);
        }
        return true;
    }
    /**
     * 执行小车移库任务
     */
    public synchronized void shuttleMoveExecute() {
        //查询小车移库任务
        List<WrkMast> wrkMasts = wrkMastMapper.selectShuttleMoveWrk();
        for (WrkMast wrkMast : wrkMasts) {
            boolean step1 = this.shuttleMoveExecuteStep1(wrkMast);//小车移动到提升机中
            if (!step1) {
                continue;
            }
            boolean step2 = this.shuttleMoveExecuteStep2(wrkMast);//提升机搬运中
            if (!step2) {
                continue;
            }
            boolean step3 = this.shuttleMoveExecuteStep3(wrkMast);//小车迁出提升机中
            if (!step3) {
                continue;
            }
            boolean step4 = this.shuttleMoveExecuteStep4(wrkMast);//小车移动到目标库位中
            if (!step4) {
                continue;
            }
        }
    }
    /**
     * 小车迁移-小车移动到提升机中
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean shuttleMoveExecuteStep1(WrkMast wrkMast) {
        //--------------------------------------小车移动到提升机中-----------------------------------------//
        Date now = new Date();
        //小车移动到提升机中  101.生成小车移库任务 ==> 102.小车到提升机中
        if (wrkMast.getWrkSts() == 101) {
            //获取四向穿梭车线程
            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 (Utils.getLev(wrkMast.getLocNo()) == shuttleProtocol.getPoint().getZ()) {
                //目标库位和小车库位处于同一楼层,需要通过提升机调度
                return true;//直接进入108.小车移动中
            }
            //计算距离小车最近的提升机站点
            //查询小车所在楼层提升机输送站点
            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;//更新输送站点
                }
            }
            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;//路径计算失败
            }
            List<NyShuttleHttpCommand> commands = result.getCommands();
            commands.add(moveCommand);//添加小车迁入提升机命令
            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.setNodes(result.getNodes());
            wrkMast.setWrkSts(102L);//小车移动到提升机中  101.生成小车移库任务 ==> 102.小车到提升机中
            wrkMast.setLiftNo(basLift.getLiftNo());//提升机号(锁定提升机防止被其他任务抢占)
            wrkMast.setModiTime(now);
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
            }
        }
        return true;
    }
    /**
     * 小车迁移-提升机搬运中
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean shuttleMoveExecuteStep2(WrkMast wrkMast) {
        //--------------------------------------提升机搬运中-----------------------------------------//
        Date now = new Date();
        //提升机搬运中  103.小车到提升机完成 ==> 104.提升机搬运中
        if (wrkMast.getWrkSts() == 103) {
            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;
            }
            //获取四向穿梭车线程
            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;
            }
            //获取源站对应的输送站点
            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;//缺少站点信息
            }
            //获取提升机命令
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), 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(104L);//提升机搬运中  103.小车到提升机完成 ==> 104.提升机搬运中
            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 shuttleMoveExecuteStep3(WrkMast wrkMast) {
        //--------------------------------------小车迁出提升机中-----------------------------------------//
        Date now = new Date();
        //小车迁出提升机中  105.提升机搬运完成 ==> 106.小车迁出提升机中
        if (wrkMast.getWrkSts() == 105) {
            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;
            }
            //获取四向穿梭车线程
            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;
            }
            //获取目标站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), liftProtocol.getLiftNo().intValue());
            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());
            List<NyShuttleHttpCommand> commands = new ArrayList<>();
            //获取小车出提升机行走命令
            NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), liftNode, NavigatePositionConvert.locNoToNode(targetBasDevp.getLocNo()), false);
            commands.add(moveCommand);//添加小车迁出提升机命令
            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.setNodes(null);
            wrkMast.setWrkSts(106L);//小车迁出提升机中  105.提升机搬运完成 ==> 106.小车迁出提升机中
            wrkMast.setModiTime(now);
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
            }
        }
        return true;
    }
    /**
     * 小车迁移-小车移动到目标库位中
     * 如需主方法执行continue,请返回false
     * ps:返回值true并不代表该方法执行成功,返回值仅做标记用于主方法是否执行continue
     */
    private boolean shuttleMoveExecuteStep4(WrkMast wrkMast) {
        //--------------------------------------小车移动到目标库位中-----------------------------------------//
        Date now = new Date();
        //小车移动到目标库位中  107.小车迁出提升机完成 ==> 108.小车移动中
        if (wrkMast.getWrkSts() == 107) {
            //获取四向穿梭车线程
            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;
            }
            //获取目标站对应的输送站点
            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) {
                return false;//路径计算失败
            }
            List<NyShuttleHttpCommand> commands = result.getCommands();
            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.setNodes(result.getNodes());
            wrkMast.setWrkSts(108L);//小车移动到目标库位中  107.小车迁出提升机完成 ==> 108.小车移动中
            wrkMast.setLiftNo(null);//释放提升机
            wrkMast.setModiTime(now);
            if (wrkMastMapper.updateById(wrkMast) > 0) {
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
            }
        }
        return true;
    }
    /**
     * 出入库模式切换