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