Jelajahi Sumber

数据建模修改

xuezizhuo 2 tahun lalu
induk
melakukan
12e10e3161

+ 0 - 13
.idea/libraries/Maven__com_github_jsqlparser_jsqlparser_4_4.xml

@@ -1,13 +0,0 @@
-<component name="libraryTable">
-  <library name="Maven: com.github.jsqlparser:jsqlparser:4.4">
-    <CLASSES>
-      <root url="jar://$PROJECT_DIR$/../../software/installpath/apache-maven-3.6.2/repository/com/github/jsqlparser/jsqlparser/4.4/jsqlparser-4.4.jar!/" />
-    </CLASSES>
-    <JAVADOC>
-      <root url="jar://$PROJECT_DIR$/../../software/installpath/apache-maven-3.6.2/repository/com/github/jsqlparser/jsqlparser/4.4/jsqlparser-4.4-javadoc.jar!/" />
-    </JAVADOC>
-    <SOURCES>
-      <root url="jar://$PROJECT_DIR$/../../software/installpath/apache-maven-3.6.2/repository/com/github/jsqlparser/jsqlparser/4.4/jsqlparser-4.4-sources.jar!/" />
-    </SOURCES>
-  </library>
-</component>

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

@@ -66,9 +66,12 @@ public class TableInfoController {
         return AjaxResult.success();
     }
 
