From 9e6d86cfea30f99668cde150b49abae780239a55 Mon Sep 17 00:00:00 2001
From: wujian <14790700720@163.com>
Date: 星期五, 22 三月 2024 08:38:20 +0800
Subject: [PATCH] change 通信逻辑 fix 相关问题修改

---
 jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java |  227 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 153 insertions(+), 74 deletions(-)

diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
index f7313b2..da17b4d 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -1,6 +1,13 @@
 package com.jcdm.main.plcserver.sub;
 
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.jcdm.main.bs.domain.BsTechnologyRouteChildInfo;
+import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling;
+import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService;
+import com.jcdm.main.bs.technologyRouteChild.service.IBsTechnologyRouteChildInfoService;
 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
 import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig;
@@ -9,13 +16,15 @@
 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
 import com.jcdm.main.da.passingStationCollection.service.impl.DaPassingStationCollectionServiceImpl;
 import com.jcdm.main.plcserver.conf.OPCElement;
+import com.jcdm.main.rm.repairRecord.domain.RmRepairRecord;
+import com.jcdm.main.rm.repairRecord.service.IRmRepairRecordService;
 import com.kangaroohy.milo.model.ReadWriteEntity;
 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
 import com.kangaroohy.milo.service.MiloService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
-import java.text.Format;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -39,16 +48,28 @@
 
     public static final HashMap<String,Integer> map = new HashMap<>();
 
+    public IBsOrderSchedulingService bsOrderSchedulingService;
+
+    public IRmRepairRecordService rmRepairRecordService;
+
+    public IBsTechnologyRouteChildInfoService bsTechnologyRouteChildInfoService;
+
     public OPCUaSubscription(MiloService miloService,
                              IDaCollectionParamConfService collectionParamConfService,
                              IDaParamCollectionService daParamCollectionService,
                              DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl,
-                             List<DaOpcuaConfig> lists) {
+                             IBsOrderSchedulingService bsOrderSchedulingService,
+                             List<DaOpcuaConfig> lists,
+                             IRmRepairRecordService rmRepairRecordService,
+                             IBsTechnologyRouteChildInfoService bsTechnologyRouteChildInfoService) {
         OPCUaSubscription.miloService = miloService;
         this.collectionParamConfService = collectionParamConfService;
         this.daParamCollectionService = daParamCollectionService;
         this.passingStationCollectionServiceImpl = passingStationCollectionServiceImpl;
+        this.bsOrderSchedulingService = bsOrderSchedulingService;
         this.lists = lists;
+        this.rmRepairRecordService = rmRepairRecordService;
+        this.bsTechnologyRouteChildInfoService = bsTechnologyRouteChildInfoService;
 
 
     }
