春风项目四线(合箱线、总装线)
yyt
2024-04-28 127f1bc6b4b204cb32462cc24ead9e7821afe095
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -21,7 +21,6 @@
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import javafx.animation.Timeline;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -141,7 +140,42 @@
            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 = "4";
                }
                //如果是返修工位需要传输返修工位号
                List<DaPassingStationCollection> daPassingStationCollections = new ArrayList<>();
                List<RmRepairRecord> rmRepairRecords = new ArrayList<>();
                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);
                    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";
                        }
                    }
                    RmRepairRecord rmRepairRecord = new RmRepairRecord();
                    rmRepairRecord.setBoxCode(SNCode);
                    rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord);
                    if (CollUtil.isNotEmpty(rmRepairRecords)){
                        a = "1";
                    }
                }
                log.info("-----返回codeCheckFeed-----,{}",a);
//                String a="1";
                // 1:OK可生产 2:NG不可生产 3:NG可返工 4:PC检索失败(无记录)5:PC检索失败(软件)
@@ -149,6 +183,8 @@
                    int input = Integer.parseInt(a);
                    ReadWriteEntity entity = new ReadWriteEntity(parts[0]+"."+parts[1]+".CodeCheckFeed", input);
                    log.info("-------监听到,{}的CodeCheck的信号",Node);
                    miloService.writeToOpcByte(entity);
                    log.info("监听到返回codecheckfeed信号,{}",entity);
                    //首站传输订单号
                    if (OPCElement.OP050_HX_CODE_CHECK.equals(Node)){
                        //查询订单号
@@ -167,123 +203,139 @@
                    //如果是返修工位需要传输返修工位号
                    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);
                        rework(SNCode,Node,daPassingStationCollections,rmRepairRecords);
                    }
                    System.out.println(entity);
                miloService.writeToOpcByte(entity);
                }
            }
        }
    }
    private void rework(String SNCode,String Node)  throws Exception{
    private void rework(String SNCode,String Node,List<DaPassingStationCollection> daPassingStationCollections,List<RmRepairRecord> rmRepairRecords)  throws Exception{
        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());
            }
        }
        RmRepairRecord rmRepairRecord = new RmRepairRecord();
        rmRepairRecord.setBoxCode(SNCode);
//        RmRepairRecord rmRepairRecord = new RmRepairRecord();
//        rmRepairRecord.setBoxCode(SNCode);
        List<ReadWriteEntity> writeList = new ArrayList<>();
        List<RmRepairRecord> rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord);
//        List<RmRepairRecord> rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord);
        //过站记录
        DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
        PassingStationCollection.setSfcCode(SNCode);
//        DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
//        PassingStationCollection.setSfcCode(SNCode);
        //过站记录
        List<DaPassingStationCollection> daPassingStationCollections = passingStationCollectionServiceImpl.selectDaPassingStationCollectionList(PassingStationCollection);
