|
@@ -50,16 +50,36 @@ public class ConnectServiceImpl implements ConnectService {
|
|
|
|
|
|
@Override
|
|
|
public synchronized Result saveConnect(ServerInformation serverInformation) {
|
|
|
+ try {
|
|
|
+ RSAUtil.decrypt(serverInformation.getIpPassword(), "UTF-8");
|
|
|
+ } catch (Exception e) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "密码错误");
|
|
|
+ }
|
|
|
String userId = userUtil.getCurrentUserId();
|
|
|
serverInformation.setUserId(userId);
|
|
|
- ServerInformation si = connectDao.getServerInformation(userId, serverInformation.getIpAddress());
|
|
|
+ ServerInformation si = connectDao.getServerInformation(userId, serverInformation.getConnectName(), serverInformation.getConnectMode());
|
|
|
if (Blank.isNotEmpty(si)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "该用户下此ip已被使保存,请更换其他ip");
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "该用户下此连接名称和类型已被使用,请更换其他连接名称和类型");
|
|
|
}
|
|
|
- if (connectDao.saveConnect(serverInformation) <= 0) {
|
|
|
- return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存连接失败");
|
|
|
+ if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
|
|
|
+ if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
|
|
|
+ if (connectDao.saveConnect(serverInformation) <= 0) {
|
|
|
+ return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存连接失败");
|
|
|
+ }
|
|
|
+ return Result.ok("保存连接成功");
|
|
|
+ }
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
+ } else if (serverInformation.getConnectMode() == ConnectModeEnum.KingOPCServer.getValue()) {
|
|
|
+ if (OpcServerUaUtil.validationServerInformation(serverInformation)) {
|
|
|
+ if (connectDao.saveConnect(serverInformation) <= 0) {
|
|
|
+ return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存连接失败");
|
|
|
+ }
|
|
|
+ return Result.ok("保存连接成功");
|
|
|
+ }
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
+ } else {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "没有此连接方式");
|
|
|
}
|
|
|
- return Result.ok("保存连接成功");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -70,14 +90,29 @@ public class ConnectServiceImpl implements ConnectService {
|
|
|
@Override
|
|
|
public synchronized Result editConnect(ServerInformation serverInformation) {
|
|
|
String userId = userUtil.getCurrentUserId();
|
|
|
- ServerInformation si = connectDao.getServerInformationEdit(serverInformation.getId(), userId, serverInformation.getIpAddress());
|
|
|
+ ServerInformation si = connectDao.getServerInformationEdit(serverInformation.getId(), userId, serverInformation.getConnectName(), serverInformation.getConnectMode());
|
|
|
if (Blank.isNotEmpty(si)) {
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "该用户下此ip已被使保存,请更换其他ip");
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "该用户下此连接名称和类型已被使用,请更换其他连接名称和类型");
|
|
|
}
|
|
|
- if (connectDao.editConnect(serverInformation) <= 0) {
|
|
|
- return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "编辑连接失败");
|
|
|
+ if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
|
|
|
+ if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
|
|
|
+ if (connectDao.editConnect(serverInformation) <= 0) {
|
|
|
+ return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "编辑连接失败");
|
|
|
+ }
|
|
|
+ return Result.ok("编辑连接成功");
|
|
|
+ }
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
+ } else if (serverInformation.getConnectMode() == ConnectModeEnum.KingOPCServer.getValue()) {
|
|
|
+ if (OpcServerUaUtil.validationServerInformation(serverInformation)) {
|
|
|
+ if (connectDao.editConnect(serverInformation) <= 0) {
|
|
|
+ return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "编辑连接失败");
|
|
|
+ }
|
|
|
+ return Result.ok("编辑连接成功");
|
|
|
+ }
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
+ } else {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "没有此连接方式");
|
|
|
}
|
|
|
- return Result.ok("编辑连接成功");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -90,6 +125,29 @@ public class ConnectServiceImpl implements ConnectService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Result closeConnect(int id) throws Exception {
|
|
|
+ ServerInformation serverInformation = connectDao.getServerInformationById(id);
|
|
|
+ if (Blank.isEmpty(serverInformation)) {
|
|
|
+ return Result.no(ResultEnum.NOT_FOUND.getRespCode(), ResultEnum.NOT_FOUND.getRespMsg());
|
|
|
+ }
|
|
|
+ serverInformation.setIpPassword(RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
|
|
|
+ //如果连接方式为kepserver
|
|
|
+ if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
|
|
|
+ if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
|
|
|
+ return KepOpcServerUtil.closeConnect(serverInformation);
|
|
|
+ }
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
+ } else if (serverInformation.getConnectMode() == ConnectModeEnum.KingOPCServer.getValue()) {
|
|
|
+ if (OpcServerUaUtil.validationServerInformation(serverInformation)) {
|
|
|
+ return OpcServerUaUtil.closeConnect(serverInformation);
|
|
|
+ }
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
+ } else {
|
|
|
+ throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "没有此连接方式");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Result openConnect(int id) throws Exception {
|
|
|
ServerInformation serverInformation = connectDao.getServerInformationById(id);
|
|
|
if (Blank.isEmpty(serverInformation)) {
|