Merge remote-tracking branch 'base/main' into dev

This commit is contained in:
chenbowen
2025-07-16 17:25:47 +08:00
20 changed files with 236 additions and 51 deletions

3
sql/dm/patch.sql Normal file
View File

@@ -0,0 +1,3 @@
ALTER TABLE infra_file ADD hash VARCHAR(64);
COMMENT ON COLUMN infra_file.hash IS '文件哈希值SHA-256';
CREATE INDEX idx_infra_file_hash ON infra_file(hash);

3
sql/mysql/patch.sql Normal file
View File

@@ -0,0 +1,3 @@
-- 1. 附件信息表新增上传文件 Hash 字段,如果上传文件 hash 重复直接复用不进行重复上传
ALTER TABLE infra_file ADD COLUMN hash VARCHAR(64) COMMENT '文件哈希值SHA-256';
CREATE INDEX idx_infra_file_hash ON infra_file(hash);

View File

@@ -19,7 +19,7 @@ public class BusinessDataPermissionConfiguration {
}
@Bean
public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() {
public DeptDataPermissionRuleCustomizer businessDeptDataPermissionRuleCustomizer() {
return rule -> {
// dept
rule.addDeptColumn("demo_contract", "dept_id");

View File

@@ -35,7 +35,7 @@ public class YudaoBusinessDataPermissionAutoConfiguration {
}
@Bean
public DeptDataPermissionRule deptDataPermissionRule(PermissionCommonApi permissionApi, List<DeptDataPermissionRuleCustomizer> customizers) {
public DeptDataPermissionRule deptBusinessDataPermissionRule(PermissionCommonApi permissionApi, List<DeptDataPermissionRuleCustomizer> customizers) {
// Cloud 专属逻辑:优先使用本地的 PermissionApi 实现类,而不是 Feign 调用
// 原因:在创建租户时,租户还没创建好,导致 Feign 调用获取数据权限时,报“租户不存在”的错误
try {

View File

@@ -34,7 +34,6 @@ import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserNickname;
import static cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils.writeAttachment;
@@ -125,21 +124,29 @@ public class CodegenController {
@Operation(summary = "预览生成代码")
@GetMapping("/preview")
@Parameter(name = "tableId", description = "表编号", required = true, example = "1024")
@Parameters({
@Parameter(name = "tableId", description = "表编号", required = true, example = "1024"),
@Parameter(name = "isBusiness", description = "是否业务基类", example = "false")
})
@PreAuthorize("@ss.hasPermission('infra:codegen:preview')")
public CommonResult<List<CodegenPreviewRespVO>> previewCodegen(@RequestParam("tableId") Long tableId) {
Map<String, String> codes = codegenService.generationCodes(tableId);
public CommonResult<List<CodegenPreviewRespVO>> previewCodegen(@RequestParam("tableId") Long tableId,
@RequestParam(value = "isBusiness", required = false, defaultValue = "false") Boolean isBusiness) {
Map<String, String> codes = codegenService.generationCodes(tableId, isBusiness);
return success(CodegenConvert.INSTANCE.convert(codes));
}
@Operation(summary = "下载生成代码")
@GetMapping("/download")
@Parameter(name = "tableId", description = "表编号", required = true, example = "1024")
@Parameters({
@Parameter(name = "tableId", description = "表编号", required = true, example = "1024"),
@Parameter(name = "isBusiness", description = "是否业务基类", example = "false")
})
@PreAuthorize("@ss.hasPermission('infra:codegen:download')")
public void downloadCodegen(@RequestParam("tableId") Long tableId,
@RequestParam(value = "isBusiness", required = false, defaultValue = "false") Boolean isBusiness,
HttpServletResponse response) throws IOException {
// 生成代码
Map<String, String> codes = codegenService.generationCodes(tableId);
// 生成代码,传递 isBusiness
Map<String, String> codes = codegenService.generationCodes(tableId, isBusiness);
// 构建 zip 包
String[] paths = codes.keySet().toArray(new String[0]);
ByteArrayInputStream[] ins = codes.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new);

View File

@@ -26,7 +26,7 @@ import lombok.*;
public class FileDO extends BaseDO {
/**
* 编号,数据库自增
* 编号
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
@@ -57,4 +57,9 @@ public class FileDO extends BaseDO {
*/
private Integer size;
/**
* 文件哈希值SHA-256
*/
private String hash;
}

View File

@@ -23,4 +23,14 @@ public interface FileMapper extends BaseMapperX<FileDO> {
.orderByDesc(FileDO::getId));
}
/**
* 根据哈希值查询文件
* @param hash 文件哈希值
* @return 文件DO若不存在返回null
*/
default FileDO selectByHash(String hash) {
return selectOne(new LambdaQueryWrapperX<FileDO>()
.eq(FileDO::getHash, hash));
}
}

View File

@@ -86,6 +86,17 @@ public interface CodegenService {
* @param tableId 表编号
* @return 生成结果。key 为文件路径value 为对应的代码内容
*/
/**
* 执行指定表的代码生成,支持业务基类继承
* @param tableId 表编号
* @param isBusiness 是否业务基类
* @return 生成结果
*/
Map<String, String> generationCodes(Long tableId, Boolean isBusiness);
/**
* 兼容原有接口,默认 isBusiness=false
*/
Map<String, String> generationCodes(Long tableId);
/**

View File

@@ -243,7 +243,10 @@ public class CodegenServiceImpl implements CodegenService {
}
@Override
public Map<String, String> generationCodes(Long tableId) {
/**
* 执行指定表的代码生成,支持业务基类继承
*/
public Map<String, String> generationCodes(Long tableId, Boolean isBusiness) {
// 校验是否已经存在
CodegenTableDO table = codegenTableMapper.selectById(tableId);
if (table == null) {
@@ -275,8 +278,16 @@ public class CodegenServiceImpl implements CodegenService {
}
}
// 执行生成
return codegenEngine.execute(table, columns, subTables, subColumnsList);
// 执行生成,传递 isBusiness
return codegenEngine.execute(table, columns, subTables, subColumnsList, isBusiness != null && isBusiness);
}
/**
* 兼容原有接口,默认 isBusiness=false
*/
@Override
public Map<String, String> generationCodes(Long tableId) {
return generationCodes(tableId, false);
}
@Override

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BusinessBaseDO;
import cn.iocoder.yudao.module.infra.convert.codegen.CodegenConvert;
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO;
@@ -67,6 +68,7 @@ public class CodegenBuilder {
* {@link cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO} 的字段
*/
public static final Set<String> BASE_DO_FIELDS = new HashSet<>();
public static final Set<String> BUSINESS_BASE_DO_FIELDS = new HashSet<>();
/**
* 新增操作,不需要传递的字段
*/
@@ -87,12 +89,18 @@ public class CodegenBuilder {
static {
Arrays.stream(ReflectUtil.getFields(BaseDO.class)).forEach(field -> BASE_DO_FIELDS.add(field.getName()));
BASE_DO_FIELDS.add(TENANT_ID_FIELD);
Arrays.stream(ReflectUtil.getFields(BusinessBaseDO.class)).forEach(field -> BUSINESS_BASE_DO_FIELDS.add(field.getName()));
BUSINESS_BASE_DO_FIELDS.add(TENANT_ID_FIELD);
// 处理 OPERATION 相关的字段
CREATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
UPDATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
LIST_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
LIST_OPERATION_EXCLUDE_COLUMN.remove("createTime"); // 创建时间,还是可能需要传递的
LIST_OPERATION_RESULT_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
CREATE_OPERATION_EXCLUDE_COLUMN.addAll(BUSINESS_BASE_DO_FIELDS);
UPDATE_OPERATION_EXCLUDE_COLUMN.addAll(BUSINESS_BASE_DO_FIELDS);
LIST_OPERATION_EXCLUDE_COLUMN.addAll(BUSINESS_BASE_DO_FIELDS);
LIST_OPERATION_RESULT_EXCLUDE_COLUMN.addAll(BUSINESS_BASE_DO_FIELDS);
LIST_OPERATION_EXCLUDE_COLUMN.remove("createTime"); // 创建时间,还是可能需要传递的
LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("createTime"); // 创建时间,还是需要返回的
}

Some files were not shown because too many files have changed in this diff Show More