Browse Source

分层

bjmzak
wxd 2 years ago
parent
commit
e08548c229
  1. 5
      src/Shentun.Peis.Application.Contracts/CardTypes/CreateCardTypeDto.cs
  2. 5
      src/Shentun.Peis.Application.Contracts/CardTypes/UpdateCardTypeDto.cs
  3. 24
      src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs
  4. 37
      src/Shentun.Peis.Application/PayModes/PayModeAppService.cs
  5. 2
      src/Shentun.Peis.Domain/CardTypes/CardType.cs
  6. 74
      src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs
  7. 54
      src/Shentun.Peis.Domain/PayModes/PayModeManager.cs

5
src/Shentun.Peis.Application.Contracts/CardTypes/CreateCardTypeDto.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Shentun.Peis.CardTypes
@ -9,18 +10,22 @@ namespace Shentun.Peis.CardTypes
/// <summary>
/// 名称
/// </summary>
[Required(ErrorMessage ="名称不能为空")]
public string DisplayName { get; set; }
/// <summary>
/// 卡模式 (0:充值卡,1:积分卡)
/// </summary>
[Required(ErrorMessage = "卡模式不能为空")]
public char CardModeId { get; set; }
/// <summary>
/// 折扣
/// </summary>
[Required(ErrorMessage = "折扣不能为空")]
public int Discount { get; set; }
/// <summary>
/// 有效期
/// </summary>
[Required(ErrorMessage = "有效期不能为空")]
public int ExpiryDay { get; set; }
/// <summary>

5
src/Shentun.Peis.Application.Contracts/CardTypes/UpdateCardTypeDto.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Shentun.Peis.CardTypes
@ -9,18 +10,22 @@ namespace Shentun.Peis.CardTypes
/// <summary>
/// 名称
/// </summary>
[Required(ErrorMessage = "名称不能为空")]
public string DisplayName { get; set; }
/// <summary>
/// 卡模式 (0:充值卡,1:积分卡)
/// </summary>
[Required(ErrorMessage = "卡模式不能为空")]
public char CardModeId { get; set; }
/// <summary>
/// 折扣
/// </summary>
[Required(ErrorMessage = "折扣不能为空")]
public int Discount { get; set; }
/// <summary>
/// 有效期
/// </summary>
[Required(ErrorMessage = "有效期不能为空")]
public int ExpiryDay { get; set; }
/// <summary>

