diff --git a/yudao-framework/yudao-spring-boot-starter-test/src/main/java/cn/iocoder/yudao/framework/test/core/util/RandomUtils.java b/yudao-framework/yudao-spring-boot-starter-test/src/main/java/cn/iocoder/yudao/framework/test/core/util/RandomUtils.java index a0ee60c42..aa2f18c76 100644 --- a/yudao-framework/yudao-spring-boot-starter-test/src/main/java/cn/iocoder/yudao/framework/test/core/util/RandomUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-test/src/main/java/cn/iocoder/yudao/framework/test/core/util/RandomUtils.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.test.core.util; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.util.collection.SetUtils; import uk.co.jemos.podam.api.PodamFactory; import uk.co.jemos.podam.api.PodamFactoryImpl; @@ -21,6 +22,9 @@ public class RandomUtils { private static final int RANDOM_STRING_LENGTH = 10; + private static final Set TINYINT_FIELDS = SetUtils.asSet("type", "category"); + private static final int TINYINT_MAX = 127; + private static final int RANDOM_DATE_MAX = 30; private static final int RANDOM_COLLECTION_LENGTH = 5; @@ -37,6 +41,10 @@ public class RandomUtils { if (attributeMetadata.getAttributeName().equals("status")) { return RandomUtil.randomEle(CommonStatusEnum.values()).getStatus(); } + // 针对部分字段,使用 tinyint 范围 + if (TINYINT_FIELDS.contains(attributeMetadata.getAttributeName())) { + return RandomUtil.randomInt(1, TINYINT_MAX + 1); + } return RandomUtil.randomInt(); }); // Boolean diff --git a/yudao-module-pay/yudao-module-pay-impl/src/test/resources/sql/create_tables.sql b/yudao-module-pay/yudao-module-pay-impl/src/test/resources/sql/create_tables.sql index e4a141e9f..890fb7700 100644 --- a/yudao-module-pay/yudao-module-pay-impl/src/test/resources/sql/create_tables.sql +++ b/yudao-module-pay/yudao-module-pay-impl/src/test/resources/sql/create_tables.sql @@ -1,5 +1,4 @@ -CREATE TABLE IF NOT EXISTS "pay_merchant" -( +CREATE TABLE IF NOT EXISTS "pay_merchant" ( "id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY, "no" varchar(32) NOT NULL, "name" varchar(64) NOT NULL, diff --git a/yudao-module-tool/yudao-module-tool-impl/src/main/java/cn/iocoder/yudao/module/tool/service/codegen/inner/CodegenEngine.java b/yudao-module-tool/yudao-module-tool-impl/src/main/java/cn/iocoder/yudao/module/tool/service/codegen/inner/CodegenEngine.java index 5aba3e329..020c2f6af 100644 --- a/yudao-module-tool/yudao-module-tool-impl/src/main/java/cn/iocoder/yudao/module/tool/service/codegen/inner/CodegenEngine.java +++ b/yudao-module-tool/yudao-module-tool-impl/src/main/java/cn/iocoder/yudao/module/tool/service/codegen/inner/CodegenEngine.java @@ -86,6 +86,7 @@ public class CodegenEngine { vueFilePath("api/${table.moduleName}/${classNameVar}.js")) // SQL .put("codegen/sql/sql.vm", "sql/sql.sql") + .put("codegen/sql/h2.vm", "sql/h2.sql") .build(); @Resource diff --git a/yudao-module-tool/yudao-module-tool-impl/src/main/resources/codegen/sql/h2.vm b/yudao-module-tool/yudao-module-tool-impl/src/main/resources/codegen/sql/h2.vm new file mode 100644 index 000000000..842605a0f --- /dev/null +++ b/yudao-module-tool/yudao-module-tool-impl/src/main/resources/codegen/sql/h2.vm @@ -0,0 +1,24 @@ +-- 将该建表 SQL 语句,添加到 yudao-module-${table.moduleName}-impl 模块的 test/resources/sql/create_tables.sql 文件里 +CREATE TABLE IF NOT EXISTS "${table.tableName}" ( +#foreach ($column in $columns) + #if (${column.primaryKey})##处理主键 + "${column.javaField}"#if (${column.javaType} == 'String') ${column.columnType} NOT NULL#else ${column.columnType} NOT NULL GENERATED BY DEFAULT AS IDENTITY#end, + #else + #if (${column.columnName} == 'create_time') + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + #elseif (${column.columnName} == 'update_time') + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + #elseif (${column.columnName} == 'creator' || ${column.columnName} == 'updater') + "${column.columnName}" ${column.columnType} DEFAULT '', + #elseif (${column.columnName} == 'deleted') + "deleted" bit NOT NULL DEFAULT FALSE, + #else + "${column.columnName}" ${column.columnType}#if (${column.nullable} == false) NOT NULL#end, + #end + #end +#end + PRIMARY KEY ("${primaryColumn.columnName}") +) COMMENT '${table.tableComment}'; + +-- 将该删表 SQL 语句,添加到 yudao-module-${table.moduleName}-impl 模块的 test/resources/sql/clean.sql 文件里 +DELETE FROM "${table.tableName}"; diff --git a/yudao-module-tool/yudao-module-tool-impl/src/test/resources/sql/clean.sql b/yudao-module-tool/yudao-module-tool-impl/src/test/resources/sql/clean.sql index e69de29bb..4afb9e7fc 100644 --- a/yudao-module-tool/yudao-module-tool-impl/src/test/resources/sql/clean.sql +++ b/yudao-module-tool/yudao-module-tool-impl/src/test/resources/sql/clean.sql @@ -0,0 +1 @@ +DELETE FROM "tool_test_demo"; diff --git a/yudao-module-tool/yudao-module-tool-impl/src/test/resources/sql/create_tables.sql b/yudao-module-tool/yudao-module-tool-impl/src/test/resources/sql/create_tables.sql index e69de29bb..298430883 100644 --- a/yudao-module-tool/yudao-module-tool-impl/src/test/resources/sql/create_tables.sql +++ b/yudao-module-tool/yudao-module-tool-impl/src/test/resources/sql/create_tables.sql @@ -0,0 +1,14 @@ +CREATE TABLE IF NOT EXISTS "tool_test_demo" ( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "name" varchar(100) NOT NULL, + "status" tinyint NOT NULL, + "type" tinyint NOT NULL, + "category" tinyint NOT NULL, + "remark" varchar(500), + "creator" varchar(64) DEFAULT '''', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar(64) DEFAULT '''', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + PRIMARY KEY ("id") +) COMMENT '字典类型表'; diff --git a/yudao-server/src/test/resources/application-unit-test.yaml b/yudao-server/src/test/resources/application-unit-test.yaml deleted file mode 100644 index d306a7af4..000000000 --- a/yudao-server/src/test/resources/application-unit-test.yaml +++ /dev/null @@ -1,44 +0,0 @@ -spring: - main: - lazy-initialization: true # 开启懒加载,加快速度 - banner-mode: off # 单元测试,禁用 Banner - ---- #################### 数据库相关配置 #################### - -spring: - # 数据源配置项 - datasource: - name: ruoyi-vue-pro - url: jdbc:h2:mem:testdb;MODE=MYSQL;DATABASE_TO_UPPER=false; # MODE 使用 MySQL 模式;DATABASE_TO_UPPER 配置表和字段使用小写 - driver-class-name: org.h2.Driver - username: sa - password: - schema: classpath:sql/create_tables.sql # MySQL 转 H2 的语句,使用 https://www.jooq.org/translate/ 工具 - druid: - async-init: true # 单元测试,异步初始化 Druid 连接池,提升启动速度 - initial-size: 1 # 单元测试,配置为 1,提升启动速度 - - # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 - redis: - host: 127.0.0.1 # 地址 - port: 16379 # 端口(单元测试,使用 16379 端口) - database: 0 # 数据库索引 - -mybatis: - lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试 - ---- #################### 定时任务相关配置 #################### - ---- #################### 配置中心相关配置 #################### - ---- #################### 服务保障相关配置 #################### - -# Lock4j 配置项(单元测试,禁用 Lock4j) - -# Resilience4j 配置项 - ---- #################### 监控相关配置 #################### - ---- #################### 芋道相关配置 #################### - -# 芋道配置项,设置当前项目所有自定义的配置 diff --git a/yudao-server/src/test/resources/logback.xml b/yudao-server/src/test/resources/logback.xml deleted file mode 100644 index 1e4bb6caf..000000000 --- a/yudao-server/src/test/resources/logback.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - -       - - - ${PATTERN_DEFAULT} - - - - - - - - - diff --git a/yudao-server/src/test/resources/sql/clean.sql b/yudao-server/src/test/resources/sql/clean.sql deleted file mode 100644 index 9e0718a86..000000000 --- a/yudao-server/src/test/resources/sql/clean.sql +++ /dev/null @@ -1,13 +0,0 @@ --- inf 开头的 DB - - --- pay 开头的 DB -DELETE FROM pay_merchant; -DELETE FROM pay_app; -DELETE FROM pay_channel; -DELETE FROM pay_order; -DELETE FROM pay_refund; - --- bpm 开头的 DB -DELETE FROM "bpm_form"; -DELETE FROM "bpm_user_group"; diff --git a/yudao-server/src/test/resources/sql/create_tables.sql b/yudao-server/src/test/resources/sql/create_tables.sql deleted file mode 100644 index 850146fec..000000000 --- a/yudao-server/src/test/resources/sql/create_tables.sql +++ /dev/null @@ -1,151 +0,0 @@ --- inf 开头的 DB - - -CREATE TABLE IF NOT EXISTS "pay_merchant" -( - "id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "no" varchar(32) NOT NULL, - "name" varchar(64) NOT NULL, - "short_name" varchar(64) NOT NULL, - "status" tinyint NOT NULL, - "remark" varchar(255) DEFAULT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit(1) NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '支付商户信息'; - --- bpm 开头的 DB - -CREATE TABLE IF NOT EXISTS "pay_app" ( - "id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(64) NOT NULL, - "status" tinyint NOT NULL, - "remark" varchar(255) DEFAULT NULL, - `pay_notify_url` varchar(1024) NOT NULL, - `refund_notify_url` varchar(1024) NOT NULL, - `merchant_id` bigint(20) NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit(1) NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT = '支付应用信息'; - -CREATE TABLE IF NOT EXISTS "pay_channel" ( - "id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "code" varchar(32) NOT NULL, - "status" tinyint(4) NOT NULL, - "remark" varchar(255) DEFAULT NULL, - "fee_rate" double NOT NULL DEFAULT 0, - "merchant_id" bigint(20) NOT NULL, - "app_id" bigint(20) NOT NULL, - "config" varchar(10240) NOT NULL, - "creator" varchar(64) NULL DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) NULL DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit(1) NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT = '支付渠道'; - -CREATE TABLE IF NOT EXISTS `pay_order` ( - "id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY, - `merchant_id` bigint(20) NOT NULL, - `app_id` bigint(20) NOT NULL, - `channel_id` bigint(20) DEFAULT NULL, - `channel_code` varchar(32) DEFAULT NULL, - `merchant_order_id` varchar(64) NOT NULL, - `subject` varchar(32) NOT NULL, - `body` varchar(128) NOT NULL, - `notify_url` varchar(1024) NOT NULL, - `notify_status` tinyint(4) NOT NULL, - `amount` bigint(20) NOT NULL, - `channel_fee_rate` double DEFAULT 0, - `channel_fee_amount` bigint(20) DEFAULT 0, - `status` tinyint(4) NOT NULL, - `user_ip` varchar(50) NOT NULL, - `expire_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP, - `success_time` datetime(0) DEFAULT CURRENT_TIMESTAMP, - `notify_time` datetime(0) DEFAULT CURRENT_TIMESTAMP, - `success_extension_id` bigint(20) DEFAULT NULL COMMENT '支付成功的订单拓展单编号', - `refund_status` tinyint(4) NOT NULL, - `refund_times` tinyint(4) NOT NULL, - `refund_amount` bigint(20) NOT NULL, - `channel_user_id` varchar(255) DEFAULT NULL, - `channel_order_no` varchar(64) DEFAULT NULL, - `creator` varchar(64) DEFAULT '', - `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updater` varchar(64) DEFAULT '', - `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `deleted` bit(1) NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT = '支付订单'; - -CREATE TABLE IF NOT EXISTS `pay_refund` ( - "id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY, - `merchant_id` bigint(20) NOT NULL, - `app_id` bigint(20) NOT NULL, - `channel_id` bigint(20) NOT NULL, - `channel_code` varchar(32) NOT NULL, - `order_id` bigint(20) NOT NULL, - `trade_no` varchar(64) NOT NULL, - `merchant_order_id` varchar(64) NOT NULL, - `merchant_refund_no` varchar(64) NOT NULL, - `notify_url` varchar(1024) NOT NULL, - `notify_status` tinyint(4) NOT NULL, - `status` tinyint(4) NOT NULL, - `type` tinyint(4) NOT NULL, - `pay_amount` bigint(20) NOT NULL, - `refund_amount` bigint(20) NOT NULL, - `reason` varchar(256) NOT NULL, - `user_ip` varchar(50) NULL DEFAULT NULL, - `channel_order_no` varchar(64) NOT NULL, - `channel_refund_no` varchar(64) NULL DEFAULT NULL, - `channel_error_code` varchar(128) NULL DEFAULT NULL, - `channel_error_msg` varchar(256) NULL DEFAULT NULL, - `channel_extras` varchar(1024) NULL DEFAULT NULL, - `expire_time` datetime(0) NULL DEFAULT NULL, - `success_time` datetime(0) NULL DEFAULT NULL, - `notify_time` datetime(0) NULL DEFAULT NULL, - `creator` varchar(64) NULL DEFAULT '', - `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updater` varchar(64) NULL DEFAULT '', - `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `deleted` bit(1) NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT = '退款订单'; - --- bpm 开头的 DB - -CREATE TABLE IF NOT EXISTS "bpm_form" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(63) NOT NULL, - "status" tinyint NOT NULL, - "fields" varchar(255) NOT NULL, - "conf" varchar(255) NOT NULL, - "remark" varchar(255), - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '动态表单'; - -CREATE TABLE IF NOT EXISTS "bpm_user_group" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(63) NOT NULL, - "description" varchar(255) NOT NULL, - "status" tinyint NOT NULL, - "member_user_ids" varchar(255) NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") - ) COMMENT '用户组'; diff --git a/更新日志.md b/更新日志.md index 6f864893d..447a78bbb 100644 --- a/更新日志.md +++ b/更新日志.md @@ -24,7 +24,7 @@ *【重构】大模块按照多 Maven Module 的方式拆分,提升可维护性,为后续重构 onemall 提供基础 *【新增】Spring Security 支持读取多种用户类型,从不同的数据库表,从而实现单项目提供管理后台、用户 APP 的不同 RESTful API 接口 -*【新增】代码生成器支持多 Maven Module 的方式生成代码,支持管理后台、用户 APP 两种场景的 RESTful API 的生成 +*【新增】代码生成器支持多 Maven Module 的方式生成代码,支持管理后台、用户 APP 两种场景的 RESTful API 的生成,支持 H2 测试数据库的生成 *【重构】将数据库文档调整到 tool 模块,更加明确 ### 🐞 Bug Fixes