From 04b311b0076edceee49dc1bbd1ce149c137c5a46 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com> Date: Thu, 14 Mar 2024 16:58:22 +0800 Subject: [PATCH 1/3] =?UTF-8?q?CardRegister=E5=A2=9E=E5=8A=A0=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E5=92=8C=E7=A6=81=E7=94=A8=E6=9C=8D=E5=8A=A1=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CardRegisters/CardRegisterDto.cs | 2 +- .../CardRegisters/CreateCardRegisterDto.cs | 2 +- .../CardRegisters/GetCardRegisterListDto.cs | 2 +- .../CardRegisters/UpdateCardRegisterDto.cs | 2 +- .../CardBills/CardBillAppService.cs | 2 +- .../CardRegisters/CardRegisterAppService.cs | 83 +++++------ .../CardRegisters/CardRegister.cs | 11 +- .../CardRegisters/CardRegisterManager.cs | 132 ++++++++++++++++++ .../CardRegisters/CardRegisterDbMapping.cs | 2 +- 9 files changed, 176 insertions(+), 62 deletions(-) create mode 100644 src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs diff --git a/src/Shentun.Peis.Application.Contracts/CardRegisters/CardRegisterDto.cs b/src/Shentun.Peis.Application.Contracts/CardRegisters/CardRegisterDto.cs index 80694e4..8944b29 100644 --- a/src/Shentun.Peis.Application.Contracts/CardRegisters/CardRegisterDto.cs +++ b/src/Shentun.Peis.Application.Contracts/CardRegisters/CardRegisterDto.cs @@ -64,7 +64,7 @@ namespace Shentun.Peis.CardRegisters /// /// 使用标志 /// - public char CardFlag { get; set; } + public char IsActive { get; set; } /// /// 备注 /// diff --git a/src/Shentun.Peis.Application.Contracts/CardRegisters/CreateCardRegisterDto.cs b/src/Shentun.Peis.Application.Contracts/CardRegisters/CreateCardRegisterDto.cs index 9f89b2a..2921822 100644 --- a/src/Shentun.Peis.Application.Contracts/CardRegisters/CreateCardRegisterDto.cs +++ b/src/Shentun.Peis.Application.Contracts/CardRegisters/CreateCardRegisterDto.cs @@ -51,7 +51,7 @@ namespace Shentun.Peis.CardRegisters /// /// 使用标志(1、启用 0、j禁用 ) /// - public char CardFlag { get; set; } + public char IsActive { get; set; } /// /// 备注 /// diff --git a/src/Shentun.Peis.Application.Contracts/CardRegisters/GetCardRegisterListDto.cs b/src/Shentun.Peis.Application.Contracts/CardRegisters/GetCardRegisterListDto.cs index b6b1e40..4d3b0da 100644 --- a/src/Shentun.Peis.Application.Contracts/CardRegisters/GetCardRegisterListDto.cs +++ b/src/Shentun.Peis.Application.Contracts/CardRegisters/GetCardRegisterListDto.cs @@ -35,7 +35,7 @@ namespace Shentun.Peis.CardRegisters /// /// 使用标志(1、启用 0、j禁用 ) /// - public char? CardFlag { get; set; } + public char? IsActive { get; set; } /// /// 手机或者电话 模糊查询 diff --git a/src/Shentun.Peis.Application.Contracts/CardRegisters/UpdateCardRegisterDto.cs b/src/Shentun.Peis.Application.Contracts/CardRegisters/UpdateCardRegisterDto.cs index 507a1af..18d20a1 100644 --- a/src/Shentun.Peis.Application.Contracts/CardRegisters/UpdateCardRegisterDto.cs +++ b/src/Shentun.Peis.Application.Contracts/CardRegisters/UpdateCardRegisterDto.cs @@ -49,7 +49,7 @@ namespace Shentun.Peis.CardRegisters /// /// 使用标志(1、启用 0、j禁用 ) /// - public char CardFlag { get; set; } + public char IsActive { get; set; } /// /// 备注 /// diff --git a/src/Shentun.Peis.Application/CardBills/CardBillAppService.cs b/src/Shentun.Peis.Application/CardBills/CardBillAppService.cs index e455485..a9353cb 100644 --- a/src/Shentun.Peis.Application/CardBills/CardBillAppService.cs +++ b/src/Shentun.Peis.Application/CardBills/CardBillAppService.cs @@ -102,7 +102,7 @@ namespace Shentun.Peis.CardBills BillMoney = s.BillMoney, MobileTelephone = s.CardRegister.MobileTelephone, CardBalance = s.CardRegister.CardBalance, - CardFlag = s.CardRegister.CardFlag, + CardFlag = s.CardRegister.IsActive, CardNo = s.CardRegister.CardNo, CardPassword = s.CardRegister.CardPassword, CardRegisterId = s.CardRegisterId, diff --git a/src/Shentun.Peis.Application/CardRegisters/CardRegisterAppService.cs b/src/Shentun.Peis.Application/CardRegisters/CardRegisterAppService.cs index 322609d..f194613 100644 --- a/src/Shentun.Peis.Application/CardRegisters/CardRegisterAppService.cs +++ b/src/Shentun.Peis.Application/CardRegisters/CardRegisterAppService.cs @@ -26,18 +26,20 @@ namespace Shentun.Peis.CardRegisters private readonly IRepository _cardBillRepository; private readonly IRepository _userRepository; private readonly IRepository _organizationUnitRepository; - + private readonly CardRegisterManager _manager; public CardRegisterAppService( IRepository cardRegisterRepository, IRepository cardBillRepository, IRepository userRepository, - IRepository organizationUnitRepository + IRepository organizationUnitRepository, + CardRegisterManager manager ) { this._cardRegisterRepository = cardRegisterRepository; this._cardBillRepository = cardBillRepository; this._userRepository = userRepository; this._organizationUnitRepository = organizationUnitRepository; + _manager = manager; } /// @@ -74,9 +76,9 @@ namespace Shentun.Peis.CardRegisters { cardRegisterList = cardRegisterList.Where(m => !string.IsNullOrEmpty(m.CustomerName) && m.CustomerName.Contains(input.CustomerName)); } - if (input.CardFlag != null) + if (input.IsActive != null) { - cardRegisterList = cardRegisterList.Where(m => m.CardFlag == input.CardFlag); + cardRegisterList = cardRegisterList.Where(m => m.IsActive == input.IsActive); } if (!string.IsNullOrEmpty(input.Phone)) { @@ -116,7 +118,7 @@ namespace Shentun.Peis.CardRegisters var entdtolist = entlist.Select(s => new CardRegisterDto { CardBalance = s.a.CardBalance, - CardFlag = s.a.CardFlag, + IsActive = s.a.IsActive, CardModeId = s.a.CardType.CardModeId, CardNo = s.a.CardNo, CardPassword = s.a.CardPassword, @@ -176,25 +178,12 @@ namespace Shentun.Peis.CardRegisters [HttpPost("api/app/cardregister/create")] public async Task CreateAsync(CreateCardRegisterDto input) { - var ent = new CardRegister - { - CardBalance = 0, - CardFlag = input.CardFlag, - CardNo = input.CardNo, - CardPassword = input.CardPassword, - CardTypeId = input.CardTypeId, - CustomerName = input.CustomerName, - Discount = input.Discount, - ExpiryDate = PageHelper.ConvertDate(input.ExpiryDate), - IdNo = input.IdNo, - MobileTelephone = input.MobileTelephone, - OrganizationUnitId = input.OrganizationUnitId, - Remark = input.Remark, - Telephone = input.Telephone - }; - var ent_insert = await _cardRegisterRepository.InsertAsync(ent); + var createEntity = ObjectMapper.Map(input); + var entity = _manager.CreateAsync(createEntity); + entity = await _cardRegisterRepository.InsertAsync(entity); + var dto = ObjectMapper.Map(entity); + return dto; - return ObjectMapper.Map(ent_insert); } /// @@ -206,31 +195,12 @@ namespace Shentun.Peis.CardRegisters [HttpPost("api/app/cardregister/update")] public async Task UpdateAsync(Guid id, UpdateCardRegisterDto input) { + var entity = await _cardRegisterRepository.GetAsync(id); + var sourceEntity = ObjectMapper.Map(input); + _manager.UpdateAsync(sourceEntity, entity); + entity = await _cardRegisterRepository.UpdateAsync(entity); + return ObjectMapper.Map(entity); - var ent = await _cardRegisterRepository.FindAsync(id); - if (ent != null) - { - ent.CardFlag = input.CardFlag; - ent.CardNo = input.CardNo; - ent.CardPassword = input.CardPassword; - ent.CardTypeId = input.CardTypeId; - ent.CustomerName = input.CustomerName; - ent.Discount = input.Discount; - ent.ExpiryDate = PageHelper.ConvertDate(input.ExpiryDate); - ent.IdNo = input.IdNo; - ent.MobileTelephone = input.MobileTelephone; - ent.OrganizationUnitId = input.OrganizationUnitId; - ent.Remark = input.Remark; - ent.Telephone = input.Telephone; - - var ent_update = await _cardRegisterRepository.UpdateAsync(ent); - - return ObjectMapper.Map(ent_update); - } - else - { - throw new UserFriendlyException("参数有误"); - } } /// @@ -239,12 +209,23 @@ namespace Shentun.Peis.CardRegisters /// /// [HttpPost("api/app/cardregister/delete")] - public async Task DeleteAsync(Guid id) + public Task DeleteAsync(Guid id) { - await _cardRegisterRepository.DeleteAsync(id); + throw new Exception("卡禁止删除"); + + } + /// + /// 更新启用状态 + /// + /// + /// + /// + public async Task UpdateActive(Guid id,char isActive) + { + var entity = await _cardRegisterRepository.GetAsync(id); + await _manager.UpdateActive(entity, isActive); + await _cardRegisterRepository.UpdateAsync(entity); } - - /// /// 会员卡充值 /// diff --git a/src/Shentun.Peis.Domain/CardRegisters/CardRegister.cs b/src/Shentun.Peis.Domain/CardRegisters/CardRegister.cs index d577e96..ce9539a 100644 --- a/src/Shentun.Peis.Domain/CardRegisters/CardRegister.cs +++ b/src/Shentun.Peis.Domain/CardRegisters/CardRegister.cs @@ -12,7 +12,7 @@ namespace Shentun.Peis.Models /// 会员卡登记 /// [Table("card_register")] - [Index(nameof(CardNo), nameof(CardFlag), Name = "ix_card_register", IsUnique = true)] + [Index(nameof(CardNo), nameof(IsActive), Name = "ix_card_register", IsUnique = true)] public class CardRegister : AuditedEntity, IHasConcurrencyStamp { public CardRegister() @@ -20,7 +20,8 @@ namespace Shentun.Peis.Models CardBills = new HashSet(); } - + internal CardRegister(Guid id):base(id) { + } /// /// 体检中心ID @@ -78,11 +79,11 @@ namespace Shentun.Peis.Models [StringLength(20)] public string? MobileTelephone { get; set; } /// - /// 使用标志(1、启用 0、j禁用 ) + /// 使用标志(Y、启用 N、j禁用 ) /// - [Column("card_flag")] + [Column("is_active")] [MaxLength(1)] - public char CardFlag { get; set; } + public char IsActive { get; set; } /// /// 备注 /// diff --git a/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs b/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs new file mode 100644 index 0000000..4f19eb7 --- /dev/null +++ b/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs @@ -0,0 +1,132 @@ +using Shentun.Peis.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TencentCloud.Ic.V20190307.Models; +using TencentCloud.Sqlserver.V20180328.Models; +using Volo.Abp; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Domain.Services; +using static log4net.Appender.RollingFileAppender; + +namespace Shentun.Peis.CardRegisters +{ + public class CardRegisterManager : DomainService + { + private readonly IRepository _repository; + public CardRegisterManager(IRepository repository) + { + _repository = repository; + + } + /// + /// 创建 + /// + /// + /// + public CardRegister CreateAsync( + CardRegister entity + ) + { + Check.NotNull(entity, nameof(entity)); + Verify(entity); + + return new CardRegister( + GuidGenerator.Create() + ) + { + CardBalance = 0, + IsActive = entity.IsActive, + CardNo = entity.CardNo, + CardPassword = entity.CardPassword, + CardTypeId = entity.CardTypeId, + CustomerName = entity.CustomerName, + Discount = entity.Discount, + ExpiryDate = entity.ExpiryDate, + IdNo = entity.IdNo, + MobileTelephone = entity.MobileTelephone, + OrganizationUnitId = entity.OrganizationUnitId, + Remark = entity.Remark, + Telephone = entity.Telephone + + }; + } + + /// + /// 更新 + /// + /// + /// + /// + public void UpdateAsync( + CardRegister sourceEntity, + CardRegister targetEntity + ) + { + Check.NotNull(sourceEntity, nameof(sourceEntity)); + Check.NotNull(targetEntity, nameof(targetEntity)); + Verify(sourceEntity); + if (sourceEntity.CardNo != targetEntity.CardNo) { + throw new ArgumentException("卡号不允许修改"); + } + if (sourceEntity.CardBalance != targetEntity.CardBalance) + { + throw new ArgumentException("卡余额不允许修改"); + } + targetEntity.IsActive = sourceEntity.IsActive; + targetEntity.CardPassword = sourceEntity.CardPassword; + targetEntity.CardTypeId = sourceEntity.CardTypeId; + targetEntity.CustomerName = sourceEntity.CustomerName; + targetEntity.Discount = sourceEntity.Discount; + targetEntity.ExpiryDate = sourceEntity.ExpiryDate; + targetEntity.IdNo = sourceEntity.IdNo; + targetEntity.MobileTelephone = sourceEntity.MobileTelephone; + targetEntity.OrganizationUnitId = sourceEntity.OrganizationUnitId; + targetEntity.Remark = sourceEntity.Remark; + targetEntity.Telephone = sourceEntity.Telephone; + + } + + public async Task UpdateActive(CardRegister entity, char isActive) + { + Check.NotNull(isActive, "isActive"); + Check.NotNull(entity, nameof(isActive)); + if (isActive != 'Y' && isActive != 'N') + { + throw new ArgumentException($"IsActive参数为:{isActive},是无效值"); + } + + if (isActive == 'N') + { + entity.IsActive = isActive; + } + else + { + //检查卡号是否用过 + var queryable = await _repository.GetQueryableAsync(); + var findedEntity = queryable.Where(x => x.Id != entity.Id && x.CardNo == entity.CardNo && x.IsActive == 'Y').FirstOrDefault(); + if (findedEntity != null) + { + throw new UserFriendlyException($"卡号已经被{findedEntity.CustomerName}使用" ); + } + } + } + public void Verify(CardRegister entity) + { + Check.NotNull(entity, nameof(entity)); + Check.NotNullOrWhiteSpace(entity.CardNo, nameof(entity.CardNo)); + Check.NotNullOrWhiteSpace(entity.CustomerName, nameof(entity.CustomerName)); + Check.NotNullOrWhiteSpace(entity.IdNo, nameof(entity.IdNo)); + Check.NotNullOrWhiteSpace(entity.MobileTelephone, nameof(entity.MobileTelephone)); + Check.NotNull(entity.CardTypeId, nameof(entity.CardTypeId)); + Check.NotNull(entity.OrganizationUnitId, nameof(entity.OrganizationUnitId)); + Check.NotNull(entity.IsActive, nameof(entity.IsActive)); + if (entity.IsActive != 'Y' && entity.IsActive != 'N') + { + throw new ArgumentException($"IsActive参数为:{entity.IsActive},是无效值"); + } + } + } +} diff --git a/src/Shentun.Peis.EntityFrameworkCore/DbMapping/CardRegisters/CardRegisterDbMapping.cs b/src/Shentun.Peis.EntityFrameworkCore/DbMapping/CardRegisters/CardRegisterDbMapping.cs index 87e91bb..730110a 100644 --- a/src/Shentun.Peis.EntityFrameworkCore/DbMapping/CardRegisters/CardRegisterDbMapping.cs +++ b/src/Shentun.Peis.EntityFrameworkCore/DbMapping/CardRegisters/CardRegisterDbMapping.cs @@ -20,7 +20,7 @@ namespace Shentun.Peis.DbMapping .ValueGeneratedNever() .HasComment("编号").IsRequired(); - entity.Property(e => e.CardFlag) + entity.Property(e => e.IsActive) .HasDefaultValueSql("0") .HasComment("使用标志").IsRequired(); From 7cc76f2b9de4adc144532157b92eec008c219176 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com> Date: Thu, 14 Mar 2024 17:00:43 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=EF=BC=8C=E5=88=A4=E6=96=AD=E5=8D=A1=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=B7=B2=E7=BB=8F=E5=85=B6=E5=AE=83=E4=BA=BA=E7=94=A8?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CardRegisters/CardRegisterManager.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs b/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs index 4f19eb7..8d7a38d 100644 --- a/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs +++ b/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs @@ -26,13 +26,18 @@ namespace Shentun.Peis.CardRegisters /// /// /// - public CardRegister CreateAsync( + public async Task CreateAsync( CardRegister entity ) { Check.NotNull(entity, nameof(entity)); Verify(entity); - + var queryable = await _repository.GetQueryableAsync(); + var findedEntity = queryable.Where(x => x.CardNo == entity.CardNo && x.IsActive == 'Y').FirstOrDefault(); + if (findedEntity != null) + { + throw new UserFriendlyException($"卡号已经被{findedEntity.CustomerName}使用"); + } return new CardRegister( GuidGenerator.Create() ) From a9e69d814db5bf5757dddb49f3bcf7a56c06a4ff Mon Sep 17 00:00:00 2001 From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com> Date: Thu, 14 Mar 2024 17:02:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9CardRegister.CreateAsync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CardRegisters/CardRegisterAppService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shentun.Peis.Application/CardRegisters/CardRegisterAppService.cs b/src/Shentun.Peis.Application/CardRegisters/CardRegisterAppService.cs index f194613..861d5dd 100644 --- a/src/Shentun.Peis.Application/CardRegisters/CardRegisterAppService.cs +++ b/src/Shentun.Peis.Application/CardRegisters/CardRegisterAppService.cs @@ -179,7 +179,7 @@ namespace Shentun.Peis.CardRegisters public async Task CreateAsync(CreateCardRegisterDto input) { var createEntity = ObjectMapper.Map(input); - var entity = _manager.CreateAsync(createEntity); + var entity = await _manager.CreateAsync(createEntity); entity = await _cardRegisterRepository.InsertAsync(entity); var dto = ObjectMapper.Map(entity); return dto;