春风项目四线(合箱线、总装线)
yyt
2024-06-03 5030f3d30ccc1bd16db371c6970a48103aff9191
提交 | 用户 | 时间
3e03af 1 package com.jcdm.main.plcserver.sub;
C 2
9e6d86 3 import cn.hutool.core.collection.CollUtil;
W 4 import cn.hutool.core.util.ObjectUtil;
5 import cn.hutool.core.util.StrUtil;
6 import com.jcdm.main.bs.domain.BsTechnologyRouteChildInfo;
7 import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling;
8 import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService;
9 import com.jcdm.main.bs.technologyRouteChild.service.IBsTechnologyRouteChildInfoService;
3e03af 10 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
C 11 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
059083 12 import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig;
3e03af 13 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
C 14 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
059083 15 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
W 16 import com.jcdm.main.da.passingStationCollection.service.impl.DaPassingStationCollectionServiceImpl;
3e03af 17 import com.jcdm.main.plcserver.conf.OPCElement;
9e6d86 18 import com.jcdm.main.rm.repairRecord.domain.RmRepairRecord;
W 19 import com.jcdm.main.rm.repairRecord.service.IRmRepairRecordService;
3e03af 20 import com.kangaroohy.milo.model.ReadWriteEntity;
C 21 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
22 import com.kangaroohy.milo.service.MiloService;
059083 23 import lombok.extern.slf4j.Slf4j;
1a444b 24 import org.slf4j.Logger;
Y 25 import org.slf4j.LoggerFactory;
3e03af 26 import org.springframework.stereotype.Component;
C 27
9f6314 28 import java.math.BigDecimal;
c76a3f 29 import java.sql.Time;
9e6d86 30 import java.time.LocalDateTime;
c76a3f 31 import java.util.*;
W 32 import java.util.concurrent.TimeUnit;
3e03af 33 import java.util.stream.Collectors;
C 34
35
059083 36 @Slf4j
3e03af 37 @Component
C 38 public class OPCUaSubscription implements SubscriptionCallback {
39
1a444b 40     private static final Logger logger = LoggerFactory.getLogger("sys-user");
3e03af 41     public static MiloService miloService;
C 42
43     public IDaCollectionParamConfService collectionParamConfService;
44
45     public IDaParamCollectionService daParamCollectionService;
46
059083 47     public DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl;
W 48
49     public List<DaOpcuaConfig> lists;
50
51     public static final HashMap<String,Integer> map = new HashMap<>();
52
9e6d86 53     public IBsOrderSchedulingService bsOrderSchedulingService;
W 54
55     public IRmRepairRecordService rmRepairRecordService;
56
57     public IBsTechnologyRouteChildInfoService bsTechnologyRouteChildInfoService;
58
c76a3f 59     public HashMap<String,List<DaCollectionParamConf>> allCollectParamList = new HashMap<>();
W 60
3e03af 61     public OPCUaSubscription(MiloService miloService,
C 62                              IDaCollectionParamConfService collectionParamConfService,
059083 63                              IDaParamCollectionService daParamCollectionService,
W 64                              DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl,
9e6d86 65                              IBsOrderSchedulingService bsOrderSchedulingService,
W 66                              List<DaOpcuaConfig> lists,
67                              IRmRepairRecordService rmRepairRecordService,
68                              IBsTechnologyRouteChildInfoService bsTechnologyRouteChildInfoService) {
3e03af 69         OPCUaSubscription.miloService = miloService;
C 70         this.collectionParamConfService = collectionParamConfService;
71         this.daParamCollectionService = daParamCollectionService;
059083 72         this.passingStationCollectionServiceImpl = passingStationCollectionServiceImpl;
9e6d86 73         this.bsOrderSchedulingService = bsOrderSchedulingService;
059083 74         this.lists = lists;
9e6d86 75         this.rmRepairRecordService = rmRepairRecordService;
W 76         this.bsTechnologyRouteChildInfoService = bsTechnologyRouteChildInfoService;
c76a3f 77
W 78
3e03af 79     }
C 80     @Override
81     public void onSubscribe(String identifier, Object value) {
82         String ecpStr = "";//异常记录标记
83         try {
9e6d86 84             if(null != value && "1".equals(value.toString())) {
059083 85                 //1、检索SN号
W 86                 //2、过站参数采集
87                 //3、扫码枪数据回传
88                 List<String> collect1 = lists.stream().filter(x -> OPCElement.SN_CHECK.equals(x.getrFunction()))
89                         .map(DaOpcuaConfig::getNode).collect(Collectors.toList());
90                 List<String> collect2 = lists.stream().filter(x -> OPCElement.SAVE_DATA.equals(x.getrFunction()))
91                         .map(DaOpcuaConfig::getNode).collect(Collectors.toList());
92                 if (collect1.contains(identifier)){
1a444b 93                     logger.info("-------监听到,{}的CODE_CHECK的信号",identifier);
Y 94                     //logger.info("-------time--------------,{}",LocalDateTime.now());
059083 95                     //sn
W 96                     this.SNRetrieval(identifier,value.toString());
97                     if (identifier.equals(OPCElement.OP120_ZZ_CODE_CHECK) && "1".equals(value.toString())){
98                         //总装上线扫码传输数据
1a444b 99                         logger.info("-------监听到,{}的扫码枪扫码的CODE_CHECK的信号",identifier);
9e6d86 100                         scannerGunMessage();
W 101                     }
1c7036 102                     if (identifier.equals(OPCElement.OP060_HX_CODE_CHECK) && "1".equals(value.toString())){
Y 103                         Object SNCodeObject = miloService.readFromOpcUa("CFL4HX.OP060.Code1").getValue();
104                         if (null == SNCodeObject){
105                             SNCodeObject = miloService.readFromOpcUa("CFL4HX.OP060.Code").getValue();
106                         }
107                         if (null != SNCodeObject){
5030f3 108                             String XT="";
Y 109                             String CZ="";
1c7036 110                             String SNCode = SNCodeObject.toString();
5030f3 111                             DaParamCollection ParamCollection = new DaParamCollection();
Y 112                             ParamCollection.setSfcCode(SNCode);
113                             List<DaParamCollection> DaParamCollectionlist=daParamCollectionService.selectDaParamCollectionList(ParamCollection);
114                             List<DaParamCollection> XTParamCollection = DaParamCollectionlist.stream().filter(x -> "箱体".equals(x.getParamName())).collect(Collectors.toList());
115                             if (CollUtil.isNotEmpty(XTParamCollection)){
116                                 DaParamCollection lastOne = XTParamCollection.get(0);
117                                 XT = lastOne.getParamValue();
118                             }
119                             List<DaParamCollection> CZParamCollection = DaParamCollectionlist.stream().filter(x -> "曲轴".equals(x.getParamName())).collect(Collectors.toList());
120                             if (CollUtil.isNotEmpty(CZParamCollection)){
121                                 DaParamCollection lastOne = CZParamCollection.get(0);
122                                 CZ = lastOne.getParamValue();
123                             }
124                             passingStationCollectionServiceImpl.sendMessage(XT+"*"+CZ,"OP060");
1c7036 125                         }
Y 126                     }
9e6d86 127                 }
W 128                 if (collect2.contains(identifier)){
129                     if ("1".equals(value.toString())){
1a444b 130                         logger.info("-------监听到,{}的SAVE_REQUEST_LAST的信号",identifier);
Y 131                         //logger.info("-------time--------------,{}",LocalDateTime.now());
9e6d86 132                         this.SaveData(identifier);
059083 133                     }
W 134                 }
3e03af 135             }
C 136         } catch (Exception e) {
9e6d86 137             System.out.println(e.getMessage());
3e03af 138         } finally {
C 139             if (!"".equals(ecpStr)) {
140                 System.out.println(ecpStr + "\r\n");
141             }
9e6d86 142         }
W 143     }
144
145     private void scannerGunMessage() throws Exception {
146         String[] parts = OPCElement.OP120_ZZ_CODE_CHECK.split("[.]");
147         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
3946f8 148         if (null == SNCodeObject){
W 149             SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
150         }
9e6d86 151         if (null != SNCodeObject){
W 152             String SNCode = SNCodeObject.toString();
1c7036 153             passingStationCollectionServiceImpl.sendMessage(SNCode,"OP120");
3e03af 154         }
C 155     }
156
059083 157     public void SNRetrieval(String Node, String value) throws Exception {
W 158         String[] parts = Node.split("[.]");
159         if(value.equals("1")) {
160             //SN号检索
161             Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
162             if(null != SNCodeObject) {
163                 String SNCode=SNCodeObject.toString();
1c7036 164 //              String a=passingStationCollectionServiceImpl.SelectSN(SNCode,parts[1]);
929bdc 165                 String a;
W 166                 BsOrderScheduling bsOrderSchedulingQuery = new BsOrderScheduling();
167                 bsOrderSchedulingQuery.setEngineNo(SNCode);
168                 List<BsOrderScheduling> queryOrderList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderSchedulingQuery);
169                 if (CollUtil.isNotEmpty(queryOrderList)){
170                     a = "1";
171                 }else {
0e3cac 172                     a = "4";
929bdc 173                 }
W 174                 //如果是返修工位需要传输返修工位号
0e3cac 175                 List<DaPassingStationCollection> daPassingStationCollections = new ArrayList<>();
W 176                 List<RmRepairRecord> rmRepairRecords = new ArrayList<>();
929bdc 177                 if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node)
W 178                         || OPCElement.OP695_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){
179                     //过站记录
180                     DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
181                     PassingStationCollection.setSfcCode(SNCode);
0e3cac 182                     daPassingStationCollections = passingStationCollectionServiceImpl.selectDaPassingStationCollectionList(PassingStationCollection);
929bdc 183                     if (CollUtil.isNotEmpty(daPassingStationCollections)){
W 184                         DaPassingStationCollection lastOne = daPassingStationCollections.get(daPassingStationCollections.size() - 1);
185                         String outRsSign = lastOne.getOutRsSign();
186                         if ("合格".equals(outRsSign)){
187                             a = "1";
188                         }else {
189                             a = "2";
190                         }
191                     }
0e3cac 192                     RmRepairRecord rmRepairRecord = new RmRepairRecord();
W 193                     rmRepairRecord.setBoxCode(SNCode);
194                     rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord);
195                     if (CollUtil.isNotEmpty(rmRepairRecords)){
196                         a = "1";
197                     }
929bdc 198                 }
1a444b 199                 logger.info("-----返回codeCheckFeed-----,{}",a);
3946f8 200 //                String a="1";
059083 201                 // 1:OK可生产 2:NG不可生产 3:NG可返工 4:PC检索失败(无记录)5:PC检索失败(软件)
9e6d86 202                 if (StrUtil.isNotBlank(a)){
W 203                     int input = Integer.parseInt(a);
204                     ReadWriteEntity entity = new ReadWriteEntity(parts[0]+"."+parts[1]+".CodeCheckFeed", input);
5030f3 205                     logger.info("发动机号:{},监听到{}的CodeCheck的信号",SNCode,Node);
cffac1 206                     miloService.writeToOpcByte(entity);
1a444b 207                     logger.info("监听到返回codecheckfeed信号,{}",entity);
9e6d86 208                     //首站传输订单号
W 209                     if (OPCElement.OP050_HX_CODE_CHECK.equals(Node)){
210                         //查询订单号
211                         BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
212                         bsOrderScheduling.setEngineNo(SNCode);
213                         List<BsOrderScheduling> tempList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
214                         String orderNum = "";
215                         if (CollUtil.isNotEmpty(tempList)){
216                             BsOrderScheduling bsOrderScheduling1 = tempList.get(0);
217                             orderNum = bsOrderScheduling1.getOrderNo();
218                         }
219                         ReadWriteEntity entity2 = new ReadWriteEntity(parts[0]+"."+parts[1]+".OrderNumber", orderNum);
2b59de 220                         miloService.writeToOpcUa(entity2);
9e6d86 221                     }
W 222                     //如果是返修工位需要传输返修工位号
3946f8 223                     if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node)
W 224                     || OPCElement.OP695_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){
0e3cac 225                         rework(SNCode,Node,daPassingStationCollections,rmRepairRecords);
9e6d86 226                     }
d4f437 227                     if (OPCElement.OP020_HX_CODE_CHECK.equals(Node)) {
Y 228                         //激光打码
229                         String[] printcode=SNCode.split("\\s+");
230                         ReadWriteEntity entity3 = new ReadWriteEntity("CFL4HX.HOP020.PrintCode1", printcode[0]);
231                         OPCUaSubscription.miloService.writeToOpcUa(entity3);//写SN
232                         ReadWriteEntity entity5 = new ReadWriteEntity("CFL4HX.HOP020.PrintCode2", printcode[1]);
233                         OPCUaSubscription.miloService.writeToOpcUa(entity5);//写SN
696fd5 234                         ReadWriteEntity entity6 = new ReadWriteEntity("CFL4HX.HOP020.SNDoor", "1");
Y 235                         logger.info("发动机号{},请求打码内容写入成功,返回SNDoor信号信号1",SNCode);
236                         miloService.writeToOpcByte(entity6);
d4f437 237                     }
3946f8 238                     System.out.println(entity);
cffac1 239
9e6d86 240                 }
W 241
059083 242             }
9e6d86 243         }
W 244     }
245
0e3cac 246     private void rework(String SNCode,String Node,List<DaPassingStationCollection> daPassingStationCollections,List<RmRepairRecord> rmRepairRecords)  throws Exception{
9e6d86 247         BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
W 248         bsOrderScheduling.setEngineNo(SNCode);
249         List<String> allProcessCoed = new ArrayList<>();
929bdc 250         List<BsTechnologyRouteChildInfo> bsTechnologyRouteChildInfos = new ArrayList<>();
9e6d86 251         List<String> collect = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling).stream().map(BsOrderScheduling::getModel).collect(Collectors.toList());
W 252         if (CollUtil.isNotEmpty(collect)){
253             String s = collect.get(0);
254             //查找次机型的完整工序
929bdc 255             bsTechnologyRouteChildInfos = bsTechnologyRouteChildInfoService.selectAllTechnologyRouteByProductCode(s);
9e6d86 256             if (CollUtil.isNotEmpty(bsTechnologyRouteChildInfos)){
W 257                 allProcessCoed = bsTechnologyRouteChildInfos.stream().map(BsTechnologyRouteChildInfo::getProcessesCode).collect(Collectors.toList());
258             }
259         }
0e3cac 260 //        RmRepairRecord rmRepairRecord = new RmRepairRecord();
W 261 //        rmRepairRecord.setBoxCode(SNCode);
9e6d86 262         List<ReadWriteEntity> writeList = new ArrayList<>();
0e3cac 263 //        List<RmRepairRecord> rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord);
3946f8 264         //过站记录
0e3cac 265 //        DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
W 266 //        PassingStationCollection.setSfcCode(SNCode);
3946f8 267         //过站记录
0e3cac 268 //        List<DaPassingStationCollection> daPassingStationCollections = passingStationCollectionServiceImpl.selectDaPassingStationCollectionList(PassingStationCollection);
3946f8 269
1a444b 270         //所有返工工位
9e6d86 271         List<String> collect1 = rmRepairRecords.stream().map(RmRepairRecord::getProcessesCode).collect(Collectors.toList());
3946f8 272         if (CollUtil.isNotEmpty(collect1)){
929bdc 273             //查询出所有需要返修工位的最小op块
W 274             Integer minOP = 0;
275             if (CollUtil.isNotEmpty(collect1)){
3946f8 276
929bdc 277                 List<Integer> sortList = new ArrayList<>();
W 278                 collect1.stream().forEach(x ->{
279                     String op = x.replace("OP", "");
280                     if (StrUtil.isNotBlank(op)){
281                         int i = Integer.parseInt(op);
282                         sortList.add(i);
283                     }
284                 });
285                 if (CollUtil.isNotEmpty(sortList)){
286                     List<Integer> collect2 = sortList.stream().filter(Objects::nonNull).sorted().collect(Collectors.toList());
287                     minOP = collect2.get(0);
3946f8 288                 }
W 289             }
929bdc 290             //获取过站记录的最大工位
W 291             String maxCode = null;
292             if (CollUtil.isNotEmpty(daPassingStationCollections)){
9bc510 293                 List<DaPassingStationCollection> collect2 = daPassingStationCollections.stream().filter(x -> "不合格".equals(x.getOutRsSign())).collect(Collectors.toList());
W 294                 if (CollUtil.isNotEmpty(collect2)){
295                     DaPassingStationCollection lastOne = collect2.get(collect2.size() - 1);
296                     maxCode = lastOne.getLocationCode();
297                 }else {
298                     DaPassingStationCollection lastOne = daPassingStationCollections.get(daPassingStationCollections.size() - 1);
299                     maxCode = lastOne.getLocationCode();
300                 }
301
28860f 302             }
929bdc 303             //所有放行工位
W 304             List<String> passStation = new ArrayList<>();
305             //所有生产工位
306             List<String> productStation = new ArrayList<>();
307             //最大工位编号
308             Integer maxCodeNum = 0;
309             if (StrUtil.isNotEmpty(maxCode)){
310                 String finalMaxCode = maxCode;
311                 //获取当前工位对应工步号
312                 List<String> collect2 = bsTechnologyRouteChildInfos.stream()
313                         .filter(x -> x.getProcessesCode().equals(finalMaxCode))
314                         .map(BsTechnologyRouteChildInfo::getStepNo).collect(Collectors.toList());
315                 if (CollUtil.isNotEmpty(collect2)){
316                     String s = collect2.get(0);
317                     if (StrUtil.isNotBlank(s)){
318                         maxCodeNum = Integer.parseInt(s);
319                     }
320                 }
321                 if (CollUtil.isNotEmpty(bsTechnologyRouteChildInfos)){
322                     bsTechnologyRouteChildInfos.forEach(x -> {
323                         x.setStepNoNum(Integer.parseInt(x.getStepNo()));
324                     });
325                     Integer finalMaxCodeNum = maxCodeNum;
326                     //勾选的返修工位中最大的工位之后的工位----1
327                     List<BsTechnologyRouteChildInfo> collect3 = bsTechnologyRouteChildInfos.stream()
328                             .filter(x -> x.getStepNoNum() >= finalMaxCodeNum).collect(Collectors.toList());
329                     if (CollUtil.isNotEmpty(collect3)){
330                         //需要生产
331                         productStation.addAll(collect3.stream().map(BsTechnologyRouteChildInfo::getProcessesCode).collect(Collectors.toList()));
332                     }
333                     //从第一个工位到返修的最大工位之间,
334                     //勾选了返修标记的需要生产---1,未勾选的不生产---2
335                     productStation.addAll(collect1);
336                 }
337             }
338             if (CollUtil.isNotEmpty(productStation)){
339                 List<String> collect2 = allProcessCoed.stream().filter(x -> !productStation.contains(x)).collect(Collectors.toList());
340                 passStation.addAll(collect2);
341             }
342             String[] parts = Node.split("[.]");
343             String par = parts[0]+"."+parts[1];
344             if (CollUtil.isNotEmpty(passStation)){
345                 passStation.forEach(x -> {
346                     ReadWriteEntity readWriteEntity = new ReadWriteEntity();
347                     readWriteEntity.setIdentifier(par+"."+x);
348                     readWriteEntity.setValue(2);
349                     writeList.add(readWriteEntity);
350                 });
351             }
352             if (CollUtil.isNotEmpty(productStation)){
353                 productStation.forEach(x -> {
354                     ReadWriteEntity readWriteEntity = new ReadWriteEntity();
355                     readWriteEntity.setIdentifier(par+"."+x);
356                     readWriteEntity.setValue(1);
357                     writeList.add(readWriteEntity);
358                 });
359             }
e94b2b 360             //对OP755做特殊处理
W 361             List<ReadWriteEntity> OP755List = new ArrayList<>();
362             if (OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){
363                 List<String> patchList = new ArrayList<>();
364                 patchList.add(par+".OP740");
365                 patchList.add(par+".OP760");
366                 patchList.add(par+".OP770");
367                 patchList.add(par+".OP780");
368                 for (String s : patchList) {
369                     ReadWriteEntity readWriteEntity = new ReadWriteEntity();
370                     readWriteEntity.setIdentifier(s);
371                     readWriteEntity.setValue(0);
372                     OP755List.add(readWriteEntity);
373                 }
374             }
929bdc 375             ReadWriteEntity readWriteEntity = new ReadWriteEntity();
W 376             readWriteEntity.setIdentifier(parts[0]+"."+parts[1]+".Repair_sign");
377             readWriteEntity.setValue(minOP);
378             miloService.writeToOpcShort(readWriteEntity);
379             miloService.writeToOpcByte(writeList);
1a444b 380             logger.info("{}返修写入:,{}",SNCode,writeList);
e94b2b 381             if (CollUtil.isNotEmpty(OP755List)){
W 382                 miloService.writeToOpcByte(OP755List);
383             }
929bdc 384         }
W 385
059083 386     }
W 387
388
3e03af 389     public void SaveData(String Node) throws Exception {
28860f 390
059083 391         String[] parts = Node.split("[.]");
3e03af 392         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
3946f8 393         if (null == SNCodeObject){
W 394             SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
395         }
3e03af 396         if(null != SNCodeObject)
C 397         {
398             String SNCode = SNCodeObject.toString();
c76a3f 399             Object object = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Runtime").getValue();
W 400             String gatherAddress = parts[0] + "." + parts[1];
401             List<DaCollectionParamConf> list = new ArrayList<>();
402             if (allCollectParamList.containsKey(gatherAddress)){
403                 list = allCollectParamList.get(gatherAddress);
404             }else {
405                 DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
406                 daCollectionParamConf.setGatherAddress(gatherAddress);
407                 daCollectionParamConf.setRemarks("1");
408                 list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
409                 if (CollUtil.isNotEmpty(list)){
410                     //加入hashmap
411                     allCollectParamList.put(gatherAddress,list);
412                 }
413             }
3e03af 414
C 415             List<String> nodeIdList = list.stream().map(info -> {
416                 String nodeid = info.getGatherAddress();
417                 return nodeid;
418             }).collect(Collectors.toList());
419
f4cb4d 420             List<ReadWriteEntity> readWriteEntityList = new ArrayList<>();
W 421             if(CollUtil.isNotEmpty(nodeIdList)){
1a444b 422                 //long time1 = new Date().getTime();
f4cb4d 423                 readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
1a444b 424                 //long time2 = new Date().getTime();
Y 425                 //logger.info("读取点位花费时间:{},",time2-time1);
f4cb4d 426             }
c76a3f 427                 //返回plc保存成功
W 428                 if (parts.length==3){
429                     if ("SaveRequest".equals(parts[2])){
430                         ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeed", 1);
431                                 miloService.writeToOpcByte(entity);
432                     }else if ("SaveRequestLast".equals(parts[2])){
433                         ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeedLast", 1);
434                                 miloService.writeToOpcByte(entity);
435                     }
1a444b 436                     logger.info("{}保存请求信号返回,MES->PLC的SaveFeedLast信号",Node);
Y 437                     //logger.info("-------请求返回-----,{}",LocalDateTime.now());
c76a3f 438                 }
1a444b 439
Y 440                 BsOrderScheduling bsOrderScheduling=bsOrderSchedulingService.selectBsOrderSchedulingSNCode(SNCode);
441
3e03af 442                 List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
f4cb4d 443                 if (CollUtil.isNotEmpty(nodeIdList)){
W 444                     for(int i=0;i<nodeIdList.size();i++){
127f1b 445                         if(ObjectUtil.isNotEmpty(readWriteEntityList.get(i).getValue()) && !readWriteEntityList.get(i).getValue().toString().equals("0.0")){
f4cb4d 446                             DaParamCollection ParamCollection = new DaParamCollection();
W 447                             ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]);
448                             ParamCollection.setLocationCode(parts[1]);
449                             if (readWriteEntityList.get(i) == null){
450                                 ParamCollection.setParamValue("0");
451                             }else {
452                                 ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
453                             }
454                             ParamCollection.setSfcCode(SNCode);
455                             ParamCollection.setParamName(list.get(i).getCollectParameterName());
456                             ParamCollection.setParamUpper(list.get(i).getParamUpper());
457                             ParamCollection.setParamLower(list.get(i).getParamLower());
458                             ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
459                             ParamCollection.setState("合格");
460                             ParamCollection.setType(list.get(i).getCollectParameterType());
461                             ParamCollection.setCollectionTime(new Date());
1a444b 462                             ParamCollection.setWorkOrderNo(bsOrderScheduling.getOrderNo());
f4cb4d 463                             daParamCollectionlist.add(ParamCollection);
c6aaad 464                         }
3e03af 465                     }
f4cb4d 466                     daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
1a444b 467                     logger.info("{}发动机({})采集数据保存完成",SNCode,Node);
3e03af 468                 }
9e6d86 469             Long beatTime = 0L;
W 470             if (ObjectUtil.isNotEmpty(object)){
9f6314 471                 String str = object.toString();
W 472                 beatTime = Float.valueOf(str).longValue();
9e6d86 473             }
127f1b 474             Object ProductStatus = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".ProductStatus").getValue();
1a444b 475             logger.info("ProductStatus,{}",ProductStatus.toString());
127f1b 476             String str1="合格" ;
Y 477             if (ObjectUtil.isNotEmpty(ProductStatus)){
478                 String productStatusString = ProductStatus.toString();
479                 if (productStatusString.contains("2") || productStatusString.contains("3")){
480                     str1="不合格";
481                 }else {
482                     str1="合格";
483                 }
484             }
9e6d86 485             DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
W 486             PassingStationCollection.setSfcCode(SNCode);
487             PassingStationCollection.setLocationCode(parts[1]);
488             PassingStationCollection.setOutboundTime(new Date());
489             PassingStationCollection.setInboundTime(new Date(new Date().getTime()-beatTime*1000));
490             PassingStationCollection.setCollectionTime(new Date());
491             PassingStationCollection.setCreateTime(new Date());
492             PassingStationCollection.setBeatTime(beatTime.toString());
127f1b 493             PassingStationCollection.setOutRsSign(str1);
1a444b 494             PassingStationCollection.setWorkOrderNo(bsOrderScheduling.getOrderNo());
9e6d86 495             passingStationCollectionServiceImpl.insertDaPassingStationCollection(PassingStationCollection);
1a444b 496             logger.info("{}发动机({})过站数据保存完成",SNCode,Node);
c76a3f 497
1a444b 498             //更新工单状态
Y 499             if ("OP790".equals(parts[1])) {
d4f437 500                 //bsOrderScheduling.setReport20("0");
1a444b 501                 bsOrderScheduling.setProductionStatus("3");
Y 502                 bsOrderScheduling.setFinalAssemblyOfflineTime(new Date());
503             }else if("OP050".equals(parts[1])){
bbc578 504                 bsOrderScheduling.setReport10("0");
1a444b 505                 bsOrderScheduling.setProductionStatus("2");
Y 506                 bsOrderScheduling.setBoxClosingOnlineTime(new Date());
507             }else if("OP120".equals(parts[1])){
d4f437 508                 bsOrderScheduling.setReport20("0");
1a444b 509                 bsOrderScheduling.setFinalAssemblyLaunchTime(new Date());
Y 510                 bsOrderScheduling.setClosingBoxOfflineTime(new Date());
511             }
512             bsOrderScheduling.setQualityStatus(str1);
513             bsOrderScheduling.setCurrentWorkstation(parts[1]);
514             bsOrderSchedulingService.updateBsOrderScheduling(bsOrderScheduling);
059083 515         }
3e03af 516     }
C 517 }