admin
2024-06-15 8cfe20288690f2ba46c804f41f39e8aa48c2dea0
jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -24,6 +24,8 @@
import com.jcdm.main.plcserver.conf.OPCElement;
import com.jcdm.main.plcserver.util.TimeUtil;
import com.jcdm.main.restful.factoryMes.service.RestfulService;
import com.jcdm.main.restful.qingYan.doman.ChildVO;
import com.jcdm.main.restful.qingYan.doman.ParentVO;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
@@ -35,6 +37,7 @@
import javax.websocket.Session;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
@@ -277,60 +280,61 @@
            if(nullList.stream().noneMatch(s -> s.equals(device))){
                if(moduleCodeList.stream().anyMatch(s -> s.equals(device))){
                    read = read + "ModuleCode";
                    if(device.equals("OP365")){
                        try {
//                            result = saveStationInfo365(thoroughfare,device);
//                            return result;
                            saveStationInfo365(thoroughfare,device);
//                            return result;
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }else {
                    read = read + "PACKCode";
                }
            }
            snCode = miloService.readFromOpcUa(read).getValue().toString();
            if(null == snCode || "".equals(snCode)){
                result = "22";
            }else{
                String workOrderNo = "";
                String productCode = "";
                //2、保存过站采集数据
                Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue();
                if(orderNumberObject!=null){
                    workOrderNo = orderNumberObject.toString();
                }
                Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue();
                if(productCodeObject!=null){
                    productCode = productCodeObject.toString();
                }
                saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode);
                //3、保存参数采集数据
                SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode);
                //如果是末尾工站要报工
                if(device.equals("OP500")){
                    RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date()));
                    //1、更新工单信息
                    updateOrderInfo(snCode);
                }
                try{
                    daParamCollectionService.pushGeelycvMesFeedback(snCode,device);
            if(device.equals("OP365")){
                try {
                    result = saveStationInfo365(thoroughfare,device);
                    return result;
//                    return saveStationInfo365(thoroughfare,device);
//                    return result;
                }catch (Exception e){
                    e.printStackTrace();
                }
                result = "21";
            }else {
                snCode = miloService.readFromOpcUa(read).getValue().toString();
                if(null == snCode || "".equals(snCode)){
                    result = "22";
                }else{
                    String workOrderNo = "";
                    String productCode = "";
                    //2、保存过站采集数据
                    Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue();
                    if(orderNumberObject!=null){
                        workOrderNo = orderNumberObject.toString();
                    }
                    Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue();
                    if(productCodeObject!=null){
                        productCode = productCodeObject.toString();
                    }
                    saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode);
                    //3、保存参数采集数据
                    List<DaParamCollection> daParamCollectionList = SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode);
                    //如果是末尾工站要报工
                    if(device.equals("OP500")){
                        RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date()));
                        //1、更新工单信息
                        updateOrderInfo(snCode);
                    }
                    try{
                        daParamCollectionService.automaticWorkstationPushGeelycvMesFeedback(snCode,device,daParamCollectionList);
                    }catch (Exception e){
                    }
                    result = "21";
                }
            }
        }catch (Exception e) {
            System.out.println(e.getMessage());
            logger.error("出站保存数据异常:"+e);
        }
        return result;
    }
@@ -390,11 +394,12 @@
        daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection);
    }
    public static void SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception {
    public static List<DaParamCollection> SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception {
        List<DaCollectionParamConf> list;
        DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
        daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device);
        list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
        List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
        List<String> nodeIdList = list.stream().map(info -> {
            String nodeid = info.getGatherAddress();
@@ -408,11 +413,12 @@
                    readWriteEntityList.get(i).setValue(" ");
                }
            }
            List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
            for(int i=0;i<nodeIdList.size();i++){
                if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){
                    String tt = readWriteEntityList.get(i).getValue().toString();
                    DaParamCollection ParamCollection = new DaParamCollection();
                    ChildVO childVO = new ChildVO();
                    ParamCollection.setParamCode(list.get(i).getCollectParameterId());
                    ParamCollection.setLocationCode(device);
                    if(tt.contains("Time")){
@@ -444,12 +450,16 @@
                }
            }
            daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
        }
        addBaseData(workOrderNo,productType,device,packCode);
        }
        List<DaParamCollection> baseDataList = addBaseData(workOrderNo,productType,device,packCode);
        for (int i = 0; i < baseDataList.size(); i++){
            daParamCollectionlist.add(baseDataList.get(i));
        }
        return daParamCollectionlist;
    }
    public static void addBaseData(String workOrderNo,String productCode,String locationCode,String packCode){
    public static List<DaParamCollection> addBaseData(String workOrderNo,String productCode,String locationCode,String packCode){
        Map<String, String> map = new HashMap<>();
        map.put("GC", "南浔工厂");
        map.put("CXBH", "Pack线");
@@ -472,6 +482,7 @@
            confList.add(saveData);
        });
        daParamCollectionService.insertBatch(confList);
        return confList;
    }
    public static void getFactoryOrder(String locationCode){
@@ -555,7 +566,7 @@
    /**
     * 保存过站采集
     */
    public void saveStationInfo365(String thoroughfare,String device) throws Exception {
    public String saveStationInfo365(String thoroughfare,String device) throws Exception {
        String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
        String prefix = thoroughfare+"."+device+".";
        List<DaPassingStationCollection> passingStationCollections = new ArrayList<>();
@@ -592,11 +603,11 @@
                passingStationCollections.add(daPassingStationCollection);
            }
            daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections);
            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
//            return "21";
//            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
            return "21";
        }else {
            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build());
//            return "22";
//            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build());
            return "22";
        }
    }