|
@@ -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());
|