DateOnly 的使用,以及解耦数据库

IRC_NewDev
hang 2024-09-26 14:22:04 +08:00
parent d0018a3ec3
commit 033c47435f
4 changed files with 36 additions and 15 deletions

View File

@ -4,8 +4,7 @@
{
public Guid? Id { get; set; }
public Guid DoctorId { get; set; }
public DateTime BeginDate { get; set; }
public DateTime EndDate { get; set; }
public string Degree { get; set; } = String.Empty;
public string Major { get; set; } = String.Empty;
public string Organization { get; set; } = String.Empty;
@ -20,13 +19,20 @@
public string ProvinceCN { get; set; } = String.Empty;
public string CityCN { get; set; } = String.Empty;
//public string BeginDate { get; set; }
//public string EndDate { get; set; }
public DateTime? BeginDate { get; set; }
public DateTime? EndDate { get; set; }
}
public class EducationInfoViewModel : EducationCommand
{
public DateTime? CreateTime { get; set; }
public string BeginDateStr => BeginDate.ToString("yyyy-MM");
public string EndDateStr => EndDate.ToString("yyyy-MM");
public string BeginDateStr => BeginDate?.ToString("yyyy-MM");
public string EndDateStr => EndDate?.ToString("yyyy-MM");
}
public class PostgraduateCommand
@ -34,9 +40,9 @@
public Guid? Id { get; set; }
public Guid DoctorId { get; set; }
public DateTime BeginDate { get; set; }
public DateTime? BeginDate { get; set; }
public DateTime EndDate { get; set; }
public DateTime? EndDate { get; set; }
public string Training { get; set; } = String.Empty;
@ -72,9 +78,10 @@
public class PostgraduateViewModel : PostgraduateCommand
{
public DateTime? CreateTime { get; set; }
public string BeginDateStr => BeginDate.ToString("yyyy-MM");
public string EndDateStr => EndDate.ToString("yyyy-MM");
public string BeginDateStr => BeginDate?.ToString("yyyy-MM");
public string EndDateStr => EndDate?.ToString("yyyy-MM");
}
public class DoctorEducationExperienceDTO
{

View File

@ -10,6 +10,23 @@ namespace IRaCIS.Core.Application.Service
{
public DoctorConfig()
{
// 从 DateTime 映射到 DateOnly
CreateMap<DateTime, DateOnly>().ConvertUsing(dt => DateOnly.FromDateTime(dt));
// 从 DateOnly 映射到 DateTime假设时间部分为 00:00:00
CreateMap<DateOnly, DateTime>().ConvertUsing(t => new DateTime(t.Year, t.Month, t.Day));
// 从 DateOnly? 映射到 DateTime?
CreateMap<DateOnly?, DateTime?>()
.ConvertUsing(t => t.HasValue ? new DateTime(t.Value.Year, t.Value.Month, t.Value.Day) : (DateTime?)null);
// 从 DateTime? 映射到 DateOnly?
CreateMap<DateTime?, DateOnly?>()
.ConvertUsing(dt => dt.HasValue ? DateOnly.FromDateTime(dt.Value) : (DateOnly?)null);
#region reviewer
//基本信息 工作信息 添加时转换使用
@ -38,7 +55,6 @@ namespace IRaCIS.Core.Application.Service
CreateMap<Education, EducationInfoViewModel>();
CreateMap<Vacation, VacationCommand>();
CreateMap<Education, EducationInfoViewModel>();
CreateMap<ResearchPublication, ResearchPublicationDTO>();
CreateMap<Postgraduate, PostgraduateViewModel>();
CreateMap<Attachment, AttachmentDTO>();

View File

@ -7,7 +7,7 @@ public class Education : BaseFullAuditEntity
#region 导航属性
#endregion
public DateTime? BeginDate { get; set; }
public DateOnly? BeginDate { get; set; }
public string City { get; set; } = null!;
@ -29,7 +29,7 @@ public class Education : BaseFullAuditEntity
public Guid DoctorId { get; set; }
public DateTime? EndDate { get; set; }
public DateOnly? EndDate { get; set; }
public string Major { get; set; } = null!;

View File

@ -10,11 +10,9 @@ public class Postgraduate : BaseFullAuditEntity
public Guid DoctorId { get; set; }
[Column(TypeName = "date")]
public DateTime? BeginDate { get; set; }
public DateOnly? BeginDate { get; set; }
[Column(TypeName = "date")]
public DateTime? EndDate { get; set; }
public DateOnly? EndDate { get; set; }
public string Training { get; set; } = string.Empty;