package com.zyplayer.doc.db.controller;
import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.zyplayer.doc.db.controller.vo.DatabaseExportVo;
import com.zyplayer.doc.db.controller.vo.TableColumnVo;
import com.zyplayer.doc.db.controller.vo.TableColumnVo.TableInfoVo;
import com.zyplayer.doc.db.framework.db.bean.DatabaseFactoryBean;
import com.zyplayer.doc.db.framework.db.bean.DatabaseFactoryBean.DatabaseProduct;
import com.zyplayer.doc.db.framework.db.bean.DatabaseRegistrationBean;
import com.zyplayer.doc.db.framework.db.dto.ColumnInfoDto;
import com.zyplayer.doc.db.framework.db.dto.DatabaseInfoDto;
import com.zyplayer.doc.db.framework.db.dto.QueryTableColumnDescDto;
import com.zyplayer.doc.db.framework.db.dto.TableColumnDescDto;
import com.zyplayer.doc.db.framework.db.dto.TableDescDto;
import com.zyplayer.doc.db.framework.db.dto.TableInfoDto;
import com.zyplayer.doc.db.framework.db.mapper.base.BaseMapper;
import com.zyplayer.doc.db.framework.db.mapper.mysql.MysqlMapper;
import com.zyplayer.doc.db.framework.json.DocDbResponseJson;
import com.zyplayer.doc.db.framework.json.ResponseJson;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ZipUtil;
/**
* 文档控制器
*
* @author 暮光:城中城
* @since 2018年8月8日
*/
@RestController
@RequestMapping("/zyplayer-doc-db/doc-db")
public class DatabaseDocController {
@Autowired(required = false)
DatabaseRegistrationBean databaseRegistrationBean;
@PostMapping(value = "/getDataSourceList")
public ResponseJson getDataSourceList() {
List<DatabaseFactoryBean> factoryBeanList = databaseRegistrationBean.getDatabaseFactoryBeanList();
Set<String> dataSourceList = factoryBeanList.stream().collect(Collectors.mapping(DatabaseFactoryBean::getHost, Collectors.toSet()));
return DocDbResponseJson.ok(dataSourceList);
}
@PostMapping(value = "/getDatabaseList")
public ResponseJson getDatabaseList(String host) {
BaseMapper baseMapper = databaseRegistrationBean.getBaseMapperByHost(host);
if (baseMapper == null) {
return DocDbResponseJson.warn("未找到对应的数据库连接");
}
List<DatabaseInfoDto> dbNameDtoList = baseMapper.getDatabaseList();
return DocDbResponseJson.ok(dbNameDtoList);
}
@PostMapping(value = "/getTableList")
public ResponseJson getTableList(String host, String dbName) {
BaseMapper baseMapper = databaseRegistrationBean.getBaseMapper(host, dbName);
if (baseMapper == null) {
return DocDbResponseJson.warn("未找到对应的数据库连接");
}
List<TableInfoDto> dbTableList = baseMapper.getTableList(dbName);
return DocDbResponseJson.ok(dbTableList);
}
@PostMapping(value = "/getTableColumnList")
public ResponseJson getTableColumnList(String host, String dbName, String tableName) {
DatabaseFactoryBean databaseFactoryBean = databaseRegistrationBean.getDatabaseFactoryBean(host, dbName);
if (databaseFactoryBean == null) {
return DocDbResponseJson.warn("未找到对应的数据库连接");
}
TableColumnVo tableColumnVo = this.getTableColumnVo(databaseFactoryBean, dbName, tableName);
return DocDbResponseJson.ok(tableColumnVo);
}
@PostMapping(value = "/getTableColumnDescList")
public ResponseJson getTableColumnDescList(String host, String dbName, String tableName) {
BaseMapper baseMapper = databaseRegistrationBean.getBaseMapper(host, dbName);
if (baseMapper == null) {
return DocDbResponseJson.warn("未找到对应的数据库连接");
}
List<TableColumnDescDto> columnDescDto = baseMapper.getTableColumnDescList(tableName);
return DocDbResponseJson.ok(columnDescDto);
}
@PostMapping(value = "/getTableAndColumnBySearch")
public ResponseJson getTableAndColumnBySearch(String host, String dbName, String tableName, String searchText) {
BaseMapper baseMapper = databaseRegistrationBean.getBaseMapper(host, dbName);
if (baseMapper == null) {
return DocDbResponseJson.warn("未找到对应的数据库连接");
}
if (StringUtils.isNotBlank(searchText)) {
searchText = "%" + searchText + "%";
}
List<QueryTableColumnDescDto> columnDescDto = baseMapper.getTableAndColumnBySearch(dbName, searchText);
return DocDbResponseJson.ok(columnDescDto);
}
@PostMapping(value = "/getTableDescList")
public ResponseJson getTableDescList(String host, String dbName, String tableName) {
BaseMapper baseMapper = databaseRegistrationBean.getBaseMapper(host, dbName);
if (baseMapper == null) {
return DocDbResponseJson.warn("未找到对应的数据库连接");
}
List<TableDescDto> columnDescDto = baseMapper.getTableDescList(tableName);
return DocDbResponseJson.ok(columnDescDto);
}
@PostMapping(value = "/updateTableDesc")
public ResponseJson updateTableDesc(String host, String dbName, String tableName, String newDesc) {
BaseMapper baseMapper = databaseRegistrationBean.getBaseMapper(host, dbName);
if (baseMapper == null) {
return DocDbResponseJson.warn("未找到对应的数据库连接");
}
baseMapper.updateTableDesc(dbName, tableName, newDesc);
return DocDbResponseJson.ok();
}
@PostMapping(value = "/updateTableColumnDesc")
public ResponseJson updateTableColumnDesc(String host, String dbName, String tableName, String columnName, String newDesc) {
BaseMapper baseMapper = databaseRegistrationBean.getBaseMapper(host, dbName);
if (baseMapper == null) {
return DocDbResponseJson.warn("未找到对应的数据库连接");
}
ColumnInfoDto columnInfo = null;
// mysql要同时修改类型默认值等,所以先查出来
MysqlMapper mysqlMapper = databaseRegistrationBean.getBaseMapper(host, dbName, MysqlMapper.class);
if (mysqlMapper != null) {
columnInfo = mysqlMapper.getColumnInfo(dbName, tableName, columnName);
String isNullable = Optional.ofNullable(columnInfo.getIsNullable()).orElse("");
columnInfo.setIsNullable("yes".equalsIgnoreCase(isNullable) ? "null" : "not null");
String columnDefault = columnInfo.getColumnDefault();
if (StringUtils.isNotBlank(columnDefault)) {
columnInfo.setColumnDefault("DEFAULT " + columnDefault);
} else {
columnInfo.setColumnDefault("");
}
String extra = columnInfo.getExtra();
columnInfo.setExtra(StringUtils.isBlank(extra) ? "" : extra);
}
baseMapper.updateTableColumnDesc(dbName, tableName, columnName, newDesc, columnInfo);
return DocDbResponseJson.ok();
}
@GetMapping(value = "/exportDatabase")
public ResponseJson exportDatabase(HttpServletResponse response, String host, String dbName, String tableNames) {
if (StringUtils.isBlank(tableNames)) {
return DocDbResponseJson.warn("请选择需要导出的表");
}
DatabaseFactoryBean databaseFactoryBean = databaseRegistrationBean.getDatabaseFactoryBean(host, dbName);
if (databaseFactoryBean == null) {
return DocDbResponseJson.warn("未找到对应的数据库连接");
}
List<TableInfoVo> tableList = new LinkedList<>();
Map<String, List<TableColumnDescDto>> columnList = new HashMap<>();
String[] tableNameArr = tableNames.split(",");
for (String tableName : tableNameArr) {
if (StringUtils.isBlank(tableName)) {
continue;
}
TableColumnVo tableColumnVo = this.getTableColumnVo(databaseFactoryBean, dbName, tableName);
columnList.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
界面重构,更加现代化和易维护。支持页面上动态添加数据源,不用在后端写死。左侧树形结构展示文档,更加方便。项目还是以模块化的方式开发的,可单独拿出来放到另外的项目里。数据库文档工具,网页方式管理,只需两步即可对表注释、字段注释进行查看、修改、导出等操作,支持字段或注释的模糊查询,只有一个单独的页面,方便集成到已有的管理系统里面,本工具不对数据源进行管理,因为后台管理系统肯定是已有的数据源,没必要再来创建,只需要注入数据源即可管理
资源推荐
资源详情
资源评论
收起资源包目录
zyplayer-doc-db-master.zip (74个子文件)
zyplayer-doc-db-master
.settings
org.eclipse.wst.validation.prefs 50B
pom.xml 6KB
src
main
resources
export
js
doc-db.js 2KB
database.js 14KB
common.js 5KB
formatjson.js 4KB
chosen.min.js 27KB
mgResizeble.js 3KB
zui.lite.min.js 43KB
jquery-3.1.0.min.js 84KB
toast.js 763B
zui.min.js 85KB
css
doc-db.css 1KB
zui.lite.min.css 106KB
zui-theme.min.css 29KB
zui.min.css 147KB
chosen.min.css 10KB
doc-db.html 2KB
fonts
zenicon.svg 290KB
zenicon.woff 83KB
zenicon.eot 83KB
zenicon.ttf 83KB
doc-db.html 7KB
webjars
doc-db
js
doc-db.js 13KB
common.js 5KB
formatjson.js 4KB
echarts.min.js 727KB
mgResizeble.js 3KB
jquery-3.1.0.min.js 84KB
toast.js 763B
option-table-relation.js 846B
img
expanded.png 331B
collapsed.png 340B
css
doc-db.css 1KB
zui
lib
dashboard
zui.dashboard.min.js 9KB
zui.dashboard.min.css 6KB
chosen
chosen.css 12KB
chosen.min.js 27KB
chosen.min.css 10KB
chosen.js 54KB
js
zui.lite.min.js 43KB
zui.min.js 85KB
css
zui.lite.min.css 106KB
zui-theme.min.css 29KB
zui.min.css 147KB
fonts
zenicon.svg 290KB
zenicon.woff 83KB
zenicon.eot 83KB
zenicon.ttf 83KB
java
com
zyplayer
doc
db
controller
DatabaseDocController.java 10KB
vo
DatabaseExportVo.java 750B
TableColumnVo.java 1012B
framework
configuration
ApplicationListenerBean.java 4KB
EnableDocDb.java 477B
json
DocDbResponseJson.java 3KB
ResponseJson.java 173B
db
mapper
mysql
MysqlBaseMapper.xml 3KB
MysqlMapper.java 457B
MysqlMapper.xml 632B
base
BaseMapper.java 3KB
sqlserver
SqlServerBaseMapper.xml 5KB
SqlServerMapper.java 220B
support
ErpRoutingDataSource.java 351B
DBInfoHolder.java 399B
dto
TableInfoDto.java 606B
ColumnInfoDto.java 786B
QueryTableColumnDescDto.java 629B
DatabaseInfoDto.java 237B
TableColumnDescDto.java 1KB
TableDescDto.java 599B
bean
DatabaseFactoryBean.java 1KB
DatabaseRegistrationBean.java 3KB
LICENSE 10KB
对外文档模板.zip 323KB
共 74 条
- 1
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7363
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功