-    @GetMapping("/tableInfoList")
-    public AjaxResult tableInfoList(){
-        return AjaxResult.success(tableInfoService.tableInfoList());
+    /**
+     * 根据当前数据源显示对应的数据表列表
+     */
+    @PostMapping("/tableInfoList")
+    public AjaxResult tableInfoList(@RequestBody Map<String,Object> map){
+        return AjaxResult.success(tableInfoService.tableInfoList(map));
     }
 
     @GetMapping("/removeTable/{tableName}")
@@ -81,8 +84,8 @@ public class TableInfoController {
     }
 
     @GetMapping("/mysqlTableFieldInfo")
-    public AjaxResult mysqlTableFieldInfo(@RequestParam("databaseName") String databaseName,@RequestParam("tableName") String tableName){
-        return AjaxResult.success(tableInfoService.mysqlTableFieldInfo(databaseName,tableName));
+    public AjaxResult mysqlTableFieldInfo(@RequestParam("tableName") String tableName){
+        return AjaxResult.success(tableInfoService.mysqlTableFieldInfo(tableName));
     }
 
     @PutMapping("/editMysqlTable")
@@ -96,13 +99,6 @@ public class TableInfoController {
 
     }
 
-    /**
-     * 获取sqlServer当前库中所有表信息
-     */
-//    @GetMapping("/sqlServerTableInfoList")
-//    public AjaxResult sqlServerTableInfoList(){
-//        return AjaxResult.success(tableInfoService.sqlServerTableInfoList());
-//    }
 
     /**
      * 删除sqlserver数据表
@@ -129,14 +125,6 @@ public class TableInfoController {
         return AjaxResult.success();
     }
 
-//
-//    /**
-//     * 获取DM当前库中所有表信息
-//     */
-//    @GetMapping("/getDataBasesInfo")
-//    public AjaxResult sqlServerTableInfoListtest(String name){
-//        return AjaxResult.success(tableInfoService.getDataBasesInfo(name));
-//    }
 
 
 }

+ 2 - 1
src/main/java/com/customer/mapper/TableInfoMapper.java

@@ -4,6 +4,7 @@ package com.customer.mapper;
 import com.customer.pojo.TableInfo;
 import com.customer.vo.TableInfoVO;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.RowBounds;
 
 import java.util.List;
 import java.util.Map;
@@ -34,7 +35,7 @@ public interface TableInfoMapper {
     /**
      * 查询数据库中的表信息
      */
-    List<TableInfoVO> tableInfoList(String databaseName);
+    List<TableInfoVO> tableInfoList(String databaseName, Map<String,Object> map, RowBounds rowBounds);
 
     /**
      * 查询表中有没有数据

+ 2 - 2
src/main/java/com/customer/service/ITableInfoService.java

@@ -30,7 +30,7 @@ public interface ITableInfoService {
     /**
      * 查询数据库中的表信息
      */
-    List<TableInfoVO> tableInfoList();
+    List<TableInfoVO> tableInfoList(Map<String,Object> map);
 
     /**
      * 查询表中有没有数据
@@ -45,7 +45,7 @@ public interface ITableInfoService {
     /**
      * 获取表字段信息
      */
-    List<TableInfo> mysqlTableFieldInfo(String dataBaseName, String tableName);
+    List<TableInfo> mysqlTableFieldInfo(String tableName);
 
     /**
      * 修改mysql数据表

+ 22 - 6
src/main/java/com/customer/service/impl/TableInfoServiceImpl.java

@@ -11,6 +11,7 @@ import com.customer.service.ICustomerService;
 import com.customer.service.IDataSourceService;
 import com.customer.service.ITableInfoService;
 import com.customer.vo.TableInfoVO;
+import org.apache.ibatis.session.RowBounds;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -112,19 +113,22 @@ public class TableInfoServiceImpl implements ITableInfoService {
     }
 
     @Override
-    public List<TableInfoVO> tableInfoList() {
+    public List<TableInfoVO> tableInfoList(Map<String,Object> map) {
+        int pageNum = (int)map.get("pageNum");
+        int pageSize = (int)map.get("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());
+                return tableInfoMapper.tableInfoList(dataSource.getDatabaseName(),map,new RowBounds(pageNum,pageSize));
             }else if(dataSource.getDatabaseType().equals(DataSourceType.SQLSERVER.getDataSourceName())){
                 return tableInfoMapper.sqlServerTableInfoList(dataSource.getDatabaseName());
             }else if(dataSource.getDatabaseType().equals(DataSourceType.DM.getDataSourceName())){
                 return tableInfoMapper.dmTableInfoList(dataSource.getDatabaseName());
             }
         }
-            return tableInfoMapper.tableInfoList(url.substring(url.lastIndexOf("/") + 1));
+            return tableInfoMapper.tableInfoList(url.substring(url.lastIndexOf("/") + 1),map,new RowBounds(pageNum,pageSize));
 
     }
 
@@ -139,13 +143,17 @@ public class TableInfoServiceImpl implements ITableInfoService {
     }
 
     @Override
-    public List<TableInfo> mysqlTableFieldInfo(String dataBaseName, String tableName) {
+    public List<TableInfo> mysqlTableFieldInfo(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);
+        }
         return tableInfoMapper.mysqlTableFieldInfo(dataBaseName,tableName);
     }
 
     @Override
     public void updateMysqlTable(Map<String, Object> map) {
-        String dataBaseName = (String) map.get("dataBaseName");
         String tableName = (String) map.get("tableName");
         List<TableInfo> filedList = JSON.parseArray(JSON.toJSONString(map.get("field")), TableInfo.class);
         List<String> list= filedList.stream().map(filed->{
@@ -164,7 +172,15 @@ public class TableInfoServiceImpl implements ITableInfoService {
             stringBuilder.append("COMMENT '"+filed.getFieldDescription()+"'");
             return stringBuilder.toString();
         }).collect(Collectors.toList());
-        tableInfoMapper.updateMysqlTable(dataBaseName,tableName,list);
+
+        if(redisTemplate.hasKey("DataSource")){
+            DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
+            tableInfoMapper.updateMysqlTable(dataSource.getDatabaseName(),tableName,list);
+        }else {
+            String dataBaseName = url.substring(url.lastIndexOf("/") + 1);
+            tableInfoMapper.updateMysqlTable(dataBaseName,tableName,list);
+        }
+
     }
 
     @Override

+ 38 - 0
src/main/java/com/customer/utils/PageUtil.java

@@ -0,0 +1,38 @@
+package com.customer.utils;
+
+import org.apache.ibatis.session.RowBounds;
+
+public class PageUtil {
+
+    public PageUtil() {
+    }
+
+    public static RowBounds getPageParam(Integer pageNum, Integer pageSize) {
+        if (pageNum == null || pageNum < 1) {
+            pageNum = 1;
+        }
+
+        if (pageSize == null || pageSize < 1) {
+            pageSize = 10;
+        }
+
+        return new RowBounds((pageNum - 1) * pageSize, pageSize);
+    }
+
+    public static int getPageNum(Integer pageNum) {
+        if (pageNum == null || pageNum < 1) {
+            pageNum = 0;
+        }
+
+        return pageNum;
+    }
+
+    public static int getPageSize(Integer pageSize) {
+        if (pageSize == null || pageSize < 1) {
+            pageSize = 10;
+        }
+
+        return pageSize;
+    }
+
+}

+ 1 - 1
src/main/java/com/customer/vo/TableInfoVO.java

@@ -19,7 +19,7 @@ public class TableInfoVO {
     /**
      * 创建时间
      */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
     private Date createTime;
 
     /**

+ 7 - 3
src/main/resources/mapper/TableInfoMapper.xml

@@ -37,6 +37,9 @@
 
     <select id="tableInfoList" resultType="com.customer.vo.TableInfoVO">
         select table_name tableName,create_time createTime,table_comment tableComment from information_schema.tables where table_schema=#{databaseName}
+        <if test="map.tableName != null and map.tableName != ''">and table_name like concat('%', #{map.tableName}, '%')</if>
+        <if test="map.tableComment != null and map.tableComment !=''">and table_comment like concat('%', #{map.tableComment}, '%')</if>
+        order by createTime asc
     </select>
 
 <!--    <select id="selectDataCount" resultType="int">-->
@@ -54,8 +57,8 @@
     </delete>
 
     <update id="updateMysqlTable">
-        DROP TABLE IF EXISTS ${dataBaseName}.${tableName};
-        CREATE TABLE IF NOT EXISTS `${dataBaseName}`.`${tableName}`
+        DROP TABLE `${dataBaseName}`.`${tableName}`;
+        CREATE TABLE `${dataBaseName}`.`${tableName}`
         (
         <foreach collection="filedList" item="filed" separator=",">
             ${filed}
@@ -78,7 +81,8 @@
             information_schema.COLUMNS
         WHERE
             table_name = #{tableName}
-          AND table_schema = #{dataBaseName};
+          AND table_schema = #{dataBaseName}
+          ORDER BY ordinal_position asc;
 
     </select>