|
|
@@ -37,40 +37,12 @@ public class SmartDataSourceServiceImpl extends ServiceImpl<SmartDataSourceMappe
|
|
|
|
|
|
@Override
|
|
|
public Map<String, String> insertSmartDataSource(SmartDataSource smartDataSource) {
|
|
|
- // 看是否有相同的记录
|
|
|
- QueryWrapper<SmartDataSource> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.like(smartDataSource.getDsClsId() != null, "ds_cls_id", smartDataSource.getDsClsId());
|
|
|
- queryWrapper.like(StringUtils.hasText(smartDataSource.getDsName()), "ds_name", smartDataSource.getDsName());
|
|
|
- queryWrapper.like(StringUtils.hasText(smartDataSource.getDsUrl()), "ds_url", smartDataSource.getDsUrl());
|
|
|
- queryWrapper.like(smartDataSource.getDsStatus() != null, "ds_status", smartDataSource.getDsStatus());
|
|
|
- queryWrapper.like(StringUtils.hasText(smartDataSource.getDsSql()), "ds_sql", smartDataSource.getDsSql());
|
|
|
- queryWrapper.like(StringUtils.hasText(smartDataSource.getDsDescrition()), "ds_descrition", smartDataSource.getDsDescrition());
|
|
|
- List<SmartDataSource> smartDataSources = smartDataSourceMapper.selectList(queryWrapper);
|
|
|
- if (smartDataSources.size() > 0) {
|
|
|
- return CommonUtil.getReturnMap("0", "有重复记录!");
|
|
|
- }
|
|
|
- // 检测必要参数是否为null
|
|
|
- if (smartDataSource.getDsClsId() == null) {
|
|
|
- return CommonUtil.getReturnMap("0", "【数据源类型id】不能为空!");
|
|
|
- }
|
|
|
-
|
|
|
- SmartDataClass smartDataClass = smartDataClassMapper.selectById(smartDataSource.getDsClsId());
|
|
|
- if (smartDataClass == null) {
|
|
|
- return CommonUtil.getReturnMap("0", "选择的【数据源类型】不存在!");
|
|
|
+ // 检测参数,还有是否存在重复记录
|
|
|
+ Map<String, String> stringStringMap = validateParams(smartDataSource, "insert");
|
|
|
+ if (stringStringMap != null) {
|
|
|
+ return stringStringMap;
|
|
|
}
|
|
|
|
|
|
- if (smartDataSource.getDsName() == null) {
|
|
|
- return CommonUtil.getReturnMap("0", "【数据源名称】不能为空!");
|
|
|
- }
|
|
|
- if (smartDataSource.getDsUrl() == null) {
|
|
|
- return CommonUtil.getReturnMap("0", "【数据源连接地址】不能为空!");
|
|
|
- }
|
|
|
- if (smartDataSource.getDsSql() == null) {
|
|
|
- return CommonUtil.getReturnMap("0", "【数据源SQL语言】不能为空!");
|
|
|
- }
|
|
|
- if (smartDataSource.getDsDescrition() == null) {
|
|
|
- return CommonUtil.getReturnMap("0", "【数据源描述】不能为空!");
|
|
|
- }
|
|
|
// 必填的参数不为null,则进行新增操作
|
|
|
int result = smartDataSourceMapper.insert(smartDataSource);
|
|
|
if (result > 0) {
|
|
|
@@ -80,33 +52,43 @@ public class SmartDataSourceServiceImpl extends ServiceImpl<SmartDataSourceMappe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Map<String, String> updateSmartDataSource(SmartDataSource smartDataSource) {
|
|
|
+ // 检测验证参数,和数据库中是否存在重复记录
|
|
|
+ private Map<String, String> validateParams(SmartDataSource smartDataSource, String action) {
|
|
|
// 看是否有相同的记录
|
|
|
QueryWrapper<SmartDataSource> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.like(smartDataSource.getDsId() != null, "ds_id", smartDataSource.getDsId());
|
|
|
+ if ("update".equals(action)) {
|
|
|
+ queryWrapper.like(smartDataSource.getDsId() != null, "ds_id", smartDataSource.getDsId());
|
|
|
+ }
|
|
|
queryWrapper.like(smartDataSource.getDsClsId() != null, "ds_cls_id", smartDataSource.getDsClsId());
|
|
|
queryWrapper.like(StringUtils.hasText(smartDataSource.getDsName()), "ds_name", smartDataSource.getDsName());
|
|
|
queryWrapper.like(StringUtils.hasText(smartDataSource.getDsUrl()), "ds_url", smartDataSource.getDsUrl());
|
|
|
+ queryWrapper.like(StringUtils.hasText(smartDataSource.getDsUser()), "ds_user", smartDataSource.getDsUser());
|
|
|
+ queryWrapper.like(StringUtils.hasText(smartDataSource.getDsPassword()), "ds_password", smartDataSource.getDsPassword());
|
|
|
queryWrapper.like(smartDataSource.getDsStatus() != null, "ds_status", smartDataSource.getDsStatus());
|
|
|
- queryWrapper.like(StringUtils.hasText(smartDataSource.getDsSql()), "ds_sql", smartDataSource.getDsSql());
|
|
|
queryWrapper.like(StringUtils.hasText(smartDataSource.getDsDescrition()), "ds_descrition", smartDataSource.getDsDescrition());
|
|
|
List<SmartDataSource> smartDataSources = smartDataSourceMapper.selectList(queryWrapper);
|
|
|
if (smartDataSources.size() > 0) {
|
|
|
- return CommonUtil.getReturnMap("0", "数据未修改,请修改后再提交!");
|
|
|
+ if ("update".equals(action)) {
|
|
|
+ return CommonUtil.getReturnMap("0", "数据未修改,请修改后再提交!");
|
|
|
+ } else {
|
|
|
+ return CommonUtil.getReturnMap("0", "有重复记录!");
|
|
|
+ }
|
|
|
}
|
|
|
// 检测必要参数是否为null
|
|
|
- if (smartDataSource.getDsId() == null) {
|
|
|
- return CommonUtil.getReturnMap("0", "【数据源id】不能为空!");
|
|
|
- }
|
|
|
- SmartDataSource sdc = smartDataSourceMapper.selectById(smartDataSource.getDsId());
|
|
|
- if (sdc == null) {
|
|
|
- return CommonUtil.getReturnMap("0", "要修改的【数据源】不存在!");
|
|
|
+ if ("update".equals(action)) {
|
|
|
+ if (smartDataSource.getDsId() == null) {
|
|
|
+ return CommonUtil.getReturnMap("0", "【数据源id】不能为空!");
|
|
|
+ }
|
|
|
+ SmartDataSource sdc = smartDataSourceMapper.selectById(smartDataSource.getDsId());
|
|
|
+ if (sdc == null) {
|
|
|
+ return CommonUtil.getReturnMap("0", "要修改的【数据源】不存在!");
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+ // 检测必要参数是否为null
|
|
|
if (smartDataSource.getDsClsId() == null) {
|
|
|
return CommonUtil.getReturnMap("0", "【数据源类型id】不能为空!");
|
|
|
}
|
|
|
+
|
|
|
SmartDataClass smartDataClass = smartDataClassMapper.selectById(smartDataSource.getDsClsId());
|
|
|
if (smartDataClass == null) {
|
|
|
return CommonUtil.getReturnMap("0", "选择的【数据源类型】不存在!");
|
|
|
@@ -118,12 +100,26 @@ public class SmartDataSourceServiceImpl extends ServiceImpl<SmartDataSourceMappe
|
|
|
if (smartDataSource.getDsUrl() == null) {
|
|
|
return CommonUtil.getReturnMap("0", "【数据源连接地址】不能为空!");
|
|
|
}
|
|
|
- if (smartDataSource.getDsSql() == null) {
|
|
|
- return CommonUtil.getReturnMap("0", "【数据源SQL语言】不能为空!");
|
|
|
+ if (smartDataSource.getDsUser() == null) {
|
|
|
+ return CommonUtil.getReturnMap("0", "【数据源用户】不能为空!");
|
|
|
+ }
|
|
|
+ if (smartDataSource.getDsPassword() == null) {
|
|
|
+ return CommonUtil.getReturnMap("0", "【数据源密码】不能为空!");
|
|
|
}
|
|
|
if (smartDataSource.getDsDescrition() == null) {
|
|
|
return CommonUtil.getReturnMap("0", "【数据源描述】不能为空!");
|
|
|
}
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, String> updateSmartDataSource(SmartDataSource smartDataSource) {
|
|
|
+ // 检测参数,还有是否存在重复记录
|
|
|
+ Map<String, String> stringStringMap = validateParams(smartDataSource, "insert");
|
|
|
+ if (stringStringMap != null) {
|
|
|
+ return stringStringMap;
|
|
|
+ }
|
|
|
+
|
|
|
int result = smartDataSourceMapper.updateById(smartDataSource);
|
|
|
if (result > 0) {
|
|
|
return CommonUtil.getReturnMap(String.valueOf(result), "数据源修改成功!");
|
|
|
@@ -140,6 +136,7 @@ public class SmartDataSourceServiceImpl extends ServiceImpl<SmartDataSourceMappe
|
|
|
queryWrapper.like(StringUtils.hasText(smartDataSource.getDsUrl()), "ds_url", smartDataSource.getDsUrl());
|
|
|
queryWrapper.like(smartDataSource.getDsStatus() != null, "ds_status", smartDataSource.getDsStatus());
|
|
|
queryWrapper.like(StringUtils.hasText(smartDataSource.getDsDescrition()), "ds_descrition", smartDataSource.getDsDescrition());
|
|
|
+ queryWrapper.orderByDesc("ds_update_time");
|
|
|
IPage<SmartDataSource> result = smartDataSourceMapper.selectPage(page, queryWrapper);
|
|
|
return new PageUtils<>(result);
|
|
|
}
|