diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseHelper.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseHelper.java index b7e73c38..1ee0d49c 100644 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseHelper.java +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseHelper.java @@ -41,6 +41,11 @@ public class DataBaseHelper { return DataBaseType.MY_SQL == getDataBaseType(); } + public static boolean isH2() { + return DataBaseType.H2 == getDataBaseType(); + } + + public static boolean isOracle() { return DataBaseType.ORACLE == getDataBaseType(); } diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseType.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseType.java index a19ea2ad..06168643 100644 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseType.java +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseType.java @@ -19,6 +19,7 @@ public enum DataBaseType { */ MY_SQL("MySQL"), + H2("H2"), /** * Oracle */ diff --git a/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml index e268896a..14f2d97b 100644 --- a/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml +++ b/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml @@ -19,6 +19,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName}) order by ordinal_position + + select column_name, +-- (case when (is_nullable = 'no' column_key != 'PRI') then '1' else null end) as is_required, + (case when (is_nullable = 'no' ) then '1' else null end) as is_required, +-- (case when column_key = 'PRI' then '1' else '0' end) as is_pk, + ordinal_position as sort +-- column_comment, +-- (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, +-- column_type + from information_schema.columns where table_name = (#{tableName}) + order by ordinal_position + select lower(temp.column_name) as column_name, (case when (temp.nullable = 'N' and temp.constraint_type != 'P') then '1' else null end) as is_required, diff --git a/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml b/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml index 446b2200..57ff7958 100644 --- a/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml +++ b/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml @@ -74,6 +74,25 @@ order by create_time desc + + select table_name + from information_schema.tables + where + table_name NOT LIKE 'pj_%' AND table_name NOT LIKE 'gen_%' + + AND table_name NOT IN + + #{item} + + + + AND lower(table_name) like lower(concat('%', #{genTable.tableName}, '%')) + + + AND lower(table_comment) like lower(concat('%', #{genTable.tableComment}, '%')) + + order by table_name desc + select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time from user_tables dt, user_tab_comments dtc, user_objects uo @@ -158,6 +177,14 @@ #{name} + + select table_name from information_schema.tables + where table_name NOT LIKE 'pj_%' and table_name NOT LIKE 'gen_%' + and table_name in + + #{name} + + select lower(dt.table_name) as table_name, dtc.comments as table_comment, uo.created as create_time, uo.last_ddl_time as update_time from user_tables dt, user_tab_comments dtc, user_objects uo diff --git a/iot-starter/src/main/resources/application.yml b/iot-starter/src/main/resources/application.yml index 3e15ebf8..dd2b8fe3 100644 --- a/iot-starter/src/main/resources/application.yml +++ b/iot-starter/src/main/resources/application.yml @@ -17,12 +17,45 @@ spring: properties: hibernate: format_sql: true - + sql: + init: + schema-locations: classpath:sql/schema.sql + mode: ALWAYS datasource: url: jdbc:h2:./data/iotkit;MODE=MySQL username: sa password: 123456 driverClassName: org.h2.Driver + type: com.zaxxer.hikari.HikariDataSource + # 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content + dynamic: + hikari: + connection-timeout: 5000 + idle-timeout: 30000 # 经过idle-timeout时间如果连接还处于空闲状态, 该连接会被回收 + min-idle: 5 # 池中维护的最小空闲连接数, 默认为 10 个 + max-pool-size: 16 # 池中最大连接数, 包括闲置和使用中的连接, 默认为 10 个 + max-lifetime: 60000 # 如果一个连接超过了时长,且没有被使用, 连接会被回收 + is-auto-commit: true + primary: master #设置默认的数据源或者数据源组,默认值即为master + strict: true #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源 + datasource: + # 主库数据源 + master: + type: ${spring.datasource.type} + driverClassName: org.h2.Driver + # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562 + # rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题) + url: jdbc:h2:./data/iotkit;MODE=MySQL + username: sa + password: 123456 + # 从库数据源 + slave: + lazy: true + type: ${spring.datasource.type} + driverClassName: org.h2.Driver + url: jdbc:h2:./data/iotkit;MODE=MySQL + username: sa + password: 123456 # 内置h2 web console设置 platform: h2 @@ -84,6 +117,8 @@ spring: mvc: pathmatch: matching-strategy: ant_path_matcher +# profiles: +# active: mysql #application.yml中打开注释支持rocketMq作为消息总线,pom.xml中打开注释使用rocketmq消息总线 #rocketmq: diff --git a/iot-module/iot-generator/src/main/resources/sql/generator.sql b/iot-starter/src/main/resources/sql/schema.sql similarity index 96% rename from iot-module/iot-generator/src/main/resources/sql/generator.sql rename to iot-starter/src/main/resources/sql/schema.sql index e99a1ff1..b9ea000a 100644 --- a/iot-module/iot-generator/src/main/resources/sql/generator.sql +++ b/iot-starter/src/main/resources/sql/schema.sql @@ -1,8 +1,7 @@ -- ---------------------------- -- 18、代码生成业务表 -- ---------------------------- -drop table if exists gen_table; -create table gen_table ( +create table if not exists gen_table ( table_id bigint(20) not null comment '编号', data_name varchar(200) default '' comment '数据源名称', table_name varchar(200) default '' comment '表名称', @@ -32,8 +31,8 @@ create table gen_table ( -- ---------------------------- -- 19、代码生成业务表字段 -- ---------------------------- -drop table if exists gen_table_column; -create table gen_table_column ( + +create table if not exists gen_table_column ( column_id bigint(20) not null comment '编号', table_id bigint(20) comment '归属表编号', column_name varchar(200) comment '列名称',