diff --git a/src/Shentun.Peis.Domain/EntityHelper.cs b/src/Shentun.Peis.Domain/EntityHelper.cs index 9a4e2f0..4f939f8 100644 --- a/src/Shentun.Peis.Domain/EntityHelper.cs +++ b/src/Shentun.Peis.Domain/EntityHelper.cs @@ -1,14 +1,16 @@ -using System; +using Shentun.Peis.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; namespace Shentun.Peis { - public class EntityHelper + internal class EntityHelper { /// /// 创建最大显示顺序 @@ -22,5 +24,36 @@ namespace Shentun.Peis int? maxDisplayOrder = await repository.MaxAsync(o => (int?)o.DisplayOrder); return (maxDisplayOrder ?? 0) + 1; } + /// + /// 检查同名 + /// + /// + /// + /// + /// + /// + /// + /// + public static async Task CheckSameName(IRepository repository,string name, TEntity updatedEntity = null) + where TEntity : class, IEntity, IDisplayName + { + Check.NotNullOrWhiteSpace(name, nameof(name)); + TEntity existEntity; + + if (updatedEntity == null) + { + existEntity = await repository.FindAsync(o => o.DisplayName == name); + } + else + { + existEntity = await repository.FindAsync(o => o.Id.ToString() != updatedEntity.Id.ToString() && o.DisplayName == name); + } + + + if (existEntity != null) + { + throw new UserFriendlyException($"名称:'{name}'已存在"); + } + } } } diff --git a/src/Shentun.Peis.Domain/GuideTypes/GuideTypeManager.cs b/src/Shentun.Peis.Domain/GuideTypes/GuideTypeManager.cs index 5e023b8..00c1579 100644 --- a/src/Shentun.Peis.Domain/GuideTypes/GuideTypeManager.cs +++ b/src/Shentun.Peis.Domain/GuideTypes/GuideTypeManager.cs @@ -30,7 +30,7 @@ namespace Shentun.Peis.GuidTypes ) { Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName)); - await CheckSameName(entity.DisplayName); + await EntityHelper.CheckSameName(_repository, entity.DisplayName); return new GuideType( GuidGenerator.Create() ) @@ -54,7 +54,8 @@ namespace Shentun.Peis.GuidTypes Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName)); if(sourceEntity.DisplayName != targetEntity.DisplayName) { - await CheckSameName(sourceEntity.DisplayName, targetEntity); + + await EntityHelper.CheckSameName(_repository, sourceEntity.DisplayName, targetEntity); targetEntity.DisplayName = sourceEntity.DisplayName; targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.DisplayName); } @@ -66,30 +67,6 @@ namespace Shentun.Peis.GuidTypes } - /// - /// 检查同名 - /// - /// - /// - /// - /// - private async Task CheckSameName(string name,GuideType updatedEntity = null) - { - Check.NotNullOrWhiteSpace(name, nameof(name)); - GuideType existEntity; - if (updatedEntity== null) - { - existEntity = await _repository.FindAsync(o => o.DisplayName == name); - } - else - { - existEntity = await _repository.FindAsync(o => o.Id != updatedEntity.Id && o.DisplayName == name); - } - - if (existEntity != null) - { - throw new UserFriendlyException($"名称:'{name}'已存在"); - } - } + } } diff --git a/src/Shentun.Peis.Domain/IDisplayName.cs b/src/Shentun.Peis.Domain/IDisplayName.cs new file mode 100644 index 0000000..149386d --- /dev/null +++ b/src/Shentun.Peis.Domain/IDisplayName.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shentun.Peis +{ + internal interface IDisplayName + { + string DisplayName { get; set; } + } +} diff --git a/src/Shentun.Peis.Domain/IDisplayOrder.cs b/src/Shentun.Peis.Domain/IDisplayOrder.cs index 0ca55d4..0f0bb07 100644 --- a/src/Shentun.Peis.Domain/IDisplayOrder.cs +++ b/src/Shentun.Peis.Domain/IDisplayOrder.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Shentun.Peis { - public interface IDisplayOrder + internal interface IDisplayOrder { int DisplayOrder { get; set; } } diff --git a/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs b/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs index 7de6c8f..94994ac 100644 --- a/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs +++ b/src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs @@ -29,7 +29,7 @@ namespace Shentun.Peis.ItemTypes { CheckNotNull(entity); - await CheckSameName(entity.DisplayName); + await EntityHelper.CheckSameName(_repository, entity.DisplayName); return new ItemType( GuidGenerator.Create() ) @@ -53,7 +53,7 @@ namespace Shentun.Peis.ItemTypes if (sourceEntity.DisplayName != targetEntity.DisplayName) { - await CheckSameName(sourceEntity.DisplayName, targetEntity); + await EntityHelper.CheckSameName(_repository, sourceEntity.DisplayName, targetEntity); targetEntity.DisplayName = sourceEntity.DisplayName; //targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.ItemTypeName); } @@ -66,30 +66,9 @@ namespace Shentun.Peis.ItemTypes } /// - /// 检查同名 + /// 检查空值 /// - /// - /// - /// - /// - private async Task CheckSameName(string name, ItemType updatedEntity = null) - { - Check.NotNullOrWhiteSpace(name, nameof(name)); - ItemType existEntity; - if (updatedEntity == null) - { - existEntity = await _repository.FindAsync(o => o.DisplayName == name); - } - else - { - existEntity = await _repository.FindAsync(o => o.Id != updatedEntity.Id && o.DisplayName == name); - } - - if (existEntity != null) - { - throw new UserFriendlyException($"名称:'{name}'已存在"); - } - } + /// private void CheckNotNull(ItemType entity) { Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName)); diff --git a/src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs b/src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs index 90b87ab..cee499a 100644 --- a/src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs +++ b/src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs @@ -27,7 +27,7 @@ namespace Shentun.Peis.MedicalReportTypes ) { Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName)); - await CheckSameName(entity.DisplayName); + await EntityHelper.CheckSameName(_repository, entity.DisplayName); return new MedicalReportType( GuidGenerator.Create() ) @@ -51,7 +51,8 @@ namespace Shentun.Peis.MedicalReportTypes Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName)); if (sourceEntity.DisplayName != targetEntity.DisplayName) { - await CheckSameName(sourceEntity.DisplayName, targetEntity); + + await EntityHelper.CheckSameName(_repository, sourceEntity.DisplayName, targetEntity); targetEntity.DisplayName = sourceEntity.DisplayName; targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.DisplayName); } @@ -62,30 +63,6 @@ namespace Shentun.Peis.MedicalReportTypes } } - /// - /// 检查同名 - /// - /// - /// - /// - /// - private async Task CheckSameName(string name, MedicalReportType updatedEntity = null) - { - Check.NotNullOrWhiteSpace(name, nameof(name)); - MedicalReportType existEntity; - if (updatedEntity == null) - { - existEntity = await _repository.FindAsync(o => o.DisplayName == name); - } - else - { - existEntity = await _repository.FindAsync(o => o.Id != updatedEntity.Id && o.DisplayName == name); - } - - if (existEntity != null) - { - throw new UserFriendlyException($"名称:'{name}'已存在"); - } - } + } } diff --git a/src/Shentun.Peis.Domain/Models/GuideType.cs b/src/Shentun.Peis.Domain/Models/GuideType.cs index befd2a4..f6a90f1 100644 --- a/src/Shentun.Peis.Domain/Models/GuideType.cs +++ b/src/Shentun.Peis.Domain/Models/GuideType.cs @@ -13,7 +13,7 @@ namespace Shentun.Peis.Models /// 指引类别 /// [Table("guide_type")] - public class GuideType : AuditedEntity,IDisplayOrder + public class GuideType : AuditedEntity,IDisplayOrder, IDisplayName { public GuideType() { diff --git a/src/Shentun.Peis.Domain/Models/ItemType.cs b/src/Shentun.Peis.Domain/Models/ItemType.cs index 3757894..c390322 100644 --- a/src/Shentun.Peis.Domain/Models/ItemType.cs +++ b/src/Shentun.Peis.Domain/Models/ItemType.cs @@ -14,7 +14,7 @@ namespace Shentun.Peis.Models /// [Table("item_type")] [Index(nameof(DisplayName), nameof(ParentId), Name = "ix_item_type", IsUnique = true)] - public class ItemType : AuditedEntity, IDisplayOrder + public class ItemType : AuditedEntity, IDisplayOrder,IDisplayName { public ItemType() diff --git a/src/Shentun.Peis.Domain/Models/MedicalReportType.cs b/src/Shentun.Peis.Domain/Models/MedicalReportType.cs index b4abcf8..17f94c0 100644 --- a/src/Shentun.Peis.Domain/Models/MedicalReportType.cs +++ b/src/Shentun.Peis.Domain/Models/MedicalReportType.cs @@ -12,7 +12,7 @@ namespace Shentun.Peis.Models /// 体检报告类别设置 /// [Table("medical_report_type")] - public class MedicalReportType : AuditedEntity, IDisplayOrder + public class MedicalReportType : AuditedEntity, IDisplayOrder,IDisplayName { public MedicalReportType() {