提交 | 用户 | 时间
|
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) { |
|
57 |
//BCOP40进站校验 |
|
58 |
if (identifier.equals("CFL4CVT.BCOP040.RecordData") && null != value && "1".equals(value.toString())) { |
|
59 |
//待添加从过站采集表取sfc_code写入plc的sncode方法 |
|
60 |
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP040.MesRecordDataDone", 11); |
|
61 |
miloService.writeToOpcByte(entity); |
|
62 |
} |
|
63 |
//BCOP40出站校验 |
|
64 |
else if (identifier.equals("CFL4CVT.BCOP040.RecordData") && null != value && "2".equals(value.toString())) { |
|
65 |
SaveData("CFL4CVT.BCOP40.RecordData"); |
|
66 |
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP040.MesRecordDataDone", 21); |
|
67 |
miloService.writeToOpcByte(entity); |
|
68 |
} |
|
69 |
//BCOP60进站校验 |
|
70 |
else if (identifier.equals("CFL4CVT.BCOP060.RecordData") && null != value && "1".equals(value.toString())) { |
|
71 |
//待添加从过站采集表取sfc_code写入plc的sncode方法 |
|
72 |
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP060.MesRecordDataDone", 11); |
|
73 |
miloService.writeToOpcByte(entity); |
|
74 |
} |
|
75 |
//BCOP60出站校验 |
|
76 |
else if (identifier.equals("CFL4CVT.BCOP060.RecordData") && null != value && "2".equals(value.toString())) { |
|
77 |
SaveData("CFL4CVT.BCOP060.RecordData"); |
|
78 |
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP060.MesRecordDataDone", 21); |
|
79 |
miloService.writeToOpcByte(entity); |
|
80 |
} |
|
81 |
//BCOP100进站校验 |
|
82 |
else if (identifier.equals("CFL4CVT.BCOP100.RecordData") && null != value && "1".equals(value.toString())) { |
|
83 |
//待添加从过站采集表取sfc_code写入plc的sncode方法 |
|
84 |
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP100.MesRecordDataDone", 11); |
|
85 |
miloService.writeToOpcByte(entity); |
|
86 |
} |
|
87 |
//BCOP100出站校验 |
|
88 |
else if (identifier.equals("CFL4CVT.BCOP100.RecordData") && null != value && "2".equals(value.toString())) { |
|
89 |
SaveData("CFL4CVT.BCOP100.RecordData"); |
|
90 |
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP100.MesRecordDataDone", 21); |
|
91 |
miloService.writeToOpcByte(entity); |
|
92 |
}//BP020进站校验 |
|
93 |
else if (identifier.equals("CFL4CVT.BP020.RecordData") && null != value && "1".equals(value.toString())) { |
|
94 |
//待添加从过站采集表取sfc_code写入plc的sncode方法 |
|
95 |
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BP020.MesRecordDataDone", 11); |
|
96 |
miloService.writeToOpcByte(entity); |
|
97 |
} |
|
98 |
//BP020出站校验 |
|
99 |
else if (identifier.equals("CFL4CVT.BP020.RecordData") && null != value && "2".equals(value.toString())) { |
|
100 |
SaveData("CFL4CVT.BP020.RecordData"); |
|
101 |
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BP020.MesRecordDataDone", 21); |
|
102 |
miloService.writeToOpcByte(entity); |
|
103 |
|
|
104 |
} |
|
105 |
|
|
106 |
} |
|
107 |
} catch (Exception e) { |
|
108 |
|
|
109 |
} finally { |
|
110 |
if (!"".equals(ecpStr)) { |
|
111 |
System.out.println(ecpStr + "\r\n"); |
|
112 |
|
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
public void SaveData(String Node) throws Exception { |
|
118 |
String[] parts = Node.split("[.]"); |
|
119 |
Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue(); |
|
120 |
|
|
121 |
if (null != SNCodeObject) { |
|
122 |
String SNCode = SNCodeObject.toString(); |
|
123 |
List<DaCollectionParamConf> list; |
|
124 |
DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf(); |
|
125 |
daCollectionParamConf.setGatherAddress(parts[0] + "." + parts[1]); |
|
126 |
list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
|
127 |
|
|
128 |
List<String> nodeIdList = list.stream().map(info -> { |
|
129 |
String nodeid = info.getGatherAddress(); |
|
130 |
return nodeid; |
|
131 |
}).collect(Collectors.toList()); |
|
132 |
|
|
133 |
if (!nodeIdList.isEmpty()) { |
|
134 |
List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList); |
|
135 |
List<DaParamCollection> daParamCollectionlist = new ArrayList<>(); |
|
136 |
for (int i = 0; i < nodeIdList.size(); i++) { |
|
137 |
DaParamCollection ParamCollection = new DaParamCollection(); |
|
138 |
if (!readWriteEntityList.get(i).getValue().toString().equals("0.0")) { |
|
139 |
ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]); |
|
140 |
ParamCollection.setLocationCode(parts[1]); |
|
141 |
Object value = readWriteEntityList.get(i).getValue(); |
|
142 |
if (ObjectUtils.isNotEmpty(value)) { |
|
143 |
String string = value.toString(); |
|
144 |
ParamCollection.setParamValue(string); |
|
145 |
} |
|
146 |
ParamCollection.setSfcCode(SNCode); |
|
147 |
ParamCollection.setParamName(list.get(i).getCollectParameterName()); |
|
148 |
ParamCollection.setParamUpper(list.get(i).getParamUpper()); |
|
149 |
ParamCollection.setParamLower(list.get(i).getParamLower()); |
|
150 |
ParamCollection.setUnit(list.get(i).getCollectParameterUnit()); |
|
151 |
ParamCollection.setState("合格"); |
|
152 |
ParamCollection.setType(list.get(i).getCollectParameterType()); |
|
153 |
ParamCollection.setCollectionTime(new Date()); |
|
154 |
daParamCollectionlist.add(ParamCollection); |
|
155 |
} |
|
156 |
} |
|
157 |
daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist); |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
161 |
|
|
162 |
|
|
163 |
public void WriteSNCode(String Node) throws Exception { |
|
164 |
|
|
165 |
|
|
166 |
} |
|
167 |
} |