自动化立体仓库 - WCS系统
#
whycq
2023-05-21 a6297bcc875d6486ab2bb1453f571d0813593ccd
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -21,6 +21,7 @@
import com.zy.common.service.CommonService;
import com.zy.common.utils.CollectionUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.News;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
@@ -105,12 +106,26 @@
                    continue;
                }
                String barcode = barcodeThread.getBarcode();
                ////判断101和104是否是拣料、并板、盘点再入库
                //WrkMast wrkMast1=wrkMastMapper.selectpj(inSta.getStaNo(),barcode);
                //if((inSta.getStaNo().equals(101) || inSta.getStaNo().equals(104)) &&!Cools.isEmpty(barcode)&&!Cools.isEmpty(wrkMast1)){
                //    log.error("101或104拣料、并板、盘点再入库", wrkMast1.getWrkNo());
                //    continue;
                //}
                if (!Cools.isEmpty(barcode)) {
                    log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
                    if ("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
                        continue;
                    }
                } else {
                    // led 异常显示
//                    LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
//                    if (ledThread != null) {
//                        String errorMsg = "扫码失败,请重试";
//                        MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
//                    }
                    continue;
                }
@@ -130,66 +145,51 @@
                if (inSta.getStaNo() == 104 && devpThread.ioModeOf1F2 == IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 111 && devpThread.ioModeOf1F3 == IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 114 && devpThread.ioModeOf1F4 == IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 201 && devpThread.ioModeOf2F1 == IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 204 && devpThread.ioModeOf2F2 == IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 301 && devpThread.ioModeOf3F1 == IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 304 && devpThread.ioModeOf3F2 == IoModeType.PAKOUT_MODE) {
                    continue;
                }
                // 判断是否满足入库条件
                if (staProtocol.isAutoing() && staProtocol.isLoading()
                if (staProtocol.isAutoing()
                        && staProtocol.isLoading()
                        && staProtocol.isInEnable()
                        && !staProtocol.isEmptyMk() && (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() > 9990)
                        && staProtocol.isPakMk()) {// && !Cools.isEmpty(barcode)) {
                        && !staProtocol.isEmptyMk()
                        && (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() > 9990)
                        && staProtocol.isPakMk()) {
//                    if(Cools.isEmpty(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode)) {
//                        log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
//                        //条码为空或者不符合,退库到172站点
//                        staProtocol.setWorkNo((short)9999);
//                        staProtocol.setStaNo((short)172);
//                        devpThread.setPakMk(staProtocol.getSiteId(), false);
//                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
//                        if (!result) {
//                            throw new CoolException("更新plc站点信息失败");
//                        }
//                        continue;
//                    }
                    // 判断重复工作档
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
                    if (wrkMast != null) {
                        log.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast.getWrkNo());
                    if(Cools.isEmpty(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode)) {
                        log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
                        //条码为空或者不符合,退库到
                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                        if (ledThread != null) {
                            String errorMsg = "扫码失败,请重试";
                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                        }
                        staProtocol.setWorkNo((short)9999);
                        staProtocol.setStaNo((short)(staProtocol.getStaNo()-1));
                        devpThread.setPakMk(staProtocol.getSiteId(), false);
                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        if (!result) {
                            throw new CoolException("更新plc站点信息失败");
                        }
                        continue;
                    }
//                    // 获取入库通知档
//                    List<WaitPakin> waitPakins = waitPakinMapper.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("io_status", "N"));
//                    if (waitPakins.isEmpty()) {
//                        log.error("无此入库条码数据。条码号={}", barcode);
//                        continue;
//                    }
                    // 判断重复工作档
                    WrkMast wrkMast = new WrkMast();
                    if (barcode.length() == 8) {
                        wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
                        if (wrkMast != null) {
                            log.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast.getWrkNo());
                            continue;
                        }
                    }
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
                        SearchLocParam param = new SearchLocParam();
                        param.setBarcode(barcode);
                        param.setIoType(1);
                        param.setSourceStaNo(inSta.getStaNo());
                        param.setLocType1(locTypeDto.getLocType1());
                        param.setFull(staProtocol.isFull());
                        String response = new HttpHandler.Builder()
                                .setUri(wmsUrl)
                                .setPath("/rpc/pakin/loc/v1")
@@ -197,6 +197,7 @@
                                .build()
                                .doPost();
                        JSONObject jsonObject = JSON.parseObject(response);
                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                        if (jsonObject.getInteger("code").equals(200)) {
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
@@ -204,6 +205,7 @@
                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                            staProtocol.setStaNo(dto.getStaNo().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            ledThread.errorReset();
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
                                throw new CoolException("更新plc站点信息失败");
@@ -308,24 +310,6 @@
                if (inSta.getStaNo() == 104 && devpThread.ioModeOf1F2 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 111 && devpThread.ioModeOf1F3 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 114 && devpThread.ioModeOf1F4 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 201 && devpThread.ioModeOf2F1 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 204 && devpThread.ioModeOf2F2 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 301 && devpThread.ioModeOf3F1 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (inSta.getStaNo() == 304 && devpThread.ioModeOf3F2 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                // 判断是否满足入库条件
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable()
@@ -370,20 +354,19 @@
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历拣料入库口
            for (DevpSlave.Sta pickSta : devp.getPickSta()) {
//                // 获取条码扫描仪信息
//                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
//                if (barcodeThread == null) {
//                    continue;
//                }
//                String barcode = barcodeThread.getBarcode();
//                if(!Cools.isEmpty(barcode)) {
//                    log.info("{}号条码扫描器检测条码信息:{}", 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)) {
                    log.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode);
                    if ("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
                        continue;
                    }
                }
                // 获取拣料入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
@@ -394,12 +377,36 @@
                    staProtocol = staProtocol.clone();
                }
//                // 入出库模式判断
//                if (devpThread.ioMode != IoModeType.PAKIN_MODE) { continue; }
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isPakMk()) {
                if (staProtocol.isAutoing()
                        && staProtocol.isLoading()
                        && staProtocol.isInEnable()
                        && staProtocol.isPakMk()
                        && staProtocol.getWorkNo() == 9991) {
//                    WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
                    LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
                    if (barcode.equals("") || barcode.equals("99999999")) {
                        Integer led = pickSta.getLed();
                        if (ledThread != null) {
                            String errorMsg = "扫码异常,请重新入库!";
                            MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg));
                        }
//                        // 更新站点信息 且 下发plc命令
                        staProtocol.setWorkNo((short)9999);
                        staProtocol.setStaNo((short)(staProtocol.getStaNo()-1));
                        devpThread.setPakMk(staProtocol.getSiteId(), false);
                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        if (!result) {
                            log.error("发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
                        }
                        continue;
                    }
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep3(staProtocol.getWorkNo().intValue());
                    ledThread.errorReset();
                    if (wrkMast == null) {
                        wrkMast = wrkMastMapper.selectPickStep(barcode);
                    }
                    if (wrkMast == null) {
                        // 无拣料数据
                        continue;
@@ -408,16 +415,8 @@
                            || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
                        continue;
                    }
                    ledThread.errorReset();
                    // 拣、盘、并 作业站转换
//                    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)
@@ -446,7 +445,19 @@
                        wrkMast.setIoTime(now);
                        wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54,107->57
                        wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
                        wrkMast.setSourceStaNo(wrkMast.getStaNo()); // 源站
                        Integer sourceStaNo = 0;
                        switch (wrkMast.getStaNo()){
                            case 100:
                                sourceStaNo = 101;
                                break;
                            case 103:
                                sourceStaNo = 104;
                                break;
                        }
                        wrkMast.setSourceStaNo(sourceStaNo); // 源站
//                        wrkMast.setSourceStaNo(wrkMast.getStaNo()); // 源站
                        wrkMast.setStaNo(staNo); // 目标站
                        wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 目标库位 = 出库时的源库位
                        wrkMast.setSourceLocNo(""); // 源库位清空
@@ -649,6 +660,7 @@
            crnCommand.setDestinationPosX((short) 0);     // 目标库位排
            crnCommand.setDestinationPosY((short) 0);     // 目标库位列
            crnCommand.setDestinationPosZ((short) 0);     // 目标库位层
            crnCommand.setLocType1((short) 0);     // 货物类型
            if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) {
                log.error("堆垛机回原点命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
            }
@@ -761,6 +773,7 @@
            crnCommand.setDestinationPosX(locMast.getRow1().shortValue());     // 目标库位排
            crnCommand.setDestinationPosY(locMast.getBay1().shortValue());     // 目标库位列
            crnCommand.setDestinationPosZ(locMast.getLev1().shortValue());     // 目标库位层
            crnCommand.setLocType1(locMast.getLocType1().shortValue());     // 货物类型
            if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
                log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
            } else {
@@ -798,6 +811,11 @@
            // 获取工作状态为11(生成出库ID)的出库工作档
//            WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId(), crnStn.getStaNo());
            List<WrkMast> wrkMasts = wrkMastMapper.selectPakOutStep11(slave.getId(), crnStn.getStaNo());
            //            获取工作状态为14的工作档
            WrkMast wrkMast1 = wrkMastMapper.selectPakOutStep14(slave.getId(), crnStn.getStaNo());
            if ( wrkMast1 !=null) {
                continue;
            }
            for (WrkMast wrkMast : wrkMasts) {
                if (wrkMast == null) {
                    continue;
@@ -808,9 +826,9 @@
                    continue;
                }
                // 获取源库位信息
                LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
                if (!sourceSta.getLocSts().equals("R") && !sourceSta.getLocSts().equals("P")) {
                    log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), sourceSta.getLocSts());
                LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());
                if (!locMast.getLocSts().equals("R") && !locMast.getLocSts().equals("P")) {
                    log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), locMast.getLocSts());
                    continue;
                }
                // 获取堆垛机出库站信息
