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