From 11520d014b69ccd9375db02705df60c6143f6e98 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Fri, 3 Jul 2026 17:47:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20DataScopeContext=20=E7=BC=93=E5=AD=98=20JS?= =?UTF-8?q?ON=20=E5=8F=8D=E5=BA=8F=E5=88=97=E5=8C=96=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 IReadOnlySet/IReadOnlyList 改为 HashSet/List 等可序列化类型;缓存读取失败时自动重建。 Co-authored-by: Cursor --- src/Oms.Application/DataPerm/DataScopeModels.cs | 10 +++++----- .../DataPerm/EffectiveScopeBuilder.cs | 12 ++++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Oms.Application/DataPerm/DataScopeModels.cs b/src/Oms.Application/DataPerm/DataScopeModels.cs index cde9293..2e24d90 100644 --- a/src/Oms.Application/DataPerm/DataScopeModels.cs +++ b/src/Oms.Application/DataPerm/DataScopeModels.cs @@ -14,17 +14,17 @@ public sealed class DataScopeContext public string DataResourceCode { get; init; } = string.Empty; - public IReadOnlySet OrganizationIds { get; init; } = new HashSet(); + public HashSet OrganizationIds { get; init; } = []; public int DataScope { get; init; } = DataPermConstants.DataScopePersonal; - public IReadOnlyList ResolvedOwnerIds { get; init; } = []; + public List ResolvedOwnerIds { get; init; } = []; - public IReadOnlyDictionary? BizFilters { get; init; } + public Dictionary? BizFilters { get; init; } - public IReadOnlySet SecretLevels { get; init; } = new HashSet(DataPermConstants.DefaultSecretLevels); + public HashSet SecretLevels { get; init; } = [.. DataPermConstants.DefaultSecretLevels]; - public IReadOnlyList CustomFilters { get; init; } = []; + public List CustomFilters { get; init; } = []; } public sealed class CompiledFilter diff --git a/src/Oms.Application/DataPerm/EffectiveScopeBuilder.cs b/src/Oms.Application/DataPerm/EffectiveScopeBuilder.cs index a7d0fba..d0da508 100644 --- a/src/Oms.Application/DataPerm/EffectiveScopeBuilder.cs +++ b/src/Oms.Application/DataPerm/EffectiveScopeBuilder.cs @@ -22,7 +22,15 @@ public class DataPermContextCache(IDistributedCache cache) : IScopedDependency return null; } - return JsonSerializer.Deserialize(bytes, JsonOptions); + try + { + return JsonSerializer.Deserialize(bytes, JsonOptions); + } + catch (JsonException) + { + // 旧缓存或类型变更导致反序列化失败时重建 + return null; + } } public Task SetAsync(DataScopeContext context, CancellationToken cancellationToken = default) @@ -212,7 +220,7 @@ public class EffectiveScopeBuilder(DataPermRepository repository, DataPermContex }) .ToList(); - IReadOnlyList resolvedOwnerIds = []; + List resolvedOwnerIds = []; if (dataScope is DataPermConstants.DataScopeTeam or DataPermConstants.DataScopeDepartment) { if (user.OrganizationId is not { } ownerOrg || ownerOrg == Guid.Empty)