|
@@ -4,18 +4,19 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.judong.chuanyiserver.dao.ConnectDao;
|
|
|
import com.judong.chuanyiserver.dao.ChannelSettingDao;
|
|
|
import com.judong.chuanyiserver.entity.ChannelSetting;
|
|
|
+import com.judong.chuanyiserver.entity.Config;
|
|
|
import com.judong.chuanyiserver.entity.ServerInformation;
|
|
|
import com.judong.chuanyiserver.enums.ConnectModeEnum;
|
|
|
import com.judong.chuanyiserver.enums.ResultEnum;
|
|
|
+import com.judong.chuanyiserver.exception.CustomException;
|
|
|
import com.judong.chuanyiserver.service.ChannelSettingService;
|
|
|
-import com.judong.chuanyiserver.util.Blank;
|
|
|
-import com.judong.chuanyiserver.util.KepOpcServerUtil;
|
|
|
-import com.judong.chuanyiserver.util.Result;
|
|
|
+import com.judong.chuanyiserver.util.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
@@ -35,7 +36,7 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
|
|
|
return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此标签配置,请更换标签名称");
|
|
|
}
|
|
|
if (channelSettingDao.addChannelSetting(channelSetting) <= 0) {
|
|
|
- return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
|
|
|
+ throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
|
|
|
}
|
|
|
return Result.ok("保存标签配置成功");
|
|
|
} else {
|
|
@@ -44,7 +45,7 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
|
|
|
return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此标签配置,请更换标签名称");
|
|
|
}
|
|
|
if (channelSettingDao.updateChannelSetting(channelSetting) <= 0) {
|
|
|
- return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
|
|
|
+ throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
|
|
|
}
|
|
|
return Result.ok("保存标签配置成功");
|
|
|
}
|
|
@@ -56,15 +57,16 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result getConnectTree(Integer serverId) {
|
|
|
+ public Result getConnectTree(Integer serverId) throws Exception {
|
|
|
ServerInformation serverInformation = connectDao.getServerInformationById(serverId);
|
|
|
if (Blank.isEmpty(serverInformation)) {
|
|
|
return Result.no(ResultEnum.NOT_FOUND.getRespCode(), ResultEnum.NOT_FOUND.getRespMsg());
|
|
|
}
|
|
|
+ serverInformation.setIpPassword(RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
|
|
|
if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
|
|
|
if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- List<ChannelSetting> channelSettings = channelSettingDao.getChannelListNoConfig(serverId);
|
|
|
+ List<ChannelSetting> channelSettings = channelSettingDao.getChHaConfByServerId(serverId);
|
|
|
if (Blank.isNotEmpty(channelSettings)) {
|
|
|
jsonObject.put("tree", KepOpcServerUtil.opcNoConfigTree(serverInformation, channelSettings));
|
|
|
} else {
|
|
@@ -78,13 +80,84 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized Result assignChannelSettingList(Integer serverId, List<String> channelNameList, String configName) {
|
|
|
- //清空配置名称为configName的通道配置
|
|
|
- channelSettingDao.clearConfigByName(serverId, configName);
|
|
|
- //给传入的List都添加configName
|
|
|
- if (channelSettingDao.addConfigByName(serverId, channelNameList, configName) <= 0) {
|
|
|
- return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存配置失败");
|
|
|
+ public synchronized Result assignChannelSettingList(Integer configId, Integer serverId, List<String> channelNameList, String configName) {
|
|
|
+ if (Blank.isEmpty(configId)) {
|
|
|
+ Config config = channelSettingDao.getConfigByName(serverId, configName);
|
|
|
+ if (Blank.isEmpty(config)) {
|
|
|
+ if (channelSettingDao.addConfigByName(serverId, configName, ConstantStr.STOP_IT) <= 0) {
|
|
|
+ throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "保存配置失败");
|
|
|
+ }
|
|
|
+ configId = channelSettingDao.getConfigId(serverId, configName);
|
|
|
+ if (channelSettingDao.addChannelConfigList(serverId, channelNameList, configId) <= 0) {
|
|
|
+ throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "保存配置失败,可能是选择的配置中,没有一个进行标签映射");
|
|
|
+ }
|
|
|
+ return Result.ok("保存配置成功");
|
|
|
+ } else {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已存在同名的配置,请更换配置名称");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ channelSettingDao.clearChannelConfig(configId);
|
|
|
+ if (channelSettingDao.addChannelConfigList(serverId, channelNameList, configId) <= 0) {
|
|
|
+ throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "保存配置失败,可能是选择的配置中,没有一个进行标签映射");
|
|
|
+ }
|
|
|
+ return Result.ok("保存配置成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public synchronized Result renameConfig(Integer configId, String configName) {
|
|
|
+ Config config = channelSettingDao.getConfigNoIdName(configId, configName);
|
|
|
+ if (Blank.isNotEmpty(config)) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已存在同名的配置,请更换配置名称");
|
|
|
+ }
|
|
|
+ if (channelSettingDao.renameConfig(configId, configName) <= 0) {
|
|
|
+ throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "重命名配置失败");
|
|
|
+ }
|
|
|
+ return Result.ok("重命名配置成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result selectConfig(Integer configId) {
|
|
|
+ return Result.ok(channelSettingDao.getChannelByConfigId(configId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public synchronized Result deleteConfig(Integer configId) {
|
|
|
+ Config config = channelSettingDao.getConfigById(configId);
|
|
|
+ if (Blank.isNotEmpty(config)) {
|
|
|
+ if (config.getRunState() == ConstantStr.START_UP) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此配置现在处于启动中,无法删除");
|
|
|
+ }
|
|
|
+ if (channelSettingDao.deleteConfig(configId) <= 0) {
|
|
|
+ throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "删除配置失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ channelSettingDao.clearChannelConfig(configId);
|
|
|
+ return Result.ok("删除配置成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result runConfigById(Integer configId, Integer runState) throws Exception {
|
|
|
+ if (runState != ConstantStr.STOP_IT && runState != ConstantStr.START_UP) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "状态只能为启用或者停用");
|
|
|
+ }
|
|
|
+ Config config = channelSettingDao.getConfigById(configId);
|
|
|
+ ServerInformation serverInformation = connectDao.getServerInformationById(config.getServerId());
|
|
|
+ List<ChannelSetting> channelSettingList=channelSettingDao.getChannelListBySeCoId(config.getServerId(),configId);
|
|
|
+ serverInformation.setIpPassword(RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
|
|
|
+ if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
|
|
|
+ if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
|
|
|
+ return KepOpcServerUtil.opcReadItemListValue(serverInformation, channelSettingList);
|
|
|
+ }
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
+ } else if (serverInformation.getConnectMode() == ConnectModeEnum.KingOPCServer.getValue()) {
|
|
|
+ if (OpcServerUaUtil.validationServerInformation(serverInformation)) {
|
|
|
+ return OpcServerUaUtil.opcReadItemValue(serverInformation, "");
|
|
|
+ }
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
+ } else {
|
|
|
+ throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "没有此连接方式");
|
|
|
}
|
|
|
- return Result.ok("保存配置成功");
|
|
|
}
|
|
|
+
|
|
|
}
|