1. 代码生成器在生成的时候可以手动选择是否是业务数据类代码(会自动继承基础业务类,合并字段,实现业务接口标记,这个标记会将右上角选择公司作为当前业务数据数据权限进行过滤,办理业务时,如果操作人归属同一个公司的多个部门,会前置校验后弹窗选择归属部门后才能正常办理业务)
2. 文件上传的地方做了一个改动,如果上传文件的 hash 和已存在的附件相同,不会重复上传,会复用相同hash 的附件(要加一个字段,加字段脚本提供两个版本的 patch 脚本 mysql:根目录/sql/mysql/patch.sql dm:根目录/sql/dm/patch.sql )
This commit is contained in:
3
sql/dm/patch.sql
Normal file
3
sql/dm/patch.sql
Normal 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
3
sql/mysql/patch.sql
Normal 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);
|
||||||
@@ -19,7 +19,7 @@ public class BusinessDataPermissionConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() {
|
public DeptDataPermissionRuleCustomizer businessDeptDataPermissionRuleCustomizer() {
|
||||||
return rule -> {
|
return rule -> {
|
||||||
// dept
|
// dept
|
||||||
rule.addDeptColumn("demo_contract", "dept_id");
|
rule.addDeptColumn("demo_contract", "dept_id");
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class YudaoBusinessDataPermissionAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public DeptDataPermissionRule deptDataPermissionRule(PermissionCommonApi permissionApi, List<DeptDataPermissionRuleCustomizer> customizers) {
|
public DeptDataPermissionRule deptBusinessDataPermissionRule(PermissionCommonApi permissionApi, List<DeptDataPermissionRuleCustomizer> customizers) {
|
||||||
// Cloud 专属逻辑:优先使用本地的 PermissionApi 实现类,而不是 Feign 调用
|
// Cloud 专属逻辑:优先使用本地的 PermissionApi 实现类,而不是 Feign 调用
|
||||||
// 原因:在创建租户时,租户还没创建好,导致 Feign 调用获取数据权限时,报“租户不存在”的错误
|
// 原因:在创建租户时,租户还没创建好,导致 Feign 调用获取数据权限时,报“租户不存在”的错误
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
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.framework.security.core.util.SecurityFrameworkUtils.getLoginUserNickname;
|
||||||
import static cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils.writeAttachment;
|
import static cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils.writeAttachment;
|
||||||
|
|
||||||
@@ -125,21 +124,29 @@ public class CodegenController {
|
|||||||
|
|
||||||
@Operation(summary = "预览生成代码")
|
@Operation(summary = "预览生成代码")
|
||||||
@GetMapping("/preview")
|
@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')")
|
@PreAuthorize("@ss.hasPermission('infra:codegen:preview')")
|
||||||
public CommonResult<List<CodegenPreviewRespVO>> previewCodegen(@RequestParam("tableId") Long tableId) {
|
public CommonResult<List<CodegenPreviewRespVO>> previewCodegen(@RequestParam("tableId") Long tableId,
|
||||||
Map<String, String> codes = codegenService.generationCodes(tableId);
|
@RequestParam(value = "isBusiness", required = false, defaultValue = "false") Boolean isBusiness) {
|
||||||
|
Map<String, String> codes = codegenService.generationCodes(tableId, isBusiness);
|
||||||
return success(CodegenConvert.INSTANCE.convert(codes));
|
return success(CodegenConvert.INSTANCE.convert(codes));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "下载生成代码")
|
@Operation(summary = "下载生成代码")
|
||||||
@GetMapping("/download")
|
@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')")
|
@PreAuthorize("@ss.hasPermission('infra:codegen:download')")
|
||||||
public void downloadCodegen(@RequestParam("tableId") Long tableId,
|
public void downloadCodegen(@RequestParam("tableId") Long tableId,
|
||||||
|
@RequestParam(value = "isBusiness", required = false, defaultValue = "false") Boolean isBusiness,
|
||||||
HttpServletResponse response) throws IOException {
|
HttpServletResponse response) throws IOException {
|
||||||
// 生成代码
|
// 生成代码,传递 isBusiness
|
||||||
Map<String, String> codes = codegenService.generationCodes(tableId);
|
Map<String, String> codes = codegenService.generationCodes(tableId, isBusiness);
|
||||||
// 构建 zip 包
|
// 构建 zip 包
|
||||||
String[] paths = codes.keySet().toArray(new String[0]);
|
String[] paths = codes.keySet().toArray(new String[0]);
|
||||||
ByteArrayInputStream[] ins = codes.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new);
|
ByteArrayInputStream[] ins = codes.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import lombok.*;
|
|||||||
public class FileDO extends BaseDO {
|
public class FileDO extends BaseDO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编号,数据库自增
|
* 编号
|
||||||
*/
|
*/
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
private Long id;
|
private Long id;
|
||||||
@@ -57,4 +57,9 @@ public class FileDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private Integer size;
|
private Integer size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件哈希值(SHA-256)
|
||||||
|
*/
|
||||||
|
private String hash;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,4 +23,14 @@ public interface FileMapper extends BaseMapperX<FileDO> {
|
|||||||
.orderByDesc(FileDO::getId));
|
.orderByDesc(FileDO::getId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据哈希值查询文件
|
||||||
|
* @param hash 文件哈希值
|
||||||
|
* @return 文件DO,若不存在返回null
|
||||||
|
*/
|
||||||
|
default FileDO selectByHash(String hash) {
|
||||||
|
return selectOne(new LambdaQueryWrapperX<FileDO>()
|
||||||
|
.eq(FileDO::getHash, hash));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,17 @@ public interface CodegenService {
|
|||||||
* @param tableId 表编号
|
* @param tableId 表编号
|
||||||
* @return 生成结果。key 为文件路径,value 为对应的代码内容
|
* @return 生成结果。key 为文件路径,value 为对应的代码内容
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* 执行指定表的代码生成,支持业务基类继承
|
||||||
|
* @param tableId 表编号
|
||||||
|
* @param isBusiness 是否业务基类
|
||||||
|
* @return 生成结果
|
||||||
|
*/
|
||||||
|
Map<String, String> generationCodes(Long tableId, Boolean isBusiness);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 兼容原有接口,默认 isBusiness=false
|
||||||
|
*/
|
||||||
Map<String, String> generationCodes(Long tableId);
|
Map<String, String> generationCodes(Long tableId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -243,7 +243,10 @@ public class CodegenServiceImpl implements CodegenService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> generationCodes(Long tableId) {
|
/**
|
||||||
|
* 执行指定表的代码生成,支持业务基类继承
|
||||||
|
*/
|
||||||
|
public Map<String, String> generationCodes(Long tableId, Boolean isBusiness) {
|
||||||
// 校验是否已经存在
|
// 校验是否已经存在
|
||||||
CodegenTableDO table = codegenTableMapper.selectById(tableId);
|
CodegenTableDO table = codegenTableMapper.selectById(tableId);
|
||||||
if (table == null) {
|
if (table == null) {
|
||||||
@@ -275,8 +278,16 @@ public class CodegenServiceImpl implements CodegenService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 执行生成
|
// 执行生成,传递 isBusiness
|
||||||
return codegenEngine.execute(table, columns, subTables, subColumnsList);
|
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
|
@Override
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.hutool.core.map.MapUtil;
|
|||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
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.convert.codegen.CodegenConvert;
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO;
|
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO;
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO;
|
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} 的字段
|
* {@link cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO} 的字段
|
||||||
*/
|
*/
|
||||||
public static final Set<String> BASE_DO_FIELDS = new HashSet<>();
|
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 {
|
static {
|
||||||
Arrays.stream(ReflectUtil.getFields(BaseDO.class)).forEach(field -> BASE_DO_FIELDS.add(field.getName()));
|
Arrays.stream(ReflectUtil.getFields(BaseDO.class)).forEach(field -> BASE_DO_FIELDS.add(field.getName()));
|
||||||
BASE_DO_FIELDS.add(TENANT_ID_FIELD);
|
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 相关的字段
|
// 处理 OPERATION 相关的字段
|
||||||
CREATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
|
CREATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
|
||||||
UPDATE_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.addAll(BASE_DO_FIELDS);
|
||||||
LIST_OPERATION_EXCLUDE_COLUMN.remove("createTime"); // 创建时间,还是可能需要传递的
|
|
||||||
LIST_OPERATION_RESULT_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS);
|
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"); // 创建时间,还是需要返回的
|
LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("createTime"); // 创建时间,还是需要返回的
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user