修复相关bug
This commit is contained in:
+54
-10
@@ -16,9 +16,11 @@ internal static class OnboardingEmployeeInfoValidator
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 规范化文本,并校验固定登记表字段的格式。
|
||||
/// 规范化文本,并按照任务冻结配置校验固定登记表必填项及字段格式。
|
||||
/// </summary>
|
||||
public static void ValidateAndNormalize(ObTaskEmployeeInfo input)
|
||||
public static void ValidateAndNormalize(
|
||||
ObTaskEmployeeInfo input,
|
||||
IReadOnlyCollection<ObTaskFormRequirement> fieldRequirements = null)
|
||||
{
|
||||
input.EmployeeName = input.EmployeeName?.Trim();
|
||||
input.Phone = input.Phone?.Trim();
|
||||
@@ -26,20 +28,27 @@ internal static class OnboardingEmployeeInfoValidator
|
||||
input.IdCardNumber = input.IdCardNumber?.Trim().ToUpperInvariant();
|
||||
input.BankCardNumber = global::System.Text.RegularExpressions.Regex.Replace(
|
||||
input.BankCardNumber ?? string.Empty,
|
||||
"[\\s-]",
|
||||
@"[\s-]",
|
||||
string.Empty);
|
||||
input.BankName = input.BankName?.Trim();
|
||||
input.BankAccountName = input.EmployeeName;
|
||||
|
||||
ValidateRequiredFields(input, fieldRequirements);
|
||||
|
||||
// 电子签约实名认证始终依赖以下三项,不能通过后台配置关闭。
|
||||
if (string.IsNullOrWhiteSpace(input.EmployeeName) || input.EmployeeName.Length > 100)
|
||||
throw Oops.Bah("员工姓名不能为空且不能超过 100 个字符");
|
||||
|
||||
if (input.Gender != "男" && input.Gender != "女")
|
||||
if (!string.IsNullOrWhiteSpace(input.Gender)
|
||||
&& input.Gender != "男"
|
||||
&& input.Gender != "女")
|
||||
{
|
||||
throw Oops.Bah("请选择正确的性别");
|
||||
}
|
||||
|
||||
if (!global::System.Text.RegularExpressions.Regex.IsMatch(
|
||||
input.Phone ?? string.Empty,
|
||||
"^1[3-9]\\d{9}$"))
|
||||
@"^1[3-9]\d{9}$"))
|
||||
{
|
||||
throw Oops.Bah("请输入正确的 11 位手机号码");
|
||||
}
|
||||
@@ -51,10 +60,11 @@ internal static class OnboardingEmployeeInfoValidator
|
||||
ValidateOptionalEmail(input.Email);
|
||||
ValidateOptionalNumber(input.Height, "身高", 100M, 250M, "厘米");
|
||||
ValidateOptionalNumber(input.Weight, "体重", 30M, 300M, "公斤");
|
||||
ValidateBankCard(input.BankCardNumber);
|
||||
if (!string.IsNullOrWhiteSpace(input.BankCardNumber))
|
||||
ValidateBankCard(input.BankCardNumber);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.BankName) || input.BankName.Length > 100)
|
||||
throw Oops.Bah("开户银行名称不能为空且不能超过 100 个字符");
|
||||
if (!string.IsNullOrWhiteSpace(input.BankName) && input.BankName.Length > 100)
|
||||
throw Oops.Bah("开户银行名称不能超过 100 个字符");
|
||||
|
||||
ValidateOptionalContactPhone(input.EmergencyPhone);
|
||||
ValidateEducationHistory(input.EducationHistoryJson);
|
||||
@@ -63,6 +73,40 @@ internal static class OnboardingEmployeeInfoValidator
|
||||
ValidateJson(input.CustomVariablesJson, global::System.Text.Json.JsonValueKind.Object, "员工补充变量");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按任务快照校验后台配置为必填的内置员工字段。
|
||||
/// </summary>
|
||||
private static void ValidateRequiredFields(
|
||||
ObTaskEmployeeInfo input,
|
||||
IReadOnlyCollection<ObTaskFormRequirement> fieldRequirements)
|
||||
{
|
||||
if (fieldRequirements == null || fieldRequirements.Count == 0)
|
||||
return;
|
||||
|
||||
foreach (var requirement in fieldRequirements.Where(item =>
|
||||
item.Required
|
||||
&& OnboardingEmployeeFieldRequirementSnapshot.IsEmployeeField(item)))
|
||||
{
|
||||
var separatorIndex = requirement.FieldCode.LastIndexOf('.');
|
||||
var propertyName = separatorIndex >= 0
|
||||
? requirement.FieldCode[(separatorIndex + 1)..]
|
||||
: requirement.FieldCode;
|
||||
var property = typeof(ObTaskEmployeeInfo).GetProperty(
|
||||
propertyName,
|
||||
global::System.Reflection.BindingFlags.Instance
|
||||
| global::System.Reflection.BindingFlags.Public
|
||||
| global::System.Reflection.BindingFlags.IgnoreCase);
|
||||
if (property == null)
|
||||
{
|
||||
throw Oops.Bah(
|
||||
$"内置员工变量“{requirement.FieldCode}”没有对应的入职登记表字段,请联系管理员");
|
||||
}
|
||||
|
||||
var value = property.GetValue(input)?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
throw Oops.Bah($"请填写入职登记表“{requirement.FieldName}”");
|
||||
}
|
||||
}
|
||||
private static bool TryValidateIdCard(
|
||||
string idCardNumber,
|
||||
out DateTime birthday,
|
||||
@@ -106,7 +150,7 @@ internal static class OnboardingEmployeeInfoValidator
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void ValidateBirthday(string birthdayText, DateTime idCardBirthday)
|
||||
private static void ValidateBirthday(string birthdayText, DateTime? idCardBirthday)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(birthdayText))
|
||||
return;
|
||||
@@ -120,7 +164,7 @@ internal static class OnboardingEmployeeInfoValidator
|
||||
if (!birthdayIsValid || birthday.Date > DateTime.Today)
|
||||
throw Oops.Bah("请输入正确的出生日期");
|
||||
|
||||
if (birthday.Date != idCardBirthday.Date)
|
||||
if (idCardBirthday.HasValue && birthday.Date != idCardBirthday.Value.Date)
|
||||
throw Oops.Bah("出生日期与身份证号码不一致");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user