Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 代码生成增加JSONObject支持;修复pgsql模板 #107

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public class InnerGenConfigDO extends GenConfigDO {
*/
private boolean hasTimeField;

/**
* 是否包含 JSON 字段
*/
private boolean hasJsonField;

public InnerGenConfigDO() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import java.time.*;
<#if hasBigDecimalField>
import java.math.BigDecimal;
</#if>

<#if hasJsonField>
import com.alibaba.fastjson2.JSONObject;
</#if>
import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import java.time.*;
<#if hasBigDecimalField>
import java.math.BigDecimal;
</#if>
<#if hasJsonField>
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler;
</#if>

import lombok.Data;

Expand All @@ -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</#if>)
public class ${className} extends BaseDO {

@Serial
Expand All @@ -32,6 +37,9 @@ public class ${className} extends BaseDO {
/**
* ${fieldConfig.comment}
*/
<#if fieldConfig.fieldType == "JSONObject">
@TableField(typeHandler = Fastjson2TypeHandler.class)
</#if>
private ${fieldConfig.fieldType} ${fieldConfig.fieldName};
</#list>
</#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);-->
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import java.time.*;
<#if hasBigDecimalField>
import java.math.BigDecimal;
</#if>

<#if hasJsonField>
import com.alibaba.fastjson2.JSONObject;
</#if>
<#if hasRequiredField>
import jakarta.validation.constraints.*;
</#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import java.time.*;
<#if hasBigDecimalField>
import java.math.BigDecimal;
</#if>

<#if hasJsonField>
import com.alibaba.fastjson2.JSONObject;
</#if>
import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ generator:
- mediumtext
- longtext
- tinytext
JSONObject:
- json
- jsonb
Integer:
- int
- tinyint
Expand All @@ -43,7 +45,9 @@ generator:
- varchar
- char
- text
JSONObject:
- json
- jsonb
Integer:
- int2
- int4
Expand Down Expand Up @@ -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
Loading