From 386e107222d673a1ea2781a03a7b1b1d28212f58 Mon Sep 17 00:00:00 2001
From: yyt <306727702@qq.com>
Date: 星期六, 17 二月 2024 16:43:10 +0800
Subject: [PATCH] 更新OPCUA

---
 jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java |  170 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 161 insertions(+), 9 deletions(-)

diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java b/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java
index 9189ab9..f168d4b 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java
@@ -7,10 +7,13 @@
 import com.jcdm.main.da.opcuaconfig.init.BeanUtils;
 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
+import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
+import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
 import lombok.extern.slf4j.Slf4j;
 import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
 import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
 
+import java.time.Duration;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -20,43 +23,63 @@
 public class MethodName {
     private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class);
     private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class);
-    private List<DataValue> s=null;
-    public void getSn(String Node, String value) throws Exception {
-        log.info(Node+":"+value);
+    private IDaPassingStationCollectionService daPassingStationCollectionService = BeanUtils.getBean(IDaPassingStationCollectionService.class);
+    public void Transit(String Node, String value) throws Exception {
+        //log.info(Node+":"+value);
         String[] parts = Node.split("[.]");
         ClientHandler clientHandler=new ClientHandler();
         switch (value) {
             case "0":   //鍒濆
-                NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("0").type("short").build();
+                NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("0").type("short").build();
                 Boolean out=clientHandler.write(node);
                 log.info("鑺傜偣:{},鍝嶅簲缁撴灉:{}", node.getIdentifier(),out);
                 break;
             case "1":   //璇锋眰涓嬪彂杩涚珯鐘舵��
-                NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("11").type("short").build();
+                NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("11").type("short").build();
                 Boolean out1=clientHandler.write(node1);
                 log.info("鑺傜偣:{},鍝嶅簲缁撴灉:{}", node1.getIdentifier(),out1);
                 break;
             case "2":   //璇锋眰璁板綍宸ヤ綅鏁版嵁
+                NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
+                String SNCode=clientHandler.read(SN_node);
+                log.info("璇诲彇鑺傜偣:{},缁撴灉:{}", SN_node.getIdentifier(),SNCode);
+                if(SNCode==null){
+                    NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("22").type("short").build();
+                    Boolean out2=clientHandler.write(node2);
+                    break;
+                }
                 List<DaCollectionParamConf> b;
                 DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
-                daCollectionParamConf.setCollectParameterId(parts[0]+"."+parts[1]);
+                daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]);
                 b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
 
                 List<NodeId> nodeId = b.stream().map(info -> {
-                    NodeId nodeid = new NodeId(2,info.getCollectParameterId());
+                    NodeId nodeid = new NodeId(2,info.getGatherAddress());
                     return nodeid;
                 }).collect(Collectors.toList());
                 List<DataValue> s=readValues(nodeId);
-
+                //淇濆瓨PLC閲囬泦鏁版嵁
                 for(int i=0;i<nodeId.size();i++)
                 {
                     DaParamCollection Config=new DaParamCollection();
                     Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]);
                     Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]);
                     Config.setParamValue(s.get(i).getValue().getValue().toString());
+                    Config.setSfcCode(SNCode);
+                    Config.setParamName(b.get(i).getGatherAddress());
                     daParamCollectionService.insertDaParamCollection(Config);
                 }
-                NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("21").type("short").build();
+                //璁板綍杩囩珯锛屽苟璁$畻鑺傛媿銆�
+                DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
+                PassingStationCollection.setSfcCode(SNCode);
+                PassingStationCollection.setLocationCode(parts[1]);
+                PassingStationCollection.setInboundTime(new Date());
+                PassingStationCollection.setOutboundTime(new Date());
+                PassingStationCollection.setCollectionTime(new Date());
+                PassingStationCollection.setBeatTime("56");
+                daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection);
+                //鏇存柊PLC鑺傜偣鐘舵��
+                NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("21").type("short").build();
                 Boolean out2=clientHandler.write(node2);
                 log.info("鑺傜偣:{},鍝嶅簲缁撴灉:{}", node2.getIdentifier(),out2);
                 break;
@@ -64,4 +87,133 @@
                 break;
         }
     }
