#
1
2025-12-19 aa6c2d4ed63195e007b44007c29547f1d66c7b49
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -114,6 +114,8 @@
    @Autowired
    private BasDevpOptService basDevpOptService;
    @Autowired
    private BasRgvOptService basRgvOptService;
    @Autowired
    private MatService matService;
    @Value("${wms.url}")
@@ -2964,13 +2966,13 @@
            StaProtocol staProtocol = null;
            if(emptyCount >= 2 && site == 1108){
                continue;
            }else if(emptyCount > 1 && site == 2031){
            }else if(emptyCount > 0 && site == 2031){
                continue;
            }
            //如果站点可出禁用,则不生成空盘出库任务
            switch (site){
                case 1108:staProtocol = devpThread.getStation().get(site - 2);break;
                case 2031:staProtocol = devpThread2.getStation().get(site);break;
                case 2031:staProtocol = devpThread2.getStation().get(site + 1);break;
            }
            if (staProtocol == null) {
                return;
@@ -3722,9 +3724,14 @@
            }
            if(rgvProtocol.getStatusType1() == RgvStatusType.IDLE &&
                    rgvProtocol.getModeType() == RgvModeType.AUTO && rgvThread.isPakMk()
                    && rgvThread.isPaking() && basRgv.getPakAll().equals("1")){
            RgvThread rgvThread1 = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgv.getId());
            RgvProtocol rgvProtocol1 = rgvThread.getRgvProtocol();
            if (rgvProtocol1 == null) {
                continue;
            }
            if(rgvProtocol1.getStatusType1() == RgvStatusType.IDLE &&
                    rgvProtocol1.getModeType() == RgvModeType.AUTO && rgvThread1.isPakMk()
                    && rgvThread1.isPaking() && basRgv.getPakAll().equals("1")){
                if(basRgv.getPakOut().equals("1") && basRgv.getPakIn().equals("1")){
                    rgvPreSchedulingIn(rgv, rgvProtocol);//若暂无下发任务预调度提前到取货点
                    if (rgvProtocol.getLastIo().equals("I")) {
@@ -4455,34 +4462,34 @@
            }
            //遍历rgv入库取货站点
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, rgvStn.getDevpPlcId());
            StaProtocol staProtocol = devpThread.getStation().get(rgvStn.getStaNo2()); //倒数第二个
            StaProtocol staProtocol = devpThread.getStation().get(rgvStn.getStaNo2()==1043?1044:1103); //倒数第二个
            StaProtocol staProtocol2 = null;  //连续取货任务站点
            RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, (int) rgvProtocol.getRgvNo());
            WrkMastSta wrkMastSta3 = null;//连取两个
            Integer staNo = null;  //与调度
            switch (rgvStn.getStaNo2()){
                case 1043: staNo = 1044;break;
                case 1104: staNo = 1103;break;
            }
            if(staNo != null ){
                staProtocol2 = devpThread.getStation().get(staNo);
                if (staProtocol2 == null) {
                    News.infoNoLog(" - Rgv入库站信息(staProtocol!=null继续执行):staProtocol=" + staProtocol);
                    continue;
                } else {
                    staProtocol2 = staProtocol2.clone();
                }
                BasDevp staDetl2 = basDevpService.selectById(rgvStn.getStaNo2());
                if (staDetl2 == null) {
                    News.error(" - 入库 ===>>Rgv站点在数据库不存在, 站点编号={}", rgvStn.getStaNo());
                    continue;
                }
                if((staProtocol.getWorkNo()>9999 && staProtocol2.getWorkNo()>9999) || (staProtocol.getWorkNo()<10000 && staProtocol2.getWorkNo()<10000)){
                    //当连续取货站点为相同类型时才能连续取
                    wrkMastSta3 = wrkMastStaMapper.selectByWrkNo(staProtocol2.getWorkNo());
                }
            }
