#
zjj
2025-05-09 a5011461e6c32c6c33dff9bfaf8389d0ca2fa997
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -49,6 +49,7 @@
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.zy.common.utils.RandomValidateCodeUtil.code;
@@ -105,6 +106,8 @@
    private String wmsUrl;
    public int workNo = 9900;
    public int workNoMax = 12000;
    /**
     * 组托
@@ -237,6 +240,7 @@
                        param.setSourceStaNo(inSta.getStaNo());
                        param.setLocType1(locTypeDto.getLocType1());
                        String response = new HttpHandler.Builder()
                                .setTimeout(30, TimeUnit.SECONDS)
                                .setUri(wmsUrl)
                                .setPath("/rpc/pakin/loc/v1")
                                .setJson(JSON.toJSONString(param))
@@ -275,6 +279,11 @@
                            }
                        } else {
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                            if (ledThread != null) {
                                String errorMsg = barcode + jsonObject.get("msg");
                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                            }
                        }
                    } catch (Exception e) {
@@ -481,6 +490,7 @@
                        param.setSourceStaNo(inSta.getStaNo());
                        param.setLocType1(locTypeDto.getLocType1());
                        String response = new HttpHandler.Builder()
                                .setTimeout(30,TimeUnit.SECONDS)
                                .setUri(wmsUrl)
                                .setPath("/rpc/pakin/loc/v1")
                                .setJson(JSON.toJSONString(param))
@@ -518,6 +528,11 @@
                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                            }
                        } else {
                            ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                            if (ledThread != null) {
                                String errorMsg = jsonObject.getString("msg");
                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                            }
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                        }
@@ -1015,11 +1030,12 @@
                } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
                    // 此标记避免多次执行移库任务
                    if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())) {
                        wrkMast.setUpdMk("Y");
                        wrkMast.setIoPri(14D);
                        wrkMastMapper.updateById(wrkMast);
                        if (moveLocForDeepLoc(slave, shallowLoc)){
                            wrkMast.setUpdMk("Y");
                            wrkMast.setIoPri(14D);
                            wrkMastMapper.updateById(wrkMast);
                        }
                        // 生成工作档,将浅库位移转到新的库位中
                        moveLocForDeepLoc(slave, shallowLoc);
                        // 生成工作档、改变浅库位的源库/目标库 库位状态、下发堆垛机命令(立马执行)
//                        moveLocForDeepLocPakin(slave, shallowLoc, wrkMast);
                    }
@@ -1159,10 +1175,12 @@
//                            if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())
//                                || Cools.isEmpty(waitWrkMast)) {
                            if (Cools.isEmpty(waitWrkMast)) {
                                wrkMast.setUpdMk("Y");
                                wrkMastMapper.updateById(wrkMast);
                                if ( moveLocForDeepLoc(slave, shallowLoc)){
                                    wrkMast.setUpdMk("Y");
                                    wrkMastMapper.updateById(wrkMast);
                                }
                                // 生成工作档,将浅库位移转到新的库位中
                                moveLocForDeepLoc(slave, shallowLoc);
                            }
                            log.error("{}任务出库失败,浅库位堵塞!浅库位号:{}", wrkMast.getWrkNo(), shallowLocNo);
                            continue;
@@ -1618,6 +1636,11 @@
                                throw new CoolException("更新plc站点信息失败");
                            }
                        } else {
                            ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed());
                            if (ledThread != null) {
                                String errorMsg = jsonObject.getString("msg");
                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, errorMsg));
                            }
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                        }
                    } catch (Exception e) {
@@ -1845,7 +1868,8 @@
     * 因双深库位阻塞,对浅库位进行移转(立即执行版)
     * tip:同步
     */
    private synchronized void moveLocForDeepLoc(CrnSlave crn, LocMast shallowLoc) {
    @Transactional
    public synchronized Boolean moveLocForDeepLoc(CrnSlave crn, LocMast shallowLoc) {
        try {
            List<Integer> rows = locMastService.queryDistinctRow(crn.getId());
            LocMast loc = null;
@@ -1889,9 +1913,9 @@
            if (null == loc) {
                log.error("双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo());
                throw new CoolException("双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo());
                return false;
            }
            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", shallowLoc.getLocNo()));
            // 获取工作号
            int workNo = commonService.getWorkNo(0);
            // 保存工作档
@@ -1904,7 +1928,7 @@
            wrkMast.setCrnNo(crn.getId());
            wrkMast.setSourceLocNo(shallowLoc.getLocNo()); // 源库位
            wrkMast.setLocNo(loc.getLocNo()); // 目标库位
            wrkMast.setFullPlt(shallowLoc.getFullPlt()); // 满板
            wrkMast.setFullPlt(Cools.isEmpty(locDetls)?"N":"Y"); // 满板:Y
            wrkMast.setPicking("N"); // 拣料
            wrkMast.setExitMk("N"); // 退出
            wrkMast.setEmptyMk(shallowLoc.getLocSts().equals("D") ? "Y" : "N"); // 空板
@@ -1918,7 +1942,7 @@
            }
            // 工作档明细保存
            if (shallowLoc.getLocSts().equals("F")) {
                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", shallowLoc.getLocNo()));
                for (LocDetl locDetl : locDetls) {
                    WrkDetl wrkDetl = new WrkDetl();
                    wrkDetl.setWrkNo(workNo);
@@ -1937,10 +1961,11 @@
                shallowLoc.setLocSts("R"); // R.出库预约
                shallowLoc.setModiTime(new Date());
                if (!locMastService.updateById(shallowLoc)) {
                    throw new CoolException("更新源库位状态失败");
//                    throw new CoolException("更新源库位状态失败");
                }
            } else {
                throw new CoolException("源库位出库失败");
                return false;
//                throw new CoolException("源库位出库失败");
            }
            // 修改目标库位状态
            if (loc.getLocSts().equals("O")) {
@@ -1950,13 +1975,13 @@
                    throw new CoolException("更新目标库位状态失败");
                }
            } else {
                throw new CoolException("移转失败");
                return false;
//                throw new CoolException("移转失败");
            }
        } catch (Exception e) {
            log.error("双深库位阻塞,对浅库位进行移转失败", e);
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return true;
    }
    /**
@@ -2842,6 +2867,7 @@
                        if (rgvSlave.getId() != 2 ){
                            continue;
                        }
                        if (workNo >= workNoMax){ workNo = 9900;}
                        workNo1 = workNo++;
                        souSta1 = Utils.getRgvStaNo(rgvSlave.getId(),inStn.getSourceStaNo());
                        if (inStn.getSourceStaNo() == 4007 && staProtocol.getTongType() == 1){
@@ -2968,6 +2994,7 @@
                            if (rgvSlave.getId() != 2 ){
                                continue;
                            }
                            if (workNo >= workNoMax){ workNo = 9900;}
                            workNo2 = workNo++;
                            souSta2 = Utils.getRgvStaNo(rgvSlave.getId(),inStn.getSourceStaNo());
                            if (inStn.getSourceStaNo() == 4007 && staProtocol.getTongType() == 1){
@@ -3085,26 +3112,10 @@
                    command.setWeight2(weight2);
                    if (workNo1 == 0 && workNo2 !=0){
                        if("0".equals(matnr2) || "".equals(batch2) ){
                            log.error("源站"+souSta2+"工位一任务缺少信息,物料代码:"+matnr+",batch:"+batch);
                            continue;
                        }
                        command.setTaskMode(RgvTaskModeType.FETCH_PUT2); // 任务模式: 2取放货
                    } else if (workNo1 != 0 && workNo2 ==0) {
                        if("0".equals(matnr) || "".equals(batch) ){
                            log.error("源站"+souSta1+"工位二任务缺少信息,物料代码:"+matnr+",batch:"+batch);
                            continue;
                        }
                        command.setTaskMode(RgvTaskModeType.FETCH_PUT1); // 任务模式: 1取放货
                    }else {
                        if("0".equals(matnr) || "".equals(batch) ){
                            log.error("源站"+souSta1+"工位一任务缺少信息,物料代码:"+matnr+",batch:"+batch);
                            continue;
                        }
                        if("0".equals(matnr2) || "".equals(batch2) ){
                            log.error("源站"+souSta2+"工位二任务缺少信息,物料代码:"+matnr+",batch:"+batch);
                            continue;
                        }
                        command.setTaskMode(RgvTaskModeType.FETCH_PUT_ALL); // 任务模式: all取放货
                    }
                    command.setCommand(false);
@@ -3653,6 +3664,7 @@
                                param.setSourceStaNo(inSta.getStaNo());
                                param.setLocType1(locTypeDto.getLocType1());
                                String response = new HttpHandler.Builder()
                                        .setTimeout(30,TimeUnit.SECONDS)
                                        .setUri(wmsUrl)
                                        .setPath("/rpc/process/in/loc/v1")
                                        .setJson(JSON.toJSONString(param))
@@ -3681,6 +3693,11 @@
                                        MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                                    }
                                } else {
                                    ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                                    if (ledThread != null) {
                                        String errorMsg = jsonObject.getString("msg");
                                        MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                                    }
                                    log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/process/in/loc/v1", JSON.toJSONString(param), response);
                                }
@@ -3720,7 +3737,7 @@
                            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                            if (jsonObject.getInteger("code").equals(200)) {
                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                                log.error(barcode + "生成任务成功,"+dto);
                                barcodeThread.setBarcode("");
                                staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                                staProtocol.setStaNo(dto.getStaNo().shortValue());
@@ -3739,6 +3756,11 @@
                                    MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                                }
                            } else {
                                ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                                if (ledThread != null) {
                                    String errorMsg = jsonObject.getString("msg");
                                    MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                                }
                                log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            }
@@ -3837,6 +3859,13 @@
//        MatnrCode matnrCode = matnrCodeService.selectByCode(code);
        Mat mat = matService.selectByCode(code);
        if (Cools.isEmpty(mat)){
            //zc 添加显示屏信息,输出物料无法或别等情况
            // led 异常显示
            LedThread   ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
            if (ledThread != null) {
                String errorMsg = code + "未找到对应的物料信息!";
                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
            }
            throw new  CoolException("未找到对应的物料信息");
        }
        CombParam combParam = new CombParam();