cl
2024-07-29 4d7a570e19413608e81b705af4a2debc5e473fc9
提交 | 用户 | 时间
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检测结果,这里不用再进行检测,只要码没问题就可以了
6a53e6 133                             boolean b = OCVResultFeedBack(thoroughfare, device,cellCode);//对替换电芯校验
e4f9cb 134                             //四个电芯的状态
C 135                             if (b){
136                                 scanResult = 11;
ec7e2a 137                             }else {
C 138                                 scanResult = 12;
6a53e6 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);
6a53e6 184                             //接收工单,保存到数据库,并且将工单传给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 {
069a9b 314
4d7a57 315             //先查询表中是否有剩余工单
C 316             List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>()
317                     .eq(OmProductionOrdeInfo::getOrderStatus, Constants.ONE)
318                     .eq(OmProductionOrdeInfo::getStationCode,device)//工位
319                     .eq(OmProductionOrdeInfo::getProductCode,materialCode));//产品类型
320             if (CollUtil.isNotEmpty(orderList)){
321                 Long id = orderList.get(0).getId();
322                 String productNum = orderList.get(0).getProductNum();//模组码
323                 String orderNum = orderList.get(0).getWorkOrderNo();
ef58b9 324
4d7a57 325                 paramProductNum = productNum;
C 326
58c9d4 327                 //下发产品模组码
C 328                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ModuleCode").value(productNum).build());
329                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build());
ef58b9 330
58c9d4 331                 //将产品SN发送到前台
C 332                 productNum = "productNum,"+ productNum;
333                 WebSocketUsers.sendMessageToUserByText(map.get(device), productNum);
4d7a57 334             }else{
C 335                 // 查询最新的工单信息
336                 OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder();
ef58b9 337
4d7a57 338                 log.info("请求工厂MES工单:入参device{},materialCode:{}", device, materialCode);
C 339                 String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "M1OP100",materialCode);
340                 JSONObject jsonObject = new JSONObject(orderJsonString);
341                 // 从JSONObject中获取data对象
342                 JSONObject dataObject = jsonObject.getJSONObject("data");
343                 String code = jsonObject.getStr("code");
344                 // 判断接单是否成功
345                 if(code.equals("success")) {
346                     log.info("请求工厂MES工单:入参pack{}出参pack:{}", paramProductNum, dataObject.getStr("productNum"));
347                     OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
348                     omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum"));
349                     omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum"));
350                     omProductionOrdeInfo.setStationCode(device);
351                     omProductionOrdeInfo.setProductCode(dataObject.getStr("materialCode"));
352                     omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity")));
353                     omProductionOrdeInfo.setOnlineCompletionMark("0");
354                     omProductionOrdeInfo.setSfResult("0");
355                     omProductionOrdeInfo.setProductModel(dataObject.getStr("model"));
356                     omProductionOrdeInfo.setCreateTime(new Date());
357                     omProductionOrdeInfo.setCreateUser("工厂MES");
358                     omProductionOrdeInfoService.save(omProductionOrdeInfo);
359
360                     String productNum = dataObject.getStr("productNum");
361                     String orderNum = dataObject.getStr("productionOrderNum");
362                     //下发产品模组码
363                     miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ModuleCode").value(productNum).build());
364                     miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build());
365
366                     //将产品SN发送到前台
367                     productNum = "productNum,"+ productNum;
368                     WebSocketUsers.sendMessageToUserByText(map.get(device), productNum);
369                 }
ef58b9 370             }
4d7a57 371
ef58b9 372         } catch (Exception e) {
C 373             throw new RuntimeException(e);
374         }
35c489 375     }
0ca254 376
A 377     /**
109e2f 378      * 读取电芯码
C 379      * @param thoroughfare 通道
380      * @param device 工位
381      * @return list
382      * @throws Exception e
0ca254 383      */
109e2f 384     private static List<String> readCellCodeList(String thoroughfare, String device){
C 385         List<String> cellCodeList = new ArrayList<>();
2de856 386         Map map = new HashMap();
109e2f 387         //电芯码地址
C 388         List<String> readList = new ArrayList<>();
389         readList.add(thoroughfare + "." + device +".CellCode_1");
390         readList.add(thoroughfare + "." + device +".CellCode_2");
391         readList.add(thoroughfare + "." + device +".CellCode_3");
392         readList.add(thoroughfare + "." + device +".CellCode_4");
0ca254 393         try {
109e2f 394             List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(readList);//电芯码
C 395             for (ReadWriteEntity readWriteEntity : readWriteEntityList) {
b59023 396                 if (ObjectUtil.isNotNull(readWriteEntity.getValue()) && !readWriteEntity.getValue().toString().trim().isEmpty()){
2de856 397                     cellCodeList.add(readWriteEntity.getValue().toString());//封装电芯码
b59023 398                 }else{
2de856 399                     cellCodeList.add("");//封装电芯码
b59023 400                 }
0ca254 401             }
2de856 402
0ca254 403         } catch (Exception e) {
A 404             throw new RuntimeException(e);
405         }
109e2f 406         return cellCodeList;
2de856 407     }
C 408
409
410     /**
411      * 保存过站数据
412      * @param thoroughfare 通道
413      * @param device 工位
414      * @param moduleCode 模组号
069a9b 415      * @param stationStatus 站状态
2de856 416      * @return list
C 417      * @throws Exception e
418      */
069a9b 419     private static Integer savePassingStation(String thoroughfare, String device,String moduleCode,String stationStatus){
2de856 420         Integer result = 21;
C 421
422         try {
423             //读进站时间
424             Date startTime = new Date();
425             ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间
426             if (ObjectUtil.isNotNull(startTimeRead.getValue())){
427                 startTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(startTimeRead.getValue().toString())));
428             }else{
429                 result = 23;
430                 log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
431                 return result;
432             }
433
434             DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
435             passingStationCollection.setSfcCode(moduleCode);//电芯码
436             passingStationCollection.setLocationCode(device);//工位
437             passingStationCollection.setInboundTime(startTime);//进站时间
438             passingStationCollection.setOutboundTime(new Date());//出站时间
439             passingStationCollection.setOutRsSign(stationStatus);//站状态值
440             passingStationCollection.setCollectionTime(new Date());//采集时间
441             daPassingStationCollectionService.save(passingStationCollection);
442
443         } catch (Exception e) {
444             throw new RuntimeException(e);
445         }
446
447         return result;
0ca254 448     }
A 449
109e2f 450     /**
C 451      * 保存过站数据
452      * @param thoroughfare 通道
453      * @param device 工位
454      * @param cellCodeList 电芯码集合
455      * @return list
456      * @throws Exception e
457      */
458     private static Integer savePassingStation(String thoroughfare, String device,List<String> cellCodeList){
459         Integer result = 21;
460
461         try {
462             //读进站时间
463             Date startTime = new Date();
464             ReadWriteEntity startTimeRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StartTime");//进站时间
465             if (ObjectUtil.isNotNull(startTimeRead.getValue())){
8c5c9c 466                 startTime = format.parse(TimeUtil.test(TimeUtil.stringProcessing(startTimeRead.getValue().toString())));
109e2f 467             }else{
C 468                 result = 23;
469                 log.info("读取到工位{}的StartTime数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
2de856 470                 return result;
109e2f 471             }
C 472
473             //读工站状态
474             String stationStatus = Constants.PASS;
475             ReadWriteEntity stationStatusRead = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus");//站状态地址
476             if (ObjectUtil.isNotNull(stationStatusRead.getValue())){
477                 String string = stationStatusRead.getValue().toString();
478                 if (Constants.TWO.equals(string)){
479                     stationStatus = Constants.UN_PASS;
480                 }
481             }else{
482                 result = 23;
2de856 483                 log.info("读取到工位{}StationStatus数据:{},返回RecordDataDone的值为{}",device,"IS NULL!",result);
C 484                 return result;
109e2f 485             }
C 486
487             List<DaPassingStationCollection> passingList = new ArrayList<>();
488             for (String cellCode : cellCodeList) {
489                 DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
2de856 490                 if (ObjectUtil.isNotNull(cellCode) && !cellCode.isEmpty()){
109e2f 491                     passingStationCollection.setSfcCode(cellCode);//电芯码
C 492                     passingStationCollection.setLocationCode(device);//工位
493                     passingStationCollection.setInboundTime(startTime);//进站时间
494                     passingStationCollection.setOutboundTime(new Date());//出站时间
495                     passingStationCollection.setOutRsSign(stationStatus);//站状态值
496                     passingStationCollection.setCollectionTime(new Date());//采集时间
497                     passingList.add(passingStationCollection);
498                 }
499             }
500
501             if (CollUtil.isNotEmpty(passingList)){
502                 daPassingStationCollectionService.insertBatch(passingList);//存储过站采集数据
503             }
504
505         } catch (Exception e) {
506             throw new RuntimeException(e);
507         }
508
509         return result;
510     }
511
2de856 512
109e2f 513     /**
2de856 514      * 保存参数数据和发送工厂MES
C 515      * @param device 工位
516      * @param moduleCode 模组号
069a9b 517      * @param stationStatus 站状态
2de856 518      * @return list
C 519      * @throws Exception e
520      */
069a9b 521     private static Integer saveParamCollection(String device,String moduleCode,String stationStatus){
2de856 522         Integer result = 21;//返回结果
5c62de 523         String sendMes = "";
2de856 524
C 525         try {
526             //查询参数配置表
527             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
528                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
529                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
530             );
531             if (CollUtil.isNotEmpty(list)){
532
533                 List<String> collect = list.stream()
534                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
535                 List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(collect);
536
537                 List<DaParamCollection> collectionList = new ArrayList<>();
538                 List<ChildVO> mesList = new ArrayList<>();
539                 for (int i = 0; i < readWriteEntityList.size(); i++) {
540                     DaParamCollection daParamCollection = new DaParamCollection();
541                     daParamCollection.setSfcCode(moduleCode);//模组码
542                     daParamCollection.setParamCode(list.get(i).getCollectParameterId());//参数编码
543                     daParamCollection.setParamName(list.get(i).getCollectParameterName());//参数名称
544                     String paramValue = "";
545                     if (ObjectUtil.isNotNull(readWriteEntityList.get(i).getValue())){
546                         paramValue = readWriteEntityList.get(i).getValue().toString();//参数值
e0c9c6 547                         if("DATE".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){
C 548                             paramValue = format.parse(TimeUtil.test(TimeUtil.stringProcessing(paramValue))).toString();
aa5f09 549                         }else if("MODEL".equals(list.get(i).getCollectParameterType()) && !paramValue.isEmpty()){
C 550                             paramValue = Constants.materialMap.get(paramValue);
e0c9c6 551                         }
2de856 552                     }
C 553                     daParamCollection.setParamValue(paramValue);//参数值
554                     daParamCollection.setLocationCode(device);//工位
555                     daParamCollection.setCollectionTime(new Date());//采集时间
556                     collectionList.add(daParamCollection);//封装参数采集list
557
558                     //发送给工厂mes参数封装
559                     ChildVO childVO = new ChildVO();
560                     childVO.setItemCode(list.get(i).getCollectParameterId());//参数编码
561                     childVO.setItemType(list.get(i).getItemType());
562                     childVO.setItemValue(paramValue);//参数值
563                     childVO.setItemText(list.get(i).getCollectParameterName());
564                     childVO.setCheckResult("1");
e0c9c6 565                     childVO.setCheckTime(format.format(new Date()));
2de856 566                     mesList.add(childVO);
C 567                 }
568
569                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
570                     //插入参数采集表
571                     daParamCollectionService.insertBatch(collectionList);
997e69 572
9a5ab9 573                     //如果220工位,进行报工,因为上层系统只支持6位,所有报工工位修改为M1P220
05181b 574                     if(Constants.OP220.equals(device)) {
9a5ab9 575                         getWorkReportResultFeedback(moduleCode, "M1P220", format.format(new Date()));
997e69 576                     }
C 577
2de856 578                     //上传到工厂mes
C 579                     ParentVO parentVO = new ParentVO();
580                     parentVO.setStationCode(device);//工位
581                     parentVO.setSiteCode("3983");
582
583                     parentVO.setRecordId(UUID.randomUUID().toString());
997e69 584                     if("2".equals(stationStatus)){//工站状态
069a9b 585                         parentVO.setTotalResult("0");
C 586                     }else {
587                         parentVO.setTotalResult("1");
588                     }
2de856 589                     parentVO.setProductNum(moduleCode);
5fbc7a 590
C 591                     //添加基础数据
06168f 592                     List<ChildVO> basicList = getCollectParamBasicData(device,moduleCode);
5fbc7a 593                     mesList.addAll(basicList);
C 594
2de856 595                     parentVO.setCheckList(mesList);
C 596
e4f9cb 597                     log.info("执行工厂MES方法start,工位号{} 传入数据:{}",device ,parentVO);
971788 598                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
e4f9cb 599                     log.info("执行工厂MES方法end,工位号{} 返回数据:{}",device,execute.body());
2de856 600
C 601                 });
602             }
603         }catch (Exception e) {
604             throw new RuntimeException(e);
605         }
606         return result;
607     }
608
609     /**
610      * 保存参数数据和发送工厂MES
109e2f 611      * @param device 工位
C 612      * @param cellCodeList 电芯码集合
613      * @return list
614      * @throws Exception e
615      */
069a9b 616     private static Integer saveParamCollection(String device,List<String> cellCodeList){
109e2f 617         Integer result = 21;//返回结果
743e2e 618         List<ChildVO> mesChildList1 = new ArrayList<>();//封装给工厂MES发送的childlist1
C 619         List<ChildVO> mesChildList2 = new ArrayList<>();//封装给工厂MES发送的childlist2
620         List<ChildVO> mesChildList3 = new ArrayList<>();//封装给工厂MES发送的childlist3
621         List<ChildVO> mesChildList4 = new ArrayList<>();//封装给工厂MES发送的childlist4
622         List<ChildVO> mesChildList0 = new ArrayList<>();//封装给工厂MES发送的childlist4
109e2f 623         try {
C 624             //查询参数配置表
625             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
626                     .eq(DaCollectionParamConf::getProcessesCode, device)//工位
8c5c9c 627                     .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
2de856 628                     );//类型
109e2f 629             if (CollUtil.isNotEmpty(list)) {
C 630                 List<DaParamCollection> saveParamList = new ArrayList<>();//封装参数采集list
631                 List<DaCollectionParamConf> confColl1 = list.stream().filter(x -> Constants.INT_ONE.equals(x.getKeyNum())).collect(Collectors.toList());
632                 List<DaCollectionParamConf> confColl2 = list.stream().filter(x -> Constants.INT_TWO.equals(x.getKeyNum())).collect(Collectors.toList());
633                 List<DaCollectionParamConf> confColl3 = list.stream().filter(x -> Constants.INT_THREE.equals(x.getKeyNum())).collect(Collectors.toList());
634                 List<DaCollectionParamConf> confColl4 = list.stream().filter(x -> Constants.INT_FOUR.equals(x.getKeyNum())).collect(Collectors.toList());
635                 List<DaCollectionParamConf> confColl0 = list.stream().filter(x -> Constants.INT_ZERO.equals(x.getKeyNum())).collect(Collectors.toList());
636
637                 List<String> collect1 = confColl1.stream()
638                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
639                 List<ReadWriteEntity> paramCollectionList1 = miloService.readFromOpcUa(collect1);//电芯1 参数值
640
641                 List<String> collect2 = confColl2.stream()
642                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
643                 List<ReadWriteEntity> paramCollectionList2 = miloService.readFromOpcUa(collect2);//电芯2 参数值
644
645                 List<String> collect3 = confColl3.stream()
646                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
647                 List<ReadWriteEntity> paramCollectionList3 = miloService.readFromOpcUa(collect3);//电芯3 参数值
648
649                 List<String> collect4 = confColl4.stream()
650                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
651                 List<ReadWriteEntity> paramCollectionList4 = miloService.readFromOpcUa(collect4);//电芯4 参数值
652
653                 List<String> collect0 = confColl0.stream()
654                         .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
655                 List<ReadWriteEntity> paramCollectionList0 = miloService.readFromOpcUa(collect0);//电芯 参数值
656
657                 //第一个电芯的数据
2de856 658                 if (CollUtil.isNotEmpty(paramCollectionList1) && !cellCodeList.get(0).isEmpty()) {
109e2f 659                     for (int i = 0; i < paramCollectionList1.size(); i++) {
C 660                         DaParamCollection daParamCollection = new DaParamCollection();
661                         daParamCollection.setSfcCode(cellCodeList.get(0));//电芯码
662                         daParamCollection.setParamCode(confColl1.get(i).getCollectParameterId());//参数编码
663                         daParamCollection.setParamName(confColl1.get(i).getCollectParameterName());//参数名称
664                         String paramValue = "";
665                         if (ObjectUtil.isNotNull(paramCollectionList1.get(i).getValue())) {
666                             paramValue = paramCollectionList1.get(i).getValue().toString();//参数值
667                         }
668                         daParamCollection.setParamValue(paramValue);//参数值
669                         daParamCollection.setLocationCode(device);//工位
670                         daParamCollection.setCollectionTime(new Date());//采集时间
671                         saveParamList.add(daParamCollection);//封装参数采集list
672
673                         //发送给工厂mes参数封装
674                         ChildVO childVO = new ChildVO();
e4f9cb 675                         childVO.setItemCode(confColl1.get(i).getCollectParameterId());//参数
109e2f 676                         childVO.setItemType(confColl1.get(i).getItemType());
C 677                         childVO.setItemValue(paramValue);//参数值
e4f9cb 678                         childVO.setItemText(confColl1.get(i).getCollectParameterName());
109e2f 679                         childVO.setCheckResult("1");
e0c9c6 680                         childVO.setCheckTime(format.format(new Date()));
109e2f 681                         mesChildList1.add(childVO);
C 682                     }
743e2e 683
109e2f 684                 }
2de856 685                 if (CollUtil.isNotEmpty(paramCollectionList2) && !cellCodeList.get(1).isEmpty()) {
109e2f 686
C 687                     for (int i = 0; i < paramCollectionList2.size(); i++) {
688                         DaParamCollection daParamCollection = new DaParamCollection();
689                         daParamCollection.setSfcCode(cellCodeList.get(1));//电芯码
690                         daParamCollection.setParamCode(confColl2.get(i).getCollectParameterId());//参数编码
691                         daParamCollection.setParamName(confColl2.get(i).getCollectParameterName());//参数名称
692                         String paramValue = "";
693                         if (ObjectUtil.isNotNull(paramCollectionList2.get(i).getValue())) {
694                             paramValue = paramCollectionList2.get(i).getValue().toString();//参数值
695                         }
696                         daParamCollection.setParamValue(paramValue);//参数值
697                         daParamCollection.setLocationCode(device);//工位
698                         daParamCollection.setCollectionTime(new Date());//采集时间
699                         saveParamList.add(daParamCollection);//封装参数采集list
700
701                         //发送给工厂mes参数封装
702                         ChildVO childVO = new ChildVO();
e4f9cb 703                         childVO.setItemCode(confColl2.get(i).getCollectParameterId());//参数
109e2f 704                         childVO.setItemType(confColl2.get(i).getItemType());
C 705                         childVO.setItemValue(paramValue);//参数值
e4f9cb 706                         childVO.setItemText(confColl2.get(i).getCollectParameterName());
109e2f 707                         childVO.setCheckResult("1");
e0c9c6 708                         childVO.setCheckTime(format.format(new Date()));
109e2f 709                         mesChildList2.add(childVO);
C 710                     }
711                 }
2de856 712                 if (CollUtil.isNotEmpty(paramCollectionList3) && !cellCodeList.get(2).isEmpty()) {
109e2f 713                     for (int i = 0; i < paramCollectionList3.size(); i++) {
C 714                         DaParamCollection daParamCollection = new DaParamCollection();
715                         daParamCollection.setSfcCode(cellCodeList.get(2));//电芯码
716                         daParamCollection.setParamCode(confColl3.get(i).getCollectParameterId());//参数编码
717                         daParamCollection.setParamName(confColl3.get(i).getCollectParameterName());//参数名称
718                         String paramValue = "";
719                         if (ObjectUtil.isNotNull(paramCollectionList3.get(i).getValue())) {
720                             paramValue = paramCollectionList3.get(i).getValue().toString();//参数值
721                         }
722                         daParamCollection.setParamValue(paramValue);//参数值
723                         daParamCollection.setLocationCode(device);//工位
724                         daParamCollection.setCollectionTime(new Date());//采集时间
725                         saveParamList.add(daParamCollection);//封装参数采集list
726
727                         //发送给工厂mes参数封装
728                         ChildVO childVO = new ChildVO();
e4f9cb 729                         childVO.setItemCode(confColl3.get(i).getCollectParameterId());//参数
109e2f 730                         childVO.setItemType(confColl3.get(i).getItemType());
C 731                         childVO.setItemValue(paramValue);//参数值
e4f9cb 732                         childVO.setItemText(confColl3.get(i).getCollectParameterName());
109e2f 733                         childVO.setCheckResult("1");
e0c9c6 734                         childVO.setCheckTime(format.format(new Date()));
109e2f 735                         mesChildList3.add(childVO);
C 736                     }
737                 }
2de856 738                 if (CollUtil.isNotEmpty(paramCollectionList4)&& !cellCodeList.get(3).isEmpty()) {
109e2f 739                     for (int i = 0; i < paramCollectionList4.size(); i++) {
C 740                         DaParamCollection daParamCollection = new DaParamCollection();
741                         daParamCollection.setSfcCode(cellCodeList.get(3));//电芯码
742                         daParamCollection.setParamCode(confColl4.get(i).getCollectParameterId());//参数编码
743                         daParamCollection.setParamName(confColl4.get(i).getCollectParameterName());//参数名称
744                         String paramValue = "";
745                         if (ObjectUtil.isNotNull(paramCollectionList4.get(i).getValue())) {
746                             paramValue = paramCollectionList4.get(i).getValue().toString();//参数值
747                         }
748                         daParamCollection.setParamValue(paramValue);//参数值
749                         daParamCollection.setLocationCode(device);//工位
750                         daParamCollection.setCollectionTime(new Date());//采集时间
751                         saveParamList.add(daParamCollection);//封装参数采集list
752
753                         //发送给工厂mes参数封装
754                         ChildVO childVO = new ChildVO();
e4f9cb 755                         childVO.setItemCode(confColl4.get(i).getCollectParameterId());//参数
109e2f 756                         childVO.setItemType(confColl4.get(i).getItemType());
C 757                         childVO.setItemValue(paramValue);//参数值
e4f9cb 758                         childVO.setItemText(confColl4.get(i).getCollectParameterName());
109e2f 759                         childVO.setCheckResult("1");
e0c9c6 760                         childVO.setCheckTime(format.format(new Date()));
109e2f 761                         mesChildList4.add(childVO);
C 762                     }
763                 }
764
765                 //公共参数
766                 if (CollUtil.isNotEmpty(paramCollectionList0)) {
767                     for (int i = 0; i < cellCodeList.size(); i++) {//循环4个电芯
2de856 768                         if(!cellCodeList.get(i).isEmpty()){
C 769                             for (int j = 0; j < paramCollectionList0.size(); j++) {
770                                 DaParamCollection daParamCollection = new DaParamCollection();
771                                 daParamCollection.setSfcCode(cellCodeList.get(i));//电芯码
772                                 daParamCollection.setParamCode(confColl0.get(j).getCollectParameterId());//参数编码
773                                 daParamCollection.setParamName(confColl0.get(j).getCollectParameterName());//参数名称
774                                 String paramValue = "";
775                                 if (ObjectUtil.isNotNull(paramCollectionList0.get(j).getValue())) {
776                                     paramValue = paramCollectionList0.get(j).getValue().toString();//参数值
e0c9c6 777                                     if("DATE".equals(confColl0.get(j).getCollectParameterType()) && !paramValue.isEmpty()){
C 778                                         paramValue = TimeUtil.test(TimeUtil.stringProcessing(paramValue));
779                                     }
2de856 780                                 }
C 781                                 daParamCollection.setParamValue(paramValue);//参数值
782                                 daParamCollection.setLocationCode(device);//工位
783                                 daParamCollection.setCollectionTime(new Date());//采集时间
784                                 saveParamList.add(daParamCollection);
109e2f 785
2de856 786                                 //发送给工厂mes参数封装
C 787                                 ChildVO childVO = new ChildVO();
e4f9cb 788                                 childVO.setItemCode(confColl0.get(j).getCollectParameterId());//参数
2de856 789                                 childVO.setItemType(confColl0.get(j).getItemType());
C 790                                 childVO.setItemValue(paramValue);//参数值
e4f9cb 791                                 childVO.setItemText(confColl0.get(j).getCollectParameterName());
2de856 792                                 childVO.setCheckResult("1");
e0c9c6 793                                 childVO.setCheckTime(format.format(new Date()));
2de856 794                                 mesChildList0.add(childVO);
C 795                             }
109e2f 796                         }
2de856 797
C 798                         //mesList.get(i).addAll(mesChildList0);
799
109e2f 800                     }
C 801
802                 }
803
804                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
805                     //插入参数采集表
806                     daParamCollectionService.insertBatch(saveParamList);
807                     //上传到工厂mes
808                     ParentVO parentVO = new ParentVO();
809                     parentVO.setStationCode(device);//工位
810                     parentVO.setSiteCode("3983");
811                     for (int i = 0; i < cellCodeList.size(); i++) {//循环4个电芯
2de856 812                         if(!cellCodeList.get(i).isEmpty()){
8e2102 813                             parentVO.setRecordId(UUID.randomUUID().toString());
C 814                             parentVO.setTotalResult("1");
2de856 815                             parentVO.setProductNum(cellCodeList.get(i));//电芯码
743e2e 816                             //封装给工厂MES发送的childlist4
C 817                             List<ChildVO> mesChildList = new ArrayList<>(mesChildList0);
818                             switch (i) {
819                                 case 0 :
820                                     mesChildList.addAll(mesChildList1);
821                                     break;
822                                 case 1 :
823                                     mesChildList.addAll(mesChildList2);
824                                     break;
825                                 case 2 :
826                                     mesChildList.addAll(mesChildList3);
827                                     break;
828                                 case 3 :
829                                     mesChildList.addAll(mesChildList4);
830                                     break;
831
832                             }
5fbc7a 833
C 834                             //添加基础数据
06168f 835                             List<ChildVO> basicList = getCollectParamBasicData(device,cellCodeList.get(i));
5fbc7a 836                             mesChildList.addAll(basicList);
C 837
743e2e 838                             parentVO.setCheckList(mesChildList);//参数
2de856 839                             //CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
C 840                             log.info("执行工厂MES方法start,传入数据:{}",parentVO);
971788 841                             HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
2de856 842                             log.info("执行工厂MES方法end,返回数据:{}",execute.body());
C 843                         }
109e2f 844                     }
C 845                 });
846             }
847         }catch (Exception e) {
743e2e 848             log.error(e.getMessage());
109e2f 849             throw new RuntimeException(e);
C 850         }
851         return result;
852     }
853
854     /**
ddf2c2 855      * OP020校验电芯挡位
C 856      * @param thoroughfare
857      * @param device
858      * @throws Exception
859      */
860     private Integer checkCellGear(String thoroughfare, String device,List<String> cellCodeList,String cellGear) throws Exception {
861         Integer result = 11;
862
863         for(int i = 0; i < cellCodeList.size(); i ++){
864             Integer cellStatus = 1;
865             String cellCode = cellCodeList.get(i);
866             if(!cellCode.isEmpty()){
867                 List<DaCellData> list = daCellDataService.list(new LambdaQueryWrapper<DaCellData>()
868                         .eq(DaCellData::getGbCellCode,cellCode));
869                 if(CollUtil.isNotEmpty(list)){
870                     DaCellData daCellData = list.get(0);
871                     String cellValue = daCellData.getCellValue();//数据库中电芯挡位
872                     String cellSerial = daCellData.getCellSerial();//数据库中电芯组别
873                     if(!cellValue.isEmpty() && cellValue.equals(cellGear)){
874                         cellStatus = 1;
875                     }else {
876                         cellStatus = 2;
877                         result = 17;//挡位校验不合格
878                     }
879                 }else {
880                     cellStatus = 2;
881                     result = 17;//查不到要校验的挡位
882                 }
883                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_"+(i+1)).value(cellStatus).build());
884             }
885         }
886         return result;
887     }
888
ec7e2a 889     /**
C 890      * 030工位返回ocv测试结果
891      * @param thoroughfare
892      * @param device
6a53e6 893      * @param cellCode
C 894      * @throws Exception
895      */
896     private boolean OCVResultFeedBack(String thoroughfare, String device,String cellCode) throws Exception {
897         boolean flag = true;
898         List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
899                 .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode)
900                 .orderByDesc(DaTestDeviceInterfaceTemp::getCreateTime)
901         );
902         if (CollUtil.isNotEmpty(list)){
903             DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(0);
904             if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
905                 flag = true;
906             }else {
907                 flag = false;
908             }
909             //daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
910         }else {
911             flag = false;
912             log.info("读取到工位{},测试设备返回的数据查询不到,电芯码为:{}",device,cellCode);
913         }
914         return flag;
915     }
916     /**
917      * 030工位返回ocv测试结果
918      * @param thoroughfare
919      * @param device
109e2f 920      * @throws Exception
C 921      */
2de856 922     private boolean OCVResultFeedBack(String thoroughfare, String device) throws Exception {
C 923         boolean flag = true;
924         Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_1").getValue();
5b755f 925         if (ObjectUtil.isNotNull(value1)){
C 926             String cellCode = value1.toString();
927             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
5f0f21 928                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode)
A 929                     .orderByDesc(DaTestDeviceInterfaceTemp::getCreateTime)
930             );
2de856 931             if (CollUtil.isNotEmpty(list)){
5f0f21 932                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(0);
5b755f 933                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
2de856 934                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(1).build());
C 935                 }else {
936                     flag = false;
937                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(2).build());
938                 }
052a06 939                 //daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
86e4f5 940             }else {
C 941                 flag = false;
a6cddf 942                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(5).build());
86e4f5 943                 log.info("读取到工位{},OP020工位没有给测试结果",device);
2de856 944             }
f18ebf 945         }else {
C 946             flag = false;
a6cddf 947             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_1").value(5).build());
f18ebf 948             log.info("读取到工位{},PLC没有给电芯码",device);
5b755f 949         }
2de856 950         Object value2 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_2").getValue();
5b755f 951         if (ObjectUtil.isNotNull(value2)){
C 952             String cellCode = value2.toString();
953             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
3bbfe1 954                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode)
A 955                     .orderByDesc(DaTestDeviceInterfaceTemp::getCreateTime)
956             );
2de856 957             if (CollUtil.isNotEmpty(list)){
3bbfe1 958                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(0);
5b755f 959                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
2de856 960                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(1).build());
C 961                 }else {
962                     flag = false;
963                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(2).build());
964                 }
052a06 965                 //daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
86e4f5 966             }else {
C 967                 flag = false;
a6cddf 968                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(5).build());
86e4f5 969                 log.info("读取到工位{},OP020工位没有给测试结果",device);
2de856 970             }
f18ebf 971         }else {
C 972             flag = false;
a6cddf 973             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_2").value(5).build());
f18ebf 974             log.info("读取到工位{},PLC没有给电芯码",device);
5b755f 975         }
C 976
2de856 977         Object value3 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_3").getValue();
5b755f 978         if (ObjectUtil.isNotNull(value3)){
C 979             String cellCode = value3.toString();
980             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
3bbfe1 981                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode)
A 982                     .orderByDesc(DaTestDeviceInterfaceTemp::getCreateTime)
983             );
2de856 984             if (CollUtil.isNotEmpty(list)){
3bbfe1 985                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(0);
5b755f 986                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
2de856 987                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(1).build());
C 988                 }else {
989                     flag = false;
990                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(2).build());
991                 }
052a06 992                 //daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
86e4f5 993             }else {
C 994                 flag = false;
a6cddf 995                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(5).build());
86e4f5 996                 log.info("读取到工位{},OP020工位没有给测试结果",device);
2de856 997             }
f18ebf 998         }else {
C 999             flag = false;
a6cddf 1000             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_3").value(5).build());
f18ebf 1001             log.info("读取到工位{},PLC没有给电芯码",device);
5b755f 1002         }
C 1003
2de856 1004         Object value4 = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellCode_4").getValue();
5b755f 1005         if (ObjectUtil.isNotNull(value4)){
C 1006             String cellCode = value4.toString();
1007             List<DaTestDeviceInterfaceTemp> list = daTestDeviceInterfaceTempService.list(new LambdaQueryWrapper<DaTestDeviceInterfaceTemp>()
3bbfe1 1008                     .eq(DaTestDeviceInterfaceTemp::getProductNum,cellCode)
A 1009                     .orderByDesc(DaTestDeviceInterfaceTemp::getCreateTime)
1010             );
2de856 1011             if (CollUtil.isNotEmpty(list)){
3bbfe1 1012                 DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = list.get(0);
5b755f 1013                 if (Constants.ONE.equals(daTestDeviceInterfaceTemp.getTotalResult())){
2de856 1014                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(1).build());
C 1015                 }else {
1016                     flag = false;
1017                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(2).build());
1018                 }
052a06 1019                 //daTestDeviceInterfaceTempService.deleteDaTestDeviceInterfaceTempByProductNum(cellCode);
86e4f5 1020             }else {
C 1021                 flag = false;
a6cddf 1022                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(5).build());
86e4f5 1023                 log.info("读取到工位{},OP020工位没有给测试结果",device);
2de856 1024             }
f18ebf 1025         }else {
C 1026             flag = false;
a6cddf 1027             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_4").value(5).build());
f18ebf 1028             log.info("读取到工位{},PLC没有给电芯码",device);
5b755f 1029         }
C 1030
2de856 1031         return flag;
109e2f 1032     }
C 1033
997e69 1034     /**
C 1035      * AMES报工结果回传
1036      * @param productNum
1037      * @param stationCode
1038      * @param confirmTime
1039      * @return
1040      */
1041     //{"code":"success","data":{"productNum":"LCV123456P0600036","stationCode":"1HZ01","resultCode":"S","resultText":"报工成功"},"message":"API调用成功"}
1042     public static String getWorkReportResultFeedback(String productNum,String stationCode,String confirmTime)
1043     {
1044         String result = "";
1045         try {
1046             String url = Constants.FACTORY_EMS_UAT_GET_RUL + "workReportResultFeedback?siteCode="+Constants.FACTORY_EMS_SITE_CODE+"&stationCode="+stationCode+"&productNum="+productNum+"&confirmTime="+confirmTime;
1047             HttpResponse response = HttpRequest.get(url).execute();
1048             HttpRequest httpRequest = HttpRequest.get(url);
1049             result =  response.body();
1050         }catch (Exception e){
aa5f09 1051             throw new RuntimeException(e);
997e69 1052         }finally {
C 1053             return result;
1054         }
1055     }
1056
109e2f 1057
aa5f09 1058     /**
C 1059      * 获取采集参数基础数据
1060      * @param stationCode
06168f 1061      * @param sfcCode
aa5f09 1062      * @return list
C 1063      */
06168f 1064     public static List<ChildVO> getCollectParamBasicData(String stationCode,String sfcCode) {
aa5f09 1065         List<ChildVO> basicList = new ArrayList<>();
06168f 1066         List<DaParamCollection> collectionList = new ArrayList<>();
aa5f09 1067         try {
C 1068             //查询参数配置表
1069             List<DaCollectionParamConf> list = collectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
1070                     .eq(DaCollectionParamConf::getProcessesCode, stationCode)//工位
1071                     .eq(DaCollectionParamConf::getCollectParameterType, "BASIC")//采集参数类型
1072             );
1073             if (CollUtil.isNotEmpty(list)){
1074                 for(DaCollectionParamConf conf:list){
1075                     ChildVO childVO = new ChildVO();
1076                     childVO.setItemCode(conf.getCollectParameterId());//参数
1077                     childVO.setItemType(conf.getItemType());
1078                     childVO.setItemValue(conf.getParamCentral());//参数值
1079                     childVO.setItemText(conf.getCollectParameterName());
1080                     childVO.setCheckResult("1");
1081                     childVO.setCheckTime(format.format(new Date()));
1082                     basicList.add(childVO);
06168f 1083
C 1084                     DaParamCollection daParamCollection = new DaParamCollection();
1085                     daParamCollection.setSfcCode(sfcCode);//模组码
1086                     daParamCollection.setParamCode(conf.getCollectParameterId());//参数编码
1087                     daParamCollection.setParamName(conf.getCollectParameterName());//参数名称
1088
1089                     daParamCollection.setParamValue(conf.getParamCentral());//参数值
1090                     daParamCollection.setLocationCode(stationCode);//工位
1091                     daParamCollection.setCollectionTime(new Date());//采集时间
1092                     collectionList.add(daParamCollection);//封装参数采集list
aa5f09 1093                 }
06168f 1094                 daParamCollectionService.insertBatch(collectionList);
aa5f09 1095             }
C 1096             return basicList;
1097         }catch (Exception e) {
1098             throw new RuntimeException(e);
1099         }
1100     }
1101
1102
1103
0ca254 1104 }