#
Junjie
2025-08-18 e22952465f1ab08a58f84c2f01e7d4e89b6bd61e
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -6,6 +6,7 @@
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.BasCrnErrorMapper;
@@ -61,7 +62,6 @@
 */
@Slf4j
@Service("mainService")
@Transactional
public class MainServiceImpl {
    public static final long COMMAND_TIMEOUT = 5 * 1000;
@@ -130,7 +130,7 @@
                LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                // 判断是否满足入库条件
                if (!staProtocol.isLoading()){
                if (!staProtocol.isLoading()) {
                    continue;
                }
@@ -138,18 +138,18 @@
                        && staProtocol.isInEnable()
                        && !staProtocol.isEmptyMk()
                        && staProtocol.getWorkNo() == 9999
                        && staProtocol.isPakMk()) {
                    News.warnNoLog(""+mark+" - 0"+" - 开始执行");
                        && staProtocol.isPakMk() && (staProtocol.getEmptyInType() != 1 && staProtocol.getEmptyInType() != 2)) {
                    News.warnNoLog("" + mark + " - 0" + " - 开始执行");
                    String barcode = barcodeThread.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        News.info(""+mark+" - 1"+" - {}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
                        if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
                    if (!Cools.isEmpty(barcode)) {
                        News.info("" + mark + " - 1" + " - {}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
//                            staProtocol.setWorkNo((short) 9992);
//                            staProtocol.setStaNo(inSta.getBackSta().shortValue());
//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
//                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            News.info(""+mark+" - 2"+" - 扫码失败1 ===>> {}号条码扫描器检测条码信息:{},站点:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
                            News.info("" + mark + " - 2" + " - 扫码失败1 ===>> {}号条码扫描器检测条码信息:{},站点:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
                            // led 异常显示
                            if (ledThread != null) {
                                String errorMsg = "扫码失败,请重试";
@@ -163,7 +163,7 @@
//                        devpThread.setPakMk(staProtocol.getSiteId(), false);
//                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        News.info(""+mark+" - 3"+" - 扫码失败2 ===>> {}号条码扫描器检测条码信息:{},站点:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
                        News.info("" + mark + " - 3" + " - 扫码失败2 ===>> {}号条码扫描器检测条码信息:{},站点:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "扫码失败,请重试";
@@ -176,13 +176,13 @@
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
                    //过滤判断,防止拣料再入库货物,经过入库站再入库时,被退回到退库站
                    WrkMast wrkMast1 = wrkMastMapper.selectPakInStepBarcode(barcode);
                    if (wrkMast1 !=null){
                        if (wrkMast1.getIoType()==103 || wrkMast1.getIoType()==107 || wrkMast1.getIoType()==104){
                    if (wrkMast1 != null) {
                        if (wrkMast1.getIoType() == 103 || wrkMast1.getIoType() == 107 || wrkMast1.getIoType() == 104) {
                            continue;
                        }
                    }
                    if (wrkMast != null) {
                        News.error(""+mark+" - 4"+" - 工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast.getWrkNo());
                        News.error("" + mark + " - 4" + " - 工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast.getWrkNo());
//                        staProtocol.setWorkNo((short)9992);
//                        staProtocol.setStaNo(inSta.getBackSta().shortValue());
//                        devpThread.setPakMk(staProtocol.getSiteId(), false);
@@ -206,7 +206,7 @@
                                .in("sta_no", 1003, 1007)
                        );
                        if (!wrkMasts.isEmpty()) {
                            News.error(""+mark+" - 4"+" - 1003站入库,检测存在出库任务,等待出库任务执行完成,托盘码={}", barcode);
                            News.error("" + mark + " - 4" + " - 1003站入库,检测存在出库任务,等待出库任务执行完成,托盘码={}", barcode);
                            continue;
                        }
                    }
@@ -233,6 +233,12 @@
                                    .eq("loc_no", dto.getLocNo()));
                            short staNo = dto.getStaNo().shortValue();
                            int sourceStaNo = dto.getSourceStaNo();
                            if (sourceStaNo == 1007) {
                                staNo = 2002;
                            }
                            if (inSta.getStaNo() == 1002) {
                                staNo = 2002;
                            }
@@ -263,7 +269,7 @@
////                                ledThread.errorReset();
//                            }
                        } else {
                            News.error(""+mark+" - 5"+" - 请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            News.error("" + mark + " - 5" + " - 请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
//                            staProtocol.setWorkNo((short)9992);
//                            staProtocol.setStaNo(inSta.getBackSta().shortValue());
//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
@@ -284,15 +290,15 @@
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    }
                }else {
                    News.errorNoLog(""+mark+" - 6"+" - 站点信息不符合入库条件!!!"+" 自动信号:"+staProtocol.isAutoing()+"、可入信号:" + staProtocol.isInEnable()
                            +"、空板信号:"+ staProtocol.isEmptyMk()+"、工作号:" + staProtocol.getWorkNo()
                            +"、锁定标记"+ staProtocol.isPakMk());
                } else {
                    News.errorNoLog("" + mark + " - 6" + " - 站点信息不符合入库条件!!!" + " 自动信号:" + staProtocol.isAutoing() + "、可入信号:" + staProtocol.isInEnable()
                            + "、空板信号:" + staProtocol.isEmptyMk() + "、工作号:" + staProtocol.getWorkNo()
                            + "、锁定标记" + staProtocol.isPakMk());
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 组托  ===》执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 组托  ===》执行完成");
    }
@@ -315,7 +321,7 @@
                }
                // 判断是否满足入库条件
                if (!staProtocol.isLoading()){
                if (!staProtocol.isLoading()) {
                    continue;
                }
@@ -324,7 +330,7 @@
                        && !staProtocol.isEmptyMk()
                        && staProtocol.getWorkNo() > 0
                        && staProtocol.isPakMk()) {
                    News.warnNoLog(""+mark+" - 0"+" - 开始执行");
                    News.warnNoLog("" + mark + " - 0" + " - 开始执行");
                    // 判断重复工作档
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
                    if (wrkMast == null) {
@@ -343,20 +349,20 @@
                        wrkMast.setWrkSts(2L); // 工作状态:2.设备上走
                        wrkMast.setModiTime(new Date());
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            News.error(""+mark+" - 1"+" - 更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo());
                            News.error("" + mark + " - 1" + " - 更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo());
                        }
                    } else {
                        News.error(""+mark+" - 2"+" - 发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
                        News.error("" + mark + " - 2" + " - 发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
                    }
                }else {
                    News.errorNoLog(""+mark+" - 6"+" - 站点信息不符合入库条件!!!"+" 自动信号:"+staProtocol.isLoading()+"、可入信号:" + staProtocol.isInEnable()
                            +"、空板信号:"+ staProtocol.isEmptyMk()+"、工作号:" + staProtocol.getWorkNo()
                            +"、锁定标记"+ staProtocol.isPakMk());
                } else {
                    News.errorNoLog("" + mark + " - 6" + " - 站点信息不符合入库条件!!!" + " 自动信号:" + staProtocol.isLoading() + "、可入信号:" + staProtocol.isInEnable()
                            + "、空板信号:" + staProtocol.isEmptyMk() + "、工作号:" + staProtocol.getWorkNo()
                            + "、锁定标记" + staProtocol.isPakMk());
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - wms入库  ===》执行完成");
        News.infoNoLog("" + mark + " - 0" + " - wms入库  ===》执行完成");
    }
@@ -381,7 +387,7 @@
                        && staProtocol.isInEnable()
                        && staProtocol.getWorkNo() > 0
                        && staProtocol.isPakMk()) {
                    News.warnNoLog(""+mark+" - 0"+" - 开始执行");
                    News.warnNoLog("" + mark + " - 0" + " - 开始执行");
//                    // 获取条码扫描仪信息
//                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
@@ -434,7 +440,7 @@
                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "此为拣料、并板、盘点再入库.请放在"+pickSta.getBackSta().shortValue()+"站点";
                            String errorMsg = "此为拣料、并板、盘点再入库.请放在" + pickSta.getBackSta().shortValue() + "站点";
                            MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(5, errorMsg));
                        }
                        continue;
@@ -462,6 +468,7 @@
                        wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 目标库位 = 出库时的源库位
                        wrkMast.setSourceLocNo(""); // 源库位清空
                        wrkMast.setModiTime(now);
                        wrkMast.setUpdMk("");//允许再次移库
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            throw new CoolException("更新工作档数据状态失败");
                        }
@@ -488,94 +495,234 @@
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    if (!result) {
                        News.error(""+mark+" - 3"+" - 发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
                        News.error("" + mark + " - 3" + " - 发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
                    }
                }else {
                    News.errorNoLog(""+mark+" - 6"+" - 站点信息不符合入库条件!!!"+" 自动信号:"+staProtocol.isLoading()+"、可入信号:" + staProtocol.isInEnable()
                            +"、空板信号:"+ staProtocol.isEmptyMk());
                } else {
                    News.errorNoLog("" + mark + " - 6" + " - 站点信息不符合入库条件!!!" + " 自动信号:" + staProtocol.isLoading() + "、可入信号:" + staProtocol.isInEnable()
                            + "、空板信号:" + staProtocol.isEmptyMk());
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 拣料、并板、盘点再入库  ===》执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 拣料、并板、盘点再入库  ===》执行完成");
    }
    /**
     * 拣料、并板、盘点再入库-条码
     */
    public synchronized void stnToCrnStnPickBarcode(Integer mark) {
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历拣料入库口
            for (DevpSlave.Sta insta : devp.getInSta()) {
                // 获取拣料入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(insta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                if (staProtocol.isAutoing()
                        && staProtocol.isLoading()
                        && staProtocol.isInEnable()
                        && staProtocol.getWorkNo() > 0
                        && staProtocol.isPakMk()) {
                    News.warnNoLog("" + mark + " - 0" + " - 开始执行");
                    // 获取条码扫描仪信息
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, insta.getBarcode());
                    if (barcodeThread == null) {
                        continue;
                    }
                    String barcode = barcodeThread.getBarcode();
                    if (!Cools.isEmpty(barcode)) {
                        News.info("" + mark + " - 1" + " - {}号条码扫描器检测条码信息:{}", insta.getBarcode(), barcode);
                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
                            continue;
                        }
                    } else {
                        continue;
                    }
                    WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
                    if (wrkMast == null) {
                        // 无拣料数据
                        continue;
                    }
                    if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107)
                            || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
                        continue;
                    }
                    // 拣、盘、并 作业站转换
//                    int stnNo = 0;
//                    if (wrkMast.getStaNo() == 109) {
//                        stnNo = 127;
//                    } else if (wrkMast.getStaNo() == 113) {
//                        stnNo = 128;
//                    } else {
//                        log.error("{}号任务数据异常!", wrkMast.getWrkNo());
//                    }
                    // 获取目标站
                    Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                            .eq("type_no", wrkMast.getIoType() - 50)
                            .eq("stn_no", insta.getStaNo()) // 作业站点 = 拣料出库的目标站
                            .eq("crn_no", wrkMast.getCrnNo()); // 堆垛机号
                    StaDesc staDesc = staDescService.selectOne(wrapper);
                    if (Cools.isEmpty(staDesc)) {
//                        News.error(""+mark+" - 2"+" - 入库路径不存在!type_no={},stn_no={},crn_no={}", wrkMast.getIoType(), pickSta.getStaNo(), wrkMast.getCrnNo());
//                        staProtocol.setWorkNo((short) 9989);
//                        staProtocol.setStaNo((short) (pickSta.getStaNo().shortValue()-(short)1));
//                        devpThread.setPakMk(staProtocol.getSiteId(), false);
//                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        //LED
                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, insta.getLed());
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "此为拣料、并板、盘点再入库.请放在" + insta.getBackSta().shortValue() + "站点";
                            MessageQueue.offer(SlaveType.Led, insta.getLed(), new Task(5, errorMsg));
                        }
                        continue;
                    }
                    try {
                        // 保存工作明细档历史档
                        if (wrkMastMapper.saveWrkDetlLog(wrkMast.getWrkNo()) == 0) {
                            throw new CoolException("保存工作明细档历史档失败");
                        }
                        // 保存工作主档历史档
                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
                            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(now);
                        wrkMast.setUpdMk("");//允许再次移库
                        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");
                        locMast.setModiTime(new Date());
                        if (!locMastService.updateById(locMast)) {
                            throw new CoolException("修改库位状态失败");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        continue;
                    }
                    LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
                    // 更新站点信息 且 下发plc命令
                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                    staProtocol.setPalletSize(locMast.getLocType2());
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    if (!result) {
                        News.error("" + mark + " - 3" + " - 发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
                    }
                } else {
                    News.errorNoLog("" + mark + " - 6" + " - 站点信息不符合入库条件!!!" + " 自动信号:" + staProtocol.isLoading() + "、可入信号:" + staProtocol.isInEnable()
                            + "、空板信号:" + staProtocol.isEmptyMk());
                }
            }
        }
        News.infoNoLog("" + mark + " - 0" + " - 拣料、并板、盘点再入库  ===》执行完成");
    }
    /**
     * 堆垛机站出库到出库站
     */
    public synchronized void crnStnToOutStn(Integer mark) {
        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                .eq("wrk_sts", 12)
        );
        for (CrnSlave crnSlave : slaveProperties.getCrn()) {
            // 遍历堆垛机出库站
            for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) {
                // 获取堆垛机出库站信息
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
                StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
        for (WrkMast wrkMast : wrkMasts) {
            // 判断工作档条件
            if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) {
                continue;
            }
            Integer devpId = null;
            Integer sourceStaNo = wrkMast.getSourceStaNo();
            for (CrnSlave crnSlave : slaveProperties.getCrn()) {
                for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) {
                    if (crnStn.getStaNo().equals(sourceStaNo)) {
                        devpId = crnStn.getDevpPlcId();
                        break;
                    }
                }
                if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
                    // 查询工作档
                    WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId());
                    if (wrkMast == null) {
            }
            if (devpId == null) {
                News.error("" + mark + " - 0" + " - 堆垛机站出库到出库站,未找到对应PLC");
                continue;
            }
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devpId);
            StaProtocol staProtocol = devpThread.getStation().get(sourceStaNo);
            if (staProtocol == null) {
                continue;
            } else {
                staProtocol = staProtocol.clone();
            }
            if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
                CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo());
                CrnProtocol crnProtocol = crnThread.getCrnProtocol();
                if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
                        && (crnProtocol.statusType == CrnStatusType.PUTTING || crnProtocol.statusType == CrnStatusType.WAITING)) {
                    //放货中 或 等待确认
                    News.warnNoLog("" + mark + " - 0" + " - 开始执行");
                    // 命令下发区 --------------------------------------------------------------------------
                    LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                            .eq("loc_no", wrkMast.getSourceLocNo()));
                    // 下发站点信息
                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                    staProtocol.setPalletSize(locMast.getLocType2());
                    if (!MessageQueue.offer(SlaveType.Devp, devpId, new Task(2, staProtocol))) {
                        continue;
                    }
                    // 判断工作档条件
                    if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) {
                        continue;
                    // 更新工作档状态为14失败
                    wrkMast.setWrkSts(14L);
                    wrkMast.setCrnEndTime(new Date());
                    if (wrkMastMapper.updateById(wrkMast) != 0) {
                        News.info("" + mark + " - 1" + " - 更新工作档的工作状态为14成功!!! [工作号:{}]", wrkMast.getWrkNo());
                    } else {
                        News.error("" + mark + " - 1" + " - 更新工作档的工作状态为14失败!!! [工作号:{}]", wrkMast.getWrkNo());
                    }
                    // 判断吊车是否实际已完成,且电脑状态在move中,以备电脑进行更新工作档
                    CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo());
                    CrnProtocol crnProtocol = crnThread.getCrnProtocol();
                    if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) {
                        // 移动中
                        continue;
                    }
                    //  判断堆垛机状态等待确认
                    if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
                            && crnProtocol.statusType == CrnStatusType.WAITING
                            && crnProtocol.forkPosType == CrnForkPosType.HOME) {
                        News.warnNoLog(""+mark+" - 0"+" - 开始执行");
                        // 命令下发区 --------------------------------------------------------------------------
                        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                                .eq("loc_no", wrkMast.getSourceLocNo()));
                        // 下发站点信息
                        staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                        staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                        staProtocol.setPalletSize(locMast.getLocType2());
                        if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
                            continue;
                        }
                        // 更新工作档状态为14失败
                        wrkMast.setWrkSts(14L);
                        wrkMast.setCrnEndTime(new Date());
                        if (wrkMastMapper.updateById(wrkMast) != 0) {
                            // 复位堆垛机
                            crnThread.setResetFlag(true);
                        } else {
                            News.error(""+mark+" - 1"+" - 更新工作档的工作状态为14失败!!! [工作号:{}]", wrkMast.getWrkNo());
                        }
                    }else {
                        News.errorNoLog(""+mark+" - 6"+" - 堆垛机信息不符合入库条件!!!"
                                +" 堆垛机状态:"+crnProtocol.modeType+"==自动AUTO:" + CrnModeType.AUTO
                                +"、堆垛机任务号:"+crnProtocol.getTaskNo()+"==工作档任务号:" + wrkMast.getWrkNo().shortValue()
                                +"、状态枚举:"+crnProtocol.statusType+"==WAITING:90 //任务完成等待WCS确认):" + CrnStatusType.WAITING
                                +"、货叉位置:"+crnProtocol.forkPosType+"==HOME:0  // 货叉原位:" + CrnForkPosType.HOME);
                    }
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 堆垛机站出库到出库站  ===》执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 堆垛机站出库到出库站  ===》执行完成");
    }
    /**
@@ -592,7 +739,7 @@
            }
            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
            if (basCrnp == null) {
                News.error(""+mark+" - 1"+" - {}号堆垛机尚未在数据库进行维护!", crn.getId());
                News.error("" + mark + " - 1" + " - {}号堆垛机尚未在数据库进行维护!", crn.getId());
                continue;
            }
@@ -601,41 +748,47 @@
//                continue;
//            }
            //堆垛机回原点任务中
            Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK + crn.getId());
            if (object != null) {
                continue;
            }
            // 只有当堆垛机空闲 并且 无任务时才继续执行
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO
                    && crnProtocol.getLoaded() == 0 && crnProtocol.getForkPos() == 0) {
                News.warnNoLog(""+mark+" - 0"+" - 开始执行堆垛机入出库作业下发");
                News.warnNoLog("" + mark + " - 0" + " - 开始执行堆垛机入出库作业下发");
                // 如果最近一次是入库模式
                if (crnProtocol.getLastIo().equals("I")) {
                    if (basCrnp.getInEnable().equals("Y")) {
                        //mark - 1 - ....
                        this.crnStnToLoc(crn, crnProtocol,mark); //  入库
                        this.crnStnToLoc(crn, crnProtocol, mark); //  入库
                        crnProtocol.setLastIo("O");
                    } else if (basCrnp.getOutEnable().equals("Y")) {
                        //mark - 2 - ....
                        this.locToCrnStn(crn, crnProtocol,mark); //  出库
                        this.locToCrnStn(crn, crnProtocol, mark); //  出库
                        crnProtocol.setLastIo("I");
                    }
                }
                // 如果最近一次是出库模式
                else if (crnProtocol.getLastIo().equals("O")) {
                    if (basCrnp.getOutEnable().equals("Y")) {
                        this.locToCrnStn(crn, crnProtocol,mark); //  出库
                        this.locToCrnStn(crn, crnProtocol, mark); //  出库
                        crnProtocol.setLastIo("I");
                    } else if (basCrnp.getInEnable().equals("Y")) {
                        this.crnStnToLoc(crn, crnProtocol,mark); //  入库
                        this.crnStnToLoc(crn, crnProtocol, mark); //  入库
                        crnProtocol.setLastIo("O");
                    }
                }
            }
            // 库位移转
            //mark - 3 - ....
            this.locToLoc(crn, crnProtocol,mark);
            this.locToLoc111(crn, crnProtocol,mark);
            this.locToLoc(crn, crnProtocol, mark);
            this.locToLoc111(crn, crnProtocol, mark);
//            this.crnRebackHp(crnProtocol, crnThread);
        }
        News.infoNoLog(""+mark+" - 0"+" - 堆垛机入出库作业下发执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 堆垛机入出库作业下发执行完成");
    }
    /**
@@ -643,6 +796,10 @@
     */
    public synchronized void crnMove() {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            if (crn.getId() == 1) {
                continue;
            }
            // 获取堆垛机信息
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
@@ -664,7 +821,7 @@
                    continue;
                }
                Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK);
                Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK + crn.getId());
                if (object != null) {
                    continue;
                }
