-
admin
2024-06-04 a759f5fd41414651325494926583843568bac334
提交 | 用户 | 时间
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());
A 254             e.printStackTrace();
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";
a320dc 280                     if(device.equals("OP365")){
A 281                         try {
282                             saveStationInfo365(thoroughfare,device);
283                         }catch (Exception e){
284                             e.printStackTrace();
285                         }
286                     }
8f0f8d 287                 }else {
288                     read = read + "PACKCode";
289                 }
290             }
291             snCode = miloService.readFromOpcUa(read).getValue().toString();
292
293             if(null == snCode || "".equals(snCode)){
294                 result = "22";
a5b351 295             }else{
8f0f8d 296
e70fb4 297                 String workOrderNo = "";
A 298                 String productCode = "";
299                 //2、保存过站采集数据
300                 Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue();
301                 if(orderNumberObject!=null){
302                     workOrderNo = orderNumberObject.toString();
303                 }
304
305                 Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue();
306                 if(productCodeObject!=null){
307                     productCode = productCodeObject.toString();
308                 }
89f416 309
8f0f8d 310                 saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode);
a5b351 311                 //3、保存参数采集数据
8f0f8d 312                 SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode);
e70fb4 313
A 314                 //如果是末尾工站要报工
315                 if(device.equals("OP500")){
316                     RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date()));
317                     //1、更新工单信息
318                     updateOrderInfo(snCode);
319                 }
a320dc 320                 try{
A 321                     daParamCollectionService.pushGeelycvMesFeedback(snCode,device);
322                 }catch (Exception e){
323                 }
a5b351 324                 result = "21";
C 325
326             }
327
328         }catch (Exception e) {
8f0f8d 329             System.out.println(e.getMessage());
a5b351 330         }
C 331         return result;
332     }
333
8f0f8d 334
335 //    /**
336 //     * 出站保存数据
337 //     */
338 //    public String outSaveDate(String thoroughfare,String device) {
339 //        String result = "";
340 //        try {
341 //            //读取SNCode
342 //            String PACKCode = thoroughfare + "." + device + ".PACKCode";
343 //            Object PACKCodeObject = miloService.readFromOpcUa(PACKCode).getValue();
344 //            if(null == PACKCodeObject || "".equals(PACKCodeObject)){
345 //               result = "22";
346 //            }else{
347 //                String PACKCodeParam = PACKCodeObject.toString();
348 //                //1、更新工单信息
349 //                //updateOrderInfo();
350 //                //2、保存过站采集数据
351 //                saveStationInfo(PACKCodeParam,thoroughfare,device);
352 //                //3、保存参数采集数据
353 //                SaveParamData(PACKCodeParam,thoroughfare,device,"","");
354 //
355 //                result = "21";
356 //
357 //            }
358 //
359 //        }catch (Exception e) {
360 //
361 //        }
362 //        return result;
363 //    }
364
a5b351 365     /**
C 366      * 保存过站采集
367      */
8f0f8d 368     public void saveStationInfo(String packCode,String thoroughfare,String device,String workOrderNo,String productCode) throws Exception {
c5e9c5 369         SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
370         sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); // CST通常表示中国标准时间,即东八区
32483a 371         String prefix = thoroughfare+"."+device+".";
c5e9c5 372         String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString();
373         String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString();
32483a 374         String stationStatus = miloService.readFromOpcUa(prefix + "StationStatus").getValue().toString();
375
a5b351 376         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
32483a 377         daPassingStationCollection.setSfcCode(packCode);
378         daPassingStationCollection.setWorkOrderNo(workOrderNo);
8f0f8d 379         daPassingStationCollection.setProductCode(productCode);
380         daPassingStationCollection.setLocationCode(device);
c5e9c5 381         String strt = TimeUtil.stringProcessing(startTime);
382         String end = TimeUtil.stringProcessing(stopTime);
616f98 383         daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//入站时间
A 384         daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//出站时间
32483a 385         daPassingStationCollection.setOutRsSign(stationStatus);//出站是否合格
a5b351 386         daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection);
C 387     }
388
054a69 389     public static void SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception {
a5b351 390         List<DaCollectionParamConf> list;
C 391         DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
392         daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device);
393         list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
394
395         List<String> nodeIdList = list.stream().map(info -> {
396             String nodeid = info.getGatherAddress();
397             return nodeid;
398         }).collect(Collectors.toList());
399
400         if(!nodeIdList.isEmpty()){
401             List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
e70fb4 402             for (int i = 0; i < readWriteEntityList.size(); i++) {
A 403                 if(readWriteEntityList.get(i).getValue() == null){
404                     readWriteEntityList.get(i).setValue(" ");
405                 }
406             }
a5b351 407             List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
C 408             for(int i=0;i<nodeIdList.size();i++){
409                 if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){
c5e9c5 410                     String tt = readWriteEntityList.get(i).getValue().toString();
32483a 411                     DaParamCollection ParamCollection = new DaParamCollection();
412                     ParamCollection.setParamCode(list.get(i).getCollectParameterId());
a5b351 413                     ParamCollection.setLocationCode(device);
c5e9c5 414                     if(tt.contains("Time")){
288790 415 //                        String str = TimeUtil.getTimestamp(TimeUtil.stringProcessing(tt));
A 416 //                        ParamCollection.setParamValue(str);
616f98 417                         ParamCollection.setParamValue(TimeUtil.test(TimeUtil.stringProcessing(tt)));
c5e9c5 418                     }else {
419                         ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
420                     }
32483a 421                     ParamCollection.setSfcCode(packCode);
288790 422                     if(device.contains("OP360")){
A 423                         String node = nodeIdList.get(i);
424                         Object value = miloService.readFromOpcUa("PACK.OP360.ModuleSNCode"+node.charAt(node.length()-1)).getValue();
425                         if(value!=null){
426                             ParamCollection.setModuleCode(value.toString());
427                         }
428                     }
a5b351 429                     ParamCollection.setParamName(list.get(i).getCollectParameterName());
C 430                     ParamCollection.setParamUpper(list.get(i).getParamUpper());
431                     ParamCollection.setParamLower(list.get(i).getParamLower());
432                     ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
433                     //ParamCollection.setState("合格");
434                     ParamCollection.setType(list.get(i).getCollectParameterType());
435                     ParamCollection.setCollectionTime(new Date());
054a69 436                     ParamCollection.setWorkOrderNo(workOrderNo);
437                     ParamCollection.setProductCode(productType);
438                     daParamCollectionlist.add(ParamCollection);
439 //                    daParamCollectionService.insertDaParamCollection(ParamCollection);
a5b351 440                 }
C 441             }
054a69 442             daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
a5b351 443         }
8f0f8d 444         addBaseData(workOrderNo,productType,device,packCode);
a5b351 445
C 446     }
8f0f8d 447
448     public static void addBaseData(String workOrderNo,String productCode,String locationCode,String packCode){
449         Map<String, String> map = new HashMap<>();
450         map.put("GC", "南浔工厂");
451         map.put("CXBH", "Pack线");
452         map.put("SBBH", "设备001");
453         map.put("YGBH", "员工001");
454         List<DaParamCollection> confList = new ArrayList<>();
455         map.forEach((key, value) -> {
456             List<DaCollectionParamConf> daCollectionParamConfs = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
457                     .eq(DaCollectionParamConf::getProcessesCode,locationCode)
458                     .like(DaCollectionParamConf::getCollectParameterId,key));
459             DaParamCollection saveData = new DaParamCollection();
460             saveData.setWorkOrderNo(workOrderNo);
461             saveData.setProductCode(productCode);
462             saveData.setLocationCode(locationCode);
463             saveData.setSfcCode(packCode);
464             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
465             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
466             saveData.setCollectionTime(new Date());
467             saveData.setParamValue(value);
468             confList.add(saveData);
469         });
470         daParamCollectionService.insertBatch(confList);
471     }
e70fb4 472
A 473     public static void getFactoryOrder(String locationCode){
474         String productionWorkOrder = RestfulService.getProductionWorkOrderRequest("", locationCode);
475         JSONObject jsonObject = new JSONObject(productionWorkOrder);
476         JSONObject dataObject = jsonObject.getJSONObject("data");
477
478         String productNum = dataObject.getStr("productNum");
479         String stationCode = dataObject.getStr("stationCode");
480         String materialCode = dataObject.getStr("materialCode");
481         String productionOrderNum = dataObject.getStr("productionOrderNum");
482
483         OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
484         omProductionOrdeInfo.setProductNum(productNum);
485         omProductionOrdeInfo.setWorkOrderNo(productionOrderNum);
486         omProductionOrdeInfo.setStationCode(stationCode);
487         omProductionOrdeInfo.setProductCode(materialCode);
488         omProductionOrdeInfoService.save(omProductionOrdeInfo);
489     }
490
491     public static void updateOrderInfo(String packCode){
492         OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, packCode));
493         one.setOrderStatus("5");
494         omProductionOrdeInfoService.saveOrUpdate(one);
495     }
496
4a5f2a 497     public static void avgFunction(){
A 498
499     }
500
501     public static String TightenTheConversionOkNg(String param){
502         // 去除首尾的方括号,然后按照逗号分割字符串
503         String[] parts = param.substring(1, param.length() - 1).split(",");
504
505         // 创建一个新的StringBuilder来构建替换后的字符串
506         StringBuilder sb = new StringBuilder();
507         sb.append('['); // 添加左方括号
508
509         for (int i = 0; i < parts.length; i++) {
510             String part = parts[i].trim(); // 去除可能的空格
511             float value;
512             try {
513                 value = Float.parseFloat(part); // 尝试将字符串转换为浮点数
514                 String replacement;
515                 if (value == 1f) {
516                     replacement = "OK";
517                 } else if (value == 2f) {
518                     replacement = "NG";
519                 } else {
520                     replacement = part; // 如果不是1或2,则保持不变
521                 }
522                 sb.append(replacement);
523                 if (i < parts.length - 1) {
524                     sb.append(','); // 添加逗号(除了最后一个元素)
525                 }
526             } catch (NumberFormatException e) {
527                 // 如果转换失败,则保持原样(或进行其他错误处理)
528                 sb.append(part);
529                 if (i < parts.length - 1) {
530                     sb.append(',');
531                 }
532             }
533         }
534         sb.append(']'); // 添加右方括号
535         return sb.toString();
536     }
537
6a462f 538
W 539     /**
540      * 校验是否存在NG
541      * @param packCode sfcCode
542      * @return boolean
543      */
544     public boolean checkIsNG(String packCode,String modelCode){
545         List<DaPassingStationCollection> list = daPassingStationCollectionService.list(new LambdaQueryWrapper<DaPassingStationCollection>()
546                 .eq(StrUtil.isNotBlank(packCode),DaPassingStationCollection::getSfcCode, packCode)
547                 .eq(DaPassingStationCollection::getOutRsSign, Constants.UN_PASS));
548         return CollUtil.isEmpty(list);
549     }
550
a320dc 551     /**
A 552      * 保存过站采集
553      */
554     public void saveStationInfo365(String thoroughfare,String device) throws Exception {
a60fef 555         String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
a320dc 556         String prefix = thoroughfare+"."+device+".";
A 557         List<DaPassingStationCollection> passingStationCollections = new ArrayList<>();
a60fef 558         String ModuleCodeA = "";
A 559         String ModuleCodeB = "";
560         String StationStatusA = "";
561         String StationStatusB = "";
a320dc 562
a60fef 563         Object objectModuleCodeA = miloService.readFromOpcUa(prefix + "ModuleCodeA").getValue();
A 564         Object objectModuleCodeB = miloService.readFromOpcUa(prefix + "ModuleCodeB").getValue();
565         Object objectStationStatusA = miloService.readFromOpcUa(prefix + "StationStatusA").getValue();
566         Object objectStationStatusB = miloService.readFromOpcUa(prefix + "StationStatusB").getValue();
567
568         if(ObjectUtil.isNotNull(objectModuleCodeA) && ObjectUtil.isNotNull(objectStationStatusA) && ObjectUtil.isNotNull(objectModuleCodeB) && ObjectUtil.isNotNull(objectStationStatusB)){
569             ModuleCodeA = objectModuleCodeA.toString();
570             ModuleCodeB = objectModuleCodeB.toString();
571             StationStatusA = objectStationStatusA.toString();
572             StationStatusB = objectStationStatusB.toString();
573
574             String[] modeles = {ModuleCodeA,ModuleCodeB};
575             String[] StationStatus = {StationStatusA,StationStatusB};
576
577             String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString();
578             String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString();
579             for (int i = 0; i < 2; i++) {
580                 DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
581                 String strt = TimeUtil.stringProcessing(startTime);
582                 String end = TimeUtil.stringProcessing(stopTime);
583                 daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//入站时间
584                 daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//出站时间
585                 daPassingStationCollection.setSfcCode(modeles[i]);
586                 daPassingStationCollection.setLocationCode(device);
587                 daPassingStationCollection.setOutRsSign(StationStatus[i]);//出站是否合格
588                 passingStationCollections.add(daPassingStationCollection);
589             }
590             daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections);
591             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
592             return;
593         }else {
594             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build());
595             return;
a320dc 596         }
A 597     }
598
1ccd69 599     private static void writeToOpc(String identifier, short value) {
A 600         try {
601             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(identifier).value(value).build());
602         } catch (Exception e) {
603             throw new RuntimeException(e);
604         }
605     }
606
a5b351 607 }