Browse Source

实现IDisplayName接口

bjmzak
DESKTOP-G961P6V\Zhh 3 years ago
parent
commit
81530d1bfa
  1. 37
      src/Shentun.Peis.Domain/EntityHelper.cs
  2. 31
      src/Shentun.Peis.Domain/GuideTypes/GuideTypeManager.cs
  3. 13
      src/Shentun.Peis.Domain/IDisplayName.cs
  4. 2
      src/Shentun.Peis.Domain/IDisplayOrder.cs
  5. 29
      src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs
  6. 31
      src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs
  7. 2
      src/Shentun.Peis.Domain/Models/GuideType.cs
  8. 2
      src/Shentun.Peis.Domain/Models/ItemType.cs
  9. 2
      src/Shentun.Peis.Domain/Models/MedicalReportType.cs

37
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
{
/// <summary>
/// 创建最大显示顺序
@ -22,5 +24,36 @@ namespace Shentun.Peis
int? maxDisplayOrder = await repository.MaxAsync(o => (int?)o.DisplayOrder);
return (maxDisplayOrder ?? 0) + 1;
}
/// <summary>
/// 检查同名
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <param name="repository"></param>
/// <param name="name"></param>
/// <param name="updatedEntity"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
public static async Task CheckSameName<TEntity,TKey>(IRepository<TEntity> repository,string name, TEntity updatedEntity = null)
where TEntity : class, IEntity<TKey>, 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}'已存在");
}
}
}
}

31
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<GuideType, Guid>(_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<GuideType, Guid>(_repository, sourceEntity.DisplayName, targetEntity);
targetEntity.DisplayName = sourceEntity.DisplayName;
targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.DisplayName);
}
@ -66,30 +67,6 @@ namespace Shentun.Peis.GuidTypes
}
/// <summary>
/// 检查同名
/// </summary>
/// <param name="name"></param>
/// <param name="updatedEntity"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
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}'已存在");
}
}
}
}

13
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; }
}
}

2
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; }
}

29
src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs

@ -29,7 +29,7 @@ namespace Shentun.Peis.ItemTypes
{
CheckNotNull(entity);
await CheckSameName(entity.DisplayName);
await EntityHelper.CheckSameName<ItemType, Guid>(_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<ItemType, Guid>(_repository, sourceEntity.DisplayName, targetEntity);
targetEntity.DisplayName = sourceEntity.DisplayName;
//targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.ItemTypeName);
}
@ -66,30 +66,9 @@ namespace Shentun.Peis.ItemTypes
}
/// <summary>
/// 检查同名
/// 检查空值
/// </summary>
/// <param name="name"></param>
/// <param name="updatedEntity"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
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}'已存在");
}
}
/// <param name="entity"></param>
private void CheckNotNull(ItemType entity)
{
Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName));

31
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<MedicalReportType, Guid>(_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<MedicalReportType, Guid>(_repository, sourceEntity.DisplayName, targetEntity);
targetEntity.DisplayName = sourceEntity.DisplayName;
targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.DisplayName);
}
@ -62,30 +63,6 @@ namespace Shentun.Peis.MedicalReportTypes
}
}
/// <summary>
/// 检查同名
/// </summary>
/// <param name="name"></param>
/// <param name="updatedEntity"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
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}'已存在");
}
}
}
}

2
src/Shentun.Peis.Domain/Models/GuideType.cs

@ -13,7 +13,7 @@ namespace Shentun.Peis.Models
/// 指引类别
/// </summary>
[Table("guide_type")]
public class GuideType : AuditedEntity<Guid>,IDisplayOrder
public class GuideType : AuditedEntity<Guid>,IDisplayOrder, IDisplayName
{
public GuideType()
{

2
src/Shentun.Peis.Domain/Models/ItemType.cs

@ -14,7 +14,7 @@ namespace Shentun.Peis.Models
/// </summary>
[Table("item_type")]
[Index(nameof(DisplayName), nameof(ParentId), Name = "ix_item_type", IsUnique = true)]
public class ItemType : AuditedEntity<Guid>, IDisplayOrder
public class ItemType : AuditedEntity<Guid>, IDisplayOrder,IDisplayName
{
public ItemType()

2
src/Shentun.Peis.Domain/Models/MedicalReportType.cs

@ -12,7 +12,7 @@ namespace Shentun.Peis.Models
/// 体检报告类别设置
/// </summary>
[Table("medical_report_type")]
public class MedicalReportType : AuditedEntity<Guid>, IDisplayOrder
public class MedicalReportType : AuditedEntity<Guid>, IDisplayOrder,IDisplayName
{
public MedicalReportType()
{

Loading…
Cancel
Save