cl
2024-07-03 2de8567d25edbe0c020f75182b44016bfcc85d0b
提交 | 用户 | 时间
0ca254 1 package com.jcdm.main.plcserver.sub;
A 2
3
4 import cn.hutool.core.collection.CollUtil;
5 import cn.hutool.core.util.ObjectUtil;
6 import cn.hutool.core.util.StrUtil;
109e2f 7 import cn.hutool.http.HttpRequest;
C 8 import cn.hutool.http.HttpResponse;
9 import cn.hutool.json.JSONUtil;
0ca254 10 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
A 11 import com.jcdm.framework.websocket.WebSocketUsers;
12 import com.jcdm.main.constant.Constants;
13 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
14 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
15 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
16 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
17 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
18 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
8c5c9c 19 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
0ca254 20 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
8c5c9c 21 import com.jcdm.main.plcserver.util.TimeUtil;
0ca254 22 import com.jcdm.main.restful.qingYan.doman.ChildVO;
A 23 import com.jcdm.main.restful.qingYan.doman.ParentVO;
24 import com.kangaroohy.milo.model.ReadWriteEntity;
25 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
26 import com.kangaroohy.milo.service.MiloService;
27 import lombok.extern.slf4j.Slf4j;
109e2f 28 import org.springframework.beans.factory.annotation.Value;
0ca254 29 import org.springframework.stereotype.Component;
A 30
31 import javax.websocket.Session;
32 import java.text.SimpleDateFormat;
33 import java.util.*;
109e2f 34 import java.util.concurrent.CompletableFuture;
0ca254 35 import java.util.stream.Collectors;
109e2f 36
0ca254 37
A 38 @Slf4j
39 @Component
40 public class OPCUaSubscription implements SubscriptionCallback {
41
8c5c9c 42     public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
0ca254 43
A 44
8c5c9c 45     Map<String, Session> map = WebSocketUsers.getUsers();
0ca254 46     public static MiloService miloService;
A 47
48
109e2f 49     public static IDaPassingStationCollectionService daPassingStationCollectionService;
0ca254 50
A 51     public static IDaCollectionParamConfService collectionParamConfService;
52
53     public static IDaParamCollectionService daParamCollectionService;
54
55     public static IOmProductionOrdeInfoService omProductionOrdeInfoService;
56
109e2f 57     @Value("${orderLineUrl}")
C 58     private static String orderLineUrl;
0ca254 59
A 60     public OPCUaSubscription(MiloService miloService,
61                              IDaPassingStationCollectionService daPassingStationCollectionService,
62                              IDaCollectionParamConfService collectionParamConfService,
63                              IDaParamCollectionService daParamCollectionService,
109e2f 64                              IOmProductionOrdeInfoService omProductionOrdeInfoService) {
0ca254 65         OPCUaSubscription.miloService = miloService;
109e2f 66         OPCUaSubscription.daPassingStationCollectionService = daPassingStationCollectionService;
0ca254 67         OPCUaSubscription.collectionParamConfService = collectionParamConfService;
A 68         OPCUaSubscription.daParamCollectionService = daParamCollectionService;
69         OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService;
70     }
71
72
73     @Override
74     public void onSubscribe(String identifier, Object value) {
109e2f 75         log.info("地址:"+identifier+"值:"+value);
0ca254 76         try {
109e2f 77             if(null != value && !Constants.ZERO.equals(value.toString())) {
0ca254 78                 String[] nodes = identifier.split("[.]");
A 79                 String thoroughfare = nodes[0];//通道
80                 String device = nodes[1];//设备
81                 String tab = nodes[2];//标记
109e2f 82                 String valueString = value.toString();//地址值
C 83                 if (Constants.RECORD_CHECK_CODE.equals(tab)){//电芯校验
84                     if (Constants.ONE.equals(valueString)){
85                         Integer scanResult = 11;
86                         if (Constants.OP010.equals(device) || Constants.OP030.equals(device)){
87                             //OP010工位电芯条码校验||OP030工位电芯条码校验
88                             Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".Scaner").getValue();
89                             if (ObjectUtil.isNotNull(value1)){
90                                 String keyCode = value1.toString();
91                                 log.info("读取到工位{}的Scaner数据:{}",device,keyCode);
92                                 //仅校验长度是否合格
93 //                                List<KeyCodeCheck> collect = keyCodeCheckService.list().stream().filter(x -> x.getKeyCode().contains(keyCode)).collect(Collectors.toList());
94 //                                if (CollUtil.isNotEmpty(collect)){
95 //                                    scanResult = 11;
0ca254 96 //                                }
A 97                             }
98                         }
109e2f 99                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ScanerResult1").value(scanResult).build());
C 100                         log.info("写入到工位{}的ScanerResult1数据:{}",device,scanResult);
0ca254 101                     }
109e2f 102                 }else if (Constants.RECORD_SN.equals(tab)){//求下发模组码请9
C 103                     if (Constants.ONE.equals(valueString)){
2de856 104                         if (Constants.OP100_1.equals(device) || Constants.OP100_2.equals(device) ){
8c5c9c 105                             //查询要生产的工单
C 106                             List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>()
107                                     .eq(OmProductionOrdeInfo::getOrderStatus, Constants.ONE));//工单状态
108
109e2f 109                             if (CollUtil.isNotEmpty(orderList)){
8c5c9c 110                                 Long id = orderList.get(0).getId();
109e2f 111                                 String productNum = orderList.get(0).getProductNum();//模组码
8c5c9c 112                                 //下发产品模组码
2de856 113                                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".MES_ModuleCode").value(productNum).build());
C 114                                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".MES_WorkOrderNumber").value(productNum).build());
115                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".MES_ProductType").value(productNum).build());
109e2f 116                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(1).build());
8c5c9c 117
C 118                                 //更新工单状态为执行中
119                                 OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
120                                 omProductionOrdeInfo.setId(id);
121                                 omProductionOrdeInfo.setOrderStatus("3");
122                                 omProductionOrdeInfoService.updateOmProductionOrdeInfo(omProductionOrdeInfo);
123
124                                 //将产品SN发送到前台
125                                 productNum = "productNum,"+ productNum;
126                                 WebSocketUsers.sendMessageToUserByText(map.get(device), productNum);
109e2f 127                             }else{
C 128                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(2).build());//没有要生产的工单
8c5c9c 129                             }
2de856 130                         }
109e2f 131                     }
C 132                 }else if (Constants.RECORD_DATA.equals(tab)){//出入站
133                     if (Constants.ONE.equals(valueString)){//入站
134                         //1:告知MES托盘已到站,请求下发进站状态
135                         if (Constants.OP030.equals(device)){
136                             //反馈电芯ocv检测结果
137                             boolean b = true;//OCVResultFeedBack(thoroughfare, device);
2de856 138
C 139                             //四个电芯的状态
109e2f 140                             if (b){
C 141                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
142                                 log.info("写入到工位{}的RecordDataDone数据:{}",device,11);
143                             }else {
144                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
145                                 log.info("写入到工位{}的RecordDataDone数据:{}",device,12);
146                             }
147                         } else {
148                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
149                             log.info("写入到工位{}的RecordDataDone数据:{}",device,11);
150                         }
151                     }else if (Constants.TWO.equals(valueString)){//出站
152                         //分段010-065段
153                         if (Constants.OP010.equals(device)){
154                             //010工位无过站记录,只给放行信号
155                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(21).build());
156                             log.info("写入到工位{}的RecordDataDone数据:{}",device,21);
157                         }else if (Constants.OP020_OP065.contains(device)){
158                             Integer result = 21;
159                             //读取电芯码
160                             List<String> cellCodeList = readCellCodeList(thoroughfare, device);
8c5c9c 161                             if(ObjectUtil.isNull(cellCodeList) || cellCodeList.size() != 4){
109e2f 162                                 result = 23;
C 163                             }else{
164                                 result = savePassingStation(thoroughfare, device,cellCodeList);//保存过站
2de856 165                                 if(result == 21) {
109e2f 166                                     result = saveParamCollection(thoroughfare, device,cellCodeList);//保存参数,发送工厂MES
C 167                                 }
168                             }
169                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
170                             log.info("写入到工位{}的RecordDataDone数据:{}",device,result);
171                         } else if (Constants.OP100_1.equals(device) || Constants.OP100_2.equals(device)){
8c5c9c 172
2de856 173                             WebSocketUsers.sendMessageToUserByText(map.get(device), "END");
109e2f 174                         } else {
2de856 175                             Integer result = 21;
C 176                             Object modulCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
177                             if (ObjectUtil.isNull(modulCodeObjcet) && modulCodeObjcet.toString().trim().isEmpty()){
178                                 result = 23;
179                             }else{
180                                 String moduleCode = modulCodeObjcet.toString();
181                                 result = savePassingStation(thoroughfare, device,moduleCode);//保存过站
182                                 if(result == 21) {
183                                     result = saveParamCollection(thoroughfare, device,moduleCode);//保存参数,发送工厂MES
109e2f 184                                 }
C 185                             }
2de856 186                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
C 187                             log.info("写入到工位{}的RecordDataDone数据:{}",device,result);
0ca254 188                         }
109e2f 189                     }
8c5c9c 190                 }  /*else if (Constants.RECORD_CHECK_CODE_1.equals(tab)) {
109e2f 191                     if (Constants.OP100_1.equals(device)){
C 192                         //钢带条码校验--发送给工厂mes
193                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ScanerResult11").value(11).build());
194                     } else if (Constants.OP100_2.equals(device)) {
195                         //PET带条码校验--发送给工厂mes
196                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ScanerResult12").value(11).build());
0ca254 197                     }
8c5c9c 198                 }*/
0ca254 199             }
A 200         } catch (Exception e) {
8c5c9c 201             log.error(e.getMessage());
109e2f 202             System.out.println(e.getMessage());
C 203             log.info(e.getMessage());
0ca254 204         }
A 205     }
206
207
208
209     /**
109e2f 210      * 读取电芯码
C 211      * @param thoroughfare 通道
212      * @param device 工位
213      * @return list
214      * @throws Exception e
0ca254 215      */
109e2f 216     private static List<String> readCellCodeList(String thoroughfare, String device){
C 217         List<String> cellCodeList = new ArrayList<>();
2de856 218         Map map = new HashMap();
109e2f 219         //电芯码地址
C 220         List<String> readList = new ArrayList<>();
221         readList.add(thoroughfare + "." + device +".CellCode_1");
222         readList.add(thoroughfare + "." + device +".CellCode_2");
223         readList.add(thoroughfare + "." + device +".CellCode_3");
224         readList.add(thoroughfare + "." + device +".CellCode_4");
0ca254 225         try {
109e2f 226             List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(readList);//电芯码
C 227             for (ReadWriteEntity readWriteEntity : readWriteEntityList) {
2de856 228                 if (ObjectUtil.isNotNull(readWriteEntity.getValue()) && !"".equals(readWriteEntity.getValue().toString().trim())){
C 229                     cellCodeList.add(readWriteEntity.getValue().toString());//封装电芯码
230                 }else{
231                     cellCodeList.add("");//封装电芯码
0ca254 232                 }
A 233             }
2de856 234
0ca254 235         } catch (Exception e) {
A 236             throw new RuntimeException(e);
237         }
109e2f 238         return cellCodeList;
2de856 239     }
C 240
241
242     /**
243      * 保存过站数据
244      * @param thoroughfare 通道
245      * @param device 工位
246      * @param moduleCode 模组号
247      * @return list
248      * @throws Exception e
249      */
250     private static Integer savePassingStation(String thoroughfare, String device,String moduleCode){
251         Integer result = 21;
252
253         try {
254             //读进站时间
255             Date startTime = new Date();
256             ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间
257             if (ObjectUtil.isNotNull(startTimeRead.getValue())){
258                 startTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(startTimeRead.getValue().toString())));
259             }else{
260                 result = 23;
261                 log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
262                 return result;
263             }
264
265             //读工站状态
266             String stationStatus = Constants.PASS;
267             ReadWriteEntity stationStatusRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus");//站状态地址
268             if (ObjectUtil.isNotNull(stationStatusRead.getValue())){
269                 String string = stationStatusRead.getValue().toString();
270                 if (Constants.TWO.equals(string)){
271                     stationStatus = Constants.UN_PASS;
272                 }
273             }else{
274                 result = 23;
275                 log.info("读取到工位{}StationStatus数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
276                 return result;
277             }
278
279             DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
280             passingStationCollection.setSfcCode(moduleCode);//电芯码
281             passingStationCollection.setLocationCode(device);//工位
282             passingStationCollection.setInboundTime(startTime);//进站时间
283             passingStationCollection.setOutboundTime(new Date());//出站时间
284             passingStationCollection.setOutRsSign(stationStatus);//站状态值
285             passingStationCollection.setCollectionTime(new Date());//采集时间
286             daPassingStationCollectionService.save(passingStationCollection);
287
288         } catch (Exception e) {
289             throw new RuntimeException(e);
290         }
291
292         return result;
0ca254 293     }
A 294
109e2f 295     /**
C 296      * 保存过站数据
297      * @param thoroughfare 通道
298      * @param device 工位
299      * @param cellCodeList 电芯码集合
300      * @return list
301      * @throws Exception e
302      */
303     private static Integer savePassingStation(String thoroughfare, String device,List<String> cellCodeList){
304         Integer result = 21;
305
306         try {
307             //读进站时间
308             Date startTime = new Date();
309             ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间
310             if (ObjectUtil.isNotNull(startTimeRead.getValue())){
8c5c9c 311                 startTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(startTimeRead.getValue().toString())));
109e2f 312             }else{
C 313                 result = 23;
314                 log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
2de856 315                 return result;
109e2f 316             }
C 317
318             //读工站状态
319             String stationStatus = Constants.PASS;
320             ReadWriteEntity stationStatusRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus");//站状态地址
321             if (ObjectUtil.isNotNull(stationStatusRead.getValue())){
322                 String string = stationStatusRead.getValue().toString();
323                 if (Constants.TWO.equals(string)){
324                     stationStatus = Constants.UN_PASS;
325                 }
326             }else{
327                 result = 23;
2de856 328                 log.info("读取到工位{}StationStatus数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
C 329                 return result;
109e2f 330             }
C 331
332             List<DaPassingStationCollection> passingList = new ArrayList<>();
333             for (String cellCode : cellCodeList) {
334                 DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
2de856 335                 if (ObjectUtil.isNotNull(cellCode) && !cellCode.isEmpty()){
109e2f 336                     passingStationCollection.setSfcCode(cellCode);//电芯码
C 337                     passingStationCollection.setLocationCode(device);//工位
338                     passingStationCollection.setInboundTime(startTime);//进站时间
339                     passingStationCollection.setOutboundTime(new Date());//出站时间
340                     passingStationCollection.setOutRsSign(stationStatus);//站状态值
341                     passingStationCollection.setCollectionTime(new Date());//采集时间
342                     passingList.add(passingStationCollection);
343                 }
344             }
345
346             if (CollUtil.isNotEmpty(passingList)){
347                 daPassingStationCollectionService.insertBatch(passingList);//存储过站采集数据
348             }
349
350         } catch (Exception e) {
351             throw new RuntimeException(e);
352         }
353
354         return result;
355     }
356
2de856 357
109e2f 358     /**
2de856 359      * 保存参数数据和发送工厂MES
C 360      * @param thoroughfare 通道
361      * @param device 工位
362      * @param moduleCode 模组号
363      * @return list
364      * @throws Exception e
365      */
366     private static Integer saveParamCollection(String thoroughfare, String device,String moduleCode){
367         Integer result = 21;//返回结果
368
369         try {
370             //查询参数配置表
371             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
372                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
373                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
374             );
375             if (CollUtil.isNotEmpty(list)){
376
377                 List<String> collect = list.stream()
378                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
379                 List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(collect);
380
381                 List<DaParamCollection> collectionList = new ArrayList<>();
382                 List<ChildVO> mesList = new ArrayList<>();
383                 for (int i = 0; i < readWriteEntityList.size(); i++) {
384                     DaParamCollection daParamCollection = new DaParamCollection();
385                     daParamCollection.setSfcCode(moduleCode);//模组码
386                     daParamCollection.setParamCode(list.get(i).getCollectParameterId());//参数编码
387                     daParamCollection.setParamName(list.get(i).getCollectParameterName());//参数名称
388                     String paramValue = "";
389                     if (ObjectUtil.isNotNull(readWriteEntityList.get(i).getValue())){
390                         paramValue = readWriteEntityList.get(i).getValue().toString();//参数值
391                     }
392                     daParamCollection.setParamValue(paramValue);//参数值
393                     daParamCollection.setLocationCode(device);//工位
394                     daParamCollection.setCollectionTime(new Date());//采集时间
395                     collectionList.add(daParamCollection);//封装参数采集list
396
397                     //发送给工厂mes参数封装
398                     ChildVO childVO = new ChildVO();
399                     childVO.setItemCode(list.get(i).getCollectParameterId());//参数编码
400                     childVO.setItemType(list.get(i).getItemType());
401                     childVO.setItemValue(paramValue);//参数值
402                     childVO.setItemText(list.get(i).getCollectParameterName());
403                     childVO.setCheckResult("1");
404                     childVO.setCheckTime(new Date().toString());
405                     mesList.add(childVO);
406                 }
407
408                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
409                     //插入参数采集表
410                     daParamCollectionService.insertBatch(collectionList);
411                     //上传到工厂mes
412                     ParentVO parentVO = new ParentVO();
413                     parentVO.setStationCode(device);//工位
414                     parentVO.setSiteCode("3983");
415
416                     parentVO.setRecordId(UUID.randomUUID().toString());
417                     parentVO.setTotalResult("1");
418                     parentVO.setProductNum(moduleCode);
419                     parentVO.setCheckList(mesList);
420
421                     log.info("执行工厂MES方法start,传入数据:{}",parentVO);
422                     HttpResponse execute = HttpRequest.post(orderLineUrl).body(JSONUtil.toJsonStr(parentVO)).execute();
423                     log.info("执行工厂MES方法end,返回数据:{}",execute.body());
424
425                 });
426             }
427         }catch (Exception e) {
428             throw new RuntimeException(e);
429         }
430         return result;
431     }
432
433     /**
434      * 保存参数数据和发送工厂MES
109e2f 435      * @param thoroughfare 通道
C 436      * @param device 工位
437      * @param cellCodeList 电芯码集合
438      * @return list
439      * @throws Exception e
440      */
441     private static Integer saveParamCollection(String thoroughfare, String device,List<String> cellCodeList){
442         Integer result = 21;//返回结果
443         List<List<ChildVO>> mesList = new ArrayList<>();//存储4个电芯的发送给MES的值
444
445         try {
446             //查询参数配置表
447             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
448                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
8c5c9c 449                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
2de856 450                     );//类型
109e2f 451             if (CollUtil.isNotEmpty(list)) {
C 452                 List<DaParamCollection> saveParamList = new ArrayList<>();//封装参数采集list
453                 List<DaCollectionParamConf> confColl1 = list.stream().filter(x -> Constants.INT_ONE.equals(x.getKeyNum())).collect(Collectors.toList());
454                 List<DaCollectionParamConf> confColl2 = list.stream().filter(x -> Constants.INT_TWO.equals(x.getKeyNum())).collect(Collectors.toList());
455                 List<DaCollectionParamConf> confColl3 = list.stream().filter(x -> Constants.INT_THREE.equals(x.getKeyNum())).collect(Collectors.toList());
456                 List<DaCollectionParamConf> confColl4 = list.stream().filter(x -> Constants.INT_FOUR.equals(x.getKeyNum())).collect(Collectors.toList());
457                 List<DaCollectionParamConf> confColl0 = list.stream().filter(x -> Constants.INT_ZERO.equals(x.getKeyNum())).collect(Collectors.toList());
458
459                 List<String> collect1 = confColl1.stream()
460                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
461                 List<ReadWriteEntity> paramCollectionList1 = miloService.readFromOpcUa(collect1);//电芯1 参数值
462
463                 List<String> collect2 = confColl2.stream()
464                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
465                 List<ReadWriteEntity> paramCollectionList2 = miloService.readFromOpcUa(collect2);//电芯2 参数值
466
467                 List<String> collect3 = confColl3.stream()
468                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
469                 List<ReadWriteEntity> paramCollectionList3 = miloService.readFromOpcUa(collect3);//电芯3 参数值
470
471                 List<String> collect4 = confColl4.stream()
472                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
473                 List<ReadWriteEntity> paramCollectionList4 = miloService.readFromOpcUa(collect4);//电芯4 参数值
474
475                 List<String> collect0 = confColl0.stream()
476                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
477                 List<ReadWriteEntity> paramCollectionList0 = miloService.readFromOpcUa(collect0);//电芯 参数值
478
479                 //第一个电芯的数据
2de856 480                 if (CollUtil.isNotEmpty(paramCollectionList1) && !cellCodeList.get(0).isEmpty()) {
109e2f 481                     List<ChildVO> mesChildList1 = new ArrayList<>();//封装给工厂MES发送的childlist1
C 482                     for (int i = 0; i < paramCollectionList1.size(); i++) {
483                         DaParamCollection daParamCollection = new DaParamCollection();
484                         daParamCollection.setSfcCode(cellCodeList.get(0));//电芯码
485                         daParamCollection.setParamCode(confColl1.get(i).getCollectParameterId());//参数编码
486                         daParamCollection.setParamName(confColl1.get(i).getCollectParameterName());//参数名称
487                         String paramValue = "";
488                         if (ObjectUtil.isNotNull(paramCollectionList1.get(i).getValue())) {
489                             paramValue = paramCollectionList1.get(i).getValue().toString();//参数值
490                         }
491                         daParamCollection.setParamValue(paramValue);//参数值
492                         daParamCollection.setLocationCode(device);//工位
493                         daParamCollection.setCollectionTime(new Date());//采集时间
494                         saveParamList.add(daParamCollection);//封装参数采集list
495
496                         //发送给工厂mes参数封装
497                         ChildVO childVO = new ChildVO();
498                         childVO.setItemCode(confColl1.get(i).getCollectParameterName());//参数
499                         childVO.setItemType(confColl1.get(i).getItemType());
500                         childVO.setItemValue(paramValue);//参数值
501                         childVO.setItemText(confColl1.get(i).getParameterSetName());
502                         childVO.setCheckResult("1");
503                         childVO.setCheckTime(new Date().toString());
504                         mesChildList1.add(childVO);
505                     }
2de856 506                     mesList.add(0, mesChildList1);
109e2f 507                 }
2de856 508                 if (CollUtil.isNotEmpty(paramCollectionList2) && !cellCodeList.get(1).isEmpty()) {
109e2f 509                     List<ChildVO> mesChildList2 = new ArrayList<>();//封装给工厂MES发送的childlist2
C 510
511                     for (int i = 0; i < paramCollectionList2.size(); i++) {
512                         DaParamCollection daParamCollection = new DaParamCollection();
513                         daParamCollection.setSfcCode(cellCodeList.get(1));//电芯码
514                         daParamCollection.setParamCode(confColl2.get(i).getCollectParameterId());//参数编码
515                         daParamCollection.setParamName(confColl2.get(i).getCollectParameterName());//参数名称
516                         String paramValue = "";
517                         if (ObjectUtil.isNotNull(paramCollectionList2.get(i).getValue())) {
518                             paramValue = paramCollectionList2.get(i).getValue().toString();//参数值
519                         }
520                         daParamCollection.setParamValue(paramValue);//参数值
521                         daParamCollection.setLocationCode(device);//工位
522                         daParamCollection.setCollectionTime(new Date());//采集时间
523                         saveParamList.add(daParamCollection);//封装参数采集list
524
525                         //发送给工厂mes参数封装
526                         ChildVO childVO = new ChildVO();
527                         childVO.setItemCode(confColl2.get(i).getCollectParameterName());//参数
528                         childVO.setItemType(confColl2.get(i).getItemType());
529                         childVO.setItemValue(paramValue);//参数值
530                         childVO.setItemText(confColl2.get(i).getParameterSetName());
531                         childVO.setCheckResult("1");
532                         childVO.setCheckTime(new Date().toString());
533                         mesChildList2.add(childVO);
534                     }
2de856 535                     mesList.add(1, mesChildList2);
109e2f 536                 }
2de856 537                 if (CollUtil.isNotEmpty(paramCollectionList3) && !cellCodeList.get(2).isEmpty()) {
109e2f 538                     List<ChildVO> mesChildList3 = new ArrayList<>();//封装给工厂MES发送的childlist3
C 539                     for (int i = 0; i < paramCollectionList3.size(); i++) {
540                         DaParamCollection daParamCollection = new DaParamCollection();
541                         daParamCollection.setSfcCode(cellCodeList.get(2));//电芯码
542                         daParamCollection.setParamCode(confColl3.get(i).getCollectParameterId());//参数编码
543                         daParamCollection.setParamName(confColl3.get(i).getCollectParameterName());//参数名称
544                         String paramValue = "";
545                         if (ObjectUtil.isNotNull(paramCollectionList3.get(i).getValue())) {
546                             paramValue = paramCollectionList3.get(i).getValue().toString();//参数值
547                         }
548                         daParamCollection.setParamValue(paramValue);//参数值
549                         daParamCollection.setLocationCode(device);//工位
550                         daParamCollection.setCollectionTime(new Date());//采集时间
551                         saveParamList.add(daParamCollection);//封装参数采集list
552
553                         //发送给工厂mes参数封装
554                         ChildVO childVO = new ChildVO();
555                         childVO.setItemCode(confColl3.get(i).getCollectParameterName());//参数
556                         childVO.setItemType(confColl3.get(i).getItemType());
557                         childVO.setItemValue(paramValue);//参数值
558                         childVO.setItemText(confColl3.get(i).getParameterSetName());
559                         childVO.setCheckResult("1");
560                         childVO.setCheckTime(new Date().toString());
561                         mesChildList3.add(childVO);
562                     }
2de856 563                     mesList.add(2, mesChildList3);
109e2f 564                 }
2de856 565                 if (CollUtil.isNotEmpty(paramCollectionList4)&& !cellCodeList.get(3).isEmpty()) {
109e2f 566                     List<ChildVO> mesChildList4 = new ArrayList<>();//封装给工厂MES发送的childlist4
C 567                     for (int i = 0; i < paramCollectionList4.size(); i++) {
568                         DaParamCollection daParamCollection = new DaParamCollection();
569                         daParamCollection.setSfcCode(cellCodeList.get(3));//电芯码
570                         daParamCollection.setParamCode(confColl4.get(i).getCollectParameterId());//参数编码
571                         daParamCollection.setParamName(confColl4.get(i).getCollectParameterName());//参数名称
572                         String paramValue = "";
573                         if (ObjectUtil.isNotNull(paramCollectionList4.get(i).getValue())) {
574                             paramValue = paramCollectionList4.get(i).getValue().toString();//参数值
575                         }
576                         daParamCollection.setParamValue(paramValue);//参数值
577                         daParamCollection.setLocationCode(device);//工位
578                         daParamCollection.setCollectionTime(new Date());//采集时间
579                         saveParamList.add(daParamCollection);//封装参数采集list
580
581                         //发送给工厂mes参数封装
582                         ChildVO childVO = new ChildVO();
583                         childVO.setItemCode(confColl4.get(i).getCollectParameterName());//参数
584                         childVO.setItemType(confColl4.get(i).getItemType());
585                         childVO.setItemValue(paramValue);//参数值
586                         childVO.setItemText(confColl4.get(i).getParameterSetName());
587                         childVO.setCheckResult("1");
588                         childVO.setCheckTime(new Date().toString());
589                         mesChildList4.add(childVO);
590                     }
2de856 591                     mesList.add(3, mesChildList4);
109e2f 592                 }
C 593
594                 //公共参数
595                 if (CollUtil.isNotEmpty(paramCollectionList0)) {
596                     for (int i = 0; i < cellCodeList.size(); i++) {//循环4个电芯
2de856 597                         if(!cellCodeList.get(i).isEmpty()){
C 598                             List<ChildVO> mesChildList0 = new ArrayList<>();//封装给工厂MES发送的childlist0
599                             for (int j = 0; j < paramCollectionList0.size(); j++) {
600                                 DaParamCollection daParamCollection = new DaParamCollection();
601                                 daParamCollection.setSfcCode(cellCodeList.get(i));//电芯码
602                                 daParamCollection.setParamCode(confColl0.get(j).getCollectParameterId());//参数编码
603                                 daParamCollection.setParamName(confColl0.get(j).getCollectParameterName());//参数名称
604                                 String paramValue = "";
605                                 if (ObjectUtil.isNotNull(paramCollectionList0.get(j).getValue())) {
606                                     paramValue = paramCollectionList0.get(j).getValue().toString();//参数值
607                                 }
608                                 if(confColl0.get(j).getCollectParameterName().contains("时间") && !"".equals(paramValue)){
609                                     paramValue = format.parse(TimeUtil.test(TimeUtil.stringProcessing(paramValue))).toString();
610                                 }
611                                 daParamCollection.setParamValue(paramValue);//参数值
612                                 daParamCollection.setLocationCode(device);//工位
613                                 daParamCollection.setCollectionTime(new Date());//采集时间
614                                 saveParamList.add(daParamCollection);
109e2f 615
2de856 616                                 //发送给工厂mes参数封装
C 617                                 ChildVO childVO = new ChildVO();
618                                 childVO.setItemCode(confColl0.get(j).getCollectParameterName());//参数
619                                 childVO.setItemType(confColl0.get(j).getItemType());
620                                 childVO.setItemValue(paramValue);//参数值
621                                 childVO.setItemText(confColl0.get(j).getParameterSetName());
622                                 childVO.setCheckResult("1");
623                                 childVO.setCheckTime(new Date().toString());
624                                 mesChildList0.add(childVO);
625                             }
626                             mesList.add(i, mesChildList0);
109e2f 627                         }
2de856 628
C 629                         //mesList.get(i).addAll(mesChildList0);
630
109e2f 631                     }
C 632
633                 }
634
635                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
636                     //插入参数采集表
637                     daParamCollectionService.insertBatch(saveParamList);
638                     //上传到工厂mes
639                     ParentVO parentVO = new ParentVO();
640                     parentVO.setStationCode(device);//工位
641                     parentVO.setSiteCode("3983");
642
643                     parentVO.setRecordId(UUID.randomUUID().toString());
644                     parentVO.setTotalResult("1");
645                     for (int i = 0; i < cellCodeList.size(); i++) {//循环4个电芯
2de856 646                         if(!cellCodeList.get(i).isEmpty()){
C 647                             parentVO.setProductNum(cellCodeList.get(i));//电芯码
648                             parentVO.setCheckList(mesList.get(i));//参数
649                             //CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
650                             log.info("执行工厂MES方法start,传入数据:{}",parentVO);
651                             HttpResponse execute = HttpRequest.post(orderLineUrl).body(JSONUtil.toJsonStr(parentVO)).execute();
652                             log.info("执行工厂MES方法end,返回数据:{}",execute.body());
653                         }
109e2f 654                     }
C 655                 });
656             }
657         }catch (Exception e) {
658             throw new RuntimeException(e);
659         }
660         return result;
661     }
662
663     /**
2de856 664      * 030工位返回ocv测试结果
C 665      * @param thoroughfare
666      * @param device
109e2f 667      * @throws Exception
C 668      */
2de856 669     private boolean OCVResultFeedBack(String thoroughfare, String device) throws Exception {
C 670         boolean flag = true;
671         Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_1").getValue();
672         /*if (ObjectUtil.isNotNull(value1)){
673             String string = value1.toString();
674             List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
675                     .eq(QingYanTestInfo::getKeyCode, string));
676             if (CollUtil.isNotEmpty(list)){
677                 QingYanTestInfo qingYanTestInfo = list.get(0);
678                 if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
679                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(1).build());
680                 }else {
681                     flag = false;
682                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(2).build());
683                 }
684             }
685         }*/
686         Object value2 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_2").getValue();
687         /*if (ObjectUtil.isNotNull(value2)){
688             String string = value2.toString();
689             List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
690                     .eq(QingYanTestInfo::getKeyCode, string));
691             if (CollUtil.isNotEmpty(list)){
692                 QingYanTestInfo qingYanTestInfo = list.get(0);
693                 if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
694                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(1).build());
695                 }else {
696                     flag = false;
697                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(2).build());
698                 }
699             }
700         }*/
701         Object value3 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_3").getValue();
702         /*if (ObjectUtil.isNotNull(value3)){
703             String string = value3.toString();
704             List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
705                     .eq(QingYanTestInfo::getKeyCode, string));
706             if (CollUtil.isNotEmpty(list)){
707                 QingYanTestInfo qingYanTestInfo = list.get(0);
708                 if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
709                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(1).build());
710                 }else {
711                     flag = false;
712                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(2).build());
713                 }
714             }
715         }*/
716         Object value4 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_4").getValue();
717         /*if (ObjectUtil.isNotNull(value4)){
718             String string = value4.toString();
719             List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
720                     .eq(QingYanTestInfo::getKeyCode, string));
721             if (CollUtil.isNotEmpty(list)){
722                 QingYanTestInfo qingYanTestInfo = list.get(0);
723                 if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
724                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(1).build());
725                 }else {
726                     flag = false;
727                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(2).build());
728                 }
729             }
730         }*/
731         return flag;
109e2f 732     }
C 733
734
0ca254 735 }