From 0d7d6a88080dc8759ef84ed5ad7875f25642df6c Mon Sep 17 00:00:00 2001
From: yantian yue <306727702@qq.com>
Date: 星期一, 23 十月 2023 10:59:18 +0800
Subject: [PATCH] OPCUA更新

---
 guns-base-support/guns-base/src/main/java/cn/stylefeng/guns/base/enums/MicroTimestamp.java |   27 +++++++++++++++++++++++++++
 guns-vip-main/src/main/java/cn/stylefeng/guns/opcua/client/ClientHandler.java              |   19 +++++++------------
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/guns-base-support/guns-base/src/main/java/cn/stylefeng/guns/base/enums/MicroTimestamp.java b/guns-base-support/guns-base/src/main/java/cn/stylefeng/guns/base/enums/MicroTimestamp.java
new file mode 100644
index 0000000..f7a66ce
--- /dev/null
+++ b/guns-base-support/guns-base/src/main/java/cn/stylefeng/guns/base/enums/MicroTimestamp.java
@@ -0,0 +1,27 @@
+package cn.stylefeng.guns.base.enums;
+
+import java.text.SimpleDateFormat;
+
+/**
+ * Class to generate timestamps with microsecond precision
+ * For example: MicroTimestamp.INSTANCE.get() = "2012-10-21 19:13:45.267128"
+ */
+public enum MicroTimestamp
+{
+    INSTANCE ;
+    private long startDate ;
+    private long startNanoseconds ;
+    private SimpleDateFormat dateFormat ;
+
+    private MicroTimestamp()
+    {  this.startDate = System.currentTimeMillis() ;
+        this.startNanoseconds = System.nanoTime() ;
+        this.dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") ;
+    }
+
+    public String get()
+    {  long microSeconds = (System.nanoTime() - this.startNanoseconds) / 1000 ;
+        long date = this.startDate + (microSeconds/1000) ;
+        return this.dateFormat.format(date) + String.format("%03d", microSeconds % 1000) ;
+    }
+}
\ No newline at end of file
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 827b8bb..b7a43c8 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;
@@ -181,12 +174,15 @@
 		log.info("浠g爜鎵ц鏃堕棿锛�" + (System.currentTimeMillis() - startTime) + "姣");
 	}*/
 	public void handle2(NodeId id, Variant value){
-		long sTime = System.currentTimeMillis();
+
+		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);
-			log.info("鏁版嵁搴撹闂唬鐮佹墽琛屾椂闂达細" + (System.currentTimeMillis() - sTime) + "姣");
 		}
 		String str1 = id.getIdentifier().toString()+":"+value.getValue().toString();
 		//浣跨敤Stream API鍦↙ist<T>涓煡鎵惧厓绱�
@@ -197,13 +193,12 @@
 		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爜鎵ц鏃堕棿锛�" + (System.currentTimeMillis() - sTime) + "姣");
+		log.info("浠g爜鎵ц寮�濮嬫椂闂翠负锛�"+ sTime +",缁撴潫鏃堕棿涓猴細"+t.INSTANCE.get()+".");
 	}
 
 

--
Gitblit v1.9.3