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