|
|
|
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;
|
|
|
|
using Volo.Abp.Uow;
|
|
|
|
using Win_in.Sfs.Scp.v1.Domain;
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Scp.WebApi
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 计划外入库单服务
|
|
|
|
/// </summary>
|
|
|
|
[Authorize]
|
|
|
|
[Route(RouteConsts.UnplannedReceipt)]
|
|
|
|
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.ScpWebApi)]
|
|
|
|
public class UnplannedReceiptAppService : ReadOnlyAppService<UnplannedReceipt, UnplannedReceiptDTO, Guid,RequestDTO>, IUnplannedReceiptAppService
|
|
|
|
{
|
|
|
|
private readonly IUnplannedReceiptRepository _unplannedReceiptRepository;
|
|
|
|
private readonly ITbReceiptRepository _tbReceiptRepository;
|
|
|
|
private readonly ITbReceiptDetailRepository _tbReceiptDetailRepository;
|
|
|
|
|
|
|
|
public UnplannedReceiptAppService(
|
|
|
|
IUnplannedReceiptRepository repository
|
|
|
|
, ITbReceiptRepository tbReceiptRepository
|
|
|
|
, ITbReceiptDetailRepository tbReceiptDetailRepository
|
|
|
|
) : base(repository)
|
|
|
|
{
|
|
|
|
_unplannedReceiptRepository = repository;
|
|
|
|
_tbReceiptRepository = tbReceiptRepository;
|
|
|
|
_tbReceiptDetailRepository = tbReceiptDetailRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 按ID获取计划外入库单 (Get unplanned receipt by ID)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">唯一ID(unique ID)</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("{id}")]
|
|
|
|
public override async Task<UnplannedReceiptDTO> GetAsync(Guid id)
|
|
|
|
{
|
|
|
|
return await base.GetAsync(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 按请求条件获取计划外入库单列表(Get unplanned receipt list by request condition)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="requestDTO">请求条件DTO(Request condition DTO)</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[Route("")]
|
|
|
|
public override async Task<PagedResultDto<UnplannedReceiptDTO>> GetListAsync(RequestDTO requestDTO)
|
|
|
|
{
|
|
|
|
return await base.GetListAsync(requestDTO);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 新增计划外入库单(Create unplanned receipt)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="receiptCreateDTO"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
[Route("")]
|
|
|
|
public virtual async Task<UnplannedReceiptDTO> CreateAsync(UnplannedReceiptCreateDTO receiptCreateDTO)
|
|
|
|
{
|
|
|
|
var entity = ObjectMapper.Map<UnplannedReceiptCreateDTO, UnplannedReceipt>(receiptCreateDTO);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
await UpsertTbReceiptAndTbReceiptDetailAsync(entity);
|
|
|
|
await CurrentUnitOfWork.SaveChangesAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
entity.ErrorCode = 1;
|
|
|
|
entity.ErrorMessage = ex.Message;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ret = await _unplannedReceiptRepository.InsertAsync(entity);
|
|
|
|
var dto = ObjectMapper.Map<UnplannedReceipt, UnplannedReceiptDTO>(ret);
|
|
|
|
return dto;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task UpsertTbReceiptAndTbReceiptDetailAsync(UnplannedReceipt entity)
|
|
|
|
{
|
|
|
|
var tbReceipt = ObjectMapper.Map<UnplannedReceipt, TB_RECEIVE_QAD>(entity);
|
|
|
|
//根据传入数据新增或修改SCP数据
|
|
|
|
await _tbReceiptRepository.UpsertAsync(tbReceipt);
|
|
|
|
|
|
|
|
//使用AutoMapper执行类型转换
|
|
|
|
var tbReceiveDetail = ObjectMapper.Map<UnplannedReceipt, TB_RECEIVE_DETAIL_QAD>(entity);
|
|
|
|
//根据传入数据新增或修改SCP数据
|
|
|
|
await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|