创建采购订单接口
This commit is contained in:
@@ -75,6 +75,18 @@ namespace Yi.Framework.Service.Base.Crud
|
||||
return entitydto;
|
||||
}
|
||||
|
||||
|
||||
public async virtual Task CreateAsync(IEnumerable<TCreateInput> dtos)
|
||||
{
|
||||
|
||||
var entity = await MapToEntitysAsync(dtos);
|
||||
|
||||
TryToSetTenantId(entity);
|
||||
|
||||
//这边需要进行判断,实体是什么guid还是雪花id
|
||||
await Repository.InsertReturnSnowflakeIdAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
@@ -126,6 +138,19 @@ namespace Yi.Framework.Service.Base.Crud
|
||||
MapToEntity(updateInput, entity);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将 批量更新输入dto转化为实体的异步
|
||||
/// </summary>
|
||||
/// <param name="updateInput"></param>
|
||||
/// <param name="entity"></param>
|
||||
protected virtual async Task<List<TEntity>> MapToEntitysAsync(IEnumerable<TCreateInput> updateInput)
|
||||
{
|
||||
List<TEntity> entitys = MapToEntitys(updateInput);
|
||||
|
||||
return await Task.FromResult(entitys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将 更新输入dto转化为实体的同步方法
|
||||
/// </summary>
|
||||
@@ -136,6 +161,17 @@ namespace Yi.Framework.Service.Base.Crud
|
||||
ObjectMapper.Map(updateInput, entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将 批量更新输入dto转化为实体的同步方法
|
||||
/// </summary>
|
||||
/// <param name="updateInput"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual List<TEntity> MapToEntitys(IEnumerable<TCreateInput> updateInput)
|
||||
{
|
||||
return ObjectMapper.Map<List<TEntity>>(updateInput);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建dto 给 实体的转换的异步方法
|
||||
/// </summary>
|
||||
@@ -203,6 +239,16 @@ namespace Yi.Framework.Service.Base.Crud
|
||||
//}
|
||||
}
|
||||
|
||||
protected virtual void TryToSetTenantId(IEnumerable<TEntity> entitys)
|
||||
{
|
||||
foreach (var entity in entitys)
|
||||
{
|
||||
TryToSetTenantId(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 判断租户id的属性是否为空
|
||||
/// </summary>
|
||||
|
||||
@@ -14,12 +14,17 @@ using Yi.Framework.Service.Base.Crud;
|
||||
|
||||
namespace Yi.Framework.Service.ERP
|
||||
{
|
||||
public class PurchaseService : CrudAppService<PurchaseEntity, PurchaseGetListOutput, long, PurchaseCreateUpdateInput>, IPurchaseService
|
||||
public class PurchaseService : CrudAppService<PurchaseEntity, PurchaseGetListOutput, long, PurchaseCreateInput, PurchaseUpdateInput>, IPurchaseService
|
||||
{
|
||||
public PurchaseService(IRepository<PurchaseEntity> repository, IMapper mapper) : base(repository, mapper)
|
||||
private readonly ISugarUnitOfWork<UnitOfWork> _unitOfWork;
|
||||
private readonly IPurchaseDetailsService _purchaseDetailsService;
|
||||
public PurchaseService(IRepository<PurchaseEntity> repository, IMapper mapper, ISugarUnitOfWork<UnitOfWork> unitOfWork,
|
||||
IPurchaseDetailsService purchaseDetailsService) : base(repository, mapper)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_purchaseDetailsService = purchaseDetailsService;
|
||||
}
|
||||
public async Task<PageModel<List<PurchaseGetListOutput>>> PageListAsync(PurchaseCreateUpdateInput input, PageParModel page)
|
||||
public async Task<PageModel<List<PurchaseGetListOutput>>> PageListAsync(PurchaseGetListInput input, PageParModel page)
|
||||
{
|
||||
RefAsync<int> totalNumber = 0;
|
||||
var data = await Repository._DbQueryable
|
||||
@@ -28,5 +33,23 @@ namespace Yi.Framework.Service.ERP
|
||||
.ToPageListAsync(page.PageNum, page.PageSize, totalNumber);
|
||||
return new PageModel<List<PurchaseGetListOutput>> { Total = totalNumber.Value, Data = await MapToGetListOutputDtosAsync(data) };
|
||||
}
|
||||
|
||||
public override async Task<PurchaseGetListOutput> CreateAsync(PurchaseCreateInput input)
|
||||
{
|
||||
|
||||
using (var uow = _unitOfWork.CreateContext())
|
||||
{
|
||||
var entity = await MapToEntityAsync(input);
|
||||
entity.PaidMoney = 0;
|
||||
entity.TotalMoney = input.PurchaseDetails.Sum(u => u.UnitPrice * u.TotalNumber);
|
||||
entity.PurchaseState = PurchaseStateEnum.Build;
|
||||
TryToSetTenantId(entity);
|
||||
var purchaseId = await Repository.InsertReturnSnowflakeIdAsync(entity);
|
||||
|
||||
await _purchaseDetailsService.CreateAsync(input.PurchaseDetails);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user