using System.ComponentModel.DataAnnotations; using System.Text.RegularExpressions; using Dlhis.Basic.Organization.Dto; using Dlhis.Entity.Basic.Enums; using Kurisu.AspNetCore.Utils.Extensions; namespace Dlhis.Basic.Organization.Request; public class GainfoOutsourceRequest : IValidatableObject { public long? Id { get; set; } /// /// 姓名 /// [Required(ErrorMessage = "姓名不可为空")] public string Name { get; set; } /// /// 工号 /// public string Code { get; set; } /// /// 证件号 /// [Required(ErrorMessage = "证件号不可为空")] public string IdNo { get; set; } /// /// 性别 GenderEnumType /// public GenderEnumType Gender { get; set; } /// /// 出生日期 /// public DateTime? Birthday { get; set; } /// /// 手机号码 /// [Required(ErrorMessage = "手机号不可为空")] public string Phone { get; set; } /// /// 厂区 /// [Required(ErrorMessage = "厂区不可为空")] public string Factory { get; set; } /// /// 入职日期 /// public DateTime EntryDate { get; set; } /// /// 离职日期 /// public DateTime? ResignationDate { get; set; } /// /// 备注 /// public string Remark { get; set; } /// /// 额外信息 /// [Required] public GainfoOutSourceExternalInfoDto ExternalInfo { get; set; } /// public IEnumerable Validate(ValidationContext validationContext) { if (Code == ExternalInfo.SapCode) { yield return new ValidationResult("工号和对接人工号不可相同", new[] { nameof(Code) }); } const string containChineseRule = "[\u4e00-\u9fa5]"; if (Code.IsPresent()) { if (Regex.IsMatch(Code, containChineseRule)) { yield return new ValidationResult($"工号[{Code}]不能包含中文", new[] { nameof(Code) }); } if (!Id.HasValue && Code.StartsWith("LS")) { yield return new ValidationResult($"工号[{Code}]不能以LS开头", new[] { nameof(Code) }); } } } }