diff --git a/SimpleAdmin.Application/Services/Onboarding/PublicTask/OnboardingEmployeeInfoValidator.cs b/SimpleAdmin.Application/Services/Onboarding/PublicTask/OnboardingEmployeeInfoValidator.cs index 20733ff..b5f0271 100644 --- a/SimpleAdmin.Application/Services/Onboarding/PublicTask/OnboardingEmployeeInfoValidator.cs +++ b/SimpleAdmin.Application/Services/Onboarding/PublicTask/OnboardingEmployeeInfoValidator.cs @@ -229,7 +229,7 @@ internal static class OnboardingEmployeeInfoValidator GetRequiredRowValue(row, "location", rowNumber, "教育经历", "学校或机构"); GetRequiredRowValue(row, "content", rowNumber, "教育经历", "专业或学习内容"); GetRequiredRowValue(row, "result", rowNumber, "教育经历", "结果或学位"); - }); + }, requireAtLeastOne: true, emptyErrorMessage: "请至少添加一条教育学习经历"); } private static void ValidateWorkHistory(string json) @@ -240,7 +240,7 @@ internal static class OnboardingEmployeeInfoValidator GetRequiredRowValue(row, "companyName", rowNumber, "工作经历", "工作单位"); GetRequiredRowValue(row, "position", rowNumber, "工作经历", "担任职务"); GetRequiredRowValue(row, "leaveReason", rowNumber, "工作经历", "离职原因"); - }); + }, requireAtLeastOne: true, emptyErrorMessage: "请至少添加一条工作经历(应届生可填写兼职、在校或实习经历)"); } private static void ValidateFamilyMembers(string json) @@ -261,16 +261,22 @@ internal static class OnboardingEmployeeInfoValidator "^(1[3-9]\\d{9}|0\\d{2,3}-?\\d{7,8})$"); if (!phoneIsValid) throw Oops.Bah($"第 {rowNumber} 条家庭成员的联系电话格式不正确"); - }); + }, requireAtLeastOne: true, emptyErrorMessage: "请至少添加一位家庭成员信息"); } private static void ValidateHistoryRows( string json, string fieldName, - Action validateRow) + Action validateRow, + bool requireAtLeastOne = false, + string emptyErrorMessage = null) { if (string.IsNullOrWhiteSpace(json)) + { + if (requireAtLeastOne) + throw Oops.Bah(emptyErrorMessage ?? $"请至少添加一条{fieldName}"); return; + } try { @@ -287,6 +293,11 @@ internal static class OnboardingEmployeeInfoValidator validateRow(row, rowNumber); } + + if (requireAtLeastOne && rowNumber == 0) + { + throw Oops.Bah(emptyErrorMessage ?? $"请至少添加一条{fieldName}"); + } } catch (global::System.Text.Json.JsonException) {