refactor(AdminPermissionService): 优化权限和角色编码重复校验逻辑

1.  将链式查询拆分为分步Where调用,使用WhereIF简化条件判断
2.  修复空值处理问题,使用id!.Value替代原值访问
3.  新增数据库菜单初始化脚本,补充Dockerfile和dotnet工具配置
This commit is contained in:
glz
2026-07-06 17:45:42 +08:00
parent a04b4be7e5
commit 2deb0279bb
5 changed files with 161 additions and 3 deletions

View File

@ -310,7 +310,9 @@ public class AdminPermissionService(
var code = input.Code.Trim();
var codeExists = await adminMenuRepository.Queryable()
.AnyAsync(x => x.Code == code && !x.IsDeleted && (!id.HasValue || x.Id != id.Value));
.Where(x => x.Code == code && !x.IsDeleted)
.WhereIF(id.HasValue, x => x.Id != id!.Value)
.AnyAsync();
BusinessException.ThrowIf(codeExists, "权限编码已存在", ResultCode.CONFLICT);
}
@ -321,7 +323,9 @@ public class AdminPermissionService(
var code = input.Code.Trim();
var codeExists = await adminRoleRepository.Queryable()
.AnyAsync(x => x.Code == code && !x.IsDeleted && (!id.HasValue || x.Id != id.Value));
.Where(x => x.Code == code && !x.IsDeleted)
.WhereIF(id.HasValue, x => x.Id != id!.Value)
.AnyAsync();
BusinessException.ThrowIf(codeExists, "角色编码已存在", ResultCode.CONFLICT);
await ValidateMenuIdsAsync(input.MenuIds);