@@ -828,24 +846,6 @@
                    continue;
                }
                if (wrkMast.getStaNo() == 103 && devpThread.ioModeOf1F2 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (wrkMast.getStaNo() == 110 && devpThread.ioModeOf1F3 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (wrkMast.getStaNo() == 113 && devpThread.ioModeOf1F4 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (wrkMast.getStaNo() == 200 && devpThread.ioModeOf2F1 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (wrkMast.getStaNo() == 203 && devpThread.ioModeOf2F2 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (wrkMast.getStaNo() == 300 && devpThread.ioModeOf3F1 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
                if (wrkMast.getStaNo() == 303 && devpThread.ioModeOf3F2 != IoModeType.PAKOUT_MODE) {
                    continue;
                }
@@ -905,7 +905,7 @@
                            continue;
                        } else if (shallowLoc.getLocSts().equals("Q") || shallowLoc.getLocSts().equals("S")) {
                            WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                            if (null != waitWrkMast && waitWrkMast.getWrkSts() == 4) {
                            if (null != waitWrkMast && (waitWrkMast.getWrkSts() == 4 || waitWrkMast.getWrkSts() == 5)) {
                                continue;
                            }
                        }
@@ -923,12 +923,13 @@
                    crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
                    crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                    crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
                    crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 源库位排
                    crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 源库位列
                    crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue());     // 源库位层
                    crnCommand.setSourcePosX(locMast.getRow1().shortValue());     // 源库位排
                    crnCommand.setSourcePosY(locMast.getBay1().shortValue());     // 源库位列
                    crnCommand.setSourcePosZ(locMast.getLev1().shortValue());     // 源库位层
                    crnCommand.setDestinationPosX(crnStn.getRow().shortValue());     // 目标库位排
                    crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列
                    crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层
                    crnCommand.setLocType1(locMast.getLocType1().shortValue());     // 货物类型
                    if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
                        log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
                    } else {
@@ -1048,6 +1049,7 @@
//                crnCommand.setDestinationPosX(crnStn.getRow().shortValue());     // 目标库位排
//                crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列
//                crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层
//                crnCommand.setLocType1(locMast.getLocType1().shortValue());     // 货物类型
//                if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
//                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
//                } else {
@@ -1074,18 +1076,18 @@
            return;
        }
        // 获取源库位信息
        LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
        if (null == sourceSta) {
        LocMast sourceLocMast = locMastService.selectById(wrkMast.getSourceLocNo());
        if (null == sourceLocMast) {
            log.error("工作档库位移转失败,原因:检索源库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
            return;
        }
        // 源库位  库位状态判断
        if (!sourceSta.getLocSts().equals("R") && !sourceSta.getLocSts().equals("S")) {
        if (!sourceLocMast.getLocSts().equals("R") && !sourceLocMast.getLocSts().equals("S")) {
            return;
        }
        // 获取目标库位信息
        LocMast sta = locMastService.selectById(wrkMast.getLocNo());
        if (null == sta) {
        LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
        if (null == locMast) {
            log.error("工作档库位移转失败,原因:检索目标库位失败!工作号={},源库位={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
            return;
        }
@@ -1111,12 +1113,13 @@
        crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
        crnCommand.setAckFinish((short) 0);  // 任务完成确认位
        crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
        crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 源库位排
        crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 源库位列
        crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue());     // 源库位层
        crnCommand.setDestinationPosX(sta.getRow1().shortValue());     // 目标库位排
        crnCommand.setDestinationPosY(sta.getBay1().shortValue());     // 目标库位列
        crnCommand.setDestinationPosZ(sta.getLev1().shortValue());     // 目标库位层
        crnCommand.setSourcePosX(sourceLocMast.getRow1().shortValue());     // 源库位排
        crnCommand.setSourcePosY(sourceLocMast.getBay1().shortValue());     // 源库位列
        crnCommand.setSourcePosZ(sourceLocMast.getLev1().shortValue());     // 源库位层
        crnCommand.setDestinationPosX(locMast.getRow1().shortValue());     // 目标库位排
        crnCommand.setDestinationPosY(locMast.getBay1().shortValue());     // 目标库位列
        crnCommand.setDestinationPosZ(locMast.getLev1().shortValue());     // 目标库位层
        crnCommand.setLocType1(locMast.getLocType1().shortValue());     // 货物类型
        if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
            log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
        } else {
@@ -1302,7 +1305,7 @@
    public synchronized void storeEmptyPlt() {
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历空板入库口
            for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) {
             for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) {
                // 获取空板入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(emptyInSta.getStaNo());
@@ -1314,8 +1317,8 @@
                // 站点条件判断
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable()
                        && staProtocol.isEmptyMk() && (staProtocol.getWorkNo() > 9990 && staProtocol.getWorkNo() <= 9999) && staProtocol.isPakMk()) {
                        && staProtocol.isEmptyMk() && (staProtocol.getWorkNo() >= 9990
                        && staProtocol.getWorkNo() <= 9999) && staProtocol.isPakMk()) {
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
@@ -1431,10 +1434,7 @@
                }
                // 获取工作档数据
                WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
//                if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; }
                if (null == wrkMast) {
                    continue;
                }
                if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; }
                wrkMasts.add(wrkMast);
                // 组装命令
                LedCommand ledCommand = new LedCommand();
@@ -1442,12 +1442,6 @@
                ledCommand.setIoType(wrkMast.getIoType());
                // 出库模式
                switch (wrkMast.getIoType()) {
                    case 1:
                        ledCommand.setTitle("全板入库");
                        break;
                    case 10:
                        ledCommand.setTitle("空板入库");
                        break;
                    case 101:
                        ledCommand.setTitle("全板出库");
                        break;
@@ -1465,16 +1459,25 @@
                        ledCommand.setEmptyMk(true);
                        break;
                    default:
                        log.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
                        News.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
                        break;
                }
                ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
                ledCommand.setLocNo(wrkMast.getLocNo());
                ledCommand.setStaNo(wrkMast.getStaNo());
//                ledCommand.setSourceStaNo(wrkMast.getSourceStaNo());
                if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) {
                ledCommand.setBarcode(wrkMast.getBarcode());
                if (wrkMast.getIoType() != 110) {
                    List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
                    wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme())));
                    wrkDetls.forEach(wrkDetl -> {
                        if (wrkMast.getIoType() == 101) {
                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme()));
                        }
                        if (wrkMast.getIoType() == 103 && (null == wrkDetl.getInspect() || 0 == wrkDetl.getInspect())) {
                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(),  wrkDetl.getAnfme()));
                        }
                        if (wrkMast.getIoType() == 107) {
                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme()));
                        }
                    });
                }
                commands.add(ledCommand);
            }
