From 47eb81eebc9a87af5f64dd765dc1a1267317d9a8 Mon Sep 17 00:00:00 2001
From: yantian yue <306727702@qq.com>
Date: 星期二, 24 十月 2023 16:21:55 +0800
Subject: [PATCH] OPCUA更新

---
 guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java |   60 +++++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java b/guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java
index 683c3ce..5877f51 100644
--- a/guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java
+++ b/guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java
@@ -1,19 +1,11 @@
 package cn.stylefeng.guns.opcua.client;
 
-import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
-import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
 import cn.stylefeng.guns.opcua.controller.OpcuaConfController;
-import cn.stylefeng.guns.opcua.entity.OpcuaConf;
-import cn.stylefeng.guns.opcua.mapper.OpcuaConfMapper;
 import cn.stylefeng.guns.opcua.model.params.OpcuaConfParam;
 import cn.stylefeng.guns.opcua.model.result.OpcuaConfResult;
-import cn.stylefeng.guns.opcua.service.OpcuaConfService;
-import cn.stylefeng.roses.kernel.model.response.ResponseData;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.common.collect.ImmutableList;
 import cn.stylefeng.guns.opcua.entity.NodeEntity;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.ss.formula.functions.T;
 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;
@@ -32,6 +24,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import cn.stylefeng.guns.base.enums.MicroTimestamp;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -49,14 +42,16 @@
 public class ClientHandler {
 
 	// 瀹㈡埛绔疄渚�
-	private OpcUaClient client = null;
+	public static OpcUaClient client = null;
+
+	public List<OpcuaConfResult> b = null;
 
 	@Autowired
 	private ClientRunner clientRunner;
 
 	@Autowired
 	private OpcuaConfController opcuaConfController;
-	List<OpcuaConfResult> a = null;
+
 
 	/**
 	 * 
@@ -113,8 +108,6 @@
 			return "鎵句笉鍒板鎴风锛屾搷浣滃け璐�";
 		}
 
-//		List<Node> ns = client.getAddressSpace().browse(new NodeId(2, "妯℃嫙閫氶亾涓�.妯℃嫙璁惧涓�")).get();
-
 		// 鏌ヨ璁㈤槄瀵硅薄锛屾病鏈夊垯鍒涘缓
 		UaSubscription subscription = null;
 		ImmutableList<UaSubscription> subscriptionList = client.getSubscriptionManager().getSubscriptions();
@@ -148,7 +141,7 @@
 		// 鍒涘缓鐩戞帶椤癸紝骞朵笖娉ㄥ唽鍙橀噺鍊兼敼鍙樻椂鍊欑殑鍥炶皟鍑芥暟
 		subscription.createMonitoredItems(TimestampsToReturn.Both, requests, (item, id) -> {
 			item.setValueConsumer((i, v) -> {
-				handle(i.getReadValueId().getNodeId(), v.getValue());
+				handle2(i.getReadValueId().getNodeId(), v.getValue());
 			});
 		}).get();
 
@@ -161,12 +154,13 @@
 	 * @CreateTime 2023骞�10鏈�13鏃�
 	 */
 
-	public void handle(NodeId id, Variant value){
+	/*public void handle(NodeId id, Variant value){
+		long startTime = System.currentTimeMillis();
+
 		OpcuaConfParam opcuaConfParam=new OpcuaConfParam();
 		opcuaConfParam.setNode(id.getIdentifier().toString());
-		if(a == null || a.size() == 0) {
-			a=opcuaConfController.mylist(opcuaConfParam);
-		}
+		List<OpcuaConfResult> a=opcuaConfController.mylist(opcuaConfParam);
+		log.info("鏁版嵁搴撹闂唬鐮佹墽琛屾椂闂达細" + (System.currentTimeMillis() - startTime) + "姣");
 		String str1 = id.getIdentifier().toString()+":"+value.getValue().toString();
 		try {
 			Class<?> clazz = Class.forName(a.get(0).getRModule());
@@ -177,7 +171,36 @@
 				 InvocationTargetException e) {
 			e.printStackTrace();
 		}
+		log.info("浠g爜鎵ц鏃堕棿锛�" + (System.currentTimeMillis() - startTime) + "姣");
+	}*/
+	public void handle2(NodeId id, Variant value){
+
+		MicroTimestamp t = null;
+		String sTime=t.INSTANCE.get();
+
+
+		if (b == null || 0 > b.size()) {
+			OpcuaConfParam opcuaConfParam=new OpcuaConfParam();
+		    opcuaConfParam.setSubscribe(1);
+		    b=opcuaConfController.mylist(opcuaConfParam);
+		}
+		String str1 = id.getIdentifier().toString()+":"+value.getValue().toString();
+		//浣跨敤Stream API鍦↙ist<T>涓煡鎵惧厓绱�
+		OpcuaConfResult opcuaConfResult = b.stream()
+				.filter(customer ->id.getIdentifier().toString().equals(customer.getNode()))
+				.findAny()
+				.orElse(null);
+		try {
+			Class<?> clazz = Class.forName(opcuaConfResult.getRModule());
+			Method method = clazz.getMethod(opcuaConfResult.getRFunction(), String.class);
+			method.invoke(clazz.newInstance(), str1);
+		} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException |
+				 InvocationTargetException e) {
+			e.printStackTrace();
+		}
+		log.info("浠g爜鎵ц寮�濮嬫椂闂翠负锛�"+ sTime +",缁撴潫鏃堕棿涓猴細"+t.INSTANCE.get()+".");
 	}
+
 
 	/**
 	 * @MethodName: write
@@ -201,6 +224,9 @@
 		case "boolean":
 			value = new Variant(Boolean.parseBoolean(node.getValue().toString()));
 			break;
+		case "long":
+			value = new Variant(Long.parseLong(node.getValue().toString()));
+			break;
 		}
 		DataValue dataValue = new DataValue(value, null, null);
 

--
Gitblit v1.9.3