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