cl
2024-07-03 5c62de89d218b7dbb06eee67f10f746eb5ce1667
提交 | 用户 | 时间
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;//返回结果
5c62de 368         String sendMes = "";
2de856 369
C 370         try {
371             //查询参数配置表
372             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
373                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
374                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
375             );
376             if (CollUtil.isNotEmpty(list)){
377
378                 List<String> collect = list.stream()
379                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
380                 List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(collect);
381
382                 List<DaParamCollection> collectionList = new ArrayList<>();
383                 List<ChildVO> mesList = new ArrayList<>();
384                 for (int i = 0; i < readWriteEntityList.size(); i++) {
385                     DaParamCollection daParamCollection = new DaParamCollection();
386                     daParamCollection.setSfcCode(moduleCode);//模组码
387                     daParamCollection.setParamCode(list.get(i).getCollectParameterId());//参数编码
388                     daParamCollection.setParamName(list.get(i).getCollectParameterName());//参数名称
389                     String paramValue = "";
390                     if (ObjectUtil.isNotNull(readWriteEntityList.get(i).getValue())){
391                         paramValue = readWriteEntityList.get(i).getValue().toString();//参数值
392                     }
393                     daParamCollection.setParamValue(paramValue);//参数值
394                     daParamCollection.setLocationCode(device);//工位
395                     daParamCollection.setCollectionTime(new Date());//采集时间
396                     collectionList.add(daParamCollection);//封装参数采集list
397
398                     //发送给工厂mes参数封装
399                     ChildVO childVO = new ChildVO();
400                     childVO.setItemCode(list.get(i).getCollectParameterId());//参数编码
401                     childVO.setItemType(list.get(i).getItemType());
402                     childVO.setItemValue(paramValue);//参数值
403                     childVO.setItemText(list.get(i).getCollectParameterName());
404                     childVO.setCheckResult("1");
405                     childVO.setCheckTime(new Date().toString());
406                     mesList.add(childVO);
407                 }
408
409                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
410                     //插入参数采集表
411                     daParamCollectionService.insertBatch(collectionList);
412                     //上传到工厂mes
413                     ParentVO parentVO = new ParentVO();
414                     parentVO.setStationCode(device);//工位
415                     parentVO.setSiteCode("3983");
416
417                     parentVO.setRecordId(UUID.randomUUID().toString());
418                     parentVO.setTotalResult("1");
419                     parentVO.setProductNum(moduleCode);
420                     parentVO.setCheckList(mesList);
421
422                     log.info("执行工厂MES方法start,传入数据:{}",parentVO);
423                     HttpResponse execute = HttpRequest.post(orderLineUrl).body(JSONUtil.toJsonStr(parentVO)).execute();
424                     log.info("执行工厂MES方法end,返回数据:{}",execute.body());
425
426                 });
427             }
428         }catch (Exception e) {
429             throw new RuntimeException(e);
430         }
431         return result;
432     }
433
434     /**
435      * 保存参数数据和发送工厂MES
109e2f 436      * @param thoroughfare 通道
C 437      * @param device 工位
438      * @param cellCodeList 电芯码集合
439      * @return list
440      * @throws Exception e
441      */
442     private static Integer saveParamCollection(String thoroughfare, String device,List<String> cellCodeList){
443         Integer result = 21;//返回结果
444         List<List<ChildVO>> mesList = new ArrayList<>();//存储4个电芯的发送给MES的值
445
446         try {
447             //查询参数配置表
448             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
449                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
8c5c9c 450                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
2de856 451                     );//类型
109e2f 452             if (CollUtil.isNotEmpty(list)) {
C 453                 List<DaParamCollection> saveParamList = new ArrayList<>();//封装参数采集list
454                 List<DaCollectionParamConf> confColl1 = list.stream().filter(x -> Constants.INT_ONE.equals(x.getKeyNum())).collect(Collectors.toList());
455                 List<DaCollectionParamConf> confColl2 = list.stream().filter(x -> Constants.INT_TWO.equals(x.getKeyNum())).collect(Collectors.toList());
456                 List<DaCollectionParamConf> confColl3 = list.stream().filter(x -> Constants.INT_THREE.equals(x.getKeyNum())).collect(Collectors.toList());
457                 List<DaCollectionParamConf> confColl4 = list.stream().filter(x -> Constants.INT_FOUR.equals(x.getKeyNum())).collect(Collectors.toList());
458                 List<DaCollectionParamConf> confColl0 = list.stream().filter(x -> Constants.INT_ZERO.equals(x.getKeyNum())).collect(Collectors.toList());
459
460                 List<String> collect1 = confColl1.stream()
461                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
462                 List<ReadWriteEntity> paramCollectionList1 = miloService.readFromOpcUa(collect1);//电芯1 参数值
463
464                 List<String> collect2 = confColl2.stream()
465                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
466                 List<ReadWriteEntity> paramCollectionList2 = miloService.readFromOpcUa(collect2);//电芯2 参数值
467
468                 List<String> collect3 = confColl3.stream()
469                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
470                 List<ReadWriteEntity> paramCollectionList3 = miloService.readFromOpcUa(collect3);//电芯3 参数值
471
472                 List<String> collect4 = confColl4.stream()
473                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
474                 List<ReadWriteEntity> paramCollectionList4 = miloService.readFromOpcUa(collect4);//电芯4 参数值
475
476                 List<String> collect0 = confColl0.stream()
477                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
478                 List<ReadWriteEntity> paramCollectionList0 = miloService.readFromOpcUa(collect0);//电芯 参数值
479
480                 //第一个电芯的数据
2de856 481                 if (CollUtil.isNotEmpty(paramCollectionList1) && !cellCodeList.get(0).isEmpty()) {
109e2f 482                     List<ChildVO> mesChildList1 = new ArrayList<>();//封装给工厂MES发送的childlist1
C 483                     for (int i = 0; i < paramCollectionList1.size(); i++) {
484                         DaParamCollection daParamCollection = new DaParamCollection();
485                         daParamCollection.setSfcCode(cellCodeList.get(0));//电芯码
486                         daParamCollection.setParamCode(confColl1.get(i).getCollectParameterId());//参数编码
487                         daParamCollection.setParamName(confColl1.get(i).getCollectParameterName());//参数名称
488                         String paramValue = "";
489                         if (ObjectUtil.isNotNull(paramCollectionList1.get(i).getValue())) {
490                             paramValue = paramCollectionList1.get(i).getValue().toString();//参数值
491                         }
492                         daParamCollection.setParamValue(paramValue);//参数值
493                         daParamCollection.setLocationCode(device);//工位
494                         daParamCollection.setCollectionTime(new Date());//采集时间
495                         saveParamList.add(daParamCollection);//封装参数采集list
496
497                         //发送给工厂mes参数封装
498                         ChildVO childVO = new ChildVO();
499                         childVO.setItemCode(confColl1.get(i).getCollectParameterName());//参数
500                         childVO.setItemType(confColl1.get(i).getItemType());
501                         childVO.setItemValue(paramValue);//参数值
502                         childVO.setItemText(confColl1.get(i).getParameterSetName());
503                         childVO.setCheckResult("1");
504                         childVO.setCheckTime(new Date().toString());
505                         mesChildList1.add(childVO);
506                     }
2de856 507                     mesList.add(0, mesChildList1);
109e2f 508                 }
2de856 509                 if (CollUtil.isNotEmpty(paramCollectionList2) && !cellCodeList.get(1).isEmpty()) {
109e2f 510                     List<ChildVO> mesChildList2 = new ArrayList<>();//封装给工厂MES发送的childlist2
C 511
512                     for (int i = 0; i < paramCollectionList2.size(); i++) {
513                         DaParamCollection daParamCollection = new DaParamCollection();
514                         daParamCollection.setSfcCode(cellCodeList.get(1));//电芯码
515                         daParamCollection.setParamCode(confColl2.get(i).getCollectParameterId());//参数编码
516                         daParamCollection.setParamName(confColl2.get(i).getCollectParameterName());//参数名称
517                         String paramValue = "";
518                         if (ObjectUtil.isNotNull(paramCollectionList2.get(i).getValue())) {
519                             paramValue = paramCollectionList2.get(i).getValue().toString();//参数值
520                         }
521                         daParamCollection.setParamValue(paramValue);//参数值
522                         daParamCollection.setLocationCode(device);//工位
523                         daParamCollection.setCollectionTime(new Date());//采集时间
524                         saveParamList.add(daParamCollection);//封装参数采集list
525
526                         //发送给工厂mes参数封装
527                         ChildVO childVO = new ChildVO();
528                         childVO.setItemCode(confColl2.get(i).getCollectParameterName());//参数
529                         childVO.setItemType(confColl2.get(i).getItemType());
530                         childVO.setItemValue(paramValue);//参数值
531                         childVO.setItemText(confColl2.get(i).getParameterSetName());
532                         childVO.setCheckResult("1");
533                         childVO.setCheckTime(new Date().toString());
534                         mesChildList2.add(childVO);
535                     }
2de856 536                     mesList.add(1, mesChildList2);
109e2f 537                 }
2de856 538                 if (CollUtil.isNotEmpty(paramCollectionList3) && !cellCodeList.get(2).isEmpty()) {
109e2f 539                     List<ChildVO> mesChildList3 = new ArrayList<>();//封装给工厂MES发送的childlist3
C 540                     for (int i = 0; i < paramCollectionList3.size(); i++) {
541                         DaParamCollection daParamCollection = new DaParamCollection();
542                         daParamCollection.setSfcCode(cellCodeList.get(2));//电芯码
543                         daParamCollection.setParamCode(confColl3.get(i).getCollectParameterId());//参数编码
544                         daParamCollection.setParamName(confColl3.get(i).getCollectParameterName());//参数名称
545                         String paramValue = "";
546                         if (ObjectUtil.isNotNull(paramCollectionList3.get(i).getValue())) {
547                             paramValue = paramCollectionList3.get(i).getValue().toString();//参数值
548                         }
549                         daParamCollection.setParamValue(paramValue);//参数值
550                         daParamCollection.setLocationCode(device);//工位
551                         daParamCollection.setCollectionTime(new Date());//采集时间
552                         saveParamList.add(daParamCollection);//封装参数采集list
553
554                         //发送给工厂mes参数封装
555                         ChildVO childVO = new ChildVO();
556                         childVO.setItemCode(confColl3.get(i).getCollectParameterName());//参数
557                         childVO.setItemType(confColl3.get(i).getItemType());
558                         childVO.setItemValue(paramValue);//参数值
559                         childVO.setItemText(confColl3.get(i).getParameterSetName());
560                         childVO.setCheckResult("1");
561                         childVO.setCheckTime(new Date().toString());
562                         mesChildList3.add(childVO);
563                     }
2de856 564                     mesList.add(2, mesChildList3);
109e2f 565                 }
2de856 566                 if (CollUtil.isNotEmpty(paramCollectionList4)&& !cellCodeList.get(3).isEmpty()) {
109e2f 567                     List<ChildVO> mesChildList4 = new ArrayList<>();//封装给工厂MES发送的childlist4
C 568                     for (int i = 0; i < paramCollectionList4.size(); i++) {
569                         DaParamCollection daParamCollection = new DaParamCollection();
570                         daParamCollection.setSfcCode(cellCodeList.get(3));//电芯码
571                         daParamCollection.setParamCode(confColl4.get(i).getCollectParameterId());//参数编码
572                         daParamCollection.setParamName(confColl4.get(i).getCollectParameterName());//参数名称
573                         String paramValue = "";
574                         if (ObjectUtil.isNotNull(paramCollectionList4.get(i).getValue())) {
575                             paramValue = paramCollectionList4.get(i).getValue().toString();//参数值
576                         }
577                         daParamCollection.setParamValue(paramValue);//参数值
578                         daParamCollection.setLocationCode(device);//工位
579                         daParamCollection.setCollectionTime(new Date());//采集时间
580                         saveParamList.add(daParamCollection);//封装参数采集list
581
582                         //发送给工厂mes参数封装
583                         ChildVO childVO = new ChildVO();
584                         childVO.setItemCode(confColl4.get(i).getCollectParameterName());//参数
585                         childVO.setItemType(confColl4.get(i).getItemType());
586                         childVO.setItemValue(paramValue);//参数值
587                         childVO.setItemText(confColl4.get(i).getParameterSetName());
588                         childVO.setCheckResult("1");
589                         childVO.setCheckTime(new Date().toString());
590                         mesChildList4.add(childVO);
591                     }
2de856 592                     mesList.add(3, mesChildList4);
109e2f 593                 }
C 594
595                 //公共参数
596                 if (CollUtil.isNotEmpty(paramCollectionList0)) {
597                     for (int i = 0; i < cellCodeList.size(); i++) {//循环4个电芯
2de856 598                         if(!cellCodeList.get(i).isEmpty()){
C 599                             List<ChildVO> mesChildList0 = new ArrayList<>();//封装给工厂MES发送的childlist0
600                             for (int j = 0; j < paramCollectionList0.size(); j++) {
601                                 DaParamCollection daParamCollection = new DaParamCollection();
602                                 daParamCollection.setSfcCode(cellCodeList.get(i));//电芯码
603                                 daParamCollection.setParamCode(confColl0.get(j).getCollectParameterId());//参数编码
604                                 daParamCollection.setParamName(confColl0.get(j).getCollectParameterName());//参数名称
605                                 String paramValue = "";
606                                 if (ObjectUtil.isNotNull(paramCollectionList0.get(j).getValue())) {
607                                     paramValue = paramCollectionList0.get(j).getValue().toString();//参数值
608                                 }
609                                 if(confColl0.get(j).getCollectParameterName().contains("时间") && !"".equals(paramValue)){
610                                     paramValue = format.parse(TimeUtil.test(TimeUtil.stringProcessing(paramValue))).toString();
611                                 }
612                                 daParamCollection.setParamValue(paramValue);//参数值
613                                 daParamCollection.setLocationCode(device);//工位
614                                 daParamCollection.setCollectionTime(new Date());//采集时间
615                                 saveParamList.add(daParamCollection);
109e2f 616
2de856 617                                 //发送给工厂mes参数封装
C 618                                 ChildVO childVO = new ChildVO();
619                                 childVO.setItemCode(confColl0.get(j).getCollectParameterName());//参数
620                                 childVO.setItemType(confColl0.get(j).getItemType());
621                                 childVO.setItemValue(paramValue);//参数值
622                                 childVO.setItemText(confColl0.get(j).getParameterSetName());
623                                 childVO.setCheckResult("1");
624                                 childVO.setCheckTime(new Date().toString());
625                                 mesChildList0.add(childVO);
626                             }
627                             mesList.add(i, mesChildList0);
109e2f 628                         }
2de856 629
C 630                         //mesList.get(i).addAll(mesChildList0);
631
109e2f 632                     }
C 633
634                 }
635
636                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
637                     //插入参数采集表
638                     daParamCollectionService.insertBatch(saveParamList);
639                     //上传到工厂mes
640                     ParentVO parentVO = new ParentVO();
641                     parentVO.setStationCode(device);//工位
642                     parentVO.setSiteCode("3983");
643
644                     parentVO.setRecordId(UUID.randomUUID().toString());
645                     parentVO.setTotalResult("1");
646                     for (int i = 0; i < cellCodeList.size(); i++) {//循环4个电芯
2de856 647                         if(!cellCodeList.get(i).isEmpty()){
C 648                             parentVO.setProductNum(cellCodeList.get(i));//电芯码
649                             parentVO.setCheckList(mesList.get(i));//参数
650                             //CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
651                             log.info("执行工厂MES方法start,传入数据:{}",parentVO);
652                             HttpResponse execute = HttpRequest.post(orderLineUrl).body(JSONUtil.toJsonStr(parentVO)).execute();
653                             log.info("执行工厂MES方法end,返回数据:{}",execute.body());
654                         }
109e2f 655                     }
C 656                 });
657             }
658         }catch (Exception e) {
659             throw new RuntimeException(e);
660         }
661         return result;
662     }
663
664     /**
2de856 665      * 030工位返回ocv测试结果
C 666      * @param thoroughfare
667      * @param device
109e2f 668      * @throws Exception
C 669      */
2de856 670     private boolean OCVResultFeedBack(String thoroughfare, String device) throws Exception {
C 671         boolean flag = true;
672         Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_1").getValue();
673         /*if (ObjectUtil.isNotNull(value1)){
674             String string = value1.toString();
675             List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
676                     .eq(QingYanTestInfo::getKeyCode, string));
677             if (CollUtil.isNotEmpty(list)){
678                 QingYanTestInfo qingYanTestInfo = list.get(0);
679                 if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
680                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(1).build());
681                 }else {
682                     flag = false;
683                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(2).build());
684                 }
685             }
686         }*/
687         Object value2 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_2").getValue();
688         /*if (ObjectUtil.isNotNull(value2)){
689             String string = value2.toString();
690             List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
691                     .eq(QingYanTestInfo::getKeyCode, string));
692             if (CollUtil.isNotEmpty(list)){
693                 QingYanTestInfo qingYanTestInfo = list.get(0);
694                 if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
695                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(1).build());
696                 }else {
697                     flag = false;
698                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(2).build());
699                 }
700             }
701         }*/
702         Object value3 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_3").getValue();
703         /*if (ObjectUtil.isNotNull(value3)){
704             String string = value3.toString();
705             List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
706                     .eq(QingYanTestInfo::getKeyCode, string));
707             if (CollUtil.isNotEmpty(list)){
708                 QingYanTestInfo qingYanTestInfo = list.get(0);
709                 if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
710                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(1).build());
711                 }else {
712                     flag = false;
713                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(2).build());
714                 }
715             }
716         }*/
717         Object value4 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_4").getValue();
718         /*if (ObjectUtil.isNotNull(value4)){
719             String string = value4.toString();
720             List<QingYanTestInfo> list = qingYanTestInfoService.list(new LambdaQueryWrapper<QingYanTestInfo>()
721                     .eq(QingYanTestInfo::getKeyCode, string));
722             if (CollUtil.isNotEmpty(list)){
723                 QingYanTestInfo qingYanTestInfo = list.get(0);
724                 if (Constants.ONE.equals(qingYanTestInfo.getStatus())){
725                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(1).build());
726                 }else {
727                     flag = false;
728                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(2).build());
729                 }
730             }
731         }*/
732         return flag;
109e2f 733     }
C 734
735
0ca254 736 }