+
+    public void Transit2(String Node, String value) throws Exception {
+        log.info(Node+":"+value);
+        String[] parts = Node.split("[.]");
+        ClientHandler clientHandler=new ClientHandler();
+        NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
+        String SNCode=clientHandler.read(SN_node);
+        log.info("璇诲彇鑺傜偣:{},缁撴灉:{}", SN_node.getIdentifier(),SNCode);
+        switch (value) {
+            case "0":   //鍒濆
+                NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("0").type("short").build();
+                Boolean out=clientHandler.write(node);
+                log.info("鑺傜偣:{},鍝嶅簲缁撴灉:{}", node.getIdentifier(),out);
+                break;
+            case "1":   //璇锋眰涓嬪彂杩涚珯鐘舵��
+                NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("11").type("short").build();
+                Boolean out1=clientHandler.write(node1);
+                DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
+                PassingStationCollection.setSfcCode(SNCode);
+                PassingStationCollection.setLocationCode(parts[1]);
+                PassingStationCollection.setInboundTime(new Date());
+                daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection);
+                log.info("鑺傜偣:{},鍝嶅簲缁撴灉:{}", node1.getIdentifier(),out1);
+                break;
+            case "2":   //璇锋眰璁板綍宸ヤ綅鏁版嵁
+                List<DaCollectionParamConf> b;
+                DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
+                daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]);
+                b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
+
+                List<NodeId> nodeId = b.stream().map(info -> {
+                    NodeId nodeid = new NodeId(2,info.getGatherAddress());
+                    return nodeid;
+                }).collect(Collectors.toList());
+                List<DataValue> s=readValues(nodeId);
+                //淇濆瓨PLC閲囬泦鏁版嵁
+                for(int i=0;i<nodeId.size();i++)
+                {
+                    DaParamCollection Config=new DaParamCollection();
+                    Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]);
+                    Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]);
+                    Config.setParamValue(s.get(i).getValue().getValue().toString());
+                    Config.setSfcCode(SNCode);
+                    Config.setParamName(b.get(i).getGatherAddress());
+                    daParamCollectionService.insertDaParamCollection(Config);
+                }
+                //鏇存柊鍑虹珯鏃堕棿锛岃绠楄妭鎷嶃��
+                DaPassingStationCollection PSC=new DaPassingStationCollection();
+                PSC.setSfcCode(SNCode);
+                List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC);
+                if(LPSC != null && LPSC.size() > 0){
+                    LPSC.get(0).setOutboundTime(new Date());
+                    LPSC.get(0).setCollectionTime(new Date());
+                    LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime())));
+                    daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0));
+                }
+                //鏇存柊PLC鑺傜偣鐘舵��
+                NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".MesRecordDataDone").value("21").type("short").build();
+                Boolean out2=clientHandler.write(node2);
+                log.info("鑺傜偣:{},鍝嶅簲缁撴灉:{}", node2.getIdentifier(),out2);
+                break;
+            default:
+                break;
+        }
+    }
+
+    public void SNRetrieval(String Node, String value) throws Exception {
+        String[] parts = Node.split("[.]");
+        if(value=="1") {
+            //SN鍙锋绱�
+            ClientHandler clientHandler=new ClientHandler();
+            NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
+            String SNCode=clientHandler.read(SN_node);
+
+            String a=daPassingStationCollectionService.SelectSN(SNCode);
+
+            // 1:OK鍙敓浜� 2:NG涓嶅彲鐢熶骇 3:NG鍙繑宸� 4:PC妫�绱㈠け璐ワ紙鏃犺褰曪級5:PC妫�绱㈠け璐ワ紙杞欢锛�
+            NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".CodeCheckFeed").value(a).type("short").build();
+            Boolean out1=clientHandler.write(node1);
+            DaPassingStationCollection PassingStationCollection=new DaPassingStationCollection();
+            PassingStationCollection.setSfcCode(SNCode);
+            PassingStationCollection.setLocationCode(parts[1]);
+            PassingStationCollection.setInboundTime(new Date());
+            daPassingStationCollectionService.insertDaPassingStationCollection(PassingStationCollection);
+        }
+    }
+    public void SaveData(String Node, String value) throws Exception {
+        String[] parts = Node.split("[.]");
+        if(value=="1") {
+            //閲囬泦鏁版嵁鏈�缁堜繚瀛�
+            ClientHandler clientHandler=new ClientHandler();
+            NodeEntity SN_node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SNCode").value("").type("").build();
+            String SNCode=clientHandler.read(SN_node);
+            List<DaCollectionParamConf> b;
+            DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
+            daCollectionParamConf.setGatherAddress(parts[0]+"."+parts[1]);
+            b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
+
+            List<NodeId> nodeId = b.stream().map(info -> {
+                NodeId nodeid = new NodeId(2,info.getGatherAddress());
+                return nodeid;
+            }).collect(Collectors.toList());
+            List<DataValue> s=readValues(nodeId);
+            //淇濆瓨PLC閲囬泦鏁版嵁
+            for(int i=0;i<nodeId.size();i++)
+            {
+                DaParamCollection Config=new DaParamCollection();
+                Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]);
+                Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]);
+                Config.setParamValue(s.get(i).getValue().getValue().toString());
+                Config.setSfcCode(SNCode);
+                Config.setParamName(b.get(i).getGatherAddress());
+                daParamCollectionService.insertDaParamCollection(Config);
+            }
+            //鏇存柊鍑虹珯鏃堕棿锛岃绠楄妭鎷嶃��
+            DaPassingStationCollection PSC=new DaPassingStationCollection();
+            PSC.setSfcCode(SNCode);
+            List<DaPassingStationCollection> LPSC=daPassingStationCollectionService.selectDaPassingStationCollectionList(PSC);
+            if(LPSC != null && LPSC.size() > 0){
+                LPSC.get(0).setOutboundTime(new Date());
+                LPSC.get(0).setCollectionTime(new Date());
+                LPSC.get(0).setBeatTime(Long.toString(Math.abs(new Date().getTime() - LPSC.get(0).getInboundTime().getTime())));
+                daPassingStationCollectionService.updateDaPassingStationCollection(LPSC.get(0));
+            }
+            //璇锋眰鏈�缁堜繚瀛樺弽棣�:1 淇濆瓨瀹屾垚 2 淇濆瓨澶辫触 3 淇濆瓨澶辫触锛屾暟鎹綅瓒呴暱
+            NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".SaveFeedLast").value("1").type("short").build();
+            Boolean out1=clientHandler.write(node1);
+        }
+    }
 }

--
Gitblit v1.9.3