#
ytfl
2025-08-11 33050f2e886fb8e4f84313388cc0450550b0b848
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;
@@ -13,7 +14,7 @@
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.asrs.utils.VersionUtils;
import com.zy.common.constant.RedisConstantType;
import com.zy.common.model.LocTypeDto;
import com.zy.common.model.MatDto;
import com.zy.common.model.SearchLocParam;
@@ -22,6 +23,7 @@
import com.zy.common.utils.CollectionUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.News;
import com.zy.common.utils.RedisUtil;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
@@ -39,6 +41,8 @@
import com.zy.core.thread.LedThread;
import com.zy.core.thread.RgvThread;
import com.zy.core.thread.SiemensDevpThread;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -91,6 +95,10 @@
    private WrkMastService wrkMastService;
    @Autowired
    private WrkMastLogService wrkMastLogService;
    @Autowired
    private ConfigService configService;
    @Autowired
    private RedisUtil redisUtil;
    @Value("${wms.url}")
    private String wmsUrl;
@@ -123,7 +131,7 @@
                LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                // 判断是否满足入库条件
                if (!staProtocol.isLoading()){
                if (!staProtocol.isLoading()) {
                    continue;
                }
@@ -131,18 +139,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 = "扫码失败,请重试";
@@ -156,7 +164,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 = "扫码失败,请重试";
@@ -169,13 +177,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);
@@ -199,7 +207,7 @@
                                .in("sta_no", 1003, 1007)
                        );
                        if (!wrkMasts.isEmpty()) {
                            News.error(""+mark+" - 4"+" - 1003站入库,检测存在出库任务,等待出库任务执行完成,托盘码={}", barcode);
                            News.error("" + mark + " - 4" + " - 1003站入库,检测存在出库任务,等待出库任务执行完成,托盘码={}", barcode);
                            continue;
                        }
                    }
@@ -225,9 +233,14 @@
                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("loc_no", dto.getLocNo()));
                            short staNo = dto.getStaNo().shortValue();
                            if (inSta.getStaNo() == 1002) {
                                staNo = 2002;
                            }
                            barcodeThread.setBarcode("");
                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                            staProtocol.setStaNo(dto.getStaNo().shortValue());
                            staProtocol.setStaNo(staNo);
                            staProtocol.setPalletSize(locMast.getLocType2());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
@@ -235,23 +248,23 @@
                                throw new CoolException("更新plc站点信息失败");
                            }
                            // led 入库信息显示
                            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, inSta.getLed(), new Task(3, commands));
//                                ledThread.errorReset();
                            }
//                            // led 入库信息显示
//                            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, inSta.getLed(), new Task(3, commands));
////                                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);
@@ -272,15 +285,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" + " - 组托  ===》执行完成");
    }
@@ -303,7 +316,7 @@
                }
                // 判断是否满足入库条件
                if (!staProtocol.isLoading()){
                if (!staProtocol.isLoading()) {
                    continue;
                }
@@ -312,7 +325,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) {
@@ -331,20 +344,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入库  ===》执行完成");
    }
@@ -364,26 +377,30 @@
                    staProtocol = staProtocol.clone();
                }
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isPakMk()) {
                    News.warnNoLog(""+mark+" - 0"+" - 开始执行");
                if (staProtocol.isAutoing()
                        && staProtocol.isLoading()
                        && staProtocol.isInEnable()
                        && staProtocol.getWorkNo() > 0
                        && staProtocol.isPakMk()) {
                    News.warnNoLog("" + mark + " - 0" + " - 开始执行");
                    // 获取条码扫描仪信息
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
                    if (barcodeThread == null) {
                        continue;
                    }
                    String barcode = barcodeThread.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        News.info(""+mark+" - 1"+" - {}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode);
                        if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
                            continue;
                        }
                    } else {
                        continue;
                    }
//                    // 获取条码扫描仪信息
//                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
//                    if (barcodeThread == null) {
//                        continue;
//                    }
//                    String barcode = barcodeThread.getBarcode();
//                    if(!Cools.isEmpty(barcode)) {
//                        News.info(""+mark+" - 1"+" - {}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode);
//                        if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
//                            continue;
//                        }
//                    } else {
//                        continue;
//                    }
                    WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
//                    WrkMast wrkMast = wrkMastMapper.selectPakInStep3(staProtocol.getWorkNo().intValue());
//                    WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep3(staProtocol.getWorkNo().intValue());
                    if (wrkMast == null) {
                        // 无拣料数据
                        continue;
@@ -409,16 +426,16 @@
                            .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));
