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