【datasource】多数据源整理

pull/3/head
fengshuonan 2021-01-23 22:32:29 +08:00
parent bcd0d7a090
commit fb1fdf07ea
8 changed files with 49 additions and 12 deletions

View File

@ -3,11 +3,11 @@ package cn.stylefeng.roses.kernel.dsctn.modular.controller;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.dsctn.modular.entity.DatabaseInfo;
import cn.stylefeng.roses.kernel.dsctn.modular.pojo.DatabaseInfoParam;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.dsctn.modular.service.DatabaseInfoService;
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
@ -78,6 +78,18 @@ public class DatabaseInfoController {
return new SuccessResponseData(pageResult);
}
/**
*
*
* @author fengshuonan
* @date 2021/1/23 20:29
*/
@GetResource(name = "查询数据源详情", path = "/databaseInfo/detail")
public ResponseData detail(@Validated(BaseRequest.detail.class) DatabaseInfoParam databaseInfoParam) {
DatabaseInfo databaseInfo = databaseInfoService.detail(databaseInfoParam);
return new SuccessResponseData(databaseInfo);
}
}

View File

@ -1,9 +1,9 @@
package cn.stylefeng.roses.kernel.dsctn.modular.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.dsctn.modular.entity.DatabaseInfo;
import cn.stylefeng.roses.kernel.dsctn.modular.pojo.DatabaseInfoParam;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
/**
*
@ -49,4 +49,14 @@ public interface DatabaseInfoService extends IService<DatabaseInfo> {
* @date 2020/11/1 21:47
*/
PageResult<DatabaseInfo> page(DatabaseInfoParam databaseInfoParam);
/**
*
*
* @param databaseInfoParam
* @author fengshuonan
* @date 2021/1/23 20:30
*/
DatabaseInfo detail(DatabaseInfoParam databaseInfoParam);
}

View File

@ -139,6 +139,19 @@ public class DatabaseInfoServiceImpl extends ServiceImpl<DatabaseInfoMapper, Dat
return PageResultFactory.createPageResult(result);
}
@Override
public DatabaseInfo detail(DatabaseInfoParam databaseInfoParam) {
DatabaseInfo oldEntity = this.getById(databaseInfoParam.getDbId());
if (oldEntity == null) {
String userTip = StrUtil.format(EDIT_DATASOURCE_ERROR.getUserTip(), databaseInfoParam.getDbId());
throw new DatasourceContainerException(EDIT_DATASOURCE_ERROR, userTip);
}
oldEntity.setPassword("***");
return oldEntity;
}
/**
*
*

View File

@ -30,7 +30,7 @@ public class DataSourceInitListener implements ApplicationListener<ApplicationCo
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
return Ordered.HIGHEST_PRECEDENCE + 200;
}
@Override

View File

@ -2,12 +2,12 @@ package cn.stylefeng.roses.kernel.dsctn.persist;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.db.api.pojo.druid.DruidProperties;
import cn.stylefeng.roses.kernel.dsctn.api.exception.DatasourceContainerException;
import cn.stylefeng.roses.kernel.dsctn.persist.sqls.AddDatabaseInfoSql;
import cn.stylefeng.roses.kernel.dsctn.persist.sqls.DatabaseListSql;
import cn.stylefeng.roses.kernel.dsctn.persist.sqls.DeleteDatabaseInfoSql;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import cn.stylefeng.roses.kernel.db.api.pojo.druid.DruidProperties;
import cn.stylefeng.roses.kernel.dsctn.api.exception.DatasourceContainerException;
import lombok.extern.slf4j.Slf4j;
import java.sql.*;
@ -82,9 +82,9 @@ public class DataBaseInfoPersistence {
preparedStatement.setLong(1, IdWorker.getId());
preparedStatement.setString(2, MASTER_DATASOURCE_NAME);
preparedStatement.setString(3, druidProperties.getDriverClassName());
preparedStatement.setString(4, druidProperties.getUsername());
preparedStatement.setString(5, druidProperties.getPassword());
preparedStatement.setString(6, druidProperties.getUrl());
preparedStatement.setString(4, druidProperties.getUrl());
preparedStatement.setString(5, druidProperties.getUsername());
preparedStatement.setString(6, druidProperties.getPassword());
preparedStatement.setString(7, "主数据源,项目启动数据源!");
preparedStatement.setString(8, DateUtil.formatDateTime(new Date()));
@ -136,7 +136,7 @@ public class DataBaseInfoPersistence {
try {
druidProperties.setDriverClassName(resultSet.getString("jdbc_driver"));
druidProperties.setUrl(resultSet.getString("jdbc_url"));
druidProperties.setUsername(resultSet.getString("user_name"));
druidProperties.setUsername(resultSet.getString("username"));
druidProperties.setPassword(resultSet.getString("password"));
} catch (SQLException exception) {
log.info(">>> 根据数据库查询结果创建DruidProperties失败", exception);

View File

@ -13,7 +13,7 @@ public class AddDatabaseInfoSql extends AbstractSql {
@Override
protected String mysql() {
return "INSERT INTO `sys_database_info`(`id`, `db_name`, `jdbc_driver`, `user_name`, `password`, `jdbc_url`, `remarks`, `create_time`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
return "INSERT INTO `sys_database_info`(`db_id`, `db_name`, `jdbc_driver`, `jdbc_url`, `username`, `password`, `remarks`, `create_time`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
}
@Override

View File

@ -13,7 +13,7 @@ public class DatabaseListSql extends AbstractSql {
@Override
protected String mysql() {
return "select db_name,jdbc_driver,jdbc_url,user_name,password from sys_database_info";
return "select db_name,jdbc_driver,jdbc_url,username,password from sys_database_info";
}
@Override

View File

@ -1,2 +1,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.stylefeng.roses.kernel.dsctn.starter.GunsDataSourceContainerAutoConfiguration
cn.stylefeng.roses.kernel.dsctn.starter.GunsDataSourceContainerAutoConfiguration
org.springframework.context.ApplicationListener=\
cn.stylefeng.roses.kernel.dsctn.listener.DataSourceInitListener