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