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