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..861d5dd 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 = await _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..8d7a38d --- /dev/null +++ b/src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs @@ -0,0 +1,137 @@ +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 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() + ) + { + 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();