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