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