数据导出功能完善
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.zyplayer.doc.db.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.util.TypeUtils;
|
||||
@@ -92,6 +94,7 @@ public class DbDataViewController {
|
||||
*/
|
||||
@PostMapping(value = "/download")
|
||||
public ResponseJson download(HttpServletResponse response, DataViewParam param) {
|
||||
param.setExecuteId(RandomUtil.simpleUUID());
|
||||
DbBaseService dbBaseService = dbBaseFactory.getDbBaseService(param.getSourceId());
|
||||
// 获取列信息等
|
||||
TableColumnVo tableColumnVo = dbBaseService.getTableColumnList(param.getSourceId(), param.getDbName(), param.getTableName());
|
||||
@@ -125,17 +128,26 @@ public class DbDataViewController {
|
||||
@PostMapping(value = "/downloadMultiple")
|
||||
public ResponseJson downloadMultiple(HttpServletResponse response, DataViewParam param) {
|
||||
DbBaseService dbBaseService = dbBaseFactory.getDbBaseService(param.getSourceId());
|
||||
if (StringUtils.isBlank(param.getTableName())) {
|
||||
if (StringUtils.isBlank(param.getTableNames())) {
|
||||
return DocDbResponseJson.warn("请选择导出的表");
|
||||
}
|
||||
StringBuilder resultSb = new StringBuilder();
|
||||
String[] tableNameArr = param.getTableName().split(",");
|
||||
param.setExecuteId(RandomUtil.simpleUUID());
|
||||
StringBuilder resultSb = new StringBuilder("/*\n" +
|
||||
" zyplayer-doc 表数据导出\n" +
|
||||
"\n" +
|
||||
" 数据库 : " + param.getDbName() + "\n" +
|
||||
" 数据库类型 : " + dbBaseService.getDatabaseProduct().name() + "\n" +
|
||||
" 导出时间 : " + DateTime.now().toString() + "\n" +
|
||||
"*/\n\n");
|
||||
String[] tableNameArr = param.getTableNames().split(",");
|
||||
try {
|
||||
for (String tabName : tableNameArr) {
|
||||
param.setTableName(tabName);
|
||||
// 获取列信息等
|
||||
TableColumnVo tableColumnVo = dbBaseService.getTableColumnList(param.getSourceId(), param.getDbName(), tabName);
|
||||
Set<String> conditionSet = StringUtils.isBlank(param.getConditionColumn()) ? Collections.emptySet() : Stream.of(param.getConditionColumn().split(",")).collect(Collectors.toSet());
|
||||
List<TableColumnDescDto> columnList = tableColumnVo.getColumnList();
|
||||
// 找主键作为更新条件
|
||||
Set<String> conditionSet = columnList.stream().filter(item -> Objects.equals(item.getIspramary(), "1")).map(TableColumnDescDto::getName).collect(Collectors.toSet());
|
||||
// 数据查询
|
||||
String queryAllSql = dbBaseService.getQueryAllSql(param);
|
||||
ExecuteParam executeParam = new ExecuteParam();
|
||||
@@ -150,8 +162,9 @@ public class DbDataViewController {
|
||||
resultSb.append(downloadTableData).append("\n");
|
||||
}
|
||||
String prefix = Objects.equals(param.getDownloadType(), "json") ? ".json" : ".sql";
|
||||
baseDownloadService.sendResponse(response, param.getTableName(), prefix, resultSb.toString());
|
||||
baseDownloadService.sendResponse(response, param.getDbName(), prefix, resultSb.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return DocDbResponseJson.error("导出失败:" + e.getMessage());
|
||||
}
|
||||
return DocDbResponseJson.ok();
|
||||
|
||||
@@ -7,6 +7,8 @@ public class DataViewParam {
|
||||
private Integer pageNum;
|
||||
private String dbName;
|
||||
private String tableName;
|
||||
// 下载多张数据表
|
||||
private String tableNames;
|
||||
private String orderColumn;
|
||||
private String orderType;
|
||||
private String condition;
|
||||
@@ -131,4 +133,12 @@ public class DataViewParam {
|
||||
public void setRetainColumn(String retainColumn) {
|
||||
this.retainColumn = retainColumn;
|
||||
}
|
||||
|
||||
public String getTableNames() {
|
||||
return tableNames;
|
||||
}
|
||||
|
||||
public void setTableNames(String tableNames) {
|
||||
this.tableNames = tableNames;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ public class TableColumnDescDto {
|
||||
@ExcelProperty("长度")
|
||||
private String length;
|
||||
|
||||
@ColumnWidth(10)
|
||||
@ExcelProperty("小数点")
|
||||
private String numericScale;
|
||||
|
||||
@ColumnWidth(10)
|
||||
@ExcelProperty("主键")
|
||||
private String ispramary;
|
||||
@@ -99,4 +103,12 @@ public class TableColumnDescDto {
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getNumericScale() {
|
||||
return numericScale;
|
||||
}
|
||||
|
||||
public void setNumericScale(String numericScale) {
|
||||
this.numericScale = numericScale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<result column="TYPE" property="type" jdbcType="VARCHAR" />
|
||||
<result column="NULLABLE" property="nullable" jdbcType="VARCHAR" />
|
||||
<result column="LENGTH" property="length" jdbcType="VARCHAR" />
|
||||
<result column="NUMERIC_SCALE" property="numericScale" jdbcType="VARCHAR" />
|
||||
<result column="ISPRAMARY" property="ispramary" jdbcType="VARCHAR" />
|
||||
<result column="DESCRIPTION" property="description" jdbcType="VARCHAR" />
|
||||
</resultMap>
|
||||
@@ -59,7 +60,10 @@
|
||||
</select>
|
||||
|
||||
<select id="getTableColumnList" resultMap="TableColumnDescDtoMap">
|
||||
SELECT table_name as TABLE_NAME,COLUMN_NAME NAME,column_comment DESCRIPTION,column_type TYPE,if(is_nullable='YES','允许','不允许') NULLABLE
|
||||
SELECT table_name as TABLE_NAME,COLUMN_NAME as NAME,column_comment DESCRIPTION,data_type TYPE,
|
||||
COALESCE(CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION) as `LENGTH`,NUMERIC_SCALE as NUMERIC_SCALE,
|
||||
if(COLUMN_KEY='PRI','1','0') as ISPRAMARY,
|
||||
if(is_nullable='YES','1','0') NULLABLE
|
||||
FROM `INFORMATION_SCHEMA`.Columns
|
||||
WHERE table_schema=#{dbName}
|
||||
<if test="tableName != null">and table_name=#{tableName}</if>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
<!-- 获取表字段集合 -->
|
||||
<select id="getTableColumnList" resultMap="TableColumnDescDtoMap">
|
||||
select t.TABLE_NAME,t.COLUMN_NAME,t.DATA_TYPE,case t.NULLABLE when 'Y' then '允许' when 'N' then '不允许' end NULLABLE, c.COMMENTS
|
||||
select t.TABLE_NAME,t.COLUMN_NAME,t.DATA_TYPE,case t.NULLABLE when 'Y' then '1' when 'N' then '0' end NULLABLE, c.COMMENTS
|
||||
from user_tab_columns t left join user_col_comments c on t.COLUMN_NAME = c.COLUMN_NAME and t.TABLE_NAME = c.TABLE_NAME
|
||||
<where>
|
||||
t.table_name in (select table_name from all_tables where owner = #{dbName} )
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
</select>
|
||||
|
||||
<select id="getTableColumnList" resultMap="TableColumnDescDtoMap">
|
||||
SELECT table_name as TABLE_NAME,a.COLUMN_NAME as NAME,b.DESCRIPTION as DESCRIPTION,udt_name as TYPE,case when is_nullable ='YES' then '允许' else '不允许' end as NULLABLE , case when character_maximum_length>0 then character_maximum_length else numeric_precision end LENGTH
|
||||
SELECT table_name as TABLE_NAME,a.COLUMN_NAME as NAME,b.DESCRIPTION as DESCRIPTION,udt_name as TYPE,case when is_nullable ='YES' then '1' else '0' end as NULLABLE , case when character_maximum_length>0 then character_maximum_length else numeric_precision end LENGTH
|
||||
FROM information_schema.columns a
|
||||
left join (SELECT a.attname as COLUMN_NAME,col_description(a.attrelid,a.attnum) as DESCRIPTION
|
||||
FROM pg_class as c,pg_attribute as a, pg_namespace as n
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
SELECT (
|
||||
SELECT IS_IDENTITY FROM SYS.ALL_COLUMNS
|
||||
WHERE SYS.ALL_COLUMNS.NAME=SYSCOLUMNS.NAME AND OBJECT_ID = OBJECT_ID(#{tableName})
|
||||
) ISIDENTITY,SYSCOLUMNS.NAME NAME,SYSTYPES.NAME TYPE,Iif(SYSCOLUMNS.ISNULLABLE=1,'允许','不允许') NULLABLE,SYSCOLUMNS.LENGTH LENGTH,PRIMARYINFO.ISPRAMARY
|
||||
) ISIDENTITY,SYSCOLUMNS.NAME NAME,SYSTYPES.NAME TYPE,Iif(SYSCOLUMNS.ISNULLABLE=1,'1','0') NULLABLE,SYSCOLUMNS.LENGTH LENGTH,PRIMARYINFO.ISPRAMARY
|
||||
FROM SYSCOLUMNS
|
||||
LEFT JOIN PRIMARYINFO ON PRIMARYINFO.COLUMNNAME=NAME
|
||||
LEFT JOIN SYSTYPES ON SYSCOLUMNS.XUSERTYPE = SYSTYPES.XUSERTYPE
|
||||
|
||||
@@ -18,10 +18,7 @@ import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* poi导出相关工具
|
||||
@@ -144,11 +141,12 @@ public class PoiUtil {
|
||||
run.setFontSize(18);
|
||||
List<List<String>> dataList = new LinkedList<>();
|
||||
List<TableColumnDescDto> tableColumnDescDtos = columnMap.get(tableInfoVo.getTableName());
|
||||
dataList.add(Arrays.asList("字段名", "是否自增", "类型", "空值", "长度", "主键", "注释"));
|
||||
dataList.add(Arrays.asList("字段名", "是否自增", "类型", "空值", "长度", "小数点", "主键", "注释"));
|
||||
// 写入表格
|
||||
for (TableColumnDescDto dto : tableColumnDescDtos) {
|
||||
dataList.add(Arrays.asList(dto.getName(), dto.getIsidenity(), dto.getType(),
|
||||
dto.getNullable(), dto.getLength(), dto.getIspramary(), dto.getDescription()));
|
||||
String nullable = Objects.equals(dto.getNullable(), "1") ? "允许" : "不允许";
|
||||
dataList.add(Arrays.asList(dto.getName(), dto.getIsidenity(), dto.getType(), nullable, dto.getLength(),
|
||||
dto.getNumericScale(), dto.getIspramary(), dto.getDescription()));
|
||||
}
|
||||
PoiUtil.createTable(document, dataList);
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-db.png><title>数据库文档管理</title><link href=css/app.b6b9fe42.css rel=preload as=style><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=js/app.fca745a8.js rel=preload as=script><link href=js/chunk-vendors.d40f789d.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/app.b6b9fe42.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-db-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.d40f789d.js></script><script src=js/app.fca745a8.js></script></body></html>
|
||||
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-db.png><title>数据库文档管理</title><link href=css/app.b6b9fe42.css rel=preload as=style><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=js/app.3a1822c4.js rel=preload as=script><link href=js/chunk-vendors.d40f789d.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/app.b6b9fe42.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-db-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.d40f789d.js></script><script src=js/app.3a1822c4.js></script></body></html>
|
||||
File diff suppressed because one or more lines are too long
@@ -2,8 +2,8 @@
|
||||
ENV = 'development'
|
||||
|
||||
# base api
|
||||
# VUE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc-manage'
|
||||
VUE_APP_BASE_API = 'http://doc.zyplayer.com/zyplayer-doc-manage'
|
||||
VUE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc-manage'
|
||||
# VUE_APP_BASE_API = 'http://doc.zyplayer.com/zyplayer-doc-manage'
|
||||
|
||||
VUE_CLI_BABEL_TRANSPILE_MODULES = true
|
||||
|
||||
|
||||
@@ -28,31 +28,35 @@
|
||||
<span slot="title">库表导出选项</span>
|
||||
<el-form label-width="100px">
|
||||
<el-form-item label="导出类型:">
|
||||
<el-select v-model="exportType" filterable placeholder="请选择导出类型" style="width: 300px;">
|
||||
<el-select v-model="exportType" @change="exportTypeChange" filterable placeholder="请选择导出类型" style="width: 430px;">
|
||||
<el-option label="表结构文档" :value="1"></el-option>
|
||||
<el-option label="建表语句SQL" :value="2"></el-option>
|
||||
<el-option label="表数据" :value="3"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="导出格式:" v-if="exportType == 1">
|
||||
<el-select v-model="exportFormat" filterable placeholder="请选择导出格式" style="width: 300px;">
|
||||
<el-select v-model="exportFormat" filterable placeholder="请选择导出格式" style="width: 430px;">
|
||||
<el-option label="HTML格式" :value="1"></el-option>
|
||||
<el-option label="Excel格式" :value="2"></el-option>
|
||||
<el-option label="Word格式" :value="3"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="导出格式:" v-else-if="exportType == 2">
|
||||
<el-select v-model="exportFormat" filterable placeholder="请选择导出格式" style="width: 300px;">
|
||||
<el-select v-model="exportFormat" filterable placeholder="请选择导出格式" style="width: 430px;">
|
||||
<el-option label="SQL格式" :value="1"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="导出格式:" v-else-if="exportType == 3">
|
||||
<el-select v-model="downloadType" filterable placeholder="请选择导出类型" style="width: 300px;">
|
||||
<el-select v-model="downloadType" filterable placeholder="请选择导出类型" style="width: 430px;">
|
||||
<el-option label="SQL Inserts" value="insert"></el-option>
|
||||
<el-option label="SQL Updates" value="update"></el-option>
|
||||
<el-option label="JSON" value="json"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="数据表:" v-if="exportType == 3 && downloadType === 'insert'">
|
||||
<el-checkbox :true-label="1" :false-label="0" v-model="dropTableFlag" @change="dropTableFlagChange">删除表{{dropTableFlag==1?'!!':''}}</el-checkbox>
|
||||
<el-checkbox :true-label="1" :false-label="0" v-model="createTableFlag" @change="createTableFlagChange">创建表</el-checkbox>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="exportTypeChoiceVisible = false">取 消</el-button>
|
||||
@@ -88,6 +92,8 @@
|
||||
},
|
||||
// 数据导出
|
||||
downloadType: 'insert',
|
||||
dropTableFlag: 0,
|
||||
createTableFlag: 0,
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
@@ -103,6 +109,7 @@
|
||||
},
|
||||
exportTypeChange() {
|
||||
this.exportFormat = 1;
|
||||
console.log(this.exportType);
|
||||
},
|
||||
doExport() {
|
||||
if (!this.exportType) {
|
||||
@@ -120,18 +127,22 @@
|
||||
}
|
||||
tableNames += this.selectTables[i].tableName;
|
||||
}
|
||||
// window.open("zyplayer-doc-db/doc-db/exportDatabase?sourceId=" + this.choiceDatasourceId
|
||||
// + "&exportType=" + this.exportType
|
||||
// + "&dbName=" + this.choiceDatabase
|
||||
// + "&tableNames=" + tableNames);
|
||||
// 改为post方式提交下载
|
||||
this.downloadFormParam.param = {
|
||||
sourceId: this.choiceDatasourceId,
|
||||
exportType: this.exportType,
|
||||
exportFormat: this.exportFormat,
|
||||
dbName: this.choiceDatabase,
|
||||
downloadType: this.downloadType,
|
||||
dropTableFlag: this.dropTableFlag,
|
||||
createTableFlag: this.createTableFlag,
|
||||
tableNames: tableNames,
|
||||
};
|
||||
if (this.exportType == 3) {
|
||||
this.downloadFormParam.url = 'zyplayer-doc-db/data-view/downloadMultiple';
|
||||
} else {
|
||||
this.downloadFormParam.url = 'zyplayer-doc-db/doc-db/exportDatabase';
|
||||
}
|
||||
setTimeout(() => this.$refs.downloadForm.submit(), 0);
|
||||
this.exportTypeChoiceVisible = false;
|
||||
},
|
||||
@@ -166,7 +177,17 @@
|
||||
},
|
||||
handleSelectionChange(val) {
|
||||
this.selectTables = val;
|
||||
}
|
||||
},
|
||||
dropTableFlagChange() {
|
||||
if (this.dropTableFlag === 1) {
|
||||
this.createTableFlag = 1;
|
||||
}
|
||||
},
|
||||
createTableFlagChange() {
|
||||
if (this.createTableFlag == 0) {
|
||||
this.dropTableFlag = 0;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -59,11 +59,16 @@
|
||||
<el-table-column label="自增" width="50">
|
||||
<template slot-scope="scope">{{scope.row.isidentity ? '是' : '否'}}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" label="类型" width="180"></el-table-column>
|
||||
<el-table-column prop="length" label="长度" width="80"></el-table-column>
|
||||
<el-table-column prop="nullable" label="空值" width="80"></el-table-column>
|
||||
<el-table-column prop="type" label="类型" width="110"></el-table-column>
|
||||
<el-table-column prop="length" label="长度" width="110"></el-table-column>
|
||||
<el-table-column prop="numericScale" label="小数点" width="80">
|
||||
<template slot-scope="scope">{{scope.row.numericScale==0 ? '' : scope.row.numericScale}}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="nullable" label="空值" width="80">
|
||||
<template slot-scope="scope">{{scope.row.nullable==1 ? '允许' : '不允许'}}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="主键" width="50">
|
||||
<template slot-scope="scope">{{scope.row.ispramary ? '是' : '否'}}</template>
|
||||
<template slot-scope="scope">{{scope.row.ispramary==1 ? '是' : '否'}}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="注释">
|
||||
<template slot-scope="scope">
|
||||
|
||||
Reference in New Issue
Block a user