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