代码优化

This commit is contained in:
fuenmao
2026-08-27 11:09:20 +08:00
parent 658869b3a7
commit ae8167a566
46 changed files with 2051 additions and 204 deletions
@@ -128,6 +128,8 @@ public class OnboardingPublicTaskService : IOnboardingPublicTaskService
throw Oops.Bah("当前任务不可编辑");
}
ValidateEmployeeInfo(input);
var old = await _db.Queryable<ObTaskEmployeeInfo>()
.FirstAsync(item => item.TaskId == task.Id);
var entity = input.Adapt<ObTaskEmployeeInfo>();
@@ -161,6 +163,46 @@ public class OnboardingPublicTaskService : IOnboardingPublicTaskService
await _snapshotService.Build(task.Id, entity, invalidateGeneratedPreview: true);
}
/// <summary>
/// 校验候选人核心身份信息,避免非法格式进入合同和正式员工档案。
/// </summary>
private static void ValidateEmployeeInfo(OnboardingTaskPublicSaveInput input)
{
input.EmployeeName = input.EmployeeName?.Trim();
input.Phone = input.Phone?.Trim();
input.IdCardNumber = input.IdCardNumber?.Trim().ToUpperInvariant();
if (string.IsNullOrWhiteSpace(input.EmployeeName) || input.EmployeeName.Length > 100)
throw Oops.Bah("员工姓名不能为空且不能超过 100 个字符");
if (!global::System.Text.RegularExpressions.Regex.IsMatch(
input.Phone ?? string.Empty,
"^1[3-9]\\d{9}$"))
{
throw Oops.Bah("请输入正确的 11 位手机号码");
}
if (!global::System.Text.RegularExpressions.Regex.IsMatch(
input.IdCardNumber ?? string.Empty,
"^\\d{17}[0-9X]$"))
{
throw Oops.Bah("请输入正确的 18 位身份证号码");
}
if (string.IsNullOrWhiteSpace(input.CustomVariablesJson))
return;
try
{
using var document = global::System.Text.Json.JsonDocument.Parse(input.CustomVariablesJson);
if (document.RootElement.ValueKind != global::System.Text.Json.JsonValueKind.Object)
throw new global::System.Text.Json.JsonException();
}
catch (global::System.Text.Json.JsonException)
{
throw Oops.Bah("员工补充变量格式不正确,请刷新页面后重新填写");
}
}
/// <summary>
/// 根据员工当前已填写信息校验变量并提前生成合同 DOCX。
/// </summary>