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