相关问题修复

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
@@ -6,19 +6,16 @@ namespace SimpleAdmin.Application;
public class OnboardingAuditService : IOnboardingAuditService
{
private readonly SqlSugarScope _db;
private readonly IConfigService _config;
private readonly IOnboardingContractSnapshotService _snapshotService;
private readonly IOnboardingEmployeeContractSnapshotService _employeeContractSnapshotService;
private readonly IOnboardingDataPermissionService _dataPermission;
public OnboardingAuditService(
IConfigService config,
IOnboardingContractSnapshotService snapshotService,
IOnboardingEmployeeContractSnapshotService employeeContractSnapshotService,
IOnboardingDataPermissionService dataPermission)
{
_db = DbContext.DB;
_config = config;
_snapshotService = snapshotService;
_employeeContractSnapshotService = employeeContractSnapshotService;
_dataPermission = dataPermission;
@@ -137,11 +134,8 @@ public class OnboardingAuditService : IOnboardingAuditService
if (task.CreateUserId.HasValue && task.CreateUserId != UserManager.UserId)
{
await _db.Updateable<ObEmployee>()
.SetColumns(item => new ObEmployee
{
CreateUserId = task.CreateUserId,
CreateUser = task.CreateUser
})
.SetColumns(item => item.CreateUserId == task.CreateUserId)
.SetColumns(item => item.CreateUser == task.CreateUser)
.Where(item => item.Id == employee.Id)
.ExecuteCommandAsync();
@@ -227,20 +221,6 @@ public class OnboardingAuditService : IOnboardingAuditService
OnboardingPermissionCodes.TaskManageAll,
"入职任务");
// 人事管理员/超级管理员可处理全部任务;普通人事还必须属于配置的审核人。
if (await _dataPermission.CanManage(null, OnboardingPermissionCodes.TaskManageAll))
return task;
var config = await _config.GetByConfigKey(CateGoryConst.CONFIG_BIZ_DEFINE, "onboard.reviewer.userIds")
?? throw Oops.Bah("请配置入职审核人");
// 审核人由全局配置与公司专属配置合并得出,不依赖独立业务表。
var reviewerIds = OnboardingReviewerConfigParser.Parse(config.ConfigValue, task.CompanyId);
if (!reviewerIds.Contains(UserManager.UserId))
{
throw Oops.Bah("您不是该入职任务的审核人");
}
return task;
}
@@ -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);
}
}
}
@@ -6,15 +6,12 @@ namespace SimpleAdmin.Application;
public class OnboardingMaterialReviewService : IOnboardingMaterialReviewService
{
private readonly SqlSugarScope _db;
private readonly IConfigService _config;
private readonly IOnboardingDataPermissionService _dataPermission;
public OnboardingMaterialReviewService(
IConfigService config,
IOnboardingDataPermissionService dataPermission)
{
_db = DbContext.DB;
_config = config;
_dataPermission = dataPermission;
}
@@ -55,22 +52,11 @@ public class OnboardingMaterialReviewService : IOnboardingMaterialReviewService
await _db.Updateable(material).ExecuteCommandAsync();
}
private async Task EnsureReviewer(ObOnboardingTask task)
private Task EnsureReviewer(ObOnboardingTask task)
{
await _dataPermission.EnsureCanManage(
return _dataPermission.EnsureCanManage(
task.CreateUserId,
OnboardingPermissionCodes.TaskManageAll,
"入职任务");
if (await _dataPermission.CanManage(null, OnboardingPermissionCodes.TaskManageAll))
return;
var config = await _config.GetByConfigKey(CateGoryConst.CONFIG_BIZ_DEFINE, "onboard.reviewer.userIds")
?? throw Oops.Bah("请配置入职审核人");
var reviewerIds = OnboardingReviewerConfigParser.Parse(config.ConfigValue, task.CompanyId);
if (!reviewerIds.Contains(UserManager.UserId))
{
throw Oops.Bah("您不是该入职任务的审核人");
}
}
}