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