72 lines
2.2 KiB

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace Win_in.Sfs.Scp.WebApi
{
/// <summary>
/// 采购订单服务
/// </summary>
[Authorize]
[Route(RouteConsts.PurchaseOrder)]
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.ScpWebApi)]
public class PurchaseOrderAppService : ReadOnlyAppService<PurchaseOrder, PurchaseOrderDTO, Guid,RequestDTO>, IPurchaseOrderAppService
{
private readonly IPurchaseOrderRepository _purchaseOrderRepository;
public PurchaseOrderAppService(IPurchaseOrderRepository repository) : base(repository)
{
_purchaseOrderRepository = repository;
}
/// <summary>
/// 按ID获取采购订单 (Get purchase order by ID)
/// </summary>
/// <param name="id">唯一ID(unique ID)</param>
/// <returns></returns>
[HttpGet]
[Route("{id}")]
public override async Task<PurchaseOrderDTO> GetAsync(Guid id)
{
return await base.GetAsync(id);
}
/// <summary>
/// 按条件获取采购订单列表 (Get purchase order list by request condition)
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("")]
public override async Task<PagedResultDto<PurchaseOrderDTO>> GetListAsync(RequestDTO input)
{
return await base.GetListAsync(input);
}
/// <summary>
/// 新增采购订单(Create New purchase order)
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("")]
public async Task<PurchaseOrderDTO> CreateAsync(PurchaseOrderCreateDTO poCreateDTO)
{
var entity = ObjectMapper.Map<PurchaseOrderCreateDTO, PurchaseOrder>(poCreateDTO);
3 years ago
foreach (var detail in entity.Details)
{
detail.SetId(GuidGenerator);
}
var ret = await _purchaseOrderRepository.InsertAsync(entity);
var dto = ObjectMapper.Map<PurchaseOrder, PurchaseOrderDTO>(ret);
return dto;
}
}
}