hdy
2024-07-10 a4362dfe3e0e9c6fad426685da0065455799d018
提交 | 用户 | 时间
8069b5 1 package com.jcdm.main.plcserver.callback;
H 2 import cn.hutool.core.collection.CollUtil;
3 import cn.hutool.core.util.StrUtil;
4 import com.jcdm.common.core.domain.BaseEntity;
5 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
6 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
7 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
8 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
9 import com.jcdm.main.da.passingStationCollection.service.impl.DaPassingStationCollectionServiceImpl;
10 import com.jcdm.main.da.tileMatchRules.service.IDaTileMatchRulesService;
11 import com.kangaroohy.milo.model.ReadWriteEntity;
12 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
13 import com.kangaroohy.milo.service.MiloService;
14 import lombok.extern.slf4j.Slf4j;
15 import org.apache.commons.lang3.ObjectUtils;
16 import org.springframework.stereotype.Component;
17 import java.util.ArrayList;
18 import java.util.Comparator;
19 import java.util.Date;
20 import java.util.List;
21 import java.util.stream.Collectors;
22
23 @Slf4j
24 @Component
25 public class InitCallback implements SubscriptionCallback {
26
27     public static MiloService miloService;
28
29     public IDaCollectionParamConfService collectionParamConfService;
30
31     public IDaParamCollectionService daParamCollectionService;
32
33     public DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl;
34
35     public IDaTileMatchRulesService daTileMatchRulesService;
36     ;
37
38     public InitCallback(MiloService miloService,
39                         IDaCollectionParamConfService collectionParamConfService,
40                         IDaParamCollectionService daParamCollectionService,
41                         DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl,
42                         IDaTileMatchRulesService daTileMatchRulesService) {
43         InitCallback.miloService = miloService;
44         this.collectionParamConfService = collectionParamConfService;
45         this.daParamCollectionService = daParamCollectionService;
46         this.passingStationCollectionServiceImpl = passingStationCollectionServiceImpl;
47         this.daTileMatchRulesService = daTileMatchRulesService;
48
49     }
50
51
52     @Override
53     public void onSubscribe(String identifier, Object value) {
54         String ecpStr = "";//异常记录标记
55         try {
56             if (null != value) {
a4362d 57                 //BCOP010出站校验
H 58                 if (identifier.equals("CFL4CVT.BCOP010.RecordData") && null != value && "2".equals(value.toString())) {
59                     ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP010.MesRecordDataDone", 21);
60                     miloService.writeToOpcShort(entity);
8069b5 61                 }
H 62                 //BCOP40出站校验
63                 else if (identifier.equals("CFL4CVT.BCOP040.RecordData") && null != value && "2".equals(value.toString())) {
a4362d 64                     SaveData("CFL4CVT.BCOP040.RecordData");
8069b5 65                 }
H 66                 //BCOP60出站校验
67                 else if (identifier.equals("CFL4CVT.BCOP060.RecordData") && null != value && "2".equals(value.toString())) {
68                     SaveData("CFL4CVT.BCOP060.RecordData");
69                 }
70                 //BCOP100出站校验
71                 else if (identifier.equals("CFL4CVT.BCOP100.RecordData") && null != value && "2".equals(value.toString())) {
72                     SaveData("CFL4CVT.BCOP100.RecordData");
a4362d 73
8069b5 74                 }
H 75                 //BP020出站校验
76                 else if (identifier.equals("CFL4CVT.BP020.RecordData") && null != value && "2".equals(value.toString())) {
77                     SaveData("CFL4CVT.BP020.RecordData");
a4362d 78                 }
H 79                 else if(identifier.equals("CFL4CVT.OP220.RecordData") && null != value && "2".equals(value.toString())) {
80                     ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.OP220.MesRecordDataDone", 21);
81                     miloService.writeToOpcShort(entity);
8069b5 82                 }
H 83
84             }
85         } catch (Exception e) {
86
87         } finally {
88             if (!"".equals(ecpStr)) {
89                 System.out.println(ecpStr + "\r\n");
90
91             }
92         }
93     }
94
a4362d 95 //    public void SaveData(String Node) throws Exception {
H 96 //        String[] parts = Node.split("[.]");
97 //        Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
98 //
99 //        if (null != SNCodeObject) {
100 //            String SNCode = SNCodeObject.toString();
101 //            List<DaCollectionParamConf> list;
102 //            DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
103 //            daCollectionParamConf.setGatherAddress(parts[0] + "." + parts[1]);
104 //            list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
105 //
106 //            List<String> nodeIdList = list.stream().map(info -> {
107 //                String nodeid = info.getGatherAddress();
108 //                return nodeid;
109 //            }).collect(Collectors.toList());
110 //
111 //            if (!nodeIdList.isEmpty()) {
112 //                List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
113 //                List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
114 //                for (int i = 0; i < nodeIdList.size(); i++) {
115 //                    DaParamCollection ParamCollection = new DaParamCollection();
116 //                    if (!readWriteEntityList.get(i).getValue().toString().equals("0.0")) {
117 //                        ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]);
118 //                        ParamCollection.setLocationCode(parts[1]);
119 //                        Object value = readWriteEntityList.get(i).getValue();
120 //                        if (ObjectUtils.isNotEmpty(value)) {
121 //                            String string = value.toString();
122 //                            ParamCollection.setParamValue(string);
123 //                        }
124 //                        ParamCollection.setSfcCode(SNCode);
125 //                        ParamCollection.setParamName(list.get(i).getCollectParameterName());
126 //                        ParamCollection.setParamUpper(list.get(i).getParamUpper());
127 //                        ParamCollection.setParamLower(list.get(i).getParamLower());
128 //                        ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
129 //                        ParamCollection.setState("合格");
130 //                        ParamCollection.setType(list.get(i).getCollectParameterType());
131 //                        ParamCollection.setCollectionTime(new Date());
132 //                        daParamCollectionlist.add(ParamCollection);
133 //                    }
134 //                }
135 //                daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
136 //            }
137 //        }
138 //    }
139
8069b5 140     public void SaveData(String Node) throws Exception {
H 141         String[] parts = Node.split("[.]");
a4362d 142         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".RecordData").getValue();
H 143         if(null != SNCodeObject)
144         {
8069b5 145             String SNCode = SNCodeObject.toString();
H 146             List<DaCollectionParamConf> list;
147             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
148             daCollectionParamConf.setGatherAddress(parts[0] + "." + parts[1]);
149             list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
150
151             List<String> nodeIdList = list.stream().map(info -> {
152                 String nodeid = info.getGatherAddress();
153                 return nodeid;
154             }).collect(Collectors.toList());
155
a4362d 156             if(!nodeIdList.isEmpty()){
8069b5 157                 List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
H 158                 List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
a4362d 159                 for(int i=0;i<nodeIdList.size();i++){
8069b5 160                     DaParamCollection ParamCollection = new DaParamCollection();
a4362d 161                     if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){
8069b5 162                         ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]);
H 163                         ParamCollection.setLocationCode(parts[1]);
a4362d 164                         ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
8069b5 165                         ParamCollection.setSfcCode(SNCode);
H 166                         ParamCollection.setParamName(list.get(i).getCollectParameterName());
167                         ParamCollection.setParamUpper(list.get(i).getParamUpper());
168                         ParamCollection.setParamLower(list.get(i).getParamLower());
169                         ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
170                         ParamCollection.setState("合格");
171                         ParamCollection.setType(list.get(i).getCollectParameterType());
172                         ParamCollection.setCollectionTime(new Date());
173                         daParamCollectionlist.add(ParamCollection);
174                     }
175                 }
176                 daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
a4362d 177                 ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1]   +".MesRecordDataDone", 21);
H 178                 miloService.writeToOpcShort(entity);
8069b5 179             }
H 180         }
181     }
182
183
184 }