春风项目四线(合箱线、总装线)
wujian
2024-04-28 929bdcf5898f03820d9d2ba62005e32a0a0ded14
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -141,7 +141,33 @@
            Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
            if(null != SNCodeObject) {
                String SNCode=SNCodeObject.toString();
                String a=passingStationCollectionServiceImpl.SelectSN(SNCode,parts[1]);
//                String a=passingStationCollectionServiceImpl.SelectSN(SNCode,parts[1]);
                String a;
                BsOrderScheduling bsOrderSchedulingQuery = new BsOrderScheduling();
                bsOrderSchedulingQuery.setEngineNo(SNCode);
                List<BsOrderScheduling> queryOrderList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderSchedulingQuery);
                if (CollUtil.isNotEmpty(queryOrderList)){
                    a = "1";
                }else {
                    a = "5";
                }
                //如果是返修工位需要传输返修工位号
                if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node)
                        || OPCElement.OP695_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){
                    //过站记录
                    DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
                    PassingStationCollection.setSfcCode(SNCode);
                    List<DaPassingStationCollection> daPassingStationCollections = passingStationCollectionServiceImpl.selectDaPassingStationCollectionList(PassingStationCollection);
                    if (CollUtil.isNotEmpty(daPassingStationCollections)){
                        DaPassingStationCollection lastOne = daPassingStationCollections.get(daPassingStationCollections.size() - 1);
                        String outRsSign = lastOne.getOutRsSign();
                        if ("合格".equals(outRsSign)){
                            a = "1";
                        }else {
                            a = "2";
                        }
                    }
                }
                log.info("-----返回codeCheckFeed-----,{}",a);
//                String a="1";
                // 1:OK可生产 2:NG不可生产 3:NG可返工 4:PC检索失败(无记录)5:PC检索失败(软件)
@@ -169,6 +195,7 @@
                    //如果是返修工位需要传输返修工位号
                    if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node)
                    || OPCElement.OP695_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){
                        rework(SNCode,Node);
                    }
                    System.out.println(entity);
