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