admin
2024-07-01 0ca2540bbe77760f8a6d6da2f911b79318cd9df9
提交 | 用户 | 时间
0ca254 1 package com.jcdm.main.plcserver.sub;
A 2
3
4 import cn.hutool.core.collection.CollUtil;
5 import cn.hutool.core.date.DateUtil;
6 import cn.hutool.core.util.ObjectUtil;
7 import cn.hutool.core.util.StrUtil;
8 import cn.hutool.json.JSONObject;
9 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
10 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
11 import com.jcdm.common.utils.StringUtils;
12 import com.jcdm.framework.websocket.WebSocketUsers;
13 import com.jcdm.main.constant.Constants;
14 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
15 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
16 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
17 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
18 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
19 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
20 import com.jcdm.main.da.testDeviceInterface.domain.DaTestDeviceInterface;
21 import com.jcdm.main.da.testDeviceInterface.service.IDaTestDeviceInterfaceService;
22 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
23 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
24 import com.jcdm.main.plcserver.conf.OPCElement;
25 import com.jcdm.main.plcserver.util.TimeUtil;
26 import com.jcdm.main.restful.factoryMes.service.RestfulService;
27 import com.jcdm.main.restful.qingYan.doman.ChildVO;
28 import com.jcdm.main.restful.qingYan.doman.ParentVO;
29 import com.kangaroohy.milo.model.ReadWriteEntity;
30 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
31 import com.kangaroohy.milo.service.MiloService;
32 import lombok.extern.slf4j.Slf4j;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
37
38 import javax.websocket.Session;
39 import java.text.SimpleDateFormat;
40 import java.time.Instant;
41 import java.util.*;
42 import java.util.stream.Collectors;
43
44 @Slf4j
45 @Component
46 public class OPCUaSubscription implements SubscriptionCallback {
47
48     private static final Logger logger = LoggerFactory.getLogger("sys-user");
49
50     public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
51
52     //新自动工站
53     public List<String> automaticList = Arrays.asList("OP280","OP310A","OP310B", "OP300A","OP300B", "OP320A","OP320B", "OP340A","OP340B", "OP350A","OP350B", "OP360","OP365","OP370", "OP390", "OP470");
54
55     //采集模组工位 ModuleCode
56     public List<String> moduleCodeList = Arrays.asList("OP300A","OP310A","OP310B","OP300B","OP320A","OP320B","OP340A","OP340B","OP365", "OP350A", "OP350B", "OP330");
57
58     //区分模组型号工位
59     public List<String> distinguishingModules = Arrays.asList("OP300","OP310", "OP340", "OP350", "OP330");
60
61     //区分小车码
62     public List<String> agvId = Arrays.asList("OP360", "OP390", "OP470","OP280");
63
64
65     //区分pack型号的工位
66     public List<String> packIdList = Arrays.asList("OP280","OP360","OP390","OP470");
67
68     //测试设备手动工位
69     public List<String> testList = Arrays.asList("OP430-1","OP430-2","OP430-3","OP430-4","OP480-1","OP480-2","OP480-3","OP440");
70
71
72     //空的
73     public List<String> nullList = Arrays.asList("OP250","OP260");
74
75
76     public static MiloService miloService;
77
78     Map<String, Session> map = WebSocketUsers.getUsers();
79
80     public IDaPassingStationCollectionService daPassingStationCollectionService;
81
82     public static IDaCollectionParamConfService collectionParamConfService;
83
84     public static IDaParamCollectionService daParamCollectionService;
85
86     public static IOmProductionOrdeInfoService omProductionOrdeInfoService;
87
88     private static IDaTestDeviceInterfaceService daTestDeviceInterfaceService;
89
90
91     public OPCUaSubscription(MiloService miloService,
92                              IDaPassingStationCollectionService daPassingStationCollectionService,
93                              IDaCollectionParamConfService collectionParamConfService,
94                              IDaParamCollectionService daParamCollectionService,
95                              IOmProductionOrdeInfoService omProductionOrdeInfoService,
96                              IDaTestDeviceInterfaceService daTestDeviceInterfaceService) {
97         OPCUaSubscription.miloService = miloService;
98         this.daPassingStationCollectionService = daPassingStationCollectionService;
99         OPCUaSubscription.collectionParamConfService = collectionParamConfService;
100         OPCUaSubscription.daParamCollectionService = daParamCollectionService;
101         OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService;
102         OPCUaSubscription.daTestDeviceInterfaceService = daTestDeviceInterfaceService;
103     }
104
105
106     @Override
107     public void onSubscribe(String identifier, Object value) {
108
109         logger.info("地址:"+identifier+"值:"+value);
110         try {
111             if(null != value && Integer.valueOf(value.toString())!= 0) {
112                 String[] nodes = identifier.split("[.]");
113                 String thoroughfare = nodes[0];//通道
114                 String device = nodes[1];//设备
115                 String tab = nodes[2];//标记
116                 String tabVlaue = value.toString();//地址值
117
118                 if (("RecordData").equals(tab)) {
119                     String recordDataDoneValue = "";
120
121                     if("1".equals(tabVlaue)){
122
123                         //请求工单
124 //                        if(device.equals("OP230")){
125 //                            getFactoryOrder("OP230");
126 //                        }
127
128                         //自动工位
129                         if(automaticList.stream().anyMatch(s -> s.equals(device))){
130                             //plc给我们一个模组码,拿模组码校验出型号
131                             if(moduleCodeList.stream().anyMatch(s -> s.equals(device))) {
132                                 String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
133                                 //读模组码
134                                 Object moduleCode = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
135                                 if(device.equals("OP365")){
136                                     Object moduleCodeA = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCodeA").getValue();
137                                     Object moduleCodeB = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCodeB").getValue();
138                                     if(moduleCodeA!=null && moduleCodeB!=null){
139                                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build());
140                                     }else {
141                                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(12).build());
142                                     }
143                                     return;
144                                 }
145
146                                 if(moduleCode!=null){
147                                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build());
148                                 }else {
149                                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(12).build());
150                                 }
151                             }else {
152                                 if(agvId.stream().anyMatch(s -> s.equals(device))){
153                                     Object agvIdObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".AGVID").getValue();
154                                     //agvId 小车码是否为空
155                                     if(agvIdObject!=null){
156                                         String PACKCode = thoroughfare + "." + device + ".MPACKCode";
157                                         OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getTrolleyYard, agvIdObject.toString()));
158                                         //小车码查找工单是否为空
159                                         if(one!=null){
160                                             String packId = one.getProductNum();
161                                             miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(PACKCode).value(packId).build());
162                                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
163                                         }else {
164                                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
165                                         }
166                                     }else {
167                                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
168                                     }
169
170                                 }else {
171                                     String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
172                                     Object packCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".PACKCode").getValue();
173                                     if(packCodeObject!=null){
174                                         //pack 如果区分型号的话就要处理
175                                         //记录数据完成
176                                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build());
177                                     }else {
178                                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(12).build());
179                                     }
180                                 }
181                             }
182                         }else {
183                             //手动工位处理逻辑
184 //                            if (map.containsKey(device)){
185                                 WebSocketUsers.sendMessageToUserByText(map.get(device), "IN");
186                                 String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
187                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build());
188 //                            }
189                         }
190
191
192                     }else if("2".equals(tabVlaue)){
193                         if(automaticList.stream().anyMatch(s -> s.equals(device))){
194                             //自动工位
195                             //出站保存数据
196                             outSaveDate(thoroughfare,device);
197                             //记录数据完成
198                             /*String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
199                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf(recordDataDoneValue)).build());*/
200                         }else {
201                             //手动工位
202 //                            if(device.contains("OP330")){
203 //                                String str = device.substring(0,5);
204 //                                WebSocketUsers.sendMessageToUserByText(map.get(str), "END");
205 //                            }else {
206                                 WebSocketUsers.sendMessageToUserByText(map.get(device), "END");
207 //                            }
208                             if(testList.stream().anyMatch(s -> s.equals(device))){
209                                 String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
210                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
211 //                                Object packCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
212 //                                DaTestDeviceInterface deviceInterfaceOne = null;
213 //
214 //                                if (ObjectUtil.isNotNull(packCodeObject)) {
215 //                                    String modelCode = packCodeObject.toString();
216 //                                    deviceInterfaceOne = daTestDeviceInterfaceService.getOne(new LambdaQueryWrapper<DaTestDeviceInterface>()
217 //                                            .eq(DaTestDeviceInterface::getProductNum, modelCode)
218 //                                            .eq(DaTestDeviceInterface::getStationCode, device));
219 //                                }
220 //
221 //                                if (deviceInterfaceOne != null && "1".equals(deviceInterfaceOne.getTotalResult())) {
222 //                                    writeToOpc(RecordDataDoneAddress, (short) 21);
223 //                                } else {
224 //                                    writeToOpc(RecordDataDoneAddress, (short) 22);
225 //                                }
226 //                                writeToOpc(RecordDataDoneAddress, (short) 21);
227                             }
228
229
230                         }
231                     }else {
232                         System.out.println("^");
233                     }
234                 }
235                 //保存拧紧数据
236                 else if (("AngleResult").equals(tab)) {
237                     if("1".equals(tabVlaue)||"2".equals(tabVlaue)){
238                         List<String> list = new ArrayList<>();
239                         String[] suffixes = {"Torque", "Angle", "TorqueResult", "AngleResult"};
240
241                         for (String suffix : suffixes) {
242                             String string = thoroughfare + "." + device + "." + suffix;
243                             list.add(string);
244                         }
245                         List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list);
246                         List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList());
247                         String joinedString = String.join(",", collect.toString());
248                         WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString));
249                         if(device.contains("270") || device.contains("260")){
250                             logger.info("读取到工位{}的Scaner数据:{}",device,TightenTheConversionOkNg(joinedString));
251                         }
252                     }
253                 }
254             }
255         } catch (Exception e) {
256             logger.info("订阅方法报错:{}"+e.getMessage());
257             logger.error("订阅方法报错",e);
258         }
259     }
260
261
262
263     /**
264      * 获取SNCode
265      */
266     public String getSNCode(){
267         String SNCode = "";
268         return SNCode;
269     }
270
271     /**
272      * 出站保存数据
273      */
274     public void outSaveDate(String thoroughfare,String device) {
275         String snCode = "";
276         String result = "";
277         String read = thoroughfare + "." + device + ".";
278
279         try {
280             if(nullList.stream().noneMatch(s -> s.equals(device))){//删除……………………………………………………
281                 if(moduleCodeList.stream().anyMatch(s -> s.equals(device))){
282                     read = read + "ModuleCode";
283                 }else {
284                     read = read + "PACKCode";
285                 }
286             }
287             if(device.equals("OP365")){
288                 try {
289                    saveStationInfo365(thoroughfare,device);
290                 }catch (Exception e){
291                     e.printStackTrace();
292                 }
293             }else {
294                 snCode = miloService.readFromOpcUa(read).getValue().toString();
295
296                 if(null == snCode || "".equals(snCode)){
297                     String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
298                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf("22")).build());
299                 }else{
300
301                     String workOrderNo = "";
302                     String productCode = "";
303                     //2、保存过站采集数据
304                     Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue();
305                     if(orderNumberObject!=null){
306                         workOrderNo = orderNumberObject.toString();
307                     }
308
309                     Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue();
310                     if(productCodeObject!=null){
311                         productCode = productCodeObject.toString();
312                     }
313
314                     saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode);
315                     //3、保存参数采集数据
316                     List<DaParamCollection> daParamCollectionList = SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode);
317
318                     //如果是末尾工站要报工
319                     if(device.equals("OP500")){
320                         RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date()));
321                         //1、更新工单信息
322                         updateOrderInfo(snCode);
323                     }
324
325                     try{
326                         daParamCollectionService.automaticWorkstationPushGeelycvMesFeedback(snCode,device,daParamCollectionList);
327                     }catch (Exception e){
328                     }
329                 }
330
331             }
332         }catch (Exception e) {
333             logger.error("出站保存数据异常:"+e);
334         }
335     }
336
337
338 //    /**
339 //     * 出站保存数据
340 //     */
341 //    public String outSaveDate(String thoroughfare,String device) {
342 //        String result = "";
343 //        try {
344 //            //读取SNCode
345 //            String PACKCode = thoroughfare + "." + device + ".PACKCode";
346 //            Object PACKCodeObject = miloService.readFromOpcUa(PACKCode).getValue();
347 //            if(null == PACKCodeObject || "".equals(PACKCodeObject)){
348 //               result = "22";
349 //            }else{
350 //                String PACKCodeParam = PACKCodeObject.toString();
351 //                //1、更新工单信息
352 //                //updateOrderInfo();
353 //                //2、保存过站采集数据
354 //                saveStationInfo(PACKCodeParam,thoroughfare,device);
355 //                //3、保存参数采集数据
356 //                SaveParamData(PACKCodeParam,thoroughfare,device,"","");
357 //
358 //                result = "21";
359 //
360 //            }
361 //
362 //        }catch (Exception e) {
363 //
364 //        }
365 //        return result;
366 //    }
367
368     /**
369      * 保存过站采集
370      */
371     public void saveStationInfo(String packCode,String thoroughfare,String device,String workOrderNo,String productCode) throws Exception {
372         logger.info("进入工位{}-方法saveStationInfo",device);
373         SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
374         sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); // CST通常表示中国标准时间,即东八区
375         String prefix = thoroughfare+"."+device+".";
376         String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString();
377         String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString();
378         String stationStatus = miloService.readFromOpcUa(prefix + "StationStatus").getValue().toString();
379
380         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
381         daPassingStationCollection.setSfcCode(packCode);
382         daPassingStationCollection.setWorkOrderNo(workOrderNo);
383         daPassingStationCollection.setProductCode(productCode);
384         daPassingStationCollection.setLocationCode(device);
385         String strt = TimeUtil.stringProcessing(startTime);
386         String end = TimeUtil.stringProcessing(stopTime);
387         daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//入站时间
388         daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//出站时间
389         daPassingStationCollection.setOutRsSign(stationStatus);//出站是否合格
390         daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection);
391         logger.info("结束工位{}-方法saveStationInfo",device);
392     }
393
394     public static List<DaParamCollection> SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception {
395         logger.info("进入工位{}-方法SaveParamData",device);
396         List<DaCollectionParamConf> list;
397         DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
398         daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device);
399         list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
400         List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
401
402         List<String> nodeIdList = list.stream().map(info -> {
403             String nodeid = info.getGatherAddress();
404             return nodeid;
405         }).collect(Collectors.toList());
406
407         if(!nodeIdList.isEmpty()){
408             List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
409             for(int i=0;i<nodeIdList.size();i++){
410                 if(readWriteEntityList.get(i).getValue() == null){
411                     readWriteEntityList.get(i).setValue(" ");
412                 }
413                 String paramValue = readWriteEntityList.get(i).getValue().toString();
414                 DaParamCollection ParamCollection = new DaParamCollection();
415                 ParamCollection.setParamCode(list.get(i).getCollectParameterId());
416                 ParamCollection.setLocationCode(device);
417                 if(paramValue.contains("Time")){
418                     ParamCollection.setParamValue(TimeUtil.test(TimeUtil.stringProcessing(paramValue)));
419                 }else {
420                     ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
421                 }
422                 ParamCollection.setSfcCode(packCode);
423                 if(device.contains("OP360")){
424                     String node = nodeIdList.get(i);
425                     Object value = miloService.readFromOpcUa("PACK.OP360.ModuleSNCode"+node.charAt(node.length()-1)).getValue();
426                     if(value!=null){
427                         ParamCollection.setModuleCode(value.toString());
428                     }
429                 }
430                 ParamCollection.setParamName(list.get(i).getCollectParameterName());
431                 ParamCollection.setParamUpper(list.get(i).getParamUpper());
432                 ParamCollection.setParamLower(list.get(i).getParamLower());
433                 ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
434                 ParamCollection.setType(list.get(i).getCollectParameterType());
435                 ParamCollection.setCollectionTime(new Date());
436                 ParamCollection.setWorkOrderNo(workOrderNo);
437                 ParamCollection.setProductCode(productType);
438                 daParamCollectionlist.add(ParamCollection);
439             }
440         }
441         String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
442         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf("21")).build());
443         logger.info("给工位{}写了21",device);
444         daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
445         List<DaParamCollection> baseDataList = addBaseData(workOrderNo,productType,device,packCode);
446         for (int i = 0; i < baseDataList.size(); i++){
447             daParamCollectionlist.add(baseDataList.get(i));
448         }
449         logger.info("结束工位{}-方法SaveParamData",device);
450         return daParamCollectionlist;
451     }
452
453     public static List<DaParamCollection> addBaseData(String workOrderNo,String productCode,String locationCode,String packCode){
454         Map<String, String> map = new HashMap<>();
455         map.put("GC", "南浔工厂");
456         map.put("CXBH", "Pack线");
457         map.put("SBBH", "设备001");
458         map.put("YGBH", "员工001");
459         List<DaParamCollection> confList = new ArrayList<>();
460         map.forEach((key, value) -> {
461             List<DaCollectionParamConf> daCollectionParamConfs = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
462                     .eq(DaCollectionParamConf::getProcessesCode,locationCode)
463                     .like(DaCollectionParamConf::getCollectParameterId,key));
464             DaParamCollection saveData = new DaParamCollection();
465             saveData.setWorkOrderNo(workOrderNo);
466             saveData.setProductCode(productCode);
467             saveData.setLocationCode(locationCode);
468             saveData.setSfcCode(packCode);
469             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
470             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
471             saveData.setCollectionTime(new Date());
472             saveData.setParamValue(value);
473             confList.add(saveData);
474         });
475         daParamCollectionService.insertBatch(confList);
476         return confList;
477     }
478
479     public static void getFactoryOrder(String locationCode){
480         String productionWorkOrder = RestfulService.getProductionWorkOrderRequest("", locationCode);
481         JSONObject jsonObject = new JSONObject(productionWorkOrder);
482         JSONObject dataObject = jsonObject.getJSONObject("data");
483
484         String productNum = dataObject.getStr("productNum");
485         String stationCode = dataObject.getStr("stationCode");
486         String materialCode = dataObject.getStr("materialCode");
487         String productionOrderNum = dataObject.getStr("productionOrderNum");
488
489         OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
490         omProductionOrdeInfo.setProductNum(productNum);
491         omProductionOrdeInfo.setWorkOrderNo(productionOrderNum);
492         omProductionOrdeInfo.setStationCode(stationCode);
493         omProductionOrdeInfo.setProductCode(materialCode);
494         omProductionOrdeInfoService.save(omProductionOrdeInfo);
495     }
496
497     public static void updateOrderInfo(String packCode){
498         OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, packCode));
499         one.setOrderStatus("5");
500         omProductionOrdeInfoService.saveOrUpdate(one);
501     }
502
503     public static void avgFunction(){
504
505     }
506
507     public static String TightenTheConversionOkNg(String param){
508         // 去除首尾的方括号,然后按照逗号分割字符串
509         String[] parts = param.substring(1, param.length() - 1).split(",");
510
511         // 创建一个新的StringBuilder来构建替换后的字符串
512         StringBuilder sb = new StringBuilder();
513         sb.append('['); // 添加左方括号
514
515         for (int i = 0; i < parts.length; i++) {
516             String part = parts[i].trim(); // 去除可能的空格
517             float value;
518             try {
519                 value = Float.parseFloat(part); // 尝试将字符串转换为浮点数
520                 String replacement;
521                 if(i<2){
522                     replacement = part;
523                 }else{
524                     if (value == 1f) {
525                         replacement = "OK";
526                     } else{
527                         replacement = "NG";
528                     }
529                 }
530             /*    if (value == 1f) {
531                     replacement = "OK";
532                 } else if (value == 2f) {
533                     replacement = "NG";
534                 } else {
535                     replacement = part; // 如果不是1或2,则保持不变
536                 }*/
537                 sb.append(replacement);
538                 if (i < parts.length - 1) {
539                     sb.append(','); // 添加逗号(除了最后一个元素)
540                 }
541             } catch (NumberFormatException e) {
542                 // 如果转换失败,则保持原样(或进行其他错误处理)
543                 sb.append(part);
544                 if (i < parts.length - 1) {
545                     sb.append(',');
546                 }
547             }
548         }
549         sb.append(']'); // 添加右方括号
550         return sb.toString();
551     }
552
553
554     /**
555      * 校验是否存在NG
556      * @param packCode sfcCode
557      * @return boolean
558      */
559     public boolean checkIsNG(String packCode,String modelCode){
560         List<DaPassingStationCollection> list = daPassingStationCollectionService.list(new LambdaQueryWrapper<DaPassingStationCollection>()
561                 .eq(StrUtil.isNotBlank(packCode),DaPassingStationCollection::getSfcCode, packCode)
562                 .eq(DaPassingStationCollection::getOutRsSign, Constants.UN_PASS));
563         return CollUtil.isEmpty(list);
564     }
565
566     /**
567      * 保存过站采集
568      */
569     public void saveStationInfo365(String thoroughfare,String device) throws Exception {
570         String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
571         String prefix = thoroughfare+"."+device+".";
572         List<DaPassingStationCollection> passingStationCollections = new ArrayList<>();
573         String ModuleCodeA = "";
574         String ModuleCodeB = "";
575         String StationStatusA = "";
576         String StationStatusB = "";
577
578         Object objectModuleCodeA = miloService.readFromOpcUa(prefix + "ModuleCodeA").getValue();
579         Object objectModuleCodeB = miloService.readFromOpcUa(prefix + "ModuleCodeB").getValue();
580         Object objectStationStatusA = miloService.readFromOpcUa(prefix + "StationStatusA").getValue();
581         Object objectStationStatusB = miloService.readFromOpcUa(prefix + "StationStatusB").getValue();
582
583         if(ObjectUtil.isNotNull(objectModuleCodeA) && ObjectUtil.isNotNull(objectStationStatusA) && ObjectUtil.isNotNull(objectModuleCodeB) && ObjectUtil.isNotNull(objectStationStatusB)){
584             ModuleCodeA = objectModuleCodeA.toString();
585             ModuleCodeB = objectModuleCodeB.toString();
586             StationStatusA = objectStationStatusA.toString();
587             StationStatusB = objectStationStatusB.toString();
588
589             String[] modeles = {ModuleCodeA,ModuleCodeB};
590             String[] StationStatus = {StationStatusA,StationStatusB};
591
592             String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString();
593             String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString();
594             for (int i = 0; i < 2; i++) {
595                 DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
596                 String strt = TimeUtil.stringProcessing(startTime);
597                 String end = TimeUtil.stringProcessing(stopTime);
598                 daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//入站时间
599                 daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//出站时间
600                 daPassingStationCollection.setSfcCode(modeles[i]);
601                 daPassingStationCollection.setLocationCode(device);
602                 daPassingStationCollection.setOutRsSign(StationStatus[i]);//出站是否合格
603                 passingStationCollections.add(daPassingStationCollection);
604             }
605             daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections);
606             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
607             logger.info("工位{}回复21",device);
608
609         }else {
610             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build());
611         }
612     }
613
614     private static void writeToOpc(String identifier, short value) {
615         try {
616             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(identifier).value(value).build());
617         } catch (Exception e) {
618             throw new RuntimeException(e);
619         }
620     }
621
622 }