#
Junjie
2024-06-12 9877b7c30b7626c4448347d373b27d0d0f2158fe
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.*;
@@ -43,7 +44,6 @@
 */
@Slf4j
@Service("mainService")
@Transactional
public class MainServiceImpl {
    @Value("${wms.url}")
@@ -112,6 +112,8 @@
    private NavigateMapUtils navigateMapUtils;
    @Autowired
    private WrkDetlLogService wrkDetlLogService;
    @Autowired
    private MatService matService;
    /**
@@ -119,89 +121,90 @@
     * 入库站,根据条码扫描生成入库工作档,工作状态 2
     */
    public void generateStoreWrkFile() {
        // 根据输送线plc遍历
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历入库口
            for (DevpSlave.Sta inSta : devp.getInSta()) {
                // 获取入库站信息
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                Short workNo = staProtocol.getWorkNo();
                // 尺寸检测异常
                boolean back = false;
                String errMsg = "异常:";
                if (staProtocol.isFrontErr()) {
                    errMsg = errMsg+"前超限;";
                    back = true;
                }
                if (staProtocol.isBackErr()) {
                    errMsg = errMsg+"后超限";
                    back = true;
                }
                if (staProtocol.isHighErr()) {
                    errMsg = errMsg+"高超限";
                    back = true;
                }
                if (staProtocol.isLeftErr()) {
                    errMsg = errMsg+"左超限";
                    back = true;
                }
                if (staProtocol.isRightErr()) {
                    errMsg = errMsg+"右超限";
                    back = true;
                }
                if (staProtocol.isWeightErr()) {
                    errMsg = errMsg+"超重";
                    back = true;
                }
                if (staProtocol.isBarcodeErr()) {
                    errMsg = errMsg+"扫码失败";
                    back = true;
                }
                // 退回
                if (back) {
                    // led 异常显示
                    LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                    if (ledThread != null) {
                        MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg));
        try {
            // 根据输送线plc遍历
            for (DevpSlave devp : slaveProperties.getDevp()) {
                // 遍历入库口
                for (DevpSlave.Sta inSta : devp.getInSta()) {
                    // 获取入库站信息
                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    continue;
                }
                // 判断是否满足入库条件
                if (staProtocol.isAutoing() && staProtocol.isLoading()
                        && staProtocol.isInEnable()
                        && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999))
                        ) {
                    // 获取条码扫描仪信息
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
                    if (barcodeThread == null) {
                    Short workNo = staProtocol.getWorkNo();
                    // 尺寸检测异常
                    boolean back = false;
                    String errMsg = "异常:";
                    if (staProtocol.isFrontErr()) {
                        errMsg = errMsg + "前超限;";
                        back = true;
                    }
                    if (staProtocol.isBackErr()) {
                        errMsg = errMsg + "后超限";
                        back = true;
                    }
                    if (staProtocol.isHighErr()) {
                        errMsg = errMsg + "高超限";
                        back = true;
                    }
                    if (staProtocol.isLeftErr()) {
                        errMsg = errMsg + "左超限";
                        back = true;
                    }
                    if (staProtocol.isRightErr()) {
                        errMsg = errMsg + "右超限";
                        back = true;
                    }
                    if (staProtocol.isWeightErr()) {
                        errMsg = errMsg + "超重";
                        back = true;
                    }
                    if (staProtocol.isBarcodeErr()) {
                        errMsg = errMsg + "扫码失败";
                        back = true;
                    }
                    // 退回
                    if (back) {
                        // led 异常显示
                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                        if (ledThread != null) {
                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg));
                        }
                        continue;
                    }
                    String barcode = barcodeThread.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                    // 判断是否满足入库条件
                    if (staProtocol.isAutoing() && staProtocol.isLoading()
                            && staProtocol.isInEnable()
                            && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999))
                    ) {
                        // 获取条码扫描仪信息
                        BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
                        if (barcodeThread == null) {
                            continue;
                        }
                        String barcode = barcodeThread.getBarcode();
                        if (!Cools.isEmpty(barcode)) {
//                        News.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
                        if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)|| "00000000".equals(barcode)) {
                            if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode) || "00000000".equals(barcode)) {
//                            staProtocol.setWorkNo((short) 32002);
//                            staProtocol.setStaNo(inSta.getBackSta().shortValue());
//                            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());
                            if (ledThread != null) {
                                String errorMsg = "扫码失败,请重试";
                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                                // 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;
                            }
                            continue;
                        }
                    } else {
                        } else {
//                        staProtocol.setWorkNo((short) 32002);
//                        staProtocol.setStaNo(inSta.getBackSta().shortValue());
//                        devpThread.setPakMk(staProtocol.getSiteId(), false);
@@ -213,42 +216,42 @@
//                            String errorMsg = "扫码失败,请重试";
//                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
//                        }
                        continue;
                    }
                            continue;
                        }
                    // 过滤盘点/拣料/并板任务
                    WrkMast wrkMast1 = wrkMastMapper.selectPickStepByBarcode(barcode);
                    if (null != wrkMast1) {
                        continue;
                    }
                        // 过滤盘点/拣料/并板任务
                        WrkMast wrkMast1 = wrkMastMapper.selectPickStepByBarcode(barcode);
                        if (null != wrkMast1) {
                            continue;
                        }
                    // 判断重复工作档
                    WrkMast wrkMast2 = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
                    if (wrkMast2 != null) {
                        News.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast2.getWrkNo());
                        continue;
                    }
                        // 判断重复工作档
                        WrkMast wrkMast2 = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
                        if (wrkMast2 != null) {
                            News.error("工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast2.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());
                        String response = new HttpHandler.Builder()
                                .setUri(wmsUrl)
                                .setPath("/rpc/pakin/loc/v1")
                                .setJson(JSON.toJSONString(param))
                                .build()
                                .doPost();
                        JSONObject jsonObject = JSON.parseObject(response);
                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                        Integer code = jsonObject.getInteger("code");
                        if (code.equals(200)) {
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                            // plc 处理
                            barcodeThread.setBarcode("");
                        try {
                            LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
                            SearchLocParam param = new SearchLocParam();
                            param.setBarcode(barcode);
                            param.setIoType(1);
                            param.setSourceStaNo(inSta.getStaNo());
                            param.setLocType1(locTypeDto.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
                                    .setPath("/rpc/pakin/loc/v2")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
                            JSONObject jsonObject = JSON.parseObject(response);
                            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                            Integer code = jsonObject.getInteger("code");
                            if (code.equals(200)) {
                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                                // plc 处理
                                barcodeThread.setBarcode("");
//                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
//                            staProtocol.setStaNo(dto.getStaNo().shortValue());
//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
@@ -258,45 +261,50 @@
//                                throw new CoolException("更新plc站点信息失败");
//                            }
                            // 判断重复工作档
                            WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
                            if (wrkMast == null) { continue; }
                            // 更新工作主档
                            wrkMast.setWrkSts(2L); // 工作状态:2.设备上走
                            wrkMast.setModiTime(new Date());
                            if (wrkMastMapper.updateById(wrkMast) == 0) {
                                News.error("更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo());
                            }
                        } else if (code == 500){
                            if (ledThread != null) {
                                String errorMsg = jsonObject.getString("msg");
                                if (!Cools.isEmpty(errorMsg)) {
                                    MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                                    ledThread.setLedMk(false);
                                // 判断重复工作档
                                WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
                                if (wrkMast == null) {
                                    continue;
                                }
                            }
                            News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                        } else if (code == 700) {
                                // 更新工作主档
                                wrkMast.setWrkSts(2L); // 工作状态:2.设备上走
                                wrkMast.setModiTime(new Date());
                                if (wrkMastMapper.updateById(wrkMast) == 0) {
                                    News.error("更新工作档失败!!! [工作号:{}]", wrkMast.getWrkNo());
                                }
                            } else if (code == 500) {
                                if (ledThread != null) {
                                    String errorMsg = jsonObject.getString("msg");
                                    if (!Cools.isEmpty(errorMsg)) {
                                        MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                                        ledThread.setLedMk(false);
                                    }
                                }
                                News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response);
                            } else if (code == 700) {
//                            staProtocol.setWorkNo((short) 32002);
//                            staProtocol.setRollback102(1);//102站回退信号
//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
//                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol));
                            // led 异常显示
                            if (ledThread != null) {
                                String errorMsg = barcode + "托盘识别异常,请先进行组托!";
                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                                ledThread.setLedMk(false);
                                // led 异常显示
                                if (ledThread != null) {
                                    String errorMsg = barcode + "托盘识别异常,请先进行组托!";
                                    MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                                    ledThread.setLedMk(false);
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
@@ -467,11 +475,11 @@
//                        }
//                        //*********************同库位组校验*********************
                        // 保存工作主档历史档
                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
                            News.info(wrkMast.getWrkNo() + "保存工作主档历史档失败");
                            continue;
                        }
//                        // 保存工作主档历史档
//                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
//                            News.info(wrkMast.getWrkNo() + "保存工作主档历史档失败");
//                            continue;
//                        }
                        try {
                            LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());//源库位
@@ -480,6 +488,7 @@
                            param.setBarcode(wrkMast.getBarcode());
                            param.setIoType(wrkMast.getIoType());
                            param.setSourceStaNo(pickSta.getStaNo());
                            param.setLiftNo(pickSta.getLiftNo());
                            param.setLocType1(locMast.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
@@ -492,28 +501,28 @@
                            if (code.equals(200)) {
                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                                //获取回库提升机目标站
                                LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(dto.getLocNo()));
                                if (liftStaProtocol == null) {
                                    News.info(wrkMast.getWrkNo() + "获取回库提升机目标站失败");
                                    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;
                                }
//                                //获取回库提升机目标站
//                                LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(dto.getLocNo()));
//                                if (liftStaProtocol == null) {
//                                    News.info(wrkMast.getWrkNo() + "获取回库提升机目标站失败");
//                                    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);
                                News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
@@ -616,11 +625,11 @@
                            continue;
                        }
                        // 保存工作主档历史档
                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
                            News.info(wrkMast.getWrkNo() + "保存工作主档历史档失败");
                            continue;
                        }
//                        // 保存工作主档历史档
//                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
//                            News.info(wrkMast.getWrkNo() + "保存工作主档历史档失败");
//                            continue;
//                        }
                        //盘点找新库位
                        try {
@@ -630,6 +639,7 @@
                            param.setBarcode(wrkMast.getBarcode());
                            param.setIoType(107);//盘点
                            param.setSourceStaNo(pickSta.getStaNo());
                            param.setLiftNo(pickSta.getLiftNo());
                            param.setLocType1(locMast.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
@@ -642,32 +652,32 @@
                            if (code.equals(200)) {
                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                                //获取回库提升机目标站
                                LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(dto.getLocNo()));
                                if (liftStaProtocol == null) {
                                    News.info(wrkMast.getWrkNo() + "获取回库提升机目标站失败");
                                    continue;
                                }
                                // 更新工作档数据状态
                                wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 107->57
                                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;
                                }
//                                //获取回库提升机目标站
//                                LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(dto.getLocNo()));
//                                if (liftStaProtocol == null) {
//                                    News.info(wrkMast.getWrkNo() + "获取回库提升机目标站失败");
//                                    continue;
//                                }
//
//                                // 更新工作档数据状态
//                                wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 107->57
//                                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;
//                                }
//                                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);
                                News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
@@ -1609,8 +1619,12 @@
            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo());
            if (wrkMast.getIoType() == 53 || wrkMast.getIoType() == 57) {
                //拣料再回库,重新分配设备工作号
                Random random = new Random();
                int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//获取设备工作号
                int deviceWrk = commonService.getWorkNo(8);//生成提升机设备工作号
                BasLiftOpt basLiftOpt = basLiftOptService.selectByDeviceWrk(String.valueOf(deviceWrk), liftThread.getSlave().getId());
                if (basLiftOpt != null) {
                    News.info("{}任务,{}号提升机,设备工作号出现重复情况,请联系技术人员支持。", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
                    return false;
                }
                liftCommand.setTaskNo((short) deviceWrk);
            }
            ArrayList<NyLiftCommand> commands = new ArrayList<>();
@@ -1773,10 +1787,13 @@
                        && liftProtocol.getTaskNo() != 0
                        && !liftProtocol.getBusy()
                ) {
                    BasLiftOpt basLiftOpt = basLiftOptService.selectByDeviceWrk(liftProtocol.getTaskNo().toString());
                    int taskNo = liftProtocol.getTaskNo().intValue();
                    if (basLiftOpt != null) {
                        taskNo = basLiftOpt.getWrkNo();
                    if (taskNo >= 20000 && taskNo <= 30000) {
                        //提升机设备工作号,需要查询对应任务号
                        BasLiftOpt basLiftOpt = basLiftOptService.selectByDeviceWrk(liftProtocol.getTaskNo().toString(), liftSlave.getId());
                        if (basLiftOpt != null) {
                            taskNo = basLiftOpt.getWrkNo();
                        }
                    }
                    //将任务档标记为完成
@@ -1801,6 +1818,7 @@
                                        wrkMast.setWrkSts(29L);
                                        wrkMast.setShuttleNo(null);//释放小车
                                        wrkMast.setLiftNo(null);//释放提升机
                                        wrkMast.setModiTime(new Date());
                                    }
                                }
@@ -2453,7 +2471,7 @@
//                        param.setLocType1(locTypeDto.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
                                    .setPath("/rpc/pakin/loc/v1")
                                    .setPath("/rpc/pakin/loc/v2")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
@@ -2477,7 +2495,7 @@
                                        MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, errorMsg));
                                    }
                                }
                                News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                                News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v2", JSON.toJSONString(param), response);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
@@ -2497,7 +2515,7 @@
    /**
     * AGV补货 => 生成入库通知档
     */
    public void robotGenerateAgvTask() {
    public synchronized void robotGenerateAgvTask() {
        try {
            //检测300站是否自动、有物、工作号
            for (DevpSlave devp : slaveProperties.getDevp()) {
@@ -2565,7 +2583,7 @@
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
//                                e.printStackTrace();
                                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            }
@@ -2590,14 +2608,14 @@
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
//            e.printStackTrace();
        }
    }
    /**
     * AGV补货 => 机械臂拣料
     */
    public void agvRestockByRobot() {
    public synchronized void agvRestockByRobot() {
        try {
            //检测300站是否自动、有物、工作号
            for (DevpSlave devp : slaveProperties.getDevp()) {
@@ -2622,9 +2640,10 @@
                    }
                    if (wrkMast.getInvWh() == null) {
                        wrkMast.setInvWh("Y");//标记已经下发机械臂任务
                        if (wrkMastMapper.updateById(wrkMast) > 0) {
                            RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetls.size(), "303");
                        boolean result = RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetls.size(), "303");
                        if (result) {
                            wrkMast.setInvWh("Y");//标记已经下发机械臂任务
                            wrkMastMapper.updateById(wrkMast);
                        }
                    }
                }
@@ -2641,9 +2660,10 @@
                        continue;
                    }
                    if (wrkMast.getInvWh() == null) {
                        wrkMast.setInvWh("Y");//标记已经下发机械臂任务
                        if (wrkMastMapper.updateById(wrkMast) > 0) {
                            RobotUtils.sendTask(staProtocol317.getWorkNo().toString(), wrkDetls.size(), "317");
                        boolean result = RobotUtils.sendTask(staProtocol317.getWorkNo().toString(), wrkDetls.size(), "317");
                        if (result) {
                            wrkMast.setInvWh("Y");//标记已经下发机械臂任务
                            wrkMastMapper.updateById(wrkMast);
                        }
                    }
                }
@@ -2656,7 +2676,7 @@
    /**
     * AGV补货(通知AGV取货)
     */
    public void agvRestockInto() {
    public synchronized void agvRestockInto() {
        try {
            //检测309和312站是否自动、有物
            for (DevpSlave devp : slaveProperties.getDevp()) {
@@ -2726,13 +2746,38 @@
        return false;
    }
    //通知WMS当前拣料站点信息
    private boolean agvCureentCall(String staNo, String barcode) {
        try {
            HashMap<String, Object> param = new HashMap<>();
            param.put("devNo", staNo);
            param.put("containerCode", barcode);
            String response = new HttpHandler.Builder()
                    .setUri(wmsUrl)
                    .setPath("/rpc/current/containerCode")
                    .setJson(JSON.toJSONString(param))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            News.info("悬挂线,WMS返回结果:" + jsonObject);
            Integer code = jsonObject.getInteger("code");
            if (code.equals(200)) {//呼叫AGV
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return false;
    }
    /**
     * AGV补货(悬挂线通知AGV取货)
     */
    public void agvRestockIntoByHangingWire() {
    public synchronized void agvRestockIntoByHangingWire() {
        try {
            //检测350和351扫码器
            int[] barcodeStaNo = {11, 12};//11 => 350站扫码器,12 => 351站扫码器
            int[] barcodeStaNo = {11, 12,14,16,18,20};//11 => 350站扫码器,12 => 351站扫码器
            for (int staNo : barcodeStaNo) {
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, staNo);
@@ -2748,11 +2793,61 @@
                    String agvStaNo = null;
                    if (staNo == 11) {
                        agvStaNo = "303-1";
                    } else {
                    } else if(staNo == 12){
                        agvStaNo = "304-1";
                    } else if(staNo == 14){
                        agvStaNo = "311-1";
                    } else if(staNo == 16){
                        agvStaNo = "313-1";
                    } else if(staNo == 18){
                        agvStaNo = "315-1";
                    } else if(staNo == 20){
                        agvStaNo = "317-1";
                    }
                    //通知AGV取货
                    boolean result = agvRestockCall(agvStaNo, barcode);
                    if (result) {
                        barcodeThread.setBarcode("");
                    }
                    log.info(barcodeThread.getSlave().getId() + "号扫码器,通知AGV取货,条码号:" + barcode);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * AGV拣料站点信息
     */
    public synchronized void agvCurrentContainerCodeInfoWire() {
        try {
            //检测350和351扫码器
            int[] barcodeStaNo = {13, 15,17,19};//11 => 350站扫码器,12 => 351站扫码器
            for (int staNo : barcodeStaNo) {
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, staNo);
                if (barcodeThread == null) {
                    continue;
                }
                String barcode = barcodeThread.getBarcode();
                if (!Cools.isEmpty(barcode)) {
                    if (barcode.contains("NoRead")) {
                        continue;
                    }
                    String agvStaNo = null;
                    if (staNo == 13) {
                        agvStaNo = "CS-310";
                    } else if(staNo == 15){
                        agvStaNo = "CS-311";
                    } else if(staNo == 17){
                        agvStaNo = "CS-312";
                    } else if(staNo == 19){
                        agvStaNo = "CS-313";
                    }
                    //通知WMS当前容器码
                    boolean result = agvCureentCall(agvStaNo, barcode);
                    if (result) {
                        barcodeThread.setBarcode("");
                    }
@@ -2774,7 +2869,10 @@
                StaProtocol staProtocol = devpThread.getStation().get(300);
                if (staProtocol == null) {
                    continue;
                }else {
                    staProtocol = staProtocol.clone();
                }
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) {
                    //查询是否有工作档
                    WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
@@ -2895,56 +2993,132 @@
                    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", wrkNo);
                            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());//料箱码
                            List<WrkDetl> detl = wrkDetlService.selectList(wrapper);
                            if (Cools.isEmpty(detl)) {
                                String suppCode = "";
                                if (locDetl.getSuppCode() != null) {
                                    suppCode = locDetl.getSuppCode();
                                }
                                ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode));
                            } else {
                                //出库数量累计
                                Double conut = 0.0;
                                for (WrkDetl wrkDetl : detl) {
                                    conut = conut + wrkDetl.getAnfme();
                                }
                                for (WrkDetl wrkDetl : detl) {
                                    String suppCode = "";
                                    if (wrkDetl.getSuppCode() != null) {
                                        suppCode = wrkDetl.getSuppCode();
                                    }
                                    ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (locDetl.getAnfme() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo()));
                                }
                            }
                        });
                        if (ioType == 107) {
                            locDetls = new ArrayList<>();
                            ledCommand.setMatDtos(new ArrayList<>());
                        }
                        if (locDetls.isEmpty()) {
                            List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo));
                        List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo));
                        if (!wrkDetls.isEmpty()) {
                            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, barcode);
                                for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
                                    ledCommand.getMatDtos().add(new MatDto(wrkDetlLog.getMatnr(), wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), wrkDetlLog.getAnfme(), wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode()));
                                double remainNum = wrkDetl.getStock() - wrkDetl.getAnfme();//剩余数量
                                if (remainNum < 0) {
                                    remainNum = 0;
                                }
                                String matnr = wrkDetl.getMatnr();
                                Mat mat = matService.selectByMatnr(wrkDetl.getMatnr());
                                if (mat != null) {
                                    if (!mat.getMatnr().equals(mat.getMatnr2())) {
                                        matnr += " - " + mat.getMatnr2();
                                    }
                                }
                                ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetl.getMaktx(), wrkDetl.getAnfme(), remainNum, wrkDetl.getSpecs(), wrkDetl.getSuppCode(), wrkDetl.getOrderNo()));
                            });
                        }else {
                            List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode);
                            for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
                                double remainNum = wrkDetlLog.getStock() - wrkDetlLog.getAnfme();//剩余数量
                                if (remainNum < 0) {
                                    remainNum = 0;
                                }
                                String matnr = wrkDetlLog.getMatnr();
                                Mat mat = matService.selectByMatnr(wrkDetlLog.getMatnr());
                                if (mat != null) {
                                    if (!mat.getMatnr().equals(mat.getMatnr2())) {
                                        matnr += " - " + mat.getMatnr2();
                                    }
                                }
                                ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), remainNum, wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode()));
                            }
                        }
