chore: continew-starter 2.7.1 => 2.7.2

1.重构代码生成(PostgreSQL 数据库兼容更完整)
2.适配 Tree 树结构生成
3.适配字典扩展配置
This commit is contained in:
2024-11-13 22:36:08 +08:00
parent fb947c98fd
commit 1ddac12cd2
17 changed files with 117 additions and 209 deletions

View File

@@ -27,6 +27,7 @@ import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import top.continew.admin.common.constant.RegexConstants;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.StrUtils;
import java.io.Serial;
import java.io.Serializable;
@@ -55,6 +56,13 @@ public class GenConfigDO implements Serializable {
@NotBlank(message = "表名称不能为空")
private String tableName;
/**
* 描述
*/
@Schema(description = "描述", example = "用户表")
@TableField(exist = false)
private String comment;
/**
* 模块名称
*/
@@ -127,4 +135,15 @@ public class GenConfigDO implements Serializable {
this.tablePrefix = StrUtil.subPre(tableName, underLineIndex + 1);
}
}
/**
* 类名前缀
*/
@Schema(description = "类名前缀", example = "User")
public String getClassNamePrefix() {
String tableName = this.getTableName();
String rawClassName = StrUtils.blankToDefault(this.getTablePrefix(), tableName, prefix -> StrUtil
.removePrefix(tableName, prefix));
return StrUtil.upperFirst(StrUtil.toCamelCase(rawClassName));
}
}

View File

@@ -22,7 +22,6 @@ import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.StrUtils;
import java.io.Serial;
import java.util.List;
@@ -101,26 +100,6 @@ 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() {
}
@@ -138,10 +117,8 @@ public class InnerGenConfigDO extends GenConfigDO {
.lastIndexOfIgnoreCase(realPackageName, StringConstants.DOT) + 1));
}
@Override
public String getClassNamePrefix() {
String tableName = super.getTableName();
String rawClassName = StrUtils.blankToDefault(super.getTablePrefix(), tableName, prefix -> StrUtil
.removePrefix(tableName, prefix));
return StrUtil.upperFirst(StrUtil.toCamelCase(rawClassName));
return super.getClassNamePrefix();
}
}

View File

