提交 | 用户 | 时间
|
a5b351
|
1 |
package com.jcdm.main.plcserver.sub; |
C |
2 |
|
|
3 |
|
|
4 |
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; |
|
5 |
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; |
|
6 |
import com.jcdm.main.da.paramCollection.domain.DaParamCollection; |
|
7 |
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; |
|
8 |
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
|
9 |
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
|
10 |
import com.jcdm.main.plcserver.conf.OPCElement; |
|
11 |
import com.kangaroohy.milo.model.ReadWriteEntity; |
|
12 |
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
|
13 |
import com.kangaroohy.milo.service.MiloService; |
|
14 |
import org.springframework.beans.factory.annotation.Autowired; |
|
15 |
import org.springframework.stereotype.Component; |
|
16 |
|
|
17 |
import java.util.ArrayList; |
|
18 |
import java.util.Date; |
|
19 |
import java.util.List; |
|
20 |
import java.util.stream.Collectors; |
|
21 |
|
|
22 |
|
|
23 |
@Component |
|
24 |
public class OPCUaSubscription implements SubscriptionCallback { |
|
25 |
|
|
26 |
public static MiloService miloService; |
|
27 |
|
|
28 |
public IDaPassingStationCollectionService daPassingStationCollectionService; |
|
29 |
|
|
30 |
public IDaCollectionParamConfService collectionParamConfService; |
|
31 |
|
|
32 |
public IDaParamCollectionService daParamCollectionService; |
|
33 |
|
|
34 |
public OPCUaSubscription(MiloService miloService, |
|
35 |
IDaPassingStationCollectionService daPassingStationCollectionService, |
|
36 |
IDaCollectionParamConfService collectionParamConfService, |
|
37 |
IDaParamCollectionService daParamCollectionService) { |
|
38 |
OPCUaSubscription.miloService = miloService; |
|
39 |
this.daPassingStationCollectionService = daPassingStationCollectionService; |
|
40 |
this.collectionParamConfService = collectionParamConfService; |
|
41 |
this.daParamCollectionService = daParamCollectionService; |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
@Override |
|
47 |
public void onSubscribe(String identifier, Object value) { |
|
48 |
|
|
49 |
try { |
|
50 |
if(null != value) { |
|
51 |
String[] nodes = identifier.split("[.]"); |
|
52 |
String thoroughfare = nodes[0];//通道 |
|
53 |
String device = nodes[1];//设备 |
|
54 |
String tab = nodes[2];//标记 |
|
55 |
String tabVlaue = value.toString();//地址值 |
|
56 |
|
|
57 |
//请求下发SN号 |
|
58 |
if (("RecordSN").equals(tab) && "1".equals(tabVlaue)) { |
|
59 |
//获取SN号方法 |
|
60 |
String SNCode = getSNCode(); |
|
61 |
|
|
62 |
//下发SN |
|
63 |
String SNCodeAddress = thoroughfare + "." + device + ".SNCode"; |
|
64 |
miloService.writeToOpcChar(ReadWriteEntity.builder().identifier(SNCodeAddress).value(SNCode).build()); |
|
65 |
//下发SN完成 |
|
66 |
String recordSNDoneAddress = thoroughfare + "." + device + ".RecordSNDone"; |
|
67 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(recordSNDoneAddress).value(1).build()); |
|
68 |
} |
|
69 |
//请求记录数据 |
|
70 |
else if (("RecordData").equals(tab)) { |
|
71 |
String recordDataDoneValue = ""; |
|
72 |
|
|
73 |
if("1".equals(tabVlaue)){ |
|
74 |
recordDataDoneValue = "11"; |
|
75 |
|
|
76 |
//进站保存数据 |
7bff29
|
77 |
// inSaveDate(thoroughfare,device) |
a5b351
|
78 |
//记录数据完成 |
C |
79 |
String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
|
80 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(recordDataDoneValue).build()); |
7bff29
|
81 |
|
懒 |
82 |
//给前端发工件到位信号 |
|
83 |
|
|
84 |
//请求工单 |
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
a5b351
|
89 |
}else if("2".equals(tabVlaue)){ |
C |
90 |
|
|
91 |
//出站保存数据 |
|
92 |
recordDataDoneValue = outSaveDate(thoroughfare,device); |
|
93 |
//记录数据完成 |
|
94 |
String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
|
95 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(recordDataDoneValue).build()); |
|
96 |
}else{ |
|
97 |
System.out.println("^"); |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
} |
|
104 |
} |
|
105 |
} catch (Exception e) { |
|
106 |
|
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
/** |
|
113 |
* 获取SNCode |
|
114 |
*/ |
|
115 |
public String getSNCode(){ |
|
116 |
String SNCode = ""; |
|
117 |
return SNCode; |
|
118 |
} |
|
119 |
|
|
120 |
|
|
121 |
/** |
|
122 |
* 出站保存数据 |
|
123 |
*/ |
|
124 |
public String outSaveDate(String thoroughfare,String device) { |
|
125 |
String result = ""; |
|
126 |
try { |
|
127 |
//读取SNCode |
|
128 |
String SNCodeAddress = thoroughfare + "." + device + ".SNCode"; |
|
129 |
Object SNCodeObject = miloService.readFromOpcUa(SNCodeAddress).getValue(); |
|
130 |
if(null == SNCodeObject || "".equals(SNCodeObject)){ |
|
131 |
result = "22"; |
|
132 |
}else{ |
|
133 |
String SNCode = SNCodeObject.toString(); |
|
134 |
//1、更新工单信息 |
|
135 |
//updateOrderInfo(); |
|
136 |
//2、保存过站采集数据 |
|
137 |
saveStationInfo(SNCode,thoroughfare,device); |
|
138 |
//3、保存参数采集数据 |
|
139 |
SaveParamData(SNCode,thoroughfare,device); |
|
140 |
|
|
141 |
result = "21"; |
|
142 |
|
|
143 |
} |
|
144 |
|
|
145 |
}catch (Exception e) { |
|
146 |
|
|
147 |
} |
|
148 |
return result; |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* 保存过站采集 |
|
153 |
*/ |
|
154 |
public void saveStationInfo(String SNCode,String thoroughfare,String device){ |
|
155 |
DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection(); |
|
156 |
daPassingStationCollection.setSfcCode(SNCode); |
|
157 |
//daPassingStationCollection.setInboundTime();//入站时间 |
|
158 |
daPassingStationCollection.setOutboundTime(new Date());//出站时间 |
|
159 |
//daPassingStationCollection.setOutRsSign();//出站是否合格 |
|
160 |
daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection); |
|
161 |
} |
|
162 |
|
|
163 |
public void SaveParamData(String SNCode,String thoroughfare,String device) throws Exception { |
|
164 |
List<DaCollectionParamConf> list; |
|
165 |
DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf(); |
|
166 |
daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device); |
|
167 |
list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
|
168 |
|
|
169 |
List<String> nodeIdList = list.stream().map(info -> { |
|
170 |
String nodeid = info.getGatherAddress(); |
|
171 |
return nodeid; |
|
172 |
}).collect(Collectors.toList()); |
|
173 |
|
|
174 |
if(!nodeIdList.isEmpty()){ |
|
175 |
List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList); |
|
176 |
List<DaParamCollection> daParamCollectionlist = new ArrayList<>(); |
|
177 |
for(int i=0;i<nodeIdList.size();i++){ |
|
178 |
DaParamCollection ParamCollection = new DaParamCollection(); |
|
179 |
if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){ |
|
180 |
ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]); |
|
181 |
ParamCollection.setLocationCode(device); |
|
182 |
ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString()); |
|
183 |
ParamCollection.setSfcCode(SNCode); |
|
184 |
ParamCollection.setParamName(list.get(i).getCollectParameterName()); |
|
185 |
ParamCollection.setParamUpper(list.get(i).getParamUpper()); |
|
186 |
ParamCollection.setParamLower(list.get(i).getParamLower()); |
|
187 |
ParamCollection.setUnit(list.get(i).getCollectParameterUnit()); |
|
188 |
//ParamCollection.setState("合格"); |
|
189 |
ParamCollection.setType(list.get(i).getCollectParameterType()); |
|
190 |
ParamCollection.setCollectionTime(new Date()); |
|
191 |
daParamCollectionlist.add(ParamCollection); |
|
192 |
} |
|
193 |
} |
|
194 |
//daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist); |
|
195 |
} |
|
196 |
|
|
197 |
} |
|
198 |
} |