瀏覽代碼

适配kepserver模式

gt 2 年之前
父節點
當前提交
6c4109e940

+ 2 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/enums/DataSourceTypeEnum.java

@@ -6,7 +6,8 @@ public enum DataSourceTypeEnum {
     OPC_UA_HISTORY("OPC UA 历史数据", "opc_ua_history"),
     OPC_DA_REAL("OPC DA 实时数据", "opc_da_real"),
     OPC_HDA_HISTORY("OPC HDA 历史数据访问", "opc_hda_history"),
-    OPC_AE_ALARMS("OPC AE 实时报警", "opc_ae_alarms");
+    OPC_AE_ALARMS("OPC AE 实时报警", "opc_ae_alarms"),
+    KEP_SERVER_REAL("KepServer 实时数据", "kep_server_real");
 
     private String name;
     private String value;

+ 1 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ChannelSettingServiceImpl.java

@@ -76,7 +76,7 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
                 if (Blank.isNotEmpty(channelSettings)) {
                     jsonObject.put("tree", KepOpcServerUtil.opcNoConfigTree(serverInformation, channelSettings));
                 } else {
-                    jsonObject.put("tree", KepOpcServerUtil.opcReadItemTree(serverInformation));
+
                 }
                 return Result.ok(jsonObject);
             }

+ 1 - 2
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ConnectServiceImpl.java

@@ -42,7 +42,7 @@ public class ConnectServiceImpl implements ConnectService {
         //如果连接方式为kepOpcserver
         if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
             if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
-                return KepOpcServerUtil.opcTestConnect(serverInformation);
+
             }
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
             //如果连接方式为kingOpcserver
@@ -169,7 +169,6 @@ public class ConnectServiceImpl implements ConnectService {
         jsonObject.put("run", configList);
         if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
             if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
-                jsonObject.put("tree", KepOpcServerUtil.opcReadItemTree(serverInformation));
                 return Result.ok(jsonObject);
             }
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());

+ 11 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/DataSourceServiceImpl.java

@@ -85,6 +85,11 @@ public class DataSourceServiceImpl implements DataSourceService {
                 return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据源ip,用户名,密码都不能为空");
             }
             return OpcDaUtil.opcDaTestConnect(dataSource);
+        } else if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.KEP_SERVER_REAL.getValue())) {
+            if (Blank.isEmpty(dataSource.getIpAddress(), dataSource.getIpUserName(), dataSource.getIpPassword())) {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据源ip,用户名,密码都不能为空");
+            }
+            return KepOpcServerUtil.opcTestConnect(dataSource);
         } else {
             throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "目前还没有此种类型的连接方式");
         }
@@ -133,6 +138,11 @@ public class DataSourceServiceImpl implements DataSourceService {
                 return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据源ip,用户名,密码都不能为空");
             }
             return OpcDaUtil.opcDaGetTree(dataSource);
+        }else if(dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.KEP_SERVER_REAL.getValue())){
+            if (Blank.isEmpty(dataSource.getIpAddress(), dataSource.getIpUserName(), dataSource.getIpPassword())) {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据源ip,用户名,密码都不能为空");
+            }
+            return KepOpcServerUtil.opcReadItemTree(dataSource);
         } else {
             throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "目前还没有此种类型的连接方式");
         }
@@ -144,7 +154,7 @@ public class DataSourceServiceImpl implements DataSourceService {
         while (iterator.hasNext()) {
             DataSourceType dataSourceType = iterator.next();
             if (dataSourceType.getParentId() == parentId) {
-                iterator.remove();
+//                iterator.remove();
                 JSONObject jsonObject = new JSONObject();
                 jsonObject.put("id", dataSourceType.getId());
                 jsonObject.put("label", dataSourceType.getDataSourceTypeName());

+ 18 - 27
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/KepOpcServerUtil.java

@@ -3,6 +3,7 @@ package com.judong.chuanyiserver.util;
 import com.alibaba.fastjson.JSONObject;
 import com.judong.chuanyiserver.config.KepOpcServerPoolFactory;
 import com.judong.chuanyiserver.entity.ChannelSetting;
+import com.judong.chuanyiserver.entity.DataSource;
 import com.judong.chuanyiserver.entity.ServerInformation;
 import com.judong.chuanyiserver.enums.ConnectModeEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
@@ -83,18 +84,17 @@ public class KepOpcServerUtil {
     /**
      * 传入给类型的key生成服务
      *
-     * @param key
+     * @param dataSource
      * @return
      */
-    public static Server createServer(String key) {
-        JSONObject jsonObject = JSONObject.parseObject(key);
+    public static Server createServer(DataSource dataSource) {
         final ConnectionInformation ci = new ConnectionInformation();
-        ci.setHost(jsonObject.getString("ip")); // 安装opc电脑IP
+        ci.setHost(dataSource.getIpAddress()); // 安装opc电脑IP
         ci.setDomain(""); // 域,为空就行
-        ci.setUser(jsonObject.getString("user")); // 电脑上自己建好的用户名
-        ci.setPassword(jsonObject.getString("password")); // 用户名的密码
+        ci.setUser(dataSource.getIpUserName()); // 电脑上自己建好的用户名
+        ci.setPassword(dataSource.getIpPassword()); // 用户名的密码
         // 使用KepOPC Server的配置
-        ci.setClsid(jsonObject.getString("clsid")); // KEPServer的注册表ID,可以在“组件服务”里看到
+        ci.setClsid(ConnectModeEnum.KEPOPCSERVER.getName()); // KEPServer的注册表ID,可以在“组件服务”里看到
         return new Server(ci, Executors.newSingleThreadScheduledExecutor());
     }
 
@@ -133,13 +133,8 @@ public class KepOpcServerUtil {
         return KepOpcServerPoolFactory.getPool();
     }
 
-    public static Result opcTestConnect(ServerInformation serverInformation) {
-        //服务
-        String opcServerDaPoolKey = KepOpcServerUtil.generateOpcPoolKey(serverInformation);
-        if (!KepOpcServerUtil.validationKey(opcServerDaPoolKey)) {
-            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
-        }
-        Server server = KepOpcServerUtil.createServer(opcServerDaPoolKey);
+    public static Result opcTestConnect(DataSource dataSource) {
+        Server server = KepOpcServerUtil.createServer(dataSource);
         try {
             // 连接到服务
             long start = System.currentTimeMillis();
@@ -164,23 +159,19 @@ public class KepOpcServerUtil {
     /**
      * 通过服务器信息读取服务器树item
      *
-     * @param serverInformation
+     * @param dataSource
      * @return
      * @throws Exception
      */
-    public static List<JSONObject> opcReadItemTree(ServerInformation serverInformation) {
+    public static Result opcReadItemTree(DataSource dataSource) {
         try {
-            String opcServerDaPoolKey = KepOpcServerUtil.generateOpcPoolKey(serverInformation);
-            if (KepOpcServerUtil.validationKey(opcServerDaPoolKey)) {
-                Server server = KepOpcServerUtil.getServer(opcServerDaPoolKey);
-                if (null == server.getServerState()) {
-                    throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
-                }
-                if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
-                    List<JSONObject> jsonObjectList = generOpcTree(server);
-                    KepOpcServerUtil.returnServer(opcServerDaPoolKey, server);
-                    return jsonObjectList;
-                }
+            Server server = KepOpcServerUtil.createServer(dataSource);
+            if (null == server.getServerState()) {
+                throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
+            }
+            if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
+                List<JSONObject> jsonObjectList = generOpcTree(server);
+                return Result.ok(jsonObjectList);
             }
         } catch (Exception e) {
             throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());