春风项目四线(合箱线、总装线)
wujian
2024-07-26 778d3d8b387ca0a8d1b51ef68f783fb0b407ef20
提交 | 用户 | 时间
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;
59e228 6 import com.jcdm.common.core.domain.BaseEntity;
9e6d86 7 import com.jcdm.main.bs.domain.BsTechnologyRouteChildInfo;
W 8 import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling;
9 import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService;
10 import com.jcdm.main.bs.technologyRouteChild.service.IBsTechnologyRouteChildInfoService;
3e03af 11 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
C 12 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
059083 13 import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig;
3e03af 14 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
C 15 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
059083 16 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
59e228 17 import com.jcdm.main.da.passingStationCollection.domain.ProductNewPassStation;
W 18 import com.jcdm.main.da.passingStationCollection.service.ProductNewPassStationService;
059083 19 import com.jcdm.main.da.passingStationCollection.service.impl.DaPassingStationCollectionServiceImpl;
3e03af 20 import com.jcdm.main.plcserver.conf.OPCElement;
9e6d86 21 import com.jcdm.main.rm.repairRecord.domain.RmRepairRecord;
W 22 import com.jcdm.main.rm.repairRecord.service.IRmRepairRecordService;
3e03af 23 import com.kangaroohy.milo.model.ReadWriteEntity;
C 24 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
25 import com.kangaroohy.milo.service.MiloService;
059083 26 import lombok.extern.slf4j.Slf4j;
59e228 27 import org.apache.commons.lang3.ObjectUtils;
1a444b 28 import org.slf4j.Logger;
Y 29 import org.slf4j.LoggerFactory;
3e03af 30 import org.springframework.stereotype.Component;
C 31
9f6314 32 import java.math.BigDecimal;
c76a3f 33 import java.sql.Time;
9e6d86 34 import java.time.LocalDateTime;
c76a3f 35 import java.util.*;
W 36 import java.util.concurrent.TimeUnit;
3e03af 37 import java.util.stream.Collectors;
C 38
39
059083 40 @Slf4j
3e03af 41 @Component
C 42 public class OPCUaSubscription implements SubscriptionCallback {
43
1a444b 44     private static final Logger logger = LoggerFactory.getLogger("sys-user");
3e03af 45     public static MiloService miloService;
C 46
47     public IDaCollectionParamConfService collectionParamConfService;
48
49     public IDaParamCollectionService daParamCollectionService;
50
059083 51     public DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl;
W 52
53     public List<DaOpcuaConfig> lists;
54
55     public static final HashMap<String,Integer> map = new HashMap<>();
56
9e6d86 57     public IBsOrderSchedulingService bsOrderSchedulingService;
W 58
59     public IRmRepairRecordService rmRepairRecordService;
60
61     public IBsTechnologyRouteChildInfoService bsTechnologyRouteChildInfoService;
59e228 62     public ProductNewPassStationService productNewPassStationService;
9e6d86 63
c76a3f 64     public HashMap<String,List<DaCollectionParamConf>> allCollectParamList = new HashMap<>();
W 65
3e03af 66     public OPCUaSubscription(MiloService miloService,
C 67                              IDaCollectionParamConfService collectionParamConfService,
059083 68                              IDaParamCollectionService daParamCollectionService,
W 69                              DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl,
9e6d86 70                              IBsOrderSchedulingService bsOrderSchedulingService,
W 71                              List<DaOpcuaConfig> lists,
72                              IRmRepairRecordService rmRepairRecordService,
59e228 73                              IBsTechnologyRouteChildInfoService bsTechnologyRouteChildInfoService,
W 74                              ProductNewPassStationService productNewPassStationService) {
3e03af 75         OPCUaSubscription.miloService = miloService;
C 76         this.collectionParamConfService = collectionParamConfService;
77         this.daParamCollectionService = daParamCollectionService;
059083 78         this.passingStationCollectionServiceImpl = passingStationCollectionServiceImpl;
9e6d86 79         this.bsOrderSchedulingService = bsOrderSchedulingService;
059083 80         this.lists = lists;
9e6d86 81         this.rmRepairRecordService = rmRepairRecordService;
W 82         this.bsTechnologyRouteChildInfoService = bsTechnologyRouteChildInfoService;
59e228 83         this.productNewPassStationService = productNewPassStationService;
c76a3f 84
W 85
3e03af 86     }
C 87     @Override
88     public void onSubscribe(String identifier, Object value) {
89         String ecpStr = "";//异常记录标记
90         try {
9e6d86 91             if(null != value && "1".equals(value.toString())) {
059083 92                 //1、检索SN号
W 93                 //2、过站参数采集
94                 //3、扫码枪数据回传
95                 List<String> collect1 = lists.stream().filter(x -> OPCElement.SN_CHECK.equals(x.getrFunction()))
96                         .map(DaOpcuaConfig::getNode).collect(Collectors.toList());
97                 List<String> collect2 = lists.stream().filter(x -> OPCElement.SAVE_DATA.equals(x.getrFunction()))
98                         .map(DaOpcuaConfig::getNode).collect(Collectors.toList());
99                 if (collect1.contains(identifier)){
1a444b 100                     logger.info("-------监听到,{}的CODE_CHECK的信号",identifier);
Y 101                     //logger.info("-------time--------------,{}",LocalDateTime.now());
059083 102                     //sn
59e228 103                     if (OPCElement.OP010_CODE_CHECK.equals(identifier)){
W 104                         ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP010.CodeCheckFeed", 1);
105                         OPCUaSubscription.miloService.writeToOpcByte(entity);//写完成
106                     } else if (OPCElement.OP020_CODE_CHECK.equals(identifier)) {
107                         ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP020.CodeCheckFeed", 1);
108                         OPCUaSubscription.miloService.writeToOpcByte(entity);//写完成
109                     } else if (OPCElement.OP030_CODE_CHECK.equals(identifier)) {
110                         ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP030.CodeCheckFeed", 1);
111                         OPCUaSubscription.miloService.writeToOpcByte(entity);//写完成
112                         Object SNCodeObject = miloService.readFromOpcUa("CFL4HX.OP030.Code").getValue();
113                         if (ObjectUtil.isNotEmpty(SNCodeObject)){
114                             String snCode = SNCodeObject.toString();
115                             if (StrUtil.isNotBlank(snCode)){
116                                 String type = productNewFlag(snCode);
117                                 if ("280".equals(type) || "380".equals(type)){
118                                     //获取箱体码
119                                     ProductNewPassStation productNewPassStation = new ProductNewPassStation();
120                                     productNewPassStation.setFinishFlag(OPCElement.UN_FINISH);
121                                     productNewPassStation.setSfcCode(snCode);
122                                     List<ProductNewPassStation> productPassStationList = productNewPassStationService.getProductPassStationList(productNewPassStation);
123                                     if (CollUtil.isNotEmpty(productPassStationList)){
124                                         List<ProductNewPassStation> collect = productPassStationList.stream().sorted(Comparator.comparing(ProductNewPassStation::getCreateTime).reversed()).collect(Collectors.toList());
125                                         ProductNewPassStation productNewPassStation1 = collect.get(0);
126                                         String boxCode = productNewPassStation1.getBoxCode();
127                                         passingStationCollectionServiceImpl.sendMessage(type+"*"+boxCode,"OP030");
128                                     }
129
130                                 }
131                             }
132
dd4482 133                         }
59e228 134                     } else if (OPCElement.OP040_CODE_CHECK.equals(identifier)) {
W 135                         ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP040.CodeCheckFeed", 1);
136                         OPCUaSubscription.miloService.writeToOpcByte(entity);//写完成
137                         //推送数据
138                         log.info("进入OP040.CodeCheck");
139                         tile2("CFL4HX.OP040.CodeCheck");
140                     } else {
141                         this.SNRetrieval(identifier,value.toString());
142                         if (identifier.equals(OPCElement.OP120_ZZ_CODE_CHECK) && "1".equals(value.toString())){
143                             //总装上线扫码传输数据
144                             logger.info("-------监听到,{}的扫码枪扫码的CODE_CHECK的信号",identifier);
145                             scannerGunMessage();
dd4482 146                         }
Y 147                     }
59e228 148
9e6d86 149                 }
W 150                 if (collect2.contains(identifier)){
151                     if ("1".equals(value.toString())){
1a444b 152                         logger.info("-------监听到,{}的SAVE_REQUEST_LAST的信号",identifier);
Y 153                         //logger.info("-------time--------------,{}",LocalDateTime.now());
59e228 154                         //HX线改装
W 155                         if (OPCElement.OP010_REQUEST_PRODUCT_TYPE.equals(identifier)){
156                            Object SNCodeObject = miloService.readFromOpcUa("CFL4HX.OP010.Code").getValue();
157                            if (ObjectUtil.isNotEmpty(SNCodeObject)){
158                                String snCode = SNCodeObject.toString();
159                                ReadWriteEntity entity3 = new ReadWriteEntity("CFL4HX.OP010.ProductTypeSN",snCode);
160                                OPCUaSubscription.miloService.writeToOpcUa(entity3);//写产品SN号反馈
161                                ReadWriteEntity entity2 = new ReadWriteEntity("CFL4HX.OP010.SNDone", 1);
162                                OPCUaSubscription.miloService.writeToOpcByte(entity2);//写完成
163
164                            }
165                         } else if (OPCElement.OP010_SAVE_REQUEST.equals(identifier)) {
166                             ReadWriteEntity entity2 = new ReadWriteEntity("CFL4HX.OP010.SaveFeed", 1);
167                             OPCUaSubscription.miloService.writeToOpcByte(entity2);//写完成
168                         } else if (OPCElement.OP020_PRINT_REQUEST.equals(identifier)) {
169                             Object SNCodeObject = miloService.readFromOpcUa("CFL4HX.OP020.Code").getValue();
170                             if (ObjectUtil.isNotEmpty(SNCodeObject)){
171                                 String snCode = SNCodeObject.toString();
778d3d 172                                 DaPassingStationCollection passingStationCollectionCheck = new DaPassingStationCollection();
W 173                                 passingStationCollectionCheck.setLocationCode("OP020");
174                                 passingStationCollectionCheck.setSfcCode(snCode);
175                                 List<DaPassingStationCollection> checkList = passingStationCollectionServiceImpl.selectDaPassingStationCollectionList(passingStationCollectionCheck);
176                                 if (CollUtil.isNotEmpty(checkList)){
177                                     if (snCode.startsWith("380")){
178                                         log.info("enter-380");
179                                         String[] split = snCode.split(StrUtil.SPACE);
180                                         if (split.length>1){
181                                             ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP020.PrintSN1", split[0]);
182                                             OPCUaSubscription.miloService.writeToOpcUa(entity);//写完成
183                                             ReadWriteEntity entity2 = new ReadWriteEntity("CFL4HX.OP020.PrintSN2", "☆"+split[1]+"☆");
184                                             OPCUaSubscription.miloService.writeToOpcUa(entity2);//写完成
185                                             ReadWriteEntity entity3 = new ReadWriteEntity("CFL4HX.OP020.SendSNDone", 2);
186                                             OPCUaSubscription.miloService.writeToOpcByte(entity3);//写完成
187                                         }
188                                     } else {
189                                         ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP020.PrintSN1", snCode);
190                                         OPCUaSubscription.miloService.writeToOpcByte(entity);//写完成
191                                         ReadWriteEntity entity3 = new ReadWriteEntity("CFL4HX.OP020.SendSNDone", 2);
59e228 192                                         OPCUaSubscription.miloService.writeToOpcByte(entity3);//写完成
W 193                                     }
194                                 } else {
778d3d 195                                     if (snCode.startsWith("380")){
W 196                                         log.info("enter-380");
197                                         String[] split = snCode.split(StrUtil.SPACE);
198                                         if (split.length>1){
199                                             ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP020.PrintSN1", split[0]);
200                                             OPCUaSubscription.miloService.writeToOpcUa(entity);//写完成
201                                             ReadWriteEntity entity2 = new ReadWriteEntity("CFL4HX.OP020.PrintSN2", "☆"+split[1]+"☆");
202                                             OPCUaSubscription.miloService.writeToOpcUa(entity2);//写完成
203                                             ReadWriteEntity entity3 = new ReadWriteEntity("CFL4HX.OP020.SendSNDone", 1);
204                                             OPCUaSubscription.miloService.writeToOpcByte(entity3);//写完成
205                                         }
206                                     } else {
207                                         ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.OP020.PrintSN1", snCode);
208                                         OPCUaSubscription.miloService.writeToOpcByte(entity);//写完成
209                                         ReadWriteEntity entity3 = new ReadWriteEntity("CFL4HX.OP020.SendSNDone", 1);
210                                         OPCUaSubscription.miloService.writeToOpcByte(entity3);//写完成
211                                     }
59e228 212                                 }
778d3d 213
59e228 214                             }
W 215                         } else if (OPCElement.OP030_SAVE_REQUEST.equals(identifier)) {
d2daac 216                             cleanForm("CFL4HX.OP030.SaveFeed");
59e228 217                             ReadWriteEntity entity2 = new ReadWriteEntity("CFL4HX.OP030.SaveFeed", 1);
W 218                             OPCUaSubscription.miloService.writeToOpcByte(entity2);//写完成
d2daac 219
59e228 220                         } else if (OPCElement.OP040_SAVE_REQUEST.equals(identifier)) {
W 221                             cleanForm040(OPCElement.OP040_SAVE_REQUEST);
222                             ReadWriteEntity entity2 = new ReadWriteEntity("CFL4HX.OP040.SaveFeed", 1);
223                             OPCUaSubscription.miloService.writeToOpcByte(entity2);//写完成
224                         } else {
225                             this.SaveData(identifier);
226                         }
227
059083 228                     }
W 229                 }
3e03af 230             }
C 231         } catch (Exception e) {
9e6d86 232             System.out.println(e.getMessage());
3e03af 233         } finally {
C 234             if (!"".equals(ecpStr)) {
235                 System.out.println(ecpStr + "\r\n");
236             }
9e6d86 237         }
W 238     }
239
240     private void scannerGunMessage() throws Exception {
241         String[] parts = OPCElement.OP120_ZZ_CODE_CHECK.split("[.]");
242         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
3946f8 243         if (null == SNCodeObject){
W 244             SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
245         }
9e6d86 246         if (null != SNCodeObject){
W 247             String SNCode = SNCodeObject.toString();
1c7036 248             passingStationCollectionServiceImpl.sendMessage(SNCode,"OP120");
3e03af 249         }
C 250     }
251
059083 252     public void SNRetrieval(String Node, String value) throws Exception {
W 253         String[] parts = Node.split("[.]");
254         if(value.equals("1")) {
255             //SN号检索
256             Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
257             if(null != SNCodeObject) {
258                 String SNCode=SNCodeObject.toString();
1c7036 259 //              String a=passingStationCollectionServiceImpl.SelectSN(SNCode,parts[1]);
929bdc 260                 String a;
W 261                 BsOrderScheduling bsOrderSchedulingQuery = new BsOrderScheduling();
262                 bsOrderSchedulingQuery.setEngineNo(SNCode);
263                 List<BsOrderScheduling> queryOrderList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderSchedulingQuery);
264                 if (CollUtil.isNotEmpty(queryOrderList)){
265                     a = "1";
266                 }else {
0e3cac 267                     a = "4";
929bdc 268                 }
W 269                 //如果是返修工位需要传输返修工位号
0e3cac 270                 List<DaPassingStationCollection> daPassingStationCollections = new ArrayList<>();
W 271                 List<RmRepairRecord> rmRepairRecords = new ArrayList<>();
929bdc 272                 if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node)
W 273                         || OPCElement.OP695_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){
274                     //过站记录
275                     DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
276                     PassingStationCollection.setSfcCode(SNCode);
0e3cac 277                     daPassingStationCollections = passingStationCollectionServiceImpl.selectDaPassingStationCollectionList(PassingStationCollection);
45f460 278 //                    if (CollUtil.isNotEmpty(daPassingStationCollections)){
Y 279 //                        DaPassingStationCollection lastOne = daPassingStationCollections.get(daPassingStationCollections.size() - 1);
280 //                        String outRsSign = lastOne.getOutRsSign();
281 //                        if ("合格".equals(outRsSign)){
282 //                            a = "1";
283 //                        }else {
284 //                            a = "2";
285 //                        }
286 //                    }
0e3cac 287                     RmRepairRecord rmRepairRecord = new RmRepairRecord();
W 288                     rmRepairRecord.setBoxCode(SNCode);
289                     rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord);
290                     if (CollUtil.isNotEmpty(rmRepairRecords)){
291                         a = "1";
45f460 292                     }else {
Y 293                         a = "2";
0e3cac 294                     }
929bdc 295                 }
1a444b 296                 logger.info("-----返回codeCheckFeed-----,{}",a);
3946f8 297 //                String a="1";
059083 298                 // 1:OK可生产 2:NG不可生产 3:NG可返工 4:PC检索失败(无记录)5:PC检索失败(软件)
9e6d86 299                 if (StrUtil.isNotBlank(a)){
W 300                     int input = Integer.parseInt(a);
301                     ReadWriteEntity entity = new ReadWriteEntity(parts[0]+"."+parts[1]+".CodeCheckFeed", input);
5030f3 302                     logger.info("发动机号:{},监听到{}的CodeCheck的信号",SNCode,Node);
cffac1 303                     miloService.writeToOpcByte(entity);
1a444b 304                     logger.info("监听到返回codecheckfeed信号,{}",entity);
9e6d86 305                     //首站传输订单号
59e228 306 //                    if (OPCElement.OP050_HX_CODE_CHECK.equals(Node)){
W 307 //                        //查询订单号
308 //                        BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
309 //                        bsOrderScheduling.setEngineNo(SNCode);
310 //                        List<BsOrderScheduling> tempList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
311 //                        String orderNum = "";
312 //                        if (CollUtil.isNotEmpty(tempList)){
313 //                            BsOrderScheduling bsOrderScheduling1 = tempList.get(0);
314 //                            orderNum = bsOrderScheduling1.getOrderNo();
315 //                        }
316 //                        ReadWriteEntity entity2 = new ReadWriteEntity(parts[0]+"."+parts[1]+".OrderNumber", orderNum);
317 //                        miloService.writeToOpcUa(entity2);
318 //                    }
9e6d86 319                     //如果是返修工位需要传输返修工位号
3946f8 320                     if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node)
W 321                     || OPCElement.OP695_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){
0e3cac 322                         rework(SNCode,Node,daPassingStationCollections,rmRepairRecords);
9e6d86 323                     }
59e228 324                     if (OPCElement.OP050_CODE_CHECK.equals(Node)) {
W 325                         //新机型050
326                         String type = productNewFlag(SNCode);
327                         if ("280".equals(type) || "380".equals(type)){
328                             ProductNewPassStation productNewPassStation = new ProductNewPassStation();
329                             productNewPassStation.setSfcCode(SNCode);
330                             List<ProductNewPassStation> passStationList = productNewPassStationService.getProductPassStationList(productNewPassStation);
331                             ProductNewPassStation productNewPassStation2 = new ProductNewPassStation();
332                             productNewPassStation2.setFinishFlag("0");
333                             List<ProductNewPassStation> collect = productNewPassStationService.getProductPassStationList(productNewPassStation2)
334                                     .stream().sorted(Comparator.comparing(ProductNewPassStation::getCreateTime))
335                                     .collect(Collectors.toList());
336                             String partSfcCode = "";
337                             if (CollUtil.isNotEmpty(collect)){
338                                 ProductNewPassStation passStation = collect.get(0);
339                                 partSfcCode = passStation.getSfcCode();
340                             }
341                             if (CollUtil.isNotEmpty(passStationList)){
342                                 ProductNewPassStation passStation = passStationList.get(0);
343                                 String productType = "";
344                                 if (ObjectUtils.isNotEmpty(passStation)){
345                                     productType = passStation.getProductType();
346                                 }
347                                 passingStationCollectionServiceImpl.sendMessage(SNCode+"*sfcCode*"+productType+"*"+partSfcCode,"OP050");
348                             }
349                         }
350                     }
351                     if (OPCElement.OP060_CODE_CHECK.equals(Node)){
352                         String type = productNewFlag(SNCode);
353                         if ("280".equals(type) || "380".equals(type)){
354                             checkBoxRod(Node);
355                         }
d4f437 356                     }
3946f8 357                     System.out.println(entity);
cffac1 358
9e6d86 359                 }
W 360
059083 361             }
9e6d86 362         }
W 363     }
364
0e3cac 365     private void rework(String SNCode,String Node,List<DaPassingStationCollection> daPassingStationCollections,List<RmRepairRecord> rmRepairRecords)  throws Exception{
9e6d86 366         BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
W 367         bsOrderScheduling.setEngineNo(SNCode);
368         List<String> allProcessCoed = new ArrayList<>();
929bdc 369         List<BsTechnologyRouteChildInfo> bsTechnologyRouteChildInfos = new ArrayList<>();
9e6d86 370         List<String> collect = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling).stream().map(BsOrderScheduling::getModel).collect(Collectors.toList());
W 371         if (CollUtil.isNotEmpty(collect)){
372             String s = collect.get(0);
373             //查找次机型的完整工序
929bdc 374             bsTechnologyRouteChildInfos = bsTechnologyRouteChildInfoService.selectAllTechnologyRouteByProductCode(s);
9e6d86 375             if (CollUtil.isNotEmpty(bsTechnologyRouteChildInfos)){
W 376                 allProcessCoed = bsTechnologyRouteChildInfos.stream().map(BsTechnologyRouteChildInfo::getProcessesCode).collect(Collectors.toList());
377             }
378         }
0e3cac 379 //        RmRepairRecord rmRepairRecord = new RmRepairRecord();
W 380 //        rmRepairRecord.setBoxCode(SNCode);
9e6d86 381         List<ReadWriteEntity> writeList = new ArrayList<>();
0e3cac 382 //        List<RmRepairRecord> rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord);
3946f8 383         //过站记录
0e3cac 384 //        DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
W 385 //        PassingStationCollection.setSfcCode(SNCode);
3946f8 386         //过站记录
0e3cac 387 //        List<DaPassingStationCollection> daPassingStationCollections = passingStationCollectionServiceImpl.selectDaPassingStationCollectionList(PassingStationCollection);
3946f8 388
1a444b 389         //所有返工工位
9e6d86 390         List<String> collect1 = rmRepairRecords.stream().map(RmRepairRecord::getProcessesCode).collect(Collectors.toList());
3946f8 391         if (CollUtil.isNotEmpty(collect1)){
929bdc 392             //查询出所有需要返修工位的最小op块
W 393             Integer minOP = 0;
394             if (CollUtil.isNotEmpty(collect1)){
3946f8 395
929bdc 396                 List<Integer> sortList = new ArrayList<>();
W 397                 collect1.stream().forEach(x ->{
398                     String op = x.replace("OP", "");
399                     if (StrUtil.isNotBlank(op)){
400                         int i = Integer.parseInt(op);
401                         sortList.add(i);
402                     }
403                 });
404                 if (CollUtil.isNotEmpty(sortList)){
405                     List<Integer> collect2 = sortList.stream().filter(Objects::nonNull).sorted().collect(Collectors.toList());
406                     minOP = collect2.get(0);
3946f8 407                 }
W 408             }
929bdc 409             //获取过站记录的最大工位
W 410             String maxCode = null;
411             if (CollUtil.isNotEmpty(daPassingStationCollections)){
9bc510 412                 List<DaPassingStationCollection> collect2 = daPassingStationCollections.stream().filter(x -> "不合格".equals(x.getOutRsSign())).collect(Collectors.toList());
W 413                 if (CollUtil.isNotEmpty(collect2)){
414                     DaPassingStationCollection lastOne = collect2.get(collect2.size() - 1);
415                     maxCode = lastOne.getLocationCode();
416                 }else {
417                     DaPassingStationCollection lastOne = daPassingStationCollections.get(daPassingStationCollections.size() - 1);
418                     maxCode = lastOne.getLocationCode();
419                 }
420
28860f 421             }
929bdc 422             //所有放行工位
W 423             List<String> passStation = new ArrayList<>();
424             //所有生产工位
425             List<String> productStation = new ArrayList<>();
426             //最大工位编号
427             Integer maxCodeNum = 0;
428             if (StrUtil.isNotEmpty(maxCode)){
429                 String finalMaxCode = maxCode;
430                 //获取当前工位对应工步号
431                 List<String> collect2 = bsTechnologyRouteChildInfos.stream()
432                         .filter(x -> x.getProcessesCode().equals(finalMaxCode))
433                         .map(BsTechnologyRouteChildInfo::getStepNo).collect(Collectors.toList());
434                 if (CollUtil.isNotEmpty(collect2)){
435                     String s = collect2.get(0);
436                     if (StrUtil.isNotBlank(s)){
437                         maxCodeNum = Integer.parseInt(s);
438                     }
439                 }
440                 if (CollUtil.isNotEmpty(bsTechnologyRouteChildInfos)){
441                     bsTechnologyRouteChildInfos.forEach(x -> {
442                         x.setStepNoNum(Integer.parseInt(x.getStepNo()));
443                     });
444                     Integer finalMaxCodeNum = maxCodeNum;
445                     //勾选的返修工位中最大的工位之后的工位----1
446                     List<BsTechnologyRouteChildInfo> collect3 = bsTechnologyRouteChildInfos.stream()
a4c4c1 447                             .filter(x -> x.getStepNoNum() > finalMaxCodeNum).collect(Collectors.toList());
929bdc 448                     if (CollUtil.isNotEmpty(collect3)){
W 449                         //需要生产
450                         productStation.addAll(collect3.stream().map(BsTechnologyRouteChildInfo::getProcessesCode).collect(Collectors.toList()));
451                     }
452                     //从第一个工位到返修的最大工位之间,
453                     //勾选了返修标记的需要生产---1,未勾选的不生产---2
454                     productStation.addAll(collect1);
455                 }
456             }
457             if (CollUtil.isNotEmpty(productStation)){
458                 List<String> collect2 = allProcessCoed.stream().filter(x -> !productStation.contains(x)).collect(Collectors.toList());
459                 passStation.addAll(collect2);
460             }
461             String[] parts = Node.split("[.]");
462             String par = parts[0]+"."+parts[1];
463             if (CollUtil.isNotEmpty(passStation)){
464                 passStation.forEach(x -> {
465                     ReadWriteEntity readWriteEntity = new ReadWriteEntity();
466                     readWriteEntity.setIdentifier(par+"."+x);
467                     readWriteEntity.setValue(2);
468                     writeList.add(readWriteEntity);
469                 });
470             }
471             if (CollUtil.isNotEmpty(productStation)){
472                 productStation.forEach(x -> {
473                     ReadWriteEntity readWriteEntity = new ReadWriteEntity();
474                     readWriteEntity.setIdentifier(par+"."+x);
475                     readWriteEntity.setValue(1);
476                     writeList.add(readWriteEntity);
477                 });
478             }
e94b2b 479             //对OP755做特殊处理
W 480             List<ReadWriteEntity> OP755List = new ArrayList<>();
481             if (OPCElement.OP755_ZZ_CODE_CHECK.equals(Node)){
482                 List<String> patchList = new ArrayList<>();
483                 patchList.add(par+".OP740");
484                 patchList.add(par+".OP760");
485                 patchList.add(par+".OP770");
486                 patchList.add(par+".OP780");
487                 for (String s : patchList) {
488                     ReadWriteEntity readWriteEntity = new ReadWriteEntity();
489                     readWriteEntity.setIdentifier(s);
490                     readWriteEntity.setValue(0);
491                     OP755List.add(readWriteEntity);
492                 }
493             }
929bdc 494             ReadWriteEntity readWriteEntity = new ReadWriteEntity();
W 495             readWriteEntity.setIdentifier(parts[0]+"."+parts[1]+".Repair_sign");
496             readWriteEntity.setValue(minOP);
497             miloService.writeToOpcShort(readWriteEntity);
498             miloService.writeToOpcByte(writeList);
1a444b 499             logger.info("{}返修写入:,{}",SNCode,writeList);
e94b2b 500             if (CollUtil.isNotEmpty(OP755List)){
W 501                 miloService.writeToOpcByte(OP755List);
502             }
929bdc 503         }
W 504
059083 505     }
W 506
507
3e03af 508     public void SaveData(String Node) throws Exception {
28860f 509
059083 510         String[] parts = Node.split("[.]");
3e03af 511         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
3946f8 512         if (null == SNCodeObject){
W 513             SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
514         }
3e03af 515         if(null != SNCodeObject)
C 516         {
517             String SNCode = SNCodeObject.toString();
c76a3f 518             Object object = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Runtime").getValue();
W 519             String gatherAddress = parts[0] + "." + parts[1];
520             List<DaCollectionParamConf> list = new ArrayList<>();
521             if (allCollectParamList.containsKey(gatherAddress)){
522                 list = allCollectParamList.get(gatherAddress);
523             }else {
524                 DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
525                 daCollectionParamConf.setGatherAddress(gatherAddress);
526                 daCollectionParamConf.setRemarks("1");
527                 list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
528                 if (CollUtil.isNotEmpty(list)){
529                     //加入hashmap
530                     allCollectParamList.put(gatherAddress,list);
531                 }
532             }
59e228 533             //60只采集老车型
W 534             if (OPCElement.OP060_SAVE_REQUEST.equals(Node) || OPCElement.OP060_SAVE_REQUEST_LAST.equals(Node)){
535                 String s = productNewFlag(SNCode);
536                 if ("280".equals(s) || "380".equals(s)){
537                     list = new ArrayList<>();
538                 }
539             }
540             //80、100只采集新车型
541             if (OPCElement.OP080_SAVE_REQUEST.equals(Node)
542                     || OPCElement.OP080_SAVE_REQUEST_LAST.equals(Node)
543                     || OPCElement.OP100_SAVE_REQUEST.equals(Node)
544                     || OPCElement.OP100_SAVE_REQUEST_LAST.equals(Node)){
545                 String s = productNewFlag(SNCode);
546                 if (StrUtil.isNotEmpty(s)){
547                     if (!"280".equals(s) && !"380".equals(s)){
548                         list = new ArrayList<>();
549                     }
550                 }
3e03af 551
59e228 552             }
3e03af 553             List<String> nodeIdList = list.stream().map(info -> {
C 554                 String nodeid = info.getGatherAddress();
555                 return nodeid;
556             }).collect(Collectors.toList());
557
f4cb4d 558             List<ReadWriteEntity> readWriteEntityList = new ArrayList<>();
W 559             if(CollUtil.isNotEmpty(nodeIdList)){
1a444b 560                 //long time1 = new Date().getTime();
f4cb4d 561                 readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
1a444b 562                 //long time2 = new Date().getTime();
Y 563                 //logger.info("读取点位花费时间:{},",time2-time1);
f4cb4d 564             }
c76a3f 565                 //返回plc保存成功
W 566                 if (parts.length==3){
567                     if ("SaveRequest".equals(parts[2])){
59e228 568                         if (OPCElement.OP050_SAVE_REQUEST.equals(Node)){
W 569                             cleanForm050(Node);
570                         } else if (OPCElement.OP060_SAVE_REQUEST.equals(Node)){
571                             cleanForm060(Node);
572                         }
c76a3f 573                         ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeed", 1);
W 574                                 miloService.writeToOpcByte(entity);
575                     }else if ("SaveRequestLast".equals(parts[2])){
59e228 576                         if (OPCElement.OP050_SAVE_REQUEST_LAST.equals(Node)){
W 577                             cleanForm050(Node);
578                         } else if (OPCElement.OP060_SAVE_REQUEST_LAST.equals(Node)){
579                             cleanForm060(Node);
580                         }
c76a3f 581                         ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeedLast", 1);
W 582                                 miloService.writeToOpcByte(entity);
583                     }
1a444b 584                     logger.info("{}保存请求信号返回,MES->PLC的SaveFeedLast信号",Node);
Y 585                     //logger.info("-------请求返回-----,{}",LocalDateTime.now());
c76a3f 586                 }
1a444b 587
Y 588                 BsOrderScheduling bsOrderScheduling=bsOrderSchedulingService.selectBsOrderSchedulingSNCode(SNCode);
589
3e03af 590                 List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
f4cb4d 591                 if (CollUtil.isNotEmpty(nodeIdList)){
W 592                     for(int i=0;i<nodeIdList.size();i++){
127f1b 593                         if(ObjectUtil.isNotEmpty(readWriteEntityList.get(i).getValue()) && !readWriteEntityList.get(i).getValue().toString().equals("0.0")){
f4cb4d 594                             DaParamCollection ParamCollection = new DaParamCollection();
W 595                             ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]);
596                             ParamCollection.setLocationCode(parts[1]);
597                             if (readWriteEntityList.get(i) == null){
598                                 ParamCollection.setParamValue("0");
599                             }else {
600                                 ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
601                             }
602                             ParamCollection.setSfcCode(SNCode);
603                             ParamCollection.setParamName(list.get(i).getCollectParameterName());
604                             ParamCollection.setParamUpper(list.get(i).getParamUpper());
605                             ParamCollection.setParamLower(list.get(i).getParamLower());
606                             ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
607                             ParamCollection.setState("合格");
608                             ParamCollection.setType(list.get(i).getCollectParameterType());
609                             ParamCollection.setCollectionTime(new Date());
1a444b 610                             ParamCollection.setWorkOrderNo(bsOrderScheduling.getOrderNo());
f4cb4d 611                             daParamCollectionlist.add(ParamCollection);
c6aaad 612                         }
3e03af 613                     }
f4cb4d 614                     daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
1a444b 615                     logger.info("{}发动机({})采集数据保存完成",SNCode,Node);
3e03af 616                 }
59e228 617
127f1b 618             Object ProductStatus = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".ProductStatus").getValue();
Y 619             String str1="合格" ;
620             if (ObjectUtil.isNotEmpty(ProductStatus)){
59e228 621                 logger.info("ProductStatus,{}",ProductStatus.toString());
127f1b 622                 String productStatusString = ProductStatus.toString();
Y 623                 if (productStatusString.contains("2") || productStatusString.contains("3")){
624                     str1="不合格";
625                 }else {
626                     str1="合格";
627                 }
59e228 628             }
W 629             Long beatTime = 0L;
630             if (ObjectUtil.isNotEmpty(object)){
631                 String str = object.toString();
632                 beatTime = Float.valueOf(str).longValue();
127f1b 633             }
9e6d86 634             DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
W 635             PassingStationCollection.setSfcCode(SNCode);
636             PassingStationCollection.setLocationCode(parts[1]);
637             PassingStationCollection.setOutboundTime(new Date());
638             PassingStationCollection.setInboundTime(new Date(new Date().getTime()-beatTime*1000));
639             PassingStationCollection.setCollectionTime(new Date());
640             PassingStationCollection.setCreateTime(new Date());
641             PassingStationCollection.setBeatTime(beatTime.toString());
127f1b 642             PassingStationCollection.setOutRsSign(str1);
1a444b 643             PassingStationCollection.setWorkOrderNo(bsOrderScheduling.getOrderNo());
9e6d86 644             passingStationCollectionServiceImpl.insertDaPassingStationCollection(PassingStationCollection);
1a444b 645             logger.info("{}发动机({})过站数据保存完成",SNCode,Node);
c76a3f 646
1a444b 647             //更新工单状态
Y 648             if ("OP790".equals(parts[1])) {
d4f437 649                 //bsOrderScheduling.setReport20("0");
1a444b 650                 bsOrderScheduling.setProductionStatus("3");
Y 651                 bsOrderScheduling.setFinalAssemblyOfflineTime(new Date());
652             }else if("OP050".equals(parts[1])){
bbc578 653                 bsOrderScheduling.setReport10("0");
1a444b 654                 bsOrderScheduling.setProductionStatus("2");
Y 655                 bsOrderScheduling.setBoxClosingOnlineTime(new Date());
656             }else if("OP120".equals(parts[1])){
d4f437 657                 bsOrderScheduling.setReport20("0");
1a444b 658                 bsOrderScheduling.setFinalAssemblyLaunchTime(new Date());
Y 659                 bsOrderScheduling.setClosingBoxOfflineTime(new Date());
660             }
661             bsOrderScheduling.setQualityStatus(str1);
662             bsOrderScheduling.setCurrentWorkstation(parts[1]);
663             bsOrderSchedulingService.updateBsOrderScheduling(bsOrderScheduling);
059083 664         }
3e03af 665     }
59e228 666
W 667
668     public String productNewFlag(String SNCode){
669         String type;
670         if (SNCode.startsWith("280")){
671             type = "280";
672         } else if (SNCode.startsWith("380")){
673             type = "380";
674         }else {
675             type = "oldType";
676         }
677         return type;
678     }
679
680     public void tile2(String Node) throws Exception {
681         String[] parts = Node.split("[.]");
682         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
683         if (null != SNCodeObject) {
684             String SNCode = SNCodeObject.toString();
685             String productNewFlag = productNewFlag(SNCode);
686             if ("380".equals(productNewFlag)){
687                 ProductNewPassStation passStation = new ProductNewPassStation();
688                 passStation.setSfcCode(SNCode);
689                 List<ProductNewPassStation> productPassStationList = productNewPassStationService.getProductPassStationList(passStation);
690                 if (CollUtil.isNotEmpty(productPassStationList)){
691                     ProductNewPassStation productNewPassStation = productPassStationList.get(0);
692                     String boxCode = productNewPassStation.getBoxCode();
693                     String productType = productNewPassStation.getProductType();
d2daac 694                     log.info("发送到OP040的页面数据productType,{}",productType);
W 695                     log.info("发送到OP040的页面数据boxCode,{}",boxCode);
59e228 696                     passingStationCollectionServiceImpl.sendMessage(productType+"*"+boxCode, "OP040");
W 697                 }
698             } else if ("280".equals(productNewFlag)){
699
700             }
701         }
702     }
703
704
705     public void cleanForm(String Node) throws Exception {
706         String[] parts = Node.split("[.]");
707         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
708         if (ObjectUtils.isNotEmpty(SNCodeObject)){
709             String snCode = SNCodeObject.toString();
710             String s = productNewFlag(snCode);
711             if ("280".equals(s) || "380".equals(s)){
d2daac 712                 log.info("发送到OP030的清除");
59e228 713                 passingStationCollectionServiceImpl.sendMessage("clean","OP030");
W 714             }
715         }
716
717     }
718
719     public void cleanForm040(String Node) throws Exception {
720         String[] parts = Node.split("[.]");
721         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
722         if (ObjectUtils.isNotEmpty(SNCodeObject)){
723             String snCode = SNCodeObject.toString();
724             String s = productNewFlag(snCode);
725             if ("280".equals(s) || "380".equals(s)){
d2daac 726                 log.info("发送到OP040的页面清除");
59e228 727                 passingStationCollectionServiceImpl.sendMessage("clean*clean","OP040");
W 728             }
729         }
730     }
731
732     public void cleanForm050(String Node) throws Exception {
733         String[] parts = Node.split("[.]");
734         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
735         if (ObjectUtils.isNotEmpty(SNCodeObject)){
736             String snCode = SNCodeObject.toString();
737             String s = productNewFlag(snCode);
738             if ("280".equals(s) || "380".equals(s)){
739                 ProductNewPassStation passStation = new ProductNewPassStation();
740                 passStation.setSfcCode(snCode);
741                 List<ProductNewPassStation> productPassStationList = productNewPassStationService.getProductPassStationList(passStation);
742                 if (CollUtil.isNotEmpty(productPassStationList)){
743                     productNewPassStationService.updatePassStationBySfcCode(snCode);
744                 }
745                 passingStationCollectionServiceImpl.sendMessage("clean*clean","OP050");
746             }
747         }
748     }
749
750     public void cleanForm060(String Node) throws Exception {
751         String[] parts = Node.split("[.]");
752         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
753         if (ObjectUtils.isNotEmpty(SNCodeObject)){
754             String snCode = SNCodeObject.toString();
755             String s = productNewFlag(snCode);
756             if ("280".equals(s) || "380".equals(s)){
757                 passingStationCollectionServiceImpl.sendMessage("clean*clean","OP060");
758             }
759         }
760     }
761
762
763     public void checkBoxRod(String Node) throws Exception {
764         String[] parts = Node.split("[.]");
765         Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code").getValue();
766         if (null != SNCodeObject) {
767             String SNCode = SNCodeObject.toString();
768             String s = productNewFlag(SNCode);
769             if ("280".equals(s) || "380".equals(s)){
770                 sendTo060(SNCode,parts);
771             }
772         }
773     }
774
775     private void sendTo060(String SNCode, String[] parts) throws Exception {
776         String boxCode = "";
777         String rodCode = "";
778         ProductNewPassStation productNewPassStation = new ProductNewPassStation();
779         productNewPassStation.setSfcCode(SNCode);
780         List<ProductNewPassStation> productPassStationList = productNewPassStationService.getProductPassStationList(productNewPassStation);
781         if (CollUtil.isNotEmpty(productPassStationList)){
782             ProductNewPassStation passStation = productPassStationList.get(0);
783             boxCode = passStation.getBoxCode();
784             rodCode = passStation.getRodCode();
785         }
786         //配瓦校验
787         passingStationCollectionServiceImpl.sendMessage(boxCode + "*" + rodCode + "*" + SNCode, parts[1]);
788     }
3e03af 789 }