Commit 6f0d8f51 authored by fangxinjiang's avatar fangxinjiang

新增代码平台服务

parent 40bf2b76
...@@ -82,7 +82,7 @@ public class GenDsConfController { ...@@ -82,7 +82,7 @@ public class GenDsConfController {
@SysLog("新增数据源表") @SysLog("新增数据源表")
@PostMapping @PostMapping
public R<Boolean> save(@RequestBody GenDatasourceConf datasourceConf) { public R<Boolean> save(@RequestBody GenDatasourceConf datasourceConf) {
return R.ok(datasourceConfService.saveDsByEnc(datasourceConf)); return datasourceConfService.saveDsByEnc(datasourceConf);
} }
/** /**
...@@ -93,7 +93,7 @@ public class GenDsConfController { ...@@ -93,7 +93,7 @@ public class GenDsConfController {
@SysLog("修改数据源表") @SysLog("修改数据源表")
@PutMapping @PutMapping
public R<Boolean> updateById(@RequestBody GenDatasourceConf conf) { public R<Boolean> updateById(@RequestBody GenDatasourceConf conf) {
return R.ok(datasourceConfService.updateDsByEnc(conf)); return datasourceConfService.updateDsByEnc(conf);
} }
/** /**
......
...@@ -17,6 +17,7 @@ package com.yifu.cloud.plus.v1.yifu.codegen.service; ...@@ -17,6 +17,7 @@ package com.yifu.cloud.plus.v1.yifu.codegen.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.codegen.entity.GenDatasourceConf; import com.yifu.cloud.plus.v1.yifu.codegen.entity.GenDatasourceConf;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
/** /**
* 数据源表 * 数据源表
...@@ -31,14 +32,14 @@ public interface GenDatasourceConfService extends IService<GenDatasourceConf> { ...@@ -31,14 +32,14 @@ public interface GenDatasourceConfService extends IService<GenDatasourceConf> {
* @param genDatasourceConf * @param genDatasourceConf
* @return * @return
*/ */
Boolean saveDsByEnc(GenDatasourceConf genDatasourceConf); R<Boolean> saveDsByEnc(GenDatasourceConf genDatasourceConf);
/** /**
* 更新数据源 * 更新数据源
* @param genDatasourceConf * @param genDatasourceConf
* @return * @return
*/ */
Boolean updateDsByEnc(GenDatasourceConf genDatasourceConf); R<Boolean> updateDsByEnc(GenDatasourceConf genDatasourceConf);
/** /**
* 更新动态数据的数据源列表 * 更新动态数据的数据源列表
...@@ -52,7 +53,7 @@ public interface GenDatasourceConfService extends IService<GenDatasourceConf> { ...@@ -52,7 +53,7 @@ public interface GenDatasourceConfService extends IService<GenDatasourceConf> {
* @param datasourceConf 数据源信息 * @param datasourceConf 数据源信息
* @return 有效/无效 * @return 有效/无效
*/ */
Boolean checkDataSource(GenDatasourceConf datasourceConf); String checkDataSource(GenDatasourceConf datasourceConf);
/** /**
* 通过数据源名称删除 * 通过数据源名称删除
......
...@@ -23,6 +23,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -23,6 +23,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.codegen.entity.GenDatasourceConf; import com.yifu.cloud.plus.v1.yifu.codegen.entity.GenDatasourceConf;
import com.yifu.cloud.plus.v1.yifu.codegen.mapper.GenDatasourceConfMapper; import com.yifu.cloud.plus.v1.yifu.codegen.mapper.GenDatasourceConfMapper;
import com.yifu.cloud.plus.v1.yifu.codegen.service.GenDatasourceConfService; import com.yifu.cloud.plus.v1.yifu.codegen.service.GenDatasourceConfService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.util.SpringContextHolder; import com.yifu.cloud.plus.v1.yifu.common.core.util.SpringContextHolder;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -55,10 +57,11 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM ...@@ -55,10 +57,11 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
* @return * @return
*/ */
@Override @Override
public Boolean saveDsByEnc(GenDatasourceConf conf) { public R<Boolean> saveDsByEnc(GenDatasourceConf conf) {
String checkOut = checkDataSource(conf);
// 校验配置合法性 // 校验配置合法性
if (!checkDataSource(conf)) { if (Common.isNotNull(checkOut)) {
return Boolean.FALSE; return R.failed(false,checkOut);
} }
// 添加动态数据源 // 添加动态数据源
...@@ -67,7 +70,7 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM ...@@ -67,7 +70,7 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
// 更新数据库配置 // 更新数据库配置
conf.setPassword(stringEncryptor.encrypt(conf.getPassword())); conf.setPassword(stringEncryptor.encrypt(conf.getPassword()));
this.baseMapper.insert(conf); this.baseMapper.insert(conf);
return Boolean.TRUE; return R.ok(true);
} }
/** /**
...@@ -76,9 +79,11 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM ...@@ -76,9 +79,11 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
* @return * @return
*/ */
@Override @Override
public Boolean updateDsByEnc(GenDatasourceConf conf) { public R<Boolean> updateDsByEnc(GenDatasourceConf conf) {
if (!checkDataSource(conf)) { String checkOut = checkDataSource(conf);
return Boolean.FALSE; // 校验配置合法性
if (Common.isNotNull(checkOut)) {
return R.failed(false,checkOut);
} }
// 先移除 // 先移除
SpringContextHolder.getBean(DynamicRoutingDataSource.class) SpringContextHolder.getBean(DynamicRoutingDataSource.class)
...@@ -92,7 +97,7 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM ...@@ -92,7 +97,7 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
conf.setPassword(stringEncryptor.encrypt(conf.getPassword())); conf.setPassword(stringEncryptor.encrypt(conf.getPassword()));
} }
this.baseMapper.updateById(conf); this.baseMapper.updateById(conf);
return Boolean.TRUE; return R.ok(true);
} }
/** /**
...@@ -131,15 +136,15 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM ...@@ -131,15 +136,15 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
* @return 有效/无效 * @return 有效/无效
*/ */
@Override @Override
public Boolean checkDataSource(GenDatasourceConf conf) { public String checkDataSource(GenDatasourceConf conf) {
try { try {
DriverManager.getConnection(conf.getUrl(), conf.getUsername(), conf.getPassword()); DriverManager.getConnection(conf.getUrl(), conf.getUsername(), conf.getPassword());
} }
catch (SQLException e) { catch (SQLException e) {
log.error("数据源配置 {} , 获取链接失败", conf.getName(), e); log.error("数据源配置 {} , 获取链接失败", conf.getName(), e);
return Boolean.FALSE; return "数据源配置 {} , 获取链接失败"+conf.getName();
} }
return Boolean.TRUE; return null;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment