From 3e03aff9ec8dde400f7323adba77e05f39fad8e9 Mon Sep 17 00:00:00 2001
From: cl <418351270@qq.com>
Date: 星期二, 05 三月 2024 14:11:07 +0800
Subject: [PATCH] 更新OPC

---
 jcdm-main/src/main/java/com/jcdm/main/plcserver/conf/OPCElement.java                         |   28 +++++
 /dev/null                                                                                    |   47 ---------
 jcdm-main/pom.xml                                                                            |   37 +------
 jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/controller/DaOpcuaConfigController.java |    5 
 jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java                            |   53 ++++++++++
 jcdm-admin/src/main/resources/application.yml                                                |    8 +
 jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java                   |  111 ++++++++++++++++++++++
 7 files changed, 208 insertions(+), 81 deletions(-)

diff --git a/jcdm-admin/src/main/resources/application.yml b/jcdm-admin/src/main/resources/application.yml
index 07f8ac5..33f46ba 100644
--- a/jcdm-admin/src/main/resources/application.yml
+++ b/jcdm-admin/src/main/resources/application.yml
@@ -130,3 +130,11 @@
   excludes: /system/notice
   # 鍖归厤閾炬帴
   urlPatterns: /system/*,/monitor/*,/tool/*
+
+kangaroohy:
+  milo:
+    primary: default
+    config:
+      default:
+        endpoint: opc.tcp://127.0.0.1:49320
+        security-policy: none
\ No newline at end of file
diff --git a/jcdm-main/pom.xml b/jcdm-main/pom.xml
index 80cbe95..3e9eefe 100644
--- a/jcdm-main/pom.xml
+++ b/jcdm-main/pom.xml
@@ -37,37 +37,6 @@
             </exclusions>
         </dependency>
 
-        <!--Server SDK渚濊禆-->
-        <dependency>
-            <groupId>org.eclipse.milo</groupId>
-            <artifactId>sdk-server</artifactId>
-            <version>0.3.6</version>
-        </dependency>
-
-        <!--Client SDK渚濊禆-->
-        <dependency>
-            <groupId>org.eclipse.milo</groupId>
-            <artifactId>sdk-client</artifactId>
-            <version>0.3.6</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.eclipse.milo</groupId>
-            <artifactId>stack-client</artifactId>
-            <version>0.3.6</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.eclipse.milo</groupId>
-            <artifactId>stack-client</artifactId>
-            <version>0.3.6</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.eclipse.milo</groupId>
-            <artifactId>stack-server</artifactId>
-            <version>0.3.6</version>
-        </dependency>
 
         <dependency>
             <groupId>org.projectlombok</groupId>
@@ -105,6 +74,12 @@
             <groupId>com.jcdm</groupId>
             <artifactId>jcdm-system</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>com.kangaroohy</groupId>
+            <artifactId>milo-spring-boot-starter</artifactId>
+            <version>3.0.5</version>
+        </dependency>
     </dependencies>
 
 </project>
\ No newline at end of file
diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/KeyStoreLoader.java b/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/KeyStoreLoader.java
deleted file mode 100644
index 9b6a4e0..0000000
--- a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/KeyStoreLoader.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package com.jcdm.main.da.opcuaconfig.cert;
-
-import org.eclipse.milo.opcua.sdk.server.util.HostnameUtil;
-import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateBuilder;
-import org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateGenerator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.security.*;
-import java.security.cert.X509Certificate;
-import java.util.regex.Pattern;
-
-/**
- * @ClassName: KeyStoreLoader
- * @Description: KeyStoreLoader
- * @author yyt
- * @date 2023骞�10鏈�13鏃�
- */
-@Component
-public class KeyStoreLoader {
-
-	private static final Pattern IP_ADDR_PATTERN = Pattern
-			.compile("^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
-
-	// 璇佷功鍒悕
-	private static final String CLIENT_ALIAS = "jlclient-ai";
-	// 鑾峰彇绉侀挜鐨勫瘑鐮�
-	private static final char[] PASSWORD = "yyt@8888888888".toCharArray();
-
-	private final Logger logger = LoggerFactory.getLogger(getClass());
-
-	// 璇佷功瀵硅薄
-	private X509Certificate clientCertificate;
-	// 瀵嗛挜瀵瑰璞�
-	private KeyPair clientKeyPair;
-
-	/**
-	 * @MethodName: load
-	 * @Description: load
-	 * @param baseDir
-	 * @return
-	 * @throws Exception
-	 * @CreateTime 2023骞�10鏈�13鏃�
-	 */
-	public KeyStoreLoader load(Path baseDir) throws Exception {
-		// 鍒涘缓涓�涓娇鐢╜PKCS12`鍔犲瘑鏍囧噯鐨凨eyStore銆侹eyStore鍦ㄥ悗闈㈠皢浣滀负璇诲彇鍜岀敓鎴愯瘉涔︾殑瀵硅薄銆�
-		KeyStore keyStore = KeyStore.getInstance("PKCS12");
-
-		// PKCS12鐨勫姞瀵嗘爣鍑嗙殑鏂囦欢鍚庣紑鏄�.pfx锛屽叾涓寘鍚簡鍏挜鍜岀閽ャ��
-		// 鑰屽叾浠栧.der绛夌殑鏍煎紡鍙寘鍚叕閽ワ紝绉侀挜鍦ㄥ彟澶栫殑鏂囦欢涓��
-		Path serverKeyStore = baseDir.resolve("OPCUA-client.pfx");
-
-		logger.info("Loading KeyStore at {}", serverKeyStore);
-
-		// 濡傛灉鏂囦欢涓嶅瓨鍦ㄥ垯鍒涘缓.pfx璇佷功鏂囦欢銆�
-		if (!Files.exists(serverKeyStore)) {
-			keyStore.load(null, PASSWORD);
-
-			// 鐢�2048浣嶇殑RAS绠楁硶銆俙SelfSignedCertificateGenerator`涓篗ilo搴撶殑瀵硅薄銆�
-			KeyPair keyPair = SelfSignedCertificateGenerator.generateRsaKeyPair(2048);
-
-			// `SelfSignedCertificateBuilder`涔熸槸Milo搴撶殑瀵硅薄锛岀敤鏉ョ敓鎴愯瘉涔︺��
-			// 涓棿鎵�璁剧疆鐨勮瘉涔﹀睘鎬у彲浠ヨ嚜琛屼慨鏀广��
-			SelfSignedCertificateBuilder builder = new SelfSignedCertificateBuilder(keyPair)
-					.setCommonName("UaClient@Jellyleo")
-					.setOrganization("JL")
-					.setOrganizationalUnit("per")
-					.setLocalityName("jl")
-					.setStateName("JiangSu")
-					.setCountryCode("CN")
-					.setApplicationUri("urn:Yyt_PC:UnifiedAutomation:UaExpert")
-					.addDnsName("Yyt_PC")
-					.addIpAddress("127.0.0.1");
-
-			// Get as many hostnames and IP addresses as we can listed in the certificate.
-			for (String hostname : HostnameUtil.getHostnames("0.0.0.0")) {
-				if (IP_ADDR_PATTERN.matcher(hostname).matches()) {
-					builder.addIpAddress(hostname);
-				} else {
-					builder.addDnsName(hostname);
-				}
-			}
-			// 鍒涘缓璇佷功
-			X509Certificate certificate = builder.build();
-
-			// 璁剧疆瀵瑰簲绉侀挜鐨勫埆鍚嶏紝瀵嗙爜锛岃瘉涔﹂摼
-			keyStore.setKeyEntry(CLIENT_ALIAS, keyPair.getPrivate(), PASSWORD, new X509Certificate[] { certificate });
-			try (OutputStream out = Files.newOutputStream(serverKeyStore)) {
-				// 淇濆瓨璇佷功鍒拌緭鍑烘祦
-				keyStore.store(out, PASSWORD);
-			}
-		} else {
-			try (InputStream in = Files.newInputStream(serverKeyStore)) {
-				// 濡傛灉鏂囦欢瀛樺湪鍒欒鍙�
-				keyStore.load(in, PASSWORD);
-			}
-		}
-
-		// 鐢ㄥ瘑鐮佽幏鍙栧搴斿埆鍚嶇殑绉侀挜銆�
-		Key serverPrivateKey = keyStore.getKey(CLIENT_ALIAS, PASSWORD);
-		if (serverPrivateKey instanceof PrivateKey) {
-			// 鑾峰彇瀵瑰簲鍒悕鐨勮瘉涔﹀璞°��
-			clientCertificate = (X509Certificate) keyStore.getCertificate(CLIENT_ALIAS);
-			// 鑾峰彇鍏挜
-			PublicKey serverPublicKey = clientCertificate.getPublicKey();
-			// 鍒涘缓Keypair瀵硅薄銆�
-			clientKeyPair = new KeyPair(serverPublicKey, (PrivateKey) serverPrivateKey);
-		}
-
-		return this;
-	}
-
-	// 杩斿洖璇佷功
-	public X509Certificate getClientCertificate() {
-		return clientCertificate;
-	}
-
-	// 杩斿洖瀵嗛挜瀵�
-	public KeyPair getClientKeyPair() {
-		return clientKeyPair;
-	}
-}
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
deleted file mode 100644
index f168d4b..0000000
--- a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java
+++ /dev/null
@@ -1,219 +0,0 @@
-package com.jcdm.main.da.opcuaconfig.cert;
-
-import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
-import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
-import com.jcdm.main.da.opcuaconfig.client.ClientHandler;
-import com.jcdm.main.da.opcuaconfig.domain.NodeEntity;
-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;
-
-import static com.jcdm.main.da.opcuaconfig.client.ClientHandler.readValues;
-
-@Slf4j
-public class MethodName {
-    private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class);
-    private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class);
-    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]+".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);
-                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.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 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;
-            default:
-                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);
-        }
-    }
-}
diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientHandler.java b/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientHandler.java
deleted file mode 100644
index 6267237..0000000
--- a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientHandler.java
+++ /dev/null
@@ -1,296 +0,0 @@
-package com.jcdm.main.da.opcuaconfig.client;
-
-import com.google.common.collect.ImmutableList;
-import com.jcdm.main.da.opcuaconfig.controller.DaOpcuaConfigController;
-import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig;
-import com.jcdm.main.da.opcuaconfig.domain.NodeEntity;
-import com.jcdm.main.da.opcuaconfig.service.IDaOpcuaConfigService;
-import lombok.extern.slf4j.Slf4j;
-import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
-import org.eclipse.milo.opcua.sdk.client.api.nodes.VariableNode;
-import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription;
-import org.eclipse.milo.opcua.stack.core.AttributeId;
-import org.eclipse.milo.opcua.stack.core.BuiltinDataType;
-import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
-import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
-import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
-import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
-import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned;
-import org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode;
-import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
-import org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateRequest;
-import org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters;
-import org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-
-/**
- * @ClassName: ClientHandler
- * @Description: 瀹㈡埛绔鐞�
- * @author Jellyleo
- * @date 2019骞�12鏈�12鏃�
- */
-@Slf4j
-@Service
-public class ClientHandler {
-
-	// 瀹㈡埛绔疄渚�
-	public static OpcUaClient client = null;
-
-	public List<DaOpcuaConfig> b = null;
-
-	@Autowired
-	private ClientRunner clientRunner;
-
-	@Autowired
-	private IDaOpcuaConfigService daOpcuaConfigService;
-
-
-	/**
-	 * 
-	 * @MethodName: connect
-	 * @Description: connect
-	 * @throws Exception
-	 * @CreateTime 2019骞�12鏈�18鏃� 涓婂崍10:41:09
-	 */
-	public String connect() throws Exception {
-
-		if (client != null) {
-			return "瀹㈡埛绔凡鍒涘缓";
-		}
-
-		client = clientRunner.run();
-
-		if (client == null) {
-			return "瀹㈡埛绔厤缃疄渚嬪寲澶辫触";
-		}
-
-		// 鍒涘缓杩炴帴
-		client.connect().get();
-		return "鍒涘缓杩炴帴鎴愬姛";
-	}
-
-	/**
-	 * @MethodName: disconnect
-	 * @Description: 鏂紑杩炴帴
-	 * @return
-	 * @throws Exception
-	 * @CreateTime 2019骞�12鏈�18鏃� 涓婂崍10:45:21
-	 */
-	public String disconnect() throws Exception {
-
-		if (client == null) {
-			return "杩炴帴宸叉柇寮�";
-		}
-
-		// 鏂紑杩炴帴
-		clientRunner.getFuture().complete(client);
-		client = null;
-		return "鏂紑杩炴帴鎴愬姛";
-	}
-
-	/**
-	 * @MethodName: subscribe
-	 * @Description: 璁㈤槄鑺傜偣鍙橀噺
-	 * @throws Exception
-	 * @CreateTime 2019骞�12鏈�18鏃� 涓婂崍10:38:11
-	 */
-	public String subscribe(List<NodeEntity> nodes) throws Exception {
-
-		if (client == null) {
-			return "鎵句笉鍒板鎴风锛屾搷浣滃け璐�";
-		}
-
-		// 鏌ヨ璁㈤槄瀵硅薄锛屾病鏈夊垯鍒涘缓
-		UaSubscription subscription = null;
-		ImmutableList<UaSubscription> subscriptionList = client.getSubscriptionManager().getSubscriptions();
-		if (CollectionUtils.isEmpty(subscriptionList)) {
-			subscription = client.getSubscriptionManager().createSubscription(1000.0).get();
-		} else {
-			subscription = subscriptionList.get(0);
-		}
-
-		// 鐩戞帶椤硅姹傚垪琛�
-		List<MonitoredItemCreateRequest> requests = new ArrayList<>();
-
-		if (!CollectionUtils.isEmpty(nodes)) {
-			for (NodeEntity node : nodes) {
-				// 鍒涘缓鐩戞帶鐨勫弬鏁�
-				MonitoringParameters parameters = new MonitoringParameters(subscription.nextClientHandle(), 1000.0, // sampling
-						// interval
-						null, // filter, null means use default
-						Unsigned.uint(10), // queue size
-						true // discard oldest
-				);
-				// 鍒涘缓璁㈤槄鐨勫彉閲忥紝 鍒涘缓鐩戞帶椤硅 姹�
-				MonitoredItemCreateRequest request = new MonitoredItemCreateRequest(
-						new ReadValueId(new NodeId(node.getIndex(), node.getIdentifier()), AttributeId.Value.uid(),
-								null, null),
-						MonitoringMode.Reporting, parameters);
-				requests.add(request);
-			}
-		}
-
-		// 鍒涘缓鐩戞帶椤癸紝骞朵笖娉ㄥ唽鍙橀噺鍊兼敼鍙樻椂鍊欑殑鍥炶皟鍑芥暟
-		subscription.createMonitoredItems(TimestampsToReturn.Both, requests, (item, id) -> {
-			item.setValueConsumer((i, v) -> {
-				handle(i.getReadValueId().getNodeId(), v.getValue());
-			});
-		}).get();
-
-		return "璁㈤槄鎴愬姛";
-	}
-
-	/**
-	 * * @MethodName: write
-	 * @Description: 鍥炶皟鍑芥暟
-	 * @CreateTime 2023骞�10鏈�13鏃�
-	 */
-	public void handle(NodeId id, Variant value){
-		if (b == null || 0 > b.size()) {
-			DaOpcuaConfig opcuaConfParam=new DaOpcuaConfig();
-		    opcuaConfParam.setSubscribe("Y");
-		    b=daOpcuaConfigService.selectDaOpcuaConfigList(opcuaConfParam);
-		}
-		//浣跨敤Stream API鍦↙ist<T>涓煡鎵惧厓绱�
-		DaOpcuaConfig daOpcuaConfig = b.stream()
-				.filter(customer ->id.getIdentifier().toString().equals(customer.getNode()))
-				.findAny()
-				.orElse(null);
-		try {
-			Class<?> clazz = Class.forName("com.jcdm.main.da.opcuaconfig.cert.MethodName");
-			Method method = clazz.getMethod(daOpcuaConfig.getrFunction(), new Class[] { String.class, String.class });
-			method.invoke(clazz.newInstance(),new Object[] {
-					new String(id.getIdentifier().toString()), new String(value.getValue().toString()) });
-		} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException |
-				 InvocationTargetException e) {
-			e.printStackTrace();
-		}
-	}
-
-
-	/**
-	 * @MethodName: write
-	 * @Description: 鍙樿妭鐐归噺鍐欏叆
-	 * @param node
-	 * @throws Exception
-	 * @CreateTime 2019骞�12鏈�18鏃� 涓婂崍9:51:40
-	 */
-	public static Boolean write(NodeEntity node) throws Exception {
-
-		if (client == null) {
-			log.info("鎵句笉鍒板鎴风锛屾搷浣滃け璐�");
-			return false;
-		}
-
-		NodeId nodeId = new NodeId(node.getIndex(), node.getIdentifier());
-		Variant value = null;
-		switch (node.getType()) {
-		case "int":
-			value = new Variant(Integer.parseInt(node.getValue().toString()));
-			break;
-		case "boolean":
-			value = new Variant(Boolean.parseBoolean(node.getValue().toString()));
-			break;
-		case "short":
-			value = new Variant(Short.parseShort(node.getValue().toString()));
-			break;
-		case "long":
-			value = new Variant(Long.parseLong(node.getValue().toString()));
-			break;
-		case "string":
-			value = new Variant(node.getValue().toString());
-			break;
-		case "char":
-			value = new Variant(node.getValue().toString().charAt(0));
-			break;
-		}
-		DataValue dataValue = new DataValue(value, null, null);
-
-		StatusCode statusCode = client.writeValue(nodeId, dataValue).get();
-
-		return statusCode.isGood();
-	}
-
-	/**
-	 * 鏂规硶鎻忚堪: 璇诲彇澶氫釜鐐逛綅鐨勫��
-	 *
-	 * @param nodeIdList 鐐逛綅闆嗗悎
-	 * @return {@link List<DataValue>}
-	 * @throws
-	 */
-	public static List<DataValue> readValues(List<NodeId> nodeIdList){
-		try {
-			List<DataValue> dataValues=client.readValues(0.0, TimestampsToReturn.Both,nodeIdList).get();
-			return dataValues;
-		} catch (InterruptedException | ExecutionException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-	/**
-	 * @MethodName: read
-	 * @Description: 璇诲彇
-	 * @param node
-	 * @return
-	 * @throws Exception
-	 * @CreateTime 2019骞�12鏈�19鏃� 涓嬪崍2:40:34
-	 */
-	public String read(NodeEntity node) throws Exception {
-
-		if (client == null) {
-			return "鎵句笉鍒板鎴风锛屾搷浣滃け璐�";
-		}
-
-		NodeId nodeId = new NodeId(node.getIndex(), node.getIdentifier());
-		VariableNode vnode = client.getAddressSpace().createVariableNode(nodeId);
-		DataValue value = vnode.readValue().get();
-		log.info("Value={}", value);
-
-		Variant variant = value.getValue();
-		log.info("Variant={}", variant.getValue());
-
-		log.info("BackingClass={}", BuiltinDataType.getBackingClass(variant.getDataType().get()));
-
-		return variant.getValue().toString();
-	}
-
-
-	/**
-	 * 鏂规硶鎻忚堪:  鍐欏叆澶氫釜鑺傜偣鐨勫��
-	 *
-	 * @param keys  鑺傜偣闆嗗悎
-	 * @param values  鍊奸泦鍚�
-	 * @param client  瀹㈡埛绔�
-	 * @return {@link Object}
-	 * @throws
-	 */
-	public static Object writeValues(Set<String> keys, List<Object> values, OpcUaClient client){
-		List<NodeId> nodeIs=new ArrayList<>(keys.size());
-		keys.forEach(e->{
-			NodeId nodeId = new NodeId(2, e);
-			nodeIs.add(nodeId);
-		});
-		List<DataValue> dataValues=new ArrayList<>(values.size());
-		values.forEach(e->{
-			Variant value=new Variant(Double.parseDouble(e.toString()));
-			DataValue dataValue=new DataValue(value);
-			dataValues.add(dataValue);
-		});
-		try {
-			client.writeValues(nodeIs,dataValues).get();
-		} catch (InterruptedException | ExecutionException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-}
diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientRunner.java b/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientRunner.java
deleted file mode 100644
index 513a6dd..0000000
--- a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/client/ClientRunner.java
+++ /dev/null
@@ -1,146 +0,0 @@
-package com.jcdm.main.da.opcuaconfig.client;
-
-import com.jcdm.main.da.opcuaconfig.cert.KeyStoreLoader;
-import com.jcdm.main.da.opcuaconfig.init.Properties;
-import lombok.extern.slf4j.Slf4j;
-import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
-import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig;
-import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
-import org.eclipse.milo.opcua.stack.client.DiscoveryClient;
-import org.eclipse.milo.opcua.stack.core.Stack;
-import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
-import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
-import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned;
-import org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-import java.util.function.Predicate;
-
-/**
- * @ClassName: ClientRunner
- * @Description: 瀹㈡埛绔惎鍔ㄧ被
- * @author yyt
- * @date 2023骞�10鏈�13鏃�
- */
-@Slf4j
-@Component
-public class ClientRunner {
-
-	private final CompletableFuture<OpcUaClient> future = new CompletableFuture<>();
-
-	@Autowired
-	private Properties properties;
-
-	@Autowired
-	private KeyStoreLoader keyStoreLoader;
-
-	/**
-	 * @MethodName: run
-	 * @Description: 鍚姩
-	 * @return
-	 * @throws Exception
-	 * @CreateTime 2023骞�10鏈�13鏃�
-	 */
-	public OpcUaClient run() throws Exception {
-
-		OpcUaClient client = createClient();
-
-		future.whenCompleteAsync((c, ex) -> {
-			if (ex != null) {
-				log.error("Error running example: {}", ex.getMessage(), ex);
-			}
-
-			try {
-				c.disconnect().get();
-				Stack.releaseSharedResources();
-			} catch (InterruptedException | ExecutionException e) {
-				log.error("Error disconnecting:", e.getMessage(), e);
-			}
-		});
-
-		return client;
-	}
-
-	/**
-	 * @MethodName: createClient
-	 * @Description: 鍒涘缓瀹㈡埛绔�
-	 * @return
-	 * @throws Exception
-	 * @CreateTime 2023骞�10鏈�13鏃�
-	 */
-	private OpcUaClient createClient() throws Exception {
-
-		Path securityTempDir = Paths.get(properties.getCertPath(), "security");
-		Files.createDirectories(securityTempDir);
-		if (!Files.exists(securityTempDir)) {
-			log.error("unable to create security dir: " + securityTempDir);
-			return null;
-		}
-
-		KeyStoreLoader loader = keyStoreLoader.load(securityTempDir);
-
-		// 鎼滅储OPC鑺傜偣
-		List<EndpointDescription> endpoints = null;
-		try {
-			//鑾峰彇瀹夊叏绛栫暐
-			endpoints = DiscoveryClient.getEndpoints(properties.getEndpointUrl()).get();
-		} catch (Throwable e) {
-			// try the explicit discovery endpoint as well
-			String discoveryUrl = properties.getEndpointUrl();
-
-			if (!discoveryUrl.endsWith("/")) {
-				discoveryUrl += "/";
-			}
-			discoveryUrl += "discovery";
-
-			log.info("Trying explicit discovery URL: {}", discoveryUrl);
-			endpoints = DiscoveryClient.getEndpoints(discoveryUrl).get();
-		}
-
-		EndpointDescription endpoint = endpoints.stream()
-				.filter(e -> e.getSecurityPolicyUri().equals(SecurityPolicy.None.getUri())).filter(endpointFilter())
-				.findFirst().orElseThrow(() -> new Exception("no desired endpoints returned"));
-
-		OpcUaClientConfig config = OpcUaClientConfig.builder()
-				// opc ua鑷畾涔夌殑鍚嶇О
-				.setApplicationName(LocalizedText.english("plc"))
-				// 鍦板潃
-				.setApplicationUri(properties.getEndpointUrl())
-				.setCertificate(loader.getClientCertificate()).setKeyPair(loader.getClientKeyPair())
-				// 瀹夊叏绛栫暐绛夐厤缃�
-				//.setEndpoint(endpoint).setIdentityProvider(new UsernameProvider("OPCUA", "yyt@8888888888"))
-				.setEndpoint(endpoint)
-				// 鍖垮悕楠岃瘉
-				.setIdentityProvider(new AnonymousProvider())
-				//绛夊緟鏃堕棿
-				.setRequestTimeout(Unsigned.uint(5000)).build();
-
-		return OpcUaClient.create(config);
-
-	}
-
-	/**
-	 * @MethodName: endpointFilter
-	 * @Description: endpointFilter
-	 * @return
-	 * @CreateTime 2023骞�10鏈�13鏃�
-	 */
-	private Predicate<EndpointDescription> endpointFilter() {
-		return e -> true;
-	}
-
-	/**
-	 * @return the future
-	 */
-	public CompletableFuture<OpcUaClient> getFuture() {
-		return future;
-	}
-
-}
diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/controller/DaOpcuaConfigController.java b/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/controller/DaOpcuaConfigController.java
index 23d2e95..0f38e76 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/controller/DaOpcuaConfigController.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/controller/DaOpcuaConfigController.java
@@ -3,7 +3,6 @@
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
-import com.jcdm.main.da.opcuaconfig.client.ClientHandler;
 import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig;
 import com.jcdm.main.da.opcuaconfig.domain.NodeEntity;
 import com.jcdm.main.da.opcuaconfig.service.IDaOpcuaConfigService;
@@ -111,10 +110,10 @@
     @PreAuthorize("@ss.hasPermi('da:opcuaconfig:query')")
     @GetMapping(value = "/SNCode/{SNCode}/{locationCode}")
     public AjaxResult setSNCode(@PathVariable("SNCode") String SNCode,@PathVariable("locationCode") String locationCode) {
-        NodeEntity node= NodeEntity.builder().index(2).identifier("CFL4CVT"+"."+locationCode+".SNCode").value(SNCode).type("string").build();
+        //NodeEntity node= NodeEntity.builder().index(2).identifier("CFL4CVT"+"."+locationCode+".SNCode").value(SNCode).type("string").build();
         Boolean out= null;
         try {
-            out = ClientHandler.write(node);
+           // out = ClientHandler.write(node);
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/OpcusConfigInit.java b/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/OpcusConfigInit.java
deleted file mode 100644
index c836a15..0000000
--- a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/init/OpcusConfigInit.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.jcdm.main.da.opcuaconfig.init;
-
-import com.google.common.collect.Lists;
-import com.jcdm.main.da.opcuaconfig.client.ClientHandler;
-import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig;
-import com.jcdm.main.da.opcuaconfig.domain.NodeEntity;
-import com.jcdm.main.da.opcuaconfig.service.IDaOpcuaConfigService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.CommandLineRunner;
-import org.springframework.stereotype.Component;
-import java.util.List;
-
-@Component
-@Slf4j
-public class OpcusConfigInit implements CommandLineRunner {
-
-    @Autowired
-    private ClientHandler clientHandler;
-
-    @Autowired
-    private IDaOpcuaConfigService daOpcuaConfigService;
-
-    @Override
-    public void run(String... args) throws Exception {
-        try {
-            DaOpcuaConfig daOpcuaConfig=new DaOpcuaConfig();
-            daOpcuaConfig.setSubscribe("Y"); //璁剧疆鏌ヨ鏉′欢锛岃闃呯姸鎬佺殑鎵�鏈夋暟鎹�.
-            daOpcuaConfig.setState(Long.valueOf("0")); //璁剧疆鏌ヨ鏉′欢锛屾甯哥姸鎬�.
-            List<DaOpcuaConfig> nodeslist=daOpcuaConfigService.selectDaOpcuaConfigList(daOpcuaConfig);
-            clientHandler.connect();
-            if (nodeslist != null && nodeslist.size() > 0) {
-                List<NodeEntity> NodeList = Lists.transform(nodeslist, (DaOpcuaConfig) -> {
-                    NodeEntity nodeEntity = new NodeEntity();
-                    nodeEntity.setIndex(2);
-                    nodeEntity.setIdentifier(DaOpcuaConfig.getNode());
-                    return nodeEntity;
-                });
-                clientHandler.subscribe(NodeList);
-            }
-            log.info("OPCUA鍒濆鍖栨垚鍔燂紝骞跺畬鎴�"+ nodeslist.size() +"涓妭鐐硅闃�");
-        } catch (Exception e) {
-            e.printStackTrace();
-            log.info("绯荤粺鎻愮ず锛孫PCUA璁㈤槄澶辫触锛�");
-        }
-    }
-}
diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java
new file mode 100644
index 0000000..bbb8144
--- /dev/null
+++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/CustomRunner.java
@@ -0,0 +1,53 @@
+package com.jcdm.main.plcserver;
+
+
+import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
+import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
+import com.jcdm.main.plcserver.conf.OPCElement;
+import com.jcdm.main.plcserver.sub.OPCUaSubscription;
+import com.kangaroohy.milo.service.MiloService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+public class CustomRunner implements ApplicationRunner {
+
+    @Autowired
+    public MiloService miloService;
+
+    @Autowired
+    public IDaCollectionParamConfService collectionParamConfService;
+
+    @Autowired
+    public IDaParamCollectionService daParamCollectionService;
+
+    @Override
+    public void run(ApplicationArguments args) throws Exception {
+
+        OPCUaSubscription opcUaSubscription = new OPCUaSubscription(
+                miloService,
+                collectionParamConfService,
+                daParamCollectionService);
+
+        List<String> lists = getSubList();
+        miloService.subscriptionFromOpcUa(lists,opcUaSubscription);
+
+    }
+
+    /**
+     * 璁㈤槄鍐呭
+     */
+    public List<String> getSubList(){
+        List<String> lists = new ArrayList<>();
+        lists.add(OPCElement.OP010_SaveRequest);//璇锋眰淇濆瓨
+        lists.add(OPCElement.OP010_CodeCheck);//璇锋眰妫�绱㈡潯鐮�
+        lists.add(OPCElement.OP020_SaveRequest);//璇锋眰淇濆瓨
+        return lists;
+    }
+}
+
diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/conf/OPCElement.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/conf/OPCElement.java
new file mode 100644
index 0000000..1641e9e
--- /dev/null
+++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/conf/OPCElement.java
@@ -0,0 +1,28 @@
+package com.jcdm.main.plcserver.conf;
+
+/**
+ * @ClassName: OPCElement
+ * @Description: PC鍜孭LC閫氫俊浣跨敤鐨凮PCserver涓婄殑鏍囪鍚嶇О鍒楄〃
+ */
+public class OPCElement {
+
+    /**
+     * OP010
+     */
+    private static final String OP010_ITEM = "CFL3ZZ.OP010.";//
+    public static final String OP010_SaveRequest = OP010_ITEM + "SaveRequest";//璇锋眰淇濆瓨
+    public static final String OP010_MesSaveFeed = OP010_ITEM + "MesSaveFeed";//Mes淇濆瓨瀹屾垚
+    public static final String OP010_CodeCheck = OP010_ITEM + "CodeCheck";//璇锋眰妫�绱㈡潯鐮�
+    public static final String OP010_MesCodeCheckFeed = OP010_ITEM + "MesCodeCheckFeed";//MES妫�绱㈠畬鎴�
+
+
+    /**
+     * OP100
+     */
+    private static final String OP020_ITEM = "OP.OP100.";//
+    public static final String OP020_SaveRequest = OP020_ITEM + "SaveRequest";//璇锋眰淇濆瓨
+    public static final String OP020_MesSaveFeed = OP020_ITEM + "MesSaveFeed";//Mes淇濆瓨瀹屾垚
+
+
+
+}
\ No newline at end of file
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
new file mode 100644
index 0000000..c6a201f
--- /dev/null
+++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -0,0 +1,111 @@
+package com.jcdm.main.plcserver.sub;
+
+
+import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
+import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
+import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
+import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
+import com.jcdm.main.plcserver.conf.OPCElement;
+import com.kangaroohy.milo.model.ReadWriteEntity;
+import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
+import com.kangaroohy.milo.service.MiloService;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+
+@Component
+public class OPCUaSubscription implements SubscriptionCallback {
+
+    public static MiloService miloService;
+
+    public IDaCollectionParamConfService collectionParamConfService;
+
+    public IDaParamCollectionService daParamCollectionService;
+
+    public OPCUaSubscription(MiloService miloService,
+                             IDaCollectionParamConfService collectionParamConfService,
+                             IDaParamCollectionService daParamCollectionService) {
+        OPCUaSubscription.miloService = miloService;
+        this.collectionParamConfService = collectionParamConfService;
+        this.daParamCollectionService = daParamCollectionService;
+
+    }
+
+
+    @Override
+    public void onSubscribe(String identifier, Object value) {
+        String ecpStr = "";//寮傚父璁板綍鏍囪
+        try {
+            if(null != value) {
+
+                //OP010淇濆瓨璇锋眰
+                if (identifier.equals(OPCElement.OP010_SaveRequest) && null != value && "1".equals(value.toString())) {
+                    SaveData(OPCElement.OP010_SaveRequest);
+                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesSaveFeed, 1);
+                    miloService.writeToOpcByte(entity);
+                }
+                //OP010璇锋眰妫�绱㈡潯鐮�
+                else if (identifier.equals(OPCElement.OP010_CodeCheck) && null != value && "1".equals(value.toString())) {
+                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesCodeCheckFeed, 1);
+                    miloService.writeToOpcByte(entity);
+                }
+            }
+
+
+
+        } catch (Exception e) {
+
+        } finally {
+            if (!"".equals(ecpStr)) {
+                System.out.println(ecpStr + "\r\n");
+
+            }
+        }
+    }
+
+    public void SaveData(String Node) throws Exception {
+        /*String[] parts = Node.split("[.]");
+        Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
+
+        if(null != SNCodeObject)
+        {
+            String SNCode = SNCodeObject.toString();
+            List<DaCollectionParamConf> list;
+            DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
+            daCollectionParamConf.setGatherAddress(parts[0] + "." + parts[1]);
+            list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
+
+            List<String> nodeIdList = list.stream().map(info -> {
+                String nodeid = info.getGatherAddress();
+                return nodeid;
+            }).collect(Collectors.toList());
+
+            if(!nodeIdList.isEmpty()){
+                List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
+                List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
+                for(int i=0;i<nodeIdList.size();i++){
+                    DaParamCollection ParamCollection = new DaParamCollection();
+                    if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){
+                        ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]);
+                        ParamCollection.setLocationCode(parts[1]);
+                        ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
+                        ParamCollection.setSfcCode(SNCode);
+                        ParamCollection.setParamName(list.get(i).getCollectParameterName());
+                        ParamCollection.setParamUpper(list.get(i).getParamUpper());
+                        ParamCollection.setParamLower(list.get(i).getParamLower());
+                        ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
+                        ParamCollection.setState("鍚堟牸");
+                        ParamCollection.setType(list.get(i).getCollectParameterType());
+                        ParamCollection.setCollectionTime(new Date());
+                        daParamCollectionlist.add(ParamCollection);
+                    }
+                }
+                daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
+            }
+        }*/
+    }
+}

--
Gitblit v1.9.3