提交 | 用户 | 时间
|
a5b351
|
1 |
package com.jcdm.main.plcserver.sub; |
C |
2 |
|
|
3 |
|
6a462f
|
4 |
import cn.hutool.core.collection.CollUtil; |
8f0f8d
|
5 |
import cn.hutool.core.date.DateUtil; |
6a462f
|
6 |
import cn.hutool.core.util.StrUtil; |
e70fb4
|
7 |
import cn.hutool.json.JSONObject; |
8f0f8d
|
8 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
懒 |
9 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
288790
|
10 |
import com.jcdm.common.utils.StringUtils; |
49c784
|
11 |
import com.jcdm.framework.websocket.WebSocketUsers; |
6a462f
|
12 |
import com.jcdm.main.constant.Constants; |
a5b351
|
13 |
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; |
C |
14 |
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; |
|
15 |
import com.jcdm.main.da.paramCollection.domain.DaParamCollection; |
|
16 |
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; |
|
17 |
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
|
18 |
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
e70fb4
|
19 |
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; |
A |
20 |
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; |
a5b351
|
21 |
import com.jcdm.main.plcserver.conf.OPCElement; |
c5e9c5
|
22 |
import com.jcdm.main.plcserver.util.TimeUtil; |
e70fb4
|
23 |
import com.jcdm.main.restful.factoryMes.service.RestfulService; |
a5b351
|
24 |
import com.kangaroohy.milo.model.ReadWriteEntity; |
C |
25 |
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
|
26 |
import com.kangaroohy.milo.service.MiloService; |
|
27 |
import org.springframework.beans.factory.annotation.Autowired; |
|
28 |
import org.springframework.stereotype.Component; |
|
29 |
|
49c784
|
30 |
import javax.websocket.Session; |
c5e9c5
|
31 |
import java.text.SimpleDateFormat; |
32483a
|
32 |
import java.util.*; |
a5b351
|
33 |
import java.util.stream.Collectors; |
C |
34 |
|
|
35 |
|
|
36 |
@Component |
|
37 |
public class OPCUaSubscription implements SubscriptionCallback { |
e70fb4
|
38 |
|
A |
39 |
public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
32483a
|
40 |
|
5316c5
|
41 |
//新自动工站 |
d545f1
|
42 |
public List<String> automaticList = Arrays.asList("OP280","OP310A","OP310B", "OP300A","OP300B", "OP320A","OP320B", "OP340A","OP340B", "OP350A","OP350B", "OP360","OP365","OP370", "OP390", "OP470"); |
5316c5
|
43 |
|
7a0867
|
44 |
//采集模组工位 ModuleCode |
3581b1
|
45 |
public List<String> moduleCodeList = Arrays.asList("OP300A","OP300B","OP320A","OP320B","OP340A","OP340B","OP365", "OP350A", "OP350B", "OP330"); |
a5b351
|
46 |
|
7a0867
|
47 |
//区分模组型号工位 |
A |
48 |
public List<String> distinguishingModules = Arrays.asList("OP300","OP310", "OP340", "OP350", "OP330"); |
|
49 |
|
4a5f2a
|
50 |
//区分小车码 |
A |
51 |
public List<String> agvId = Arrays.asList("OP360", "OP390", "OP470","OP280"); |
|
52 |
|
5316c5
|
53 |
|
A |
54 |
//区分pack型号的工位 |
7a0867
|
55 |
public List<String> packIdList = Arrays.asList("OP280","OP360","OP390","OP470"); |
A |
56 |
|
288790
|
57 |
//测试设备手动工位 |
A |
58 |
public List<String> testList = Arrays.asList("OP430-1","OP430-2","OP430-3","OP430-4","OP480-1","OP480-2","OP480-3","OP440"); |
|
59 |
|
8f0f8d
|
60 |
|
63b254
|
61 |
//空的 |
8f0f8d
|
62 |
public List<String> nullList = Arrays.asList("OP250","OP260"); |
懒 |
63 |
|
|
64 |
|
a5b351
|
65 |
public static MiloService miloService; |
49c784
|
66 |
|
懒 |
67 |
Map<String, Session> map = WebSocketUsers.getUsers(); |
a5b351
|
68 |
|
C |
69 |
public IDaPassingStationCollectionService daPassingStationCollectionService; |
|
70 |
|
054a69
|
71 |
public static IDaCollectionParamConfService collectionParamConfService; |
a5b351
|
72 |
|
054a69
|
73 |
public static IDaParamCollectionService daParamCollectionService; |
a5b351
|
74 |
|
e70fb4
|
75 |
public static IOmProductionOrdeInfoService omProductionOrdeInfoService; |
A |
76 |
|
a5b351
|
77 |
public OPCUaSubscription(MiloService miloService, |
C |
78 |
IDaPassingStationCollectionService daPassingStationCollectionService, |
|
79 |
IDaCollectionParamConfService collectionParamConfService, |
e70fb4
|
80 |
IDaParamCollectionService daParamCollectionService, |
A |
81 |
IOmProductionOrdeInfoService omProductionOrdeInfoService) { |
a5b351
|
82 |
OPCUaSubscription.miloService = miloService; |
C |
83 |
this.daPassingStationCollectionService = daPassingStationCollectionService; |
8f0f8d
|
84 |
OPCUaSubscription.collectionParamConfService = collectionParamConfService; |
懒 |
85 |
OPCUaSubscription.daParamCollectionService = daParamCollectionService; |
e70fb4
|
86 |
OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService; |
a5b351
|
87 |
} |
C |
88 |
|
|
89 |
|
|
90 |
@Override |
|
91 |
public void onSubscribe(String identifier, Object value) { |
|
92 |
|
|
93 |
try { |
70cc26
|
94 |
if(null != value && Integer.valueOf(value.toString())!= 0) { |
a5b351
|
95 |
String[] nodes = identifier.split("[.]"); |
C |
96 |
String thoroughfare = nodes[0];//通道 |
|
97 |
String device = nodes[1];//设备 |
|
98 |
String tab = nodes[2];//标记 |
|
99 |
String tabVlaue = value.toString();//地址值 |
|
100 |
|
288790
|
101 |
if (("RecordData").equals(tab)) { |
a5b351
|
102 |
String recordDataDoneValue = ""; |
C |
103 |
|
|
104 |
if("1".equals(tabVlaue)){ |
89f416
|
105 |
|
e70fb4
|
106 |
//请求工单 |
A |
107 |
// if(device.equals("OP230")){ |
|
108 |
// getFactoryOrder("OP230"); |
|
109 |
// } |
|
110 |
|
|
111 |
//自动工位 |
5316c5
|
112 |
if(automaticList.stream().anyMatch(s -> s.equals(device))){ |
A |
113 |
//plc给我们一个模组码,拿模组码校验出型号 |
288790
|
114 |
if(moduleCodeList.stream().anyMatch(s -> s.equals(device))) { |
A |
115 |
String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
5316c5
|
116 |
//读模组码 |
288790
|
117 |
Object moduleCode = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue(); |
a320dc
|
118 |
if(device.equals("OP365")){ |
A |
119 |
Object moduleCodeA = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCodeA").getValue(); |
|
120 |
Object moduleCodeB = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCodeB").getValue(); |
|
121 |
if(moduleCodeA!=null && moduleCodeB!=null){ |
|
122 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build()); |
|
123 |
}else { |
|
124 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(12).build()); |
|
125 |
} |
|
126 |
return; |
|
127 |
} |
288790
|
128 |
|
A |
129 |
if(moduleCode!=null){ |
06713a
|
130 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build()); |
288790
|
131 |
}else { |
A |
132 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(12).build()); |
|
133 |
} |
7a0867
|
134 |
}else { |
4a5f2a
|
135 |
if(agvId.stream().anyMatch(s -> s.equals(device))){ |
288790
|
136 |
Object agvIdObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".AGVID").getValue(); |
A |
137 |
//agvId 小车码是否为空 |
|
138 |
if(agvIdObject!=null){ |
|
139 |
String PACKCode = thoroughfare + "." + device + ".MPACKCode"; |
|
140 |
OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getTrolleyYard, agvIdObject.toString())); |
|
141 |
//小车码查找工单是否为空 |
|
142 |
if(one!=null){ |
|
143 |
String packId = one.getProductNum(); |
|
144 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(PACKCode).value(packId).build()); |
|
145 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build()); |
|
146 |
}else { |
|
147 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build()); |
|
148 |
} |
|
149 |
}else { |
4a5f2a
|
150 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build()); |
A |
151 |
} |
7a0867
|
152 |
|
288790
|
153 |
}else { |
A |
154 |
String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
|
155 |
Object packCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".PACKCode").getValue(); |
|
156 |
if(packCodeObject!=null){ |
|
157 |
//pack 如果区分型号的话就要处理 |
|
158 |
//记录数据完成 |
|
159 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build()); |
|
160 |
}else { |
|
161 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(12).build()); |
|
162 |
} |
|
163 |
} |
e70fb4
|
164 |
} |
A |
165 |
}else { |
|
166 |
//手动工位处理逻辑 |
288790
|
167 |
WebSocketUsers.sendMessageToUserByText(map.get(device), "IN"); |
e70fb4
|
168 |
String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
A |
169 |
|
|
170 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build()); |
32483a
|
171 |
} |
e70fb4
|
172 |
|
7bff29
|
173 |
|
a5b351
|
174 |
}else if("2".equals(tabVlaue)){ |
32483a
|
175 |
if(automaticList.stream().anyMatch(s -> s.equals(device))){ |
懒 |
176 |
//自动工位 |
|
177 |
//出站保存数据 |
|
178 |
recordDataDoneValue = outSaveDate(thoroughfare,device); |
|
179 |
//记录数据完成 |
|
180 |
String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
70cc26
|
181 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf(recordDataDoneValue)).build()); |
32483a
|
182 |
}else { |
懒 |
183 |
//手动工位 |
1c84ae
|
184 |
if(device.contains("OP330")){ |
A |
185 |
String str = device.substring(0,5); |
|
186 |
WebSocketUsers.sendMessageToUserByText(map.get(str), "END"); |
|
187 |
}else { |
|
188 |
WebSocketUsers.sendMessageToUserByText(map.get(device), "END"); |
288790
|
189 |
} |
A |
190 |
if(testList.stream().anyMatch(s -> s.equals(device))){ |
|
191 |
String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
|
192 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); |
1c84ae
|
193 |
} |
32483a
|
194 |
} |
3c2299
|
195 |
}else { |
懒 |
196 |
System.out.println("^"); |
|
197 |
} |
|
198 |
} |
|
199 |
//保存拧紧数据 |
|
200 |
else if (("AngleResult").equals(tab)) { |
b5fcd8
|
201 |
if("1".equals(tabVlaue)||"2".equals(tabVlaue)){ |
32483a
|
202 |
List<String> list = new ArrayList<>(); |
0caf87
|
203 |
String[] suffixes = {"Torque", "Angle", "TorqueResult", "AngleResult"}; |
32483a
|
204 |
|
懒 |
205 |
for (String suffix : suffixes) { |
|
206 |
String string = thoroughfare + "." + device + "." + suffix; |
|
207 |
list.add(string); |
|
208 |
} |
49c784
|
209 |
List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list); |
懒 |
210 |
List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList()); |
|
211 |
String joinedString = String.join(",", collect.toString()); |
4a5f2a
|
212 |
WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString)); |
a5b351
|
213 |
} |
C |
214 |
} |
|
215 |
} |
|
216 |
} catch (Exception e) { |
|
217 |
|
|
218 |
} |
|
219 |
} |
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
/** |
|
224 |
* 获取SNCode |
|
225 |
*/ |
|
226 |
public String getSNCode(){ |
|
227 |
String SNCode = ""; |
|
228 |
return SNCode; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* 出站保存数据 |
|
233 |
*/ |
|
234 |
public String outSaveDate(String thoroughfare,String device) { |
8f0f8d
|
235 |
String snCode = ""; |
a5b351
|
236 |
String result = ""; |
8f0f8d
|
237 |
String read = thoroughfare + "." + device + "."; |
懒 |
238 |
|
a5b351
|
239 |
try { |
8f0f8d
|
240 |
if(nullList.stream().noneMatch(s -> s.equals(device))){ |
懒 |
241 |
if(moduleCodeList.stream().anyMatch(s -> s.equals(device))){ |
|
242 |
read = read + "ModuleCode"; |
a320dc
|
243 |
if(device.equals("OP365")){ |
A |
244 |
try { |
|
245 |
saveStationInfo365(thoroughfare,device); |
|
246 |
}catch (Exception e){ |
|
247 |
e.printStackTrace(); |
|
248 |
} |
|
249 |
} |
8f0f8d
|
250 |
}else { |
懒 |
251 |
read = read + "PACKCode"; |
|
252 |
} |
|
253 |
} |
|
254 |
snCode = miloService.readFromOpcUa(read).getValue().toString(); |
|
255 |
|
|
256 |
if(null == snCode || "".equals(snCode)){ |
|
257 |
result = "22"; |
a5b351
|
258 |
}else{ |
8f0f8d
|
259 |
|
e70fb4
|
260 |
String workOrderNo = ""; |
A |
261 |
String productCode = ""; |
|
262 |
//2、保存过站采集数据 |
|
263 |
Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue(); |
|
264 |
if(orderNumberObject!=null){ |
|
265 |
workOrderNo = orderNumberObject.toString(); |
|
266 |
} |
|
267 |
|
|
268 |
Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue(); |
|
269 |
if(productCodeObject!=null){ |
|
270 |
productCode = productCodeObject.toString(); |
|
271 |
} |
89f416
|
272 |
|
8f0f8d
|
273 |
saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode); |
a5b351
|
274 |
//3、保存参数采集数据 |
8f0f8d
|
275 |
SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode); |
e70fb4
|
276 |
|
A |
277 |
//如果是末尾工站要报工 |
|
278 |
if(device.equals("OP500")){ |
|
279 |
RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date())); |
|
280 |
//1、更新工单信息 |
|
281 |
updateOrderInfo(snCode); |
|
282 |
} |
a320dc
|
283 |
try{ |
A |
284 |
daParamCollectionService.pushGeelycvMesFeedback(snCode,device); |
|
285 |
}catch (Exception e){ |
|
286 |
} |
a5b351
|
287 |
result = "21"; |
C |
288 |
|
|
289 |
} |
|
290 |
|
|
291 |
}catch (Exception e) { |
8f0f8d
|
292 |
System.out.println(e.getMessage()); |
a5b351
|
293 |
} |
C |
294 |
return result; |
|
295 |
} |
|
296 |
|
8f0f8d
|
297 |
|
懒 |
298 |
// /** |
|
299 |
// * 出站保存数据 |
|
300 |
// */ |
|
301 |
// public String outSaveDate(String thoroughfare,String device) { |
|
302 |
// String result = ""; |
|
303 |
// try { |
|
304 |
// //读取SNCode |
|
305 |
// String PACKCode = thoroughfare + "." + device + ".PACKCode"; |
|
306 |
// Object PACKCodeObject = miloService.readFromOpcUa(PACKCode).getValue(); |
|
307 |
// if(null == PACKCodeObject || "".equals(PACKCodeObject)){ |
|
308 |
// result = "22"; |
|
309 |
// }else{ |
|
310 |
// String PACKCodeParam = PACKCodeObject.toString(); |
|
311 |
// //1、更新工单信息 |
|
312 |
// //updateOrderInfo(); |
|
313 |
// //2、保存过站采集数据 |
|
314 |
// saveStationInfo(PACKCodeParam,thoroughfare,device); |
|
315 |
// //3、保存参数采集数据 |
|
316 |
// SaveParamData(PACKCodeParam,thoroughfare,device,"",""); |
|
317 |
// |
|
318 |
// result = "21"; |
|
319 |
// |
|
320 |
// } |
|
321 |
// |
|
322 |
// }catch (Exception e) { |
|
323 |
// |
|
324 |
// } |
|
325 |
// return result; |
|
326 |
// } |
|
327 |
|
a5b351
|
328 |
/** |
C |
329 |
* 保存过站采集 |
|
330 |
*/ |
8f0f8d
|
331 |
public void saveStationInfo(String packCode,String thoroughfare,String device,String workOrderNo,String productCode) throws Exception { |
c5e9c5
|
332 |
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); |
懒 |
333 |
sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); // CST通常表示中国标准时间,即东八区 |
32483a
|
334 |
String prefix = thoroughfare+"."+device+"."; |
c5e9c5
|
335 |
String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString(); |
懒 |
336 |
String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString(); |
32483a
|
337 |
String stationStatus = miloService.readFromOpcUa(prefix + "StationStatus").getValue().toString(); |
懒 |
338 |
|
a5b351
|
339 |
DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection(); |
32483a
|
340 |
daPassingStationCollection.setSfcCode(packCode); |
懒 |
341 |
daPassingStationCollection.setWorkOrderNo(workOrderNo); |
8f0f8d
|
342 |
daPassingStationCollection.setProductCode(productCode); |
懒 |
343 |
daPassingStationCollection.setLocationCode(device); |
c5e9c5
|
344 |
String strt = TimeUtil.stringProcessing(startTime); |
懒 |
345 |
String end = TimeUtil.stringProcessing(stopTime); |
616f98
|
346 |
daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//入站时间 |
A |
347 |
daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//出站时间 |
32483a
|
348 |
daPassingStationCollection.setOutRsSign(stationStatus);//出站是否合格 |
a5b351
|
349 |
daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection); |
C |
350 |
} |
|
351 |
|
054a69
|
352 |
public static void SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception { |
a5b351
|
353 |
List<DaCollectionParamConf> list; |
C |
354 |
DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf(); |
|
355 |
daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device); |
|
356 |
list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
|
357 |
|
|
358 |
List<String> nodeIdList = list.stream().map(info -> { |
|
359 |
String nodeid = info.getGatherAddress(); |
|
360 |
return nodeid; |
|
361 |
}).collect(Collectors.toList()); |
|
362 |
|
|
363 |
if(!nodeIdList.isEmpty()){ |
|
364 |
List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList); |
e70fb4
|
365 |
for (int i = 0; i < readWriteEntityList.size(); i++) { |
A |
366 |
if(readWriteEntityList.get(i).getValue() == null){ |
|
367 |
readWriteEntityList.get(i).setValue(" "); |
|
368 |
} |
|
369 |
} |
a5b351
|
370 |
List<DaParamCollection> daParamCollectionlist = new ArrayList<>(); |
C |
371 |
for(int i=0;i<nodeIdList.size();i++){ |
|
372 |
if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){ |
c5e9c5
|
373 |
String tt = readWriteEntityList.get(i).getValue().toString(); |
32483a
|
374 |
DaParamCollection ParamCollection = new DaParamCollection(); |
懒 |
375 |
ParamCollection.setParamCode(list.get(i).getCollectParameterId()); |
a5b351
|
376 |
ParamCollection.setLocationCode(device); |
c5e9c5
|
377 |
if(tt.contains("Time")){ |
288790
|
378 |
// String str = TimeUtil.getTimestamp(TimeUtil.stringProcessing(tt)); |
A |
379 |
// ParamCollection.setParamValue(str); |
616f98
|
380 |
ParamCollection.setParamValue(TimeUtil.test(TimeUtil.stringProcessing(tt))); |
c5e9c5
|
381 |
}else { |
懒 |
382 |
ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString()); |
|
383 |
} |
32483a
|
384 |
ParamCollection.setSfcCode(packCode); |
288790
|
385 |
if(device.contains("OP360")){ |
A |
386 |
String node = nodeIdList.get(i); |
|
387 |
Object value = miloService.readFromOpcUa("PACK.OP360.ModuleSNCode"+node.charAt(node.length()-1)).getValue(); |
|
388 |
if(value!=null){ |
|
389 |
ParamCollection.setModuleCode(value.toString()); |
|
390 |
} |
|
391 |
} |
a5b351
|
392 |
ParamCollection.setParamName(list.get(i).getCollectParameterName()); |
C |
393 |
ParamCollection.setParamUpper(list.get(i).getParamUpper()); |
|
394 |
ParamCollection.setParamLower(list.get(i).getParamLower()); |
|
395 |
ParamCollection.setUnit(list.get(i).getCollectParameterUnit()); |
|
396 |
//ParamCollection.setState("合格"); |
|
397 |
ParamCollection.setType(list.get(i).getCollectParameterType()); |
|
398 |
ParamCollection.setCollectionTime(new Date()); |
054a69
|
399 |
ParamCollection.setWorkOrderNo(workOrderNo); |
懒 |
400 |
ParamCollection.setProductCode(productType); |
|
401 |
daParamCollectionlist.add(ParamCollection); |
|
402 |
// daParamCollectionService.insertDaParamCollection(ParamCollection); |
a5b351
|
403 |
} |
C |
404 |
} |
054a69
|
405 |
daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist); |
a5b351
|
406 |
} |
8f0f8d
|
407 |
addBaseData(workOrderNo,productType,device,packCode); |
a5b351
|
408 |
|
C |
409 |
} |
8f0f8d
|
410 |
|
懒 |
411 |
public static void addBaseData(String workOrderNo,String productCode,String locationCode,String packCode){ |
|
412 |
Map<String, String> map = new HashMap<>(); |
|
413 |
map.put("GC", "南浔工厂"); |
|
414 |
map.put("CXBH", "Pack线"); |
|
415 |
map.put("SBBH", "设备001"); |
|
416 |
map.put("YGBH", "员工001"); |
|
417 |
List<DaParamCollection> confList = new ArrayList<>(); |
|
418 |
map.forEach((key, value) -> { |
|
419 |
List<DaCollectionParamConf> daCollectionParamConfs = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>() |
|
420 |
.eq(DaCollectionParamConf::getProcessesCode,locationCode) |
|
421 |
.like(DaCollectionParamConf::getCollectParameterId,key)); |
|
422 |
DaParamCollection saveData = new DaParamCollection(); |
|
423 |
saveData.setWorkOrderNo(workOrderNo); |
|
424 |
saveData.setProductCode(productCode); |
|
425 |
saveData.setLocationCode(locationCode); |
|
426 |
saveData.setSfcCode(packCode); |
|
427 |
saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId()); |
|
428 |
saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName()); |
|
429 |
saveData.setCollectionTime(new Date()); |
|
430 |
saveData.setParamValue(value); |
|
431 |
confList.add(saveData); |
|
432 |
}); |
|
433 |
daParamCollectionService.insertBatch(confList); |
|
434 |
} |
e70fb4
|
435 |
|
A |
436 |
public static void getFactoryOrder(String locationCode){ |
|
437 |
String productionWorkOrder = RestfulService.getProductionWorkOrderRequest("", locationCode); |
|
438 |
JSONObject jsonObject = new JSONObject(productionWorkOrder); |
|
439 |
JSONObject dataObject = jsonObject.getJSONObject("data"); |
|
440 |
|
|
441 |
String productNum = dataObject.getStr("productNum"); |
|
442 |
String stationCode = dataObject.getStr("stationCode"); |
|
443 |
String materialCode = dataObject.getStr("materialCode"); |
|
444 |
String productionOrderNum = dataObject.getStr("productionOrderNum"); |
|
445 |
|
|
446 |
OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); |
|
447 |
omProductionOrdeInfo.setProductNum(productNum); |
|
448 |
omProductionOrdeInfo.setWorkOrderNo(productionOrderNum); |
|
449 |
omProductionOrdeInfo.setStationCode(stationCode); |
|
450 |
omProductionOrdeInfo.setProductCode(materialCode); |
|
451 |
omProductionOrdeInfoService.save(omProductionOrdeInfo); |
|
452 |
} |
|
453 |
|
|
454 |
public static void updateOrderInfo(String packCode){ |
|
455 |
OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, packCode)); |
|
456 |
one.setOrderStatus("5"); |
|
457 |
omProductionOrdeInfoService.saveOrUpdate(one); |
|
458 |
} |
|
459 |
|
4a5f2a
|
460 |
public static void avgFunction(){ |
A |
461 |
|
|
462 |
} |
|
463 |
|
|
464 |
public static String TightenTheConversionOkNg(String param){ |
|
465 |
// 去除首尾的方括号,然后按照逗号分割字符串 |
|
466 |
String[] parts = param.substring(1, param.length() - 1).split(","); |
|
467 |
|
|
468 |
// 创建一个新的StringBuilder来构建替换后的字符串 |
|
469 |
StringBuilder sb = new StringBuilder(); |
|
470 |
sb.append('['); // 添加左方括号 |
|
471 |
|
|
472 |
for (int i = 0; i < parts.length; i++) { |
|
473 |
String part = parts[i].trim(); // 去除可能的空格 |
|
474 |
float value; |
|
475 |
try { |
|
476 |
value = Float.parseFloat(part); // 尝试将字符串转换为浮点数 |
|
477 |
String replacement; |
|
478 |
if (value == 1f) { |
|
479 |
replacement = "OK"; |
|
480 |
} else if (value == 2f) { |
|
481 |
replacement = "NG"; |
|
482 |
} else { |
|
483 |
replacement = part; // 如果不是1或2,则保持不变 |
|
484 |
} |
|
485 |
sb.append(replacement); |
|
486 |
if (i < parts.length - 1) { |
|
487 |
sb.append(','); // 添加逗号(除了最后一个元素) |
|
488 |
} |
|
489 |
} catch (NumberFormatException e) { |
|
490 |
// 如果转换失败,则保持原样(或进行其他错误处理) |
|
491 |
sb.append(part); |
|
492 |
if (i < parts.length - 1) { |
|
493 |
sb.append(','); |
|
494 |
} |
|
495 |
} |
|
496 |
} |
|
497 |
sb.append(']'); // 添加右方括号 |
|
498 |
return sb.toString(); |
|
499 |
} |
|
500 |
|
6a462f
|
501 |
|
W |
502 |
/** |
|
503 |
* 校验是否存在NG |
|
504 |
* @param packCode sfcCode |
|
505 |
* @return boolean |
|
506 |
*/ |
|
507 |
public boolean checkIsNG(String packCode,String modelCode){ |
|
508 |
List<DaPassingStationCollection> list = daPassingStationCollectionService.list(new LambdaQueryWrapper<DaPassingStationCollection>() |
|
509 |
.eq(StrUtil.isNotBlank(packCode),DaPassingStationCollection::getSfcCode, packCode) |
|
510 |
.eq(DaPassingStationCollection::getOutRsSign, Constants.UN_PASS)); |
|
511 |
return CollUtil.isEmpty(list); |
|
512 |
} |
|
513 |
|
a320dc
|
514 |
/** |
A |
515 |
* 保存过站采集 |
|
516 |
*/ |
|
517 |
public void saveStationInfo365(String thoroughfare,String device) throws Exception { |
|
518 |
String prefix = thoroughfare+"."+device+"."; |
|
519 |
List<DaPassingStationCollection> passingStationCollections = new ArrayList<>(); |
|
520 |
String ModuleCodeA = miloService.readFromOpcUa(prefix + "ModuleCodeA").getValue().toString(); |
|
521 |
String ModuleCodeB = miloService.readFromOpcUa(prefix + "ModuleCodeB").getValue().toString(); |
|
522 |
String StationStatusA = miloService.readFromOpcUa(prefix + "StationStatusA").getValue().toString(); |
|
523 |
String StationStatusB = miloService.readFromOpcUa(prefix + "StationStatusB").getValue().toString(); |
|
524 |
String[] modeles = {ModuleCodeA,ModuleCodeB}; |
|
525 |
String[] StationStatus = {StationStatusA,StationStatusB}; |
|
526 |
|
|
527 |
String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString(); |
|
528 |
String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString(); |
|
529 |
for (int i = 0; i < 2; i++) { |
|
530 |
DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection(); |
|
531 |
String strt = TimeUtil.stringProcessing(startTime); |
|
532 |
String end = TimeUtil.stringProcessing(stopTime); |
|
533 |
daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//入站时间 |
|
534 |
daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//出站时间 |
|
535 |
daPassingStationCollection.setSfcCode(modeles[i]); |
|
536 |
daPassingStationCollection.setLocationCode(device); |
|
537 |
daPassingStationCollection.setOutRsSign(StationStatus[i]);//出站是否合格 |
|
538 |
passingStationCollections.add(daPassingStationCollection); |
|
539 |
} |
|
540 |
daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections); |
|
541 |
String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone"; |
|
542 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build()); |
|
543 |
return; |
|
544 |
} |
|
545 |
|
a5b351
|
546 |
} |