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