You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
5.6 KiB
153 lines
5.6 KiB
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Threading.Tasks;
|
|
using FluentValidation;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Volo.Abp.Application.Dtos;
|
|
using Volo.Abp.Application.Services;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.MultiTenancy;
|
|
using Volo.Abp.Uow;
|
|
using Volo.Abp.Validation;
|
|
using Win_in.Sfs.Scp.v1.Domain;
|
|
using Volo.Abp.TenantManagement;
|
|
|
|
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;
|
|
private readonly ITaVenderRepository _taVenderRepository;
|
|
private readonly ITenantStore _tenantStore;
|
|
private readonly ITenantRepository _tenantRepository;
|
|
private readonly IDataFilter _dataFilter;
|
|
|
|
public UnplannedReceiptAppService(
|
|
IUnplannedReceiptRepository repository
|
|
, ITbReceiptRepository tbReceiptRepository
|
|
, ITbReceiptDetailRepository tbReceiptDetailRepository
|
|
, ITaVenderRepository taVenderRepository
|
|
, ITenantStore tenantStore
|
|
, ITenantRepository tenantRepository
|
|
, IDataFilter dataFilter
|
|
) : base(repository)
|
|
{
|
|
_unplannedReceiptRepository = repository;
|
|
_tbReceiptRepository = tbReceiptRepository;
|
|
_tbReceiptDetailRepository = tbReceiptDetailRepository;
|
|
_taVenderRepository = taVenderRepository;
|
|
_tenantStore = tenantStore;
|
|
_tenantRepository = tenantRepository;
|
|
_dataFilter = dataFilter;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 按ID获取计划外入库单 (Get unplanned receipt by ID)
|
|
/// </summary>
|
|
/// <param name="id">唯一ID(unique ID)</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("{id}")]
|
|
[HiddenApi]
|
|
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("paged-list")]
|
|
[HiddenApi]
|
|
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<ActionResult<UnplannedReceiptDTO>> CreateAsync(
|
|
UnplannedReceiptCreateDTO receiptCreateDTO)
|
|
{
|
|
var entity = ObjectMapper.Map<UnplannedReceiptCreateDTO, UnplannedReceipt>(receiptCreateDTO);
|
|
|
|
try
|
|
{
|
|
Validator.CheckSite(_tenantRepository, entity.Site);
|
|
Validator.CheckSite(_tenantRepository, entity.Company);
|
|
var tenant = await _tenantStore.FindAsync(entity.Site);
|
|
using (CurrentTenant.Change(tenant.Id, tenant.Name))
|
|
{
|
|
using (_dataFilter.Disable<IMultiTenant>())
|
|
{
|
|
|
|
Validator.CheckSupplierCode(_taVenderRepository, entity.Site, entity.Address);
|
|
|
|
await UpsertTbReceiptAndTbReceiptDetailAsync(entity, tenant.Id);
|
|
await CurrentUnitOfWork.SaveChangesAsync();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var baseEx = ex.GetBaseException();
|
|
entity.ErrorCode = 1;
|
|
entity.ErrorMessage = baseEx.Message;
|
|
}
|
|
|
|
|
|
var ret = await _unplannedReceiptRepository.InsertAsync(entity);
|
|
var dto = ObjectMapper.Map<UnplannedReceipt, UnplannedReceiptDTO>(ret);
|
|
dto.CreationTime = Clock.Now;
|
|
if (dto.ErrorCode != 0)
|
|
{
|
|
throw new AbpValidationException(new List<ValidationResult>
|
|
{
|
|
new(dto.ErrorMessage)
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return new OkObjectResult(dto);
|
|
}
|
|
}
|
|
|
|
private async Task UpsertTbReceiptAndTbReceiptDetailAsync(UnplannedReceipt entity, Guid tenantId)
|
|
{
|
|
//使用AutoMapper执行类型转换
|
|
var tbReceipt = ObjectMapper.Map<UnplannedReceipt, TB_RECEIVE_QAD>(entity);
|
|
var tbReceiveDetail = ObjectMapper.Map<UnplannedReceipt, TB_RECEIVE_DETAIL_QAD>(entity);
|
|
tbReceipt.TenantId = tenantId;
|
|
|
|
//根据传入数据新增或修改SCP数据
|
|
await _tbReceiptRepository.UpsertAsync(tbReceipt);
|
|
|
|
tbReceiveDetail.TenantId = tenantId;
|
|
//根据传入数据新增或修改SCP数据
|
|
await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail);
|
|
}
|
|
}
|
|
}
|