自动化立体仓库 - WCS系统
#
Junjie
2023-12-14 6336be7369c0fc18d7feed62cb0a33c51c517a90
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -1,7 +1,6 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
@@ -37,8 +36,6 @@
import java.util.*;
import java.util.stream.Collectors;
import static com.zy.asrs.utils.Utils.isJson;
/**
 * 立体仓库WCS系统主流程业务
@@ -106,13 +103,15 @@
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private WrkMastLocMapper wrkMastLocMapper;
    private WrkMastLogMapper wrkMastLogMapper;
    @Autowired
    private BasLiftOptService basLiftOptService;
    @Autowired
    private ConfigService configService;
    @Autowired
    private NavigateMapUtils navigateMapUtils;
    @Autowired
    private WrkDetlLogService wrkDetlLogService;
    /**
@@ -409,10 +408,6 @@
            for (DevpSlave devp : slaveProperties.getDevp()) {
                // 遍历拣料入库口
                for (DevpSlave.Sta pickSta : devp.getPickInSta()) {
                    if (pickSta.getStaNo() == 325 || pickSta.getStaNo() == 331 || pickSta.getStaNo() == 333 || pickSta.getStaNo() == 339) {
                        continue;
                    }
                    // 获取拣料入库站信息
                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
@@ -450,27 +445,27 @@
                            continue;
                        }
                        //*********************同库位组校验*********************
                        boolean flag = false;
                        String th = "";
                        List<String> innerLoc = Utils.getGroupInnerLoc(wrkMast.getSourceLocNo());
                        for (String loc : innerLoc) {
                            LocMast locMast = locMastService.selectById(loc);
                            if (locMast == null) {
                                continue;
                            }
                            if (!locMast.getLocSts().equals("F")) {
                                flag = true;
                                th = loc + "库位存在未回库任务";
                                break;
                            }
                        }
                        if (flag) {
                            News.info(th);
                            continue;
                        }
                        //*********************同库位组校验*********************
//                        //*********************同库位组校验*********************
//                        boolean flag = false;
//                        String th = "";
//                        List<String> innerLoc = Utils.getGroupInnerLoc(wrkMast.getSourceLocNo());
//                        for (String loc : innerLoc) {
//                            LocMast locMast = locMastService.selectById(loc);
//                            if (locMast == null) {
//                                continue;
//                            }
//
//                            if (!locMast.getLocSts().equals("F")) {
//                                flag = true;
//                                th = loc + "库位存在未回库任务";
//                                break;
//                            }
//                        }
//                        if (flag) {
//                            News.info(th);
//                            continue;
//                        }
//                        //*********************同库位组校验*********************
                        // 保存工作主档历史档
                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
@@ -478,35 +473,51 @@
                            continue;
                        }
                        String sourceLocNo = wrkMast.getSourceLocNo().trim();
                        LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(sourceLocNo));//获取回库提升机目标站
                        if (liftStaProtocol == null) {
                            continue;
                        }
                        try {
                            LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());//源库位
                            SearchLocParam param = new SearchLocParam();
                            param.setWrkNo(wrkMast.getWrkNo());
                            param.setBarcode(wrkMast.getBarcode());
                            param.setIoType(wrkMast.getIoType());
                            param.setSourceStaNo(pickSta.getStaNo());
                            param.setLocType1(locMast.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
                                    .setPath("/rpc/pakin/loc/v2")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
                            JSONObject jsonObject = JSON.parseObject(response);
                            Integer code = jsonObject.getInteger("code");
                            if (code.equals(200)) {
                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                        // 更新工作档数据状态
                        wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54,107->57
                        wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
                        wrkMast.setSourceStaNo(pickSta.getBackSta()); // 源站
//                            wrkMast.setStaNo(dto.getStaNo()); // 目标站
//                            wrkMast.setCrnNo(dto.getCrnNo());
                        wrkMast.setStaNo(liftStaProtocol.getStaNo());//目标站
                        wrkMast.setLocNo(sourceLocNo); // 目标库位 = 出库时的源库位
                        wrkMast.setShuttleNo(null); // 穿梭车清空
                        wrkMast.setLiftNo(null);// 提升机清空
                        wrkMast.setModiTime(new Date());
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            News.info(wrkMast.getWrkNo() + "更新工作档数据状态失败");
                            continue;
                        }
                                //获取回库提升机目标站
                                LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(dto.getLocNo()));
                                if (liftStaProtocol == null) {
                                    News.info(wrkMast.getWrkNo() + "获取回库提升机目标站失败");
                                    continue;
                                }
                        // 修改库位状态 Q.拣料/盘点/并板再入库
                        LocMast locMast = locMastService.selectById(sourceLocNo);
                        locMast.setLocSts("Q");
                        locMast.setModiTime(new Date());
                        if (!locMastService.updateById(locMast)) {
                            News.info("修改库位状态失败");
                            continue;
                                // 更新工作档数据状态
                                wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54
                                wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
                                wrkMast.setSourceStaNo(dto.getSourceStaNo()); // 源站
                                wrkMast.setStaNo(liftStaProtocol.getStaNo());//目标站
                                wrkMast.setLocNo(dto.getLocNo()); // 目标库位
                                wrkMast.setShuttleNo(null); // 穿梭车清空
                                wrkMast.setLiftNo(null);// 提升机清空
                                wrkMast.setModiTime(new Date());
                                if (wrkMastMapper.updateById(wrkMast) == 0) {
                                    News.info(wrkMast.getWrkNo() + "更新工作档数据状态失败");
                                    continue;
                                }
                            } else if (code == 500) {
                                News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        }
                    }
                }
@@ -525,11 +536,7 @@
        try {
            for (DevpSlave devp : slaveProperties.getDevp()) {
                // 遍历拣料入库口
                for (DevpSlave.Sta pickSta : devp.getPickInSta()) {
                    if (!(pickSta.getStaNo() == 325 || pickSta.getStaNo() == 331 || pickSta.getStaNo() == 333 || pickSta.getStaNo() == 339)) {
                        continue;
                    }
                for (DevpSlave.Sta pickSta : devp.getPickInSta2()) {
                    // 获取拣料入库站信息
                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
@@ -545,76 +552,16 @@
                            && staProtocol.isPakMk()) {
                        WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
                        if (wrkMast == null) {//找不到工作档
                        if (wrkMast == null) {
                            continue;
                        }
                        if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104)
                                || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
                            continue;
                        if (wrkMast.getSteNo() == null) {
                            wrkMast.setSteNo(1);
                            wrkMastMapper.updateById(wrkMast);
                            staProtocol.setStaNo((short) 341);//写入目标站
                            staProtocol.setPakMk(false);
                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        }
                        //*********************同库位组校验*********************
                        boolean flag = false;
                        String th = "";
                        List<String> innerLoc = Utils.getGroupInnerLoc(wrkMast.getSourceLocNo());
                        for (String loc : innerLoc) {
                            LocMast locMast = locMastService.selectById(loc);
                            if (locMast == null) {
                                continue;
                            }
                            if (!locMast.getLocSts().equals("F")) {
                                flag = true;
                                th = loc + "库位存在未回库任务";
                                break;
                            }
                        }
                        if (flag) {
                            News.info(th);
                            continue;
                        }
                        //*********************同库位组校验*********************
                        // 保存工作主档历史档
                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
                            News.info(wrkMast.getWrkNo() + "保存工作主档历史档失败");
                            continue;
                        }
                        String sourceLocNo = wrkMast.getSourceLocNo().trim();
                        LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(sourceLocNo));//获取回库提升机目标站
                        if (liftStaProtocol == null) {
                            continue;
                        }
                        // 更新工作档数据状态
                        wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54,107->57
                        wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
                        wrkMast.setSourceStaNo(pickSta.getBackSta()); // 源站
//                            wrkMast.setStaNo(dto.getStaNo()); // 目标站
//                            wrkMast.setCrnNo(dto.getCrnNo());
                        wrkMast.setStaNo(liftStaProtocol.getStaNo());//目标站
                        wrkMast.setLocNo(sourceLocNo); // 目标库位 = 出库时的源库位
                        wrkMast.setShuttleNo(null); // 穿梭车清空
                        wrkMast.setLiftNo(null);// 提升机清空
                        wrkMast.setModiTime(new Date());
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            News.info(wrkMast.getWrkNo() + "更新工作档数据状态失败");
                            continue;
                        }
                        // 修改库位状态 Q.拣料/盘点/并板再入库
                        LocMast locMast = locMastService.selectById(sourceLocNo);
                        locMast.setLocSts("Q");
                        locMast.setModiTime(new Date());
                        if (!locMastService.updateById(locMast)) {
                            News.info("修改库位状态失败");
                            continue;
                        }
                        staProtocol.setStaNo(pickSta.getBackSta().shortValue());//写入目标站
                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    }
                }
@@ -633,10 +580,6 @@
            for (DevpSlave devp : slaveProperties.getDevp()) {
                // 遍历拣料入库口
                for (DevpSlave.Sta pickSta : devp.getPickInSta()) {
//                if (pickSta.getStaNo() == 325 || pickSta.getStaNo() == 331 || pickSta.getStaNo() == 333 || pickSta.getStaNo() == 339) {
//                    continue;
//                }
                    // 获取拣料入库站信息
                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
@@ -648,10 +591,22 @@
                    if (staProtocol.isAutoing()
                            && staProtocol.isLoading()
                            && staProtocol.isInEnable()
                            && (staProtocol.getWorkNo() > 0)
//                            && (staProtocol.getWorkNo() > 0)
                            && staProtocol.isPakMk()) {
                        WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
                        // 获取条码扫描仪信息
                        BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
                        if (barcodeThread == null) {
                            continue;
                        }
                        String barcode = barcodeThread.getBarcode();
                        if (Cools.isEmpty(barcode)) {
                            continue;
                        }
                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
                            continue;
                        }
                        WrkMast wrkMast = wrkMastMapper.selectByBarcode(barcode);
                        if (wrkMast == null) {//找不到工作档
                            continue;
                        }
@@ -660,28 +615,6 @@
                                || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
                            continue;
                        }
                        //*********************同库位组校验*********************
                        boolean flag = false;
                        String th = "";
                        List<String> innerLoc = Utils.getGroupInnerLoc(wrkMast.getSourceLocNo());
                        for (String loc : innerLoc) {
                            LocMast locMast = locMastService.selectById(loc);
                            if (locMast == null) {
                                continue;
                            }
                            if (!locMast.getLocSts().equals("F")) {
                                flag = true;
                                th = loc + "库位存在未回库任务";
                                break;
                            }
                        }
                        if (flag) {
                            News.info(th);
                            continue;
                        }
                        //*********************同库位组校验*********************
                        // 保存工作主档历史档
                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
@@ -696,11 +629,11 @@
                            param.setWrkNo(wrkMast.getWrkNo());
                            param.setBarcode(wrkMast.getBarcode());
                            param.setIoType(107);//盘点
                            param.setSourceStaNo(wrkMast.getStaNo());
                            param.setSourceStaNo(pickSta.getStaNo());
                            param.setLocType1(locMast.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
                                    .setPath("/rpc/pakin/loc/v1")
                                    .setPath("/rpc/pakin/loc/v2")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
@@ -730,8 +663,8 @@
                                    continue;
                                }
                                staProtocol.setStaNo(dto.getSourceStaNo().shortValue());//写入目标站
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
//                                staProtocol.setStaNo(dto.getSourceStaNo().shortValue());//写入目标站
//                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            } else if (code == 500) {
                                News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
@@ -1267,15 +1200,15 @@
                return false;//出库站点不存在
            }
            if (!basDevp.getAutoing().equals("Y")) {
                News.info("{}任务,{}站点,不是自动状态",wrkMast.getWrkNo(),basDevp.getDevNo());
                return false;//不是自动状态
            }
            if (!basDevp.getOutEnable().equals("Y")) {
                News.info("{}任务,{}站点,没有可出信号", wrkMast.getWrkNo(), basDevp.getDevNo());
                return false;//出库站点不可出
            }
//            if (!basDevp.getAutoing().equals("Y")) {
//                News.info("{}任务,{}站点,不是自动状态",wrkMast.getWrkNo(),basDevp.getDevNo());
//                return false;//不是自动状态
//            }
//
//            if (!basDevp.getOutEnable().equals("Y")) {
//                News.info("{}任务,{}站点,没有可出信号", wrkMast.getWrkNo(), basDevp.getDevNo());
//                return false;//出库站点不可出
//            }
            Integer liftNo = basDevp.getLiftNo();//搜索出库提升机是否存在入库任务,如存在禁止出库
            List<WrkMast> liftWrkMasts = wrkMastMapper.selectInWrkMastByLiftNo(liftNo);
@@ -1306,7 +1239,7 @@
            if (wrkMast.getStaNo() == 300) {
                //出300站,检测300站任务数量
                List<WrkMast> wrkMasts = wrkMastMapper.select300Wrk();
                if (wrkMasts.size() >= 4) {
                if (wrkMasts.size() >= 20) {
                    News.info("{}任务,输送线任务过载{}", wrkMast.getWrkNo(), wrkMasts.size());
                    return false;
                }
@@ -1454,7 +1387,7 @@
                        if (wrkMastMapper.updateById(wrkMast) > 0) {
                            if (wrkMast.getWrkSts() == 111) {
                                // 保存工作主档历史档
                                if (wrkMastLocMapper.save(wrkMast.getWrkNo()) <= 0) {
                                if (wrkMastLogMapper.save(wrkMast.getWrkNo()) <= 0) {
                                    log.info("保存工作历史档[workNo={0}]失败", wrkMast.getWrkNo());
                                }
                                // 删除工作主档
@@ -1744,6 +1677,16 @@
                    News.info("{}任务,{}小车,小车在输送站点调度小车避让失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                    return false;
                }
            }
            if (!basDevp.getAutoing().equals("Y")) {
                News.info("{}任务,{}站点,没有自动信号,禁止派发", wrkMast.getWrkNo(), basDevp.getDevNo());
                return false;//出库站点不可出
            }
            if (basDevp.getLoading().equals("Y")) {
                News.info("{}任务,{}站点,存在有物信号,禁止派发", wrkMast.getWrkNo(), basDevp.getDevNo());
                return false;//出库站点不可出
            }
            if (!basDevp.getOutEnable().equals("Y")) {
@@ -2891,16 +2834,40 @@
                    }
                    // 获取工作档数据
                    WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
                    if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) {
                        continue;
                    Integer wrkNo = staProtocol.getWorkNo().intValue();
                    Integer ioType = null;
                    String sourceLocNo = null;
                    String locNo = null;
                    Integer wrkStaNo = null;
                    String barcode = null;
                    if (wrkMast == null) {
                        //查询历史档
                        WrkMastLog wrkMastLog = wrkMastLogMapper.selectLatestByWorkNo(staProtocol.getWorkNo().intValue());
                        if (wrkMastLog == null) {
                            continue;
                        }
                        ioType = wrkMastLog.getIoType();
                        sourceLocNo = wrkMastLog.getSourceLocNo();
                        locNo = wrkMastLog.getLocNo();
                        wrkStaNo = wrkMastLog.getStaNo();
                        barcode = wrkMastLog.getBarcode();
                    }else {
                        if (wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) {
                            continue;
                        }
                        ioType = wrkMast.getIoType();
                        sourceLocNo = wrkMast.getSourceLocNo();
                        locNo = wrkMast.getLocNo();
                        wrkStaNo = wrkMast.getStaNo();
                        barcode = wrkMast.getBarcode();
                    }
                    wrkMasts.add(wrkMast);
                    // 组装命令
                    LedCommand ledCommand = new LedCommand();
                    ledCommand.setWorkNo(wrkMast.getWrkNo());
                    ledCommand.setIoType(wrkMast.getIoType());
                    ledCommand.setWorkNo(wrkNo);
                    ledCommand.setIoType(ioType);
                    // 出库模式
                    switch (wrkMast.getIoType()) {
                    switch (ioType) {
                        case 101:
                            ledCommand.setTitle("全板出库");
                            break;
@@ -2918,22 +2885,22 @@
                            ledCommand.setEmptyMk(true);
                            break;
                        default:
                            News.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
                            News.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkNo, ioType);
                            break;
                    }
                    ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
                    ledCommand.setLocNo(wrkMast.getLocNo());
                    ledCommand.setStaNo(wrkMast.getStaNo());
                    if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) {
                        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getSourceLocNo()));
                    ledCommand.setSourceLocNo(sourceLocNo);
                    ledCommand.setLocNo(locNo);
                    ledCommand.setStaNo(wrkStaNo);
                    ledCommand.setBarcode(barcode);
                    if (ioType != 110 && ioType != 10) {
                        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
                        locDetls.forEach(locDetl -> {
                            Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>().eq("matnr", locDetl.getMatnr()).eq("wrk_no", wrkMast.getWrkNo());
                            Utils.wapperSetCondition(wrapper, "batch", locDetl.getBatch());
                            Utils.wapperSetCondition(wrapper, "three_code", locDetl.getThreeCode());
                            Utils.wapperSetCondition(wrapper, "dead_time", locDetl.getDeadTime());
                            Utils.wapperSetCondition(wrapper, "supp_code", locDetl.getSuppCode());//料箱码
                            WrkDetl detl = wrkDetlService.selectOne(wrapper);
                            List<WrkDetl> detl = wrkDetlService.selectList(wrapper);
                            if (Cools.isEmpty(detl)) {
                                String suppCode = "";
                                if (locDetl.getSuppCode() != null) {
@@ -2941,28 +2908,35 @@
                                }
                                ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode));
                            } else {
                                String suppCode = "";
                                String orderNo = detl.getOrderNo();
                                if (detl.getSuppCode() != null) {
                                    suppCode = detl.getSuppCode();
                                //出库数量累计
                                Double conut = 0.0;
                                for (WrkDetl wrkDetl : detl) {
                                    conut = conut + wrkDetl.getAnfme();
                                }
                                try {
                                    JSONArray orders = JSON.parseArray(orderNo);
                                    for (Object order : orders) {
                                        JSONObject order1 = (JSONObject) order;
                                        ledCommand.getMatDtos().add(new MatDto(detl.getMatnr(), detl.getMaktx(), (Double) order1.get("anfme"), (locDetl.getAnfme() - detl.getAnfme()), detl.getSpecs(), suppCode,(String) order1.get("orderNo")));
                                for (WrkDetl wrkDetl : detl) {
                                    String suppCode = "";
                                    if (wrkDetl.getSuppCode() != null) {
                                        suppCode = wrkDetl.getSuppCode();
                                    }
                                } catch (Exception e) {
                                    ledCommand.getMatDtos().add(new MatDto(detl.getMatnr(), detl.getMaktx(), detl.getAnfme(), (locDetl.getAnfme() - detl.getAnfme()), detl.getSpecs(), suppCode,detl.getOrderNo()));
                                    ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (locDetl.getAnfme() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo()));
                                }
                            }
                        });
                        if (locDetls.isEmpty()) {
                            List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
                            List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo));
                            wrkDetls.forEach(wrkDetl -> {
                                ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), wrkDetl.getAnfme(), wrkDetl.getSpecs(), wrkDetl.getSuppCode()));
                            });
                            if (wrkDetls.isEmpty()) {//从历史档查询
                                List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo);
                                wrkDetlLogs.forEach(wrkDetl -> {
                                    ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), wrkDetl.getAnfme(), wrkDetl.getSpecs(), wrkDetl.getSuppCode()));
                                });
                            }
                        }
                    }
@@ -3063,7 +3037,7 @@
                // 获取led线程
                LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
                // led显示默认内容
                if (reset && !ledThread.isLedMk()) {
                if (reset) {
                    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());
@@ -3885,7 +3859,7 @@
                if (wrkMast.getWrkSts() == 111) {
                    // 保存工作主档历史档
                    if (wrkMastLocMapper.save(wrkMast.getWrkNo()) <= 0) {
                    if (wrkMastLogMapper.save(wrkMast.getWrkNo()) <= 0) {
                        log.info("保存工作历史档[workNo={0}]失败", wrkMast.getWrkNo());
                    }
                    // 删除工作主档
@@ -3963,63 +3937,36 @@
        return true;
    }
    /**
     * 出入库模式切换
     */
    public synchronized void outAndIn() {
        try {
            // 根据输送线plc遍历
            for (DevpSlave devp : slaveProperties.getDevp()) {
                for (DevpSlave.Sta inSta : devp.getInSta()) {
                    Thread.sleep(500);
                    boolean a=true,b=true;
                    List<WrkMast> wrkMasts = wrkMastMapper.selectAll(inSta.getStaNo());
                    if (Cools.isEmpty(wrkMasts)){
                        b=false;
                    }else {
                        for (WrkMast wrkMast:wrkMasts){
                            if (wrkMast.getSourceStaNo() > wrkMast.getStaNo()){
                                a=false;
                                break;
                            }
                        }
                    }
                    switch (inSta.getStaNo()) {
                        case 102://1F
                            if (a && b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 11));
                            }else if (b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 12));
                            }else {
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 10));
                            }
                            break;
                        case 202://2F
                            if (a && b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 21));
                            }else if (b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 22));
                            }else {
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 20));
                            }
                            break;
                        case 302://3F
                            if (a && b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 31));
                            }else if (b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 32));
                            }else {
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 30));
                            }
                            break;
                    }
                }
    //扫描设备PakMk标记是否超时
    public synchronized void scanDevicePakMk() {
        //扫描小车
        for (ShuttleSlave slave : slaveProperties.getShuttle()) {
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace();
            if ((System.currentTimeMillis() - shuttleProtocol.getSendTime() > (1000*60*5)) && shuttleProtocol.getPakMk()) {
                //设备超过5分钟还没复位标记
                shuttleProtocol.setPakMk(false);//复位标记
            }
        }
    }
        //扫描提升机
        for (LiftSlave slave : slaveProperties.getLift()) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, slave.getId());
            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
            if (liftProtocol == null) {
                continue;
            }
            if ((System.currentTimeMillis() - liftProtocol.getSendTime() > (1000*60*5)) && liftProtocol.getPakMk()) {
                //设备超过5分钟还没复位标记
                liftProtocol.setPakMk(false);//复位标记
            }
        }
    }
}