//                        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, 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;
@@ -446,6 +463,7 @@
                        wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 目标库位 = 出库时的源库位
                        wrkMast.setSourceLocNo(""); // 源库位清空
                        wrkMast.setModiTime(now);
                        wrkMast.setUpdMk("");//允许再次移库
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            throw new CoolException("更新工作档数据状态失败");
                        }
@@ -472,18 +490,160 @@
                    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" + " - 拣料、并板、盘点再入库  ===》执行完成");
    }
    /**
@@ -523,7 +683,7 @@
                    if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
                            && crnProtocol.statusType == CrnStatusType.WAITING
                            && crnProtocol.forkPosType == CrnForkPosType.HOME) {
                        News.warnNoLog(""+mark+" - 0"+" - 开始执行");
                        News.warnNoLog("" + mark + " - 0" + " - 开始执行");
                        // 命令下发区 --------------------------------------------------------------------------
@@ -545,21 +705,21 @@
                            // 复位堆垛机
                            crnThread.setResetFlag(true);
                        } else {
                            News.error(""+mark+" - 1"+" - 更新工作档的工作状态为14失败!!! [工作号:{}]", wrkMast.getWrkNo());
                            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);
                    } 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" + " - 堆垛机站出库到出库站  ===》执行完成");
    }
    /**
@@ -576,7 +736,7 @@
            }
            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
            if (basCrnp == null) {
                News.error(""+mark+" - 1"+" - {}号堆垛机尚未在数据库进行维护!", crn.getId());
                News.error("" + mark + " - 1" + " - {}号堆垛机尚未在数据库进行维护!", crn.getId());
                continue;
            }
@@ -588,108 +748,196 @@
            // 只有当堆垛机空闲 并且 无任务时才继续执行
            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" + " - 堆垛机入出库作业下发执行完成");
    }
    /**
     * 回原点,堆垛机没有执行中任务,设备存在入库任务时叫回原点
     * 堆垛机无任务两分钟,回入库口待机
     */
    public synchronized void crnRebackHp(CrnProtocol crnProtocol, CrnThread crnThread) {
//        for (CrnSlave crn : slaveProperties.getCrn()) {
//            // 获取堆垛机信息
//            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
//            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
//            if (crnProtocol == null) {
//                continue;
//            }
//            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
//            if (basCrnp == null) {
//                log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
//                continue;
//            }
        if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
            if (crnProtocol.getBay() == 1 && crnProtocol.getLevel() == 1) {
                return;
    public synchronized void crnMove() {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            if (crn.getId() == 1) {
                continue;
            }
            // 已经存在吊车执行任务时,则过滤3,12
            if (wrkMastMapper.selectWorking(crnProtocol.getCrnNo()) != null) {
                return;
            // 获取堆垛机信息
            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;
            }
            //堆垛机有执行中任务,过滤3,4,11,12
            if (wrkMastMapper.selectCrnWorking(crnProtocol.getCrnNo()) != null) {
                return;
            }
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
                if (crnProtocol.getBay() == 1 && crnProtocol.getLevel() == 1) {
                    continue;
                }
            //输送线没有入库任务,过滤2
            if (wrkMastMapper.selectDevWorking(crnProtocol.getCrnNo()) == null) {
                return;
                if (System.currentTimeMillis() - crnProtocol.getLastCommandTime() < 1000 * 60 * 2) {
                    continue;
                }
                Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK);
                if (object != null) {
                    continue;
                }
                List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                        .eq("crn_no", crn.getId())
                        .notIn("wrk_sts", 5, 14, 15)
                );
                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", 60);
                try {
                    Thread.sleep(500);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            News.info("堆垛机召回原点==>>" + crnProtocol.getCrnNo() + "号堆垛机有入库任务,召回原点");
            // 命令下发区 --------------------------------------------------------------------------
            CrnCommand crnCommand = new CrnCommand();
            crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 堆垛机编号
            crnCommand.setTaskNo((short) 9999); // 工作号
            crnCommand.setAckFinish((short) 0);  // 任务完成确认位
            crnCommand.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式:  回原点
            crnCommand.setSourcePosX((short) 0);     // 源库位排
            crnCommand.setSourcePosY((short) 0);     // 源库位列
            crnCommand.setSourcePosZ((short) 0);     // 源库位层
            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);
        }
//        }
    }
    /**
     * 堆垛机有入库任务时,回入库口待机
     */
    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);
                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", 60);
                try {
                    Thread.sleep(500);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    /**
     * 入库  ===>>  堆垛机站到库位
     */
    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();
@@ -697,7 +945,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()
@@ -705,27 +953,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;
            }
