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.
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7530
最新资源
- 直接序列扩频(DSSS)用于BPSK、QPSK和16QAM调制Matlab代码.rar
- 子载波方差vr归一化载波频率偏移Matlab代码.rar
- 自适应调制 OFDM LTE Matlab代码.rar
- 最小二乘均衡器以补偿信道失真Matlab代码.rar
- jQuery实现的砸金蛋抽奖游戏源码.zip
- 户外储能电源方案双向逆变器主板方案,含原理文件,PCB文件,源代码,BOM表,非标件电感与变压器规格参数,户外储能电源额定功率2KW(峰值功率3KW),双向逆变电源生产资料,本生产资料含有前级DCDC
- 结构光多频外差解相位 结构光编解码,可用于基于相位的单目或者双目结构光三维重建系统
- comsol枝晶生长相场法模拟 二元合金 考虑溶质偏析
- 基于python开发的圣诞树代码.txt
- STM 32开发的直流电机PWM 调速项目,包括程序源码和protues 仿真 驱动为L 298N PWM 调速电机是单片机控制电机必会的
- 【复现SCI+参考文献】基于扩展(EKF)和无迹卡尔曼滤波(UKF)的电力系统动态状态估计 该程序对应文章Power System Dynamic State Estimation Using Ex
- spss27操作软件下载
- 传统永磁同步电机的FOC离散化simulink模型,效果较好 附赠传递函数离散化推导的文档,初学者可以入手
- 模块化多电平变流器MMC均衡控制的matlab仿真 1外环电压电流环+电容电压均分+桥臂环流抑制策略; 2子模块直流电压Udc=2000V,11电平级联,额定功率10MW; 3有效的实现
- C#编写电量采集系统,MODBUS 485通信读取70块电量表电度数(电表品牌:中电),里面有完整的采集源码,采集数据10分钟存盘一次存至数量库,随时可查看或计算区间电量 提供,运行稳定,不受使用时
- 静态随机存储器实验报告
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