//        List<DaPassingStationCollection> daPassingStationCollections = passingStationCollectionServiceImpl.selectDaPassingStationCollectionList(PassingStationCollection);
        //所有反工工位
        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);
            }
            //获取过站记录的最大工位
            String maxCode = null;
            if (CollUtil.isNotEmpty(daPassingStationCollections)){
                DaPassingStationCollection lastOne = daPassingStationCollections.get(daPassingStationCollections.size() - 1);
                maxCode = lastOne.getLocationCode();
            }
            //所有放行工位
            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);
        }
        //所有放行工位
        //过站记录除去返修记录就是传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());
        }
        if (CollUtil.isNotEmpty(collect3)){
            collect3.forEach(x -> {
                ReadWriteEntity readWriteEntity = new ReadWriteEntity();
                readWriteEntity.setIdentifier(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(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[] parts = Node.split("[.]");
        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("Repair_sign");
        readWriteEntity.setValue(minOP);
        writeList.add(readWriteEntity);
        miloService.writeToOpcByte(writeList);
    }
    public void SaveData(String Node) throws Exception {
        String[] parts = Node.split("[.]");
        Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
        if (null == SNCodeObject){
@@ -313,12 +365,13 @@
                return nodeid;
            }).collect(Collectors.toList());
            if(!nodeIdList.isEmpty()){
            List<ReadWriteEntity> readWriteEntityList = new ArrayList<>();
            if(CollUtil.isNotEmpty(nodeIdList)){
                long time1 = new Date().getTime();
                List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
                readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
                long time2 = new Date().getTime();
                log.info("读取点位花费时间:{},",time2-time1);
            }
                //返回plc保存成功
                if (parts.length==3){
                    if ("SaveRequest".equals(parts[2])){
@@ -332,36 +385,50 @@
                    log.info("-------请求返回-----,{}",LocalDateTime.now());
                }
                List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
                for(int i=0;i<nodeIdList.size();i++){
                    if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){
                        DaParamCollection ParamCollection = new DaParamCollection();
                        ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]);
                        ParamCollection.setLocationCode(parts[1]);
                        if (readWriteEntityList.get(i) == null){
                            ParamCollection.setParamValue("0");
                        }else {
                            ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
                if (CollUtil.isNotEmpty(nodeIdList)){
                    for(int i=0;i<nodeIdList.size();i++){
                        if(ObjectUtil.isNotEmpty(readWriteEntityList.get(i).getValue()) && !readWriteEntityList.get(i).getValue().toString().equals("0.0")){
                            DaParamCollection ParamCollection = new DaParamCollection();
                            ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]);
                            ParamCollection.setLocationCode(parts[1]);
                            if (readWriteEntityList.get(i) == null){
                                ParamCollection.setParamValue("0");
                            }else {
                                ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
                            }
                            ParamCollection.setSfcCode(SNCode);
                            ParamCollection.setParamName(list.get(i).getCollectParameterName());
                            ParamCollection.setParamUpper(list.get(i).getParamUpper());
                            ParamCollection.setParamLower(list.get(i).getParamLower());
                            ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
                            ParamCollection.setState("合格");
                            ParamCollection.setType(list.get(i).getCollectParameterType());
                            ParamCollection.setCollectionTime(new Date());
                            daParamCollectionlist.add(ParamCollection);
                        }
                        ParamCollection.setSfcCode(SNCode);
                        ParamCollection.setParamName(list.get(i).getCollectParameterName());
                        ParamCollection.setParamUpper(list.get(i).getParamUpper());
                        ParamCollection.setParamLower(list.get(i).getParamLower());
                        ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
                        ParamCollection.setState("合格");
                        ParamCollection.setType(list.get(i).getCollectParameterType());
                        ParamCollection.setCollectionTime(new Date());
                        daParamCollectionlist.add(ParamCollection);
                    }
                    daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
                    log.info("-------保存数据完成---------");
                }
                daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
                log.info("-------保存数据完成---------");
            }
            Long beatTime = 0L;
            if (ObjectUtil.isNotEmpty(object)){
                String str = object.toString();
                beatTime = Float.valueOf(str).longValue();
            }
            Object ProductStatus = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".ProductStatus").getValue();
            log.info("ProductStatus,{}",ProductStatus.toString());
            String str1="合格" ;
            if (ObjectUtil.isNotEmpty(ProductStatus)){
                String productStatusString = ProductStatus.toString();
                if (productStatusString.contains("2") || productStatusString.contains("3")){
                    str1="不合格";
                }else {
                    str1="合格";
                }
            }
            DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
            PassingStationCollection.setSfcCode(SNCode);
@@ -371,7 +438,7 @@
            PassingStationCollection.setCollectionTime(new Date());
            PassingStationCollection.setCreateTime(new Date());
            PassingStationCollection.setBeatTime(beatTime.toString());
            PassingStationCollection.setOutRsSign("合格");
            PassingStationCollection.setOutRsSign(str1);
            passingStationCollectionServiceImpl.insertDaPassingStationCollection(PassingStationCollection);
            log.info("-------保存过站记录数据完成---------");