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