@@ -23,14 +23,14 @@ import java.io.Serial;
import java.io.Serializable;
/**
* 表信息查询条件
* 生成配置查询条件
*
* @author Charles7c
* @since 2023/4/12 20:21
*/
@Data
@Schema(description = "表信息查询条件")
public class TableQuery implements Serializable {
@Schema(description = "生成配置查询条件")
public class GenConfigQuery implements Serializable {
@Serial
private static final long serialVersionUID = 1L;

View File

@@ -1,85 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.generator.model.resp;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
/**
* 表信息
*
* @author Charles7c
* @since 2023/4/12 20:21
*/
@Data
@Schema(description = "表信息")
public class TableResp implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 表名称
*/
@Schema(description = "表名称", example = "sys_user")
private String tableName;
/**
* 描述
*/
@Schema(description = "描述", example = "用户表")
private String comment;
/**
* 存储引擎
*/
@Schema(description = "存储引擎", example = "InnoDB")
private String engine;
/**
* 字符集
*/
@Schema(description = "字符集", example = "utf8mb4_general_ci")
private String charset;
/**
* 创建时间
*/
@Schema(description = "创建时间", example = "2023-08-08 08:08:08", type = "string")
private LocalDateTime createTime;
/**
* 是否已配置
*/
@Schema(description = "是否已配置", example = "true")
private Boolean isConfiged;
/**
* 是否禁用
*/
@Schema(description = "是否禁用", example = "true")
private Boolean disabled;
public Boolean getDisabled() {
return !isConfiged;
}
}

View File

@@ -19,10 +19,9 @@ package top.continew.admin.generator.service;
import jakarta.servlet.http.HttpServletResponse;
import top.continew.admin.generator.model.entity.FieldConfigDO;
import top.continew.admin.generator.model.entity.GenConfigDO;
import top.continew.admin.generator.model.query.TableQuery;
import top.continew.admin.generator.model.query.GenConfigQuery;
import top.continew.admin.generator.model.req.GenConfigReq;
import top.continew.admin.generator.model.resp.GeneratePreviewResp;
import top.continew.admin.generator.model.resp.TableResp;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
@@ -38,14 +37,13 @@ import java.util.List;
public interface GeneratorService {
/**
* 分页查询表信息列表
* 分页查询生成配置列表
*
* @param query 查询条件
* @param pageQuery 分页查询条件
* @return 表信息分页列表
* @throws SQLException /
* @return 分页列表信息
*/
PageResp<TableResp> pageTable(TableQuery query, PageQuery pageQuery) throws SQLException;
PageResp<GenConfigDO> pageGenConfig(GenConfigQuery query, PageQuery pageQuery);
/**
* 查询生成配置信息

View File

@@ -25,6 +25,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
import cn.hutool.db.meta.Column;
import cn.hutool.db.meta.Table;
import cn.hutool.system.SystemUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.servlet.http.HttpServletResponse;
@@ -40,10 +41,9 @@ import top.continew.admin.generator.mapper.GenConfigMapper;
import top.continew.admin.generator.model.entity.FieldConfigDO;
import top.continew.admin.generator.model.entity.GenConfigDO;
import top.continew.admin.generator.model.entity.InnerGenConfigDO;
import top.continew.admin.generator.model.query.TableQuery;
import top.continew.admin.generator.model.query.GenConfigQuery;
import top.continew.admin.generator.model.req.GenConfigReq;
import top.continew.admin.generator.model.resp.GeneratePreviewResp;
import top.continew.admin.generator.model.resp.TableResp;
import top.continew.admin.generator.service.GeneratorService;
import top.continew.starter.core.autoconfigure.project.ProjectProperties;
import top.continew.starter.core.constant.StringConstants;
@@ -52,7 +52,6 @@ import top.continew.starter.core.util.TemplateUtils;
import top.continew.starter.core.util.validate.CheckUtils;
import top.continew.starter.data.core.enums.DatabaseType;
import top.continew.starter.data.core.util.MetaUtils;
import top.continew.starter.data.core.util.Table;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.web.util.FileUploadUtils;
@@ -83,25 +82,30 @@ public class GeneratorServiceImpl implements GeneratorService {
private static final List<String> TIME_PACKAGE_CLASS = Arrays.asList("LocalDate", "LocalTime", "LocalDateTime");
@Override
public PageResp<TableResp> pageTable(TableQuery query, PageQuery pageQuery) throws SQLException {
public PageResp<GenConfigDO> pageGenConfig(GenConfigQuery query, PageQuery pageQuery) {
// 查询所有表
List<Table> tableList = MetaUtils.getTables(dataSource);
tableList.removeIf(table -> StrUtil.equalsAnyIgnoreCase(table.getTableName(), generatorProperties
.getExcludeTables()));
String tableName = query.getTableName();
if (StrUtil.isNotBlank(tableName)) {
tableList.removeIf(table -> !StrUtil.containsAnyIgnoreCase(table.getTableName(), tableName));
}
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());
List<TableResp> tableRespList = BeanUtil.copyToList(tableList, TableResp.class);
PageResp<TableResp> pageResp = PageResp.build(pageQuery.getPage(), pageQuery.getSize(), tableRespList);
pageResp.getList().parallelStream().forEach(tableResp -> {
long count = genConfigMapper.selectCount(Wrappers.lambdaQuery(GenConfigDO.class)
.eq(GenConfigDO::getTableName, tableResp.getTableName()));
tableResp.setIsConfiged(count > 0);
});
return pageResp;
// 查询生成配置
List<GenConfigDO> list = tableList.parallelStream().map(table -> {
GenConfigDO genConfig = genConfigMapper.selectById(table.getTableName());
if (genConfig == null) {
genConfig = new GenConfigDO(table.getTableName());
}
genConfig.setComment(table.getComment());
return genConfig;
})
.sorted(Comparator.comparing(GenConfigDO::getTableName)
.thenComparing(GenConfigDO::getUpdateTime, Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(GenConfigDO::getCreateTime, Comparator.nullsLast(Comparator.naturalOrder())))
.toList();
// 分页
return PageResp.build(pageQuery.getPage(), pageQuery.getSize(), list);
}
@Override

View File

@@ -0,0 +1,37 @@
-- ${businessName}管理菜单
INSERT INTO `sys_menu`
(`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, b'0', b'0', b'0', NULL, 1, 1, 1, NOW(), NULL, NULL);
SET @parentId = LAST_INSERT_ID();
-- ${businessName}管理按钮
INSERT INTO `sys_menu`
(`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);
<#--
-- 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);-->

View File

@@ -1,50 +0,0 @@
-- 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());
-->