提交 | 用户 | 时间
|
b78728
|
1 |
package com.jcdm.main.plcserver.sub; |
A |
2 |
|
|
3 |
|
|
4 |
import cn.hutool.core.collection.CollUtil; |
|
5 |
import cn.hutool.core.util.ObjectUtil; |
|
6 |
import cn.hutool.http.HttpRequest; |
|
7 |
import cn.hutool.http.HttpResponse; |
|
8 |
import cn.hutool.json.JSONObject; |
|
9 |
import cn.hutool.json.JSONUtil; |
|
10 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
a90728
|
11 |
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
b78728
|
12 |
import com.jcdm.framework.websocket.WebSocketUsers; |
A |
13 |
import com.jcdm.main.constant.Constants; |
|
14 |
import com.jcdm.main.da.cellData.service.IDaCellDataService; |
|
15 |
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; |
|
16 |
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; |
|
17 |
import com.jcdm.main.da.paramCollection.domain.DaParamCollection; |
|
18 |
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; |
|
19 |
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
|
20 |
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
|
21 |
import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService; |
|
22 |
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; |
|
23 |
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; |
|
24 |
import com.jcdm.main.plcserver.util.TimeUtil; |
|
25 |
import com.jcdm.main.restful.factoryMes.service.RestfulService; |
|
26 |
import com.jcdm.main.restful.qingYan.doman.ChildVO; |
|
27 |
import com.jcdm.main.restful.qingYan.doman.ParentVO; |
|
28 |
import com.kangaroohy.milo.model.ReadWriteEntity; |
3c3c4d
|
29 |
import com.kangaroohy.milo.model.WriteEntity; |
b78728
|
30 |
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
A |
31 |
import com.kangaroohy.milo.service.MiloService; |
|
32 |
import lombok.extern.slf4j.Slf4j; |
3c3c4d
|
33 |
import org.apache.xmlbeans.GDate; |
C |
34 |
import org.eclipse.milo.opcua.stack.core.types.builtin.DateTime; |
|
35 |
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; |
b78728
|
36 |
import org.springframework.stereotype.Component; |
A |
37 |
|
|
38 |
import javax.websocket.Session; |
|
39 |
import java.text.SimpleDateFormat; |
3c3c4d
|
40 |
import java.time.LocalDateTime; |
b78728
|
41 |
import java.util.*; |
A |
42 |
import java.util.concurrent.CompletableFuture; |
|
43 |
import java.util.stream.Collectors; |
|
44 |
|
|
45 |
|
|
46 |
@Slf4j |
|
47 |
@Component |
|
48 |
public class OPCUaSubscription implements SubscriptionCallback { |
|
49 |
|
|
50 |
public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
51 |
|
|
52 |
|
|
53 |
Map<String, Session> map = WebSocketUsers.getUsers(); |
|
54 |
public static MiloService miloService; |
|
55 |
|
|
56 |
|
|
57 |
public static IDaPassingStationCollectionService daPassingStationCollectionService; |
|
58 |
|
|
59 |
public static IDaCollectionParamConfService collectionParamConfService; |
|
60 |
|
|
61 |
public static IDaParamCollectionService daParamCollectionService; |
|
62 |
|
|
63 |
public static IOmProductionOrdeInfoService omProductionOrdeInfoService; |
|
64 |
|
|
65 |
public static IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService; |
|
66 |
|
|
67 |
public static IDaCellDataService daCellDataService; |
|
68 |
|
|
69 |
public OPCUaSubscription(MiloService miloService, |
|
70 |
IDaPassingStationCollectionService daPassingStationCollectionService, |
|
71 |
IDaCollectionParamConfService collectionParamConfService, |
|
72 |
IDaParamCollectionService daParamCollectionService, |
|
73 |
IOmProductionOrdeInfoService omProductionOrdeInfoService, |
|
74 |
IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService, |
|
75 |
IDaCellDataService daCellDataService) { |
|
76 |
OPCUaSubscription.miloService = miloService; |
|
77 |
OPCUaSubscription.daPassingStationCollectionService = daPassingStationCollectionService; |
|
78 |
OPCUaSubscription.collectionParamConfService = collectionParamConfService; |
|
79 |
OPCUaSubscription.daParamCollectionService = daParamCollectionService; |
|
80 |
OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService; |
|
81 |
OPCUaSubscription.daTestDeviceInterfaceTempService = daTestDeviceInterfaceTempService; |
|
82 |
OPCUaSubscription.daCellDataService = daCellDataService; |
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
@Override |
|
87 |
public void onSubscribe(String identifier, Object value) { |
|
88 |
log.info("地址:"+identifier+"值:"+value); |
|
89 |
try { |
|
90 |
if(null != value && !Constants.ZERO.equals(value.toString())) { |
|
91 |
String[] nodes = identifier.split("[.]"); |
|
92 |
String thoroughfare = nodes[0];//通道 |
|
93 |
String device = nodes[1];//设备 |
|
94 |
String tab = nodes[2];//标记 |
|
95 |
String valueString = value.toString();//地址值 |
|
96 |
|
|
97 |
CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { |
|
98 |
subHandle(thoroughfare,device,tab,valueString); |
|
99 |
}); |
|
100 |
|
|
101 |
} |
|
102 |
} catch (Exception e) { |
|
103 |
log.error(e.getMessage()); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
public void subHandle(String thoroughfare,String device,String tab,String valueString){ |
|
108 |
try{ |
d819b1
|
109 |
if (Constants.RECORD_DATA.equals(tab)) { //出入站 |
b321b8
|
110 |
if (Constants.ONE.equals(valueString)) {//入站 |
5b939f
|
111 |
if(Constants.OP040_OP160.contains(device)){//人工工位 |
8c09d8
|
112 |
Object snCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue(); |
2b9842
|
113 |
if (ObjectUtil.isNull(snCodeObjcet)){ |
C |
114 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build()); |
|
115 |
}else{ |
8fb831
|
116 |
String productNum = snCodeObjcet.toString().trim(); |
3bda47
|
117 |
if(productNum.length()<10){ |
C |
118 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build()); |
|
119 |
}else{ |
|
120 |
//将产品SN发送到前台 |
|
121 |
productNum = "productNum,"+ productNum; |
|
122 |
WebSocketUsers.sendMessageToUserByText(map.get(device), productNum); |
|
123 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build()); |
|
124 |
} |
|
125 |
|
2b9842
|
126 |
} |
5b939f
|
127 |
}else {//自动工位 |
C |
128 |
//所有进站将进站时间写给PLC |
|
129 |
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
130 |
String currentDate = dateFormat.format(new Date()); |
|
131 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StartTime").value(currentDate).build()); |
|
132 |
|
2b9842
|
133 |
Integer recordDataDone = 11; |
C |
134 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build()); |
|
135 |
} |
5b939f
|
136 |
|
b321b8
|
137 |
} else if(Constants.TWO.equals(valueString)){//出站 |
8c09d8
|
138 |
if(Constants.OP040_OP160.contains(device)){//人工工位 |
afc51f
|
139 |
if(Constants.OP165.equals(device)){ |
A |
140 |
WebSocketUsers.sendMessageToUserByText(map.get(device), "print");//打印 |
|
141 |
}else { |
|
142 |
WebSocketUsers.sendMessageToUserByText(map.get(device), "END"); |
|
143 |
} |
8bab65
|
144 |
} else if (Constants.OP0170_OP220.contains(device)) { |
6f1a28
|
145 |
WebSocketUsers.sendMessageToUserByText(map.get(device), "END"); |
C |
146 |
} else{//自动工位 |
|
147 |
//先判断是否有产品SN |
8c09d8
|
148 |
Object snCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue(); |
C |
149 |
Object orderObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".WorkOrderNumber").getValue(); |
|
150 |
if (ObjectUtil.isNull(snCodeObjcet)){ |
|
151 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(25).build()); |
|
152 |
}else { |
5b939f
|
153 |
|
8c09d8
|
154 |
Integer result = 21; |
8fb831
|
155 |
String snCode = snCodeObjcet.toString().trim();//产品SN |
C |
156 |
String orderNumber = orderObjcet.toString().trim();//工单号 |
3bda47
|
157 |
if(snCode.length()<10){ |
C |
158 |
result = 22; |
|
159 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build()); |
|
160 |
}else { |
|
161 |
//所有出站将出站时间写给PLC |
|
162 |
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
163 |
String currentDate = dateFormat.format(new Date()); |
|
164 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StopTime").value(currentDate).build()); |
|
165 |
|
|
166 |
Object stationStatusObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus").getValue();//站状态地址 |
|
167 |
if (ObjectUtil.isNotNull(stationStatusObjcet)) { |
|
168 |
String stationStatus = stationStatusObjcet.toString(); |
|
169 |
if (Constants.OP010.equals(device)) { |
6435ce
|
170 |
Object housingCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".HousingCode").getValue();//壳体条码,存到工单,返修用 |
C |
171 |
if (ObjectUtil.isNull(housingCodeObjcet)){ |
|
172 |
result = 25; |
|
173 |
}else{ |
|
174 |
String housingCode = housingCodeObjcet.toString();//壳体条码,存到工单,返修用 |
|
175 |
if(housingCode.length()<10){ |
|
176 |
result = 25; |
|
177 |
}else{ |
|
178 |
CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { |
|
179 |
updateOrderStatus(snCode, "3",housingCode);//OP010工位更新工单状态为执行中,并更新主物料壳体条码 |
|
180 |
reportFactoryMes(snCode, device, format.format(new Date()));//工厂MES报工 |
|
181 |
}); |
|
182 |
} |
|
183 |
} |
8bab65
|
184 |
} |
C |
185 |
if(Constants.OP230.equals(device)){ |
|
186 |
CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { |
|
187 |
updateOrderStatus(snCode, "5","");//OP230工位更新工单状态为已完成 |
|
188 |
reportFactoryMes(snCode, device, format.format(new Date()));//工厂MES报工 |
|
189 |
}); |
3bda47
|
190 |
} |
6435ce
|
191 |
if(result == 21){ |
C |
192 |
result = savePassingStation(thoroughfare, device, snCode, orderNumber, stationStatus);//保存过站 |
|
193 |
} |
3bda47
|
194 |
if (result == 21) { |
C |
195 |
result = saveParamCollection(device, snCode, orderNumber, stationStatus);//保存参数,发送工厂MES |
|
196 |
} |
|
197 |
} else { |
|
198 |
result = 23; |
|
199 |
log.info("读取到工位{}StationStatus数据:{},返回RecordDataDone的值为{}", device, "IS NULL!", result); |
8c09d8
|
200 |
} |
3bda47
|
201 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build()); |
8c09d8
|
202 |
} |
3bda47
|
203 |
|
a90728
|
204 |
} |
d819b1
|
205 |
} |
C |
206 |
} |
|
207 |
}else if (Constants.RECORD_SN.equals(tab)){//请求产品序列号 |
|
208 |
if (Constants.ONE.equals(valueString)){ |
|
209 |
//进站PLC给产品类型,MES读取产品类型 |
|
210 |
Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//产品类型 |
|
211 |
if (ObjectUtil.isNotNull(productTypeObjcet)){ |
|
212 |
String productType = productTypeObjcet.toString();//产品类型 |
|
213 |
String materialCode = Constants.materialMap.get(productType); |
|
214 |
//接收工单,保存到数据库,并且将工单传给PLC |
|
215 |
CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { |
|
216 |
receivingWorkOrders(thoroughfare, device,materialCode); |
|
217 |
}); |
|
218 |
}else{ |
f3862f
|
219 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(12).build()); |
d819b1
|
220 |
} |
f3862f
|
221 |
|
b78728
|
222 |
} |
f3862f
|
223 |
}else if(Constants.SCREW.equals(tab)){ |
C |
224 |
List<String> list = new ArrayList<>(); |
5b939f
|
225 |
String[] suffixes = {"Torque1", "Angle1", "TorqueResult1", "AngleResult1"}; |
f3862f
|
226 |
|
C |
227 |
for (String suffix : suffixes) { |
|
228 |
String string = thoroughfare + "." + device + "." + suffix; |
|
229 |
list.add(string); |
|
230 |
} |
|
231 |
List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list); |
|
232 |
List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList()); |
|
233 |
String joinedString = String.join(",", collect.toString()); |
|
234 |
WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString)); |
b78728
|
235 |
} |
A |
236 |
}catch (Exception e) { |
|
237 |
log.error(e.getMessage()); |
|
238 |
} |
|
239 |
} |
d819b1
|
240 |
|
C |
241 |
/** |
|
242 |
* 保存过站数据 |
|
243 |
* @param thoroughfare 通道 |
|
244 |
* @param device 工位 |
|
245 |
* @param snCode 产品序列号 |
|
246 |
* @param stationStatus 站状态 |
|
247 |
* @return Integer |
|
248 |
* @throws Exception e |
|
249 |
*/ |
|
250 |
private static Integer savePassingStation(String thoroughfare, String device,String snCode,String orderNumber,String stationStatus){ |
|
251 |
Integer result = 21; |
|
252 |
try { |
|
253 |
//读进站时间 |
|
254 |
Date startTime = new Date(); |
|
255 |
ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间 |
|
256 |
if (ObjectUtil.isNotNull(startTimeRead.getValue())){ |
5b939f
|
257 |
startTime = format.parse(startTimeRead.getValue().toString()); |
d819b1
|
258 |
}else{ |
C |
259 |
result = 23; |
|
260 |
log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result); |
|
261 |
return result; |
|
262 |
} |
|
263 |
|
|
264 |
DaPassingStationCollection passingStationCollection = new DaPassingStationCollection(); |
|
265 |
passingStationCollection.setSfcCode(snCode);//产品序列号 |
|
266 |
passingStationCollection.setWorkOrderNo(orderNumber);//工单号 |
|
267 |
passingStationCollection.setLocationCode(device);//工位 |
|
268 |
passingStationCollection.setInboundTime(startTime);//进站时间 |
|
269 |
passingStationCollection.setOutboundTime(new Date());//出站时间 |
|
270 |
passingStationCollection.setOutRsSign(stationStatus);//站状态值 |
|
271 |
passingStationCollection.setCollectionTime(new Date());//采集时间 |
|
272 |
daPassingStationCollectionService.save(passingStationCollection); |
|
273 |
|
|
274 |
} catch (Exception e) { |
|
275 |
throw new RuntimeException(e); |
|
276 |
} |
|
277 |
|
|
278 |
return result; |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* 保存参数数据和发送工厂MES |
|
283 |
* @param device 工位 |
|
284 |
* @param snCode 产品SN |
|
285 |
* @param orderNumber 工单号 |
|
286 |
* @param stationStatus 站状态 |
|
287 |
* @return result |
|
288 |
* @throws Exception e |
|
289 |
*/ |
|
290 |
private static Integer saveParamCollection(String device,String snCode,String orderNumber,String stationStatus){ |
|
291 |
Integer result = 21;//返回结果 |
|
292 |
try { |
|
293 |
//查询参数配置表 |
|
294 |
List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>() |
|
295 |
.eq(DaCollectionParamConf::getProcessesCode, device)//工位 |
|
296 |
.eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集 |
|
297 |
); |
|
298 |
if (CollUtil.isNotEmpty(list)){ |
|
299 |
|
|
300 |
List<String> collect = list.stream() |
|
301 |
.map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList()); |
|
302 |
List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(collect); |
|
303 |
|
|
304 |
List<DaParamCollection> collectionList = new ArrayList<>(); |
|
305 |
List<ChildVO> mesList = new ArrayList<>(); |
|
306 |
for (int i = 0; i < readWriteEntityList.size(); i++) { |
|
307 |
DaParamCollection daParamCollection = new DaParamCollection(); |
|
308 |
daParamCollection.setSfcCode(snCode);//产品SN |
|
309 |
daParamCollection.setWorkOrderNo(orderNumber);//工单号 |
|
310 |
daParamCollection.setParamCode(list.get(i).getCollectParameterId());//参数编码 |
|
311 |
daParamCollection.setParamName(list.get(i).getCollectParameterName());//参数名称 |
|
312 |
String paramValue = ""; |
|
313 |
if (ObjectUtil.isNotNull(readWriteEntityList.get(i).getValue())){ |
|
314 |
paramValue = readWriteEntityList.get(i).getValue().toString();//参数值 |
509744
|
315 |
/*if("DATE".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){ |
d819b1
|
316 |
paramValue = format.parse(TimeUtil.test(TimeUtil.stringProcessing(paramValue))).toString(); |
C |
317 |
}else if("MODEL".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){ |
|
318 |
paramValue = Constants.materialMap.get(paramValue); |
509744
|
319 |
}*/ |
d819b1
|
320 |
} |
C |
321 |
daParamCollection.setParamValue(paramValue);//参数值 |
|
322 |
daParamCollection.setLocationCode(device);//工位 |
|
323 |
daParamCollection.setCollectionTime(new Date());//采集时间 |
|
324 |
collectionList.add(daParamCollection);//封装参数采集list |
|
325 |
|
|
326 |
//发送给工厂mes参数封装 |
|
327 |
ChildVO childVO = new ChildVO(); |
|
328 |
childVO.setItemCode(list.get(i).getCollectParameterId());//参数编码 |
|
329 |
childVO.setItemType(list.get(i).getItemType()); |
|
330 |
childVO.setItemValue(paramValue);//参数值 |
|
331 |
childVO.setItemText(list.get(i).getCollectParameterName()); |
|
332 |
childVO.setCheckResult("1"); |
|
333 |
childVO.setCheckTime(format.format(new Date())); |
|
334 |
mesList.add(childVO); |
|
335 |
} |
|
336 |
|
509744
|
337 |
CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { |
d819b1
|
338 |
//插入参数采集表 |
C |
339 |
daParamCollectionService.insertBatch(collectionList); |
|
340 |
//上传到工厂mes |
|
341 |
ParentVO parentVO = new ParentVO(); |
|
342 |
parentVO.setStationCode(device);//工位 |
|
343 |
parentVO.setSiteCode("3983"); |
|
344 |
parentVO.setRecordId(UUID.randomUUID().toString()); |
|
345 |
if("2".equals(stationStatus)){//工站状态 |
|
346 |
parentVO.setTotalResult("0"); |
989363
|
347 |
}else{ |
A |
348 |
parentVO.setTotalResult("1"); |
d819b1
|
349 |
} |
C |
350 |
parentVO.setProductNum(snCode); |
|
351 |
parentVO.setCheckList(mesList); |
|
352 |
log.info("执行工厂MES方法start,工位号{} 传入数据:{}",device ,parentVO); |
|
353 |
HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute(); |
|
354 |
log.info("执行工厂MES方法end,工位号{} 返回数据:{}",device,execute.body()); |
|
355 |
|
509744
|
356 |
}); |
d819b1
|
357 |
} |
C |
358 |
}catch (Exception e) { |
|
359 |
throw new RuntimeException(e); |
|
360 |
} |
|
361 |
return result; |
|
362 |
} |
|
363 |
|
|
364 |
/** |
|
365 |
* 接收工单信息 |
|
366 |
* @param thoroughfare 通道 |
|
367 |
* @param device 工位 |
|
368 |
* @param materialCode 物料号 |
|
369 |
* @throws Exception e |
|
370 |
*/ |
|
371 |
public synchronized void receivingWorkOrders(String thoroughfare ,String device ,String materialCode) |
|
372 |
{ |
|
373 |
try { |
|
374 |
String productNum = "";//模组码 |
|
375 |
String orderNum = "";//工单号 |
|
376 |
|
|
377 |
//先查询表中是否有剩余工单 |
|
378 |
List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>() |
|
379 |
.eq(OmProductionOrdeInfo::getOrderStatus, Constants.ONE) |
|
380 |
.eq(OmProductionOrdeInfo::getStationCode,device)//工位 |
|
381 |
.eq(OmProductionOrdeInfo::getProductCode,materialCode));//产品类型 |
|
382 |
if (CollUtil.isNotEmpty(orderList)){ |
|
383 |
Long id = orderList.get(0).getId(); |
509744
|
384 |
productNum = orderList.get(0).getProductNum();//产品码 |
d819b1
|
385 |
orderNum = orderList.get(0).getWorkOrderNo(); |
C |
386 |
}else{ |
|
387 |
// 查询最新的工单信息 |
|
388 |
OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder(); |
|
389 |
|
|
390 |
log.info("请求工厂MES工单:入参device{},materialCode:{}", device, materialCode); |
46b20f
|
391 |
String facMaterialCode = Constants.facMaterialMap.get(materialCode); |
C |
392 |
String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "OP010",facMaterialCode); |
d819b1
|
393 |
log.info("请求工厂MES工单:出参pack:{}", orderJsonString); |
C |
394 |
|
|
395 |
JSONObject jsonObject = new JSONObject(orderJsonString); |
|
396 |
// 从JSONObject中获取data对象 |
|
397 |
JSONObject dataObject = jsonObject.getJSONObject("data"); |
|
398 |
String code = jsonObject.getStr("code"); |
|
399 |
// 判断接单是否成功 |
|
400 |
if(code.equals("success")) { |
|
401 |
OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); |
|
402 |
omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum")); |
|
403 |
omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum")); |
|
404 |
omProductionOrdeInfo.setStationCode(device); |
46b20f
|
405 |
omProductionOrdeInfo.setProductCode(materialCode); |
C |
406 |
omProductionOrdeInfo.setMaterialCode(dataObject.getStr("materialCode")); |
d819b1
|
407 |
omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity"))); |
C |
408 |
omProductionOrdeInfo.setOnlineCompletionMark("0"); |
|
409 |
omProductionOrdeInfo.setSfResult("0"); |
|
410 |
omProductionOrdeInfo.setProductModel(dataObject.getStr("model")); |
|
411 |
omProductionOrdeInfo.setCreateTime(new Date()); |
|
412 |
omProductionOrdeInfo.setCreateUser("工厂MES"); |
|
413 |
omProductionOrdeInfoService.save(omProductionOrdeInfo); |
|
414 |
|
|
415 |
productNum = dataObject.getStr("productNum"); |
|
416 |
orderNum = dataObject.getStr("productionOrderNum"); |
|
417 |
} |
|
418 |
} |
|
419 |
//下发产品SN和工单号 |
|
420 |
if(!productNum.isEmpty() && !orderNum.isEmpty()){ |
8c09d8
|
421 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SNCode").value(productNum).build()); |
d819b1
|
422 |
miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build()); |
f3862f
|
423 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(11).build()); |
d819b1
|
424 |
} |
C |
425 |
|
|
426 |
} catch (Exception e) { |
|
427 |
throw new RuntimeException(e); |
|
428 |
} |
|
429 |
} |
|
430 |
|
|
431 |
/** |
a90728
|
432 |
* 更新工单 |
C |
433 |
* @param snCode 产品sn |
|
434 |
* @param orderStatus 工单状态 |
8bab65
|
435 |
* @param materialCode 壳体条码 |
a90728
|
436 |
* @throws Exception e |
C |
437 |
*/ |
6435ce
|
438 |
private static void updateOrderStatus(String snCode,String orderStatus,String materialCode){ |
a90728
|
439 |
try { |
C |
440 |
//更新工单状态为已执行 |
|
441 |
LambdaUpdateWrapper<OmProductionOrdeInfo> updateWrapper = new LambdaUpdateWrapper<>(); |
|
442 |
updateWrapper.set(OmProductionOrdeInfo::getOrderStatus,orderStatus); |
14c14e
|
443 |
if(!materialCode.isEmpty()){//上线 |
8bab65
|
444 |
updateWrapper.set(OmProductionOrdeInfo::getTrolleyYard,materialCode);//壳体条码 |
C |
445 |
updateWrapper.set(OmProductionOrdeInfo::getActualStartTime,new Date());//开始时间 |
14c14e
|
446 |
}else{//下线 |
8bab65
|
447 |
updateWrapper.set(OmProductionOrdeInfo::getActualEndTime,new Date());//结束时间 |
C |
448 |
} |
a90728
|
449 |
updateWrapper.eq(OmProductionOrdeInfo::getProductNum,snCode); |
C |
450 |
omProductionOrdeInfoService.update(new OmProductionOrdeInfo(),updateWrapper); |
|
451 |
} catch (Exception e) { |
|
452 |
throw new RuntimeException(e); |
|
453 |
} |
|
454 |
|
|
455 |
} |
|
456 |
|
|
457 |
/** |
d819b1
|
458 |
* 工厂MES报工 |
C |
459 |
* @param productNum 通道 |
|
460 |
* @param stationCode 工位 |
|
461 |
* @param confirmTime 物料号 |
|
462 |
* @throws Exception e |
|
463 |
*/ |
|
464 |
//{"code":"success","data":{"productNum":"LCV123456P0600036","stationCode":"1HZ01","resultCode":"S","resultText":"报工成功"},"message":"API调用成功"} |
|
465 |
public static void reportFactoryMes(String productNum, String stationCode, String confirmTime) |
|
466 |
{ |
|
467 |
try { |
a90728
|
468 |
CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> { |
C |
469 |
log.info("请求工厂MES报工:入参device{},productNum:{}", stationCode, productNum); |
|
470 |
String url = Constants.FACTORY_EMS_UAT_GET_RUL + "workReportResultFeedback?siteCode="+Constants.FACTORY_EMS_SITE_CODE+"&stationCode="+stationCode+"&productNum="+productNum+"&confirmTime="+confirmTime; |
|
471 |
HttpResponse response = HttpRequest.get(url).execute(); |
|
472 |
/*HttpRequest httpRequest = HttpRequest.get(url);*/ |
|
473 |
String result = response.body(); |
|
474 |
log.info("请求工厂MES报工:出参:{}", result); |
|
475 |
}); |
|
476 |
|
d819b1
|
477 |
}catch (Exception e){ |
C |
478 |
throw new RuntimeException(e); |
|
479 |
} |
|
480 |
} |
f3862f
|
481 |
|
C |
482 |
public static String TightenTheConversionOkNg(String param){ |
|
483 |
// 去除首尾的方括号,然后按照逗号分割字符串 |
|
484 |
String[] parts = param.substring(1, param.length() - 1).split(","); |
|
485 |
|
|
486 |
// 创建一个新的StringBuilder来构建替换后的字符串 |
|
487 |
StringBuilder sb = new StringBuilder(); |
|
488 |
sb.append('['); // 添加左方括号 |
|
489 |
|
|
490 |
for (int i = 0; i < parts.length; i++) { |
|
491 |
String part = parts[i].trim(); // 去除可能的空格 |
|
492 |
float value; |
|
493 |
try { |
|
494 |
value = Float.parseFloat(part); // 尝试将字符串转换为浮点数 |
|
495 |
String replacement; |
|
496 |
if(i<2){ |
|
497 |
replacement = part; |
|
498 |
}else{ |
|
499 |
if (value == 1f) { |
|
500 |
replacement = "OK"; |
|
501 |
} else{ |
|
502 |
replacement = "NG"; |
|
503 |
} |
|
504 |
} |
|
505 |
/* if (value == 1f) { |
|
506 |
replacement = "OK"; |
|
507 |
} else if (value == 2f) { |
|
508 |
replacement = "NG"; |
|
509 |
} else { |
|
510 |
replacement = part; // 如果不是1或2,则保持不变 |
|
511 |
}*/ |
|
512 |
sb.append(replacement); |
|
513 |
if (i < parts.length - 1) { |
|
514 |
sb.append(','); // 添加逗号(除了最后一个元素) |
|
515 |
} |
|
516 |
} catch (NumberFormatException e) { |
|
517 |
// 如果转换失败,则保持原样(或进行其他错误处理) |
|
518 |
sb.append(part); |
|
519 |
if (i < parts.length - 1) { |
|
520 |
sb.append(','); |
|
521 |
} |
|
522 |
} |
|
523 |
} |
|
524 |
sb.append(']'); // 添加右方括号 |
|
525 |
return sb.toString(); |
|
526 |
} |
5b939f
|
527 |
|
C |
528 |
/* public static void main(String[] args) { |
|
529 |
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
530 |
String currentDate = dateFormat.format(new Date()); |
|
531 |
System.out.println(currentDate); |
|
532 |
}*/ |
b78728
|
533 |
} |