cl
2024-07-17 a6cddf700d296d4f13a4479b8b62a4c5043a003e
提交 | 用户 | 时间
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;
ef58b9 9 import cn.hutool.json.JSONObject;
109e2f 10 import cn.hutool.json.JSONUtil;
0ca254 11 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
ef58b9 12 import com.jcdm.common.core.domain.AjaxResult;
0ca254 13 import com.jcdm.framework.websocket.WebSocketUsers;
A 14 import com.jcdm.main.constant.Constants;
15 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
16 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
17 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
18 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
19 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
20 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
5b755f 21 import com.jcdm.main.da.testDeviceInterfaceTemp.domain.DaTestDeviceInterfaceTemp;
C 22 import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService;
8c5c9c 23 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
0ca254 24 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
8c5c9c 25 import com.jcdm.main.plcserver.util.TimeUtil;
ef58b9 26 import com.jcdm.main.restful.factoryMes.service.RestfulService;
0ca254 27 import com.jcdm.main.restful.qingYan.doman.ChildVO;
A 28 import com.jcdm.main.restful.qingYan.doman.ParentVO;
29 import com.kangaroohy.milo.model.ReadWriteEntity;
30 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
31 import com.kangaroohy.milo.service.MiloService;
32 import lombok.extern.slf4j.Slf4j;
109e2f 33 import org.springframework.beans.factory.annotation.Value;
0ca254 34 import org.springframework.stereotype.Component;
ef58b9 35 import org.springframework.web.bind.annotation.GetMapping;
0ca254 36
A 37 import javax.websocket.Session;
38 import java.text.SimpleDateFormat;
39 import java.util.*;
109e2f 40 import java.util.concurrent.CompletableFuture;
0ca254 41 import java.util.stream.Collectors;
109e2f 42
0ca254 43
A 44 @Slf4j
45 @Component
46 public class OPCUaSubscription implements SubscriptionCallback {
47
8c5c9c 48     public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
0ca254 49
A 50
8c5c9c 51     Map<String, Session> map = WebSocketUsers.getUsers();
0ca254 52     public static MiloService miloService;
A 53
54
109e2f 55     public static IDaPassingStationCollectionService daPassingStationCollectionService;
0ca254 56
A 57     public static IDaCollectionParamConfService collectionParamConfService;
58
59     public static IDaParamCollectionService daParamCollectionService;
60
61     public static IOmProductionOrdeInfoService omProductionOrdeInfoService;
62
5b755f 63     public static IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService;
C 64
0d7433 65 /*    @Value("${orderLineUrl}")
C 66     private static String orderLineUrl;*/
0ca254 67
A 68     public OPCUaSubscription(MiloService miloService,
69                              IDaPassingStationCollectionService daPassingStationCollectionService,
70                              IDaCollectionParamConfService collectionParamConfService,
71                              IDaParamCollectionService daParamCollectionService,
5b755f 72                              IOmProductionOrdeInfoService omProductionOrdeInfoService,
C 73                              IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService) {
0ca254 74         OPCUaSubscription.miloService = miloService;
109e2f 75         OPCUaSubscription.daPassingStationCollectionService = daPassingStationCollectionService;
0ca254 76         OPCUaSubscription.collectionParamConfService = collectionParamConfService;
A 77         OPCUaSubscription.daParamCollectionService = daParamCollectionService;
78         OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService;
5b755f 79         OPCUaSubscription.daTestDeviceInterfaceTempService = daTestDeviceInterfaceTempService;
0ca254 80     }
A 81
82
83     @Override
84     public void onSubscribe(String identifier, Object value) {
109e2f 85         log.info("地址:"+identifier+"值:"+value);
0ca254 86         try {
109e2f 87             if(null != value && !Constants.ZERO.equals(value.toString())) {
0ca254 88                 String[] nodes = identifier.split("[.]");
A 89                 String thoroughfare = nodes[0];//通道
90                 String device = nodes[1];//设备
91                 String tab = nodes[2];//标记
109e2f 92                 String valueString = value.toString();//地址值
e4f9cb 93
C 94                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
95                     subHandle(thoroughfare,device,tab,valueString);
96                 });
97
98             }
99         } catch (Exception e) {
100             log.error(e.getMessage());
101         }
102     }
103
104     public void subHandle(String thoroughfare,String device,String tab,String valueString){
105         try{
106             if (Constants.RECORD_CHECK_CODE.equals(tab)){//电芯校验
107                 if (Constants.ONE.equals(valueString)){
108                     Integer scanResult = 11;
109                     if (Constants.OP010.equals(device)){
110                         //OP010工位电芯条码校验||OP030工位电芯条码校验
111                         Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".Scaner").getValue();
112                         if (ObjectUtil.isNotNull(value1)){
113                             String keyCode = value1.toString();
114                             log.info("读取到工位{}的Scaner数据:{}",device,keyCode);
115                             //仅校验长度是否合格
109e2f 116 //                                List<KeyCodeCheck> collect = keyCodeCheckService.list().stream().filter(x -> x.getKeyCode().contains(keyCode)).collect(Collectors.toList());
C 117 //                                if (CollUtil.isNotEmpty(collect)){
118 //                                    scanResult = 11;
0ca254 119 //                                }
e4f9cb 120                         }
C 121                     }else if(Constants.OP030.equals(device)){
9411b2 122                         Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".Scaner").getValue();//电芯码
e4f9cb 123                         if (ObjectUtil.isNotNull(value1)){
C 124                             String cellCode = value1.toString();
86e4f5 125                             scanResult = 11;
C 126                             //反馈电芯ocv检测结果,这里不用再进行检测,只要码没问题就可以了
127                             /*boolean b = OCVResultFeedBack(thoroughfare, device,cellCode);//对替换电芯校验
e4f9cb 128                             //四个电芯的状态
C 129                             if (b){
130                                 scanResult = 11;
ec7e2a 131                             }else {
C 132                                 scanResult = 12;
86e4f5 133                             }*/
e4f9cb 134                         }else {
C 135                             scanResult = 12;
0ca254 136                         }
A 137                     }
e4f9cb 138                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ScanerResult1").value(scanResult).build());
C 139                     log.info("写入到工位{}的ScanerResult1数据:{}",device,scanResult);
140                 }
141             }else if (Constants.RECORD_SN.equals(tab)){//求下发模组码请9
142                 if (Constants.ONE.equals(valueString)){
143                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(1).build());//没有要生产的工单
144                 }
145             }else if (Constants.RECORD_DATA.equals(tab)){//出入站
146                 if (Constants.ONE.equals(valueString)){//入站
147                     //1:告知MES托盘已到站,请求下发进站状态
148                     if (Constants.OP030.equals(device)){
149                         //反馈电芯ocv检测结果
997e69 150                         boolean b = OCVResultFeedBack(thoroughfare, device);//进站对4个电芯校验
e4f9cb 151                         //四个电芯的状态
C 152                         if (b){
109e2f 153                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
C 154                             log.info("写入到工位{}的RecordDataDone数据:{}",device,11);
e4f9cb 155                         }else {
C 156                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
157                             log.info("写入到工位{}的RecordDataDone数据:{}",device,12);
109e2f 158                         }
e4f9cb 159                     } else if(Constants.OP100_1.equals(device) || Constants.OP100_2.equals(device)){
C 160                         //1、进站PLC给产品类型,MES读取产品类型
161                         Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//产品类型
162                         if (ObjectUtil.isNotNull(productTypeObjcet)){
163                             String productType = productTypeObjcet.toString();//产品类型
35c489 164                             String materialCode = Constants.materialMap.get(productType);
58c9d4 165                             //调用工厂MES,保存到数据库,并且将工单传给PLC
C 166                             receivingWorkOrders(thoroughfare, device,materialCode);
e4f9cb 167                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
C 168                             log.info("写入到工位{}的RecordDataDone数据:{}",device,11);
169                         }else{
170                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
171                         }
172
58c9d4 173                     }else if (Constants.OP150.contains(device)){//人工工位
C 174                         Object modulCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
175                         if (ObjectUtil.isNull(modulCodeObjcet)){
176                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
177                         }else{
178                             String productNum = modulCodeObjcet.toString();
179                             //将产品SN发送到前台
180                             productNum = "productNum,"+ productNum;
181                             WebSocketUsers.sendMessageToUserByText(map.get(device), productNum);
182                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
183                         }
e4f9cb 184                     }else if (Constants.ModuleList.contains(device)){//有模组码的工位
C 185                         Object modulCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
186                         if (ObjectUtil.isNull(modulCodeObjcet)){
187                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
188                         }else{
189                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
0ca254 190                         }
109e2f 191                     }
e4f9cb 192                     else {
C 193                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
194                         log.info("写入到工位{}的RecordDataDone数据:{}",device,11);
0ca254 195                     }
e4f9cb 196                 }else if (Constants.TWO.equals(valueString)){//出站
C 197                     //分段010-065段
198                     if (Constants.OP010.equals(device)){
199                         //010工位无过站记录,只给放行信号
200                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(21).build());
201                         log.info("写入到工位{}的RecordDataDone数据:{}",device,21);
202                     }else if (Constants.OP020_OP090.contains(device)){
203                         Integer result = 21;
204                         //读取电芯码
205                         List<String> cellCodeList = readCellCodeList(thoroughfare, device);
b59023 206                         if(ObjectUtil.isNull(cellCodeList) || cellCodeList.size() != 4 ){
e4f9cb 207                             result = 23;
C 208                         }else{
09dec7 209                             String cellCode1 = cellCodeList.get(0);
C 210                             String cellCode2 = cellCodeList.get(1);
211                             String cellCode3 = cellCodeList.get(2);
212                             String cellCode4 = cellCodeList.get(3);
213                             if ((!cellCode1.isEmpty() && cellCode2.isEmpty()) || (cellCode1.isEmpty() && !cellCode2.isEmpty())
214                             || (!cellCode3.isEmpty() && cellCode4.isEmpty()) || (!cellCode4.isEmpty() && cellCode3.isEmpty())) {
215                                 result = 23;
216                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
217                                 return;
b59023 218                             }
C 219
e4f9cb 220                             result = savePassingStation(thoroughfare, device,cellCodeList);//保存过站
C 221                             if(result == 21) {
069a9b 222                                 result = saveParamCollection(device,cellCodeList);//保存参数,发送工厂MES
e4f9cb 223                             }
C 224                         }
225                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
226                         log.info("写入到工位{}的RecordDataDone数据:{}",device,result);
227                     } else if (Constants.OP100_OP150.contains(device)){//人工工位
228                         WebSocketUsers.sendMessageToUserByText(map.get(device), "END");
229                     } else {
230                         Integer result = 21;
13a2a4 231                         //Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//产品类型
e4f9cb 232                         Object modulCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
C 233                         if (ObjectUtil.isNull(modulCodeObjcet)){
234                             result = 23;
235                         }else{
236                             String moduleCode = modulCodeObjcet.toString();
069a9b 237                             Object stationStatusObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus").getValue();//站状态地址
C 238                             if (ObjectUtil.isNotNull(stationStatusObjcet)){
239                                 String stationStatus = stationStatusObjcet.toString();
240                                 result = savePassingStation(thoroughfare, device,moduleCode,stationStatus);//保存过站
241                                 if(result == 21) {
242                                     result = saveParamCollection(device,moduleCode,stationStatus);//保存参数,发送工厂MES
243                                 }
244                             }else{
245                                 result = 23;
246                                 log.info("读取到工位{}StationStatus数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
e4f9cb 247                             }
069a9b 248
e4f9cb 249                         }
C 250                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
251                         log.info("写入到工位{}的RecordDataDone数据:{}",device,result);
252                     }
253                 }
0ca254 254             }
e4f9cb 255         }catch (Exception e) {
8c5c9c 256             log.error(e.getMessage());
0ca254 257         }
A 258     }
4878fe 259
35c489 260     public void receivingWorkOrders(String thoroughfare ,String device ,String materialCode)
ef58b9 261     {
C 262         String paramProductNum = "";
263         try {
264             // 查询最新的工单信息
22c9e0 265             OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder();
069a9b 266
C 267             log.info("请求工厂MES工单:入参device{},materialCode:{}", device, materialCode);
35c489 268             String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "M1OP100",materialCode);
ef58b9 269             JSONObject jsonObject = new JSONObject(orderJsonString);
C 270             // 从JSONObject中获取data对象
271             JSONObject dataObject = jsonObject.getJSONObject("data");
272             String code = jsonObject.getStr("code");
273             // 判断接单是否成功
274             if(code.equals("success")) {
275                 log.info("请求工厂MES工单:入参pack{}出参pack:{}", paramProductNum, dataObject.getStr("productNum"));
276                 OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
277                 omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum"));
278                 omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum"));
279                 omProductionOrdeInfo.setStationCode(dataObject.getStr("stationCode"));
aa5f09 280                 omProductionOrdeInfo.setProductCode(dataObject.getStr("materialCode"));
653b17 281                 omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity")));
ef58b9 282                 omProductionOrdeInfo.setOnlineCompletionMark("0");
C 283                 omProductionOrdeInfo.setSfResult("0");
aa5f09 284                 omProductionOrdeInfo.setProductModel(dataObject.getStr("model"));
ef58b9 285                 omProductionOrdeInfo.setCreateTime(new Date());
C 286                 omProductionOrdeInfo.setCreateUser("工厂MES");
287                 omProductionOrdeInfoService.save(omProductionOrdeInfo);
288
58c9d4 289                 String productNum = dataObject.getStr("productNum");
C 290                 String orderNum = dataObject.getStr("productionOrderNum");
291                 //下发产品模组码
292                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ModuleCode").value(productNum).build());
293                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build());
ef58b9 294
58c9d4 295                 //将产品SN发送到前台
C 296                 productNum = "productNum,"+ productNum;
297                 WebSocketUsers.sendMessageToUserByText(map.get(device), productNum);
ef58b9 298
C 299             }
300         } catch (Exception e) {
301             throw new RuntimeException(e);
302         }
35c489 303     }
0ca254 304
A 305     /**
109e2f 306      * 读取电芯码
C 307      * @param thoroughfare 通道
308      * @param device 工位
309      * @return list
310      * @throws Exception e
0ca254 311      */
109e2f 312     private static List<String> readCellCodeList(String thoroughfare, String device){
C 313         List<String> cellCodeList = new ArrayList<>();
2de856 314         Map map = new HashMap();
109e2f 315         //电芯码地址
C 316         List<String> readList = new ArrayList<>();
317         readList.add(thoroughfare + "." + device +".CellCode_1");
318         readList.add(thoroughfare + "." + device +".CellCode_2");
319         readList.add(thoroughfare + "." + device +".CellCode_3");
320         readList.add(thoroughfare + "." + device +".CellCode_4");
0ca254 321         try {
109e2f 322             List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(readList);//电芯码
C 323             for (ReadWriteEntity readWriteEntity : readWriteEntityList) {
b59023 324                 if (ObjectUtil.isNotNull(readWriteEntity.getValue()) && !readWriteEntity.getValue().toString().trim().isEmpty()){
2de856 325                     cellCodeList.add(readWriteEntity.getValue().toString());//封装电芯码
b59023 326                 }else{
2de856 327                     cellCodeList.add("");//封装电芯码
b59023 328                 }
0ca254 329             }
2de856 330
0ca254 331         } catch (Exception e) {
A 332             throw new RuntimeException(e);
333         }
109e2f 334         return cellCodeList;
2de856 335     }
C 336
337
338     /**
339      * 保存过站数据
340      * @param thoroughfare 通道
341      * @param device 工位
342      * @param moduleCode 模组号
069a9b 343      * @param stationStatus 站状态
2de856 344      * @return list
C 345      * @throws Exception e
346      */
069a9b 347     private static Integer savePassingStation(String thoroughfare, String device,String moduleCode,String stationStatus){
2de856 348         Integer result = 21;
C 349
350         try {
351             //读进站时间
352             Date startTime = new Date();
353             ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间
354             if (ObjectUtil.isNotNull(startTimeRead.getValue())){
355                 startTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(startTimeRead.getValue().toString())));
356             }else{
357                 result = 23;
358                 log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
359                 return result;
360             }
361
362             DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
363             passingStationCollection.setSfcCode(moduleCode);//电芯码
364             passingStationCollection.setLocationCode(device);//工位
365             passingStationCollection.setInboundTime(startTime);//进站时间
366             passingStationCollection.setOutboundTime(new Date());//出站时间
367             passingStationCollection.setOutRsSign(stationStatus);//站状态值
368             passingStationCollection.setCollectionTime(new Date());//采集时间
369             daPassingStationCollectionService.save(passingStationCollection);
370
371         } catch (Exception e) {
372             throw new RuntimeException(e);
373         }
374
375         return result;
0ca254 376     }
A 377
109e2f 378     /**
C 379      * 保存过站数据
380      * @param thoroughfare 通道
381      * @param device 工位
382      * @param cellCodeList 电芯码集合
383      * @return list
384      * @throws Exception e
385      */
386     private static Integer savePassingStation(String thoroughfare, String device,List<String> cellCodeList){
387         Integer result = 21;
388
389         try {
390             //读进站时间
391             Date startTime = new Date();
392             ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间
393             if (ObjectUtil.isNotNull(startTimeRead.getValue())){
8c5c9c 394                 startTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(startTimeRead.getValue().toString())));
109e2f 395             }else{
C 396                 result = 23;
397                 log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
2de856 398                 return result;
109e2f 399             }
C 400
401             //读工站状态
402             String stationStatus = Constants.PASS;
403             ReadWriteEntity stationStatusRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus");//站状态地址
404             if (ObjectUtil.isNotNull(stationStatusRead.getValue())){
405                 String string = stationStatusRead.getValue().toString();
406                 if (Constants.TWO.equals(string)){
407                     stationStatus = Constants.UN_PASS;
408                 }
409             }else{
410                 result = 23;
2de856 411                 log.info("读取到工位{}StationStatus数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
C 412                 return result;
109e2f 413             }
C 414
415             List<DaPassingStationCollection> passingList = new ArrayList<>();
416             for (String cellCode : cellCodeList) {
417                 DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
2de856 418                 if (ObjectUtil.isNotNull(cellCode) && !cellCode.isEmpty()){
109e2f 419                     passingStationCollection.setSfcCode(cellCode);//电芯码
C 420                     passingStationCollection.setLocationCode(device);//工位
421                     passingStationCollection.setInboundTime(startTime);//进站时间
422                     passingStationCollection.setOutboundTime(new Date());//出站时间
423                     passingStationCollection.setOutRsSign(stationStatus);//站状态值
424                     passingStationCollection.setCollectionTime(new Date());//采集时间
425                     passingList.add(passingStationCollection);
426                 }
427             }
428
429             if (CollUtil.isNotEmpty(passingList)){
430                 daPassingStationCollectionService.insertBatch(passingList);//存储过站采集数据
431             }
432
433         } catch (Exception e) {
434             throw new RuntimeException(e);
435         }
436
437         return result;
438     }
439
2de856 440
109e2f 441     /**
2de856 442      * 保存参数数据和发送工厂MES
C 443      * @param device 工位
444      * @param moduleCode 模组号
069a9b 445      * @param stationStatus 站状态
2de856 446      * @return list
C 447      * @throws Exception e
448      */
069a9b 449     private static Integer saveParamCollection(String device,String moduleCode,String stationStatus){
2de856 450         Integer result = 21;//返回结果
5c62de 451         String sendMes = "";
2de856 452
C 453         try {
454             //查询参数配置表
455             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
456                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
457                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
458             );
459             if (CollUtil.isNotEmpty(list)){
460
461                 List<String> collect = list.stream()
462                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
463                 List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(collect);
464
465                 List<DaParamCollection> collectionList = new ArrayList<>();
466                 List<ChildVO> mesList = new ArrayList<>();
467                 for (int i = 0; i < readWriteEntityList.size(); i++) {
468                     DaParamCollection daParamCollection = new DaParamCollection();
469                     daParamCollection.setSfcCode(moduleCode);//模组码
470                     daParamCollection.setParamCode(list.get(i).getCollectParameterId());//参数编码
471                     daParamCollection.setParamName(list.get(i).getCollectParameterName());//参数名称
472                     String paramValue = "";
473                     if (ObjectUtil.isNotNull(readWriteEntityList.get(i).getValue())){
474                         paramValue = readWriteEntityList.get(i).getValue().toString();//参数值
e0c9c6 475                         if("DATE".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){
C 476                             paramValue = format.parse(TimeUtil.test(TimeUtil.stringProcessing(paramValue))).toString();
aa5f09 477                         }else if("MODEL".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){
C 478                             paramValue = Constants.materialMap.get(paramValue);
e0c9c6 479                         }
2de856 480                     }
C 481                     daParamCollection.setParamValue(paramValue);//参数值
482                     daParamCollection.setLocationCode(device);//工位
483                     daParamCollection.setCollectionTime(new Date());//采集时间
484                     collectionList.add(daParamCollection);//封装参数采集list
485
486                     //发送给工厂mes参数封装
487                     ChildVO childVO = new ChildVO();
488                     childVO.setItemCode(list.get(i).getCollectParameterId());//参数编码
489                     childVO.setItemType(list.get(i).getItemType());
490                     childVO.setItemValue(paramValue);//参数值
491                     childVO.setItemText(list.get(i).getCollectParameterName());
492                     childVO.setCheckResult("1");
e0c9c6 493                     childVO.setCheckTime(format.format(new Date()));
2de856 494                     mesList.add(childVO);
C 495                 }
496
497                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
498                     //插入参数采集表
499                     daParamCollectionService.insertBatch(collectionList);
997e69 500
C 501                     //如果220工位,进行报工
502                     if("M1OP220".equals(device)) {
06168f 503                         getWorkReportResultFeedback(moduleCode, "M1OP220", format.format(new Date()));
997e69 504                     }
C 505
2de856 506                     //上传到工厂mes
C 507                     ParentVO parentVO = new ParentVO();
508                     parentVO.setStationCode(device);//工位
509                     parentVO.setSiteCode("3983");
510
511                     parentVO.setRecordId(UUID.randomUUID().toString());
997e69 512                     if("2".equals(stationStatus)){//工站状态
069a9b 513                         parentVO.setTotalResult("0");
C 514                     }else {
515                         parentVO.setTotalResult("1");
516                     }
2de856 517                     parentVO.setProductNum(moduleCode);
5fbc7a 518
C 519                     //添加基础数据
06168f 520                     List<ChildVO> basicList = getCollectParamBasicData(device,moduleCode);
5fbc7a 521                     mesList.addAll(basicList);
C 522
2de856 523                     parentVO.setCheckList(mesList);
C 524
e4f9cb 525                     log.info("执行工厂MES方法start,工位号{} 传入数据:{}",device ,parentVO);
971788 526                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
e4f9cb 527                     log.info("执行工厂MES方法end,工位号{} 返回数据:{}",device,execute.body());
2de856 528
C 529                 });
530             }
531         }catch (Exception e) {
532             throw new RuntimeException(e);
533         }
534         return result;
535     }
536
537     /**
538      * 保存参数数据和发送工厂MES
109e2f 539      * @param device 工位
C 540      * @param cellCodeList 电芯码集合
541      * @return list
542      * @throws Exception e
543      */
069a9b 544     private static Integer saveParamCollection(String device,List<String> cellCodeList){
109e2f 545         Integer result = 21;//返回结果
743e2e 546         List<ChildVO> mesChildList1 = new ArrayList<>();//封装给工厂MES发送的childlist1
C 547         List<ChildVO> mesChildList2 = new ArrayList<>();//封装给工厂MES发送的childlist2
548         List<ChildVO> mesChildList3 = new ArrayList<>();//封装给工厂MES发送的childlist3
549         List<ChildVO> mesChildList4 = new ArrayList<>();//封装给工厂MES发送的childlist4
550         List<ChildVO> mesChildList0 = new ArrayList<>();//封装给工厂MES发送的childlist4
109e2f 551         try {
C 552             //查询参数配置表
553             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
554                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
8c5c9c 555                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
2de856 556                     );//类型
109e2f 557             if (CollUtil.isNotEmpty(list)) {
C 558                 List<DaParamCollection> saveParamList = new ArrayList<>();//封装参数采集list
559                 List<DaCollectionParamConf> confColl1 = list.stream().filter(x -> Constants.INT_ONE.equals(x.getKeyNum())).collect(Collectors.toList());
560                 List<DaCollectionParamConf> confColl2 = list.stream().filter(x -> Constants.INT_TWO.equals(x.getKeyNum())).collect(Collectors.toList());
561                 List<DaCollectionParamConf> confColl3 = list.stream().filter(x -> Constants.INT_THREE.equals(x.getKeyNum())).collect(Collectors.toList());
562                 List<DaCollectionParamConf> confColl4 = list.stream().filter(x -> Constants.INT_FOUR.equals(x.getKeyNum())).collect(Collectors.toList());
563                 List<DaCollectionParamConf> confColl0 = list.stream().filter(x -> Constants.INT_ZERO.equals(x.getKeyNum())).collect(Collectors.toList());
564
565                 List<String> collect1 = confColl1.stream()
566                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
567                 List<ReadWriteEntity> paramCollectionList1 = miloService.readFromOpcUa(collect1);//电芯1 参数值
568
569                 List<String> collect2 = confColl2.stream()
570                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
571                 List<ReadWriteEntity> paramCollectionList2 = miloService.readFromOpcUa(collect2);//电芯2 参数值
572
573                 List<String> collect3 = confColl3.stream()
574                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
575                 List<ReadWriteEntity> paramCollectionList3 = miloService.readFromOpcUa(collect3);//电芯3 参数值
576
577                 List<String> collect4 = confColl4.stream()
578                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
579                 List<ReadWriteEntity> paramCollectionList4 = miloService.readFromOpcUa(collect4);//电芯4 参数值
580
581                 List<String> collect0 = confColl0.stream()
582                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
583                 List<ReadWriteEntity> paramCollectionList0 = miloService.readFromOpcUa(collect0);//电芯 参数值
584
585                 //第一个电芯的数据
2de856 586                 if (CollUtil.isNotEmpty(paramCollectionList1) && !cellCodeList.get(0).isEmpty()) {
109e2f 587                     for (int i = 0; i < paramCollectionList1.size(); i++) {
C 588                         DaParamCollection daParamCollection = new DaParamCollection();
589                         daParamCollection.setSfcCode(cellCodeList.get(0));//电芯码
590                         daParamCollection.setParamCode(confColl1.get(i).getCollectParameterId());//参数编码
591                         daParamCollection.setParamName(confColl1.get(i).getCollectParameterName());//参数名称
592                         String paramValue = "";
593                         if (ObjectUtil.isNotNull(paramCollectionList1.get(i).getValue())) {
594                             paramValue = paramCollectionList1.get(i).getValue().toString();//参数值
595                         }
596                         daParamCollection.setParamValue(paramValue);//参数值
597                         daParamCollection.setLocationCode(device);//工位
598                         daParamCollection.setCollectionTime(new Date());//采集时间
599                         saveParamList.add(daParamCollection);//封装参数采集list
600
601                         //发送给工厂mes参数封装
602                         ChildVO childVO = new ChildVO();
e4f9cb 603                         childVO.setItemCode(confColl1.get(i).getCollectParameterId());//参数
109e2f 604                         childVO.setItemType(confColl1.get(i).getItemType());
C 605                         childVO.setItemValue(paramValue);//参数值
e4f9cb 606                         childVO.setItemText(confColl1.get(i).getCollectParameterName());
109e2f 607                         childVO.setCheckResult("1");
e0c9c6 608                         childVO.setCheckTime(format.format(new Date()));
109e2f 609                         mesChildList1.add(childVO);
C 610                     }
743e2e 611
109e2f 612                 }
2de856 613                 if (CollUtil.isNotEmpty(paramCollectionList2) && !cellCodeList.get(1).isEmpty()) {
109e2f 614
C 615                     for (int i = 0; i < paramCollectionList2.size(); i++) {
616                         DaParamCollection daParamCollection = new DaParamCollection();
617                         daParamCollection.setSfcCode(cellCodeList.get(1));//电芯码
618                         daParamCollection.setParamCode(confColl2.get(i).getCollectParameterId());//参数编码
619                         daParamCollection.setParamName(confColl2.get(i).getCollectParameterName());//参数名称
620                         String paramValue = "";
621                         if (ObjectUtil.isNotNull(paramCollectionList2.get(i).getValue())) {
622                             paramValue = paramCollectionList2.get(i).getValue().toString();//参数值
623                         }
624                         daParamCollection.setParamValue(paramValue);//参数值
625                         daParamCollection.setLocationCode(device);//工位
626                         daParamCollection.setCollectionTime(new Date());//采集时间
627                         saveParamList.add(daParamCollection);//封装参数采集list
628
629                         //发送给工厂mes参数封装
630                         ChildVO childVO = new ChildVO();
e4f9cb 631                         childVO.setItemCode(confColl2.get(i).getCollectParameterId());//参数
109e2f 632                         childVO.setItemType(confColl2.get(i).getItemType());
C 633                         childVO.setItemValue(paramValue);//参数值
e4f9cb 634                         childVO.setItemText(confColl2.get(i).getCollectParameterName());
109e2f 635                         childVO.setCheckResult("1");
e0c9c6 636                         childVO.setCheckTime(format.format(new Date()));
109e2f 637                         mesChildList2.add(childVO);
C 638                     }
639                 }
2de856 640                 if (CollUtil.isNotEmpty(paramCollectionList3) && !cellCodeList.get(2).isEmpty()) {
109e2f 641                     for (int i = 0; i < paramCollectionList3.size(); i++) {
C 642                         DaParamCollection daParamCollection = new DaParamCollection();
643                         daParamCollection.setSfcCode(cellCodeList.get(2));//电芯码
644                         daParamCollection.setParamCode(confColl3.get(i).getCollectParameterId());//参数编码
645                         daParamCollection.setParamName(confColl3.get(i).getCollectParameterName());//参数名称
646                         String paramValue = "";
647                         if (ObjectUtil.isNotNull(paramCollectionList3.get(i).getValue())) {
648                             paramValue = paramCollectionList3.get(i).getValue().toString();//参数值
649                         }
650                         daParamCollection.setParamValue(paramValue);//参数值
651                         daParamCollection.setLocationCode(device);//工位
652                         daParamCollection.setCollectionTime(new Date());//采集时间
653                         saveParamList.add(daParamCollection);//封装参数采集list
654
655                         //发送给工厂mes参数封装
656                         ChildVO childVO = new ChildVO();
e4f9cb 657                         childVO.setItemCode(confColl3.get(i).getCollectParameterId());//参数
109e2f 658                         childVO.setItemType(confColl3.get(i).getItemType());
C 659                         childVO.setItemValue(paramValue);//参数值
e4f9cb 660                         childVO.setItemText(confColl3.get(i).getCollectParameterName());
109e2f 661                         childVO.setCheckResult("1");
e0c9c6 662                         childVO.setCheckTime(format.format(new Date()));
109e2f 663                         mesChildList3.add(childVO);
C 664                     }
665                 }
2de856 666                 if (CollUtil.isNotEmpty(paramCollectionList4)&& !cellCodeList.get(3).isEmpty()) {
109e2f 667                     for (int i = 0; i < paramCollectionList4.size(); i++) {
C 668                         DaParamCollection daParamCollection = new DaParamCollection();
669                         daParamCollection.setSfcCode(cellCodeList.get(3));//电芯码
670                         daParamCollection.setParamCode(confColl4.get(i).getCollectParameterId());//参数编码
671                         daParamCollection.setParamName(confColl4.get(i).getCollectParameterName());//参数名称
672                         String paramValue = "";
673                         if (ObjectUtil.isNotNull(paramCollectionList4.get(i).getValue())) {
674                             paramValue = paramCollectionList4.get(i).getValue().toString();//参数值
675                         }
676                         daParamCollection.setParamValue(paramValue);//参数值
677                         daParamCollection.setLocationCode(device);//工位
678                         daParamCollection.setCollectionTime(new Date());//采集时间
679                         saveParamList.add(daParamCollection);//封装参数采集list
680
681                         //发送给工厂mes参数封装
682                         ChildVO childVO = new ChildVO();
e4f9cb 683                         childVO.setItemCode(confColl4.get(i).getCollectParameterId());//参数
109e2f 684                         childVO.setItemType(confColl4.get(i).getItemType());
C 685                         childVO.setItemValue(paramValue);//参数值
e4f9cb 686                         childVO.setItemText(confColl4.get(i).getCollectParameterName());
109e2f 687                         childVO.setCheckResult("1");
e0c9c6 688                         childVO.setCheckTime(format.format(new Date()));
109e2f 689                         mesChildList4.add(childVO);
C 690                     }
691                 }
692
693                 //公共参数
694                 if (CollUtil.isNotEmpty(paramCollectionList0)) {
695                     for (int i = 0; i < cellCodeList.size(); i++) {//循环4个电芯
2de856 696                         if(!cellCodeList.get(i).isEmpty()){
C 697                             for (int j = 0; j < paramCollectionList0.size(); j++) {
698                                 DaParamCollection daParamCollection = new DaParamCollection();
699                                 daParamCollection.setSfcCode(cellCodeList.get(i));//电芯码
700                                 daParamCollection.setParamCode(confColl0.get(j).getCollectParameterId());//参数编码
701                                 daParamCollection.setParamName(confColl0.get(j).getCollectParameterName());//参数名称
702                                 String paramValue = "";
703                                 if (ObjectUtil.isNotNull(paramCollectionList0.get(j).getValue())) {
704                                     paramValue = paramCollectionList0.get(j).getValue().toString();//参数值
e0c9c6 705                                     if("DATE".equals(confColl0.get(j).getCollectParameterType()) && !paramValue.isEmpty()){
C 706                                         paramValue = TimeUtil.test(TimeUtil.stringProcessing(paramValue));
707                                     }
2de856 708                                 }
C 709                                 daParamCollection.setParamValue(paramValue);//参数值
710                                 daParamCollection.setLocationCode(device);//工位
711                                 daParamCollection.setCollectionTime(new Date());//采集时间
712                                 saveParamList.add(daParamCollection);
109e2f 713
2de856 714                                 //发送给工厂mes参数封装
C 715                                 ChildVO childVO = new ChildVO();
e4f9cb 716                                 childVO.setItemCode(confColl0.get(j).getCollectParameterId());//参数
2de856 717                                 childVO.setItemType(confColl0.get(j).getItemType());
C 718                                 childVO.setItemValue(paramValue);//参数值
e4f9cb 719                                 childVO.setItemText(confColl0.get(j).getCollectParameterName());
2de856 720                                 childVO.setCheckResult("1");
e0c9c6 721                                 childVO.setCheckTime(format.format(new Date()));
2de856 722                                 mesChildList0.add(childVO);
C 723                             }
109e2f 724                         }
2de856 725
C 726                         //mesList.get(i).addAll(mesChildList0);
727
109e2f 728                     }
C 729
730                 }
731
732                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
733                     //插入参数采集表
734                     daParamCollectionService.insertBatch(saveParamList);
735                     //上传到工厂mes
736                     ParentVO parentVO = new ParentVO();
737                     parentVO.setStationCode(device);//工位
738                     parentVO.setSiteCode("3983");
739
740                     parentVO.setRecordId(UUID.randomUUID().toString());
741                     parentVO.setTotalResult("1");
742                     for (int i = 0; i < cellCodeList.size(); i++) {//循环4个电芯
2de856 743                         if(!cellCodeList.get(i).isEmpty()){
C 744                             parentVO.setProductNum(cellCodeList.get(i));//电芯码
743e2e 745                             //封装给工厂MES发送的childlist4
C 746                             List<ChildVO> mesChildList = new ArrayList<>(mesChildList0);
747                             switch (i) {
748                                 case 0 :
749                                     mesChildList.addAll(mesChildList1);
750                                     break;
751                                 case 1 :
752                                     mesChildList.addAll(mesChildList2);
753                                     break;
754                                 case 2 :
755                                     mesChildList.addAll(mesChildList3);
756                                     break;
757                                 case 3 :
758                                     mesChildList.addAll(mesChildList4);
759                                     break;
760
761                             }
5fbc7a 762
C 763                             //添加基础数据
06168f 764                             List<ChildVO> basicList = getCollectParamBasicData(device,cellCodeList.get(i));
5fbc7a 765                             mesChildList.addAll(basicList);
C 766
743e2e 767                             parentVO.setCheckList(mesChildList);//参数
2de856 768                             //CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
C 769                             log.info("执行工厂MES方法start,传入数据:{}",parentVO);
971788 770                             HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
2de856 771                             log.info("执行工厂MES方法end,返回数据:{}",execute.body());
C 772                         }
109e2f 773                     }
C 774                 });
775             }
776         }catch (Exception e) {
743e2e 777             log.error(e.getMessage());
109e2f 778             throw new RuntimeException(e);
C 779         }
780         return result;
781     }
782
783     /**
2de856 784      * 030工位返回ocv测试结果
C 785      * @param thoroughfare
786      * @param device
ec7e2a 787      * @param cellCode
C 788      * @throws Exception
789      */
790     private boolean OCVResultFeedBack(String thoroughfare, String device,String cellCode) throws Exception {
791         boolean flag = true;
792
793         List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
9411b2 794                 .eq(DaTestDeviceInterfaceTemp::getStationCode, "M1OP020")
ec7e2a 795                 .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode));
C 796         if (CollUtil.isNotEmpty(list)){
d8e6a5 797             DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(list.size()-1);
ec7e2a 798             if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
9411b2 799                 flag = true;
ec7e2a 800             }else {
C 801                 flag = false;
802             }
d8e6a5 803             daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
f18ebf 804         }else {
C 805             flag = false;
806             log.info("读取到工位{},测试设备返回的数据查询不到,电芯码为:{}",device,cellCode);
ec7e2a 807         }
C 808         return flag;
809     }
810     /**
811      * 030工位返回ocv测试结果
812      * @param thoroughfare
813      * @param device
109e2f 814      * @throws Exception
C 815      */
2de856 816     private boolean OCVResultFeedBack(String thoroughfare, String device) throws Exception {
C 817         boolean flag = true;
818         Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_1").getValue();
5b755f 819         if (ObjectUtil.isNotNull(value1)){
C 820             String cellCode = value1.toString();
821             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
9411b2 822                     .eq(DaTestDeviceInterfaceTemp::getStationCode, "M1OP020")
5b755f 823                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode));
2de856 824             if (CollUtil.isNotEmpty(list)){
18b39c 825                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(list.size()-1);
5b755f 826                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
2de856 827                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(1).build());
C 828                 }else {
829                     flag = false;
830                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(2).build());
831                 }
18b39c 832                 daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
86e4f5 833             }else {
C 834                 flag = false;
a6cddf 835                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(5).build());
86e4f5 836                 log.info("读取到工位{},OP020工位没有给测试结果",device);
2de856 837             }
f18ebf 838         }else {
C 839             flag = false;
a6cddf 840             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(5).build());
f18ebf 841             log.info("读取到工位{},PLC没有给电芯码",device);
5b755f 842         }
2de856 843         Object value2 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_2").getValue();
5b755f 844         if (ObjectUtil.isNotNull(value2)){
C 845             String cellCode = value2.toString();
846             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
847                     .eq(DaTestDeviceInterfaceTemp::getStationCode, device)
848                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode));
2de856 849             if (CollUtil.isNotEmpty(list)){
18b39c 850                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(list.size()-1);
5b755f 851                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
2de856 852                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(1).build());
C 853                 }else {
854                     flag = false;
855                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(2).build());
856                 }
18b39c 857                 daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
86e4f5 858             }else {
C 859                 flag = false;
a6cddf 860                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(5).build());
86e4f5 861                 log.info("读取到工位{},OP020工位没有给测试结果",device);
2de856 862             }
f18ebf 863         }else {
C 864             flag = false;
a6cddf 865             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(5).build());
f18ebf 866             log.info("读取到工位{},PLC没有给电芯码",device);
5b755f 867         }
C 868
2de856 869         Object value3 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_3").getValue();
5b755f 870         if (ObjectUtil.isNotNull(value3)){
C 871             String cellCode = value3.toString();
872             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
873                     .eq(DaTestDeviceInterfaceTemp::getStationCode, device)
874                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode));
2de856 875             if (CollUtil.isNotEmpty(list)){
18b39c 876                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(list.size()-1);
5b755f 877                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
2de856 878                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(1).build());
C 879                 }else {
880                     flag = false;
881                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(2).build());
882                 }
18b39c 883                 daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
86e4f5 884             }else {
C 885                 flag = false;
a6cddf 886                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(5).build());
86e4f5 887                 log.info("读取到工位{},OP020工位没有给测试结果",device);
2de856 888             }
f18ebf 889         }else {
C 890             flag = false;
a6cddf 891             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(5).build());
f18ebf 892             log.info("读取到工位{},PLC没有给电芯码",device);
5b755f 893         }
C 894
2de856 895         Object value4 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_4").getValue();
5b755f 896         if (ObjectUtil.isNotNull(value4)){
C 897             String cellCode = value4.toString();
898             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
899                     .eq(DaTestDeviceInterfaceTemp::getStationCode, device)
900                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode));
2de856 901             if (CollUtil.isNotEmpty(list)){
18b39c 902                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(list.size()-1);
5b755f 903                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
2de856 904                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(1).build());
C 905                 }else {
906                     flag = false;
907                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(2).build());
908                 }
18b39c 909                 daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
86e4f5 910             }else {
C 911                 flag = false;
a6cddf 912                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(5).build());
86e4f5 913                 log.info("读取到工位{},OP020工位没有给测试结果",device);
2de856 914             }
f18ebf 915         }else {
C 916             flag = false;
a6cddf 917             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(5).build());
f18ebf 918             log.info("读取到工位{},PLC没有给电芯码",device);
5b755f 919         }
C 920
2de856 921         return flag;
109e2f 922     }
C 923
997e69 924     /**
C 925      * AMES报工结果回传
926      * @param productNum
927      * @param stationCode
928      * @param confirmTime
929      * @return
930      */
931     //{"code":"success","data":{"productNum":"LCV123456P0600036","stationCode":"1HZ01","resultCode":"S","resultText":"报工成功"},"message":"API调用成功"}
932     public static String getWorkReportResultFeedback(String productNum,String stationCode,String confirmTime)
933     {
934         String result = "";
935         try {
936             String url = Constants.FACTORY_EMS_UAT_GET_RUL + "workReportResultFeedback?siteCode="+Constants.FACTORY_EMS_SITE_CODE+"&stationCode="+stationCode+"&productNum="+productNum+"&confirmTime="+confirmTime;
937             HttpResponse response = HttpRequest.get(url).execute();
938             HttpRequest httpRequest = HttpRequest.get(url);
939             result =  response.body();
940         }catch (Exception e){
aa5f09 941             throw new RuntimeException(e);
997e69 942         }finally {
C 943             return result;
944         }
945     }
946
109e2f 947
aa5f09 948     /**
C 949      * 获取采集参数基础数据
950      * @param stationCode
06168f 951      * @param sfcCode
aa5f09 952      * @return list
C 953      */
06168f 954     public static List<ChildVO> getCollectParamBasicData(String stationCode,String sfcCode) {
aa5f09 955         List<ChildVO> basicList = new ArrayList<>();
06168f 956         List<DaParamCollection> collectionList = new ArrayList<>();
aa5f09 957         try {
C 958             //查询参数配置表
959             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
960                     .eq(DaCollectionParamConf::getProcessesCode, stationCode)//工位
961                     .eq(DaCollectionParamConf::getCollectParameterType, "BASIC")//采集参数类型
962             );
963             if (CollUtil.isNotEmpty(list)){
964                 for(DaCollectionParamConf conf:list){
965                     ChildVO childVO = new ChildVO();
966                     childVO.setItemCode(conf.getCollectParameterId());//参数
967                     childVO.setItemType(conf.getItemType());
968                     childVO.setItemValue(conf.getParamCentral());//参数值
969                     childVO.setItemText(conf.getCollectParameterName());
970                     childVO.setCheckResult("1");
971                     childVO.setCheckTime(format.format(new Date()));
972                     basicList.add(childVO);
06168f 973
C 974                     DaParamCollection daParamCollection = new DaParamCollection();
975                     daParamCollection.setSfcCode(sfcCode);//模组码
976                     daParamCollection.setParamCode(conf.getCollectParameterId());//参数编码
977                     daParamCollection.setParamName(conf.getCollectParameterName());//参数名称
978
979                     daParamCollection.setParamValue(conf.getParamCentral());//参数值
980                     daParamCollection.setLocationCode(stationCode);//工位
981                     daParamCollection.setCollectionTime(new Date());//采集时间
982                     collectionList.add(daParamCollection);//封装参数采集list
aa5f09 983                 }
06168f 984                 daParamCollectionService.insertBatch(collectionList);
aa5f09 985             }
C 986             return basicList;
987         }catch (Exception e) {
988             throw new RuntimeException(e);
989         }
990     }
991
992
993
0ca254 994 }