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