@@ -745,37 +993,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);
@@ -790,17 +1044,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();
@@ -815,7 +1069,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();
@@ -836,19 +1090,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());
@@ -859,20 +1134,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 {
@@ -891,6 +1166,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) {
@@ -901,13 +1199,29 @@
                // 查询站点详细信息
                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 && staProtocol.isOutEnable()) {
                        && staProtocol.getWorkNo() == 0) {
                    //根据参数判断是否校验可出信号
                    String crnOutVerifyOut = "Y";
                    Config crnOutVerifyOutEnableConfig = configService.selectOne(new EntityWrapper<Config>()
                            .eq("code", "crnOutVerifyOutEnable"));
                    if (crnOutVerifyOutEnableConfig != null) {
                        crnOutVerifyOut = crnOutVerifyOutEnableConfig.getValue();
                    }
                    if (crnOutVerifyOut.equals("Y")) {
                        if (!staProtocol.isOutEnable()) {
                            continue;
                        }
                    }
                    // 命令下发区 --------------------------------------------------------------------------
                    // 堆垛机控制过滤
@@ -918,7 +1232,7 @@
                    if (crnProtocol.getCrnNo() == 1) {
                        //判断堆垛机和当前任务是否处于一个巷道
                        if (Utils.getLaneByLocNo(wrkMast.getLocNo()) != crnProtocol.getCrnLane()) {
                        if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) {
                            //判断堆垛机所在巷道是否存在其他任务,如存在则优先执行
                            List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
                            if (!currentWrkMasts.isEmpty()) {
@@ -929,12 +1243,12 @@
                    // 双深库位且浅库位有货,则需先对浅库位进行库位移转
                    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);
@@ -943,7 +1257,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 {
@@ -951,7 +1265,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);
@@ -959,7 +1273,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);
@@ -972,10 +1286,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;
                            }
                        }
@@ -987,9 +1301,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();
@@ -1004,7 +1318,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();
@@ -1012,14 +1326,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" + " - 堆垛机入出库作业下发 : 出库执行完毕");
    }
//    /**
@@ -1142,17 +1456,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;
        }
        // 源库位  库位状态判断
@@ -1162,7 +1476,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;
        }
        // 获取堆垛机信息 并 判断是否可入出
@@ -1181,9 +1495,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();
@@ -1198,7 +1512,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();
@@ -1206,36 +1520,36 @@
            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" + " - 堆垛机入出库作业下发:库位移转完成");
    }
    /**
     * 库位移转
     */
    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) {
@@ -1244,7 +1558,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;
            }
        }
@@ -1264,9 +1578,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();
@@ -1281,7 +1595,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();
@@ -1289,10 +1603,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" + " - 堆垛机入出库作业下发:库位移转完成");
    }