//                        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
//                        if (ioType == 101) {
//                            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(), 0D, wrkDetl.getSpecs(), wrkDetl.getSuppCode()));
//                            });
////                            locDetls.forEach(locDetl -> {
////                                Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>().eq("matnr", locDetl.getMatnr()).eq("wrk_no", wrkNo);
////                                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());//料箱码
////                                List<WrkDetl> detl = wrkDetlService.selectList(wrapper);
////                                if (Cools.isEmpty(detl)) {
////                                    String suppCode = "";
////                                    if (locDetl.getSuppCode() != null) {
////                                        suppCode = locDetl.getSuppCode();
////                                    }
////                                    ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode));
////                                } else {
////                                    //出库数量累计
////                                    Double conut = 0.0;
////                                    for (WrkDetl wrkDetl : detl) {
////                                        conut = conut + wrkDetl.getAnfme();
////                                    }
////
////                                    for (WrkDetl wrkDetl : detl) {
////                                        String suppCode = "";
////                                        if (wrkDetl.getSuppCode() != null) {
////                                            suppCode = wrkDetl.getSuppCode();
////                                        }
////                                        ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (locDetl.getAnfme() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo()));
////                                    }
////                                }
////
////                            });
//                        } else {
//                            locDetls.forEach(locDetl -> {
//                                Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>().eq("matnr", locDetl.getMatnr()).eq("wrk_no", wrkNo);
//                                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());//料箱码
//                                List<WrkDetl> detl = wrkDetlService.selectList(wrapper);
//                                if (Cools.isEmpty(detl)) {
//                                    String suppCode = "";
//                                    if (locDetl.getSuppCode() != null) {
//                                        suppCode = locDetl.getSuppCode();
//                                    }
//                                    ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode));
//                                } else {
//                                    //出库数量累计
//                                    Double conut = 0.0;
//                                    for (WrkDetl wrkDetl : detl) {
//                                        conut = conut + wrkDetl.getAnfme();
//                                    }
//
//                                    for (WrkDetl wrkDetl : detl) {
//                                        String suppCode = "";
//                                        if (wrkDetl.getSuppCode() != null) {
//                                            suppCode = wrkDetl.getSuppCode();
//                                        }
//                                        ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (wrkDetl.getStock() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo()));
//                                    }
//                                }
//
//                            });
//                        }
//
//
//                        if (ioType == 107) {
//                            locDetls = new ArrayList<>();
//                            ledCommand.setMatDtos(new ArrayList<>());
//                        }
//
//                        if (locDetls.isEmpty() && ioType != 101) {
//                            List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo));
//                            wrkDetls.forEach(wrkDetl -> {
//                                if (wrkDetl.getAnfme() > 0D) {
//                                    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, barcode);
//                                for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
//                                    if (wrkDetlLog.getAnfme() > 0D) {
//                                        ledCommand.getMatDtos().add(new MatDto(wrkDetlLog.getMatnr(), wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), wrkDetlLog.getAnfme(), wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode()));
//                                    }
//                                }
//                            }
//                        }
                    }
                    commands.add(ledCommand);
