自动化立体仓库 - WCS系统
#
18516761980
2022-06-09 d251a0234fae2d58ff8a9d92069064617dc0a94b
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -87,6 +87,7 @@
    private BasErrLogService basErrLogService;
    @Autowired
    private BasCrnErrorMapper basCrnErrorMapper;
    @Value("${wms.url}")
    private String wmsUrl;
@@ -404,19 +405,23 @@
                            throw new CoolException("保存工作主档历史档失败");
                        }
                        Date now = new Date();
                        // 堆垛机站点(目标站)
                        Integer staNo = staDesc.getCrnStn();
                        // 更新工作档数据状态
                        wrkMast.setIoTime(now);
                        wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54,107->57
                        wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
                        wrkMast.setSourceStaNo(wrkMast.getStaNo()); // 源站
                        wrkMast.setStaNo(staNo); // 目标站
                        wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 目标库位 = 出库时的源库位
                        wrkMast.setSourceLocNo(""); // 源库位清空
                        wrkMast.setModiTime(new Date());
                        wrkMast.setModiTime(now);
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            throw new CoolException("更新工作档数据状态失败");
                        }
                        // 更新明细档io_time (历史档关联使用)
                        wrkDetlService.updateIoTime(wrkMast.getWrkNo(), now);
                        // 修改库位状态 Q.拣料/盘点/并板再入库
                        LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
                        locMast.setLocSts("Q");
@@ -524,6 +529,11 @@
                log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
                continue;
            }
            if(crnThread.isBackHpFlag()){
                continue;
            }
            // 只有当堆垛机空闲 并且 无任务时才继续执行
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
                // 如果最近一次是入库模式
@@ -549,45 +559,51 @@
            }
            // 库位移转
            this.locToLoc(crn, crnProtocol);
            this.crnRebackHp(crnProtocol, crnThread);
        }
    }
    /**
     * 回原点,堆垛机没有执行中任务,设备存在入库任务时叫回原点
     */
    public void crnRebackHp(){
        for (CrnSlave crn : slaveProperties.getCrn()) {
            // 获取堆垛机信息
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
            if (crnProtocol == null) {
                continue;
            }
            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
            if (basCrnp == null) {
                log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
                continue;
            }
    public synchronized void crnRebackHp(CrnProtocol crnProtocol, CrnThread crnThread){
//        for (CrnSlave crn : slaveProperties.getCrn()) {
//            // 获取堆垛机信息
//            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
//            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
//            if (crnProtocol == null) {
//                continue;
//            }
//            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
//            if (basCrnp == null) {
//                log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
//                continue;
//            }
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
                // 已经存在吊车执行任务时,则过滤
                if (wrkMastMapper.selectWorking(crn.getId()) != null) {
                    continue;
                if(crnProtocol.getBay() ==1 && crnProtocol.getLevel()==1){
                    return;
                }
                //堆垛机有执行中任务,过滤
                if (wrkMastMapper.selectCrnWorking(crn.getId()) != null) {
                    continue;
                // 已经存在吊车执行任务时,则过滤3,12
                if (wrkMastMapper.selectWorking(crnProtocol.getCrnNo()) != null) {
                    return;
                }
                //输送线没有入库任务,过滤
                if (wrkMastMapper.selectDevWorking(crn.getId()) == null) {
                    continue;
                //堆垛机有执行中任务,过滤3,4,11,12
                if (wrkMastMapper.selectCrnWorking(crnProtocol.getCrnNo()) != null) {
                    return;
                }
                //输送线没有入库任务,过滤2
                if (wrkMastMapper.selectDevWorking(crnProtocol.getCrnNo()) == null) {
                    return;
                }
                log.info("堆垛机召回原点==>>" + crnProtocol.getCrnNo() + "号堆垛机有入库任务,召回原点");
                // 命令下发区 --------------------------------------------------------------------------
                CrnCommand crnCommand = new CrnCommand();
                crnCommand.setCrnNo(crn.getId()); // 堆垛机编号
                crnCommand.setTaskNo((short) 1); // 工作号
                crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号
                crnCommand.setTaskNo((short) 9999); // 工作号
                crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                crnCommand.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式:  回原点
                crnCommand.setSourcePosX((short) 0);     // 源库位排
@@ -596,11 +612,12 @@
                crnCommand.setDestinationPosX((short) 0);     // 目标库位排
                crnCommand.setDestinationPosY((short) 0);     // 目标库位列
                crnCommand.setDestinationPosZ((short) 0);     // 目标库位层
                if (!MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(2, crnCommand))) {
                    log.error("堆垛机回原点命令下发失败,堆垛机号={},任务数据={}", crn.getId(), JSON.toJSON(crnCommand));
                if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) {
                    log.error("堆垛机回原点命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
                }
                crnThread.setBackHpFlag(true);
            }
        }
//        }
    }
    /**
@@ -672,8 +689,9 @@
                        if (wrkMastMapper.updateById(waitWrkMast) == 0) {
                            log.error("调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
                        }
                        continue;
                    }
                    continue;
                } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
                    // 此标记避免多次执行移库任务
                    if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())) {
@@ -734,120 +752,253 @@
    /**
     * 出库  ===>>  库位到堆垛机站
     * 2022-06-09 TQS修改,查询工作档LIST,遍历下发,防止第一个任务堵塞出库
     */
    public void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol){
        for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) {
            // 获取工作状态为11(生成出库ID)的出库工作档
            WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId(), crnStn.getStaNo());
            if (wrkMast == null) {
                continue;
            }
            // 工作档状态判断
            if (wrkMast.getIoType() < 100 || wrkMast.getSourceStaNo() == null){
                log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
                continue;
            }
            // 获取源库位信息
            LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
            if (!sourceSta.getLocSts().equals("R") &&!sourceSta.getLocSts().equals("P")) {
                log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), sourceSta.getLocSts());
                continue;
            }
            // 获取堆垛机出库站信息
            SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
            if (staProtocol == null) {
                continue;
            } else {
                staProtocol = staProtocol.clone();
            }
