From f42213951fe191f71871b8f35c45c799c71387a3 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Jan 2026 13:47:18 +0000 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E5=BC=BA=E5=88=B6=E8=A6=86=E7=9B=96=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dictionary/Models/LabelOverrideDto.cs | 3 +- .../DictionaryLabelOverrideService.cs | 68 ++----------------- .../Dictionary/Enums/OverrideType.cs | 7 +- 3 files changed, 9 insertions(+), 69 deletions(-) diff --git a/src/Application/TakeoutSaaS.Application/Dictionary/Models/LabelOverrideDto.cs b/src/Application/TakeoutSaaS.Application/Dictionary/Models/LabelOverrideDto.cs index 39ab2a4..7a48697 100644 --- a/src/Application/TakeoutSaaS.Application/Dictionary/Models/LabelOverrideDto.cs +++ b/src/Application/TakeoutSaaS.Application/Dictionary/Models/LabelOverrideDto.cs @@ -53,7 +53,6 @@ public sealed class LabelOverrideDto public string OverrideTypeName => OverrideType switch { OverrideType.TenantCustomization => "租户定制", - OverrideType.PlatformEnforcement => "平台强制", _ => "未知" }; @@ -102,7 +101,7 @@ public sealed class UpsertLabelOverrideRequest public Dictionary OverrideValue { get; init; } = new(StringComparer.OrdinalIgnoreCase); /// - /// 覆盖原因/备注(平台强制覆盖时建议填写)。 + /// 覆盖原因/备注。 /// public string? Reason { get; init; } } diff --git a/src/Application/TakeoutSaaS.Application/Dictionary/Services/DictionaryLabelOverrideService.cs b/src/Application/TakeoutSaaS.Application/Dictionary/Services/DictionaryLabelOverrideService.cs index 4ab7183..8d3346c 100644 --- a/src/Application/TakeoutSaaS.Application/Dictionary/Services/DictionaryLabelOverrideService.cs +++ b/src/Application/TakeoutSaaS.Application/Dictionary/Services/DictionaryLabelOverrideService.cs @@ -72,12 +72,13 @@ public sealed class DictionaryLabelOverrideService( // 2. 查找现有覆盖或创建新记录 var existing = await overrideRepository.GetByItemIdAsync(tenantId, request.DictionaryItemId, cancellationToken); var now = DateTime.UtcNow; - + // 2.1 更新现有覆盖或创建新记录 if (existing != null) { - if (existing.OverrideType == OverrideType.PlatformEnforcement) + // 2.2 仅允许租户定制类型被租户修改,其他类型视为系统保留数据 + if (existing.OverrideType != OverrideType.TenantCustomization) { - throw new BusinessException(ErrorCodes.Forbidden, "平台强制覆盖不可由租户修改"); + throw new BusinessException(ErrorCodes.Forbidden, "该覆盖记录不允许由租户修改"); } existing.OverrideValue = DictionaryValueConverter.Serialize(request.OverrideValue); @@ -109,61 +110,6 @@ public sealed class DictionaryLabelOverrideService( return MapToDto(existing); } - /// - /// 创建或更新平台对租户字典的强制覆盖(平台强制)。 - /// - /// 目标租户 ID。 - /// 覆盖请求。 - /// 操作人 ID。 - /// 取消标记。 - public async Task UpsertPlatformOverrideAsync( - long targetTenantId, - UpsertLabelOverrideRequest request, - long operatorId, - CancellationToken cancellationToken = default) - { - // 1. 验证字典项存在 - var item = await itemRepository.GetByIdAsync(request.DictionaryItemId, cancellationToken); - if (item == null) - { - throw new BusinessException(ErrorCodes.NotFound, "字典项不存在"); - } - - // 2. 查找现有覆盖或创建新记录 - var existing = await overrideRepository.GetByItemIdAsync(targetTenantId, request.DictionaryItemId, cancellationToken); - var now = DateTime.UtcNow; - - if (existing != null) - { - existing.OverrideValue = DictionaryValueConverter.Serialize(request.OverrideValue); - existing.OverrideType = OverrideType.PlatformEnforcement; - existing.Reason = request.Reason; - existing.UpdatedAt = now; - existing.UpdatedBy = operatorId; - await overrideRepository.UpdateAsync(existing, cancellationToken); - } - else - { - existing = new DictionaryLabelOverride - { - TenantId = targetTenantId, - DictionaryItemId = request.DictionaryItemId, - OriginalValue = item.Value, - OverrideValue = DictionaryValueConverter.Serialize(request.OverrideValue), - OverrideType = OverrideType.PlatformEnforcement, - Reason = request.Reason, - CreatedAt = now, - CreatedBy = operatorId - }; - await overrideRepository.AddAsync(existing, cancellationToken); - } - - await overrideRepository.SaveChangesAsync(cancellationToken); - - existing.DictionaryItem = item; - return MapToDto(existing); - } - /// /// 删除覆盖配置。 /// @@ -175,7 +121,6 @@ public sealed class DictionaryLabelOverrideService( long tenantId, long dictionaryItemId, long operatorId, - bool allowPlatformEnforcement = true, CancellationToken cancellationToken = default) { var existing = await overrideRepository.GetByItemIdAsync(tenantId, dictionaryItemId, cancellationToken); @@ -184,9 +129,10 @@ public sealed class DictionaryLabelOverrideService( return false; } - if (!allowPlatformEnforcement && existing.OverrideType == OverrideType.PlatformEnforcement) + // 1. (空行后) 仅允许删除租户定制类型,其他类型视为系统保留数据 + if (existing.OverrideType != OverrideType.TenantCustomization) { - throw new BusinessException(ErrorCodes.Forbidden, "平台强制覆盖不可由租户删除"); + throw new BusinessException(ErrorCodes.Forbidden, "该覆盖记录不允许由租户删除"); } existing.DeletedBy = operatorId; diff --git a/src/Domain/TakeoutSaaS.Domain/Dictionary/Enums/OverrideType.cs b/src/Domain/TakeoutSaaS.Domain/Dictionary/Enums/OverrideType.cs index f235a03..c5c8dc3 100644 --- a/src/Domain/TakeoutSaaS.Domain/Dictionary/Enums/OverrideType.cs +++ b/src/Domain/TakeoutSaaS.Domain/Dictionary/Enums/OverrideType.cs @@ -8,10 +8,5 @@ public enum OverrideType /// /// 租户定制:租户覆盖系统字典的显示值。 /// - TenantCustomization = 1, - - /// - /// 平台强制:平台管理员强制修正租户字典的显示值。 - /// - PlatformEnforcement = 2 + TenantCustomization = 1 }