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