//            WrkMastSta wrkMastSta3 = null;//连取两个
//            Integer staNo = null;  //与调度
//            switch (rgvStn.getStaNo2()){
//                case 1043: staNo = 1044;break;
//                case 1104: staNo = 1103;break;
//            }
//            if(staNo != null ){
//                staProtocol2 = devpThread.getStation().get(staNo);
//                if (staProtocol2 == null) {
//                    News.infoNoLog(" - Rgv入库站信息(staProtocol!=null继续执行):staProtocol=" + staProtocol);
//                    continue;
//                } else {
//                    staProtocol2 = staProtocol2.clone();
//                }
//                BasDevp staDetl2 = basDevpService.selectById(rgvStn.getStaNo2());
//                if (staDetl2 == null) {
//                    News.error(" - 入库 ===>>Rgv站点在数据库不存在, 站点编号={}", rgvStn.getStaNo());
//                    continue;
//                }
//                if((staProtocol.getWorkNo()>9999 && staProtocol2.getWorkNo()>9999) || (staProtocol.getWorkNo()<10000 && staProtocol2.getWorkNo()<10000)){
//                    //当连续取货站点为相同类型时才能连续取
//                    wrkMastSta3 = wrkMastStaMapper.selectByWrkNo(staProtocol2.getWorkNo());
//                }
//
//            }
            if(rgvProtocol.getTaskNo2() > 9999 && staProtocol.getWorkNo() < 10000){
                continue;
            }
@@ -4543,21 +4550,21 @@
            sign = rgvTakeFullAll(basRgvMap.getRgvNo(), wrkMastSta); //命令下发
            if (sign){
                if(wrkMastSta3 != null ){
                    List<WrkMastSta> wrkMastStaPaking = wrkMastStaService.selectPakingWrk(wrkMastSta3.getStaStart());
                    if(wrkMastStaPaking.size() < 1 && !wrkMastSta3.getWrkNo().equals(wrkMastSta.getWrkNo())){//已有标记不再标记
                        wrkMastSta3.setMk(1);
                        basRgv.setPakAll("0");
                        basRgvService.updateById(basRgv);
                        try{
                            wrkMastStaMapper.updateById(wrkMastSta3);
                            log.error("锁定相隔站点任务");
                        }catch (Exception e){
                            log.error("锁定相隔站点任务失败");
                        }
                    }
                }
//                if(wrkMastSta3 != null ){
//                    List<WrkMastSta> wrkMastStaPaking = wrkMastStaService.selectPakingWrk(wrkMastSta3.getStaStart());
//                    if(wrkMastStaPaking.size() < 1 && !wrkMastSta3.getWrkNo().equals(wrkMastSta.getWrkNo())){//已有标记不再标记
//                        wrkMastSta3.setMk(1);
//                        basRgv.setPakAll("0");
//                        basRgvService.updateById(basRgv);
//
//                        try{
//                            wrkMastStaMapper.updateById(wrkMastSta3);
//                            log.error("锁定相隔站点任务");
//                        }catch (Exception e){
//                            log.error("锁定相隔站点任务失败");
//                        }
//                    }
//                }
                basRgv.setPakOut("0");//出库不允许
                basRgvService.updateById(basRgv);
                rgvThread.setPaking(false);//任务下发锁定
@@ -4600,6 +4607,21 @@
            if (targetPosition == 1038) {
                System.out.println("小车下发命令时间:" +
                        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(now));
            }
            EntityWrapper<BasRgvOpt> entityWrapper = new EntityWrapper<>();
            entityWrapper.eq("rgv_no", rgvId)
                    .orderBy("send_time");  // 按 send_time 降序排列
            BasRgvOpt basRgvOpt = basRgvOptService.selectOne(entityWrapper);
            // 防止重复下发命令
            if (basRgvOpt != null) {
                // 获取最新记录的 mode 对应的任务类型
                RgvTaskStatusType latestTaskStatus = RgvTaskStatusType.valueOf(basRgvOpt.getMode());
                // 判断当前命令与最新记录是否相同
                if (latestTaskStatus != null && latestTaskStatus == type && basRgvOpt.getPosSta().equals(wrkMastSta.getWorkSta())) {
                    // 如果最新记录的 mode 和 posSta 与当前命令相同,认为是重复命令
                    log.error("命令重复下发,当前命令与最新记录相同,任务不下发!");
                    return false;
                }
            }
            rgvCommand.setTaskNo(Math.toIntExact(wrkMastSta.getWrkNo())); // 工位工作号
@@ -4749,20 +4771,26 @@
                    // 获取站点信息
                    SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(armSta.getStaNo());
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    StaProtocol staProtocol = null;
                    String barcode = null;
                    // 可以轮询读取,确保条码稳定不变
                    for(int retry=0; retry<3; retry++){
                        staProtocol = devpThread.getStation().get(armSta.getStaNo());
                        barcode = staProtocol.getBarcode();
                        if (staProtocol == null) {
                            continue;
                        } else {
                            staProtocol = staProtocol.clone();
                        }
                        Thread.sleep(150); // 小延时等待PLC刷新
                    }
                    String barcode = staProtocol.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "0".equals(barcode) || barcode.length()<5) {
                            armTaskAssignmentCallApiLogSave(staProtocol, "托盘条码为空", staProtocol.getSiteId()+"码垛位置,===》托盘条码为空", false);
                            armTaskAssignmentCallApiLogSave(staProtocol, "拆垛条码为空", staProtocol.getSiteId()+"码垛位置,===》托盘条码为空", false);
                            continue;
                        }
                    } else {
                        armTaskAssignmentCallApiLogSave(staProtocol, "托盘条码为空", staProtocol.getSiteId()+"码垛位置,===》托盘条码为空", false);
                        armTaskAssignmentCallApiLogSave(staProtocol, "拆垛条码为空", staProtocol.getSiteId()+"码垛位置,===》托盘条码为空", false);
                        continue;
                    }
                    String[] barcodeList = barcode.split(";");
