admin
6 天以前 18cb51817380016c4024f9f462ea91b57bfa40f9
提交 | 用户 | 时间
61c519 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;
7 import cn.hutool.http.HttpRequest;
8 import cn.hutool.http.HttpResponse;
9 import cn.hutool.json.JSONObject;
10 import cn.hutool.json.JSONUtil;
11 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4162bc 12 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
61c519 13 import com.jcdm.common.core.domain.AjaxResult;
A 14 import com.jcdm.framework.websocket.WebSocketUsers;
15 import com.jcdm.main.constant.Constants;
16 import com.jcdm.main.da.cellData.domain.DaCellData;
17 import com.jcdm.main.da.cellData.service.IDaCellDataService;
18 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
19 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
20 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
21 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
22 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
23 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
4162bc 24 import com.jcdm.main.da.psConf.domain.DaPsConf;
C 25 import com.jcdm.main.da.psConf.service.IDaPsConfService;
61c519 26 import com.jcdm.main.da.testDeviceInterfaceTemp.domain.DaTestDeviceInterfaceTemp;
A 27 import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService;
28 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
29 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
30 import com.jcdm.main.plcserver.util.TimeUtil;
31 import com.jcdm.main.restful.factoryMes.service.RestfulService;
32 import com.jcdm.main.restful.qingYan.doman.ChildVO;
33 import com.jcdm.main.restful.qingYan.doman.ParentVO;
34 import com.kangaroohy.milo.model.ReadWriteEntity;
35 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
36 import com.kangaroohy.milo.service.MiloService;
37 import lombok.extern.slf4j.Slf4j;
4162bc 38 import org.apache.commons.lang3.StringUtils;
61c519 39 import org.springframework.beans.factory.annotation.Value;
A 40 import org.springframework.stereotype.Component;
41 import org.springframework.web.bind.annotation.GetMapping;
42
43 import javax.websocket.Session;
44 import java.text.SimpleDateFormat;
4162bc 45 import java.time.LocalDate;
61c519 46 import java.util.*;
A 47 import java.util.concurrent.CompletableFuture;
48 import java.util.stream.Collectors;
49
50
51 @Slf4j
52 @Component
53 public class OPCUaSubscription implements SubscriptionCallback {
54
55     public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
56
57
58     Map<String, Session> map = WebSocketUsers.getUsers();
59     public static MiloService miloService;
60
61
62     public static IDaPassingStationCollectionService daPassingStationCollectionService;
63
64     public static IDaCollectionParamConfService collectionParamConfService;
65
66     public static IDaParamCollectionService daParamCollectionService;
67
68     public static IOmProductionOrdeInfoService omProductionOrdeInfoService;
69
70     public static IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService;
71
72     public static IDaCellDataService daCellDataService;
4162bc 73     public static IDaPsConfService daPsConfService;
61c519 74 /*    @Value("${orderLineUrl}")
A 75     private static String orderLineUrl;*/
76
77     public OPCUaSubscription(MiloService miloService,
78                              IDaPassingStationCollectionService daPassingStationCollectionService,
79                              IDaCollectionParamConfService collectionParamConfService,
80                              IDaParamCollectionService daParamCollectionService,
81                              IOmProductionOrdeInfoService omProductionOrdeInfoService,
82                              IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService,
4162bc 83                              IDaCellDataService daCellDataService,
C 84                              IDaPsConfService daPsConfService) {
61c519 85         OPCUaSubscription.miloService = miloService;
A 86         OPCUaSubscription.daPassingStationCollectionService = daPassingStationCollectionService;
87         OPCUaSubscription.collectionParamConfService = collectionParamConfService;
88         OPCUaSubscription.daParamCollectionService = daParamCollectionService;
89         OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService;
90         OPCUaSubscription.daTestDeviceInterfaceTempService = daTestDeviceInterfaceTempService;
91         OPCUaSubscription.daCellDataService = daCellDataService;
4162bc 92         OPCUaSubscription.daPsConfService = daPsConfService;
61c519 93     }
A 94
95
96     @Override
97     public void onSubscribe(String identifier, Object value) {
98         log.info("地址:"+identifier+"值:"+value);
99         try {
100             if(null != value && !Constants.ZERO.equals(value.toString())) {
101                 String[] nodes = identifier.split("[.]");
102                 String thoroughfare = nodes[0];//通道
103                 String device = nodes[1];//设备
104                 String tab = nodes[2];//标记
105                 String valueString = value.toString();//地址值
106
107                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
108                     subHandle(thoroughfare,device,tab,valueString);
109                 });
110
111             }
112         } catch (Exception e) {
113             log.error(e.getMessage());
114         }
115     }
116
117     public void subHandle(String thoroughfare,String device,String tab,String valueString){
118         try{
119             if (Constants.RECORD_CHECK_CODE.equals(tab)){//电芯校验
120                 if (Constants.ONE.equals(valueString)){
121                     Integer scanResult = 11;
122                     if (Constants.OP010.equals(device)){
123                         //OP010工位电芯条码校验||OP030工位电芯条码校验
22ae12 124                         //电芯批次校验
A 125 //                        Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".Scaner").getValue();
126 //                        Object value2 = miloService.readFromOpcUa(thoroughfare + "." + device + ".Batch").getValue();
127 //                        if (ObjectUtil.isNotNull(value1)&&ObjectUtil.isNotNull(value2)){
128 //                            String keyCode = value1.toString();
129 //                            String batch = value2.toString();
130 //                            log.info("读取到工位{}的Scaner数据:{} 校验批次为:{}",device,keyCode,batch);
131 //                            //仅校验长度是否合格
132 ////                                List<KeyCodeCheck> collect = keyCodeCheckService.list().stream().filter(x -> x.getKeyCode().contains(keyCode)).collect(Collectors.toList());
133 ////                                if (CollUtil.isNotEmpty(collect)){
134 ////                                    scanResult = 11;
135 ////                                }
136 //                            scanResult = batchVerification(keyCode,batch);
137 //                        }else {
138 //                            scanResult = 12;
139 //                        }
61c519 140                     }else if(Constants.OP030.equals(device)){
A 141                         Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".Scaner").getValue();//电芯码
142                         if (ObjectUtil.isNotNull(value1)){
8cc77a 143                             /*String cellCode = value1.toString();*/
61c519 144                             scanResult = 11;
8cc77a 145                           /*  //反馈电芯ocv检测结果,这里不用再进行检测,只要码没问题就可以了
61c519 146                             boolean b = OCVResultFeedBack(thoroughfare, device,cellCode);//对替换电芯校验
A 147                             //四个电芯的状态
148                             if (b){
149                                 scanResult = 11;
150                             }else {
151                                 scanResult = 12;
8cc77a 152                             }*/
61c519 153                         }else {
A 154                             scanResult = 12;
155                         }
156                     }
157                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ScanerResult1").value(scanResult).build());
158                     log.info("写入到工位{}的ScanerResult1数据:{}",device,scanResult);
159                 }
160             }else if (Constants.RECORD_SN.equals(tab)){//求下发模组码请9
161                 if (Constants.ONE.equals(valueString)){
162                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(1).build());//没有要生产的工单
163                 }
164             }else if (Constants.RECORD_DATA.equals(tab)){//出入站
165                 if (Constants.ONE.equals(valueString)){//入站 //1:告知MES托盘已到站,请求下发进站状态
166
167                     //OP020 电芯挡位校验
168                     if (Constants.OP020.equals(device)){
169                         Integer result = 11;
22ae12 170 //                        Object cellGearObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellGear").getValue();
A 171 //                        if (ObjectUtil.isNull(cellGearObjcet)){
172 //                            result = 11;//如果电芯挡位为空,不进行挡位校验
173 //                        }else{
174 //                            String cellGear = cellGearObjcet.toString();
175 //                            List<String> cellCodeList = readCellCodeList(thoroughfare, device);
176 //                            result = checkCellGear(thoroughfare, device,cellCodeList,cellGear);//校验电芯挡位和组别
177 //                            Constants.OLD_CELL_GEAR = cellGear;//挡位赋值
178 //                        }
61c519 179                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
A 180
181                     }else if (Constants.OP030.equals(device)){
182                         //反馈电芯ocv检测结果
183                         boolean b = OCVResultFeedBack(thoroughfare, device);//进站对4个电芯校验
184                         //四个电芯的状态
185                         if (b){
186                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
187                             log.info("写入到工位{}的RecordDataDone数据:{}",device,11);
188                         }else {
189                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
190                             log.info("写入到工位{}的RecordDataDone数据:{}",device,12);
191                         }
192                     } else if(Constants.OP100_1.equals(device) || Constants.OP100_2.equals(device)){
193                         //1、进站PLC给产品类型,MES读取产品类型
194                         Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//产品类型
195                         if (ObjectUtil.isNotNull(productTypeObjcet)){
196                             String productType = productTypeObjcet.toString();//产品类型
197                             String materialCode = Constants.materialMap.get(productType);
198                             //接收工单,保存到数据库,并且将工单传给PLC
199                             CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
200                                 receivingWorkOrders(thoroughfare, device,materialCode);
201                             });
202                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
203                             log.info("写入到工位{}的RecordDataDone数据:{}",device,11);
204                         }else{
205                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
206                         }
207
208                     }else if (Constants.OP150.contains(device)){//人工工位
209                         Object modulCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
210                         if (ObjectUtil.isNull(modulCodeObjcet)){
211                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
212                         }else{
213                             String productNum = modulCodeObjcet.toString();
214                             //将产品SN发送到前台
215                             productNum = "productNum,"+ productNum;
216                             WebSocketUsers.sendMessageToUserByText(map.get(device), productNum);
217                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
218                         }
219                     }else if (Constants.ModuleList.contains(device)){//有模组码的工位
220                         Object modulCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
221                         if (ObjectUtil.isNull(modulCodeObjcet)){
222                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(12).build());
223                         }else{
224                             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
225                         }
226                     }
227                     else {
228                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(11).build());
229                         log.info("写入到工位{}的RecordDataDone数据:{}",device,11);
230                     }
231                 }else if (Constants.TWO.equals(valueString)){//出站
232                     //分段010-065段
233                     if (Constants.OP010.equals(device)){
234                         //010工位无过站记录,只给放行信号
235                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(21).build());
236                         log.info("写入到工位{}的RecordDataDone数据:{}",device,21);
237                     }else if (Constants.OP020_OP090.contains(device)){
238                         Integer result = 21;
239                         //读取电芯码
240                         List<String> cellCodeList = readCellCodeList(thoroughfare, device);
241                         if(ObjectUtil.isNull(cellCodeList) || cellCodeList.size() != 4 ){
242                             result = 23;
243                         }else{
244                             String cellCode1 = cellCodeList.get(0);
245                             String cellCode2 = cellCodeList.get(1);
246                             String cellCode3 = cellCodeList.get(2);
247                             String cellCode4 = cellCodeList.get(3);
248                             if ((!cellCode1.isEmpty() && cellCode2.isEmpty()) || (cellCode1.isEmpty() && !cellCode2.isEmpty())
249                             || (!cellCode3.isEmpty() && cellCode4.isEmpty()) || (!cellCode4.isEmpty() && cellCode3.isEmpty())) {
250                                 result = 23;
251                                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
252                                 return;
253                             }
254
ba3b88 255                             //result = savePassingStation(thoroughfare, device,cellCodeList);//保存过站
61c519 256                             if(result == 21) {
A 257                                 if(Constants.OP020.contains(device)){
258                                     if(!cellCode1.isEmpty()){
259                                         daCellDataService.deleteDaCellDataByGbCellCode(cellCode1);
260                                     }
261                                     if(!cellCode2.isEmpty()){
262                                         daCellDataService.deleteDaCellDataByGbCellCode(cellCode2);
263                                     }
264                                     if(!cellCode3.isEmpty()){
265                                         daCellDataService.deleteDaCellDataByGbCellCode(cellCode3);
266                                     }
267                                     if(!cellCode4.isEmpty()){
268                                         daCellDataService.deleteDaCellDataByGbCellCode(cellCode4);
269                                     }
270                                 }else if(Constants.OP030.contains(device)){
271                                     if(!cellCode1.isEmpty()){
272                                         daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode1);
273                                     }
274                                     if(!cellCode2.isEmpty()){
275                                         daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode2);
276                                     }
277                                     if(!cellCode3.isEmpty()){
278                                         daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode3);
279                                     }
280                                     if(!cellCode4.isEmpty()) {
281                                         daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode4);
282                                     }
283                                 }
284                                 result = saveParamCollection(device,cellCodeList);//保存参数,发送工厂MES
285                             }
286
287                         }
288
289                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
290                         log.info("写入到工位{}的RecordDataDone数据:{}",device,result);
291                     } else if (Constants.OP100_OP150.contains(device)){//人工工位
292                         WebSocketUsers.sendMessageToUserByText(map.get(device), "END");
293                     } else {
294                         Integer result = 21;
295                         //Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//产品类型
296                         Object modulCodeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
297                         if (ObjectUtil.isNull(modulCodeObjcet)){
298                             result = 23;
299                         }else{
300                             String moduleCode = modulCodeObjcet.toString();
301                             Object stationStatusObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus").getValue();//站状态地址
302                             if (ObjectUtil.isNotNull(stationStatusObjcet)){
303                                 String stationStatus = stationStatusObjcet.toString();
ba3b88 304                                 //result = savePassingStation(thoroughfare, device,moduleCode,stationStatus);//保存过站
61c519 305                                 if(result == 21) {
A 306                                     result = saveParamCollection(device,moduleCode,stationStatus);//保存参数,发送工厂MES
307                                 }
308                             }else{
309                                 result = 23;
310                                 log.info("读取到工位{}StationStatus数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
311                             }
312
313                         }
314                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
315                         log.info("写入到工位{}的RecordDataDone数据:{}",device,result);
316                     }
317                 }
318             }
319         }catch (Exception e) {
320             log.error(e.getMessage());
321         }
322     }
323
324     public synchronized void receivingWorkOrders(String thoroughfare ,String device ,String materialCode)
325     {
326         try {
8cc77a 327             //先查询表中是否有剩余工单
C 328             List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>()
329                     .eq(OmProductionOrdeInfo::getOrderStatus, Constants.ONE)
330                     .eq(OmProductionOrdeInfo::getStationCode,device)//工位
331                     .eq(OmProductionOrdeInfo::getProductCode,materialCode));//产品类型
332             if (CollUtil.isNotEmpty(orderList)){
333                 Long id = orderList.get(0).getId();
334                 String productNum = orderList.get(0).getProductNum();//模组码
335                 String orderNum = orderList.get(0).getWorkOrderNo();
61c519 336
A 337
338                 //下发产品模组码
339                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ModuleCode").value(productNum).build());
340                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build());
341
342                 //将产品SN发送到前台
343                 productNum = "productNum,"+ productNum;
344                 WebSocketUsers.sendMessageToUserByText(map.get(device), productNum);
8cc77a 345             }else {
C 346                 // 查询最新的工单信息
347                 OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder();
61c519 348
8cc77a 349                 log.info("请求工厂MES工单:入参device{},materialCode:{}", device, materialCode);
C 350                 String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "M2OP100", materialCode);
351                 log.info("请求工厂MES工单:出参pack:{}", orderJsonString);
352                 JSONObject jsonObject = new JSONObject(orderJsonString);
353                 // 从JSONObject中获取data对象
354                 JSONObject dataObject = jsonObject.getJSONObject("data");
355                 String code = jsonObject.getStr("code");
356                 // 判断接单是否成功
357                 if (code.equals("success")) {
358
359                     OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
360                     omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum"));
361                     omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum"));
362                     omProductionOrdeInfo.setStationCode(device);
363                     omProductionOrdeInfo.setProductCode(dataObject.getStr("materialCode"));
364                     omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity")));
365                     omProductionOrdeInfo.setOnlineCompletionMark("0");
366                     omProductionOrdeInfo.setSfResult("0");
367                     omProductionOrdeInfo.setProductModel(dataObject.getStr("model"));
368                     omProductionOrdeInfo.setCreateTime(new Date());
369                     omProductionOrdeInfo.setCreateUser("工厂MES");
370                     omProductionOrdeInfoService.save(omProductionOrdeInfo);
371
372                     String productNum = dataObject.getStr("productNum");
373                     String orderNum = dataObject.getStr("productionOrderNum");
374                     //下发产品模组码
375                     miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ModuleCode").value(productNum).build());
376                     miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build());
377
378                     //将产品SN发送到前台
379                     productNum = "productNum," + productNum;
380                     WebSocketUsers.sendMessageToUserByText(map.get(device), productNum);
381
382                 }
61c519 383             }
A 384         } catch (Exception e) {
385             throw new RuntimeException(e);
386         }
387     }
388
389     /**
390      * 读取电芯码
391      * @param thoroughfare 通道
392      * @param device 工位
393      * @return list
394      * @throws Exception e
395      */
396     private static List<String> readCellCodeList(String thoroughfare, String device){
397         List<String> cellCodeList = new ArrayList<>();
398         Map map = new HashMap();
399         //电芯码地址
400         List<String> readList = new ArrayList<>();
401         readList.add(thoroughfare + "." + device +".CellCode_1");
402         readList.add(thoroughfare + "." + device +".CellCode_2");
403         readList.add(thoroughfare + "." + device +".CellCode_3");
404         readList.add(thoroughfare + "." + device +".CellCode_4");
405         try {
406             List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(readList);//电芯码
407             for (ReadWriteEntity readWriteEntity : readWriteEntityList) {
408                 if (ObjectUtil.isNotNull(readWriteEntity.getValue()) && !readWriteEntity.getValue().toString().trim().isEmpty()){
409                     cellCodeList.add(readWriteEntity.getValue().toString());//封装电芯码
410                 }else{
411                     cellCodeList.add("");//封装电芯码
412                 }
413             }
414
415         } catch (Exception e) {
416             throw new RuntimeException(e);
417         }
418         return cellCodeList;
419     }
420
421
422     /**
423      * 保存过站数据
424      * @param thoroughfare 通道
425      * @param device 工位
426      * @param moduleCode 模组号
427      * @param stationStatus 站状态
428      * @return list
429      * @throws Exception e
430      */
431     private static Integer savePassingStation(String thoroughfare, String device,String moduleCode,String stationStatus){
432         Integer result = 21;
433
434         try {
435             //读进站时间
436             Date startTime = new Date();
437             ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间
438             if (ObjectUtil.isNotNull(startTimeRead.getValue())){
439                 startTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(startTimeRead.getValue().toString())));
440             }else{
441                 result = 23;
442                 log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
443                 return result;
444             }
445
446             DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
447             passingStationCollection.setSfcCode(moduleCode);//电芯码
448             passingStationCollection.setLocationCode(device);//工位
449             passingStationCollection.setInboundTime(startTime);//进站时间
450             passingStationCollection.setOutboundTime(new Date());//出站时间
451             passingStationCollection.setOutRsSign(stationStatus);//站状态值
452             passingStationCollection.setCollectionTime(new Date());//采集时间
453             daPassingStationCollectionService.save(passingStationCollection);
454
455         } catch (Exception e) {
456             throw new RuntimeException(e);
457         }
458
459         return result;
460     }
461
462     /**
463      * 保存过站数据
464      * @param thoroughfare 通道
465      * @param device 工位
466      * @param cellCodeList 电芯码集合
467      * @return list
468      * @throws Exception e
469      */
470     private static Integer savePassingStation(String thoroughfare, String device,List<String> cellCodeList){
471         Integer result = 21;
472
473         try {
474             //读进站时间
475             Date startTime = new Date();
476             ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间
477             if (ObjectUtil.isNotNull(startTimeRead.getValue())){
478                 startTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(startTimeRead.getValue().toString())));
479             }else{
480                 result = 23;
481                 log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
482                 return result;
483             }
484
485             //读工站状态
486             String stationStatus = Constants.PASS;
487             ReadWriteEntity stationStatusRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus");//站状态地址
488             if (ObjectUtil.isNotNull(stationStatusRead.getValue())){
489                 String string = stationStatusRead.getValue().toString();
490                 if (Constants.TWO.equals(string)){
491                     stationStatus = Constants.UN_PASS;
492                 }
493             }else{
494                 result = 23;
495                 log.info("读取到工位{}StationStatus数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
496                 return result;
497             }
498
499             List<DaPassingStationCollection> passingList = new ArrayList<>();
500             for (String cellCode : cellCodeList) {
501                 DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
502                 if (ObjectUtil.isNotNull(cellCode) && !cellCode.isEmpty()){
503                     passingStationCollection.setSfcCode(cellCode);//电芯码
504                     passingStationCollection.setLocationCode(device);//工位
505                     passingStationCollection.setInboundTime(startTime);//进站时间
506                     passingStationCollection.setOutboundTime(new Date());//出站时间
507                     passingStationCollection.setOutRsSign(stationStatus);//站状态值
508                     passingStationCollection.setCollectionTime(new Date());//采集时间
509                     passingList.add(passingStationCollection);
510                 }
511             }
512
513             if (CollUtil.isNotEmpty(passingList)){
514                 daPassingStationCollectionService.insertBatch(passingList);//存储过站采集数据
515             }
516
517         } catch (Exception e) {
518             throw new RuntimeException(e);
519         }
520
521         return result;
522     }
523
524
525     /**
526      * 保存参数数据和发送工厂MES
527      * @param device 工位
528      * @param moduleCode 模组号
529      * @param stationStatus 站状态
530      * @return list
531      * @throws Exception e
532      */
533     private static Integer saveParamCollection(String device,String moduleCode,String stationStatus){
534         Integer result = 21;//返回结果
535         String sendMes = "";
536
537         try {
538             //查询参数配置表
539             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
540                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
541                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
542             );
543             if (CollUtil.isNotEmpty(list)){
544
545                 List<String> collect = list.stream()
546                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
547                 List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(collect);
548
549                 List<DaParamCollection> collectionList = new ArrayList<>();
550                 List<ChildVO> mesList = new ArrayList<>();
551                 for (int i = 0; i < readWriteEntityList.size(); i++) {
552                     DaParamCollection daParamCollection = new DaParamCollection();
553                     daParamCollection.setSfcCode(moduleCode);//模组码
554                     daParamCollection.setParamCode(list.get(i).getCollectParameterId());//参数编码
555                     daParamCollection.setParamName(list.get(i).getCollectParameterName());//参数名称
556                     String paramValue = "";
557                     if (ObjectUtil.isNotNull(readWriteEntityList.get(i).getValue())){
558                         paramValue = readWriteEntityList.get(i).getValue().toString();//参数值
559                         if("DATE".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){
560                             paramValue = format.parse(TimeUtil.test(TimeUtil.stringProcessing(paramValue))).toString();
561                         }else if("MODEL".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){
562                             paramValue = Constants.materialMap.get(paramValue);
563                         }
564                     }
565                     daParamCollection.setParamValue(paramValue);//参数值
566                     daParamCollection.setLocationCode(device);//工位
567                     daParamCollection.setCollectionTime(new Date());//采集时间
568                     collectionList.add(daParamCollection);//封装参数采集list
569
570                     //发送给工厂mes参数封装
571                     ChildVO childVO = new ChildVO();
572                     childVO.setItemCode(list.get(i).getCollectParameterId());//参数编码
573                     childVO.setItemType(list.get(i).getItemType());
574                     childVO.setItemValue(paramValue);//参数值
575                     childVO.setItemText(list.get(i).getCollectParameterName());
576                     childVO.setCheckResult("1");
577                     childVO.setCheckTime(format.format(new Date()));
578                     mesList.add(childVO);
579                 }
580
581                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
582                     //插入参数采集表
583                     daParamCollectionService.insertBatch(collectionList);
584
585                     //如果220工位,进行报工,因为上层系统只支持6位,所有报工工位修改为M2P220
586                     if(Constants.OP220.equals(device)) {
587                         getWorkReportResultFeedback(moduleCode, "M2P220", format.format(new Date()));
588                     }
589
590                     //上传到工厂mes
591                     ParentVO parentVO = new ParentVO();
592                     parentVO.setStationCode(device);//工位
593                     parentVO.setSiteCode("3983");
594
595                     parentVO.setRecordId(UUID.randomUUID().toString());
596                     if("2".equals(stationStatus)){//工站状态
597                         parentVO.setTotalResult("0");
598                     }else {
599                         parentVO.setTotalResult("1");
600                     }
601                     parentVO.setProductNum(moduleCode);
602
603                     //添加基础数据
604                     List<ChildVO> basicList = getCollectParamBasicData(device,moduleCode);
605                     mesList.addAll(basicList);
606
607                     parentVO.setCheckList(mesList);
608
609                     log.info("执行工厂MES方法start,工位号{} 传入数据:{}",device ,parentVO);
610                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
611                     log.info("执行工厂MES方法end,工位号{} 返回数据:{}",device,execute.body());
612
613                 });
614             }
615         }catch (Exception e) {
616             throw new RuntimeException(e);
617         }
618         return result;
619     }
620
621     /**
622      * 保存参数数据和发送工厂MES
623      * @param device 工位
624      * @param cellCodeList 电芯码集合
625      * @return list
626      * @throws Exception e
627      */
628     private static Integer saveParamCollection(String device,List<String> cellCodeList){
629         Integer result = 21;//返回结果
630         List<ChildVO> mesChildList1 = new ArrayList<>();//封装给工厂MES发送的childlist1
631         List<ChildVO> mesChildList2 = new ArrayList<>();//封装给工厂MES发送的childlist2
632         List<ChildVO> mesChildList3 = new ArrayList<>();//封装给工厂MES发送的childlist3
633         List<ChildVO> mesChildList4 = new ArrayList<>();//封装给工厂MES发送的childlist4
634         List<ChildVO> mesChildList0 = new ArrayList<>();//封装给工厂MES发送的childlist4
635         try {
636             //查询参数配置表
637             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
638                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
639                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
640                     );//类型
641             if (CollUtil.isNotEmpty(list)) {
642                 List<DaParamCollection> saveParamList = new ArrayList<>();//封装参数采集list
643                 List<DaCollectionParamConf> confColl1 = list.stream().filter(x -> Constants.INT_ONE.equals(x.getKeyNum())).collect(Collectors.toList());
644                 List<DaCollectionParamConf> confColl2 = list.stream().filter(x -> Constants.INT_TWO.equals(x.getKeyNum())).collect(Collectors.toList());
645                 List<DaCollectionParamConf> confColl3 = list.stream().filter(x -> Constants.INT_THREE.equals(x.getKeyNum())).collect(Collectors.toList());
646                 List<DaCollectionParamConf> confColl4 = list.stream().filter(x -> Constants.INT_FOUR.equals(x.getKeyNum())).collect(Collectors.toList());
647                 List<DaCollectionParamConf> confColl0 = list.stream().filter(x -> Constants.INT_ZERO.equals(x.getKeyNum())).collect(Collectors.toList());
648
649                 List<String> collect1 = confColl1.stream()
650                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
651                 List<ReadWriteEntity> paramCollectionList1 = miloService.readFromOpcUa(collect1);//电芯1 参数值
652
653                 List<String> collect2 = confColl2.stream()
654                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
655                 List<ReadWriteEntity> paramCollectionList2 = miloService.readFromOpcUa(collect2);//电芯2 参数值
656
657                 List<String> collect3 = confColl3.stream()
658                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
659                 List<ReadWriteEntity> paramCollectionList3 = miloService.readFromOpcUa(collect3);//电芯3 参数值
660
661                 List<String> collect4 = confColl4.stream()
662                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
663                 List<ReadWriteEntity> paramCollectionList4 = miloService.readFromOpcUa(collect4);//电芯4 参数值
664
665                 List<String> collect0 = confColl0.stream()
666                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
667                 List<ReadWriteEntity> paramCollectionList0 = miloService.readFromOpcUa(collect0);//电芯 参数值
668
669                 //第一个电芯的数据
670                 if (CollUtil.isNotEmpty(paramCollectionList1) && !cellCodeList.get(0).isEmpty()) {
671                     for (int i = 0; i < paramCollectionList1.size(); i++) {
672                         DaParamCollection daParamCollection = new DaParamCollection();
673                         daParamCollection.setSfcCode(cellCodeList.get(0));//电芯码
674                         daParamCollection.setParamCode(confColl1.get(i).getCollectParameterId());//参数编码
675                         daParamCollection.setParamName(confColl1.get(i).getCollectParameterName());//参数名称
676                         String paramValue = "";
677                         if (ObjectUtil.isNotNull(paramCollectionList1.get(i).getValue())) {
678                             paramValue = paramCollectionList1.get(i).getValue().toString();//参数值
679                         }
680                         daParamCollection.setParamValue(paramValue);//参数值
681                         daParamCollection.setLocationCode(device);//工位
682                         daParamCollection.setCollectionTime(new Date());//采集时间
683                         saveParamList.add(daParamCollection);//封装参数采集list
684
685                         //发送给工厂mes参数封装
686                         ChildVO childVO = new ChildVO();
687                         childVO.setItemCode(confColl1.get(i).getCollectParameterId());//参数
688                         childVO.setItemType(confColl1.get(i).getItemType());
689                         childVO.setItemValue(paramValue);//参数值
690                         childVO.setItemText(confColl1.get(i).getCollectParameterName());
691                         childVO.setCheckResult("1");
692                         childVO.setCheckTime(format.format(new Date()));
693                         mesChildList1.add(childVO);
694                     }
695
696                 }
697                 if (CollUtil.isNotEmpty(paramCollectionList2) && !cellCodeList.get(1).isEmpty()) {
698
699                     for (int i = 0; i < paramCollectionList2.size(); i++) {
700                         DaParamCollection daParamCollection = new DaParamCollection();
701                         daParamCollection.setSfcCode(cellCodeList.get(1));//电芯码
702                         daParamCollection.setParamCode(confColl2.get(i).getCollectParameterId());//参数编码
703                         daParamCollection.setParamName(confColl2.get(i).getCollectParameterName());//参数名称
704                         String paramValue = "";
705                         if (ObjectUtil.isNotNull(paramCollectionList2.get(i).getValue())) {
706                             paramValue = paramCollectionList2.get(i).getValue().toString();//参数值
707                         }
708                         daParamCollection.setParamValue(paramValue);//参数值
709                         daParamCollection.setLocationCode(device);//工位
710                         daParamCollection.setCollectionTime(new Date());//采集时间
711                         saveParamList.add(daParamCollection);//封装参数采集list
712
713                         //发送给工厂mes参数封装
714                         ChildVO childVO = new ChildVO();
715                         childVO.setItemCode(confColl2.get(i).getCollectParameterId());//参数
716                         childVO.setItemType(confColl2.get(i).getItemType());
717                         childVO.setItemValue(paramValue);//参数值
718                         childVO.setItemText(confColl2.get(i).getCollectParameterName());
719                         childVO.setCheckResult("1");
720                         childVO.setCheckTime(format.format(new Date()));
721                         mesChildList2.add(childVO);
722                     }
723                 }
724                 if (CollUtil.isNotEmpty(paramCollectionList3) && !cellCodeList.get(2).isEmpty()) {
725                     for (int i = 0; i < paramCollectionList3.size(); i++) {
726                         DaParamCollection daParamCollection = new DaParamCollection();
727                         daParamCollection.setSfcCode(cellCodeList.get(2));//电芯码
728                         daParamCollection.setParamCode(confColl3.get(i).getCollectParameterId());//参数编码
729                         daParamCollection.setParamName(confColl3.get(i).getCollectParameterName());//参数名称
730                         String paramValue = "";
731                         if (ObjectUtil.isNotNull(paramCollectionList3.get(i).getValue())) {
732                             paramValue = paramCollectionList3.get(i).getValue().toString();//参数值
733                         }
734                         daParamCollection.setParamValue(paramValue);//参数值
735                         daParamCollection.setLocationCode(device);//工位
736                         daParamCollection.setCollectionTime(new Date());//采集时间
737                         saveParamList.add(daParamCollection);//封装参数采集list
738
739                         //发送给工厂mes参数封装
740                         ChildVO childVO = new ChildVO();
741                         childVO.setItemCode(confColl3.get(i).getCollectParameterId());//参数
742                         childVO.setItemType(confColl3.get(i).getItemType());
743                         childVO.setItemValue(paramValue);//参数值
744                         childVO.setItemText(confColl3.get(i).getCollectParameterName());
745                         childVO.setCheckResult("1");
746                         childVO.setCheckTime(format.format(new Date()));
747                         mesChildList3.add(childVO);
748                     }
749                 }
750                 if (CollUtil.isNotEmpty(paramCollectionList4)&& !cellCodeList.get(3).isEmpty()) {
751                     for (int i = 0; i < paramCollectionList4.size(); i++) {
752                         DaParamCollection daParamCollection = new DaParamCollection();
753                         daParamCollection.setSfcCode(cellCodeList.get(3));//电芯码
754                         daParamCollection.setParamCode(confColl4.get(i).getCollectParameterId());//参数编码
755                         daParamCollection.setParamName(confColl4.get(i).getCollectParameterName());//参数名称
756                         String paramValue = "";
757                         if (ObjectUtil.isNotNull(paramCollectionList4.get(i).getValue())) {
758                             paramValue = paramCollectionList4.get(i).getValue().toString();//参数值
759                         }
760                         daParamCollection.setParamValue(paramValue);//参数值
761                         daParamCollection.setLocationCode(device);//工位
762                         daParamCollection.setCollectionTime(new Date());//采集时间
763                         saveParamList.add(daParamCollection);//封装参数采集list
764
765                         //发送给工厂mes参数封装
766                         ChildVO childVO = new ChildVO();
767                         childVO.setItemCode(confColl4.get(i).getCollectParameterId());//参数
768                         childVO.setItemType(confColl4.get(i).getItemType());
769                         childVO.setItemValue(paramValue);//参数值
770                         childVO.setItemText(confColl4.get(i).getCollectParameterName());
771                         childVO.setCheckResult("1");
772                         childVO.setCheckTime(format.format(new Date()));
773                         mesChildList4.add(childVO);
774                     }
775                 }
776
777                 //公共参数
778                 if (CollUtil.isNotEmpty(paramCollectionList0)) {
779                     for (int i = 0; i < cellCodeList.size(); i++) {//循环4个电芯
780                         if(!cellCodeList.get(i).isEmpty()){
781                             for (int j = 0; j < paramCollectionList0.size(); j++) {
782                                 DaParamCollection daParamCollection = new DaParamCollection();
783                                 daParamCollection.setSfcCode(cellCodeList.get(i));//电芯码
784                                 daParamCollection.setParamCode(confColl0.get(j).getCollectParameterId());//参数编码
785                                 daParamCollection.setParamName(confColl0.get(j).getCollectParameterName());//参数名称
786                                 String paramValue = "";
787                                 if (ObjectUtil.isNotNull(paramCollectionList0.get(j).getValue())) {
788                                     paramValue = paramCollectionList0.get(j).getValue().toString();//参数值
789                                     if("DATE".equals(confColl0.get(j).getCollectParameterType()) && !paramValue.isEmpty()){
790                                         paramValue = TimeUtil.test(TimeUtil.stringProcessing(paramValue));
791                                     }
792                                 }
793                                 daParamCollection.setParamValue(paramValue);//参数值
794                                 daParamCollection.setLocationCode(device);//工位
795                                 daParamCollection.setCollectionTime(new Date());//采集时间
796                                 saveParamList.add(daParamCollection);
797
798                                 //发送给工厂mes参数封装
799                                 ChildVO childVO = new ChildVO();
800                                 childVO.setItemCode(confColl0.get(j).getCollectParameterId());//参数
801                                 childVO.setItemType(confColl0.get(j).getItemType());
802                                 childVO.setItemValue(paramValue);//参数值
803                                 childVO.setItemText(confColl0.get(j).getCollectParameterName());
804                                 childVO.setCheckResult("1");
805                                 childVO.setCheckTime(format.format(new Date()));
806                                 mesChildList0.add(childVO);
807                             }
808                         }
809
810                         //mesList.get(i).addAll(mesChildList0);
811
812                     }
813
814                 }
815
816                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
817                     //插入参数采集表
818                     daParamCollectionService.insertBatch(saveParamList);
819                     //上传到工厂mes
820                     ParentVO parentVO = new ParentVO();
821                     parentVO.setStationCode(device);//工位
822                     parentVO.setSiteCode("3983");
823                     for (int i = 0; i < cellCodeList.size(); i++) {//循环4个电芯
824                         if(!cellCodeList.get(i).isEmpty()){
825                             parentVO.setRecordId(UUID.randomUUID().toString());
826                             parentVO.setTotalResult("1");
827                             parentVO.setProductNum(cellCodeList.get(i));//电芯码
828                             //封装给工厂MES发送的childlist4
829                             List<ChildVO> mesChildList = new ArrayList<>(mesChildList0);
830                             switch (i) {
831                                 case 0 :
832                                     mesChildList.addAll(mesChildList1);
833                                     break;
834                                 case 1 :
835                                     mesChildList.addAll(mesChildList2);
836                                     break;
837                                 case 2 :
838                                     mesChildList.addAll(mesChildList3);
839                                     break;
840                                 case 3 :
841                                     mesChildList.addAll(mesChildList4);
842                                     break;
843
844                             }
845
846                             //添加基础数据
847                             List<ChildVO> basicList = getCollectParamBasicData(device,cellCodeList.get(i));
848                             mesChildList.addAll(basicList);
849
850                             parentVO.setCheckList(mesChildList);//参数
851                             //CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
852                             log.info("执行工厂MES方法start,传入数据:{}",parentVO);
853                             HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
854                             log.info("执行工厂MES方法end,返回数据:{}",execute.body());
855                         }
856                     }
857                 });
858             }
859         }catch (Exception e) {
860             log.error(e.getMessage());
861             throw new RuntimeException(e);
862         }
863         return result;
864     }
865
866     /**
867      * OP020校验电芯挡位
868      * @param thoroughfare
869      * @param device
870      * @throws Exception
871      */
872     private Integer checkCellGear(String thoroughfare, String device,List<String> cellCodeList,String cellGear) throws Exception {
873         Integer result = 11;
be28fb 874         String cellSerial = "";
61c519 875         for(int i = 0; i < cellCodeList.size(); i ++){
A 876             Integer cellStatus = 1;
877             String cellCode = cellCodeList.get(i);
878             if(!cellCode.isEmpty()){
879                 List<DaCellData> list = daCellDataService.list(new LambdaQueryWrapper<DaCellData>()
880                         .eq(DaCellData::getGbCellCode,cellCode));
881                 if(CollUtil.isNotEmpty(list)){
882                     DaCellData daCellData = list.get(0);
883                     String cellValue = daCellData.getCellValue();//数据库中电芯挡位
be28fb 884                     cellSerial = daCellData.getCellSerial();//数据库中电芯组别
61c519 885                     if(!cellValue.isEmpty() && cellValue.equals(cellGear)){
A 886                         cellStatus = 1;
887                     }else {
888                         cellStatus = 2;
4ab63d 889                         result = 16;//挡位校验不合格
be28fb 890                         log.info("电芯挡位校验不合格:电芯码为{},PLC设置挡位为{},工厂MES下发挡位为:{}",cellCode,cellGear,cellValue);
61c519 891                     }
be28fb 892                 }else {
61c519 893                     cellStatus = 2;
be28fb 894                     result = 16;//查不到要校验的挡位
C 895                     log.info("电芯挡位校验不合格:电芯码为{},PLC设置挡位为{},工厂MES下发挡位为空,查询不到该数据",cellCode,cellGear);
896                 }
897                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".Cell_Status_"+(i+1)).value(cellStatus).build());
61c519 898             }
A 899         }
be28fb 900
C 901         //当电芯挡位发生变化时,并且老的挡位不为空,删除当前电芯批次
902         if(!Constants.OLD_CELL_GEAR.isEmpty() && !cellGear.equals(Constants.OLD_CELL_GEAR)){
903             if(!cellSerial.isEmpty()){
904                 daCellDataService.deleteDaCellDataByCellSerial(cellSerial);
905             }
906             log.info("电芯挡位发生改变,老的挡位为:{},新的挡位为:{},批次号为{}",Constants.OLD_CELL_GEAR,cellGear,cellSerial);
907         }
908
61c519 909         return result;
A 910     }
911
912     /**
913      * 030工位返回ocv测试结果
914      * @param thoroughfare
915      * @param device
916      * @param cellCode
917      * @throws Exception
918      */
919     private boolean OCVResultFeedBack(String thoroughfare, String device,String cellCode) throws Exception {
920         boolean flag = true;
921         List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
922                 .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode)
923                 .orderByDesc(DaTestDeviceInterfaceTemp::getCreateTime)
924         );
925         if (CollUtil.isNotEmpty(list)){
926             DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(0);
927             if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
928                 flag = true;
929             }else {
930                 flag = false;
931             }
932             //daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
933         }else {
934             flag = false;
935             log.info("读取到工位{},测试设备返回的数据查询不到,电芯码为:{}",device,cellCode);
936         }
937         return flag;
938     }
939     /**
940      * 030工位返回ocv测试结果
941      * @param thoroughfare
942      * @param device
943      * @throws Exception
944      */
945     private boolean OCVResultFeedBack(String thoroughfare, String device) throws Exception {
946         boolean flag = true;
947         Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_1").getValue();
948         if (ObjectUtil.isNotNull(value1)){
949             String cellCode = value1.toString();
950             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
951                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode)
952                     .orderByDesc(DaTestDeviceInterfaceTemp::getCreateTime)
953             );
954             if (CollUtil.isNotEmpty(list)){
955                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(0);
956                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
957                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(1).build());
958                 }else {
959                     flag = false;
960                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(2).build());
961                 }
962                 //daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
963             }else {
964                 flag = false;
965                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(5).build());
966                 log.info("读取到工位{},OP020工位没有给测试结果",device);
967             }
968         }else {
969             flag = false;
970             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(5).build());
971             log.info("读取到工位{},PLC没有给电芯码",device);
972         }
973         Object value2 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_2").getValue();
974         if (ObjectUtil.isNotNull(value2)){
975             String cellCode = value2.toString();
976             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
977                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode)
978                     .orderByDesc(DaTestDeviceInterfaceTemp::getCreateTime)
979             );
980             if (CollUtil.isNotEmpty(list)){
981                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(0);
982                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
983                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(1).build());
984                 }else {
985                     flag = false;
986                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(2).build());
987                 }
988                 //daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
989             }else {
990                 flag = false;
991                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(5).build());
992                 log.info("读取到工位{},OP020工位没有给测试结果",device);
993             }
994         }else {
995             flag = false;
996             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(5).build());
997             log.info("读取到工位{},PLC没有给电芯码",device);
998         }
999
1000         Object value3 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_3").getValue();
1001         if (ObjectUtil.isNotNull(value3)){
1002             String cellCode = value3.toString();
1003             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
1004                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode)
1005                     .orderByDesc(DaTestDeviceInterfaceTemp::getCreateTime)
1006             );
1007             if (CollUtil.isNotEmpty(list)){
1008                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(0);
1009                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
1010                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(1).build());
1011                 }else {
1012                     flag = false;
1013                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(2).build());
1014                 }
1015                 //daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
1016             }else {
1017                 flag = false;
1018                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(5).build());
1019                 log.info("读取到工位{},OP020工位没有给测试结果",device);
1020             }
1021         }else {
1022             flag = false;
1023             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(5).build());
1024             log.info("读取到工位{},PLC没有给电芯码",device);
1025         }
1026
1027         Object value4 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_4").getValue();
1028         if (ObjectUtil.isNotNull(value4)){
1029             String cellCode = value4.toString();
1030             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
1031                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode)
1032                     .orderByDesc(DaTestDeviceInterfaceTemp::getCreateTime)
1033             );
1034             if (CollUtil.isNotEmpty(list)){
1035                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(0);
1036                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
1037                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(1).build());
1038                 }else {
1039                     flag = false;
1040                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(2).build());
1041                 }
1042                 //daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
1043             }else {
1044                 flag = false;
1045                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(5).build());
1046                 log.info("读取到工位{},OP020工位没有给测试结果",device);
1047             }
1048         }else {
1049             flag = false;
1050             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(5).build());
1051             log.info("读取到工位{},PLC没有给电芯码",device);
1052         }
1053
1054         return flag;
1055     }
1056
1057     /**
1058      * AMES报工结果回传
1059      * @param productNum
1060      * @param stationCode
1061      * @param confirmTime
1062      * @return
1063      */
1064     //{"code":"success","data":{"productNum":"LCV123456P0600036","stationCode":"1HZ01","resultCode":"S","resultText":"报工成功"},"message":"API调用成功"}
1065     public static String getWorkReportResultFeedback(String productNum,String stationCode,String confirmTime)
1066     {
1067         String result = "";
73d19a 1068         String url = Constants.FACTORY_EMS_UAT_GET_RUL + "workReportResultFeedback?siteCode="+Constants.FACTORY_EMS_SITE_CODE+"&stationCode="+stationCode+"&productNum="+productNum+"&confirmTime="+confirmTime;
61c519 1069         try {
73d19a 1070             log.info("执行工厂MES报工方法start,序列号{}工位号{}url{}",productNum,stationCode ,url);
61c519 1071             HttpResponse response = HttpRequest.get(url).execute();
73d19a 1072             //HttpRequest httpRequest = HttpRequest.get(url);
61c519 1073             result =  response.body();
73d19a 1074             log.info("执行工厂MES报工方法第一次end,序列号{}工位号{}返回数据{}",productNum,stationCode ,result);
61c519 1075         }catch (Exception e){
A 1076             throw new RuntimeException(e);
1077         }finally {
73d19a 1078             if(result.isEmpty()){
C 1079                 HttpResponse response = HttpRequest.get(url).execute();
1080                 result =  response.body();
1081                 log.info("执行工厂MES报工方法第二次end,序列号{}工位号{}返回数据{}",productNum,stationCode ,result);
1082             }
61c519 1083             return result;
A 1084         }
1085     }
1086
1087
1088     /**
1089      * 获取采集参数基础数据
1090      * @param stationCode
1091      * @param sfcCode
1092      * @return list
1093      */
1094     public static List<ChildVO> getCollectParamBasicData(String stationCode,String sfcCode) {
1095         List<ChildVO> basicList = new ArrayList<>();
1096         List<DaParamCollection> collectionList = new ArrayList<>();
1097         try {
1098             //查询参数配置表
1099             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
1100                     .eq(DaCollectionParamConf::getProcessesCode, stationCode)//工位
1101                     .eq(DaCollectionParamConf::getCollectParameterType, "BASIC")//采集参数类型
1102             );
1103             if (CollUtil.isNotEmpty(list)){
1104                 for(DaCollectionParamConf conf:list){
4162bc 1105                     //1P1S生成
1ad632 1106                     if("1P1S".equals(conf.getCollectParameterId())){
4162bc 1107                         String result = get1P1S(sfcCode);
C 1108                         conf.setParamCentral(result);
1109                     }
61c519 1110                     ChildVO childVO = new ChildVO();
A 1111                     childVO.setItemCode(conf.getCollectParameterId());//参数
1112                     childVO.setItemType(conf.getItemType());
1113                     childVO.setItemValue(conf.getParamCentral());//参数值
1114                     childVO.setItemText(conf.getCollectParameterName());
1115                     childVO.setCheckResult("1");
1116                     childVO.setCheckTime(format.format(new Date()));
1117                     basicList.add(childVO);
1118
1119                     DaParamCollection daParamCollection = new DaParamCollection();
1120                     daParamCollection.setSfcCode(sfcCode);//模组码
1121                     daParamCollection.setParamCode(conf.getCollectParameterId());//参数编码
1122                     daParamCollection.setParamName(conf.getCollectParameterName());//参数名称
1123
1124                     daParamCollection.setParamValue(conf.getParamCentral());//参数值
1125                     daParamCollection.setLocationCode(stationCode);//工位
1126                     daParamCollection.setCollectionTime(new Date());//采集时间
1127                     collectionList.add(daParamCollection);//封装参数采集list
1128                 }
1129                 daParamCollectionService.insertBatch(collectionList);
1130             }
1131             return basicList;
1132         }catch (Exception e) {
1133             throw new RuntimeException(e);
1134         }
1135     }
4162bc 1136     /**
C 1137      * 生成1P1S码
1138      * @param sfcCode
1139      * @return list
1140      */
1141     public static String get1P1S(String sfcCode) {
1142         String result = "";
1143         LocalDate now = LocalDate.now();
1144         String supplierCode  = sfcCode.substring(0,3);
1145         try {
1146             List<DaPsConf> list = daPsConfService.list(new LambdaQueryWrapper<DaPsConf>()
1147                     .eq(DaPsConf::getSpareField1, supplierCode)//供应商识别码
1148                     .eq(DaPsConf::getState,"1"));//状态
1149             if(!list.isEmpty()){
1150                 String mfCode = list.get(0).getMfCode();//厂商代码
1151                 String proTypeCode = list.get(0).getProTypeCode();//产品类型代码
1152                 String batteryTypeCode = list.get(0).getBatteryTypeCode();//电池类型代码
1153                 String specificationsCode = list.get(0).getSpecificationsCode();//规格代码
1154                 String traceInfoCode = list.get(0).getTraceInfoCode();//追溯信息代码
b42c5d 1155                 String oldDateCode = list.get(0).getProDateCode();
4162bc 1156                 String proDateCode = Constants.YEARSMAP.get(now.getYear())
C 1157                         + Constants.MONTHSMAP.get(now.getMonthValue())
1158                         + Constants.DAYMAP.get(now.getDayOfMonth());//生产日期
1159
b42c5d 1160                 String code = "";
C 1161                 if(oldDateCode.equals(proDateCode)){
1162                     code = list.get(0).getSfcCode();//序列号
1163                 }else {
1164                     code = "0";
1165                 }
4162bc 1166                 code = StringUtils.leftPad(String.valueOf(Integer.valueOf(code)+1),7, "0");;//序列号
C 1167                 result = mfCode+proTypeCode+batteryTypeCode+specificationsCode+traceInfoCode+proDateCode+code;
1168
1169                 log.info("读取到电芯码为:{},1P1S码为:{}",sfcCode,result);
1170
1171                 //更新日期和序列号
1172                 LambdaUpdateWrapper<DaPsConf> lambdaUpdateWrapper = new LambdaUpdateWrapper<DaPsConf>();
1173                 lambdaUpdateWrapper.set(DaPsConf::getProDateCode,proDateCode);//生产日期
1174                 lambdaUpdateWrapper.set(DaPsConf::getSfcCode,code);//序列号
1175                 lambdaUpdateWrapper.eq(DaPsConf::getSpareField1,supplierCode);//供应商识别码
1176                 lambdaUpdateWrapper.eq(DaPsConf::getState,"1");//状态
1177                 daPsConfService.update(lambdaUpdateWrapper);
1178
1179             }else{
1180                 log.info("请先去1P1S配置页面配置规则!");
1181             }
1182             return result;
1183         }catch (Exception e) {
1184             throw new RuntimeException(e);
1185         }
1186     }
61c519 1187
22ae12 1188     /**
A 1189      * 批次校验
1190      * @param keyCode,batch
1191      * @return list
1192      */
1193     public Integer batchVerification(String keyCode,String batch){
1194         Integer result = 11;
1195         List<DaCellData> cellDataList = daCellDataService.list(new LambdaQueryWrapper<DaCellData>()
1196                 .eq(DaCellData::getGbCellCode, keyCode)
1197                 .eq(DaCellData::getCellSerial, batch)
1198         );
1199         if(cellDataList.isEmpty()){
1200             result = 13;
1201             log.info("电芯码{} 工位010校验批次失败:批次为{}",keyCode,batch);
1202         }
1203         return result;
1204     }
1205
61c519 1206
A 1207 }