//            WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId(), crnStn.getStaNo());
            List<WrkMast> wrkMasts = wrkMastMapper.selectPakOutStep11(slave.getId(), crnStn.getStaNo());
            for (WrkMast wrkMast : wrkMasts){
                if (wrkMast == null) {
                    continue;
                }
                // 工作档状态判断
                if (wrkMast.getIoType() < 100 || wrkMast.getSourceStaNo() == null){
                    log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
                    continue;
                }
                // 获取源库位信息
                LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
                if (!sourceSta.getLocSts().equals("R") &&!sourceSta.getLocSts().equals("P")) {
                    log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), sourceSta.getLocSts());
                    continue;
                }
                // 获取堆垛机出库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
                StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
                if (staProtocol == null) {
                    break;
//                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
//            // 入出库模式判断
//            if (devpThread.ioMode != IoModeType.PAKOUT_MODE) { continue; }
            // 查询站点详细信息
            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
            if (staDetl == null) {
                log.error("出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                continue;
            }
            // 判断堆垛机出库站状态
            if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() !=null && staDetl.getCanouting().equals("Y")
                    && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
                // 命令下发区 --------------------------------------------------------------------------
                // 堆垛机控制过滤
                if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                    continue;
                // 查询站点详细信息
                BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
                if (staDetl == null) {
                    log.error("出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                    break;
//                    continue;
                }
                // 判断堆垛机出库站状态
                if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() !=null && staDetl.getCanouting().equals("Y")
                        && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
                    // 命令下发区 --------------------------------------------------------------------------
                // 双深库位且浅库位有货,则需先对浅库位进行库位移转
                if (Utils.isDeepLoc(slaveProperties, wrkMast.getSourceLocNo())) {
                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getSourceLocNo());
                    LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                    // O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!
                    if (shallowLoc.getLocSts().equals("P") || shallowLoc.getLocSts().equals("R")) {
                        WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                        if (null == waitWrkMast) {
                            log.error("{}库位异常,未检索到相应工作档!", shallowLocNo);
                        } else {
                            if(waitWrkMast.getWrkSts() == 11) {
                                waitWrkMast.setIoPri(15D);
                                waitWrkMast.setModiTime(new Date());
                                if (wrkMastMapper.updateById(waitWrkMast) == 0) {
                                    log.error("调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
                                }
                                continue;
                    // 堆垛机控制过滤
                    if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
//                        continue;
                        break;
                    }
                    // 双深库位且浅库位有货,则需先对浅库位进行库位移转
                    if (Utils.isDeepLoc(slaveProperties, wrkMast.getSourceLocNo())) {
                        String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getSourceLocNo());
                        LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                        // O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!
                        if (shallowLoc.getLocSts().equals("P") || shallowLoc.getLocSts().equals("R")) {
                            WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                            if (null == waitWrkMast) {
                                log.error("{}库位异常,未检索到相应工作档!", shallowLocNo);
                            } else {
                                if(waitWrkMast.getWrkSts() == 11) {
                                    waitWrkMast.setIoPri(15D);
                                    waitWrkMast.setModiTime(new Date());
                                    if (wrkMastMapper.updateById(waitWrkMast) == 0) {
                                        log.error("调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
                                    }
                                    continue;
                                } else {
                                }
                            }
                        } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
                            WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                            // 此标记避免多次执行移库任务
                            if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())
                                || Cools.isEmpty(waitWrkMast)) {
                                wrkMast.setUpdMk("Y");
                                wrkMastMapper.updateById(wrkMast);
                                // 生成工作档、改变浅库位的源库/目标库 库位状态、下发堆垛机命令(立马执行)
                                moveLocForDeepLoc(slave, shallowLoc);
                            }
                            log.error("{}任务出库失败,浅库位堵塞!", wrkMast.getWrkNo());
                            continue;
                        } else if (shallowLoc.getLocSts().equals("Q") || shallowLoc.getLocSts().equals("S")){
                            WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                            if (null != waitWrkMast && waitWrkMast.getWrkSts()==4) {
                                continue;
                            }
                        }
                    } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
                        // 此标记避免多次执行移库任务
                        if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())) {
                            wrkMast.setUpdMk("Y");
                            wrkMastMapper.updateById(wrkMast);
                            // 生成工作档、改变浅库位的源库/目标库 库位状态、下发堆垛机命令(立马执行)
                            moveLocForDeepLoc(slave, shallowLoc);
                        }
                        log.error("{}任务出库失败,浅库位堵塞!", wrkMast.getWrkNo());
                        continue;
                    }
                }
                // 已经存在吊车执行任务时,则过滤
                if (wrkMastMapper.selectWorking(slave.getId()) != null) {
                    return;
                }
                    // 已经存在吊车执行任务时,则过滤
                    if (wrkMastMapper.selectWorking(slave.getId()) != null) {
                        break;
//                        return;
                    }
                // 1.堆垛机开始移动
                CrnCommand crnCommand = new CrnCommand();
                crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
                crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
                crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
                crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 源库位排
                crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 源库位列
                crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue());     // 源库位层
                crnCommand.setDestinationPosX(crnStn.getRow().shortValue());     // 目标库位排
                crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列
                crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层
                if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
                } else {
                    // 修改工作档状态 11.生成出库ID => 12.吊车出库中
                    Date now = new Date();
                    wrkMast.setWrkSts(12L);
                    wrkMast.setCrnStrTime(now);
                    wrkMast.setModiTime(now);
                    if (wrkMastMapper.updateById(wrkMast) == 0) {
                        log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
                    // 1.堆垛机开始移动
                    CrnCommand crnCommand = new CrnCommand();
                    crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
                    crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
                    crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                    crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
                    crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 源库位排
                    crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 源库位列
                    crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue());     // 源库位层
                    crnCommand.setDestinationPosX(crnStn.getRow().shortValue());     // 目标库位排
                    crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列
                    crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层
                    if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
                        log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
                    } else {
                        // 修改工作档状态 11.生成出库ID => 12.吊车出库中
                        Date now = new Date();
                        wrkMast.setWrkSts(12L);
                        wrkMast.setCrnStrTime(now);
                        wrkMast.setModiTime(now);
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
                        }
                        break;
                    }
                }
            }
        }
    }