@@ -4792,9 +4820,9 @@
                    List<BasArm> basArmList = basArmService.selectList(new EntityWrapper<BasArm>().eq("arm_no",armSta.getArmNo()));
                    boolean sign = true;
                    for (BasArm basArm : basArmList){
                        if (basArm.getStaNo()==2){//NG
                            continue;
                        }
//                        if (basArm.getStaNo()==2){//NG
//                            continue;
//                        }
                        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", basArm.getStaNoSou()));
                        if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("D")){
                            continue;
@@ -4820,22 +4848,22 @@
                        sign = false;
                        break;
                    }
                    if (sign){
                        for (BasArm basArm : basArmList){
                            if (basArm.getStaNo()==2){//NG
                                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", basArm.getStaNoSou()));
                                if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("D")){
                                    continue;
                                }
                                BasArmMast basArmMast = new BasArmMast(armBarcodeTwoParam);
                                basArmMast.setArmNo(basArm.getArmNo());
                                basArmMast.setStaNo(basArm.getStaNoSou());
                                basArmMast.setSortingLine(basArm.getSortingLineSou());
                                basArmMastService.insert(basArmMast);
                                break;
                            }
                        }
                    }
//                    if (sign){
//                        for (BasArm basArm : basArmList){
//                            if (basArm.getStaNo()==2){//NG
//                                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", basArm.getStaNoSou()));
//                                if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("D")){
//                                    continue;
//                                }
//                                BasArmMast basArmMast = new BasArmMast(armBarcodeTwoParam);
//                                basArmMast.setArmNo(basArm.getArmNo());
//                                basArmMast.setStaNo(basArm.getStaNoSou());
//                                basArmMast.setSortingLine(basArm.getSortingLineSou());
//                                basArmMastService.insert(basArmMast);
//                                break;
//                            }
//                        }
//                    }
                }
            }
        } catch (Exception e){
@@ -5123,11 +5151,11 @@
                    String barcode = locMastEnd.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "0".equals(barcode)) {
                            armTaskAssignmentCallApiLogSave(locMastEnd, "托盘条码为空", basArm.getStaNoSou()+"码垛位置,===》托盘条码为空", false);
                            armTaskAssignmentCallApiLogSave(locMastEnd, "取货条码为空", basArm.getStaNoSou()+"码垛位置,===》托盘条码为空", false);
                            continue;
                        }
                    } else {
                        armTaskAssignmentCallApiLogSave(locMastEnd, "托盘条码为空", basArm.getStaNoSou()+"码垛位置,===》托盘条码为空", false);
                        armTaskAssignmentCallApiLogSave(locMastEnd, "取货条码为空", basArm.getStaNoSou()+"码垛位置,===》托盘条码为空", false);
                        continue;
                    }