Browse Source

补充提交

xuezizhuo 1 year ago
parent
commit
8703fc49f9

+ 5 - 0
zkqy-datamodeling/src/main/java/com/zkqy/datamodeling/mapper/TableInfoMapper.java

@@ -229,5 +229,10 @@ public interface TableInfoMapper {
      */
      */
     void addOracleTableDescription(String description);
     void addOracleTableDescription(String description);
 
 
+    /**
+     * 获取当前库中所有表信息
+     */
+    List<TableInfoVO> oracleTableInfoList(@Param("databaseName") String databaseName, @Param("map") Map<String, Object> map);
+
 
 
 }
 }

+ 28 - 19
zkqy-datamodeling/src/main/java/com/zkqy/datamodeling/service/impl/TableInfoServiceImpl.java

@@ -132,6 +132,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
         int pageSize = Integer.valueOf(map.get("pageSize").toString());
         int pageSize = Integer.valueOf(map.get("pageSize").toString());
         String databaseType = (String) map.get("databaseType");
         String databaseType = (String) map.get("databaseType");
         String databaseName = (String) map.get("databaseName");
         String databaseName = (String) map.get("databaseName");
+        String username = (String) map.get("username");
         //获取数据源信息
         //获取数据源信息
 //        if(redisTemplate.hasKey("DataSource")){
 //        if(redisTemplate.hasKey("DataSource")){
 //            DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
 //            DataSource dataSource =JSON.parseObject(redisTemplate.opsForValue().get("DataSource").toString(),DataSource.class);
@@ -164,6 +165,15 @@ public class TableInfoServiceImpl implements ITableInfoService {
                     .put("msg", "操作成功")
                     .put("msg", "操作成功")
                     .put("total", dmTableList.size());
                     .put("total", dmTableList.size());
             return ajaxResult;
             return ajaxResult;
+        } else if (databaseType.equals(DataSourceType.ORACLE.getDataSourceName())) {
+            List<TableInfoVO> dmTableList = tableInfoMapper.oracleTableInfoList(username,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;
         }
         }
 //        }
 //        }
         List<TableInfoVO> mysqlTableList = tableInfoMapper.tableInfoList(databaseName, map);
         List<TableInfoVO> mysqlTableList = tableInfoMapper.tableInfoList(databaseName, map);
