admin
2024-09-18 2d564a5921cec98b2c7e6065cc8f066abd614b76
提交 | 用户 | 时间
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)){//人工工位
252f60 112                         Object snCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue();
C 113                         if (ObjectUtil.isNull(snCodeObject)){
2b9842 114                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
C 115                         }else{
252f60 116                             String productNum = snCodeObject.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());
2bbc7c 124                                 String str = thoroughfare + "." + device + ".MESScrew";
A 125                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(1).build());//拧紧步骤
3bda47 126                             }
C 127
2b9842 128                         }
5b939f 129                     }else {//自动工位
2d564a 130                         Object snCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue();
A 131                         if (ObjectUtil.isNull(snCodeObject)){
132                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
133                         }else{
134                             //所有进站将进站时间写给PLC
135                             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
136                             String currentDate = dateFormat.format(new Date());
137                             miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StartTime").value(currentDate).build());
5b939f 138
2d564a 139                             Integer recordDataDone = 11;
A 140                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build());
141                         }
142
2b9842 143                     }
5b939f 144
b321b8 145                 } else if(Constants.TWO.equals(valueString)){//出站
8c09d8 146                         if(Constants.OP040_OP160.contains(device)){//人工工位
afc51f 147                             if(Constants.OP165.equals(device)){
A 148                                 WebSocketUsers.sendMessageToUserByText(map.get(device), "print");//打印
149                             }else {
150                                 WebSocketUsers.sendMessageToUserByText(map.get(device), "END");
151                             }
8bab65 152                         }  else if (Constants.OP0170_OP220.contains(device)) {
6f1a28 153                             WebSocketUsers.sendMessageToUserByText(map.get(device), "END");
C 154                         } else{//自动工位
155                             //先判断是否有产品SN
252f60 156                             Object snCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".SNCode").getValue();
8c09d8 157                             Object orderObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".WorkOrderNumber").getValue();
252f60 158                             if (ObjectUtil.isNull(snCodeObject)){
8c09d8 159                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(25).build());
C 160                             }else {
5b939f 161
8c09d8 162                                 Integer result = 21;
252f60 163                                 String snCode = snCodeObject.toString().trim();//产品SN
8fb831 164                                 String orderNumber = orderObjcet.toString().trim();//工单号
3bda47 165                                 if(snCode.length()<10){
C 166                                     result = 22;
167                                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
168                                 }else {
169                                     //所有出站将出站时间写给PLC
170                                     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
171                                     String currentDate = dateFormat.format(new Date());
172                                     miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StopTime").value(currentDate).build());
173
174                                     Object stationStatusObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus").getValue();//站状态地址
175                                     if (ObjectUtil.isNotNull(stationStatusObjcet)) {
176                                         String stationStatus = stationStatusObjcet.toString();
177                                         if (Constants.OP010.equals(device)) {
252f60 178                                             Object housingCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".HousingCode").getValue();//壳体条码,存到工单,返修用
C 179                                             if (ObjectUtil.isNull(housingCodeObject)){
6435ce 180                                                 result = 25;
C 181                                             }else{
252f60 182                                                 String housingCode = housingCodeObject.toString();//壳体条码,存到工单,返修用
6435ce 183                                                 if(housingCode.length()<10){
C 184                                                     result = 25;
185                                                 }else{
186                                                     CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
187                                                         updateOrderStatus(snCode, "3",housingCode);//OP010工位更新工单状态为执行中,并更新主物料壳体条码
188                                                         reportFactoryMes(snCode, device, format.format(new Date()));//工厂MES报工
dd9383 189                                                      });
6435ce 190                                                 }
C 191                                             }
8bab65 192                                         }
C 193                                         if(Constants.OP230.equals(device)){
616068 194                                             WebSocketUsers.sendMessageToUserByText(map.get(device), "twoHundredAndThirtyEND");
8bab65 195                                             CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
C 196                                                 updateOrderStatus(snCode, "5","");//OP230工位更新工单状态为已完成
b82de6 197                                                 reportFactoryMes(snCode, "OP240", format.format(new Date()));//工厂MES报工   //暂时 OP240工位还没有好,在230报240的工
8bab65 198                                             });
616068 199                                             miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SNCode").value("").build());
3bda47 200                                         }
6435ce 201                                         if(result == 21){
C 202                                             result = savePassingStation(thoroughfare, device, snCode, orderNumber, stationStatus);//保存过站
203                                         }
3bda47 204                                         if (result == 21) {
C 205                                             result = saveParamCollection(device, snCode, orderNumber, stationStatus);//保存参数,发送工厂MES
206                                         }
207                                     } else {
208                                         result = 23;
209                                         log.info("读取到工位{}StationStatus数据:{},返回RecordDataDone的值为{}", device, "IS NULL!", result);
8c09d8 210                                     }
3bda47 211                                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
8c09d8 212                                 }
3bda47 213
a90728 214                             }
d819b1 215                         }
C 216                 }
217             }else if (Constants.RECORD_SN.equals(tab)){//请求产品序列号
218                 if (Constants.ONE.equals(valueString)){
219                     //进站PLC给产品类型,MES读取产品类型
220                     Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//产品类型
221                     if (ObjectUtil.isNotNull(productTypeObjcet)){
222                         String productType = productTypeObjcet.toString();//产品类型
223                         String materialCode = Constants.materialMap.get(productType);
224                         //接收工单,保存到数据库,并且将工单传给PLC
225                         CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
226                             receivingWorkOrders(thoroughfare, device,materialCode);
227                         });
228                     }else{
f3862f 229                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(12).build());
d819b1 230                     }
f3862f 231
b78728 232                 }
f3862f 233             }else if(Constants.SCREW.equals(tab)){
C 234                 List<String> list = new ArrayList<>();
5b939f 235                 String[] suffixes = {"Torque1", "Angle1", "TorqueResult1", "AngleResult1"};
f3862f 236
C 237                 for (String suffix : suffixes) {
238                     String string = thoroughfare + "." + device + "." + suffix;
239                     list.add(string);
240                 }
241                 List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list);
242                 List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList());
243                 String joinedString = String.join(",", collect.toString());
244                 WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString));
b78728 245             }
A 246         }catch (Exception e) {
247             log.error(e.getMessage());
248         }
249     }
d819b1 250
C 251     /**
252      * 保存过站数据
253      * @param thoroughfare 通道
254      * @param device 工位
255      * @param snCode 产品序列号
256      * @param stationStatus 站状态
257      * @return Integer
258      * @throws Exception e
259      */
260     private static Integer savePassingStation(String thoroughfare, String device,String snCode,String orderNumber,String stationStatus){
261         Integer result = 21;
262         try {
263             //读进站时间
264             Date startTime = new Date();
265             ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间
266             if (ObjectUtil.isNotNull(startTimeRead.getValue())){
5b939f 267                 startTime = format.parse(startTimeRead.getValue().toString());
d819b1 268             }else{
C 269                 result = 23;
270                 log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
271                 return result;
272             }
273
274             DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
275             passingStationCollection.setSfcCode(snCode);//产品序列号
276             passingStationCollection.setWorkOrderNo(orderNumber);//工单号
277             passingStationCollection.setLocationCode(device);//工位
278             passingStationCollection.setInboundTime(startTime);//进站时间
279             passingStationCollection.setOutboundTime(new Date());//出站时间
280             passingStationCollection.setOutRsSign(stationStatus);//站状态值
281             passingStationCollection.setCollectionTime(new Date());//采集时间
282             daPassingStationCollectionService.save(passingStationCollection);
283
284         } catch (Exception e) {
285             throw new RuntimeException(e);
286         }
287
288         return result;
289     }
290
291     /**
292      * 保存参数数据和发送工厂MES
293      * @param device 工位
294      * @param snCode 产品SN
295      * @param orderNumber 工单号
296      * @param stationStatus 站状态
297      * @return result
298      * @throws Exception e
299      */
300     private static Integer saveParamCollection(String device,String snCode,String orderNumber,String stationStatus){
301         Integer result = 21;//返回结果
302         try {
303             //查询参数配置表
304             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
305                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
306                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
307             );
308             if (CollUtil.isNotEmpty(list)){
309
310                 List<String> collect = list.stream()
311                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
312                 List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(collect);
313
314                 List<DaParamCollection> collectionList = new ArrayList<>();
315                 List<ChildVO> mesList = new ArrayList<>();
316                 for (int i = 0; i < readWriteEntityList.size(); i++) {
317                     DaParamCollection daParamCollection = new DaParamCollection();
318                     daParamCollection.setSfcCode(snCode);//产品SN
319                     daParamCollection.setWorkOrderNo(orderNumber);//工单号
320                     daParamCollection.setParamCode(list.get(i).getCollectParameterId());//参数编码
321                     daParamCollection.setParamName(list.get(i).getCollectParameterName());//参数名称
322                     String paramValue = "";
323                     if (ObjectUtil.isNotNull(readWriteEntityList.get(i).getValue())){
324                         paramValue = readWriteEntityList.get(i).getValue().toString();//参数值
509744 325                         /*if("DATE".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){
d819b1 326                             paramValue = format.parse(TimeUtil.test(TimeUtil.stringProcessing(paramValue))).toString();
C 327                         }else if("MODEL".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){
328                             paramValue = Constants.materialMap.get(paramValue);
509744 329                         }*/
d819b1 330                     }
C 331                     daParamCollection.setParamValue(paramValue);//参数值
332                     daParamCollection.setLocationCode(device);//工位
333                     daParamCollection.setCollectionTime(new Date());//采集时间
334                     collectionList.add(daParamCollection);//封装参数采集list
335
336                     //发送给工厂mes参数封装
337                     ChildVO childVO = new ChildVO();
338                     childVO.setItemCode(list.get(i).getCollectParameterId());//参数编码
339                     childVO.setItemType(list.get(i).getItemType());
340                     childVO.setItemValue(paramValue);//参数值
341                     childVO.setItemText(list.get(i).getCollectParameterName());
342                     childVO.setCheckResult("1");
343                     childVO.setCheckTime(format.format(new Date()));
344                     mesList.add(childVO);
345                 }
346
509744 347                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
d819b1 348                     //插入参数采集表
C 349                     daParamCollectionService.insertBatch(collectionList);
350                     //上传到工厂mes
351                     ParentVO parentVO = new ParentVO();
352                     parentVO.setStationCode(device);//工位
353                     parentVO.setSiteCode("3983");
354                     parentVO.setRecordId(UUID.randomUUID().toString());
355                     if("2".equals(stationStatus)){//工站状态
356                         parentVO.setTotalResult("0");
989363 357                     }else{
A 358                         parentVO.setTotalResult("1");
d819b1 359                     }
C 360                     parentVO.setProductNum(snCode);
361                     parentVO.setCheckList(mesList);
362                     log.info("执行工厂MES方法start,工位号{} 传入数据:{}",device ,parentVO);
363                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
364                     log.info("执行工厂MES方法end,工位号{} 返回数据:{}",device,execute.body());
365
509744 366                 });
d819b1 367             }
C 368         }catch (Exception e) {
369             throw new RuntimeException(e);
370         }
371         return result;
372     }
373
374     /**
375      * 接收工单信息
376      * @param thoroughfare 通道
377      * @param device 工位
378      * @param materialCode 物料号
379      * @throws Exception e
380      */
381     public synchronized void receivingWorkOrders(String thoroughfare ,String device ,String materialCode)
382     {
383         try {
384             String productNum = "";//模组码
385             String orderNum = "";//工单号
386
387             //先查询表中是否有剩余工单
388             List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>()
389                     .eq(OmProductionOrdeInfo::getOrderStatus, Constants.ONE)
390                     .eq(OmProductionOrdeInfo::getStationCode,device)//工位
ef4005 391                     //.eq(OmProductionOrdeInfo::getProductCode,materialCode)
C 392             );//产品类型
d819b1 393             if (CollUtil.isNotEmpty(orderList)){
C 394                 Long id = orderList.get(0).getId();
509744 395                 productNum = orderList.get(0).getProductNum();//产品码
d819b1 396                 orderNum = orderList.get(0).getWorkOrderNo();
C 397             }else{
398                 // 查询最新的工单信息
399                 OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder();
ef4005 400                 //String facMaterialCode = Constants.facMaterialMap.get(materialCode);
C 401                 log.info("请求工厂MES工单:入参device{},请求工厂物料编码,产品物料编码MaterialCode{}", device,materialCode);
402                 String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), device,"");
d819b1 403                 log.info("请求工厂MES工单:出参pack:{}", orderJsonString);
C 404
405                 JSONObject jsonObject = new JSONObject(orderJsonString);
406                 // 从JSONObject中获取data对象
407                 JSONObject dataObject = jsonObject.getJSONObject("data");
408                 String code = jsonObject.getStr("code");
409                 // 判断接单是否成功
252f60 410                 if("success".equals(code)) {
d819b1 411                     OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
C 412                     omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum"));
413                     omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum"));
414                     omProductionOrdeInfo.setStationCode(device);
46b20f 415                     omProductionOrdeInfo.setProductCode(materialCode);
C 416                     omProductionOrdeInfo.setMaterialCode(dataObject.getStr("materialCode"));
d819b1 417                     omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity")));
C 418                     omProductionOrdeInfo.setOnlineCompletionMark("0");
419                     omProductionOrdeInfo.setSfResult("0");
420                     omProductionOrdeInfo.setProductModel(dataObject.getStr("model"));
421                     omProductionOrdeInfo.setCreateTime(new Date());
422                     omProductionOrdeInfo.setCreateUser("工厂MES");
423                     omProductionOrdeInfoService.save(omProductionOrdeInfo);
424
425                     productNum = dataObject.getStr("productNum");
426                     orderNum = dataObject.getStr("productionOrderNum");
427                 }
428             }
429             //下发产品SN和工单号
430             if(!productNum.isEmpty() && !orderNum.isEmpty()){
8c09d8 431                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".SNCode").value(productNum).build());
d819b1 432                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build());
f3862f 433                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(11).build());
6f85c8 434             }else{
A 435                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(12).build());
d819b1 436             }
C 437
438         } catch (Exception e) {
439             throw new RuntimeException(e);
440         }
441     }
442
443     /**
a90728 444      * 更新工单
C 445      * @param snCode 产品sn
446      * @param orderStatus 工单状态
8bab65 447      * @param materialCode 壳体条码
a90728 448      * @throws Exception e
C 449      */
6435ce 450     private static void updateOrderStatus(String snCode,String orderStatus,String materialCode){
a90728 451         try {
C 452             //更新工单状态为已执行
453             LambdaUpdateWrapper<OmProductionOrdeInfo> updateWrapper = new LambdaUpdateWrapper<>();
454             updateWrapper.set(OmProductionOrdeInfo::getOrderStatus,orderStatus);
14c14e 455             if(!materialCode.isEmpty()){//上线
8bab65 456                 updateWrapper.set(OmProductionOrdeInfo::getTrolleyYard,materialCode);//壳体条码
C 457                 updateWrapper.set(OmProductionOrdeInfo::getActualStartTime,new Date());//开始时间
14c14e 458             }else{//下线
8bab65 459                 updateWrapper.set(OmProductionOrdeInfo::getActualEndTime,new Date());//结束时间
C 460             }
a90728 461             updateWrapper.eq(OmProductionOrdeInfo::getProductNum,snCode);
C 462             omProductionOrdeInfoService.update(new OmProductionOrdeInfo(),updateWrapper);
463         } catch (Exception e) {
464             throw new RuntimeException(e);
465         }
466
467     }
468
469     /**
d819b1 470      * 工厂MES报工
C 471      * @param productNum  通道
472      * @param stationCode 工位
252f60 473      * @param confirmTime 时间
d819b1 474      * @throws Exception e
C 475      */
476     //{"code":"success","data":{"productNum":"LCV123456P0600036","stationCode":"1HZ01","resultCode":"S","resultText":"报工成功"},"message":"API调用成功"}
252f60 477     public static void reportFactoryMes(String productNum,String stationCode,String confirmTime)
d819b1 478     {
252f60 479         String result = "";
C 480         String url = Constants.FACTORY_EMS_UAT_GET_RUL + "workReportResultFeedback?siteCode="+Constants.FACTORY_EMS_SITE_CODE+"&stationCode="+stationCode+"&productNum="+productNum+"&confirmTime="+confirmTime;
d819b1 481         try {
252f60 482             log.info("执行工厂MES报工方法start,序列号{}工位号{}url{}",productNum,stationCode ,url);
C 483             HttpResponse response = HttpRequest.get(url).execute();
484             //HttpRequest httpRequest = HttpRequest.get(url);
485             result =  response.body();
486             log.info("执行工厂MES报工方法第一次end,序列号{}工位号{}返回数据{}",productNum,stationCode ,result);
d819b1 487         }catch (Exception e){
C 488             throw new RuntimeException(e);
252f60 489         }finally {
C 490             if(result.isEmpty()){
491                 HttpResponse response = HttpRequest.get(url).execute();
492                 result =  response.body();
493                 log.info("执行工厂MES报工方法第二次end,序列号{}工位号{}返回数据{}",productNum,stationCode ,result);
494             }
d819b1 495         }
C 496     }
f3862f 497     public static String TightenTheConversionOkNg(String param){
C 498         // 去除首尾的方括号,然后按照逗号分割字符串
499         String[] parts = param.substring(1, param.length() - 1).split(",");
500
501         // 创建一个新的StringBuilder来构建替换后的字符串
502         StringBuilder sb = new StringBuilder();
503         sb.append('['); // 添加左方括号
504
505         for (int i = 0; i < parts.length; i++) {
506             String part = parts[i].trim(); // 去除可能的空格
507             float value;
508             try {
509                 value = Float.parseFloat(part); // 尝试将字符串转换为浮点数
510                 String replacement;
511                 if(i<2){
512                     replacement = part;
513                 }else{
514                     if (value == 1f) {
515                         replacement = "OK";
516                     } else{
517                         replacement = "NG";
518                     }
519                 }
520             /*    if (value == 1f) {
521                     replacement = "OK";
522                 } else if (value == 2f) {
523                     replacement = "NG";
524                 } else {
525                     replacement = part; // 如果不是1或2,则保持不变
526                 }*/
527                 sb.append(replacement);
528                 if (i < parts.length - 1) {
529                     sb.append(','); // 添加逗号(除了最后一个元素)
530                 }
531             } catch (NumberFormatException e) {
532                 // 如果转换失败,则保持原样(或进行其他错误处理)
533                 sb.append(part);
534                 if (i < parts.length - 1) {
535                     sb.append(',');
536                 }
537             }
538         }
539         sb.append(']'); // 添加右方括号
540         return sb.toString();
541     }
5b939f 542
C 543  /*   public static void main(String[] args) {
544         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
545         String currentDate = dateFormat.format(new Date());
546         System.out.println(currentDate);
547     }*/
b78728 548 }