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