@@ -3384,7 +3558,7 @@
                return false;//检测目标站点路径是否未被占用
            }
            //尝试锁定目标站路径
            boolean result2 = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(wrkMast.getLocNo()), targetNodes, true);//所使用的路径进行锁定禁用
            boolean result2 = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(wrkMast.getLocNo()), shuttleProtocol.getShuttleNo().intValue(), targetNodes, true);//所使用的路径进行锁定禁用
            if (!result2) {
                News.info("{}任务,{}小车,路径锁定失败,禁止派发", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                return false;//路径锁定失败
@@ -3396,7 +3570,7 @@
            if (result == null) {
                //路径获取失败,需要解锁上面锁定的路径
                //尝试解锁目标站路径
                boolean result3 = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(wrkMast.getLocNo()), targetNodes, false);//所使用的路径进行解锁
                boolean result3 = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(wrkMast.getLocNo()), shuttleProtocol.getShuttleNo().intValue(), targetNodes, false);//所使用的路径进行解锁
                if (!result3) {
                    News.info("{}任务,{}小车,路径解锁失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo());
                    return false;//路径解锁失败
@@ -3520,8 +3694,12 @@
                //获取提升机命令,调度提升机到源站位置
                NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceLiftSta.getStaNo(), sourceLiftSta.getStaNo(), wrkMast.getWrkNo());
                Random random = new Random();
                int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//获取设备工作号
                int deviceWrk = commonService.getWorkNo(8);//生成提升机设备工作号
                BasLiftOpt basLiftOpt = basLiftOptService.selectByDeviceWrk(String.valueOf(deviceWrk), liftThread.getSlave().getId());
                if (basLiftOpt != null) {
                    News.info("{}任务,{}号提升机,设备工作号出现重复情况,请联系技术人员支持。", wrkMast.getWrkNo(), liftProtocol.getLiftNo());
                    return false;
                }
                liftCommand.setTaskNo((short) deviceWrk);//更换随机任务号
                ArrayList<NyLiftCommand> commands = new ArrayList<>();
@@ -3962,32 +4140,36 @@
    //扫描设备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;
        try {
            //扫描小车
            for (ShuttleSlave slave : slaveProperties.getShuttle()) {
                NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
                NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
                if (shuttleProtocol == null) {
                    continue;
                }
                if ((System.currentTimeMillis() - shuttleProtocol.getSendTime() > (1000 * 60 * 5)) && shuttleProtocol.getPakMk()) {
                    //设备超过5分钟还没复位标记
                    shuttleProtocol.setPakMk(false);//复位标记
                }
            }
            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;
                }
        //扫描提升机
        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);//复位标记
                }
            }
            if ((System.currentTimeMillis() - liftProtocol.getSendTime() > (1000*60*5)) && liftProtocol.getPakMk()) {
                //设备超过5分钟还没复位标记
                liftProtocol.setPakMk(false);//复位标记
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }