yantian yue
2023-10-24 47eb81eebc9a87af5f64dd765dc1a1267317d9a8
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,7 +42,7 @@
public class ClientHandler {
   // 客户端实例
   private OpcUaClient client = null;
   public static OpcUaClient client = null;
   public List<OpcuaConfResult> b = null;
@@ -181,12 +174,15 @@
      log.info("代码执行时间:" + (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在List<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("代码执行时间:" + (System.currentTimeMillis() - sTime) + "毫秒");
      log.info("代码执行开始时间为:"+ sTime +",结束时间为:"+t.INSTANCE.get()+".");
   }
@@ -229,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);