数据库表信息状态展示

This commit is contained in:
暮光:城中城
2019-09-04 22:41:44 +08:00
parent abc24b424f
commit c4ccaa20ca
11 changed files with 374 additions and 119 deletions

View File

@@ -19,6 +19,7 @@ import com.zyplayer.doc.data.utils.CacheUtil;
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.controller.vo.TableStatusVo;
import com.zyplayer.doc.db.framework.consts.DbAuthType;
import com.zyplayer.doc.db.framework.db.bean.DatabaseFactoryBean;
import com.zyplayer.doc.db.framework.db.bean.DatabaseFactoryBean.DatabaseProduct;
@@ -158,6 +159,13 @@ public class DatabaseDocController {
return DocDbResponseJson.ok(dbNameDtoList);
}
@PostMapping(value = "/getTableStatus")
public ResponseJson getTableStatus(Long sourceId, String dbName, String tableName) {
BaseMapper baseMapper = this.getViewAuthBaseMapper(sourceId);
TableStatusVo tableStatusVo = baseMapper.getTableStatus(dbName, tableName);
return DocDbResponseJson.ok(tableStatusVo);
}
@PostMapping(value = "/getTableList")
public ResponseJson getTableList(Long sourceId, String dbName) {
BaseMapper baseMapper = this.getBaseMapper(sourceId);

View File

@@ -0,0 +1,168 @@
package com.zyplayer.doc.db.controller.vo;
import java.util.Date;
public class TableStatusVo {
private String name;
private String engine;
private Long version;
private String rowFormat;
private Long rows;
private Long avgRowLength;
private Long dataLength;
private Long maxDataLength;
private Long indexLength;
private Long dataFree;
private Long autoIncrement;
private Date createTime;
private Date updateTime;
private Date checkTime;
private String collation;
private String checksum;
private String createOptions;
private String comment;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEngine() {
return engine;
}
public void setEngine(String engine) {
this.engine = engine;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
public String getRowFormat() {
return rowFormat;
}
public void setRowFormat(String rowFormat) {
this.rowFormat = rowFormat;
}
public Long getRows() {
return rows;
}
public void setRows(Long rows) {
this.rows = rows;
}
public Long getAvgRowLength() {
return avgRowLength;
}
public void setAvgRowLength(Long avgRowLength) {
this.avgRowLength = avgRowLength;
}
public Long getDataLength() {
return dataLength;
}
public void setDataLength(Long dataLength) {
this.dataLength = dataLength;
}
public Long getMaxDataLength() {
return maxDataLength;
}
public void setMaxDataLength(Long maxDataLength) {
this.maxDataLength = maxDataLength;
}
public Long getIndexLength() {
return indexLength;
}
public void setIndexLength(Long indexLength) {
this.indexLength = indexLength;
}
public Long getDataFree() {
return dataFree;
}
public void setDataFree(Long dataFree) {
this.dataFree = dataFree;
}
public Long getAutoIncrement() {
return autoIncrement;
}
public void setAutoIncrement(Long autoIncrement) {
this.autoIncrement = autoIncrement;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Date getCheckTime() {
return checkTime;
}
public void setCheckTime(Date checkTime) {
this.checkTime = checkTime;
}
public String getCollation() {
return collation;
}
public void setCollation(String collation) {
this.collation = collation;
}
public String getChecksum() {
return checksum;
}
public void setChecksum(String checksum) {
this.checksum = checksum;
}
public String getCreateOptions() {
return createOptions;
}
public void setCreateOptions(String createOptions) {
this.createOptions = createOptions;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}

View File

@@ -1,5 +1,6 @@
package com.zyplayer.doc.db.framework.db.mapper.base;
import com.zyplayer.doc.db.controller.vo.TableStatusVo;
import com.zyplayer.doc.db.framework.db.dto.*;
import org.apache.ibatis.annotations.Param;
@@ -90,5 +91,14 @@ public interface BaseMapper {
void updateTableColumnDesc(@Param("dbName") String dbName, @Param("tableName") String tableName,
@Param("columnName") String columnName, @Param("newDesc") String newDesc,
@Param("columnInfo") ColumnInfoDto columnInfo);
/**
* 获取表基本信息
*
* @author 暮光:城中城
* @since 2019年9月1日
* @param dbName 数据库名
* @param tableName 表名
*/
TableStatusVo getTableStatus(@Param("dbName") String dbName, @Param("tableName") String tableName);
}

View File

@@ -19,6 +19,27 @@
<result column="DESCRIPTION" property="description" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="TableStatusDtoMap" type="com.zyplayer.doc.db.controller.vo.TableStatusVo">
<result column="Name" property="name"/>
<result column="Engine" property="engine"/>
<result column="Version" property="version"/>
<result column="Row_format" property="rowFormat"/>
<result column="Rows" property="rows"/>
<result column="Avg_row_length" property="avgRowLength"/>
<result column="Data_length" property="dataLength"/>
<result column="Max_data_length" property="maxDataLength"/>
<result column="Index_length" property="indexLength"/>
<result column="Data_free" property="dataFree"/>
<result column="Auto_increment" property="autoIncrement"/>
<result column="Create_time" property="createTime"/>
<result column="Update_time" property="updateTime"/>
<result column="Check_time" property="checkTime"/>
<result column="Collation" property="collation"/>
<result column="Checksum" property="checksum"/>
<result column="Create_options" property="createOptions"/>
<result column="Comment" property="comment"/>
</resultMap>
<select id="getDatabaseList" resultType="com.zyplayer.doc.db.framework.db.dto.DatabaseInfoDto">
select TABLE_SCHEMA dbName
from information_schema.tables
@@ -39,6 +60,10 @@
ORDER BY ordinal_position
</select>
<select id="getTableStatus" resultMap="TableStatusDtoMap">
show table status from ${dbName} like #{tableName}
</select>
<select id="getTableColumnDescList" resultMap="TableColumnDescDtoMap">
select 1
</select>

View File

@@ -1,103 +1,107 @@
<?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="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 NAME as dbName FROM Master..SysDatabases ORDER BY NAME
</select>
<select id="getTableList" resultType="com.zyplayer.doc.db.framework.db.dto.TableInfoDto">
SELECT NAME as tableName, ID as tableId
FROM ${dbName}..SysObjects Where XType='U' ORDER BY NAME
</select>
<select id="getTableColumnList" resultMap="TableColumnDescDtoMap">
WITH PRIMARYINFO( COLUMNNAME ,ISPRAMARY) AS
(
SELECT C.NAME,'true' AS COLUMNNAME
FROM SYSINDEXES I
JOIN SYSINDEXKEYS K ON I.ID = K.ID AND I.INDID = K.INDID
JOIN SYSOBJECTS O ON I.ID = O.ID
JOIN SYSCOLUMNS C ON I.ID=C.ID AND K.COLID = C.COLID
WHERE O.XTYPE = 'U'
AND EXISTS(SELECT 1 FROM SYSOBJECTS WHERE XTYPE = 'PK' AND NAME = I.NAME)
AND O.NAME=#{tableName}
)
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
FROM SYSCOLUMNS
LEFT JOIN PRIMARYINFO ON PRIMARYINFO.COLUMNNAME=NAME
LEFT JOIN SYSTYPES ON SYSCOLUMNS.XUSERTYPE = SYSTYPES.XUSERTYPE
WHERE SYSCOLUMNS.ID = OBJECT_ID(#{tableName})
</select>
<select id="getTableColumnDescList" resultMap="TableColumnDescDtoMap">
SELECT B.name AS NAME,C.value AS DESCRIPTION
FROM sys.tables A
INNER JOIN sys.columns B ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
WHERE A.name = #{tableName}
</select>
<select id="getTableAndColumnBySearch" resultMap="QueryTableColumnDescDtoMap">
SELECT top 500
A.name AS TABLE_NAME,B.name AS COLUMN_NAME,C.value AS DESCRIPTION
FROM sys.tables A
INNER JOIN sys.columns B ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
WHERE convert(nvarchar(max),C.value) like #{searchText} OR B.name like #{searchText}
</select>
<select id="getTableDescList" resultType="com.zyplayer.doc.db.framework.db.dto.TableDescDto">
select 'TABLEDESC_SYS' as tableName, value as description, major_id as majorId
from sys.extended_properties
WHERE minor_id=0
<if test="tableName != null">
and major_id=object_id(#{tableName})
</if>
</select>
<insert id="updateTableDesc">
IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 'SCHEMA', 'dbo', 'TABLE', #{tableName}, NULL, NULL)) > 0)
EXEC sp_updateextendedproperty @name = 'MS_Description', @value = #{newDesc}
, @level0type = 'SCHEMA', @level0name = 'dbo'
, @level1type = 'TABLE', @level1name = #{tableName}
ELSE
EXEC sp_addextendedproperty @name = 'MS_Description', @value = #{newDesc}
, @level0type = 'SCHEMA', @level0name = 'dbo'
, @level1type = 'TABLE', @level1name = #{tableName}
</insert>
<insert id="updateTableColumnDesc">
IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 'SCHEMA', 'dbo', 'TABLE', #{tableName}, 'COLUMN', #{columnName})) > 0)
EXEC sp_updateextendedproperty @name = 'MS_Description', @value = #{newDesc}
, @level0type = 'SCHEMA', @level0name = 'dbo'
, @level1type = 'TABLE', @level1name = #{tableName}
, @level2type = 'COLUMN', @level2name = #{columnName}
ELSE
EXEC sp_addextendedproperty @name = 'MS_Description', @value = #{newDesc}
, @level0type = 'SCHEMA', @level0name = 'dbo'
, @level1type = 'TABLE', @level1name = #{tableName}
, @level2type = 'COLUMN', @level2name = #{columnName}
<?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="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 NAME as dbName FROM Master..SysDatabases ORDER BY NAME
</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 NAME as tableName, ID as tableId
FROM ${dbName}..SysObjects Where XType='U' ORDER BY NAME
</select>
<select id="getTableColumnList" resultMap="TableColumnDescDtoMap">
WITH PRIMARYINFO( COLUMNNAME ,ISPRAMARY) AS
(
SELECT C.NAME,'true' AS COLUMNNAME
FROM SYSINDEXES I
JOIN SYSINDEXKEYS K ON I.ID = K.ID AND I.INDID = K.INDID
JOIN SYSOBJECTS O ON I.ID = O.ID
JOIN SYSCOLUMNS C ON I.ID=C.ID AND K.COLID = C.COLID
WHERE O.XTYPE = 'U'
AND EXISTS(SELECT 1 FROM SYSOBJECTS WHERE XTYPE = 'PK' AND NAME = I.NAME)
AND O.NAME=#{tableName}
)
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
FROM SYSCOLUMNS
LEFT JOIN PRIMARYINFO ON PRIMARYINFO.COLUMNNAME=NAME
LEFT JOIN SYSTYPES ON SYSCOLUMNS.XUSERTYPE = SYSTYPES.XUSERTYPE
WHERE SYSCOLUMNS.ID = OBJECT_ID(#{tableName})
</select>
<select id="getTableColumnDescList" resultMap="TableColumnDescDtoMap">
SELECT B.name AS NAME,C.value AS DESCRIPTION
FROM sys.tables A
INNER JOIN sys.columns B ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
WHERE A.name = #{tableName}
</select>
<select id="getTableAndColumnBySearch" resultMap="QueryTableColumnDescDtoMap">
SELECT top 500
A.name AS TABLE_NAME,B.name AS COLUMN_NAME,C.value AS DESCRIPTION
FROM sys.tables A
INNER JOIN sys.columns B ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
WHERE convert(nvarchar(max),C.value) like #{searchText} OR B.name like #{searchText}
</select>
<select id="getTableDescList" resultType="com.zyplayer.doc.db.framework.db.dto.TableDescDto">
select 'TABLEDESC_SYS' as tableName, value as description, major_id as majorId
from sys.extended_properties
WHERE minor_id=0
<if test="tableName != null">
and major_id=object_id(#{tableName})
</if>
</select>
<insert id="updateTableDesc">
IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 'SCHEMA', 'dbo', 'TABLE', #{tableName}, NULL, NULL)) > 0)
EXEC sp_updateextendedproperty @name = 'MS_Description', @value = #{newDesc}
, @level0type = 'SCHEMA', @level0name = 'dbo'
, @level1type = 'TABLE', @level1name = #{tableName}
ELSE
EXEC sp_addextendedproperty @name = 'MS_Description', @value = #{newDesc}
, @level0type = 'SCHEMA', @level0name = 'dbo'
, @level1type = 'TABLE', @level1name = #{tableName}
</insert>
</mapper>
<insert id="updateTableColumnDesc">
IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description', 'SCHEMA', 'dbo', 'TABLE', #{tableName}, 'COLUMN', #{columnName})) > 0)
EXEC sp_updateextendedproperty @name = 'MS_Description', @value = #{newDesc}
, @level0type = 'SCHEMA', @level0name = 'dbo'
, @level1type = 'TABLE', @level1name = #{tableName}
, @level2type = 'COLUMN', @level2name = #{columnName}
ELSE
EXEC sp_addextendedproperty @name = 'MS_Description', @value = #{newDesc}
, @level0type = 'SCHEMA', @level0name = 'dbo'
, @level1type = 'TABLE', @level1name = #{tableName}
, @level2type = 'COLUMN', @level2name = #{columnName}
</insert>
</mapper>

File diff suppressed because one or more lines are too long

View File

@@ -1,2 +1,2 @@
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={2:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"80bc97c8e1f56e403c39",1:"0a0403eb1820498dc9bc"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
//# sourceMappingURL=doc-db-manifest.js.map?42eca50901b3d81e2837
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var i,a,f,l=0,s=[];l<t.length;l++)a=t[l],o[a]&&s.push(o[a][0]),o[a]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={2:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(a);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+""+e+".js?"+{0:"ea7225220eb365539ffe",1:"0a0403eb1820498dc9bc"}[e];var a=setTimeout(r,12e4);return i.onerror=i.onload=r,u.appendChild(i),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
//# sourceMappingURL=doc-db-manifest.js.map?468c61085fdba28ab9e4

View File

@@ -8,7 +8,7 @@
<body>
<div id="app"></div>
<script type="text/javascript" src="doc-db-manifest.js?42eca50901b3d81e2837"></script><script type="text/javascript" src="doc-db-vendor.js?0a0403eb1820498dc9bc"></script><script type="text/javascript" src="doc-db-index.js?80bc97c8e1f56e403c39"></script></body>
<script type="text/javascript" src="doc-db-manifest.js?468c61085fdba28ab9e4"></script><script type="text/javascript" src="doc-db-vendor.js?0a0403eb1820498dc9bc"></script><script type="text/javascript" src="doc-db-index.js?ea7225220eb365539ffe"></script></body>
</html>