@@ -1487,22 +1490,10 @@
            }
            // 命令下发 -------------------------------------------------------------------------------
            if (!commands.isEmpty()) {
                if (led.getId() == 7) {
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
                        log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                        continue;
                    } else {
                        ledThread.setLedMk(false);
                    }
                } else {
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
                        log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                        continue;
                    } else {
                        ledThread.setLedMk(false);
                    }
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
                    News.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    continue;
                }
            }
            try {
@@ -1530,33 +1521,6 @@
     * 其他  ===>> LED显示器复位,显示默认信息
     */
    public synchronized void ledReset() {
//        for (LedSlave led : slaveProperties.getLed()) {
//            // 获取输送线plc线程
//            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
//            // 命令集合
//            boolean reset = true;
//            for (Integer staNo : led.getStaArr()) {
//                // 获取叉车站点
//                StaProtocol staProtocol = devpThread.getStation().get(staNo);
//                if (staProtocol == null) {
//                    continue;
//                } else {
//                    staProtocol = staProtocol.clone();
//                }
//                if (staProtocol.getWorkNo() != 0) {
//                    reset = false;
//                    break;
//                }
//            }
//            // 获取led线程
//            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getDevpPlcId());
//            // led显示默认内容
//            if (reset) {
//                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
//                    log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
//                }
//            }
//        }
        for (LedSlave led : slaveProperties.getLed()) {
            // 获取输送线plc线程
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
@@ -1565,32 +1529,18 @@
            for (Integer staNo : led.getStaArr()) {
                // 获取叉车站点
                StaProtocol staProtocol = devpThread.getStation().get(staNo);
                if (staProtocol == null) {
                    continue;
                }
                if (staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) {
                if (staProtocol == null) { continue; }
                if (staProtocol.getWorkNo() != 0) {
                    reset = false;
                    break;
                }
            }
            // 获取led线程
            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getDevpPlcId());
            // led显示默认内容
            if (reset && !ledThread.isLedMk()) {
                if (led.getId() == 7) {
                    ledThread.setLedMk(true);
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
                        log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    } else {
                    }
                } else {
                    ledThread.setLedMk(true);
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
                        log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    } else {
                    }
            if (reset) {
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
                    News.error("{}号LED命令下发失败1565!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                }
            }
        }
@@ -1815,8 +1765,11 @@
                    }
                    LocMast sourceLoc = locMastService.queryDemoSourceLoc(crn.getId());
                    LocMast loc = locMastService.queryDemoLoc(crn.getId());
                    if (null == sourceLoc || null == loc) {
                    if (null == sourceLoc ) {
                        continue;
                    }
                    LocMast loc = locMastService.queryDemoLoc0(crn.getId(),sourceLoc.getLocType1());
                    if ( null == loc) {
                        continue;
                    }
@@ -1874,6 +1827,111 @@
                    // 修改目标库位状态
                    if (loc.getLocSts().equals("O")) {
                        loc.setLocSts("S"); // S.入库预约
                        loc.setModiTime(new Date());
                        if (!locMastService.updateById(loc)) {
                            throw new CoolException("更新目标库位状态失败");
                        }
                    } else {
                        throw new CoolException("移转失败");
                    }
                }
            }
        } catch (Exception e) {
            log.error("堆垛机演示  ===>> 库位移转失败", e);
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }
    /**
     * 堆垛机演示  ===>> 所有库位轮询
     */
    public synchronized void crnDemoOfLocMove2() {
        try {
            for (CrnSlave crn : slaveProperties.getCrn()) {
                if (!crn.getDemo()) {
                    continue;
                }   // 必须为演示状态
                CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
                CrnProtocol crnProtocol = crnThread.getCrnProtocol();
                if (crnProtocol == null) {
                    continue;
                }
                // 只有当堆垛机空闲 并且 无任务时才继续执行
                if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
                    // 获取移库工作档信息
                    WrkMast wrkMast = wrkMastMapper.selectLocMove(crn.getId());
                    if (null != wrkMast) {
                        continue;
                    }
                    LocMast sourceLoc = locMastService.queryDemoSourceLoc1(crn.getId());
                    if (null == sourceLoc ) {
                        continue;
                    }
                    LocMast loc = locMastService.queryDemoLoc2(crn.getId(),sourceLoc.getLocType1());
                    if ( null == loc) {
                        continue;
                    }
                    String sourceLocNo = sourceLoc.getLocNo();
                    String locNo = loc.getLocNo();
                    // 获取工作号
                    int workNo = commonService.getWorkNo(0);
                    // 保存工作档
                    wrkMast = new WrkMast();
                    wrkMast.setWrkNo(workNo);
                    wrkMast.setIoTime(new Date());
                    wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
                    wrkMast.setIoType(11); // 入出库状态: 11.库格移载
                    wrkMast.setIoPri(13D);
                    wrkMast.setCrnNo(crn.getId());
                    wrkMast.setSourceLocNo(sourceLocNo); // 源库位
                    wrkMast.setLocNo(locNo); // 目标库位
                    wrkMast.setFullPlt("N"); // 满板:Y
                    wrkMast.setPicking("N"); // 拣料
                    wrkMast.setExitMk("N"); // 退出
                    wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D") ? "Y" : "N"); // 空板
                    wrkMast.setBarcode(sourceLoc.getBarcode()); // 托盘码
                    wrkMast.setLinkMis("N");
                    wrkMast.setAppeTime(new Date());
                    wrkMast.setModiTime(new Date());
                    int res = wrkMastMapper.insert(wrkMast);
                    if (res == 0) {
                        throw new CoolException("保存工作档失败");
                    }
                    // 工作档明细保存
//                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
//                for (LocDetl locDetl : locDetls) {
//                    WrkDetl wrkDetl = new WrkDetl();
//                    wrkDetl.setWrkNo(workNo);
//                    wrkDetl.setIoTime(new Date());
//                    wrkDetl.setAnfme(locDetl.getAnfme());
//                    VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
//                    wrkDetl.setAppeTime(new Date());
//                    wrkDetl.setModiTime(new Date());
//                    if (!wrkDetlService.insert(wrkDetl)) {
//                        throw new CoolException("保存工作档明细失败");
//                    }
//                }
                    // 修改源库位状态
                    if (sourceLoc.getLocSts().equals("D")) {
                        sourceLoc.setLocSts("R"); // R.出库预约
                        sourceLoc.setModiTime(new Date());
                        if (!locMastService.updateById(sourceLoc)) {
                            throw new CoolException("更新源库位状态失败");
                        }
                    } else {
                        throw new CoolException("源库位出库失败");
                    }
                    // 修改目标库位状态
                    if (loc.getLocSts().equals("O")) {
                        loc.setLocSts("S"); // S.入库预约
                        loc.setCtnKind(1);
                        loc.setModiTime(new Date());
                        if (!locMastService.updateById(loc)) {
                            throw new CoolException("更新目标库位状态失败");
@@ -1951,20 +2009,29 @@
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                for (DevpSlave.Sta inSta : devp.getInSta()) {
                    if (inSta.getStaNo() == 2) {
                        continue;
//                    if (inSta.getStaNo() == 2) {
//                        continue;
//                    }
                    Integer staNo = 0;
                    switch (inSta.getStaNo()){
                        case 101:
                            staNo = 102;
                            break;
                        case 104:
                            staNo = 105;
                            break;
                    }
                    WrkMast pakout = wrkMastMapper.selectWorkingPakout(inSta.getStaNo());
                    WrkMast pakout = wrkMastMapper.selectWorkingPakout(staNo);
                    switch (inSta.getStaNo()) {
                        case 102: // 1F1
                        case 101: // 1F1
                            if (pakout != null) {
                                if (devpThread.ioModeOf1F1 != IoModeType.PAKOUT_MODE) {
                                    // 出库切换中
                                    devpThread.ioModeOf1F1 = IoModeType.PAKOUT_BOOTING;
                                    WrkMast pakin = wrkMastMapper.selectWorkingPakin(inSta.getStaNo());
                                    if (pakin == null && !devpThread.getStation().get(inSta.getStaNo()).isLoading()
                                            && !devpThread.getStation().get(inSta.getStaNo() + 1).isLoading()
                                            && devpThread.getStation().get(inSta.getStaNo() + 1).getWorkNo() == 0) {
                                            && !devpThread.getStation().get(inSta.getStaNo() - 1).isLoading()
                                            && devpThread.getStation().get(inSta.getStaNo() - 1).getWorkNo() == 0) {
                                        // 出库模式
                                        devpThread.ioModeOf1F1 = IoModeType.PAKOUT_MODE;
                                    }
@@ -1974,15 +2041,15 @@
                                devpThread.ioModeOf1F1 = IoModeType.PAKIN_MODE;
                            }
                            break;
                        case 106: // 1F2
                        case 104: // 1F2
                            if (pakout != null) {
                                if (devpThread.ioModeOf1F2 != IoModeType.PAKOUT_MODE) {
                                    // 出库切换中
                                    devpThread.ioModeOf1F2 = IoModeType.PAKOUT_BOOTING;
                                    WrkMast pakin = wrkMastMapper.selectWorkingPakin(inSta.getStaNo());
                                    if (pakin == null && !devpThread.getStation().get(inSta.getStaNo()).isLoading()
                                            && !devpThread.getStation().get(inSta.getStaNo() + 1).isLoading()
                                            && devpThread.getStation().get(inSta.getStaNo() + 1).getWorkNo() == 0) {
                                            && !devpThread.getStation().get(inSta.getStaNo() - 1).isLoading()
                                            && devpThread.getStation().get(inSta.getStaNo() - 1).getWorkNo() == 0) {
                                        // 出库模式
                                        devpThread.ioModeOf1F2 = IoModeType.PAKOUT_MODE;
                                    }
@@ -1990,114 +2057,6 @@
                            } else {
                                // 入库模式
                                devpThread.ioModeOf1F2 = IoModeType.PAKIN_MODE;
                            }
                            break;
                        case 112: // 1F3
                            if (pakout != null) {
                                if (devpThread.ioModeOf1F3 != IoModeType.PAKOUT_MODE) {
                                    // 出库切换中
                                    devpThread.ioModeOf1F3 = IoModeType.PAKOUT_BOOTING;
                                    WrkMast pakin = wrkMastMapper.selectWorkingPakin(inSta.getStaNo());
                                    if (pakin == null && !devpThread.getStation().get(inSta.getStaNo()).isLoading()
                                            && !devpThread.getStation().get(inSta.getStaNo() + 1).isLoading()
                                            && devpThread.getStation().get(inSta.getStaNo() + 1).getWorkNo() == 0) {
                                        // 出库模式
                                        devpThread.ioModeOf1F3 = IoModeType.PAKOUT_MODE;
                                    }
                                }
                            } else {
                                // 入库模式
                                devpThread.ioModeOf1F3 = IoModeType.PAKIN_MODE;
                            }
                            break;
                        case 116: // 1F4
                            if (pakout != null) {
                                if (devpThread.ioModeOf1F4 != IoModeType.PAKOUT_MODE) {
                                    // 出库切换中
                                    devpThread.ioModeOf1F4 = IoModeType.PAKOUT_BOOTING;
                                    WrkMast pakin = wrkMastMapper.selectWorkingPakin(inSta.getStaNo());
                                    if (pakin == null && !devpThread.getStation().get(inSta.getStaNo()).isLoading()
                                            && !devpThread.getStation().get(inSta.getStaNo() + 1).isLoading()
                                            && devpThread.getStation().get(inSta.getStaNo() + 1).getWorkNo() == 0) {
                                        // 出库模式
                                        devpThread.ioModeOf1F4 = IoModeType.PAKOUT_MODE;
                                    }
                                }
                            } else {
                                // 入库模式
                                devpThread.ioModeOf1F4 = IoModeType.PAKIN_MODE;
                            }
                            break;
                        case 202: // 2F1
                            if (pakout != null) {
                                if (devpThread.ioModeOf2F1 != IoModeType.PAKOUT_MODE) {
                                    // 出库切换中
                                    devpThread.ioModeOf2F1 = IoModeType.PAKOUT_BOOTING;
                                    WrkMast pakin = wrkMastMapper.selectWorkingPakin(inSta.getStaNo());
                                    if (pakin == null && !devpThread.getStation().get(inSta.getStaNo()).isLoading()
                                            && !devpThread.getStation().get(inSta.getStaNo() + 1).isLoading()
                                            && devpThread.getStation().get(inSta.getStaNo() + 1).getWorkNo() == 0) {
                                        // 出库模式
                                        devpThread.ioModeOf2F1 = IoModeType.PAKOUT_MODE;
                                    }
                                }
                            } else {
                                // 入库模式
                                devpThread.ioModeOf2F1 = IoModeType.PAKIN_MODE;
                            }
                            break;
                        case 205: // 2F2
                            if (pakout != null) {
                                if (devpThread.ioModeOf2F2 != IoModeType.PAKOUT_MODE) {
                                    // 出库切换中
                                    devpThread.ioModeOf2F2 = IoModeType.PAKOUT_BOOTING;
                                    WrkMast pakin = wrkMastMapper.selectWorkingPakin(inSta.getStaNo());
                                    if (pakin == null && !devpThread.getStation().get(inSta.getStaNo()).isLoading()
                                            && !devpThread.getStation().get(inSta.getStaNo() + 1).isLoading()
                                            && devpThread.getStation().get(inSta.getStaNo() + 1).getWorkNo() == 0) {
                                        // 出库模式
                                        devpThread.ioModeOf2F2 = IoModeType.PAKOUT_MODE;
                                    }
                                }
                            } else {
                                // 入库模式
                                devpThread.ioModeOf2F2 = IoModeType.PAKIN_MODE;
                            }
                            break;
                        case 302: // 3F1
                            if (pakout != null) {
                                if (devpThread.ioModeOf3F1 != IoModeType.PAKOUT_MODE) {
                                    // 出库切换中
                                    devpThread.ioModeOf3F1 = IoModeType.PAKOUT_BOOTING;
                                    WrkMast pakin = wrkMastMapper.selectWorkingPakin(inSta.getStaNo());
                                    if (pakin == null && !devpThread.getStation().get(inSta.getStaNo()).isLoading()
                                            && !devpThread.getStation().get(inSta.getStaNo() + 1).isLoading()
                                            && devpThread.getStation().get(inSta.getStaNo() + 1).getWorkNo() == 0) {
                                        // 出库模式
                                        devpThread.ioModeOf3F1 = IoModeType.PAKOUT_MODE;
                                    }
                                }
                            } else {
                                // 入库模式
                                devpThread.ioModeOf3F1 = IoModeType.PAKIN_MODE;
                            }
                            break;
                        case 305: // 3F2
                            if (pakout != null) {
                                if (devpThread.ioModeOf3F2 != IoModeType.PAKOUT_MODE) {
                                    // 出库切换中
                                    devpThread.ioModeOf3F2 = IoModeType.PAKOUT_BOOTING;
                                    WrkMast pakin = wrkMastMapper.selectWorkingPakin(inSta.getStaNo());
                                    if (pakin == null && !devpThread.getStation().get(inSta.getStaNo()).isLoading()
                                            && !devpThread.getStation().get(inSta.getStaNo() + 1).isLoading()
                                            && devpThread.getStation().get(inSta.getStaNo() + 1).getWorkNo() == 0) {
                                        // 出库模式
                                        devpThread.ioModeOf3F2 = IoModeType.PAKOUT_MODE;
                                    }
                                }
                            } else {
                                // 入库模式
                                devpThread.ioModeOf3F2 = IoModeType.PAKIN_MODE;
                            }
                            break;
                    }