9 changed files with 181 additions and 62 deletions
-
2src/Shentun.Peis.Application.Contracts/CardRegisters/CardRegisterDto.cs
-
2src/Shentun.Peis.Application.Contracts/CardRegisters/CreateCardRegisterDto.cs
-
2src/Shentun.Peis.Application.Contracts/CardRegisters/GetCardRegisterListDto.cs
-
2src/Shentun.Peis.Application.Contracts/CardRegisters/UpdateCardRegisterDto.cs
-
2src/Shentun.Peis.Application/CardBills/CardBillAppService.cs
-
83src/Shentun.Peis.Application/CardRegisters/CardRegisterAppService.cs
-
11src/Shentun.Peis.Domain/CardRegisters/CardRegister.cs
-
137src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs
-
2src/Shentun.Peis.EntityFrameworkCore/DbMapping/CardRegisters/CardRegisterDbMapping.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<CardRegister, Guid> _repository; |
||||
|
public CardRegisterManager(IRepository<CardRegister, Guid> repository) |
||||
|
{ |
||||
|
_repository = repository; |
||||
|
|
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 创建
|
||||
|
/// </summary>
|
||||
|
/// <param name="entity"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public async Task<CardRegister> CreateAsync( |
||||
|
CardRegister entity |
||||
|
) |
||||
|
{ |
||||
|
Check.NotNull<CardRegister>(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 |
||||
|
|
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新
|
||||
|
/// </summary>
|
||||
|
/// <param name="sourceEntity"></param>
|
||||
|
/// <param name="targetEntity"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public void UpdateAsync( |
||||
|
CardRegister sourceEntity, |
||||
|
CardRegister targetEntity |
||||
|
) |
||||
|
{ |
||||
|
Check.NotNull<CardRegister>(sourceEntity, nameof(sourceEntity)); |
||||
|
Check.NotNull<CardRegister>(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<CardRegister>(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<CardRegister>(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<Guid>(entity.CardTypeId, nameof(entity.CardTypeId)); |
||||
|
Check.NotNull<Guid>(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},是无效值"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue