refactor: 移除字典强制覆盖能力
This commit is contained in:
@@ -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<string, string> OverrideValue { get; init; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// 覆盖原因/备注(平台强制覆盖时建议填写)。
|
||||
/// 覆盖原因/备注。
|
||||
/// </summary>
|
||||
public string? Reason { get; init; }
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建或更新平台对租户字典的强制覆盖(平台强制)。
|
||||
/// </summary>
|
||||
/// <param name="targetTenantId">目标租户 ID。</param>
|
||||
/// <param name="request">覆盖请求。</param>
|
||||
/// <param name="operatorId">操作人 ID。</param>
|
||||
/// <param name="cancellationToken">取消标记。</param>
|
||||
public async Task<LabelOverrideDto> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除覆盖配置。
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
|
||||
@@ -8,10 +8,5 @@ public enum OverrideType
|
||||
/// <summary>
|
||||
/// 租户定制:租户覆盖系统字典的显示值。
|
||||
/// </summary>
|
||||
TenantCustomization = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 平台强制:平台管理员强制修正租户字典的显示值。
|
||||
/// </summary>
|
||||
PlatformEnforcement = 2
|
||||
TenantCustomization = 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user