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