@@ -1309,7 +1623,7 @@
            }
            //  状态:等待确认 并且  任务完成位 = 1
            if (crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) {
                News.warnNoLog(""+mark+" - 0"+" - 开始执行对工作档的完成操作");
                News.warnNoLog("" + mark + " - 0" + " - 开始执行对工作档的完成操作");
                if (crnProtocol.getTaskNo() == 9999) {
                    // 堆垛机复位
                    crnThread.setResetFlag(true);
@@ -1317,11 +1631,11 @@
                    // 获取入库待确认工作档
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue());
                    if (wrkMast == null) {
                        News.error(""+mark+" - 1"+" - 堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo());
                        News.error("" + mark + " - 1" + " - 堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo());
                        continue;
                    }
                    // 入库 + 库位转移  ==> 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;
@@ -1332,14 +1646,14 @@
                    // 修改成功后复位堆垛机
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        // 堆垛机复位
                        News.warnNoLog(""+mark+" - 2"+" - 修改成功后复位堆垛机 : 堆垛机号={}",crnThread.getCrnProtocol().getCrnNo());
                        News.warnNoLog("" + mark + " - 2" + " - 修改成功后复位堆垛机 : 堆垛机号={}", crnThread.getCrnProtocol().getCrnNo());
                        crnThread.setResetFlag(true);
                    }
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 对工作档的完成操作执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 对工作档的完成操作执行完成");
    }
    /**
@@ -1362,7 +1676,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) {
@@ -1394,7 +1708,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 {
@@ -1404,7 +1718,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());
                            }
                        }
                    }
@@ -1413,7 +1727,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());
@@ -1442,7 +1756,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);
                            }
                        }
                        // 无异常
@@ -1453,7 +1767,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());
                            }
                        }
                    }
@@ -1461,7 +1775,7 @@
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 堆垛机异常信息记录执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 堆垛机异常信息记录执行完成");
    }
@@ -1485,11 +1799,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;
                }
@@ -1498,8 +1818,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);
@@ -1508,6 +1852,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")
@@ -1524,55 +1869,137 @@
                            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(1007);
                    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);
                    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" + " - 空栈板初始化入库,叉车入库站放货执行完成");
    }
    /**
@@ -1601,7 +2028,7 @@
                if (null == wrkMast) {
                    continue;
                }
                News.warnNoLog(""+mark+" - 0"+" - 开始执行:出库  ===>> 工作档信息写入led显示器");
                News.warnNoLog("" + mark + " - 0" + " - 开始执行:出库  ===>> 工作档信息写入led显示器");
                wrkMasts.add(wrkMast);
                // 组装命令
                LedCommand ledCommand = new LedCommand();
@@ -1641,12 +2068,13 @@
                        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());
                ledCommand.setLocNo(wrkMast.getLocNo());
                ledCommand.setStaNo(wrkMast.getStaNo());
                ledCommand.setBarcode(wrkMast.getBarcode());
//                ledCommand.setSourceStaNo(wrkMast.getSourceStaNo());
                if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) {
                    List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
@@ -1664,7 +2092,22 @@
//                    }catch (Exception e){
//                        log.error("工作档案明细输入电视机失败1:异常信息==》"+e);
//                    }
                    wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(),wrkDetl.getWeight(),wrkDetl.getSpecs(),wrkDetl.getSku())));
                    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);
            }
@@ -1699,7 +2142,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);
                }
            }
@@ -1710,7 +2153,7 @@
                    wrkMast.setOveMk("Y");
                    wrkMast.setModiTime(new Date());
                    if (wrkMastMapper.updateById(wrkMast) == 0) {
                        News.errorNoLog(""+mark+" - 4"+" - 更新工作档失败");
                        News.errorNoLog("" + mark + " - 4" + " - 更新工作档失败");
                        throw new CoolException("更新工作档失败");
                    }
                }
@@ -1724,7 +2167,7 @@
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 出库  ===>> 工作档信息写入led显示器执行完成");
        News.infoNoLog("" + mark + " - 0" + " - 出库  ===>> 工作档信息写入led显示器执行完成");
    }
    /**
@@ -1732,7 +2175,7 @@
     */
    public synchronized void ledReset(Integer mark) {
        News.warnNoLog(""+mark+" - 0"+" - 开始执行:其他  ===>> LED显示器复位,显示默认信息");
        News.warnNoLog("" + mark + " - 0" + " - 开始执行:其他  ===>> LED显示器复位,显示默认信息");
        for (LedSlave led : slaveProperties.getLed()) {
            // 获取输送线plc线程
@@ -1756,13 +2199,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显示器复位,显示默认信息");
    }
    /**
@@ -1804,10 +2247,11 @@
            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", shallowLoc.getLocNo()));
            for (LocDetl locDetl : locDetls) {
                WrkDetl wrkDetl = new WrkDetl();
                wrkDetl.sync(locDetl);
                wrkDetl.setWrkNo(workNo);
                wrkDetl.setIoTime(now);
                wrkDetl.setAnfme(locDetl.getAnfme());
                VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
//                VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
                wrkDetl.setAppeTime(now);
                wrkDetl.setModiTime(now);
                if (!wrkDetlService.insert(wrkDetl)) {
@@ -1845,10 +2289,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) {
@@ -1890,7 +2334,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 {
@@ -1918,7 +2362,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;
                    }
@@ -1928,14 +2372,15 @@
                        for (LocDetl locDetl : locDetls) {
                            WrkDetl wrkDetl = new WrkDetl();
                            wrkDetl.sync(locDetl);
                            wrkDetl.setWrkNo(workNo);
                            wrkDetl.setIoTime(new Date());
                            wrkDetl.setAnfme(locDetl.getAnfme());
                            VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
//                            VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
                            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;
                            }
@@ -1946,12 +2391,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;
                    }
@@ -1960,23 +2405,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();
        }
@@ -2010,6 +2455,11 @@
                    LocMast sourceLoc = locMastService.queryDemoSourceLoc(crn.getId());
                    LocMast loc = locMastService.queryDemoLoc(crn.getId());
                    if (null == sourceLoc || null == loc) {
                        continue;
                    }
                    Integer ctnType = 1;
                    if (ctnType.equals(loc.getCtnType())) {
                        continue;
                    }
@@ -2067,6 +2517,7 @@
                    // 修改目标库位状态
                    if (loc.getLocSts().equals("O")) {
                        loc.setLocSts("S"); // S.入库预约
                        loc.setCtnType(1);
                        loc.setModiTime(new Date());
                        if (!locMastService.updateById(loc)) {
                            throw new CoolException("更新目标库位状态失败");
@@ -2136,16 +2587,22 @@
    // RGV  ===>> 执行对RGV操作
    public synchronized void rgvExecute(Integer mark) {
        ArrayList<Integer> list = new ArrayList<Integer>(){{add(1090);add(1091);}};
        ArrayList<Integer> list = new ArrayList<Integer>() {{
            add(2003);
            add(2002);
        }};
        for (Integer staNo : list) {
            Integer devpId = null;
            Integer rgvStaNoDevpId = null;
            Integer rgvStaNo = null;
            if (staNo == 1090) {
            if (staNo == 2003) {
                devpId = 1;
                rgvStaNo = 1091;
            }else {
                rgvStaNo = 2002;
                rgvStaNoDevpId = 2;
            } else {
                devpId = 2;
                rgvStaNo = 1090;
                rgvStaNo = 2003;
                rgvStaNoDevpId = 1;
            }
            SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devpId);
@@ -2166,7 +2623,49 @@
            ) {
                WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
                        .eq("wrk_no", staProtocol.getWorkNo()));
                if (wrkMast == null) {
                    continue;
                }
                if (wrkMast.getWrkSts() == 201) {
                    continue;
                }
                SiemensDevpThread devpThread2 = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, rgvStaNoDevpId);
                if (devpThread2 == null) {
                    continue;
                }
                StaProtocol staProtocolRgvStaNo = devpThread2.getStation().get(rgvStaNo);
                if (staProtocolRgvStaNo == null) {
                    continue;
                }
                if (!staProtocolRgvStaNo.isAutoing()) {
                    continue;
                }
                if (staProtocolRgvStaNo.isLoading()) {
                    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;
                }
@@ -2187,6 +2686,7 @@
                wrkMast.setWrkSts(201L);//201.RGV搬运中
                wrkMast.setModiTime(new Date());
                wrkMastService.updateById(wrkMast);
                redisUtil.set(RedisConstantType.RGV_MOVE_LOCK + wrkMast.getWrkNo(), "lock", 60 * 60);
            }
        }
    }
@@ -2206,34 +2706,39 @@
            }
            //  状态:等待确认 并且  任务完成位 = 1
            if (rgvProtocol.statusType == RgvStatusType.WAITING && rgvProtocol.getTaskNo1() != 0) {
                News.warnNoLog(""+mark+" - 0"+" - 开始执行对RGV工作档的完成操作");
            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());
                    News.error("" + mark + " - 1" + " - RGV处于等待确认且任务完成状态,但未找到工作档。RGV号={},工作号={}", rgvSlave.getId(), rgvProtocol.getTaskNo1());
                    continue;
                }
                if (Cools.isEmpty(wrkMast.getMemo())) {
                    News.error(""+mark+" - 1"+" - RGV处于等待确认且任务完成状态,但工作档数据异常。RGV号={},工作号={}", rgvSlave.getId(), rgvProtocol.getTaskNo1());
                if (wrkMast.getWrkSts() != 201) {
                    continue;
                }
                if (wrkMast.getIoType() == 3) {
                    //站到站走另外一个方法
                    continue;
                }
                Integer devpId = null;
                Integer devpStaNo = null;
                String locNo = null;
                Long updateWrkSts = null;
                if (wrkMast.getIoType() < 100) {
                    //入库
                    wrkMast.setWrkSts(2L);
                    updateWrkSts = 2L;
                    devpId = 1;
                    devpStaNo = 1090;
                    devpStaNo = 2003;
                    locNo = wrkMast.getLocNo();
                }else {
                } else {
                    //出库
                    wrkMast.setWrkSts(15L);
                    updateWrkSts = 15L;
                    devpId = 2;
                    devpStaNo = 1091;
                    devpStaNo = 2002;
                    locNo = wrkMast.getSourceLocNo();
                }
@@ -2260,14 +2765,92 @@
                    if (!result) {
                        throw new CoolException("更新plc站点信息失败");
                    }
                    Date now = new Date();
                    wrkMast.setModiTime(now);
                    wrkMastMapper.updateById(wrkMast);
                    wrkMastMapper.updateWrkSts(updateWrkSts, wrkMast.getWrkNo());
                    rgvThread.setResetFlag1(true);
                }
            }
        }
        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" + " - 对工作档的完成操作执行完成");
    }
//    /**