From 6c9774a12537781dca0830953d6efdb86055dad7 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com> Date: Wed, 13 Mar 2024 18:06:49 +0800 Subject: [PATCH] =?UTF-8?q?CardType=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CardTypes/CardTypeAppService.cs | 29 ++++-- .../PayModes/PayModeAppService.cs | 14 ++- src/Shentun.Peis.Domain/CardTypes/CardType.cs | 10 +- .../CardTypes/CardTypeManager.cs | 93 +++++++++++++++++++ .../PayModes/PayModeManager.cs | 47 ++++++++++ 5 files changed, 180 insertions(+), 13 deletions(-) create mode 100644 src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs create mode 100644 src/Shentun.Peis.Domain/PayModes/PayModeManager.cs diff --git a/src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs b/src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs index d6bbdcd..6204a27 100644 --- a/src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs +++ b/src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Shentun.Peis.GuideTypes; +using Shentun.Peis.GuidTypes; using Shentun.Peis.Models; using System; using System.Collections.Generic; @@ -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,15 @@ namespace Shentun.Peis.CardTypes { private readonly IRepository _cardTypeRepository; private readonly IRepository _userRepository; - + private readonly CardTypeManager _manager; public CardTypeAppService( IRepository cardTypeRepository, - IRepository userRepository) : base(cardTypeRepository) + IRepository userRepository, + CardTypeManager manager) : base(cardTypeRepository) { this._cardTypeRepository = cardTypeRepository; this._userRepository = userRepository; + _manager = manager; } @@ -110,9 +114,13 @@ namespace Shentun.Peis.CardTypes /// /// [HttpPost("api/app/cardtype/create")] - public override Task CreateAsync(CreateCardTypeDto input) + public override async Task CreateAsync(CreateCardTypeDto input) { - return base.CreateAsync(input); + var createEntity = ObjectMapper.Map(input); + var entity = await _manager.CreateAsync(createEntity); + entity = await Repository.InsertAsync(entity); + var dto = ObjectMapper.Map(entity); + return dto; } /// @@ -122,9 +130,13 @@ namespace Shentun.Peis.CardTypes /// /// [HttpPost("api/app/cardtype/update")] - public override Task UpdateAsync(Guid id, UpdateCardTypeDto input) + public override async Task UpdateAsync(Guid id, UpdateCardTypeDto input) { - return base.UpdateAsync(id, input); + var entity = await Repository.GetAsync(id); + var sourceEntity = ObjectMapper.Map(input); + await _manager.UpdateAsync(sourceEntity, entity); + entity = await Repository.UpdateAsync(entity); + return ObjectMapper.Map(entity); } /// @@ -133,9 +145,10 @@ namespace Shentun.Peis.CardTypes /// /// [HttpPost("api/app/cardtype/delete")] - public override Task DeleteAsync(Guid id) + public override async Task DeleteAsync(Guid id) { - return base.DeleteAsync(id); + var entity = await Repository.GetAsync(id); + await _manager.CheckAndDeleteAsync(entity); } } } diff --git a/src/Shentun.Peis.Application/PayModes/PayModeAppService.cs b/src/Shentun.Peis.Application/PayModes/PayModeAppService.cs index f126481..1bffbc7 100644 --- a/src/Shentun.Peis.Application/PayModes/PayModeAppService.cs +++ b/src/Shentun.Peis.Application/PayModes/PayModeAppService.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc; using Shentun.Peis.HelperDto; using Shentun.Peis.Models; using Shentun.Peis.PayModes; +using Shentun.Peis.PersonnelTypes; using Shentun.Utilities; using System; using System.Collections.Generic; @@ -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,11 @@ namespace Shentun.Peis.PayModes public class PayModeAppService : ApplicationService { private readonly IRepository _repository; - - public PayModeAppService(IRepository repository) + private readonly PayModeManager _manager; + public PayModeAppService(IRepository repository, PayModeManager manager) { this._repository = repository; + _manager = manager; } @@ -65,6 +68,12 @@ namespace Shentun.Peis.PayModes /// public async Task UpdateAsync(string Id, UpdatePayModeDto input) { + var entity = await _repository.GetAsync(o=>o.Id == Id); + var sourceEntity = ObjectMapper.Map(input); + await _manager.UpdateAsync(sourceEntity, entity); + entity = await _repository.UpdateAsync(entity); + return ObjectMapper.Map(entity); + /* 废弃,改为通过_manager处理业务, by zhh 2024-03-13 Check.NotNullOrWhiteSpace(input.DisplayName, nameof(input.DisplayName)); PayMode existEntity = await _repository.FindAsync(o => o.Id != Id && o.DisplayName == input.DisplayName); @@ -88,6 +97,7 @@ namespace Shentun.Peis.PayModes { return ObjectMapper.Map(ent); } + */ } diff --git a/src/Shentun.Peis.Domain/CardTypes/CardType.cs b/src/Shentun.Peis.Domain/CardTypes/CardType.cs index 23c4da2..b12f14b 100644 --- a/src/Shentun.Peis.Domain/CardTypes/CardType.cs +++ b/src/Shentun.Peis.Domain/CardTypes/CardType.cs @@ -12,15 +12,19 @@ namespace Shentun.Peis.Models /// 会员卡类别 /// [Table("card_type")] - public class CardType : AuditedEntity, IHasConcurrencyStamp + public class CardType : AuditedEntity, IHasConcurrencyStamp, IDisplayName, IDisplayOrder { public CardType() { CardRegisters = new HashSet(); } + internal CardType(Guid id + ) : base(id) + { + + } + - - /// /// 名称 /// diff --git a/src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs b/src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs new file mode 100644 index 0000000..7663ea3 --- /dev/null +++ b/src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs @@ -0,0 +1,93 @@ +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 _repository; + private readonly IRepository _cardRegisterRepository; + public CardTypeManager(IRepository repository, + IRepository cardRegisterRepository) + { + _repository = repository; + _cardRegisterRepository = cardRegisterRepository; + } + + /// + /// 创建 + /// + /// + /// + public async Task CreateAsync( + CardType entity + ) + { + Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName)); + await EntityHelper.CheckSameName(_repository, entity.DisplayName); + return new CardType( + GuidGenerator.Create() + ) + { + DisplayName = entity.DisplayName, + DisplayOrder = await EntityHelper.CreateMaxDisplayOrder(_repository), + CardModeId = entity.CardModeId, + Discount = entity.Discount, + ExpiryDay = entity.ExpiryDay, + Remark = entity.Remark + }; + } + + + /// + /// 更新 + /// + /// + /// + /// + public async Task UpdateAsync( + CardType sourceEntity, + CardType targetEntity + ) + { + Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName)); + if (sourceEntity.DisplayName != targetEntity.DisplayName) + { + + await EntityHelper.CheckSameName(_repository, sourceEntity.DisplayName, targetEntity); + targetEntity.DisplayName = sourceEntity.DisplayName; + } + targetEntity.CardModeId = sourceEntity.CardModeId; + targetEntity.Discount = sourceEntity.Discount; + targetEntity.ExpiryDay = sourceEntity.ExpiryDay; + targetEntity.Remark = sourceEntity.Remark; + + + + } + + public async Task CheckAndDeleteAsync(CardType entity) + { + + var queryable = await _cardRegisterRepository.GetQueryableAsync(); + var item = queryable.Where(o => o.CardTypeId.Equals(entity.Id)).FirstOrDefault(); + if (item != null) + { + throw new BusinessException("", $"卡类别\"{entity.DisplayName}\"已在卡登记\"{item.CustomerName}\"中使用,不能删除"); + } + + await _repository.DeleteAsync(entity); + } + + + } +} diff --git a/src/Shentun.Peis.Domain/PayModes/PayModeManager.cs b/src/Shentun.Peis.Domain/PayModes/PayModeManager.cs new file mode 100644 index 0000000..32491b4 --- /dev/null +++ b/src/Shentun.Peis.Domain/PayModes/PayModeManager.cs @@ -0,0 +1,47 @@ +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; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Domain.Services; + +namespace Shentun.Peis.PayModes +{ + public class PayModeManager : DomainService + { + private readonly IRepository _repository; + + public PayModeManager( + IRepository repository + ) + { + _repository = repository; + } + + public async Task UpdateAsync( + PayMode sourceEntity, + PayMode targetEntity + ) + { + Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName)); + + + if (sourceEntity.DisplayName != targetEntity.DisplayName) + { + PayMode existEntity = await _repository.FindAsync(o => o.Id != targetEntity.Id && o.DisplayName == sourceEntity.DisplayName); + if (existEntity != null) + { + throw new UserFriendlyException($"名称:'{sourceEntity.DisplayName}'已存在"); + } + + targetEntity.DisplayName = sourceEntity.DisplayName; + targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.DisplayName); + } + targetEntity.IsActive = sourceEntity.IsActive; + } + } +}