数据库增加postgresql支持,展示优化
This commit is contained in:
@@ -30,6 +30,16 @@ public class DatasourceUtil {
|
||||
}
|
||||
databaseFactoryBean.setDatabaseProduct(DatabaseFactoryBean.DatabaseProduct.MYSQL);
|
||||
resources = resolver.getResources("classpath:com/zyplayer/doc/db/framework/db/mapper/mysql/*.xml");
|
||||
} else if (dbUrl.contains("postgresql")) {
|
||||
// jdbc:mysql://192.168.0.1:3306/user_info?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true
|
||||
String[] urlParamArr = dbUrl.split("\\?");
|
||||
String[] urlDbNameArr = urlParamArr[0].split("/");
|
||||
if (urlDbNameArr.length >= 2) {
|
||||
databaseFactoryBean.setDbName(urlDbNameArr[urlDbNameArr.length - 1]);
|
||||
//databaseFactoryBean.setHost(urlDbNameArr[urlDbNameArr.length - 2]);
|
||||
}
|
||||
databaseFactoryBean.setDatabaseProduct(DatabaseFactoryBean.DatabaseProduct.POSTGRESQL);
|
||||
resources = resolver.getResources("classpath:com/zyplayer/doc/db/framework/db/mapper/postgresql/*.xml");
|
||||
} else if (dbUrl.contains("sqlserver")) {
|
||||
// jdbc:jtds:sqlserver://192.168.0.1:33434;socketTimeout=60;DatabaseName=user_info;
|
||||
String[] urlParamArr = dbUrl.split(";");
|
||||
|
||||
@@ -43,7 +43,7 @@ public class DatabaseFactoryBean {
|
||||
}
|
||||
|
||||
public static enum DatabaseProduct {
|
||||
MYSQL, SQLSERVER, ORACLE
|
||||
MYSQL, SQLSERVER, ORACLE, POSTGRESQL
|
||||
}
|
||||
|
||||
public DruidDataSource getDataSource() {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TableColumnDescDto {
|
||||
private String type;
|
||||
|
||||
@ColumnWidth(10)
|
||||
@ExcelProperty("NULL")
|
||||
@ExcelProperty("空值")
|
||||
private String nullable;
|
||||
|
||||
@ColumnWidth(10)
|
||||
|
||||
@@ -42,32 +42,32 @@
|
||||
|
||||
<select id="getDatabaseList" resultType="com.zyplayer.doc.db.framework.db.dto.DatabaseInfoDto">
|
||||
select TABLE_SCHEMA dbName
|
||||
from information_schema.tables
|
||||
from `information_schema`.tables
|
||||
<!--排除系统库-->
|
||||
where TABLE_SCHEMA != 'information_schema'
|
||||
group by TABLE_SCHEMA
|
||||
</select>
|
||||
|
||||
<select id="getTableDdl" resultType="java.util.Map">
|
||||
show create table ${dbName}.${tableName}
|
||||
show create table `${dbName}`.${tableName}
|
||||
</select>
|
||||
|
||||
<select id="getTableList" resultType="com.zyplayer.doc.db.framework.db.dto.TableInfoDto">
|
||||
select table_schema dbName,table_name tableName, table_comment as tableComment
|
||||
from information_schema.tables
|
||||
from `information_schema`.tables
|
||||
<if test="dbName != null">where table_schema=#{dbName}</if>
|
||||
</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',1,0) NULLABLE
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
SELECT table_name as TABLE_NAME,COLUMN_NAME NAME,column_comment DESCRIPTION,column_type TYPE,if(is_nullable='YES','允许','不允许') NULLABLE
|
||||
FROM `INFORMATION_SCHEMA`.Columns
|
||||
WHERE table_schema=#{dbName}
|
||||
<if test="tableName != null">and table_name=#{tableName}</if>
|
||||
ORDER BY ordinal_position
|
||||
</select>
|
||||
|
||||
<select id="getTableStatus" resultMap="TableStatusDtoMap">
|
||||
show table status from ${dbName} like #{tableName}
|
||||
show table status from `${dbName}` like #{tableName}
|
||||
</select>
|
||||
|
||||
<select id="getTableColumnDescList" resultMap="TableColumnDescDtoMap">
|
||||
@@ -76,13 +76,13 @@
|
||||
|
||||
<select id="getTableAndColumnBySearch" resultMap="QueryTableColumnDescDtoMap">
|
||||
SELECT TABLE_NAME, COLUMN_NAME, column_comment DESCRIPTION
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
FROM `INFORMATION_SCHEMA`.Columns
|
||||
WHERE table_schema=#{dbName} AND (COLUMN_NAME like #{searchText} or column_comment like #{searchText})
|
||||
</select>
|
||||
|
||||
<select id="getTableDescList" resultType="com.zyplayer.doc.db.framework.db.dto.TableDescDto">
|
||||
select table_name tableName, table_comment as description
|
||||
from information_schema.tables
|
||||
from `information_schema`.tables
|
||||
<where>
|
||||
<if test="dbName != null">and table_schema=#{dbName}</if>
|
||||
<if test="tableName != null">and table_name=#{tableName}</if>
|
||||
@@ -90,11 +90,11 @@
|
||||
</select>
|
||||
|
||||
<insert id="updateTableDesc">
|
||||
alter table ${dbName}.${tableName} comment #{newDesc}
|
||||
alter table `${dbName}`.${tableName} comment #{newDesc}
|
||||
</insert>
|
||||
|
||||
<insert id="updateTableColumnDesc">
|
||||
alter table ${dbName}.${tableName} modify column ${columnName}
|
||||
alter table `${dbName}`.${tableName} modify column ${columnName}
|
||||
${columnInfo.columnType} ${columnInfo.isNullable} ${columnInfo.columnDefault} ${columnInfo.extra}
|
||||
comment #{newDesc}
|
||||
</insert>
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
select USERNAME dbName from all_users
|
||||
</select>
|
||||
|
||||
<select id="getTableStatus" resultType="com.zyplayer.doc.db.controller.vo.TableStatusVo">
|
||||
select 1
|
||||
</select>
|
||||
|
||||
<!-- 获取表列表 -->
|
||||
<select id="getTableList" resultType="com.zyplayer.doc.db.framework.db.dto.TableInfoDto">
|
||||
select t.OWNER as dbName,t.TABLE_NAME as tableName,c.COMMENTS as tableComment from all_tables t left join user_tab_comments c on t.TABLE_NAME = c.TABLE_NAME
|
||||
@@ -31,7 +35,7 @@
|
||||
|
||||
<!-- 获取表字段集合 -->
|
||||
<select id="getTableColumnList" resultMap="TableColumnDescDtoMap">
|
||||
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
|
||||
select t.TABLE_NAME,t.COLUMN_NAME,t.DATA_TYPE,case t.NULLABLE when 'Y' then '允许' when 'N' then '不允许' 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} )
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zyplayer.doc.db.framework.db.mapper.base.BaseMapper">
|
||||
|
||||
<resultMap id="TableColumnDescDtoMap" type="com.zyplayer.doc.db.framework.db.dto.TableColumnDescDto">
|
||||
<result column="TABLE_NAME" property="tableName" jdbcType="VARCHAR"/>
|
||||
<result column="NAME" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="ISIDENITY" property="isidenity" jdbcType="VARCHAR"/>
|
||||
<result column="TYPE" property="type" jdbcType="VARCHAR"/>
|
||||
<result column="NULLABLE" property="nullable" jdbcType="VARCHAR"/>
|
||||
<result column="LENGTH" property="length" jdbcType="VARCHAR"/>
|
||||
<result column="ISPRAMARY" property="ispramary" jdbcType="VARCHAR"/>
|
||||
<result column="DESCRIPTION" property="description" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="QueryTableColumnDescDtoMap" type="com.zyplayer.doc.db.framework.db.dto.QueryTableColumnDescDto">
|
||||
<result column="TABLE_NAME" property="tableName" jdbcType="VARCHAR"/>
|
||||
<result column="COLUMN_NAME" property="columnName" jdbcType="VARCHAR"/>
|
||||
<result column="DESCRIPTION" property="description" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getDatabaseList" resultType="com.zyplayer.doc.db.framework.db.dto.DatabaseInfoDto">
|
||||
SELECT distinct table_schema as dbName
|
||||
FROM information_schema.tables ORDER BY 1
|
||||
</select>
|
||||
|
||||
<select id="getTableStatus" resultType="com.zyplayer.doc.db.controller.vo.TableStatusVo">
|
||||
SELECT relname as name, reltuples as rows
|
||||
FROM pg_class r JOIN pg_namespace n
|
||||
ON (relnamespace = n.oid)
|
||||
WHERE relkind = 'r' AND n.nspname = #{dbName} and relname = #{tableName}
|
||||
</select>
|
||||
|
||||
<select id="getTableList" resultType="com.zyplayer.doc.db.framework.db.dto.TableInfoDto">
|
||||
select relname as tableName,cast(obj_description(relfilenode,'pg_class') as varchar) as tableComment from pg_class c
|
||||
where relname in (select tablename from pg_tables where schemaname=#{dbName} and position('_2' in tablename)=0)
|
||||
order by 1
|
||||
</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
|
||||
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
|
||||
where a.attrelid = c.oid and a.attnum>0
|
||||
and c.relnamespace = n.oid AND n.nspname = #{dbName} and c.relname = #{tableName}) b on a.COLUMN_NAME= b.COLUMN_NAME
|
||||
WHERE table_schema=#{dbName} and table_name=#{tableName}
|
||||
ORDER BY ordinal_position
|
||||
</select>
|
||||
|
||||
<select id="getTableColumnDescList" resultMap="TableColumnDescDtoMap">
|
||||
SELECT
|
||||
col_description (A .attrelid, A .attnum) AS COMMENT,
|
||||
format_type (A .atttypid, A .atttypmod) AS TYPE,
|
||||
A .attname AS NAME,
|
||||
A .attnotnull AS NOTNULL
|
||||
FROM
|
||||
pg_class AS C,
|
||||
pg_attribute AS A
|
||||
WHERE
|
||||
C .relname =#{tableName}
|
||||
AND A .attrelid = C .oid
|
||||
AND A .attnum > 0
|
||||
</select>
|
||||
|
||||
<select id="getTableAndColumnBySearch" resultMap="QueryTableColumnDescDtoMap">
|
||||
SELECT
|
||||
col_description (A .attrelid, A .attnum) AS COMMENT,
|
||||
format_type (A .atttypid, A .atttypmod) AS TYPE,
|
||||
A .attname AS NAME,
|
||||
A .attnotnull AS NOTNULL
|
||||
FROM
|
||||
pg_class AS C,
|
||||
pg_attribute AS A
|
||||
WHERE
|
||||
C .relnamelike #{searchText}
|
||||
AND A .attrelid = C .oid
|
||||
AND A .attnum > 0
|
||||
</select>
|
||||
|
||||
<select id="getTableDescList" resultType="com.zyplayer.doc.db.framework.db.dto.TableDescDto">
|
||||
select t.relname as tableName ,description as description
|
||||
from pg_description d,pg_class c,pg_stat_all_tables t
|
||||
where d.objoid=c.oid and objsubid=0 and t.relname=c.relname and t.schemaname=#{dbName}
|
||||
<if test="tableName != null">
|
||||
and t.relname=#{tableName}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.zyplayer.doc.db.framework.db.mapper.postgresql;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.zyplayer.doc.db.framework.db.dto.ColumnInfoDto;
|
||||
|
||||
/**
|
||||
* mysql数据库的mapper持有对象
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年8月8日
|
||||
*/
|
||||
public interface PostgresqlMapper {
|
||||
|
||||
ColumnInfoDto getColumnInfo(@Param("dbName") String dbName, @Param("tableName") String tableName, @Param("columnName") String columnName);
|
||||
}
|
||||
@@ -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,SYSCOLUMNS.ISNULLABLE NULLABLE,SYSCOLUMNS.LENGTH LENGTH,PRIMARYINFO.ISPRAMARY
|
||||
) ISIDENTITY,SYSCOLUMNS.NAME NAME,SYSTYPES.NAME TYPE,Iif(SYSCOLUMNS.ISNULLABLE=1,'允许','不允许') NULLABLE,SYSCOLUMNS.LENGTH LENGTH,PRIMARYINFO.ISPRAMARY
|
||||
FROM SYSCOLUMNS
|
||||
LEFT JOIN PRIMARYINFO ON PRIMARYINFO.COLUMNNAME=NAME
|
||||
LEFT JOIN SYSTYPES ON SYSCOLUMNS.XUSERTYPE = SYSTYPES.XUSERTYPE
|
||||
|
||||
@@ -114,7 +114,7 @@ public class PoiUtil {
|
||||
run.setFontSize(18);
|
||||
List<List<String>> dataList = new LinkedList<>();
|
||||
List<TableColumnDescDto> tableColumnDescDtos = columnMap.get(tableInfoVo.getTableName());
|
||||
dataList.add(Arrays.asList("字段名", "是否自增", "类型", "NULL", "长度", "主键", "注释"));
|
||||
dataList.add(Arrays.asList("字段名", "是否自增", "类型", "空值", "长度", "主键", "注释"));
|
||||
// 写入表格
|
||||
for (TableColumnDescDto dto : tableColumnDescDtos) {
|
||||
dataList.add(Arrays.asList(dto.getName(), dto.getIsidenity(), dto.getType(),
|
||||
|
||||
Reference in New Issue
Block a user