From 033c47435f0e23460ba3b752ac1b9e2de27405f6 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 26 Sep 2024 14:22:04 +0800 Subject: [PATCH] =?UTF-8?q?DateOnly=20=E7=9A=84=E4=BD=BF=E7=94=A8=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E8=A7=A3=E8=80=A6=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Doctor/DTO/EducationModel.cs | 23 ++++++++++++------- .../Service/Doctor/_MapConfig.cs | 18 ++++++++++++++- IRaCIS.Core.Domain/Dcotor/Education.cs | 4 ++-- IRaCIS.Core.Domain/Dcotor/Postgraduate.cs | 6 ++--- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Doctor/DTO/EducationModel.cs b/IRaCIS.Core.Application/Service/Doctor/DTO/EducationModel.cs index 470e389d9..913cbdde6 100644 --- a/IRaCIS.Core.Application/Service/Doctor/DTO/EducationModel.cs +++ b/IRaCIS.Core.Application/Service/Doctor/DTO/EducationModel.cs @@ -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 { diff --git a/IRaCIS.Core.Application/Service/Doctor/_MapConfig.cs b/IRaCIS.Core.Application/Service/Doctor/_MapConfig.cs index c841db91e..da118fc36 100644 --- a/IRaCIS.Core.Application/Service/Doctor/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Doctor/_MapConfig.cs @@ -10,6 +10,23 @@ namespace IRaCIS.Core.Application.Service { public DoctorConfig() { + + // 从 DateTime 映射到 DateOnly + CreateMap().ConvertUsing(dt => DateOnly.FromDateTime(dt)); + + // 从 DateOnly 映射到 DateTime,假设时间部分为 00:00:00 + + CreateMap().ConvertUsing(t => new DateTime(t.Year, t.Month, t.Day)); + + // 从 DateOnly? 映射到 DateTime? + CreateMap() + .ConvertUsing(t => t.HasValue ? new DateTime(t.Value.Year, t.Value.Month, t.Value.Day) : (DateTime?)null); + + // 从 DateTime? 映射到 DateOnly? + CreateMap() + .ConvertUsing(dt => dt.HasValue ? DateOnly.FromDateTime(dt.Value) : (DateOnly?)null); + + #region reviewer //基本信息 工作信息 添加时转换使用 @@ -38,7 +55,6 @@ namespace IRaCIS.Core.Application.Service CreateMap(); CreateMap(); - CreateMap(); CreateMap(); CreateMap(); CreateMap(); diff --git a/IRaCIS.Core.Domain/Dcotor/Education.cs b/IRaCIS.Core.Domain/Dcotor/Education.cs index c0f857db9..76d890f63 100644 --- a/IRaCIS.Core.Domain/Dcotor/Education.cs +++ b/IRaCIS.Core.Domain/Dcotor/Education.cs @@ -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!; diff --git a/IRaCIS.Core.Domain/Dcotor/Postgraduate.cs b/IRaCIS.Core.Domain/Dcotor/Postgraduate.cs index c52942813..e703f9070 100644 --- a/IRaCIS.Core.Domain/Dcotor/Postgraduate.cs +++ b/IRaCIS.Core.Domain/Dcotor/Postgraduate.cs @@ -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;