@@ -58,7 +79,7 @@
     public void onSubscribe(String identifier, Object value) {
         String ecpStr = "";//寮傚父璁板綍鏍囪
         try {
-            if(null != value) {
+            if(null != value && "1".equals(value.toString())) {
                 //1銆佹绱N鍙�
                 //2銆佽繃绔欏弬鏁伴噰闆�
                 //3銆佹壂鐮佹灙鏁版嵁鍥炰紶
@@ -72,80 +93,57 @@
                     if (identifier.equals(OPCElement.OP120_ZZ_CODE_CHECK) && "1".equals(value.toString())){
                         //鎬昏涓婄嚎鎵爜浼犺緭鏁版嵁
                         log.info("-------鐩戝惉鍒�,{}鐨勬壂鐮佹灙鎵爜鐨凜ODE_CHECK鐨勪俊鍙�",identifier);
-                        Integer i = map.getOrDefault(identifier + "鐨勬壂鐮佹灙鎵爜鐨凜ODE_CHECK鐨勪俊鍙�",0);
-                        if (0==i){
-                            map.put(identifier + "鐨勬壂鐮佹灙鎵爜鐨凜ODE_CHECK鐨勪俊鍙�",i+1);
-                        }
-                        String[] parts = OPCElement.OP120_ZZ_CODE_CHECK.split("[.]");
-                        Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
-                        if (null != SNCodeObject){
-                            String SNCode = SNCodeObject.toString();
-                            passingStationCollectionServiceImpl.sendMessage(SNCode);
+                        scannerGunMessage();
+                    }
+                }
+                if (collect2.contains(identifier)){
+                    if ("1".equals(value.toString())){
+                        //save
+                        this.SaveData(identifier);
+                        //杩斿洖plc淇濆瓨鎴愬姛
+                        String[] parts = identifier.split("[.]");
+                        if (parts.length==3){
+                            if ("SaveRequest".equals(parts[2])){
+                                ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeed", 1);
+                                log.info("-------鐩戝惉鍒�,{}鐨剆aveRequest鐨勪俊鍙�",identifier);
+                                Integer i = map.getOrDefault(identifier + "鐨剆aveRequest鐨勪俊鍙�",0);
+                                if (0==i){
+                                    map.put(identifier + "鐨剆aveRequest鐨勪俊鍙�",i+1);
+                                }
+//                                miloService.writeToOpcByte(entity);
+                            }else if ("SaveRequestLast".equals(parts[2])){
+                                ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeedLast", 1);
+                                log.info("-------鐩戝惉鍒�,{}鐨凷aveRequestLast鐨勪俊鍙�",identifier);
+                                Integer i = map.getOrDefault(identifier + "鐨凷aveRequestLast鐨勪俊鍙�",0);
+                                if (0==i){
+                                    map.put(identifier + "鐨凷aveRequestLast鐨勪俊鍙�",i+1);
+                                }
+//                                miloService.writeToOpcByte(entity);
+                            }
                         }
                     }
                 }
-                else if (collect2.contains(identifier)){
-                    //save
-                    this.SaveData(identifier);
-                    //杩斿洖plc淇濆瓨鎴愬姛
-                    String[] parts = identifier.split("[.]");
-                    if (parts.length==3){
-                        if ("SaveRequest".equals(parts[2])){
-                            ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeed", 1);
-                            log.info("-------鐩戝惉鍒�,{}鐨剆aveRequest鐨勪俊鍙�",identifier);
-                            Integer i = map.getOrDefault(identifier + "鐨剆aveRequest鐨勪俊鍙�",0);
-                            if (0==i){
-                                map.put(identifier + "鐨剆aveRequest鐨勪俊鍙�",i+1);
-                            }
-//                            miloService.writeToOpcByte(entity);
-                        }else if ("SaveRequestLast".equals(parts[2])){
-                            ReadWriteEntity entity = new ReadWriteEntity(parts[0] + "." + parts[1] + ".SaveFeedLast", 1);
-                            log.info("-------鐩戝惉鍒�,{}鐨凷aveRequestLast鐨勪俊鍙�",identifier);
-                            Integer i = map.getOrDefault(identifier + "鐨凷aveRequestLast鐨勪俊鍙�",0);
-                            if (0==i){
-                                map.put(identifier + "鐨凷aveRequestLast鐨勪俊鍙�",i+1);
-                            }
-//                            miloService.writeToOpcByte(entity);
-                        }
-                    }
 
-
-                }
-
-                //OP010淇濆瓨璇锋眰
-//                if (identifier.equals(OPCElement.OP120_SaveRequestLast) && "1".equals(value.toString())) {
-//                    this.SaveData(OPCElement.OP120_SaveRequestLast);
-//                    //1銆佹洿鏂板伐鍗曟暟鎹�
-//                    //2銆佷繚瀛樿繃绔欓噰闆嗘暟鎹�
-//                    //3銆佷繚瀛樺弬鏁伴噰闆嗘暟鎹�
-//                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesSaveFeed, 1);
-//                    miloService.writeToOpcByte(entity);
-//                }
-//                else if (identifier.equals(OPCElement.OP120_ZZ_CODE_CHECK) && "1".equals(value.toString())){
-//                    //鎬昏涓婄嚎鎵爜浼犺緭鏁版嵁
-//                    String[] parts = OPCElement.OP120_ZZ_CODE_CHECK.split("[.]");
-//                    Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
-//                    if (null != SNCodeObject){
-//                        String SNCode = SNCodeObject.toString();
-//                        passingStationCollectionServiceImpl.sendMessage(SNCode);
-//                    }
-//                }
-//                //OP010璇锋眰妫�绱㈡潯鐮�
-//                else if (identifier.equals(OPCElement.OP010_CodeCheck) && "1".equals(value.toString())) {
-//                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesCodeCheckFeed, 1);
-//                    miloService.writeToOpcByte(entity);
-//                }
             }
 
 
 
         } catch (Exception e) {
-
+            System.out.println(e.getMessage());
         } finally {
             if (!"".equals(ecpStr)) {
                 System.out.println(ecpStr + "\r\n");
 
             }
+        }
+    }
+
+    private void scannerGunMessage() throws Exception {
+        String[] parts = OPCElement.OP120_ZZ_CODE_CHECK.split("[.]");
+        Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
+        if (null != SNCodeObject){
+            String SNCode = SNCodeObject.toString();
+            passingStationCollectionServiceImpl.sendMessage(SNCode);
         }
     }
 
@@ -157,20 +155,83 @@
             if(null != SNCodeObject) {
                 String SNCode=SNCodeObject.toString();
                 String a=passingStationCollectionServiceImpl.SelectSN(SNCode,parts[1]);
+//                String a="1";
                 // 1:OK鍙敓浜� 2:NG涓嶅彲鐢熶骇 3:NG鍙繑宸� 4:PC妫�绱㈠け璐ワ紙鏃犺褰曪級5:PC妫�绱㈠け璐ワ紙杞欢锛�
-                ReadWriteEntity entity = new ReadWriteEntity(parts[0]+"."+parts[1]+".CodeCheckFeed", a);
-                log.info("-------鐩戝惉鍒�,{}鐨凜odeCheck鐨勪俊鍙�",Node);
-                Integer i = map.getOrDefault(Node + "鐨凜odeCheck鐨勪俊鍙�",0);
-                if (0==i){
-                    map.put(Node + "鐨凜odeCheck鐨勪俊鍙�",i+1);
-                }
+                if (StrUtil.isNotBlank(a)){
+                    int input = Integer.parseInt(a);
+                    ReadWriteEntity entity = new ReadWriteEntity(parts[0]+"."+parts[1]+".CodeCheckFeed", input);
+                    log.info("-------鐩戝惉鍒�,{}鐨凜odeCheck鐨勪俊鍙�",Node);
+                    //棣栫珯浼犺緭璁㈠崟鍙�
+                    if (OPCElement.OP050_HX_CODE_CHECK.equals(Node)){
+                        //鏌ヨ璁㈠崟鍙�
+                        BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
+                        bsOrderScheduling.setEngineNo(SNCode);
+                        List<BsOrderScheduling> tempList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
+                        String orderNum = "";
+                        if (CollUtil.isNotEmpty(tempList)){
+                            BsOrderScheduling bsOrderScheduling1 = tempList.get(0);
+                            orderNum = bsOrderScheduling1.getOrderNo();
+                        }
+
+                        ReadWriteEntity entity2 = new ReadWriteEntity(parts[0]+"."+parts[1]+".OrderNumber", orderNum);
+//                        miloService.writeToOpcByte(entity2);
+                    }
+                    //濡傛灉鏄繑淇伐浣嶉渶瑕佷紶杈撹繑淇伐浣嶅彿
+                    if (OPCElement.OP465_ZZ_CODE_CHECK.equals(Node) || OPCElement.OP355_ZZ_CODE_CHECK.equals(Node)){
+                        rework(SNCode);
+                    }
 //                miloService.writeToOpcByte(entity);
-                DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
-                PassingStationCollection.setSfcCode(SNCode);
-                PassingStationCollection.setLocationCode(parts[1]);
-                PassingStationCollection.setInboundTime(new Date());
-                passingStationCollectionServiceImpl.insertDaPassingStationCollection(PassingStationCollection);
+                }
+
             }
+        }
+    }
+
+    private void rework(String SNCode) {
+        BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
+        bsOrderScheduling.setEngineNo(SNCode);
+        List<String> allProcessCoed = new ArrayList<>();
+        List<String> collect = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling).stream().map(BsOrderScheduling::getModel).collect(Collectors.toList());
+        if (CollUtil.isNotEmpty(collect)){
+            String s = collect.get(0);
+            //鏌ユ壘娆℃満鍨嬬殑瀹屾暣宸ュ簭
+            List<BsTechnologyRouteChildInfo> bsTechnologyRouteChildInfos = bsTechnologyRouteChildInfoService.selectAllTechnologyRouteByProductCode(SNCode);
+            if (CollUtil.isNotEmpty(bsTechnologyRouteChildInfos)){
+                allProcessCoed = bsTechnologyRouteChildInfos.stream().map(BsTechnologyRouteChildInfo::getProcessesCode).collect(Collectors.toList());
+            }
+        }
+        RmRepairRecord rmRepairRecord = new RmRepairRecord();
+        rmRepairRecord.setBoxCode(SNCode);
+        List<ReadWriteEntity> writeList = new ArrayList<>();
+        List<RmRepairRecord> rmRepairRecords = rmRepairRecordService.selectRmRepairRecordList(rmRepairRecord);
+        //鎵�鏈夊弽宸ュ伐浣�
+        List<String> collect1 = rmRepairRecords.stream().map(RmRepairRecord::getProcessesCode).collect(Collectors.toList());
+        //鎵�鏈夋斁琛屽伐浣�
+        List<String> collect2 = allProcessCoed;
+        if (CollUtil.isNotEmpty(rmRepairRecords)){
+            //鏁版嵁搴撴煡璇㈠嚭鐨勫伐浣�
+            rmRepairRecords.forEach(x -> {
+                ReadWriteEntity readWriteEntity = new ReadWriteEntity();
+                readWriteEntity.setIdentifier(x.getProcessesCode());
+                readWriteEntity.setValue(1);
+                writeList.add(readWriteEntity);
+            });
+            collect2 = allProcessCoed.stream().filter(x -> !collect1.contains(x)).collect(Collectors.toList());
+        }
+        if (CollUtil.isNotEmpty(collect2)){
+            collect2.forEach(x -> {
+                ReadWriteEntity readWriteEntity = new ReadWriteEntity();
+                readWriteEntity.setIdentifier(x);
+                readWriteEntity.setValue(2);
+                writeList.add(readWriteEntity);
+            });
+        }
+        if (CollUtil.isNotEmpty(writeList)){
+            ReadWriteEntity readWriteEntity = new ReadWriteEntity();
+            readWriteEntity.setIdentifier("Repair_sign");
+            readWriteEntity.setValue(1);
+            writeList.add(readWriteEntity);
+//                            miloService.writeToOpcByte(writeList);
         }
     }
 
@@ -214,6 +275,24 @@
                 }
                 daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
             }
+
+            Object object = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Runtime").getValue();
+            Long beatTime = 0L;
+            if (ObjectUtil.isNotEmpty(object)){
+                beatTime = (Long) object;
+            }
+            DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
+            PassingStationCollection.setSfcCode(SNCode);
+            PassingStationCollection.setLocationCode(parts[1]);
+            PassingStationCollection.setOutboundTime(new Date());
+            PassingStationCollection.setInboundTime(new Date(new Date().getTime()-beatTime*1000));
+            PassingStationCollection.setCollectionTime(new Date());
+            PassingStationCollection.setCreateTime(new Date());
+            PassingStationCollection.setBeatTime(beatTime.toString());
+            PassingStationCollection.setOutRsSign("鍚堟牸");
+            passingStationCollectionServiceImpl.insertDaPassingStationCollection(PassingStationCollection);
+
+
         }
     }
 }

--
Gitblit v1.9.3