Skip to content

Commit

Permalink
feat(generator): 代码生成新增菜单SQL模板 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyMelody authored Nov 13, 2024
1 parent c28d3cf commit fb947c9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ public class InnerGenConfigDO extends GenConfigDO {
*/
private boolean hasTimeField;

/**
* Menu icon
*/
private String icon = "list";

/**
* Menu sort order
*/
private Integer sort = 1;

/**
* Parent menu ID placeholder
*/
private String parentMenuId = "#{parentMenuId}";

/**
* Menu type (2 for menu)
*/
private Integer menuType = 2;

public InnerGenConfigDO() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public PageResp<TableResp> pageTable(TableQuery query, PageQuery pageQuery) thro
tableList.removeIf(table -> StrUtil.equalsAnyIgnoreCase(table.getTableName(), generatorProperties
.getExcludeTables()));
CollUtil.sort(tableList, Comparator.comparing(Table::getCreateTime)
.thenComparing(table -> Optional.ofNullable(table.getUpdateTime()).orElse(table.getCreateTime()))
.reversed());
.thenComparing(table -> Optional.ofNullable(table.getUpdateTime()).orElse(table.getCreateTime()))
.reversed());
List<TableResp> tableRespList = BeanUtil.copyToList(tableList, TableResp.class);
PageResp<TableResp> pageResp = PageResp.build(pageQuery.getPage(), pageQuery.getSize(), tableRespList);
pageResp.getList().parallelStream().forEach(tableResp -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- MYSQL
-- ${businessName}管理菜单
INSERT INTO sys_menu (
title, parent_id, type, path, name, component, icon,
is_external, is_cache, is_hidden, permission, sort, status, create_time, update_time
) VALUES (
'${businessName}管理', 1000, ${menuType}, '/${apiModuleName}/${apiName}',
'${classNamePrefix}', '${apiModuleName}/${apiName}/index', '${icon!"list"}',
0, 1, 0, null, ${sort!1}, 1, now(), now()
);

SET @parentId = LAST_INSERT_ID();

-- ${businessName}管理按钮
INSERT INTO sys_menu (
title, parent_id, type, permission, sort, status, create_time, update_time
) VALUES
('查询${businessName}', @parentId, 3, '${apiModuleName}:${apiName}:list', 1, 1, now(), now()),
('详情${businessName}', @parentId, 3, '${apiModuleName}:${apiName}:detail', 2, 1, now(), now()),
('新增${businessName}', @parentId, 3, '${apiModuleName}:${apiName}:add', 3, 1, now(), now()),
('修改${businessName}', @parentId, 3, '${apiModuleName}:${apiName}:update', 4, 1, now(), now()),
('删除${businessName}', @parentId, 3, '${apiModuleName}:${apiName}:delete', 5, 1, now(), now()),
('导出${businessName}', @parentId, 3, '${apiModuleName}:${apiName}:export', 6, 1, now(), now()),
('导入${businessName}', @parentId, 3, '${apiModuleName}:${apiName}:import', 7, 1, now(), now());


<#--
-- PG_SQL
-- ${businessName}管理菜单
INSERT INTO sys_menu (
title, parent_id, type, path, name, component, icon,
is_external, is_cache, is_hidden, permission, sort, status, create_time, update_time
) VALUES (
'${businessName}管理', 1000, ${menuType}, '/${apiModuleName}/${apiName}',
'${classNamePrefix}', '${apiModuleName}/${apiName}/index', '${icon!"list"}',
0, 1, 0, null, ${sort!1}, 1, now(), now()
) RETURNING id INTO parentId;
-- ${businessName}管理按钮
INSERT INTO sys_menu (
title, parent_id, type, permission, sort, status, create_time, update_time
) VALUES
('查询${businessName}', parentId, 3, '${apiModuleName}:${apiName}:list', 1, 1, now(), now()),
('详情${businessName}', parentId, 3, '${apiModuleName}:${apiName}:detail', 2, 1, now(), now()),
('新增${businessName}', parentId, 3, '${apiModuleName}:${apiName}:add', 3, 1, now(), now()),
('修改${businessName}', parentId, 3, '${apiModuleName}:${apiName}:update', 4, 1, now(), now()),
('删除${businessName}', parentId, 3, '${apiModuleName}:${apiName}:delete', 5, 1, now(), now()),
('导出${businessName}', parentId, 3, '${apiModuleName}:${apiName}:export', 6, 1, now(), now()),
('导入${businessName}', parentId, 3, '${apiModuleName}:${apiName}:import', 7, 1, now(), now());
-->
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ generator:
- timestamp
## 模板配置
templateConfigs:
MenuSql:
template-path: backend/menu.sql.ftl
package-name: sql
extension: .sql
backend: true
DO:
# 模板路径
templatePath: backend/Entity.ftl
Expand Down

0 comments on commit fb947c9

Please sign in to comment.