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