数据库文档优化

This commit is contained in:
暮光:城中城
2019-07-23 21:39:57 +08:00
parent fb5438e1ec
commit 417132d25c
11 changed files with 56 additions and 20 deletions

View File

@@ -45,7 +45,12 @@ public class DatabaseDocController {
@PostMapping(value = "/getDataSourceList")
public ResponseJson getDataSourceList() {
List<DatabaseFactoryBean> factoryBeanList = databaseRegistrationBean.getDatabaseFactoryBeanList();
Set<String> dataSourceList = factoryBeanList.stream().collect(Collectors.mapping(DatabaseFactoryBean::getHost, Collectors.toSet()));
List<DatabaseFactoryBean> dataSourceList = factoryBeanList.stream().map(val -> {
DatabaseFactoryBean bean = new DatabaseFactoryBean();
bean.setCnName(val.getCnName());
bean.setHost(val.getHost());
return bean;
}).collect(Collectors.toList());
return DocDbResponseJson.ok(dataSourceList);
}
@@ -90,14 +95,15 @@ public class DatabaseDocController {
}
@PostMapping(value = "/getTableAndColumnBySearch")
public ResponseJson getTableAndColumnBySearch(String host, String dbName, String tableName, String searchText) {
public ResponseJson getTableAndColumnBySearch(String host, String dbName, String searchText) {
BaseMapper baseMapper = databaseRegistrationBean.getBaseMapper(host, dbName);
if (baseMapper == null) {
return DocDbResponseJson.warn("未找到对应的数据库连接");
}
if (StringUtils.isNotBlank(searchText)) {
searchText = "%" + searchText + "%";
if (StringUtils.isBlank(searchText)) {
return DocDbResponseJson.ok();
}
searchText = "%" + searchText + "%";
List<QueryTableColumnDescDto> columnDescDto = baseMapper.getTableAndColumnBySearch(dbName, searchText);
return DocDbResponseJson.ok(columnDescDto);
}

View File

@@ -48,7 +48,9 @@ public class DbDatasourceController {
@PostMapping(value = "/update")
public ResponseJson update(DbDatasource dbDatasource) {
if (StringUtils.isBlank(dbDatasource.getDriverClassName())) {
if (StringUtils.isBlank(dbDatasource.getName())) {
return DocDbResponseJson.warn("名字必填");
} else if (StringUtils.isBlank(dbDatasource.getDriverClassName())) {
return DocDbResponseJson.warn("驱动类必选");
} else if (StringUtils.isBlank(dbDatasource.getSourceUrl())) {
return DocDbResponseJson.warn("地址必填");

View File

@@ -79,6 +79,7 @@ public class DatasourceUtil {
SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactoryBean.getObject());
// 组装自定义的bean
databaseFactoryBean.setId(dbDatasource.getId());
databaseFactoryBean.setCnName(dbDatasource.getName());
databaseFactoryBean.setDataSource(dataSource);
databaseFactoryBean.setSqlSessionTemplate(sqlSessionTemplate);
databaseFactoryBean.setUrl(dbUrl);

View File

@@ -15,6 +15,7 @@ public class DatabaseFactoryBean {
private String url;
private String host;
private String dbName;
private String cnName;
private DatabaseProduct databaseProduct;
public Long getId() {
@@ -25,6 +26,14 @@ public class DatabaseFactoryBean {
this.id = id;
}
public String getCnName() {
return cnName;
}
public void setCnName(String cnName) {
this.cnName = cnName;
}
public static enum DatabaseProduct {
MYSQL, SQLSERVER
}