#
zjj
2025-05-08 b44b85a4d7512615b8c19c95dc21e537a15a0d5b
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);
                        }
@@ -1618,6 +1633,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) {
@@ -1891,7 +1911,7 @@
                log.error("双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo());
                throw new CoolException("双深库位 --- 浅库位阻塞异常! 待移转浅库位:" + shallowLoc.getLocNo());
            }
            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", shallowLoc.getLocNo()));
            // 获取工作号
            int workNo = commonService.getWorkNo(0);
            // 保存工作档
@@ -1904,7 +1924,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 +1938,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);
@@ -2842,6 +2862,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 +2989,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){
@@ -3432,6 +3454,11 @@
                                wrkMast.setWrkSts(105L);
                                wrkMast.setModiTime(date);
                                wrkMastService.updateById(wrkMast);
                            } else if (wrkMast.getIoType() == 105){
                                Date date = new Date();
                                wrkMast.setWrkSts(14L);
                                wrkMast.setModiTime(date);
                                wrkMastService.updateById(wrkMast);
                            }
                        }
@@ -3615,56 +3642,78 @@
//                     获取入库通知档
                    WaitPakin waitPakin = waitPakinService.selectOne(new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("io_status", "N"));
                    if (Cools.isEmpty(waitPakin)) {
                        try {
                            CreateComb(barcode, staProtocol.getMatnr().toString(),staProtocol.getWorkNo().intValue(),staProtocol.getBatch(),inSta);
                        }catch (IOException e) {
                            throw new CoolException(e);
                        WrkMast mast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", barcode).eq("io_type", 105));
                        if (Cools.isEmpty(mast)) {
                            try {
                                CreateComb(barcode, staProtocol.getMatnr().toString(),staProtocol.getWorkNo().intValue(),staProtocol.getBatch(),inSta);
                            }catch (IOException e) {
                                throw new CoolException(e);
                            }
                        } else {
                            try {
                                LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
                                SearchLocParam param = new SearchLocParam();
                                param.setBarcode(barcode);
                                param.setBatch(staProtocol.getBatch());
                                param.setIoType(105);
                                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))
                                        .build()
                                        .doPost();
                                JSONObject jsonObject = JSON.parseObject(response);
                                LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                                if (jsonObject.getInteger("code").equals(200)) {
                                    StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                                    barcodeThread.setBarcode("");
                                    staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                                    staProtocol.setStaNo(dto.getStaNo().shortValue());
                                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                                    ledThread.errorReset();
                                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                                    if (!result) {
                                        throw new CoolException("更新plc站点信息失败");
                                    }
                                } else if(jsonObject.getInteger("code").equals(700)) {
                                    log.error(barcode + "托盘识别异常,请先进行组托!");
                                    // led 异常显示
                                    ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                                    if (ledThread != null) {
                                        String errorMsg = barcode + "托盘识别异常,请先进行组托!";
                                        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);
                                }
                            } catch (Exception e) {
                                log.error(""+e);
                                e.printStackTrace();
                                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            }
                        }
                    } else if (waitPakin.getWeight() == null) {
                        try {
                            LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
                            SearchLocParam param = new SearchLocParam();
                            param.setBarcode(barcode);
                            param.setIoType(105);
                            param.setSourceStaNo(inSta.getStaNo());
                            param.setLocType1(locTypeDto.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
                                    .setPath("/rpc/process/in/loc/v1")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
                            JSONObject jsonObject = JSON.parseObject(response);
                            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                            if (jsonObject.getInteger("code").equals(200)) {
                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                                barcodeThread.setBarcode("");
                                staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                                staProtocol.setStaNo(dto.getStaNo().shortValue());
                                devpThread.setPakMk(staProtocol.getSiteId(), false);
                                ledThread.errorReset();
                                boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                                if (!result) {
                                    throw new CoolException("更新plc站点信息失败");
                                }
                            } else if(jsonObject.getInteger("code").equals(700)) {
                                log.error(barcode + "托盘识别异常,请先进行组托!");
                                // led 异常显示
                                ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                                if (ledThread != null) {
                                    String errorMsg = barcode + "托盘识别异常,请先进行组托!";
                                    MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errorMsg));
                                }
                            } else {
                                log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/process/in/loc/v1", JSON.toJSONString(param), response);
                        WrkMastSta wrkMastSta = wrkMastStaService.selectOne(new EntityWrapper<WrkMastSta>().eq("wrk_no", staProtocol.getWorkNo().intValue()));
                        if (Cools.isEmpty(wrkMastSta)){
                            wrkMastSta = wrkMastStaService.selectOne(new EntityWrapper<WrkMastSta>().eq("wrk_no2", staProtocol.getWorkNo().intValue()));
                            if (Cools.isEmpty(wrkMastSta)){
                                throw new  CoolException("未找到对应的任务信息");
                            }
                        } catch (Exception e) {
                            log.error(""+e);
                            e.printStackTrace();
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            waitPakin.setWeight(wrkMastSta.getWeight2());
                        }else {
                            waitPakin.setWeight(wrkMastSta.getWeight());
                        }
                        waitPakinService.update(waitPakin,new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("io_status", "N"));
                    } else {
                        try {
                            LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
@@ -3683,7 +3732,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());
@@ -3702,6 +3751,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);
                            }
@@ -3731,12 +3785,13 @@
                    String response = new HttpHandler.Builder()
                            .setUri(wmsUrl)
                            .setPath("/rpc/process/loc/v1")
                            .setJson(JSON.toJSONString(""))
                            .build()
                            .doPost();
                    JSONObject jsonObject = JSON.parseObject(response);
                    if (jsonObject.getInteger("code").equals(200)) {
                        log.info("任务下发成功");
                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, null));
                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, null));
                    } else {
                        log.error("请求接口失败!!!url:{};response:{}", wmsUrl + "/mobile/comb/auth", response);
                    }
@@ -3755,6 +3810,11 @@
                if (!Cools.isEmpty(wrkDetls)) {
                    for (WrkDetl wrkDetl : wrkDetls) {
                        wrkDetl.setWeight(weight.doubleValue());
                        if (isHalf == 1) {
                            wrkDetl.setMemo("存在半桶");
                        } else {
                            wrkDetl.setMemo("不存在半桶");
                        }
                        wrkDetlService.updateById(wrkDetl);
                    }
                }
@@ -3794,6 +3854,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();