24
src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.Asbitems;
using Shentun.Peis.GuideTypes;
using Shentun.Peis.Models;
using System;
@ -13,6 +14,7 @@ using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
using Volo.Abp.ObjectMapping;
namespace Shentun.Peis.CardTypes
{
@ -28,13 +30,16 @@ namespace Shentun.Peis.CardTypes
{
private readonly IRepository<CardType, Guid> _cardTypeRepository;
private readonly IRepository<IdentityUser, Guid> _userRepository;
private readonly CardTypeManager _manager;
public CardTypeAppService(
IRepository<CardType, Guid> cardTypeRepository,
IRepository<IdentityUser, Guid> userRepository) : base(cardTypeRepository)
IRepository<IdentityUser, Guid> userRepository,
CardTypeManager manager) : base(cardTypeRepository)
{
this._cardTypeRepository = cardTypeRepository;
this._userRepository = userRepository;
this._manager = manager;
}
@ -110,9 +115,14 @@ namespace Shentun.Peis.CardTypes
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/cardtype/create")]
public override Task<CardTypeDto> CreateAsync(CreateCardTypeDto input)
public override async Task<CardTypeDto> CreateAsync(CreateCardTypeDto input)
{
return base.CreateAsync(input);
var createEntity = ObjectMapper.Map<CreateCardTypeDto, CardType>(input);
var entity = await _manager.CreateAsync(createEntity);
entity = await Repository.InsertAsync(entity);
var dto = ObjectMapper.Map<CardType, CardTypeDto>(entity);
return dto;
}
/// <summary>
@ -122,9 +132,13 @@ namespace Shentun.Peis.CardTypes
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/cardtype/update")]
public override Task<CardTypeDto> UpdateAsync(Guid id, UpdateCardTypeDto input)
public override async Task<CardTypeDto> UpdateAsync(Guid id, UpdateCardTypeDto input)
{
return base.UpdateAsync(id, input);
var entity = await Repository.GetAsync(id);
var sourceEntity = ObjectMapper.Map<UpdateCardTypeDto, CardType>(input);
await _manager.UpdateAsync(sourceEntity, entity);
entity = await Repository.UpdateAsync(entity);
return ObjectMapper.Map<CardType, CardTypeDto>(entity);
}
/// <summary>

37
src/Shentun.Peis.Application/PayModes/PayModeAppService.cs

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.HelperDto;
using Shentun.Peis.Models;
using Shentun.Peis.Patients;
using Shentun.Peis.PayModes;
using Shentun.Utilities;
using System;
@ -13,6 +14,7 @@ using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;
namespace Shentun.Peis.PayModes
{
@ -25,10 +27,14 @@ namespace Shentun.Peis.PayModes
public class PayModeAppService : ApplicationService
{
private readonly IRepository<PayMode> _repository;
private readonly PayModeManager _manager;
public PayModeAppService(IRepository<PayMode> repository)
public PayModeAppService(
IRepository<PayMode> repository,
PayModeManager manager)
{
this._repository = repository;
this._manager = manager;
}
@ -65,30 +71,11 @@ namespace Shentun.Peis.PayModes
/// <returns></returns>
public async Task<PayModeDto> UpdateAsync(string Id, UpdatePayModeDto input)
{
Check.NotNullOrWhiteSpace(input.DisplayName, nameof(input.DisplayName));
PayMode existEntity = await _repository.FindAsync(o => o.Id != Id && o.DisplayName == input.DisplayName);
if (existEntity != null)
{
throw new UserFriendlyException($"名称:'{input.DisplayName}'已存在");
}
var ent = await _repository.GetAsync(m => m.Id == Id);
if (ent != null)
{
ent.DisplayName = input.DisplayName;
ent.SimpleCode = LanguageConverter.GetPYSimpleCode(input.DisplayName);
ent.IsActive = input.IsActive;
var newent = await _repository.UpdateAsync(ent);
return ObjectMapper.Map<PayMode, PayModeDto>(newent);
}
else
{
return ObjectMapper.Map<PayMode, PayModeDto>(ent);
}
var entity = await _repository.GetAsync(m => m.Id == Id);
var sourceEntity = ObjectMapper.Map<UpdatePayModeDto, PayMode>(input);
_manager.UpdateAsync(sourceEntity, entity);
entity = await _repository.UpdateAsync(entity);
return ObjectMapper.Map<PayMode, PayModeDto>(entity);
}

2
src/Shentun.Peis.Domain/CardTypes/CardType.cs

@ -12,7 +12,7 @@ namespace Shentun.Peis.Models
/// 会员卡类别
/// </summary>
[Table("card_type")]
public class CardType : AuditedEntity<Guid>, IHasConcurrencyStamp
public class CardType : AuditedEntity<Guid>, IDisplayName, IDisplayOrder, IHasConcurrencyStamp
{
public CardType()
{

74
src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs

@ -0,0 +1,74 @@
using Shentun.Peis.Models;
using Shentun.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TencentCloud.Sqlserver.V20180328.Models;
using Volo.Abp;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;
namespace Shentun.Peis.CardTypes
{
public class CardTypeManager : DomainService
{
private readonly IRepository<CardType, Guid> _repository;
public CardTypeManager(IRepository<CardType, Guid> Repository)
{
_repository = Repository;
}
/// <summary>
/// 创建
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public async Task<CardType> CreateAsync(
CardType entity
)
{
Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName));
await EntityHelper.CheckSameName<CardType, Guid>(_repository, entity.DisplayName);
return new CardType
{
DisplayName = entity.DisplayName,
DisplayOrder = await EntityHelper.CreateMaxDisplayOrder<CardType>(_repository),
CardModeId = entity.CardModeId,
Discount = entity.Discount,
ExpiryDay = entity.ExpiryDay,
Remark = entity.Remark
};
}
/// <summary>
/// 更新
/// </summary>
/// <param name="sourceEntity"></param>
/// <param name="targetEntity"></param>
/// <returns></returns>
public async Task UpdateAsync(
CardType sourceEntity,
CardType targetEntity
)
{
Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName));
if (sourceEntity.DisplayName != targetEntity.DisplayName)
{
await EntityHelper.CheckSameName<CardType, Guid>(_repository, sourceEntity.DisplayName, targetEntity);
targetEntity.DisplayName = sourceEntity.DisplayName;
}
targetEntity.CardModeId = sourceEntity.CardModeId;
targetEntity.Discount = sourceEntity.Discount;
targetEntity.ExpiryDay = sourceEntity.ExpiryDay;
targetEntity.Remark = sourceEntity.Remark;
}
}
}

54
src/Shentun.Peis.Domain/PayModes/PayModeManager.cs

@ -0,0 +1,54 @@
using AutoMapper.Internal.Mappers;
using Shentun.Peis.Models;
using Shentun.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp;
using Volo.Abp.Domain.Services;
namespace Shentun.Peis.PayModes
{
public class PayModeManager : DomainService
{
private readonly IRepository<PayMode> _repository;
public PayModeManager(IRepository<PayMode> repository)
{
_repository = repository;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="sourceEntity"></param>
/// <param name="targetEntity"></param>
/// <returns></returns>
public async void UpdateAsync(
PayMode sourceEntity,
PayMode targetEntity
)
{
Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName));
PayMode existEntity = await _repository.FindAsync(o => o.Id != targetEntity.Id && o.DisplayName == sourceEntity.DisplayName);
if (existEntity != null)
{
throw new UserFriendlyException($"名称:'{sourceEntity.DisplayName}'已存在");
}
if (sourceEntity.DisplayName != targetEntity.DisplayName)
{
targetEntity.DisplayName = sourceEntity.DisplayName;
targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(sourceEntity.DisplayName);
}
targetEntity.IsActive = sourceEntity.IsActive;
}
}
}
Loading…
Cancel
Save