@@ -445,16 +455,6 @@ public class TableInfoServiceImpl implements ITableInfoService {
         tableInfoMapper.createDmTable(databaseName, tableName, list);
         tableInfoMapper.createDmTable(databaseName, tableName, list);
         descriptionList.stream().forEach(f -> tableInfoMapper.addTableDescription(f));
         descriptionList.stream().forEach(f -> tableInfoMapper.addTableDescription(f));
         tableInfoMapper.addDmTableComment(databaseName, tableName, tableComment);
         tableInfoMapper.addDmTableComment(databaseName, tableName, tableComment);
-//        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
     @Override
@@ -670,7 +670,7 @@ public class TableInfoServiceImpl implements ITableInfoService {
                 showDatabaseSql = "select name from sys.databases";
                 showDatabaseSql = "select name from sys.databases";
                 createDatabaseSql = "CREATE DATABASE " + dataSource.getDatabaseName();
                 createDatabaseSql = "CREATE DATABASE " + dataSource.getDatabaseName();
                 // 封装sqlserver基础库信息连接信息
                 // 封装sqlserver基础库信息连接信息
-                foundationDriverName = "com.mysql.cj.jdbc.Driver";
+                foundationDriverName =driverName;
                 foundationDBURL += "jdbc:sqlserver://" + infoMap.get("databaseIp") + ":" + infoMap.get("portNumber") + ";DatabaseName=" + infoMap.get("databaseName") + ";trustServerCertificate=true;";
                 foundationDBURL += "jdbc:sqlserver://" + infoMap.get("databaseIp") + ":" + infoMap.get("portNumber") + ";DatabaseName=" + infoMap.get("databaseName") + ";trustServerCertificate=true;";
                 foundationUserName += infoMap.get("username");
                 foundationUserName += infoMap.get("username");
                 foundationUserPwd += infoMap.get("password");
                 foundationUserPwd += infoMap.get("password");
@@ -681,8 +681,8 @@ public class TableInfoServiceImpl implements ITableInfoService {
                 showDatabaseSql = "select name from sysobjects where TYPE$='sch' and SUBTYPE$ is null";
                 showDatabaseSql = "select name from sysobjects where TYPE$='sch' and SUBTYPE$ is null";
                 createDatabaseSql = "CREATE SCHEMA " + dataSource.getDatabaseName();
                 createDatabaseSql = "CREATE SCHEMA " + dataSource.getDatabaseName();
                 // 封装dm基础库信息连接信息
                 // 封装dm基础库信息连接信息
-                foundationDriverName = "com.mysql.cj.jdbc.Driver";
-                foundationDBURL += "jdbc:mysql://" + infoMap.get("databaseIp") + ":" + infoMap.get("portNumber") + "/" + infoMap.get("databaseName") + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
+                foundationDriverName = driverName;
+                foundationDBURL += "jdbc:dm://" + infoMap.get("databaseIp") + ":" + infoMap.get("portNumber") + "?schema=" + infoMap.get("databaseName");
                 foundationUserName += infoMap.get("username");
                 foundationUserName += infoMap.get("username");
                 foundationUserPwd += infoMap.get("password");
                 foundationUserPwd += infoMap.get("password");
                 break;
                 break;
@@ -690,8 +690,8 @@ public class TableInfoServiceImpl implements ITableInfoService {
                 driverName = LoadDriverConstants.ORACLE;
                 driverName = LoadDriverConstants.ORACLE;
                 dbURL = "jdbc:oracle:thin:@" + dataSource.getDatabaseIp() + ":" + dataSource.getPortNumber();
                 dbURL = "jdbc:oracle:thin:@" + dataSource.getDatabaseIp() + ":" + dataSource.getPortNumber();
                 // 封装oracle基础库信息连接信息
                 // 封装oracle基础库信息连接信息
-                foundationDriverName = "com.mysql.cj.jdbc.Driver";
-                foundationDBURL += "jdbc:mysql://" + infoMap.get("databaseIp") + ":" + infoMap.get("portNumber") + "/" + infoMap.get("databaseName") + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
+                foundationDriverName = driverName;
+                foundationDBURL += "jdbc:oracle:thin:@" + infoMap.get("databaseIp") + ":" + infoMap.get("portNumber") + ":" + infoMap.get("databaseName");
                 foundationUserName += infoMap.get("username");
                 foundationUserName += infoMap.get("username");
                 foundationUserPwd += infoMap.get("password");
                 foundationUserPwd += infoMap.get("password");
                 break;
                 break;
@@ -747,13 +747,13 @@ public class TableInfoServiceImpl implements ITableInfoService {
                 String sqlScript = "";
                 String sqlScript = "";
                 switch (dataSource.getDatabaseType()) {
                 switch (dataSource.getDatabaseType()) {
                     case "sqlserver":
                     case "sqlserver":
-                        sqlScript = "sql/sqlserver.sql";
+                        sqlScript = "zkqy-datamodeling\\src\\main\\resources\\sql\\sqlserver.sql";
                         break;
                         break;
                     case "dm":
                     case "dm":
-                        sqlScript = "sql/dm.sql";
+                        sqlScript = "zkqy-datamodeling\\src\\main\\resources\\sql\\dm.sql";
                         break;
                         break;
-                    case "orcale":
-                        sqlScript = "sql/orcale.sql";
+                    case "oracle":
+                        sqlScript = "zkqy-datamodeling\\src\\main\\resources\\sql\\oracle.sql";
                         break;
                         break;
                 }
                 }
                 // 读取SQL脚本文件
                 // 读取SQL脚本文件
@@ -765,6 +765,15 @@ public class TableInfoServiceImpl implements ITableInfoService {
                     script.append(System.lineSeparator());
                     script.append(System.lineSeparator());
                 }
                 }
                 reader.close();
                 reader.close();
+                if (dataSource.getDatabaseType().equals("dm")){
+                    foundationSt.execute("set schema " + dataSource.getDatabaseName() +";");
+                }
+                if (dataSource.getDatabaseType().equals("sqlserver")){
+                    foundationSt.executeUpdate("USE " + dataSource.getDatabaseName() + ";");
+                }
+                if (dataSource.getDatabaseType().equals("oracle")){
+                    foundationSt.executeUpdate("USE `" + dataSource.getDatabaseName() + "`");
+                }
                 // 将SQL脚本内容作为字符串执行
                 // 将SQL脚本内容作为字符串执行
                 foundationSt.execute(script.toString());
                 foundationSt.execute(script.toString());
             }
             }

+ 16 - 1
zkqy-datamodeling/src/main/resources/mapper/datamodeling/TableInfoMapper.xml

@@ -257,7 +257,7 @@
     <select id="dmTableInfoList" resultType="com.zkqy.datamodeling.domain.vo.TableInfoVO">
     <select id="dmTableInfoList" resultType="com.zkqy.datamodeling.domain.vo.TableInfoVO">
         select a.object_name as tableName,b.comment$ as tableComment,a.created as createTime
         select a.object_name as tableName,b.comment$ as tableComment,a.created as createTime
         from dba_objects a
         from dba_objects a
-                 left join SYSTABLECOMMENTS b on b.tvname = a.object_name
+                 left join SYSTABLECOMMENTS b on b.tvname = a.object_name and b.schname = a.owner
         where a.object_type = 'TABLE' and a.owner = #{databaseName}
         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.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>
         <if test="map.tableComment != null and map.tableComment !=''">and b.comment$ like concat('%', #{map.tableComment}, '%')</if>
@@ -331,6 +331,21 @@
         ${description}
         ${description}
     </update>
     </update>
 
 
+    <select id="oracleTableInfoList" resultType="com.zkqy.datamodeling.domain.vo.TableInfoVO">
+        SELECT
+            a.table_name tableName,
+            a.comments tableComment,
+            o.created createTime
+        FROM
+            all_tab_comments a
+                LEFT JOIN all_objects o ON a.owner = o.owner
+                AND a.table_name = o.object_name
+        WHERE
+            a.table_type = 'TABLE'
+          AND a.owner = #{databaseName}
+        <if test="map.tableName != null and map.tableName != ''">and a.table_name like concat('%', #{map.tableName}, '%')</if>
+        <if test="map.tableComment != null and map.tableComment !=''">and a.comments like concat('%', #{map.tableComment}, '%')</if>
+    </select>
 
 
 
 
 </mapper>
 </mapper>

+ 2 - 111
zkqy-datamodeling/src/main/resources/sql/dm.sql

@@ -1,4 +1,4 @@
-CREATE TABLE "test1"."adsa"
+CREATE TABLE "adsa"
 (
 (
 "q" DOUBLE PRECISION,
 "q" DOUBLE PRECISION,
 "w" DATE,
 "w" DATE,
@@ -9,113 +9,4 @@ CREATE TABLE "test1"."adsa"
 "u" DATETIME(6) WITH TIME ZONE,
 "u" DATETIME(6) WITH TIME ZONE,
 "i" TIMESTAMP(6) WITH LOCAL TIME ZONE,
 "i" TIMESTAMP(6) WITH LOCAL TIME ZONE,
 "o" DATETIME(6) WITH TIME ZONE,
 "o" DATETIME(6) WITH TIME ZONE,
-"p" TEXT) STORAGE(ON "MAIN", CLUSTERBTR) ;
-
-COMMENT ON TABLE "test1"."adsa" IS '测试数据类型21-30';
-
-
-CREATE TABLE "test1"."cscs"
-(
-"a" INT,
-"x" BIGINT,
-"c" TINYINT,
-"v" BYTE,
-"j" SMALLINT,
-"h" BINARY(1),
-"k" VARBINARY(10),
-"l" FLOAT,
-"m" DOUBLE,
-"n" REAL) STORAGE(ON "MAIN", CLUSTERBTR) ;
-
-COMMENT ON TABLE "test1"."cscs" IS '测试数据类型11-20';
-
-
-CREATE TABLE "test1"."customer"
-(
-"id" BIGINT IDENTITY(1, 1) NOT NULL,
-"name" VARCHAR(50),
-"address" VARCHAR(50),
-"phone" VARCHAR(50),
-NOT CLUSTER PRIMARY KEY("id")) STORAGE(ON "MAIN", CLUSTERBTR) ;
-
-COMMENT ON TABLE "test1"."customer" IS '客户表';
-COMMENT ON COLUMN "test1"."customer"."id" IS '编号';
-COMMENT ON COLUMN "test1"."customer"."name" IS '姓名';
-COMMENT ON COLUMN "test1"."customer"."address" IS '地址';
-COMMENT ON COLUMN "test1"."customer"."phone" IS '电话';
-
-
-CREATE TABLE "test1"."TABLE_1"
-(
-"name" CHAR(10),
-"age" CHAR(10)) STORAGE(ON "MAIN", CLUSTERBTR) ;
-
-COMMENT ON TABLE "test1"."TABLE_1" IS '测试';
-
-
-CREATE TABLE "test1"."TABLE_2"
-(
-"a" CHAR(10),
-"COLUMN_1" CHARACTER(10),
-"COLUMN_2" VARCHAR(50),
-"COLUMN_3" VARCHAR2(50),
-"COLUMN_4" NUMERIC(22,6),
-"COLUMN_5" DECIMAL(22,6),
-"COLUMN_6" NUMBER(22,6),
-"COLUMN_7" DEC(22,6),
-"COLUMN_8" BIT,
-"COLUMN_9" INTEGER) STORAGE(ON "MAIN", CLUSTERBTR) ;
-
-CREATE TABLE "test1"."TABLE_3"
-(
-"COLUMN_1" ROWID,
-"COLUMN_2" "SYS"."AQ$_AGENT") STORAGE(ON "MAIN", CLUSTERBTR) ;
-
-COMMENT ON TABLE "test1"."TABLE_3" IS 'a';
-
-
-CREATE TABLE "test1"."table_sql"
-(
-"t_id" BIGINT IDENTITY(1, 1) NOT NULL,
-"table_sql" TEXT,
-"table_condition" TEXT,
-"table_alias" VARCHAR(50),
-"sql_key" VARCHAR(100),
-"table_export_field" TEXT,
-"create_by" VARCHAR(50),
-"create_time" DATETIME(6),
-"update_by" VARCHAR(50),
-"update_time" DATETIME(6),
-"del_flag" CHAR(1),
-NOT CLUSTER PRIMARY KEY("t_id")) STORAGE(ON "MAIN", CLUSTERBTR) ;
-
-CREATE TABLE "test1"."test"
-(
-"id" INT IDENTITY(1, 1) NOT NULL,
-"name" VARCHAR(50),
-"age" INT,
-"address" VARCHAR(50),
-UNIQUE("id"),
-NOT CLUSTER PRIMARY KEY("id")) STORAGE(ON "MAIN", CLUSTERBTR) ;
-
-COMMENT ON COLUMN "test1"."test"."id" IS '编号';
-COMMENT ON COLUMN "test1"."test"."name" IS '姓名';
-COMMENT ON COLUMN "test1"."test"."age" IS '年龄';
-COMMENT ON COLUMN "test1"."test"."address" IS '地址';
-
-
-CREATE TABLE "test1"."test01"
-(
-"id" FLOAT NOT NULL,
-NOT CLUSTER PRIMARY KEY("id")) STORAGE(ON "MAIN", CLUSTERBTR) ;
-
-COMMENT ON TABLE "test1"."test01" IS '22';
-
-
-CREATE TABLE "test1"."test02"
-(
-"id" INT) STORAGE(ON "MAIN", CLUSTERBTR) ;
-
-COMMENT ON TABLE "test1"."test02" IS '02';
-
-
+"p" TEXT) STORAGE(ON "MAIN", CLUSTERBTR);