@@ -696,7 +853,79 @@
                    News.error("堆垛机移动命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
                }
                crnThread.setBackHpFlag(true);
                redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60);
                redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 10);
                try {
                    Thread.sleep(500);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    /**
     * 堆垛机有入库任务时,回入库口待机
     */
    public synchronized void crnMoveByInTask() {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            if (crn.getId() == 1) {
                continue;
            }
            // 获取堆垛机信息
            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 (crnProtocol.getBay() == 1 && crnProtocol.getLevel() == 1) {
                    continue;
                }
                if (System.currentTimeMillis() - crnProtocol.getLastCommandTime() < 1000 * 60) {
                    continue;
                }
                Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK + crn.getId());
                if (object != null) {
                    continue;
                }
                List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                        .eq("crn_no", crn.getId())
                        .eq("wrk_sts", 2)
                );
                if (wrkMasts.isEmpty()) {
                    continue;
                }
                CrnSlave.CrnStn crnStn = crn.getCrnInStn().get(0);
                News.info("堆垛机有入库任务时,回入库口待机==>>" + crnProtocol.getCrnNo() + "号堆垛机");
                // 命令下发区 --------------------------------------------------------------------------
                CrnCommand crnCommand = new CrnCommand();
                crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号
                crnCommand.setTaskNo((short) 9999); // 工作号
                crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                crnCommand.setTaskMode(CrnTaskModeType.CRN_MOVE); // 任务模式:  堆垛机移动
                crnCommand.setSourcePosX(crnStn.getRow().shortValue());     // 源库位排
                crnCommand.setSourcePosY((short) 1);     // 源库位列
                crnCommand.setSourcePosZ((short) 1);     // 源库位层
                crnCommand.setDestinationPosX((short) 0);     // 目标库位排
                crnCommand.setDestinationPosY((short) 0);     // 目标库位列
                crnCommand.setDestinationPosZ((short) 0);     // 目标库位层
                if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) {
                    News.error("堆垛机移动命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
                }
                crnThread.setBackHpFlag(true);
                redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 10);
                try {
                    Thread.sleep(500);
                } catch (Exception e) {
@@ -709,15 +938,15 @@
    /**
     * 入库  ===>>  堆垛机站到库位
     */
    public synchronized void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol,Integer mark) {
        News.warnNoLog(""+mark+" - 1"+" - 0"+" - 堆垛机入出库作业下发:执行入库");
    public synchronized void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol, Integer mark) {
        News.warnNoLog("" + mark + " - 1" + " - 0" + " - 堆垛机入出库作业下发:执行入库");
        for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) {
            boolean flag = false;
            // 获取堆垛机入库站信息
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
            if (staProtocol == null) {
                News.infoNoLog(""+mark+" - 1"+" - 1"+" - 堆垛机入库站信息(staProtocol!=null继续执行):staProtocol="+staProtocol);
                News.infoNoLog("" + mark + " - 1" + " - 1" + " - 堆垛机入库站信息(staProtocol!=null继续执行):staProtocol=" + staProtocol);
                continue;
            } else {
                staProtocol = staProtocol.clone();
@@ -725,7 +954,7 @@
            // 查询站点详细信息
            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
            if (staDetl == null) {
                News.error(""+mark+" - 1"+" - 2"+" - 入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                News.error("" + mark + " - 1" + " - 2" + " - 入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                continue;
            }
            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable()
@@ -733,27 +962,27 @@
                flag = true;
            }
            if (!flag) {
                News.errorNoLog(""+mark+" - 1"+" - 3"+" - 堆垛机入库站信息(以下需要全true):"
                        +"自动信号"+staProtocol.isAutoing()+"有物信号"+staProtocol.isLoading()
                        +"工作号>0"+staProtocol.getWorkNo()+"可入信号"+staProtocol.isInEnable()
                        +"能入信号(wms设置).equals(\"Y\")"+staDetl.getCanining());
                News.errorNoLog("" + mark + " - 1" + " - 3" + " - 堆垛机入库站信息(以下需要全true):"
                        + "自动信号" + staProtocol.isAutoing() + "有物信号" + staProtocol.isLoading()
                        + "工作号>0" + staProtocol.getWorkNo() + "可入信号" + staProtocol.isInEnable()
                        + "能入信号(wms设置).equals(\"Y\")" + staDetl.getCanining());
                continue;
            }
            // 获取工作状态为2(设备上走)的入库工作档
            WrkMast wrkMast = wrkMastMapper.selectPakInStep2(slave.getId(), staProtocol.getWorkNo().intValue(), crnStn.getStaNo());
            if (null == wrkMast) {
                News.infoNoLog(""+mark+" - 1"+" - 4"+" - 查询无待入库数据--wrk_sts=2, 工作号={}", staProtocol.getWorkNo());
                News.infoNoLog("" + mark + " - 1" + " - 4" + " - 查询无待入库数据--wrk_sts=2, 工作号={}", staProtocol.getWorkNo());
//                log.error("查询无待入库数据--wrk_sts=2, 工作号={}", staProtocol.getWorkNo());
                continue;
            }
            // 获取库位信息
            LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
            if (locMast == null) {
                News.error(""+mark+" - 1"+" - 5"+" - 查询库存无数据--库位号{}", wrkMast.getLocNo());
                News.error("" + mark + " - 1" + " - 5" + " - 查询库存无数据--库位号{}", wrkMast.getLocNo());
                continue;
            }
            if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
                News.error(""+mark+" - 1"+" - 6"+" - 入库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), locMast.getLocSts());
                News.error("" + mark + " - 1" + " - 6" + " - 入库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), locMast.getLocSts());
                continue;
            }
@@ -773,37 +1002,43 @@
                if (Utils.getLaneByLocNo(wrkMast.getLocNo()) != crnProtocol.getCrnLane()) {
                    //判断堆垛机所在巷道是否存在其他任务,如存在则优先执行
                    List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
                    if (!currentWrkMasts.isEmpty()) {
                        continue;//当前堆垛机所在巷道存在任务
                    }
//                    if (!currentWrkMasts.isEmpty()) {
//                        continue;//当前堆垛机所在巷道存在任务
//                    }
                }
            }
            // 双深库位且浅库位有货,则需先对浅库位进行库位移转
            if (Utils.isDeepLoc(slaveProperties, wrkMast.getLocNo())) {
                News.warnNoLog(""+mark+" - 1"+" - 8"+" - 双深库位且浅库位有货,则需先对浅库位进行库位移转 : 开始执行 任务号={}",wrkMast.getWrkNo());
                News.warnNoLog("" + mark + " - 1" + " - 8" + " - 双深库位且浅库位有货,则需先对浅库位进行库位移转 : 开始执行 任务号={}", wrkMast.getWrkNo());
                String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getLocNo());
                LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                // O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!
                if (shallowLoc.getLocSts().equals("P") || shallowLoc.getLocSts().equals("R")) {
                    News.warnNoLog(""+mark+" - 1"+" - 9"+" - // O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!库位状态={}",shallowLoc.getLocSts());
                    News.warn("" + mark + " - 1" + " - 9" + " - // O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!库位={},库位状态={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
                    WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                    if (null == waitWrkMast) {
                        News.error(""+mark+" - 1"+" - 10"+" - {}库位异常,未检索到相应工作档!", shallowLocNo);
                        News.error("" + mark + " - 1" + " - 10" + " - {}库位异常,未检索到相应工作档!", shallowLocNo);
                    } else {
                        waitWrkMast.setIoPri(15D);
                        waitWrkMast.setModiTime(new Date());
                        if (wrkMastMapper.updateById(waitWrkMast) == 0) {
                            News.error(""+mark+" - 1"+" - 11"+" - 调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
                        if (waitWrkMast.getWrkSts() != 14 && waitWrkMast.getIoType() > 100) {
                            waitWrkMast.setIoPri(15D);
                            waitWrkMast.setModiTime(new Date());
                            if (wrkMastMapper.updateById(waitWrkMast) == 0) {
                                News.error("" + mark + " - 1" + " - 11" + " - 调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
                            }
                            continue;
                        }
                        continue;
                        if (waitWrkMast.getWrkSts() < 5 && waitWrkMast.getIoType() < 100) {
                            continue;//有任务禁止搬运,有可能浅库位状态还未变更完成
                        }
                    }
                } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
                    News.warnNoLog(""+mark+" - 1"+" - 12"+" - // F、D  库位状态={}",shallowLoc.getLocSts());
                    News.warn("" + mark + " - 1" + " - 12" + " - // F、D  库位={},库位状态={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
                    // 此标记避免多次执行移库任务
                    if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())) {
                        if (moveLocForDeepLoc(slave, shallowLoc,mark)){
                        if (moveLocForDeepLoc(slave, shallowLoc, mark)) {
                            wrkMast.setUpdMk("Y");
                            wrkMast.setIoPri(14D);
                            wrkMastMapper.updateById(wrkMast);
@@ -818,17 +1053,17 @@
                    }
                    continue;
                } else if (shallowLoc.getLocSts().equals("Q")) {
                    News.warnNoLog(""+mark+" - 1"+" - 13"+" - // Q  库位状态={}",shallowLoc.getLocSts());
                    News.warn("" + mark + " - 1" + " - 13" + " - // Q  库位={},库位状态={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
                    WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                    if (null != waitWrkMast && waitWrkMast.getWrkSts() == 4) {
                        News.infoNoLog(""+mark+" - 1"+" - 14"+" - // F、D  工作状态(判断条件为==4)={}",waitWrkMast.getWrkSts());
                        News.infoNoLog("" + mark + " - 1" + " - 14" + " - // F、D  工作状态(判断条件为==4)={}", waitWrkMast.getWrkSts());
                        continue;
                    }
                }
            }
            News.warnNoLog(""+mark+" - 1"+" - 15"+" - 命令下发 : 工作号={},源排={},源列={},源层={},目标排={},目标列={},目标层={}",wrkMast.getWrkNo().shortValue()
                    ,crnStn.getRow().shortValue(),crnStn.getBay().shortValue(),crnStn.getLev().shortValue()
                    ,locMast.getRow1().shortValue(),locMast.getBay1().shortValue(),locMast.getLev1().shortValue());
            News.info("" + mark + " - 1" + " - 15" + " - 命令下发 : 工作号={},源排={},源列={},源层={},目标排={},目标列={},目标层={}", wrkMast.getWrkNo().shortValue()
                    , crnStn.getRow().shortValue(), crnStn.getBay().shortValue(), crnStn.getLev().shortValue()
                    , locMast.getRow1().shortValue(), locMast.getBay1().shortValue(), locMast.getLev1().shortValue());
            // 命令下发区 --------------------------------------------------------------------------
            CrnCommand crnCommand = new CrnCommand();
@@ -843,7 +1078,7 @@
            crnCommand.setDestinationPosY(locMast.getBay1().shortValue());     // 目标库位列
            crnCommand.setDestinationPosZ(locMast.getLev1().shortValue());     // 目标库位层
            if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
                News.error(""+mark+" - 1"+" - 16"+" - 堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
                News.error("" + mark + " - 1" + " - 16" + " - 堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
            } else {
//                long startTime = System.currentTimeMillis();
@@ -864,19 +1099,40 @@
                wrkMast.setCrnStrTime(now);
                wrkMast.setModiTime(now);
                if (wrkMastMapper.updateById(wrkMast) == 0) {
                    News.error(""+mark+" - 1"+" - 17"+" - 修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", wrkMast.getWrkNo());
                    News.error("" + mark + " - 1" + " - 17" + " - 修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", wrkMast.getWrkNo());
                }
            }
        }
        News.infoNoLog(""+mark+" - 1"+" - 0"+" - 堆垛机入出库作业下发 : 入库执行完毕");
        News.infoNoLog("" + mark + " - 1" + " - 0" + " - 堆垛机入出库作业下发 : 入库执行完毕");
    }
    /**
     * 出库  ===>>  库位到堆垛机站
     * 2022-06-09 TQS修改,查询工作档LIST,遍历下发,防止第一个任务堵塞出库
     */
    public synchronized void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol,Integer mark) {
        News.warnNoLog(""+mark+" - 2"+" - 0"+" - 堆垛机入出库作业下发:执行出库");
    public synchronized void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol, Integer mark) {
        News.warnNoLog("" + mark + " - 2" + " - 0" + " - 堆垛机入出库作业下发:执行出库");
        int devpTaskStackOver = 20;
        Config config = configService.selectOne(new EntityWrapper<Config>()
                .eq("code", "devpTaskStackOver"));
        if (config != null) {
            devpTaskStackOver = Integer.parseInt(config.getValue());
        }
        int devpCheckTaskStackOver = 2;
        Config config2 = configService.selectOne(new EntityWrapper<Config>()
                .eq("code", "devpCheckTaskStackOver"));
        if (config2 != null) {
            devpCheckTaskStackOver = Integer.parseInt(config2.getValue());
        }
        Integer devpWorkingCount = commonService.queryDevpWorkingCount();
        if (devpWorkingCount > devpTaskStackOver) {
            News.warn("" + mark + " - 2" + " - 0" + " - 输送线任务过载,当前输送线承载数量:{}", devpWorkingCount);
            return;
        }
        for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) {
            // 获取工作状态为11(生成出库ID)的出库工作档
//            WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId(), crnStn.getStaNo());
@@ -887,20 +1143,20 @@
                }
                // 工作档状态判断
                if (wrkMast.getIoType() < 100 || wrkMast.getSourceStaNo() == null) {
                    News.error(""+mark+" - 2"+" - 1"+" - 查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
                    News.error("" + mark + " - 2" + " - 1" + " - 查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
                    continue;
                }
                // 获取源库位信息
                LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
                if (!sourceSta.getLocSts().equals("R") && !sourceSta.getLocSts().equals("P")) {
                    News.error(""+mark+" - 2"+" - 2"+" - 出库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), sourceSta.getLocSts());
                    News.error("" + mark + " - 2" + " - 2" + " - 出库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), sourceSta.getLocSts());
                    continue;
                }
                // 获取堆垛机出库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
                StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
                if (staProtocol == null) {
                    News.infoNoLog(""+mark+" - 2"+" - 3"+" - 堆垛机出库站信息(staProtocol!=null继续执行,否则循环终止):staProtocol="+staProtocol);
                    News.infoNoLog("" + mark + " - 2" + " - 3" + " - 堆垛机出库站信息(staProtocol!=null继续执行,否则循环终止):staProtocol=" + staProtocol);
                    break;
//                    continue;
                } else {
@@ -919,6 +1175,29 @@
                    }
                }
                //zhangc
                if (wrkMast.getIoType() == 103 || wrkMast.getIoType() == 107) {
                    if (wrkMast.getStaNo() == 1058) {
                        List<WrkMast> inWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                                .in("wrk_sts", 12, 14)
                                .eq("sta_no", 1058)
                        );
                        if (!Cools.isEmpty(inWrkMasts) && inWrkMasts.size() >= devpCheckTaskStackOver) {
                            News.error("" + mark + " - 2" + " - 检测存在1058站点,存在两笔工作中的任务,工作号={}" + wrkMast.getWrkNo());
                            continue;
                        }
                    } else if (wrkMast.getStaNo() == 1062) {
                        List<WrkMast> inWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                                .in("wrk_sts", 12, 14)
                                .eq("sta_no", 1062)
                        );
                        if (!Cools.isEmpty(inWrkMasts) && inWrkMasts.size() >= devpCheckTaskStackOver) {
                            News.error("" + mark + " - 2" + " - 检测存在1062站点,存在两笔工作中的任务,工作号={}" + wrkMast.getWrkNo());
                            continue;
                        }
                    }
                }
//            // 入出库模式判断
//            if (devpThread.ioMode != IoModeType.PAKOUT_MODE) { continue; }
//                if (wrkMast.getStaNo() == 204 && devpThread.ioModeOf2F != IoModeType.PAKOUT_MODE) {
@@ -929,24 +1208,27 @@
                // 查询站点详细信息
                BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
                if (staDetl == null) {
                    News.error(""+mark+" - 2"+" - 5"+" - 出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                    News.error("" + mark + " - 2" + " - 5" + " - 出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                    break;
//                    continue;
                }
                // 判断堆垛机出库站状态
                if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")
                        && staProtocol.getWorkNo() == 0) {
                if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")) {
                    //根据参数判断是否校验可出信号
                    String crnOutVerifyOut = "Y";
                    Config crnOutVerifyOutEnableConfig = configService.selectOne(new EntityWrapper<Config>()
                            .eq("code", "crnOutVerifyOutEnable"));
                    if(crnOutVerifyOutEnableConfig != null) {
                    if (crnOutVerifyOutEnableConfig != null) {
                        crnOutVerifyOut = crnOutVerifyOutEnableConfig.getValue();
                    }
                    if (crnOutVerifyOut.equals("Y")) {
                        if (!staProtocol.isOutEnable()) {
                            continue;
                        }
                        if (staProtocol.getWorkNo() > 0) {
                            continue;
                        }
                    }
@@ -961,24 +1243,34 @@
                    }
                    if (crnProtocol.getCrnNo() == 1) {
                        //判断堆垛机和当前任务是否处于一个巷道
                        if (Utils.getLaneByLocNo(wrkMast.getLocNo()) != crnProtocol.getCrnLane()) {
                            //判断堆垛机所在巷道是否存在其他任务,如存在则优先执行
                            List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
                            if (!currentWrkMasts.isEmpty()) {
                                continue;//当前堆垛机所在巷道存在任务
                        String turnCrnExecuteCurrentChannel = "Y";
                        Config turnCrnExecuteCurrentChannelConfig = configService.selectOne(new EntityWrapper<Config>()
                                .eq("code", "turnCrnExecuteCurrentChannel")
                        );
                        if (turnCrnExecuteCurrentChannelConfig != null) {
                            turnCrnExecuteCurrentChannel = turnCrnExecuteCurrentChannelConfig.getValue();
                        }
                        if(turnCrnExecuteCurrentChannel.equals("Y")) {
                            //判断堆垛机和当前任务是否处于一个巷道
                            if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) {
                                //判断堆垛机所在巷道是否存在其他任务,如存在则优先执行
                                List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
                                if (!currentWrkMasts.isEmpty()) {
                                    continue;//当前堆垛机所在巷道存在任务
                                }
                            }
                        }
                    }
                    // 双深库位且浅库位有货,则需先对浅库位进行库位移转
                    if (Utils.isDeepLoc(slaveProperties, wrkMast.getSourceLocNo())) {
                        News.warnNoLog(""+mark+" - 2"+" - 6"+" - 双深库位且浅库位有货,则需先对浅库位进行库位移转 : 开始执行 任务号={}",wrkMast.getWrkNo());
                        News.warnNoLog("" + mark + " - 2" + " - 6" + " - 双深库位且浅库位有货,则需先对浅库位进行库位移转 : 开始执行 任务号={}", wrkMast.getWrkNo());
                        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")) {
                            News.warnNoLog(""+mark+" - 2"+" - 7"+" - // O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!库位状态={}",shallowLoc.getLocSts());
                            News.warnNoLog("" + mark + " - 2" + " - 7" + " - // O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!库位={},库位状态={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
                            WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                            if (null == waitWrkMast) {
                                News.error("{}库位异常,未检索到相应工作档!", shallowLocNo);
@@ -987,7 +1279,7 @@
                                    waitWrkMast.setIoPri(15D);
                                    waitWrkMast.setModiTime(new Date());
                                    if (wrkMastMapper.updateById(waitWrkMast) == 0) {
                                        News.error(""+mark+" - 2"+" - 8"+" - 调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
                                        News.error("" + mark + " - 2" + " - 8" + " - 调整工作档优先级失败!工作号={}", waitWrkMast.getWrkNo());
                                    }
                                    continue;
                                } else {
@@ -995,7 +1287,7 @@
                                }
                            }
                        } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
                            News.warnNoLog(""+mark+" - 2"+" - 9"+" - // F、D  库位状态={}",shallowLoc.getLocSts());
                            News.warnNoLog("" + mark + " - 2" + " - 9" + " - // F、D  库位={},库位状态={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
//                            WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                            //2022-08-16 modify,不根据updmk标记移库任务(容易被取消导致堵塞),查询工作档是否存在任务
                            WrkMast waitWrkMast = wrkMastMapper.selectByLocNo1(shallowLocNo);
@@ -1003,7 +1295,7 @@
//                            if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())
//                                || Cools.isEmpty(waitWrkMast)) {
                            if (Cools.isEmpty(waitWrkMast)) {
                                if (moveLocForDeepLoc(slave, shallowLoc,mark)){
                                if (moveLocForDeepLoc(slave, shallowLoc, mark)) {
                                    wrkMast.setUpdMk("Y");
//                                    wrkMast.setIoPri(14D);
                                    wrkMastMapper.updateById(wrkMast);
@@ -1016,10 +1308,10 @@
                            News.error("{}任务出库失败,浅库位堵塞!浅库位号:{}", wrkMast.getWrkNo(), shallowLocNo);
                            continue;
                        } else if (shallowLoc.getLocSts().equals("Q") || shallowLoc.getLocSts().equals("S")) {
                            News.warnNoLog(""+mark+" - 2"+" - 10"+" - // Q、S  库位状态={}",shallowLoc.getLocSts());
                            News.warnNoLog("" + mark + " - 2" + " - 10" + " - // Q、S  库位={},库位状态={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
                            WrkMast waitWrkMast = wrkMastMapper.selectByLocNo1(shallowLocNo);
                            if (null != waitWrkMast && waitWrkMast.getWrkSts() == 4) {
                                News.infoNoLog(""+mark+" - 2"+" - 11"+" - // F、D  工作状态(判断条件为==4)={}",waitWrkMast.getWrkSts());
                                News.infoNoLog("" + mark + " - 2" + " - 11" + " - // F、D  工作状态(判断条件为==4)={}", waitWrkMast.getWrkSts());
                                continue;
                            }
                        }
@@ -1031,9 +1323,9 @@
//                        return;
                    }
                    News.warnNoLog(""+mark+" - 2"+" - 12"+" - 命令下发 : 工作号={},源排={},源列={},源层={},目标排={},目标列={},目标层={}",wrkMast.getWrkNo().shortValue()
                            ,sourceSta.getRow1().shortValue(),sourceSta.getBay1().shortValue(),sourceSta.getLev1().shortValue()
                            ,crnStn.getRow().shortValue(),crnStn.getBay().shortValue(),crnStn.getLev().shortValue());
                    News.warnNoLog("" + mark + " - 2" + " - 12" + " - 命令下发 : 工作号={},源排={},源列={},源层={},目标排={},目标列={},目标层={}", wrkMast.getWrkNo().shortValue()
                            , sourceSta.getRow1().shortValue(), sourceSta.getBay1().shortValue(), sourceSta.getLev1().shortValue()
                            , crnStn.getRow().shortValue(), crnStn.getBay().shortValue(), crnStn.getLev().shortValue());
                    // 1.堆垛机开始移动
                    CrnCommand crnCommand = new CrnCommand();
@@ -1048,7 +1340,7 @@
                    crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列
                    crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层
                    if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
                        News.error(""+mark+" - 2"+" - 13"+" - 堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
                        News.error("" + mark + " - 2" + " - 13" + " - 堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
                    } else {
                        // 修改工作档状态 11.生成出库ID => 12.吊车出库中
                        Date now = new Date();
@@ -1056,14 +1348,14 @@
                        wrkMast.setCrnStrTime(now);
                        wrkMast.setModiTime(now);
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            News.error(""+mark+" - 2"+" - 14"+" - 修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
                            News.error("" + mark + " - 2" + " - 14" + " - 修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
                        }
                        break;
                    }
                }
            }
        }
        News.infoNoLog(""+mark+" - 2"+" - 0"+" - 堆垛机入出库作业下发 : 出库执行完毕");
        News.infoNoLog("" + mark + " - 2" + " - 0" + " - 堆垛机入出库作业下发 : 出库执行完毕");
    }
//    /**
@@ -1186,17 +1478,17 @@
    /**
     * 库位移转
     */
    public synchronized void locToLoc(CrnSlave slave, CrnProtocol crnProtocol,Integer mark) {
    public synchronized void locToLoc(CrnSlave slave, CrnProtocol crnProtocol, Integer mark) {
        // 获取工作档信息
        WrkMast wrkMast = wrkMastMapper.selectLocMove(slave.getId());
        if (null == wrkMast) {
            return;
        }
        News.warnNoLog(""+mark+" - 3"+" - 0"+" - 堆垛机入出库作业下发:执行库位移转");
        News.warnNoLog("" + mark + " - 3" + " - 0" + " - 堆垛机入出库作业下发:执行库位移转");
        // 获取源库位信息
        LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
        if (null == sourceSta) {
            News.error(""+mark+" - 3"+" - 1"+" - 工作档库位移转失败,原因:检索源库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
            News.error("" + mark + " - 3" + " - 1" + " - 工作档库位移转失败,原因:检索源库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
            return;
        }
        // 源库位  库位状态判断
@@ -1206,7 +1498,7 @@
        // 获取目标库位信息
        LocMast sta = locMastService.selectById(wrkMast.getLocNo());
        if (null == sta) {
            News.error(""+mark+" - 3"+" - 2"+" - 工作档库位移转失败,原因:检索目标库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
            News.error("" + mark + " - 3" + " - 2" + " - 工作档库位移转失败,原因:检索目标库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
            return;
        }
        // 获取堆垛机信息 并 判断是否可入出
@@ -1225,9 +1517,9 @@
            return;
        }
        News.warnNoLog(""+mark+" - 3"+" - 3"+" - 命令下发 : 工作号={},源排={},源列={},源层={},目标排={},目标列={},目标层={}",wrkMast.getWrkNo().shortValue()
                ,sourceSta.getRow1().shortValue(),sourceSta.getBay1().shortValue(),sourceSta.getLev1().shortValue()
                ,sta.getRow1().shortValue(),sta.getBay1().shortValue(),sta.getLev1().shortValue());
        News.warnNoLog("" + mark + " - 3" + " - 3" + " - 命令下发 : 工作号={},源排={},源列={},源层={},目标排={},目标列={},目标层={}", wrkMast.getWrkNo().shortValue()
                , sourceSta.getRow1().shortValue(), sourceSta.getBay1().shortValue(), sourceSta.getLev1().shortValue()
                , sta.getRow1().shortValue(), sta.getBay1().shortValue(), sta.getLev1().shortValue());
        // 命令下发区 --------------------------------------------------------------------------
        CrnCommand crnCommand = new CrnCommand();
@@ -1242,7 +1534,7 @@
        crnCommand.setDestinationPosY(sta.getBay1().shortValue());     // 目标库位列
        crnCommand.setDestinationPosZ(sta.getLev1().shortValue());     // 目标库位层
        if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
            News.error(""+mark+" - 3"+" - 4"+" - 堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
            News.error("" + mark + " - 3" + " - 4" + " - 堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
        } else {
            // 修改工作档状态 11.生成出库ID => 12.吊车出库中
            Date now = new Date();
@@ -1250,36 +1542,37 @@
            wrkMast.setCrnStrTime(now);
            wrkMast.setModiTime(now);
            if (wrkMastMapper.updateById(wrkMast) == 0) {
                News.error(""+mark+" - 3"+" - 5"+" - 【库位移转】 修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
                News.error("" + mark + " - 3" + " - 5" + " - 【库位移转】 修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
            }
            crnProtocol.setLastIo("I");
        }
        News.infoNoLog(""+mark+" - 3"+" - 0"+" - 堆垛机入出库作业下发:库位移转完成");
        News.infoNoLog("" + mark + " - 3" + " - 0" + " - 堆垛机入出库作业下发:库位移转完成");
    }
    /**
     * 库位移转
     */
    public synchronized void locToLoc111(CrnSlave slave, CrnProtocol crnProtocol,Integer mark) {
    public synchronized void locToLoc111(CrnSlave slave, CrnProtocol crnProtocol, Integer mark) {
        // 获取工作档信息
        WrkMast wrkMast = wrkMastMapper.selectLocMove111(slave.getId());
        if (null == wrkMast) {
            return;
        }
        News.warnNoLog(""+mark+" - 3"+" - 0"+" - 堆垛机入出库作业下发:执行库位移转");
        News.warnNoLog("" + mark + " - 3" + " - 0" + " - 堆垛机入出库作业下发:执行库位移转");
        // 获取源库位信息
        LocMast sourceLoc = locMastService.selectById(wrkMast.getSourceLocNo());
        if (null == sourceLoc) {
            News.error(""+mark+" - 3"+" - 1"+" - 工作档库位移转失败,原因:检索源库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
            News.error("" + mark + " - 3" + " - 1" + " - 工作档库位移转失败,原因:检索源库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
            return;
        }
        // 源库位  库位状态判断
        if (!sourceLoc.getLocSts().equals("R")) {
            News.error(""+mark+" - 3"+" - 11"+" - 工作档库位移转失败,原因:源库位状态不为R!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
            News.error("" + mark + " - 3" + " - 11" + " - 工作档库位移转失败,原因:源库位状态不为R!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
            return;
        }
        if(wrkMast.getIoType() != 111) {
        if (wrkMast.getIoType() != 111) {
            // 获取目标库位信息
            LocMast loc = locMastService.selectById(wrkMast.getLocNo());
            if (null == loc) {
@@ -1288,7 +1581,7 @@
            }
            // 源库位  库位状态判断
            if (!loc.getLocSts().equals("S")) {
                News.error(""+mark+" - 3"+" - 21"+" - 工作档库位移转失败,原因:目标库位状态不为R!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
                News.error("" + mark + " - 3" + " - 21" + " - 工作档库位移转失败,原因:目标库位状态不为R!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
                return;
            }
        }
@@ -1308,9 +1601,9 @@
            return;
        }
        News.warnNoLog(""+mark+" - 3"+" - 3"+" - 命令下发 : 工作号={},源排={},源列={},源层={},目标排={},目标列={},目标层={}",wrkMast.getWrkNo().shortValue()
                ,sourceLoc.getRow1().shortValue(),sourceLoc.getBay1().shortValue(),sourceLoc.getLev1().shortValue()
                ,sourceLoc.getRow1().shortValue(),sourceLoc.getBay1().shortValue(),sourceLoc.getLev1().shortValue());
        News.warnNoLog("" + mark + " - 3" + " - 3" + " - 命令下发 : 工作号={},源排={},源列={},源层={},目标排={},目标列={},目标层={}", wrkMast.getWrkNo().shortValue()
                , sourceLoc.getRow1().shortValue(), sourceLoc.getBay1().shortValue(), sourceLoc.getLev1().shortValue()
                , sourceLoc.getRow1().shortValue(), sourceLoc.getBay1().shortValue(), sourceLoc.getLev1().shortValue());
        // 命令下发区 --------------------------------------------------------------------------
        CrnCommand crnCommand = new CrnCommand();
@@ -1325,7 +1618,7 @@
        crnCommand.setDestinationPosY(sourceLoc.getBay1().shortValue());     // 目标库位列
        crnCommand.setDestinationPosZ(sourceLoc.getLev1().shortValue());     // 目标库位层
        if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
            News.error(""+mark+" - 3"+" - 4"+" - 堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
            News.error("" + mark + " - 3" + " - 4" + " - 堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
        } else {
            // 修改工作档状态 11.生成出库ID => 12.吊车出库中
            Date now = new Date();
@@ -1333,10 +1626,10 @@
            wrkMast.setCrnStrTime(now);
            wrkMast.setModiTime(now);
            if (wrkMastMapper.updateById(wrkMast) == 0) {
                News.error(""+mark+" - 3"+" - 5"+" - 【库位移转】 修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
                News.error("" + mark + " - 3" + " - 5" + " - 【库位移转】 修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", wrkMast.getWrkNo());
            }
        }
        News.infoNoLog(""+mark+" - 3"+" - 0"+" - 堆垛机入出库作业下发:库位移转完成");
        News.infoNoLog("" + mark + " - 3" + " - 0" + " - 堆垛机入出库作业下发:库位移转完成");
    }
@@ -1353,37 +1646,57 @@
            }
            //  状态:等待确认 并且  任务完成位 = 1
            if (crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) {
                News.warnNoLog(""+mark+" - 0"+" - 开始执行对工作档的完成操作");
                News.warnNoLog("" + mark + " - 0" + " - 开始执行对工作档的完成操作");
                if (crnProtocol.getTaskNo() == 9999) {
                    // 堆垛机复位
                    crnThread.setResetFlag(true);
                } else {
                    // 获取入库待确认工作档
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue());
                    if (wrkMast == null) {
                        News.error(""+mark+" - 1"+" - 堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo());
                        continue;
                    }
                    redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 8);//防止回原点后下发指令过快
                    continue;
                }
                // 获取待确认工作档
                WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue());
                if (wrkMast == null) {
                    News.error("" + mark + " - 1" + " - 堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo());
                    continue;
                }
                Date now = new Date();
                if(wrkMast.getIoType() < 100){
                    // 入库 + 库位转移  ==> 4.入库完成
                    if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && (wrkMast.getIoType() == 11 || wrkMast.getIoType()==111))) {
                    if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && (wrkMast.getIoType() == 11 || wrkMast.getIoType() == 111))) {
                        wrkMast.setWrkSts(4L);
                    } else {
                        continue;
                    }
                    Date now = new Date();
                    wrkMast.setCrnEndTime(now);
                    wrkMast.setModiTime(now);
                    // 修改成功后复位堆垛机
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        // 堆垛机复位
                        News.warnNoLog(""+mark+" - 2"+" - 修改成功后复位堆垛机 : 堆垛机号={}",crnThread.getCrnProtocol().getCrnNo());
                        News.warnNoLog("" + mark + " - 2" + " - 修改成功后复位堆垛机 : 堆垛机号={}", crnThread.getCrnProtocol().getCrnNo());
                        crnThread.setResetFlag(true);
                    }
                }else {
                    List<Long> list = new ArrayList<>();
                    list.add(14L);
                    list.add(15L);
                    if (!list.contains(wrkMast.getWrkSts())) {
                        News.error("" + mark + " - 1" + " - 堆垛机处于等待确认但工作档状态未完成。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo());
                        continue;
                    }
                    wrkMast.setCrnEndTime(now);
                    if (wrkMastMapper.updateById(wrkMast) != 0) {
                        // 复位堆垛机
                        crnThread.setResetFlag(true);
                    }
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 对工作档的完成操作执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 对工作档的完成操作执行完成");
    }
    /**
@@ -1406,7 +1719,7 @@
                    BasErrLog latest = basErrLogService.findLatestByTaskNo(crn.getId(), crnProtocol.getTaskNo().intValue());
                    // 有异常
                    if (latest == null) {
                        News.warnNoLog(""+mark+" - 1"+" - 开始执行:堆垛机异常信息记录 : 有任务,有异常");
                        News.warnNoLog("" + mark + " - 1" + " - 开始执行:堆垛机异常信息记录 : 有任务,有异常");
                        if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) {
                            WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo());
                            if (wrkMast == null) {
@@ -1438,7 +1751,7 @@
                                    "任务中异常"    // 备注
                            );
                            if (!basErrLogService.insert(basErrLog)) {
                                News.error(""+mark+" - 2"+" - 堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), errName);
                                News.error("" + mark + " - 2" + " - 堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), errName);
                            }
                        }
                    } else {
@@ -1448,7 +1761,7 @@
                            latest.setUpdateTime(now);
                            latest.setStatus(2);
                            if (!basErrLogService.updateById(latest)) {
                                News.error(""+mark+" - 3"+" - 堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
                                News.error("" + mark + " - 3" + " - 堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
                            }
                        }
                    }
@@ -1457,7 +1770,7 @@
                    BasErrLog latest = basErrLogService.findLatest(crn.getId());
                    // 有异常
                    if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) {
                        News.warnNoLog(""+mark+" - 4"+" - 开始执行:堆垛机异常信息记录 : 无任务,有异常");
                        News.warnNoLog("" + mark + " - 4" + " - 开始执行:堆垛机异常信息记录 : 无任务,有异常");
                        // 记录新异常
                        if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm().intValue())) {
                            BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm());
@@ -1486,7 +1799,7 @@
                                    "无任务异常"    // 备注
                            );
                            if (!basErrLogService.insert(basErrLog)) {
                                News.error(""+mark+" - 5"+" - 堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), errName);
                                News.error("" + mark + " - 5" + " - 堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), errName);
                            }
                        }
                        // 无异常
@@ -1497,7 +1810,7 @@
                            latest.setUpdateTime(now);
                            latest.setStatus(2);
                            if (!basErrLogService.updateById(latest)) {
                                News.error(""+mark+" - 6"+" - 堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
                                News.error("" + mark + " - 6" + " - 堆垛机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
                            }
                        }
                    }
@@ -1505,7 +1818,7 @@
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 堆垛机异常信息记录执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 堆垛机异常信息记录执行完成");
    }
@@ -1529,11 +1842,17 @@
                }
                LedThread ledThread = null;
                if (!Cools.isEmpty(emptyInSta.getLed()))  {
                if (!Cools.isEmpty(emptyInSta.getLed())) {
                    ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed());
                }
                if (!staProtocol.isLoading()){
                if (!staProtocol.isLoading()) {
                    continue;
                }
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, emptyInSta.getBarcode());
                if (barcodeThread == null) {
                    continue;
                }
@@ -1542,8 +1861,32 @@
                        && staProtocol.isInEnable()
                        && staProtocol.isEmptyMk()
                        && (staProtocol.getWorkNo() > 9990 && staProtocol.getWorkNo() <= 9999)
                        && staProtocol.isPakMk()) {
                    News.warnNoLog(""+mark+" - 0"+" - 开始执行:空栈板初始化入库,叉车入库站放货");
                        && staProtocol.isPakMk()
                        && staProtocol.getEmptyInType() == 1
                ) {
                    News.warnNoLog("" + mark + " - 0" + " - 开始执行:空栈板初始化入库,叉车入库站放货");
                    String barcode = barcodeThread.getBarcode();
                    if (!Cools.isEmpty(barcode)) {
                        News.info("" + mark + " - 1" + " - {}号条码扫描器检测条码信息:{}", emptyInSta.getBarcode(), barcode);
                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
                            News.info("" + mark + " - 2" + " - 扫码失败1 ===>> {}号条码扫描器检测条码信息:{},站点:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
                            // led 异常显示
                            if (ledThread != null) {
                                String errorMsg = "扫码失败,请重试";
                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                            }
                            continue;
                        }
                    } else {
                        News.info("" + mark + " - 3" + " - 扫码失败2 ===>> {}号条码扫描器检测条码信息:{},站点:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "扫码失败,请重试";
                            MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                        }
                        continue;
                    }
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
@@ -1552,6 +1895,7 @@
                        param.setIoType(10);
                        param.setSourceStaNo(emptyInSta.getStaNo());
                        param.setLocType1(locTypeDto.getLocType1());
                        param.setBarcode(barcode);
                        String response = new HttpHandler.Builder()
                                .setUri(wmsUrl)
                                .setPath("/rpc/pakin/loc/v1")
@@ -1562,61 +1906,148 @@
                        if (jsonObject.getInteger("code").equals(200)) {
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("loc_no", dto.getLocNo()));
                            // 更新站点信息 且 下发plc命令
                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                            staProtocol.setStaNo(dto.getStaNo().shortValue());
                            staProtocol.setPalletSize(locMast.getLocType2());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
                                News.errorNoLog(""+mark+" - 1"+" - 更新plc站点信息失败");
                                News.errorNoLog("" + mark + " - 1" + " - 更新plc站点信息失败");
                                throw new CoolException("更新plc站点信息失败");
                            }
                            if (ledThread != null) {
                                // 命令集合
                                List<LedCommand> commands = new ArrayList<>();
                                // 组装命令
                                LedCommand ledCommand = new LedCommand();
                                ledCommand.setWorkNo(dto.getWorkNo());
                                ledCommand.setIoType(1);
                                ledCommand.setTitle("全板入库");
                                ledCommand.setLocNo(dto.getLocNo());
                                ledCommand.setStaNo(dto.getStaNo());
                                commands.add(ledCommand);
                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, commands));
//                                ledThread.errorReset();
                            }
                        } else {
                            staProtocol.setWorkNo((short)9992);
                            staProtocol.setStaNo(emptyInSta.getBackSta().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
                                News.errorNoLog(""+mark+" - 2"+" - 更新plc站点信息失败");
                                throw new CoolException("更新plc站点信息失败");
                            }
                            if (ledThread != null) {
                                String errorMsg = jsonObject.getString("msg");
                                if (!Cools.isEmpty(errorMsg)) {
                                    MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                                }
                            }
                            News.error(""+mark+" - 3"+" - 请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            News.error("" + mark + " - 3" + " - 请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    }
                } else {
                    News.errorNoLog(""+mark+" - 4"+" - 站点信息不符合入库条件!!!"+" 自动信号:"+staProtocol.isAutoing()+"、可入信号:" + staProtocol.isInEnable()
                            +"、空板信号:"+ staProtocol.isEmptyMk()+"、工作号:" + staProtocol.getWorkNo()
                            +"、锁定标记"+ staProtocol.isPakMk());
                    News.errorNoLog("" + mark + " - 4" + " - 站点信息不符合入库条件!!!" + " 自动信号:" + staProtocol.isAutoing() + "、可入信号:" + staProtocol.isInEnable()
                            + "、空板信号:" + staProtocol.isEmptyMk() + "、工作号:" + staProtocol.getWorkNo()
                            + "、锁定标记" + staProtocol.isPakMk());
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 空栈板初始化入库,叉车入库站放货执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 空栈板初始化入库,叉车入库站放货执行完成");
    }
    /**
     * 空托盘入库-产线
     */
    public synchronized void storeEmptyPltLine(Integer mark) {
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历空板入库口
            for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) {
                // 获取空板入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(emptyInSta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                LedThread ledThread = null;
                if (!Cools.isEmpty(emptyInSta.getLed())) {
                    ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed());
                }
                if (!staProtocol.isLoading()) {
                    continue;
                }
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, emptyInSta.getBarcode());
                if (barcodeThread == null) {
                    continue;
                }
                // 站点条件判断
                if (staProtocol.isAutoing()
                        && staProtocol.isInEnable()
                        && staProtocol.isEmptyMk()
                        && (staProtocol.getWorkNo() > 9990 && staProtocol.getWorkNo() <= 9999)
                        && staProtocol.isPakMk()
                        && staProtocol.getEmptyInType() == 2
                ) {
                    News.warnNoLog("" + mark + " - 0" + " - 开始执行:空栈板初始化入库,叉车入库站放货");
                    String barcode = barcodeThread.getBarcode();
                    if (!Cools.isEmpty(barcode)) {
                        News.info("" + mark + " - 1" + " - {}号条码扫描器检测条码信息:{}", emptyInSta.getBarcode(), barcode);
                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
                            News.info("" + mark + " - 2" + " - 扫码失败1 ===>> {}号条码扫描器检测条码信息:{},站点:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
                            // led 异常显示
                            if (ledThread != null) {
                                String errorMsg = "扫码失败,请重试";
                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                            }
                            continue;
                        }
                    } else {
                        News.info("" + mark + " - 3" + " - 扫码失败2 ===>> {}号条码扫描器检测条码信息:{},站点:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "扫码失败,请重试";
                            MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                        }
                        continue;
                    }
                    WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
                            .eq("barcode", barcode)
                    );
                    if (wrkMast != null) {
                        continue;
                    }
                    int workNo = commonService.getWorkNo(3);
                    // 生成工作档
                    WrkMast wrkMast1 = new WrkMast();
                    wrkMast1.setWrkNo(workNo);
                    wrkMast1.setIoTime(new Date());
                    wrkMast1.setWrkSts(2L); // 工作状态:设备上走
                    wrkMast1.setIoType(3); // 入出库状态:3.站到站
                    wrkMast1.setIoPri(13D); // 优先级
                    wrkMast1.setSourceStaNo(emptyInSta.getStaNo());
                    wrkMast1.setStaNo(1004);
                    wrkMast1.setBarcode(barcode);
                    // 操作人员数据
                    wrkMast1.setAppeTime(new Date());
                    wrkMast1.setModiTime(new Date());
                    boolean res = wrkMastService.insert(wrkMast1);
                    if (!res) {
                        throw new CoolException("保存工作档失败");
                    }
                    // 更新站点信息 且 下发plc命令
                    staProtocol.setWorkNo((short) workNo);
                    staProtocol.setStaNo((short) 2003);
                    staProtocol.setPalletSize((short) 1);
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    if (!result) {
                        News.errorNoLog("" + mark + " - 1" + " - 更新plc站点信息失败");
                        throw new CoolException("更新plc站点信息失败");
                    }
                } else {
                    News.errorNoLog("" + mark + " - 4" + " - 站点信息不符合入库条件!!!" + " 自动信号:" + staProtocol.isAutoing() + "、可入信号:" + staProtocol.isInEnable()
                            + "、空板信号:" + staProtocol.isEmptyMk() + "、工作号:" + staProtocol.getWorkNo()
                            + "、锁定标记" + staProtocol.isPakMk());
                }
            }
        }
        News.infoNoLog("" + mark + " - 0" + " - 空栈板初始化入库,叉车入库站放货执行完成");
    }
    /**
@@ -1645,7 +2076,7 @@
                if (null == wrkMast) {
                    continue;
                }
                News.warnNoLog(""+mark+" - 0"+" - 开始执行:出库  ===>> 工作档信息写入led显示器");
                News.warnNoLog("" + mark + " - 0" + " - 开始执行:出库  ===>> 工作档信息写入led显示器");
                wrkMasts.add(wrkMast);
                // 组装命令
                LedCommand ledCommand = new LedCommand();
@@ -1685,7 +2116,7 @@
                        ledCommand.setTitle("并板入库");
                        break;
                    default:
                        News.error(""+mark+" - 1"+" - 任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
                        News.error("" + mark + " - 1" + " - 任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
                        break;
                }
                ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
@@ -1709,21 +2140,64 @@
//                    }catch (Exception e){
//                        log.error("工作档案明细输入电视机失败1:异常信息==》"+e);
//                    }
                    wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(
                            wrkDetl.getMatnr()
                            , wrkDetl.getMaktx()
                            , wrkDetl.getAnfme()
                            , wrkDetl.getWeight()
                            , wrkDetl.getStockNum()
                            , wrkDetl.getStockNum2()
                            , wrkDetl.getSpecs()
                            , wrkDetl.getSku()
                            , wrkDetl.getZpallet()
                            , wrkDetl.getModel()
                            , wrkDetl.getSupp()
                            , wrkDetl.getKpCstmrName()
                            , wrkDetl.getOrderNo()
                    )));
                    if (!wrkDetls.isEmpty()) {
                        WrkDetl wrkDetl = wrkDetls.get(0);
                        double anfme = 0D;
                        double weight = 0D;
                        for (WrkDetl detl : wrkDetls) {
                            anfme += detl.getAnfme();
                            weight += detl.getWeight();
                            wrkDetl.setAnfme(anfme);
                            wrkDetl.setWeight(weight);
                        }
                        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
                                .eq("loc_no", wrkMast.getSourceLocNo()));
                        double totalAnfme = 0D;
                        double totalWeight = 0D;
                        for (LocDetl locDetl : locDetls) {
                            totalAnfme += locDetl.getAnfme();
                            totalWeight += locDetl.getWeight();
                        }
                        wrkDetl.setStockNum(totalAnfme);
                        wrkDetl.setStockNum2(totalWeight);
                        ledCommand.getMatDtos().add(new MatDto(
                                wrkDetl.getMatnr()
                                , wrkDetl.getMaktx()
                                , wrkDetl.getAnfme()
                                , wrkDetl.getWeight()
                                , wrkDetl.getStockNum()
                                , wrkDetl.getStockNum2()
                                , wrkDetl.getSpecs()
                                , wrkDetl.getSku()
                                , wrkDetl.getZpallet()
                                , wrkDetl.getModel()
                                , wrkDetl.getSupp()
                                , wrkDetl.getKpCstmrName()
                                , wrkDetl.getOrderNo()
                                , wrkDetl.getCstateid$()
                        ));
//                        wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(
//                                wrkDetl.getMatnr()
//                                , wrkDetl.getMaktx()
//                                , wrkDetl.getAnfme()
//                                , wrkDetl.getWeight()
//                                , wrkDetl.getStockNum()
//                                , wrkDetl.getStockNum2()
//                                , wrkDetl.getSpecs()
//                                , wrkDetl.getSku()
//                                , wrkDetl.getZpallet()
//                                , wrkDetl.getModel()
//                                , wrkDetl.getSupp()
//                                , wrkDetl.getKpCstmrName()
//                                , wrkDetl.getOrderNo()
//                                , wrkDetl.getCstateid$()
//                        )));
                    }
                }
                commands.add(ledCommand);
            }
@@ -1758,7 +2232,7 @@
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
                    News.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    continue;
                }else {
                } else {
                    ledThread.setLedMk(false);
                }
            }
@@ -1769,7 +2243,7 @@
                    wrkMast.setOveMk("Y");
                    wrkMast.setModiTime(new Date());
                    if (wrkMastMapper.updateById(wrkMast) == 0) {
                        News.errorNoLog(""+mark+" - 4"+" - 更新工作档失败");
                        News.errorNoLog("" + mark + " - 4" + " - 更新工作档失败");
                        throw new CoolException("更新工作档失败");
                    }
                }
@@ -1783,7 +2257,7 @@
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 出库  ===>> 工作档信息写入led显示器执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 出库  ===>> 工作档信息写入led显示器执行完成");
    }
    /**
@@ -1791,7 +2265,7 @@
     */
    public synchronized void ledReset(Integer mark) {
        News.warnNoLog(""+mark+" - 0"+" - 开始执行:其他  ===>> LED显示器复位,显示默认信息");
        News.warnNoLog("" + mark + " - 0" + " - 开始执行:其他  ===>> LED显示器复位,显示默认信息");
        for (LedSlave led : slaveProperties.getLed()) {
            // 获取输送线plc线程
@@ -1815,13 +2289,13 @@
            if (reset && !ledThread.isLedMk()) {
                ledThread.setLedMk(true);
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
                    News.error(""+mark+" - 1"+" - {}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    News.error("" + mark + " - 1" + " - {}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                } else {
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 执行完成:其他  ===>> LED显示器复位,显示默认信息");
        News.infoNoLog("" + mark + " - 0" + " - 执行完成:其他  ===>> LED显示器复位,显示默认信息");
    }
    /**
@@ -1905,10 +2379,10 @@
     * 因双深库位阻塞,对浅库位进行移转(立即执行版)
     * tip:同步
     */
    private synchronized boolean moveLocForDeepLoc(CrnSlave crn, LocMast shallowLoc,Integer mark) {
    private synchronized boolean moveLocForDeepLoc(CrnSlave crn, LocMast shallowLoc, Integer mark) {
        try {
            News.warnNoLog(""+mark+"moveLocForDeepLoc"+" - 0"+" - 开始执行:因双深库位阻塞,对浅库位进行移转(立即执行版)");
            News.warnNoLog("" + mark + "moveLocForDeepLoc" + " - 0" + " - 开始执行:因双深库位阻塞,对浅库位进行移转(立即执行版)");
            List<Integer> rows = locMastService.queryDistinctRow(crn.getId());
            LocMast loc = null;
            for (Integer row : rows) {
@@ -1950,7 +2424,7 @@
            }
            if (null == loc) {
                News.error(""+mark+"moveLocForDeepLoc"+" - 1"+" - 双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo());
                News.error("" + mark + "moveLocForDeepLoc" + " - 1" + " - 双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo());
                return false;
//                throw new CoolException("双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo());
            } else {
@@ -1978,7 +2452,7 @@
                    wrkMast.setModiTime(new Date());
                    int res = wrkMastMapper.insert(wrkMast);
                    if (res == 0) {
                        News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 2"+" - 保存工作档失败");
                        News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 2" + " - 保存工作档失败");
//                        throw new CoolException("保存工作档失败");
                        return true;
                    }
@@ -1996,7 +2470,7 @@
                            wrkDetl.setAppeTime(new Date());
                            wrkDetl.setModiTime(new Date());
                            if (!wrkDetlService.insert(wrkDetl)) {
                                News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 3"+" - 保存工作档明细失败");
                                News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 3" + " - 保存工作档明细失败");
//                                throw new CoolException("保存工作档明细失败");
                                return true;
                            }
@@ -2007,12 +2481,12 @@
                        shallowLoc.setLocSts("R"); // R.出库预约
                        shallowLoc.setModiTime(new Date());
                        if (!locMastService.updateById(shallowLoc)) {
                            News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 4"+" - 更新源库位状态失败");
                            News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 4" + " - 更新源库位状态失败");
//                            throw new CoolException("更新源库位状态失败");
                            return true;
                        }
                    } else {
                        News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 5"+" - 源库位出库失败");
                        News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 5" + " - 源库位出库失败");
//                        throw new CoolException("源库位出库失败");
                        return true;
                    }
@@ -2021,23 +2495,23 @@
                        loc.setLocSts("S"); // S.入库预约
                        loc.setModiTime(new Date());
                        if (!locMastService.updateById(loc)) {
                            News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 6"+" - 更新目标库位状态失败");
                            News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 6" + " - 更新目标库位状态失败");
//                            throw new CoolException("更新目标库位状态失败");
                            return true;
                        }
                    } else {
                        News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 7"+" - 移转失败");
                        News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 7" + " - 移转失败");
//                        throw new CoolException("移转失败");
                        return true;
                    }
                } catch (Exception e){
                    News.error(""+mark+"moveLocForDeepLoc"+" - 8"+" - 双深库位阻塞,对浅库位进行移转失败", e);
                } catch (Exception e) {
                    News.error("" + mark + "moveLocForDeepLoc" + " - 8" + " - 双深库位阻塞,对浅库位进行移转失败", e);
                }
            }
        } catch (Exception e) {
            News.error(""+mark+"moveLocForDeepLoc"+" - 8"+" - 双深库位阻塞,对浅库位进行移转失败", e);
            News.error("" + mark + "moveLocForDeepLoc" + " - 8" + " - 双深库位阻塞,对浅库位进行移转失败", e);
//            e.printStackTrace();
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
@@ -2203,7 +2677,10 @@
    // RGV  ===>> 执行对RGV操作
    public synchronized void rgvExecute(Integer mark) {
        ArrayList<Integer> list = new ArrayList<Integer>(){{add(2003);add(2002);}};
        ArrayList<Integer> list = new ArrayList<Integer>() {{
            add(2003);
            add(2002);
        }};
        for (Integer staNo : list) {
            Integer devpId = null;
            Integer rgvStaNoDevpId = null;
@@ -2212,7 +2689,7 @@
                devpId = 1;
                rgvStaNo = 2002;
                rgvStaNoDevpId = 2;
            }else {
            } else {
                devpId = 2;
                rgvStaNo = 2003;
                rgvStaNoDevpId = 1;
@@ -2262,6 +2739,21 @@
                    continue;
                }
                // 获取RGV信息
                RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, 1);
                if (rgvThread == null) {
                    continue;
                }
                RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
                if (rgvProtocol == null) {
                    continue;
                }
                if (rgvProtocol.statusType1 != RgvStatusType.IDLE && rgvProtocol.getTaskNo1() != 0) {
                    continue;
                }
                Object object = redisUtil.get(RedisConstantType.RGV_MOVE_LOCK + wrkMast.getWrkNo());
                if (object != null) {
                    continue;
@@ -2305,15 +2797,20 @@
            //  状态:等待确认 并且  任务完成位 = 1
            if (rgvProtocol.statusType1 == RgvStatusType.WAITING && rgvProtocol.getTaskNo1() != 0) {
                News.warnNoLog(""+mark+" - 0"+" - 开始执行对RGV工作档的完成操作");
                News.warnNoLog("" + mark + " - 0" + " - 开始执行对RGV工作档的完成操作");
                // 获取入库待确认工作档
                WrkMast wrkMast = wrkMastMapper.selectPakInStep3(rgvProtocol.getTaskNo1().intValue());
                if (wrkMast == null) {
                    News.error(""+mark+" - 1"+" - RGV处于等待确认且任务完成状态,但未找到工作档。RGV号={},工作号={}", rgvSlave.getId(), rgvProtocol.getTaskNo1());
                    News.error("" + mark + " - 1" + " - RGV处于等待确认且任务完成状态,但未找到工作档。RGV号={},工作号={}", rgvSlave.getId(), rgvProtocol.getTaskNo1());
                    continue;
                }
                if (wrkMast.getWrkSts() != 201) {
                    continue;
                }
                if (wrkMast.getIoType() == 3) {
                    //站到站走另外一个方法
                    continue;
                }
@@ -2327,7 +2824,7 @@
                    devpId = 1;
                    devpStaNo = 2003;
                    locNo = wrkMast.getLocNo();
                }else {
                } else {
                    //出库
                    updateWrkSts = 15L;
                    devpId = 2;
@@ -2363,7 +2860,87 @@
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 对工作档的完成操作执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 对工作档的完成操作执行完成");
    }
    // RGV  ===>> 执行对RGV工作档的完成操作 站到站
    public synchronized void rgvFinished2(Integer mark) {
        for (RgvSlave rgvSlave : slaveProperties.getRgv()) {
            // 获取RGV信息
            RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId());
            if (rgvThread == null) {
                continue;
            }
            RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
            if (rgvProtocol == null) {
                continue;
            }
            //  状态:等待确认 并且  任务完成位 = 1
            if (rgvProtocol.statusType1 == RgvStatusType.WAITING && rgvProtocol.getTaskNo1() != 0) {
                News.warnNoLog("" + mark + " - 0" + " - 开始执行对RGV工作档的完成操作");
                // 获取入库待确认工作档
                WrkMast wrkMast = wrkMastMapper.selectPakInStep3(rgvProtocol.getTaskNo1().intValue());
                if (wrkMast == null) {
                    News.error("" + mark + " - 1" + " - RGV处于等待确认且任务完成状态,但未找到工作档。RGV号={},工作号={}", rgvSlave.getId(), rgvProtocol.getTaskNo1());
                    continue;
                }
                if (wrkMast.getWrkSts() != 201) {
                    continue;
                }
                if (wrkMast.getIoType() != 3) {
                    //不是站到站
                    continue;
                }
                Integer devpId = 2;
                Integer devpStaNo = 2002;
                // 获取入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devpId);
                StaProtocol staProtocol = devpThread.getStation().get(devpStaNo);
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                if (staProtocol.isAutoing()
                        && staProtocol.isLoading()
                        && staProtocol.getWorkNo() == 0
                ) {
                    short locType2 = 1;
                    String barcode = wrkMast.getBarcode();
                    if (barcode.startsWith("11")) {
                        locType2 = 1;
                    } else if (barcode.startsWith("13")) {
                        locType2 = 2;
                    } else if (barcode.startsWith("16")) {
                        locType2 = 3;
                    } else {
                        continue;
                    }
                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                    staProtocol.setPalletSize(locType2);
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devpId, new Task(2, staProtocol));
                    if (!result) {
                        throw new CoolException("更新plc站点信息失败");
                    }
                    rgvThread.setResetFlag1(true);
                    wrkMastService.delete(new EntityWrapper<WrkMast>()
                            .eq("wrk_no", wrkMast.getWrkNo()));
                }
            }
        }
        News.infoNoLog("" + mark + " - 0" + " - 对工作档的完成操作执行完成");
    }
//    /**