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