//    /**
//     * 出库  ===>>  库位到堆垛机站
//     */
//    public void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol){
//        for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) {
//            // 获取工作状态为11(生成出库ID)的出库工作档
//            WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId(), crnStn.getStaNo());
//            if (wrkMast == null) {
//                continue;
//            }
//            // 工作档状态判断
//            if (wrkMast.getIoType() < 100 || wrkMast.getSourceStaNo() == null){
//                log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
//                continue;
//            }
//            // 获取源库位信息
//            LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
//            if (!sourceSta.getLocSts().equals("R") &&!sourceSta.getLocSts().equals("P")) {
//                log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), sourceSta.getLocSts());
//                continue;
//            }
//            // 获取堆垛机出库站信息
//            SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
//            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
//            if (staProtocol == null) {
//                continue;
//            } else {
//                staProtocol = staProtocol.clone();
//            }
//
////            // 入出库模式判断
////            if (devpThread.ioMode != IoModeType.PAKOUT_MODE) { continue; }
//
//
//            // 查询站点详细信息
//            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
//            if (staDetl == null) {
//                log.error("出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
//                continue;
//            }
//            // 判断堆垛机出库站状态
//            if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() !=null && staDetl.getCanouting().equals("Y")
//                    && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
//                // 命令下发区 --------------------------------------------------------------------------
//
//                // 堆垛机控制过滤
//                if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
//                    continue;
//                }
//
//                // 双深库位且浅库位有货,则需先对浅库位进行库位移转
//                if (Utils.isDeepLoc(slaveProperties, wrkMast.getSourceLocNo())) {
//                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getSourceLocNo());
//                    LocMast shallowLoc = locMastService.selectById(shallowLocNo);
//                    // O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!
//                    if (shallowLoc.getLocSts().equals("P") || shallowLoc.getLocSts().equals("R")) {
//                        WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
//                        if (null == waitWrkMast) {
//                            log.error("{}库位异常,未检索到相应工作档!", shallowLocNo);
//                        } else {
//                            if(waitWrkMast.getWrkSts() == 11) {
//                                waitWrkMast.setIoPri(15D);
//                                waitWrkMast.setModiTime(new Date());
//                                if (wrkMastMapper.updateById(waitWrkMast) == 0) {
//                                    log.error("调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
//                                }
//                                continue;
//                            } else {
//
//                            }
//                        }
//                    } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
//                        // 此标记避免多次执行移库任务
//                        if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())) {
//                            wrkMast.setUpdMk("Y");
//                            wrkMastMapper.updateById(wrkMast);
//                            // 生成工作档、改变浅库位的源库/目标库 库位状态、下发堆垛机命令(立马执行)
//                            moveLocForDeepLoc(slave, shallowLoc);
//                        }
//                        log.error("{}任务出库失败,浅库位堵塞!", wrkMast.getWrkNo());
//                        continue;
//                    }
//                }
//
//                // 已经存在吊车执行任务时,则过滤
//                if (wrkMastMapper.selectWorking(slave.getId()) != null) {
//                    return;
//                }
//
//                // 1.堆垛机开始移动
//                CrnCommand crnCommand = new CrnCommand();
//                crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
//                crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
//                crnCommand.setAckFinish((short) 0);  // 任务完成确认位
//                crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
//                crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 源库位排
//                crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 源库位列
//                crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue());     // 源库位层
//                crnCommand.setDestinationPosX(crnStn.getRow().shortValue());     // 目标库位排
//                crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列
//                crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层
//                if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
//                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
//                } else {
//                    // 修改工作档状态 11.生成出库ID => 12.吊车出库中
//                    Date now = new Date();
//                    wrkMast.setWrkSts(12L);
//                    wrkMast.setCrnStrTime(now);
//                    wrkMast.setModiTime(now);
//                    if (wrkMastMapper.updateById(wrkMast) == 0) {
//                        log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
//                    }
//                }
//            }
//        }
//    }
    /**
     * 库位移转
@@ -929,25 +1080,30 @@
            if (crnProtocol == null) { continue; }
            //  状态:等待确认 并且  任务完成位 = 1
            if (crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) {
                // 获取入库待确认工作档
                WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue());
                if (wrkMast == null) {
                    log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo());
                    continue;
                }
                // 入库 + 库位转移  ==> 4.入库完成
                if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && wrkMast.getIoType() == 11)){
                    wrkMast.setWrkSts(4L);
                } else  {
                    continue;
                }
                Date now = new Date();
                wrkMast.setCrnEndTime(now);
                wrkMast.setModiTime(now);
                // 修改成功后复位堆垛机
                if (wrkMastMapper.updateById(wrkMast) > 0) {
                if(crnProtocol.getTaskNo()==9999){
                    // 堆垛机复位
                    crnThread.setResetFlag(true);
                }else {
                    // 获取入库待确认工作档
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue());
                    if (wrkMast == null) {
                        log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo());
                        continue;
                    }
                    // 入库 + 库位转移  ==> 4.入库完成
                    if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && wrkMast.getIoType() == 11)) {
                        wrkMast.setWrkSts(4L);
                    } else {
                        continue;
                    }
                    Date now = new Date();
                    wrkMast.setCrnEndTime(now);
                    wrkMast.setModiTime(now);
                    // 修改成功后复位堆垛机
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        // 堆垛机复位
                        crnThread.setResetFlag(true);
                    }
                }
            }
@@ -1439,13 +1595,16 @@
            if (Utils.isDeepLoc(slaveProperties, row)) {
                loc = locMastService.queryFreeLocMast(row, shallowLoc.getLocType1());
                if (Utils.isDeepLoc(slaveProperties, loc.getLocNo())){
                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, loc.getLocNo());
                    LocMast shallowLoc1 = locMastService.selectById(shallowLocNo);
                    if(!shallowLoc1.getLocSts().equals("O")){
                        loc = null;
                if (loc !=null) {
                    if (Utils.isDeepLoc(slaveProperties, loc.getLocNo())){
                        String shallowLocNo = Utils.getShallowLoc(slaveProperties, loc.getLocNo());
                        LocMast shallowLoc1 = locMastService.selectById(shallowLocNo);
                        if(!shallowLoc1.getLocSts().equals("O")){
                            loc = null;
                        }
                    }
                }
                if (null != loc) { break; }
            }
@@ -1695,5 +1854,18 @@
    }
    public void outOfDevp() {
        List<WrkMast> wrkMasts = wrkMastMapper.selectPick();
        for (WrkMast wrkMast : wrkMasts) {
            if (basDevpService.selectCount(new EntityWrapper<BasDevp>().eq("wrk_no", wrkMast.getWrkNo())) == 0) {
                wrkMast.setCtnNo("Y");
                if (wrkMastMapper.updateById(wrkMast) == 0) {
                    log.error("修改{}工作档失败,ctn_no", wrkMast.getWrkNo());
                }
            }
        }
    }
}