Selaa lähdekoodia

数据建模修改

xuezizhuo 2 vuotta sitten
vanhempi
säilyke
07595631a6

+ 8 - 12
src/main/java/com/customer/controller/TableInfoController.java

@@ -74,13 +74,7 @@ public class TableInfoController {
      */
     @PostMapping("/tableInfoList")
     public AjaxResult tableInfoList(@RequestBody Map<String,Object> map){
-        List<TableInfoVO> tableInfoVOS = tableInfoService.tableInfoList(map);
-        AjaxResult ajaxResult = new AjaxResult();
-        ajaxResult.put("code",200)
-                .put("data",tableInfoVOS)
-                .put("msg","操作成功")
-                .put("total",tableInfoVOS.size());
-        return ajaxResult;
+        return tableInfoService.tableInfoList(map);
     }
 
     /**
@@ -91,15 +85,17 @@ public class TableInfoController {
         return tableInfoService.dropTable(tableName);
     }
 
-    //---------------------------------------通用接口-----------------------------------------------------
-
-
-
+    /**
+     * 获取表字段
+     */
     @GetMapping("/mysqlTableFieldInfo")
     public AjaxResult mysqlTableFieldInfo(@RequestParam("tableName") String tableName){
-        return AjaxResult.success(tableInfoService.mysqlTableFieldInfo(tableName));
+        return AjaxResult.success(tableInfoService.tableFieldInfo(tableName));
     }
 
+    //---------------------------------------通用接口-----------------------------------------------------
+
+
     @PutMapping("/editMysqlTable")
     public AjaxResult editMysqlTable(@RequestBody Map<String, Object> map){
         String tableName = (String) map.get("tableName");

+ 15 - 5
src/main/java/com/customer/mapper/TableInfoMapper.java

@@ -35,7 +35,7 @@ public interface TableInfoMapper {
     /**
      * 查询数据库中的表信息
      */
-    List<TableInfoVO> tableInfoList(@Param("databaseName") String databaseName,@Param("map") Map<String,Object> map, RowBounds rowBounds);
+    List<TableInfoVO> tableInfoList(@Param("databaseName") String databaseName,@Param("map") Map<String,Object> map);
 
     /**
      * 查询表中有没有数据
@@ -72,7 +72,7 @@ public interface TableInfoMapper {
     /**
      * 创建数据表
      */
-    void createSqlServerTable(@Param("dataBaseName") String dataBaseName,@Param("tableName") String tableName,@Param("filedList") List<String> filedList,@Param("descriptionList") List<String> descriptionList);
+    void createSqlServerTable(@Param("dataBaseName") String dataBaseName,@Param("tableName") String tableName,@Param("filedList") List<String> filedList,@Param("descriptionList") List<String> descriptionList,@Param("tableComment") String tableComment);
 
     /**
      * 判断数据库是否存在
@@ -82,7 +82,7 @@ public interface TableInfoMapper {
     /**
      * 获取当前库中所有表信息
      */
-    List<TableInfoVO> sqlServerTableInfoList(String databaseName);
+    List<TableInfoVO> sqlServerTableInfoList(@Param("databaseName") String databaseName,@Param("map") Map<String,Object> map);
 
     /**
      * 查询表中是否有数据
@@ -122,14 +122,19 @@ public interface TableInfoMapper {
     void createDmTable(@Param("databaseName") String databaseName,@Param("tableName") String tableName,@Param("filedList") List<String> filedList);
 
     /**
-     * 添加表注释
+     * 添加表字段注释
      */
     void addTableDescription(String description);
 
     /**
+     * 添加表描述
+     */
+    void addDmTableComment(@Param("databaseName") String databaseName,@Param("tableName") String tableName,@Param("tableComment") String tableComment);
+
+    /**List<TableInfoVO> dmTableInfoList(@Param("databaseName") String databaseName,@Param("map") Map<String,Object> map, RowBounds rowBounds);
      * 库中所有表信息
      */
-    List<TableInfoVO> dmTableInfoList(String databaseName);
+    List<TableInfoVO> dmTableInfoList(@Param("databaseName") String databaseName,@Param("map") Map<String,Object> map);
 
     /**
      * 查询表行数
@@ -141,6 +146,11 @@ public interface TableInfoMapper {
      */
     void dropDmTable(String tableName);
 
+    /**
+     * 查询数据库中表数量
+     */
+    int queryDmTableCount(@Param("databaseName") String databaseName,@Param("map") Map<String,Object> map);
+
 
     //---------------------------------oracle------------------------------------------
 

+ 7 - 19
src/main/java/com/customer/service/ITableInfoService.java

@@ -35,13 +35,10 @@ public interface ITableInfoService {
 
 
 
-
-
-
     /**
      * 查询数据库中的表信息
      */
-    List<TableInfoVO> tableInfoList(Map<String,Object> map);
+    AjaxResult tableInfoList(Map<String,Object> map);
 
     /**
      * 删除表
@@ -53,24 +50,15 @@ public interface ITableInfoService {
      */
     AjaxResult createTable(Map<String,Object> map);
 
-
-
     /**
      * 查询表中有没有数据
      */
     int selectDataCount(String tableName);
 
-    /**
-     * 删除表
-     */
-//    void dropMysqlTable(String tableName);
-
-
-
     /**
      * 获取表字段信息
      */
-    List<TableInfo> mysqlTableFieldInfo(String tableName);
+    List<TableInfo> tableFieldInfo(String tableName);
 
     /**
      * 修改mysql数据表
@@ -89,11 +77,6 @@ public interface ITableInfoService {
      */
     int sqlServerTableExist(String dataBaseName,String tableName);
 
-//    /**
-//     * 获取当前库中所有表信息
-//     */
-//    List<TableInfoVO> sqlServerTableInfoList();
-
     /**
      * 查询表中是否有数据
      */
@@ -126,6 +109,11 @@ public interface ITableInfoService {
      */
     void createDmDataBase(Map<String,Object> map);
 
+    /**
+     * 查询数据库中表数量
+     */
+//    int queryDmTableCount(Map<String,Object> map);
+
     //---------------------------------oracle------------------------------------------
 
     /**

+ 65 - 25
src/main/java/com/customer/service/impl/TableInfoServiceImpl.java

@@ -71,6 +71,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
     public void createSqlServerDataBase(Map<String, Object> map) {
         String dataBaseName = (String) map.get("dataBaseName");
         String tableName = (String) map.get("tableName");
+        String tableComment = (String) map.get("tableComment");
         List<TableInfo> filedList = JSON.parseArray(JSON.toJSONString(map.get("field")), TableInfo.class);
         List<String> list= filedList.stream().map(filed->{
             StringBuilder stringBuilder = new StringBuilder();
@@ -102,7 +103,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
         }).collect(Collectors.toList());
 
         tableInfoMapper.createSqlServerDataBase(dataBaseName);
-        tableInfoMapper.createSqlServerTable(dataBaseName,tableName,list,descriptionList);
+        tableInfoMapper.createSqlServerTable(dataBaseName,tableName,list,descriptionList,tableComment);
     }
 
     @Override
@@ -116,22 +117,51 @@ public class TableInfoServiceImpl implements ITableInfoService {
     }
 
     @Override
-    public List<TableInfoVO> tableInfoList(Map<String,Object> map) {
+    public AjaxResult tableInfoList(Map<String,Object> map) {
         int pageNum = (int)map.get("pageNum");
         int pageSize = (int)map.get("pageSize");
-        RowBounds rowBounds = PageUtil.getPageParam(pageNum,pageSize);
         //获取数据源信息
         if(redisTemplate.hasKey("DataSource")){
             DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
             if(dataSource.getDatabaseType().equals(DataSourceType.MYSQL.getDataSourceName())){
-                return tableInfoMapper.tableInfoList(dataSource.getDatabaseName(),map,rowBounds);
+                List<TableInfoVO> mysqlTableList = tableInfoMapper.tableInfoList(dataSource.getDatabaseName(),map);
+                AjaxResult ajaxResult = new AjaxResult();
+                ajaxResult.put("code",200)
+                        .put("data",mysqlTableList.stream().skip((pageNum-1)*pageSize).limit(pageSize).
+                                collect(Collectors.toList()))
+                        .put("msg","操作成功")
+                        .put("total",mysqlTableList.size());
+                return ajaxResult;
+
             }else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
-                return tableInfoMapper.sqlServerTableInfoList(dataSource.getDatabaseName());
+                List<TableInfoVO> sqlServerTableList = tableInfoMapper.sqlServerTableInfoList(dataSource.getDatabaseName(),map);
+                AjaxResult ajaxResult = new AjaxResult();
+                ajaxResult.put("code",200)
+                        .put("data",sqlServerTableList.stream().skip((pageNum-1)*pageSize).limit(pageSize).
+                                collect(Collectors.toList()))
+                        .put("msg","操作成功")
+                        .put("total",sqlServerTableList.size());
+                return ajaxResult;
+
             }else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
-                return tableInfoMapper.dmTableInfoList(dataSource.getDatabaseName());
+                List<TableInfoVO> dmTableList = tableInfoMapper.dmTableInfoList(dataSource.getDatabaseName(),map);
+                AjaxResult ajaxResult = new AjaxResult();
+                ajaxResult.put("code",200)
+                        .put("data",dmTableList.stream().skip((pageNum-1)*pageSize).limit(pageSize).
+                                collect(Collectors.toList()))
+                        .put("msg","操作成功")
+                        .put("total",dmTableList.size());
+                return ajaxResult;
             }
         }
-        return tableInfoMapper.tableInfoList(url.substring(url.lastIndexOf("/") + 1),map,rowBounds);
+        List<TableInfoVO> mysqlTableList = tableInfoMapper.tableInfoList(url.substring(url.lastIndexOf("/") + 1),map);
+        AjaxResult ajaxResult = new AjaxResult();
+        ajaxResult.put("code",200)
+                .put("data",mysqlTableList.stream().skip((pageNum-1)*pageSize).limit(pageSize).
+                        collect(Collectors.toList()))
+                .put("msg","操作成功")
+                .put("total",mysqlTableList.size());
+        return ajaxResult;
 
     }
 
@@ -140,11 +170,6 @@ public class TableInfoServiceImpl implements ITableInfoService {
         return tableInfoMapper.selectDataCount(tableName);
     }
 
-//    @Override
-//    public void dropMysqlTable(String tableName) {
-//        tableInfoMapper.dropMysqlTable(tableName);
-//    }
-
     @Override
     public AjaxResult dropTable(String tableName) {
         if(redisTemplate.hasKey("DataSource")){
@@ -210,13 +235,16 @@ public class TableInfoServiceImpl implements ITableInfoService {
         return AjaxResult.success();
     }
 
-
     @Override
-    public List<TableInfo> mysqlTableFieldInfo(String tableName) {
+    public List<TableInfo> tableFieldInfo(String tableName) {
         String dataBaseName = url.substring(url.lastIndexOf("/") + 1);
         if(redisTemplate.hasKey("DataSource")){
             DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
-            return tableInfoMapper.mysqlTableFieldInfo(dataSource.getDatabaseName(),tableName);
+            if(dataSource.getDatabaseType().equals(DataSourceType.MYSQL.getDataSourceName())){
+                return tableInfoMapper.mysqlTableFieldInfo(dataSource.getDatabaseName(),tableName);
+            }else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
+
+            }
         }
         return tableInfoMapper.mysqlTableFieldInfo(dataBaseName,tableName);
     }
@@ -262,11 +290,6 @@ public class TableInfoServiceImpl implements ITableInfoService {
         return tableInfoMapper.sqlServerTableExist(stringBuilder.toString());
     }
 
-//    @Override
-//    public List<TableInfoVO> sqlServerTableInfoList() {
-//        return tableInfoMapper.sqlServerTableInfoList();
-//    }
-
     @Override
     public int selectSqlServerDataCount(String tableName) {
         return tableInfoMapper.selectSqlServerDataCount(tableName);
@@ -313,11 +336,6 @@ public class TableInfoServiceImpl implements ITableInfoService {
         tableInfoMapper.updateSqlserverTable(tableName,list,descriptionList);
     }
 
-//    @Override
-//    public List<Map<String, Object>> getDataBasesInfo(String DBname) {
-//        return tableInfoMapper.getDataBasesInfo(DBname);
-//    }
-
     @Override
     public int dmTableExist(String dataBaseName, String tableName) {
         return tableInfoMapper.dmTableExist(dataBaseName,tableName);
@@ -327,6 +345,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
     public void createDmDataBase(Map<String, Object> map) {
         String dataBaseName = (String) map.get("dataBaseName");
         String tableName = (String) map.get("tableName");
+        String tableComment = (String) map.get("tableComment");
         List<TableInfo> filedList = JSON.parseArray(JSON.toJSONString(map.get("field")), TableInfo.class);
         List<String> descriptionList = new ArrayList<>();
         List<String> list= filedList.stream().map(filed->{
@@ -360,13 +379,34 @@ public class TableInfoServiceImpl implements ITableInfoService {
         if(tableInfoMapper.dmDataBaseExist(dataBaseName)>0){
             tableInfoMapper.createDmTable(dataBaseName,tableName,list);
             descriptionList.stream().forEach(f->tableInfoMapper.addTableDescription(f));
+            tableInfoMapper.addDmTableComment(dataBaseName,tableName,tableComment);
         }else {
             tableInfoMapper.createDmDataBase(dataBaseName);
             tableInfoMapper.createDmTable(dataBaseName,tableName,list);
             descriptionList.stream().forEach(f->tableInfoMapper.addTableDescription(f));
+            tableInfoMapper.addDmTableComment(dataBaseName,tableName,tableComment);
         }
     }
 
+//    @Override
+//    public int queryDmTableCount(Map<String,Object> map) {
+//        String dataBaseName = (String) map.get("dataBaseName");
+//        if(redisTemplate.hasKey("DataSource")){
+//            DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
+//            if(dataSource.getDatabaseType().equals(DataSourceType.MYSQL.getDataSourceName())){
+//                return 0;
+//
+//            }else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
+//                return 0;
+//
+//            }else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
+//                return tableInfoMapper.queryDmTableCount(dataSource.getDatabaseName(),map);
+//            }
+//        }
+//        return 0;
+//
+//    }
+
     @Override
     public int oracleTableExist(String tableName) {
         return tableInfoMapper.oracleTableExist(tableName);

+ 24 - 6
src/main/resources/mapper/TableInfoMapper.xml

@@ -105,6 +105,7 @@
         <foreach collection="descriptionList" item="description" separator=";">
             ${description}
         </foreach>
+        ;EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'${tableComment}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'${tableName}'
     </update>
 
     <select id="existOrNot" resultType="int">
@@ -118,8 +119,10 @@
             CONVERT ( NVARCHAR ( 100 ), isnull( g.[value], '' ) ) AS tableComment
         from ${databaseName}.sys.tables a
                  LEFT JOIN sys.extended_properties g ON ( a.object_id = g.major_id AND g.minor_id = 0 )
-        where a.type = 'U';
-
+        where a.type = 'U'
+        <if test="map.tableName != null and map.tableName != ''">and a.name like concat('%', #{map.tableName}, '%')</if>
+        <if test="map.tableComment != null and map.tableComment !=''">and CONVERT ( NVARCHAR ( 100 ), isnull( g.[value], '' ) ) like concat('%', #{map.tableComment}, '%')</if>
+        order by createTime asc
     </select>
 
     <select id="selectSqlServerDataCount" resultType="int">
@@ -155,9 +158,9 @@
         CREATE SCHEMA ${databaseName}
     </update>
 
-    <update id="useDmDataBase">
-        set schema ${dataBaseName};
-    </update>
+<!--    <update id="useDmDataBase">-->
+<!--        set schema ${dataBaseName};-->
+<!--    </update>-->
 
     <update id="createDmTable">
 
@@ -173,12 +176,18 @@
            ${description}
     </update>
 
+    <update id="addDmTableComment">
+        comment on table ${databaseName}.${tableName} is '${tableComment}';
+    </update>
+
     <select id="dmTableInfoList" resultType="com.customer.vo.TableInfoVO">
         select a.object_name as tableName,b.comment$ as tableComment,a.created as createTime
         from dba_objects a
                  left join SYSTABLECOMMENTS b on b.tvname = a.object_name
         where a.object_type = 'TABLE' and a.owner = #{databaseName}
-
+        <if test="map.tableName != null and map.tableName != ''">and a.object_name like concat('%', #{map.tableName}, '%')</if>
+        <if test="map.tableComment != null and map.tableComment !=''">and b.comment$ like concat('%', #{map.tableComment}, '%')</if>
+        order by createTime asc
     </select>
 
     <select id="selectDmDataCount" resultType="int">
@@ -189,6 +198,15 @@
         drop table ${tableName}
     </delete>
 
+    <select id="queryDmTableCount" resultType="int">
+        select count(1)
+        from dba_objects a
+        left join SYSTABLECOMMENTS b on b.tvname = a.object_name
+        where a.object_type = 'TABLE' and a.owner = #{databaseName}
+        <if test="map.tableName != null and map.tableName != ''">and a.object_name like concat('%', #{map.tableName}, '%')</if>
+        <if test="map.tableComment != null and map.tableComment !=''">and b.comment$ like concat('%', #{map.tableComment}, '%')</if>
+    </select>
+
     <update id="createOracleUser">
         CREATE USER ${username} IDENTIFIED BY ${password} DEFAULT TABLESPACE users QUOTA unlimited ON users
     </update>