From cf67d606ae9a4649a49b291090a3e3448acf8c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Thu, 17 Mar 2022 19:52:40 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=88=9D=E6=AD=A5=E9=80=82=E9=85=8D?= =?UTF-8?q?=20postgres=20(=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E4=B8=A4?= =?UTF-8?q?=E6=AC=A1=E5=AF=BC=E5=85=A5=E6=9C=89=E9=97=AE=E9=A2=98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/generator/util/VelocityUtils.java | 2 +- .../mapper/generator/GenTableColumnMapper.xml | 31 ++++++++ .../mapper/generator/GenTableMapper.xml | 77 +++++++++++++++++++ ruoyi-ui/src/views/tool/gen/index.vue | 2 +- script/sql/postgres/postgres_ry_vue_4.X.sql | 2 +- 5 files changed, 111 insertions(+), 3 deletions(-) diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java index 81afe56c..74649704 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java @@ -139,7 +139,7 @@ public class VelocityUtils { if (DataBaseHelper.isOracle()) { templates.add("vm/sql/oracle/sql.vm"); } else if (DataBaseHelper.isPostgerSql()) { - templates.add("vm/sql/postgers/sql.vm"); + templates.add("vm/sql/postgres/sql.vm"); } else if (DataBaseHelper.isSqlServer()) { templates.add("vm/sql/sqlserver/sql.vm"); } else { diff --git a/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml index 4614dd41..7b1e9c5f 100644 --- a/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml +++ b/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml @@ -62,6 +62,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ORDER BY temp.column_id + SELECT column_name, is_required, is_pk, sort, column_comment, is_increment, column_type + FROM ( + SELECT c.relname AS table_name, + a.attname AS column_name, + d.description AS column_comment, + CASE WHEN a.attnotnull AND con.conname IS NULL THEN 1 ELSE 0 + END AS is_required, + CASE WHEN con.conname IS NOT NULL THEN 1 ELSE 0 + END AS is_pk, + a.attnum AS sort, + CASE WHEN "position"(pg_get_expr(ad.adbin, ad.adrelid), + ((c.relname::text || '_'::text) || a.attname::text) || '_seq'::text) > 0 THEN 1 ELSE 0 + END AS is_increment, + btrim( + CASE WHEN t.typelem ]]> 0::oid AND t.typlen = '-1'::integer THEN 'ARRAY'::text ELSE + CASE WHEN t.typtype = 'd'::"char" THEN format_type(t.typbasetype, NULL::integer) + ELSE format_type(a.atttypid, NULL::integer) END + END, '"'::text + ) AS column_type + FROM pg_attribute a + JOIN (pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid) ON a.attrelid = c.oid + LEFT JOIN pg_description d ON d.objoid = c.oid AND a.attnum = d.objsubid + LEFT JOIN pg_constraint con ON con.conrelid = c.oid AND (a.attnum = ANY (con.conkey)) + LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum + LEFT JOIN pg_type t ON a.atttypid = t.oid + WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"])) + AND a.attnum > 0 + AND n.nspname = 'public'::name + ORDER BY c.relname, a.attnum + ) temp + WHERE table_name = (#{tableName}) diff --git a/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml index c2a39fda..b66b25d8 100644 --- a/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml +++ b/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml @@ -85,6 +85,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by create_time desc + select table_name, table_comment, create_time, update_time + from ( + SELECT c.relname AS table_name, + obj_description(c.oid) AS table_comment, + CURRENT_TIMESTAMP AS create_time, + CURRENT_TIMESTAMP AS update_time + FROM pg_class c + LEFT JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"])) + AND c.relname != 'spatial_%'::text + AND n.nspname = 'public'::name + AND n.nspname ]]> ''::name + ) list_table + where table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%' + AND table_name NOT IN (select table_name from gen_table) + + AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%')) + + + AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%')) + + order by create_time desc @@ -121,6 +143,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by create_time desc + select table_name, table_comment, create_time, update_time + from ( + SELECT c.relname AS table_name, + obj_description(c.oid) AS table_comment, + CURRENT_TIMESTAMP AS create_time, + CURRENT_TIMESTAMP AS update_time + FROM pg_class c + LEFT JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"])) + AND c.relname != 'spatial_%'::text + AND n.nspname = 'public'::name + AND n.nspname ]]> ''::name + ) list_table + where table_name NOT LIKE 'xxl_job_%' AND table_name NOT LIKE 'gen_%' + AND table_name NOT IN (select table_name from gen_table) + + AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%')) + + + AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%')) + + order by create_time desc @@ -149,6 +193,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + select table_name, table_comment, create_time, update_time + from ( + SELECT c.relname AS table_name, + obj_description(c.oid) AS table_comment, + CURRENT_TIMESTAMP AS create_time, + CURRENT_TIMESTAMP AS update_time + FROM pg_class c + LEFT JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"])) + AND c.relname != 'spatial_%'::text + AND n.nspname = 'public'::name + AND n.nspname ]]> ''::name + ) list_table + where table_name NOT LIKE 'xxl_job_%' and table_name NOT LIKE 'gen_%' + and table_name in + + #{name} + @@ -171,6 +233,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and lower(dt.table_name) = #{tableName} + select table_name, table_comment, create_time, update_time + from ( + SELECT c.relname AS table_name, + obj_description(c.oid) AS table_comment, + CURRENT_TIMESTAMP AS create_time, + CURRENT_TIMESTAMP AS update_time + FROM pg_class c + LEFT JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE (c.relkind = ANY (ARRAY ['r'::"char", 'p'::"char"])) + AND c.relname != 'spatial_%'::text + AND n.nspname = 'public'::name + AND n.nspname ]]> ''::name + ) list_table + where table_name NOT LIKE 'xxl_job_%' and table_name NOT LIKE 'gen_%' + and table_name = #{tableName} diff --git a/ruoyi-ui/src/views/tool/gen/index.vue b/ruoyi-ui/src/views/tool/gen/index.vue index 25db1c4b..47d3c8fb 100644 --- a/ruoyi-ui/src/views/tool/gen/index.vue +++ b/ruoyi-ui/src/views/tool/gen/index.vue @@ -229,7 +229,7 @@ export default { }; }, created() { - localStorage.setItem("dataName", "master"); + localStorage.setItem("dataName", "postgres"); this.getList(); }, activated() { diff --git a/script/sql/postgres/postgres_ry_vue_4.X.sql b/script/sql/postgres/postgres_ry_vue_4.X.sql index 7a1a60de..5c9c66b8 100644 --- a/script/sql/postgres/postgres_ry_vue_4.X.sql +++ b/script/sql/postgres/postgres_ry_vue_4.X.sql @@ -825,7 +825,7 @@ drop table if exists gen_table_column; create table if not exists gen_table_column ( column_id int8, - table_id varchar(64) default null::varchar, + table_id int8, column_name varchar(200) default null::varchar, column_comment varchar(500) default null::varchar, column_type varchar(100) default null::varchar,