-
admin
2024-05-17 1ccd6932893e47722574e6d1147e63b2ec4972c1
提交 | 用户 | 时间
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
3581b1 48     public List<String> moduleCodeList = Arrays.asList("OP300A","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                             //手动工位处理逻辑
288790 175                             WebSocketUsers.sendMessageToUserByText(map.get(device), "IN");
e70fb4 176                             String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
A 177
178                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build());
32483a 179                         }
e70fb4 180
7bff29 181
a5b351 182                     }else if("2".equals(tabVlaue)){
32483a 183                         if(automaticList.stream().anyMatch(s -> s.equals(device))){
184                             //自动工位
185                             //出站保存数据
186                             recordDataDoneValue = outSaveDate(thoroughfare,device);
187                             //记录数据完成
188                             String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
70cc26 189                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf(recordDataDoneValue)).build());
32483a 190                         }else {
191                             //手动工位
1c84ae 192                             if(device.contains("OP330")){
A 193                                 String str = device.substring(0,5);
194                                 WebSocketUsers.sendMessageToUserByText(map.get(str), "END");
195                             }else {
196                                 WebSocketUsers.sendMessageToUserByText(map.get(device), "END");
288790 197                             }
A 198                             if(testList.stream().anyMatch(s -> s.equals(device))){
199                                 String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
1ccd69 200 //                                Object packCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
A 201 //                                DaTestDeviceInterface deviceInterfaceOne = null;
202 //
203 //                                if (ObjectUtil.isNotNull(packCodeObject)) {
204 //                                    String modelCode = packCodeObject.toString();
205 //                                    deviceInterfaceOne = daTestDeviceInterfaceService.getOne(new LambdaQueryWrapper<DaTestDeviceInterface>()
206 //                                            .eq(DaTestDeviceInterface::getProductNum, modelCode)
207 //                                            .eq(DaTestDeviceInterface::getStationCode, device));
208 //                                }
209 //
210 //                                if (deviceInterfaceOne != null && "1".equals(deviceInterfaceOne.getTotalResult())) {
211 //                                    writeToOpc(RecordDataDoneAddress, (short) 21);
212 //                                } else {
213 //                                    writeToOpc(RecordDataDoneAddress, (short) 22);
214 //                                }
215                                 writeToOpc(RecordDataDoneAddress, (short) 21);
1c84ae 216                             }
1ccd69 217
A 218
32483a 219                         }
3c2299 220                     }else {
221                         System.out.println("^");
222                     }
223                 }
224                 //保存拧紧数据
225                 else if (("AngleResult").equals(tab)) {
b5fcd8 226                     if("1".equals(tabVlaue)||"2".equals(tabVlaue)){
32483a 227                         List<String> list = new ArrayList<>();
0caf87 228                         String[] suffixes = {"Torque", "Angle", "TorqueResult", "AngleResult"};
32483a 229
230                         for (String suffix : suffixes) {
231                             String string = thoroughfare + "." + device + "." + suffix;
232                             list.add(string);
233                         }
49c784 234                         List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list);
235                         List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList());
236                         String joinedString = String.join(",", collect.toString());
4a5f2a 237                         WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString));
a5b351 238                     }
C 239                 }
240             }
241         } catch (Exception e) {
242
243         }
244     }
245
246
247
248     /**
249      * 获取SNCode
250      */
251     public String getSNCode(){
252         String SNCode = "";
253         return SNCode;
254     }
255
256     /**
257      * 出站保存数据
258      */
259     public String outSaveDate(String thoroughfare,String device) {
8f0f8d 260         String snCode = "";
a5b351 261         String result = "";
8f0f8d 262         String read = thoroughfare + "." + device + ".";
263
a5b351 264         try {
8f0f8d 265             if(nullList.stream().noneMatch(s -> s.equals(device))){
266                 if(moduleCodeList.stream().anyMatch(s -> s.equals(device))){
267                     read = read + "ModuleCode";
a320dc 268                     if(device.equals("OP365")){
A 269                         try {
270                             saveStationInfo365(thoroughfare,device);
271                         }catch (Exception e){
272                             e.printStackTrace();
273                         }
274                     }
8f0f8d 275                 }else {
276                     read = read + "PACKCode";
277                 }
278             }
279             snCode = miloService.readFromOpcUa(read).getValue().toString();
280
281             if(null == snCode || "".equals(snCode)){
282                 result = "22";
a5b351 283             }else{
8f0f8d 284
e70fb4 285                 String workOrderNo = "";
A 286                 String productCode = "";
287                 //2、保存过站采集数据
288                 Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue();
289                 if(orderNumberObject!=null){
290                     workOrderNo = orderNumberObject.toString();
291                 }
292
293                 Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue();
294                 if(productCodeObject!=null){
295                     productCode = productCodeObject.toString();
296                 }
89f416 297
8f0f8d 298                 saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode);
a5b351 299                 //3、保存参数采集数据
8f0f8d 300                 SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode);
e70fb4 301
A 302                 //如果是末尾工站要报工
303                 if(device.equals("OP500")){
304                     RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date()));
305                     //1、更新工单信息
306                     updateOrderInfo(snCode);
307                 }
a320dc 308                 try{
A 309                     daParamCollectionService.pushGeelycvMesFeedback(snCode,device);
310                 }catch (Exception e){
311                 }
a5b351 312                 result = "21";
C 313
314             }
315
316         }catch (Exception e) {
8f0f8d 317             System.out.println(e.getMessage());
a5b351 318         }
C 319         return result;
320     }
321
8f0f8d 322
323 //    /**
324 //     * 出站保存数据
325 //     */
326 //    public String outSaveDate(String thoroughfare,String device) {
327 //        String result = "";
328 //        try {
329 //            //读取SNCode
330 //            String PACKCode = thoroughfare + "." + device + ".PACKCode";
331 //            Object PACKCodeObject = miloService.readFromOpcUa(PACKCode).getValue();
332 //            if(null == PACKCodeObject || "".equals(PACKCodeObject)){
333 //               result = "22";
334 //            }else{
335 //                String PACKCodeParam = PACKCodeObject.toString();
336 //                //1、更新工单信息
337 //                //updateOrderInfo();
338 //                //2、保存过站采集数据
339 //                saveStationInfo(PACKCodeParam,thoroughfare,device);
340 //                //3、保存参数采集数据
341 //                SaveParamData(PACKCodeParam,thoroughfare,device,"","");
342 //
343 //                result = "21";
344 //
345 //            }
346 //
347 //        }catch (Exception e) {
348 //
349 //        }
350 //        return result;
351 //    }
352
a5b351 353     /**
C 354      * 保存过站采集
355      */
8f0f8d 356     public void saveStationInfo(String packCode,String thoroughfare,String device,String workOrderNo,String productCode) throws Exception {
c5e9c5 357         SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
358         sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); // CST通常表示中国标准时间,即东八区
32483a 359         String prefix = thoroughfare+"."+device+".";
c5e9c5 360         String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString();
361         String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString();
32483a 362         String stationStatus = miloService.readFromOpcUa(prefix + "StationStatus").getValue().toString();
363
a5b351 364         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
32483a 365         daPassingStationCollection.setSfcCode(packCode);
366         daPassingStationCollection.setWorkOrderNo(workOrderNo);
8f0f8d 367         daPassingStationCollection.setProductCode(productCode);
368         daPassingStationCollection.setLocationCode(device);
c5e9c5 369         String strt = TimeUtil.stringProcessing(startTime);
370         String end = TimeUtil.stringProcessing(stopTime);
616f98 371         daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//入站时间
A 372         daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//出站时间
32483a 373         daPassingStationCollection.setOutRsSign(stationStatus);//出站是否合格
a5b351 374         daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection);
C 375     }
376
054a69 377     public static void SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception {
a5b351 378         List<DaCollectionParamConf> list;
C 379         DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
380         daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device);
381         list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
382
383         List<String> nodeIdList = list.stream().map(info -> {
384             String nodeid = info.getGatherAddress();
385             return nodeid;
386         }).collect(Collectors.toList());
387
388         if(!nodeIdList.isEmpty()){
389             List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
e70fb4 390             for (int i = 0; i < readWriteEntityList.size(); i++) {
A 391                 if(readWriteEntityList.get(i).getValue() == null){
392                     readWriteEntityList.get(i).setValue(" ");
393                 }
394             }
a5b351 395             List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
C 396             for(int i=0;i<nodeIdList.size();i++){
397                 if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){
c5e9c5 398                     String tt = readWriteEntityList.get(i).getValue().toString();
32483a 399                     DaParamCollection ParamCollection = new DaParamCollection();
400                     ParamCollection.setParamCode(list.get(i).getCollectParameterId());
a5b351 401                     ParamCollection.setLocationCode(device);
c5e9c5 402                     if(tt.contains("Time")){
288790 403 //                        String str = TimeUtil.getTimestamp(TimeUtil.stringProcessing(tt));
A 404 //                        ParamCollection.setParamValue(str);
616f98 405                         ParamCollection.setParamValue(TimeUtil.test(TimeUtil.stringProcessing(tt)));
c5e9c5 406                     }else {
407                         ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
408                     }
32483a 409                     ParamCollection.setSfcCode(packCode);
288790 410                     if(device.contains("OP360")){
A 411                         String node = nodeIdList.get(i);
412                         Object value = miloService.readFromOpcUa("PACK.OP360.ModuleSNCode"+node.charAt(node.length()-1)).getValue();
413                         if(value!=null){
414                             ParamCollection.setModuleCode(value.toString());
415                         }
416                     }
a5b351 417                     ParamCollection.setParamName(list.get(i).getCollectParameterName());
C 418                     ParamCollection.setParamUpper(list.get(i).getParamUpper());
419                     ParamCollection.setParamLower(list.get(i).getParamLower());
420                     ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
421                     //ParamCollection.setState("合格");
422                     ParamCollection.setType(list.get(i).getCollectParameterType());
423                     ParamCollection.setCollectionTime(new Date());
054a69 424                     ParamCollection.setWorkOrderNo(workOrderNo);
425                     ParamCollection.setProductCode(productType);
426                     daParamCollectionlist.add(ParamCollection);
427 //                    daParamCollectionService.insertDaParamCollection(ParamCollection);
a5b351 428                 }
C 429             }
054a69 430             daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
a5b351 431         }
8f0f8d 432         addBaseData(workOrderNo,productType,device,packCode);
a5b351 433
C 434     }
8f0f8d 435
436     public static void addBaseData(String workOrderNo,String productCode,String locationCode,String packCode){
437         Map<String, String> map = new HashMap<>();
438         map.put("GC", "南浔工厂");
439         map.put("CXBH", "Pack线");
440         map.put("SBBH", "设备001");
441         map.put("YGBH", "员工001");
442         List<DaParamCollection> confList = new ArrayList<>();
443         map.forEach((key, value) -> {
444             List<DaCollectionParamConf> daCollectionParamConfs = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
445                     .eq(DaCollectionParamConf::getProcessesCode,locationCode)
446                     .like(DaCollectionParamConf::getCollectParameterId,key));
447             DaParamCollection saveData = new DaParamCollection();
448             saveData.setWorkOrderNo(workOrderNo);
449             saveData.setProductCode(productCode);
450             saveData.setLocationCode(locationCode);
451             saveData.setSfcCode(packCode);
452             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
453             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
454             saveData.setCollectionTime(new Date());
455             saveData.setParamValue(value);
456             confList.add(saveData);
457         });
458         daParamCollectionService.insertBatch(confList);
459     }
e70fb4 460
A 461     public static void getFactoryOrder(String locationCode){
462         String productionWorkOrder = RestfulService.getProductionWorkOrderRequest("", locationCode);
463         JSONObject jsonObject = new JSONObject(productionWorkOrder);
464         JSONObject dataObject = jsonObject.getJSONObject("data");
465
466         String productNum = dataObject.getStr("productNum");
467         String stationCode = dataObject.getStr("stationCode");
468         String materialCode = dataObject.getStr("materialCode");
469         String productionOrderNum = dataObject.getStr("productionOrderNum");
470
471         OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
472         omProductionOrdeInfo.setProductNum(productNum);
473         omProductionOrdeInfo.setWorkOrderNo(productionOrderNum);
474         omProductionOrdeInfo.setStationCode(stationCode);
475         omProductionOrdeInfo.setProductCode(materialCode);
476         omProductionOrdeInfoService.save(omProductionOrdeInfo);
477     }
478
479     public static void updateOrderInfo(String packCode){
480         OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, packCode));
481         one.setOrderStatus("5");
482         omProductionOrdeInfoService.saveOrUpdate(one);
483     }
484
4a5f2a 485     public static void avgFunction(){
A 486
487     }
488
489     public static String TightenTheConversionOkNg(String param){
490         // 去除首尾的方括号,然后按照逗号分割字符串
491         String[] parts = param.substring(1, param.length() - 1).split(",");
492
493         // 创建一个新的StringBuilder来构建替换后的字符串
494         StringBuilder sb = new StringBuilder();
495         sb.append('['); // 添加左方括号
496
497         for (int i = 0; i < parts.length; i++) {
498             String part = parts[i].trim(); // 去除可能的空格
499             float value;
500             try {
501                 value = Float.parseFloat(part); // 尝试将字符串转换为浮点数
502                 String replacement;
503                 if (value == 1f) {
504                     replacement = "OK";
505                 } else if (value == 2f) {
506                     replacement = "NG";
507                 } else {
508                     replacement = part; // 如果不是1或2,则保持不变
509                 }
510                 sb.append(replacement);
511                 if (i < parts.length - 1) {
512                     sb.append(','); // 添加逗号(除了最后一个元素)
513                 }
514             } catch (NumberFormatException e) {
515                 // 如果转换失败,则保持原样(或进行其他错误处理)
516                 sb.append(part);
517                 if (i < parts.length - 1) {
518                     sb.append(',');
519                 }
520             }
521         }
522         sb.append(']'); // 添加右方括号
523         return sb.toString();
524     }
525
6a462f 526
W 527     /**
528      * 校验是否存在NG
529      * @param packCode sfcCode
530      * @return boolean
531      */
532     public boolean checkIsNG(String packCode,String modelCode){
533         List<DaPassingStationCollection> list = daPassingStationCollectionService.list(new LambdaQueryWrapper<DaPassingStationCollection>()
534                 .eq(StrUtil.isNotBlank(packCode),DaPassingStationCollection::getSfcCode, packCode)
535                 .eq(DaPassingStationCollection::getOutRsSign, Constants.UN_PASS));
536         return CollUtil.isEmpty(list);
537     }
538
a320dc 539     /**
A 540      * 保存过站采集
541      */
542     public void saveStationInfo365(String thoroughfare,String device) throws Exception {
543         String prefix = thoroughfare+"."+device+".";
544         List<DaPassingStationCollection> passingStationCollections = new ArrayList<>();
545         String ModuleCodeA = miloService.readFromOpcUa(prefix + "ModuleCodeA").getValue().toString();
546         String ModuleCodeB = miloService.readFromOpcUa(prefix + "ModuleCodeB").getValue().toString();
547         String StationStatusA = miloService.readFromOpcUa(prefix + "StationStatusA").getValue().toString();
548         String StationStatusB = miloService.readFromOpcUa(prefix + "StationStatusB").getValue().toString();
549         String[] modeles = {ModuleCodeA,ModuleCodeB};
550         String[] StationStatus = {StationStatusA,StationStatusB};
551
552         String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString();
553         String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString();
554         for (int i = 0; i < 2; i++) {
555             DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
556             String strt = TimeUtil.stringProcessing(startTime);
557             String end = TimeUtil.stringProcessing(stopTime);
558             daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//入站时间
559             daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//出站时间
560             daPassingStationCollection.setSfcCode(modeles[i]);
561             daPassingStationCollection.setLocationCode(device);
562             daPassingStationCollection.setOutRsSign(StationStatus[i]);//出站是否合格
563             passingStationCollections.add(daPassingStationCollection);
564         }
565         daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections);
566         String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
567         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
568         return;
569     }
570
1ccd69 571     private static void writeToOpc(String identifier, short value) {
A 572         try {
573             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(identifier).value(value).build());
574         } catch (Exception e) {
575             throw new RuntimeException(e);
576         }
577     }
578
a5b351 579 }