相关问题修复

This commit is contained in:
fuenmao
2026-09-18 20:44:57 +08:00
parent c42d82d100
commit ff7e9c1496
3 changed files with 4 additions and 102 deletions
@@ -1,64 +0,0 @@
namespace SimpleAdmin.Application;
/// <summary>
/// 解析入职审核人系统配置,统一支持全局审核人和公司专属审核人。
/// </summary>
internal static class OnboardingReviewerConfigParser
{
private const string ConfigKey = "onboard.reviewer.userIds";
/// <summary>
/// 获取指定公司的全部有效审核人用户 Id。
/// </summary>
public static HashSet<long> Parse(string configValue, long companyId)
{
if (string.IsNullOrWhiteSpace(configValue))
throw Oops.Bah($"系统配置 {ConfigKey} 不能为空");
try
{
using var document = global::System.Text.Json.JsonDocument.Parse(configValue);
if (document.RootElement.ValueKind != global::System.Text.Json.JsonValueKind.Object)
throw new global::System.Text.Json.JsonException();
var reviewerIds = new HashSet<long>();
if (document.RootElement.TryGetProperty("all", out var allReviewers))
AddReviewers(allReviewers, reviewerIds);
if (document.RootElement.TryGetProperty("company", out var companyReviewers))
{
if (companyReviewers.ValueKind != global::System.Text.Json.JsonValueKind.Object)
throw new global::System.Text.Json.JsonException();
if (companyReviewers.TryGetProperty(companyId.ToString(), out var reviewers))
AddReviewers(reviewers, reviewerIds);
}
return reviewerIds;
}
catch (global::System.Text.Json.JsonException)
{
throw Oops.Bah(
$"系统配置 {ConfigKey} 格式不正确,应为包含 all 数组和 company 对象的 JSON");
}
}
/// <summary>
/// 将 JSON 数组中的审核人 Id 加入集合,并拒绝非整数配置。
/// </summary>
private static void AddReviewers(
global::System.Text.Json.JsonElement element,
HashSet<long> reviewerIds)
{
if (element.ValueKind != global::System.Text.Json.JsonValueKind.Array)
throw new global::System.Text.Json.JsonException();
foreach (var reviewer in element.EnumerateArray())
{
if (!reviewer.TryGetInt64(out var reviewerId) || reviewerId <= 0)
throw new global::System.Text.Json.JsonException();
reviewerIds.Add(reviewerId);
}
}
}