diff --git a/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/model/entity/InnerGenConfigDO.java b/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/model/entity/InnerGenConfigDO.java index d350dd4df..43aac3272 100644 --- a/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/model/entity/InnerGenConfigDO.java +++ b/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/model/entity/InnerGenConfigDO.java @@ -100,6 +100,11 @@ public class InnerGenConfigDO extends GenConfigDO { */ private boolean hasTimeField; + /** + * 是否包含 JSON 字段 + */ + private boolean hasJsonField; + public InnerGenConfigDO() { } diff --git a/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java b/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java index 9a495489d..eabc8e698 100644 --- a/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java +++ b/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/service/impl/GeneratorServiceImpl.java @@ -370,6 +370,9 @@ private void pretreatment(InnerGenConfigDO genConfig) { if (TIME_PACKAGE_CLASS.contains(fieldType)) { genConfig.setHasTimeField(true); } + if ("JSONObject".equals(fieldType)) { + genConfig.setHasJsonField(true); + } // 字典码 if (StrUtil.isNotBlank(fieldConfig.getDictCode())) { genConfig.setHasDictField(true); diff --git a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/DetailResp.ftl b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/DetailResp.ftl index 5f8dfc7de..6868accfd 100644 --- a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/DetailResp.ftl +++ b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/DetailResp.ftl @@ -7,7 +7,9 @@ import java.time.*; <#if hasBigDecimalField> import java.math.BigDecimal; - +<#if hasJsonField> + import com.alibaba.fastjson2.JSONObject; + import lombok.Data; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Entity.ftl b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Entity.ftl index f5707e972..6b7ff2a7f 100644 --- a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Entity.ftl +++ b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Entity.ftl @@ -7,6 +7,11 @@ import java.time.*; <#if hasBigDecimalField> import java.math.BigDecimal; +<#if hasJsonField> + import com.alibaba.fastjson2.JSONObject; + import com.baomidou.mybatisplus.annotation.TableField; + import com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler; + import lombok.Data; @@ -21,7 +26,7 @@ import top.continew.starter.extension.crud.model.entity.BaseDO; * @since ${datetime} */ @Data -@TableName("${tableName}") +@TableName(value = "${tableName}"<#if hasJsonField>, autoResultMap = true) public class ${className} extends BaseDO { @Serial @@ -32,6 +37,9 @@ public class ${className} extends BaseDO { /** * ${fieldConfig.comment} */ + <#if fieldConfig.fieldType == "JSONObject"> + @TableField(typeHandler = Fastjson2TypeHandler.class) + private ${fieldConfig.fieldType} ${fieldConfig.fieldName}; diff --git a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu.ftl b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu.ftl index 02030d071..0d07c5211 100644 --- a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu.ftl +++ b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu.ftl @@ -16,22 +16,3 @@ VALUES ('修改', @parentId, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '${apiModuleName}:${apiName}:update', 4, 1, 1, NOW(), NULL, NULL), ('删除', @parentId, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '${apiModuleName}:${apiName}:delete', 5, 1, 1, NOW(), NULL, NULL), ('导出', @parentId, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '${apiModuleName}:${apiName}:export', 6, 1, 1, NOW(), NULL, NULL); - -<#-- --- PostgreSQL --- ${businessName}管理菜单 -INSERT INTO "sys_menu" -("id", "title", "parent_id", "type", "path", "name", "component", "redirect", "icon", "is_external", "is_cache", "is_hidden", "permission", "sort", "status", "create_user", "create_time", "update_user", "update_time") -VALUES -('${businessName}管理', 1000, 2, '/${apiModuleName}/${apiName}', '${classNamePrefix}', '${apiModuleName}/${apiName}/index', NULL, NULL, false, false, false, NULL, 1, 1, 1, NOW(), NULL, NULL) RETURNING id INTO parentId; - --- ${businessName}管理按钮 -INSERT INTO "sys_menu" -("id", "title", "parent_id", "type", "path", "name", "component", "redirect", "icon", "is_external", "is_cache", "is_hidden", "permission", "sort", "status", "create_user", "create_time", "update_user", "update_time") -VALUES -('列表', parentId, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '${apiModuleName}:${apiName}:list', 1, 1, 1, NOW(), NULL, NULL), -('详情', parentId, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '${apiModuleName}:${apiName}:detail', 2, 1, 1, NOW(), NULL, NULL), -('新增', parentId, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '${apiModuleName}:${apiName}:add', 3, 1, 1, NOW(), NULL, NULL), -('修改', parentId, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '${apiModuleName}:${apiName}:update', 4, 1, 1, NOW(), NULL, NULL), -('删除', parentId, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '${apiModuleName}:${apiName}:delete', 5, 1, 1, NOW(), NULL, NULL), -('导出', parentId, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '${apiModuleName}:${apiName}:export', 6, 1, 1, NOW(), NULL, NULL);--> diff --git a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu_pg.ftl b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu_pg.ftl new file mode 100644 index 000000000..c30b77c2a --- /dev/null +++ b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Menu_pg.ftl @@ -0,0 +1,29 @@ +--PG SQL +-- 创建序列(如果还不存在的话) +CREATE SEQUENCE IF NOT EXISTS sys_menu_id_seq; + +-- ${businessName}管理菜单 +WITH inserted_menu AS ( +INSERT INTO sys_menu ( +id, title, parent_id, type, path, name, component, icon, +is_external, is_cache, is_hidden, permission, sort, status, create_time, update_time, create_user +) VALUES ( +nextval('sys_menu_id_seq'), '${businessName}管理', 0, ${menuType}, '/${apiModuleName}/${apiName}', +'${classNamePrefix}', '${apiModuleName}/${apiName}/index', '${icon!"list"}', +false, true, false, null, ${sort!1}, 1, now(), now(), 1 +) RETURNING id +) +-- ${businessName}管理按钮 +INSERT INTO sys_menu ( +id, title, parent_id, type, permission, sort, status, create_time, update_time, create_user +) +SELECT nextval('sys_menu_id_seq'), title, (SELECT id FROM inserted_menu), type, permission, sort, status, create_time, update_time, create_user +FROM (VALUES +('查询${businessName}', 3, '${apiModuleName}:${apiName}:list', 1, 1, now(), now(), 1), +('详情${businessName}', 3, '${apiModuleName}:${apiName}:detail', 2, 1, now(), now(), 1), +('新增${businessName}', 3, '${apiModuleName}:${apiName}:add', 3, 1, now(), now(), 1), +('修改${businessName}', 3, '${apiModuleName}:${apiName}:update', 4, 1, now(), now(), 1), +('删除${businessName}', 3, '${apiModuleName}:${apiName}:delete', 5, 1, now(), now(), 1), +('导出${businessName}', 3, '${apiModuleName}:${apiName}:export', 6, 1, now(), now(), 1), +('导入${businessName}', 3, '${apiModuleName}:${apiName}:import', 7, 1, now(), now(), 1) +) AS t(title, type, permission, sort, status, create_time, update_time, create_user); \ No newline at end of file diff --git a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Req.ftl b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Req.ftl index 72111f18f..a34911607 100644 --- a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Req.ftl +++ b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Req.ftl @@ -7,7 +7,9 @@ import java.time.*; <#if hasBigDecimalField> import java.math.BigDecimal; - +<#if hasJsonField> + import com.alibaba.fastjson2.JSONObject; + <#if hasRequiredField> import jakarta.validation.constraints.*; diff --git a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Resp.ftl b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Resp.ftl index 1c12bd969..7b625d51e 100644 --- a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Resp.ftl +++ b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Resp.ftl @@ -7,7 +7,9 @@ import java.time.*; <#if hasBigDecimalField> import java.math.BigDecimal; - +<#if hasJsonField> + import com.alibaba.fastjson2.JSONObject; + import lombok.Data; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/continew-webapi/src/main/resources/config/application-generator.yml b/continew-webapi/src/main/resources/config/application-generator.yml index 7a808fad2..47260bd08 100644 --- a/continew-webapi/src/main/resources/config/application-generator.yml +++ b/continew-webapi/src/main/resources/config/application-generator.yml @@ -16,7 +16,9 @@ generator: - mediumtext - longtext - tinytext + JSONObject: - json + - jsonb Integer: - int - tinyint @@ -43,7 +45,9 @@ generator: - varchar - char - text + JSONObject: - json + - jsonb Integer: - int2 - int4 @@ -133,4 +137,9 @@ generator: template-path: backend/Menu.ftl packageName: sql extension: .sql + backend: true + MenuPG: + template-path: backend/Menu_pg.ftl + packageName: sql + extension: .sql backend: true \ No newline at end of file