@@ -183,11 +210,12 @@
        BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
        bsOrderScheduling.setEngineNo(SNCode);
        List<String> allProcessCoed = new ArrayList<>();
        List<BsTechnologyRouteChildInfo> bsTechnologyRouteChildInfos = new ArrayList<>();
        List<String> collect = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling).stream().map(BsOrderScheduling::getModel).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(collect)){
            String s = collect.get(0);
            //查找次机型的完整工序
            List<BsTechnologyRouteChildInfo> bsTechnologyRouteChildInfos = bsTechnologyRouteChildInfoService.selectAllTechnologyRouteByProductCode(s);
            bsTechnologyRouteChildInfos = bsTechnologyRouteChildInfoService.selectAllTechnologyRouteByProductCode(s);
            if (CollUtil.isNotEmpty(bsTechnologyRouteChildInfos)){
                allProcessCoed = bsTechnologyRouteChildInfos.stream().map(BsTechnologyRouteChildInfo::getProcessesCode).collect(Collectors.toList());
            }
@@ -204,104 +232,97 @@
        //所有反工工位
        List<String> collect1 = rmRepairRecords.stream().map(RmRepairRecord::getProcessesCode).collect(Collectors.toList());
        //查询出所有需要返修工位的最小op块
        Integer minOP = 0;
        if (CollUtil.isNotEmpty(collect1)){
            //查询出所有需要返修工位的最小op块
            Integer minOP = 0;
            if (CollUtil.isNotEmpty(collect1)){
            List<Integer> sortList = new ArrayList<>();
            collect1.stream().forEach(x ->{
                String op = x.replace("OP", "");
                if (StrUtil.isNotBlank(op)){
                    int i = Integer.parseInt(op);
                    sortList.add(i);
                List<Integer> sortList = new ArrayList<>();
                collect1.stream().forEach(x ->{
                    String op = x.replace("OP", "");
                    if (StrUtil.isNotBlank(op)){
                        int i = Integer.parseInt(op);
                        sortList.add(i);
                    }
                });
                if (CollUtil.isNotEmpty(sortList)){
                    List<Integer> collect2 = sortList.stream().filter(Objects::nonNull).sorted().collect(Collectors.toList());
                    minOP = collect2.get(0);
                }
            });
            if (CollUtil.isNotEmpty(sortList)){
                List<Integer> collect2 = sortList.stream().sorted().collect(Collectors.toList());
                minOP = collect2.get(0);
            }
        }
        //所有放行工位
        //过站记录除去返修记录就是传2,返修数据及后面占位数据传1
        List<String> collect3 = daPassingStationCollections.stream().map(DaPassingStationCollection::getLocationCode).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(collect1)){
            collect3 = collect3.stream().filter(x -> !collect1.contains(x)).collect(Collectors.toList());
        }
        String[] parts = Node.split("[.]");
        String par = parts[0]+"."+parts[1];
        if (CollUtil.isNotEmpty(collect3)){
            collect3.forEach(x -> {
                ReadWriteEntity readWriteEntity = new ReadWriteEntity();
                readWriteEntity.setIdentifier(par+"."+x);
                readWriteEntity.setValue(2);
                writeList.add(readWriteEntity);
            });
        }
        //需生产工位
        List<String> collect4 = allProcessCoed;
        if (CollUtil.isNotEmpty(collect3)){
            List<String> finalCollect = collect3;
            collect4 = allProcessCoed.stream().filter(x -> !finalCollect.contains(x)).collect(Collectors.toList());
        }
        if (CollUtil.isNotEmpty(collect4)){
            //数据库查询出的工位
            collect4.forEach(x -> {
                ReadWriteEntity readWriteEntity = new ReadWriteEntity();
                readWriteEntity.setIdentifier(par+"."+x);
                readWriteEntity.setValue(1);
                writeList.add(readWriteEntity);
            });
        }
//        List<String> collect2 = allProcessCoed;
//        if (CollUtil.isNotEmpty(rmRepairRecords)){
//            //数据库查询出的工位
//            rmRepairRecords.forEach(x -> {
//                ReadWriteEntity readWriteEntity = new ReadWriteEntity();
//                readWriteEntity.setIdentifier(x.getProcessesCode());
//                readWriteEntity.setValue(1);
//                writeList.add(readWriteEntity);
//            });
//            collect2 = allProcessCoed.stream().filter(x -> !collect1.contains(x)).collect(Collectors.toList());
//        }
//        if (CollUtil.isNotEmpty(collect2)){
//            collect2.forEach(x -> {
//                ReadWriteEntity readWriteEntity = new ReadWriteEntity();
//                readWriteEntity.setIdentifier(x);
//                readWriteEntity.setValue(2);
//                writeList.add(readWriteEntity);
//            });
//        }
//        String a=passingStationCollectionServiceImpl.SelectSN(SNCode,parts[1]);
//        if (StrUtil.isNotBlank(a)){
//            int input = Integer.parseInt(a);
//            ReadWriteEntity entity = new ReadWriteEntity(parts[0]+"."+parts[1]+".CodeCheckFeed", input);
//            writeList.add(entity);
//        }
        ReadWriteEntity readWriteEntity = new ReadWriteEntity();
        readWriteEntity.setIdentifier(parts[0]+"."+parts[1]+".Repair_sign");
        readWriteEntity.setValue(minOP);
        miloService.writeToOpcShort(readWriteEntity);
        /*if (CollUtil.isNotEmpty(writeList)){
            List<ReadWriteEntity> tempList = new ArrayList<>();
            for (int i = 0; i < writeList.size(); i++) {
                miloService.writeToOpc();
//                tempList.add(writeList.get(i));
//                if (tempList.size()>10){
//                    miloService.writeToOpcByte(tempList);
//                    log.info("写入返修:,{}",tempList);
//                    tempList = new ArrayList<>();
//                }
            //获取过站记录的最大工位
            String maxCode = null;
            if (CollUtil.isNotEmpty(daPassingStationCollections)){
                DaPassingStationCollection lastOne = daPassingStationCollections.get(daPassingStationCollections.size() - 1);
                maxCode = lastOne.getLocationCode();
            }
//            if (CollUtil.isNotEmpty(tempList)){
//                miloService.writeToOpcByte(tempList);
//                log.info("写入返修:,{}",tempList);
//            }
        }*/
        miloService.writeToOpcByte(writeList);
            //所有放行工位
            List<String> passStation = new ArrayList<>();
            //所有生产工位
            List<String> productStation = new ArrayList<>();
            //最大工位编号
            Integer maxCodeNum = 0;
            if (StrUtil.isNotEmpty(maxCode)){
                String finalMaxCode = maxCode;
                //获取当前工位对应工步号
                List<String> collect2 = bsTechnologyRouteChildInfos.stream()
                        .filter(x -> x.getProcessesCode().equals(finalMaxCode))
                        .map(BsTechnologyRouteChildInfo::getStepNo).collect(Collectors.toList());
                if (CollUtil.isNotEmpty(collect2)){
                    String s = collect2.get(0);
                    if (StrUtil.isNotBlank(s)){
                        maxCodeNum = Integer.parseInt(s);
                    }
                }
                if (CollUtil.isNotEmpty(bsTechnologyRouteChildInfos)){
                    bsTechnologyRouteChildInfos.forEach(x -> {
                        x.setStepNoNum(Integer.parseInt(x.getStepNo()));
                    });
                    Integer finalMaxCodeNum = maxCodeNum;
                    //勾选的返修工位中最大的工位之后的工位----1
                    List<BsTechnologyRouteChildInfo> collect3 = bsTechnologyRouteChildInfos.stream()
                            .filter(x -> x.getStepNoNum() >= finalMaxCodeNum).collect(Collectors.toList());
                    if (CollUtil.isNotEmpty(collect3)){
                        //需要生产
                        productStation.addAll(collect3.stream().map(BsTechnologyRouteChildInfo::getProcessesCode).collect(Collectors.toList()));
                    }
                    //从第一个工位到返修的最大工位之间,
                    //勾选了返修标记的需要生产---1,未勾选的不生产---2
                    productStation.addAll(collect1);
                }
            }
            if (CollUtil.isNotEmpty(productStation)){
                List<String> collect2 = allProcessCoed.stream().filter(x -> !productStation.contains(x)).collect(Collectors.toList());
                passStation.addAll(collect2);
            }
            String[] parts = Node.split("[.]");
            String par = parts[0]+"."+parts[1];
            if (CollUtil.isNotEmpty(passStation)){
                passStation.forEach(x -> {
                    ReadWriteEntity readWriteEntity = new ReadWriteEntity();
                    readWriteEntity.setIdentifier(par+"."+x);
                    readWriteEntity.setValue(2);
                    writeList.add(readWriteEntity);
                });
            }
            if (CollUtil.isNotEmpty(productStation)){
                productStation.forEach(x -> {
                    ReadWriteEntity readWriteEntity = new ReadWriteEntity();
                    readWriteEntity.setIdentifier(par+"."+x);
                    readWriteEntity.setValue(1);
                    writeList.add(readWriteEntity);
                });
            }
            ReadWriteEntity readWriteEntity = new ReadWriteEntity();
            readWriteEntity.setIdentifier(parts[0]+"."+parts[1]+".Repair_sign");
            readWriteEntity.setValue(minOP);
            miloService.writeToOpcShort(readWriteEntity);
            miloService.writeToOpcByte(writeList);
            log.info("返修写入:,{}",writeList);
        }
    }