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