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.
178 lines
7.4 KiB
178 lines
7.4 KiB
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Threading.Tasks;
|
|
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;
|
|
using Microsoft.IdentityModel.Logging;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Win_in.Sfs.Scp.WebApi
|
|
{
|
|
/// <summary>
|
|
/// 收货单服务
|
|
/// </summary>
|
|
[Authorize]
|
|
[Route(RouteConsts.Receipt)]
|
|
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.ScpWebApi)]
|
|
public class ReceiptAppService : ReadOnlyAppService<Receipt, ReceiptDTO, Guid, RequestDTO>, IReceiptAppService
|
|
{
|
|
private readonly IReceiptRepository _receiptRepository;
|
|
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 ReceiptAppService(
|
|
IReceiptRepository repository
|
|
, ITbReceiptRepository tbReceiptRepository
|
|
, ITbReceiptDetailRepository tbReceiptDetailRepository
|
|
, ITaVenderRepository taVenderRepository
|
|
, ITenantStore tenantStore
|
|
, ITenantRepository tenantRepository
|
|
, IDataFilter dataFilter
|
|
) : base(repository)
|
|
{
|
|
_receiptRepository = repository;
|
|
_tbReceiptRepository = tbReceiptRepository;
|
|
_tbReceiptDetailRepository = tbReceiptDetailRepository;
|
|
_taVenderRepository = taVenderRepository;
|
|
_tenantStore = tenantStore;
|
|
_tenantRepository = tenantRepository;
|
|
_dataFilter = dataFilter;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 按ID获取收货单 (Get receipt by ID)
|
|
/// </summary>
|
|
/// <param name="id">唯一ID(unique ID)</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("{id}")]
|
|
[HiddenApi]
|
|
public override async Task<ReceiptDTO> GetAsync(Guid id)
|
|
{
|
|
return await base.GetAsync(id);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 按请求条件获取收货单列表(Get 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<ReceiptDTO>> GetListAsync(RequestDTO requestDTO)
|
|
{
|
|
return await base.GetListAsync(requestDTO);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 新增收货单(Create receipt)
|
|
/// </summary>
|
|
/// <param name="receiptCreateDTO"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("")]
|
|
|
|
public virtual async Task<ActionResult<ReceiptDTO>> CreateAsync(ReceiptCreateDTO receiptCreateDTO)
|
|
{
|
|
var entity = ObjectMapper.Map<ReceiptCreateDTO, Receipt>(receiptCreateDTO);
|
|
|
|
try
|
|
{
|
|
Validator.CheckSite(_tenantRepository, entity.Site);
|
|
Validator.CheckSite(_tenantRepository, entity.Company);
|
|
var tenant = await _tenantStore.FindAsync(entity.Site);
|
|
bool flag = true;
|
|
using (CurrentTenant.Change(tenant.Id, tenant.Name))
|
|
{
|
|
using (_dataFilter.Disable<IMultiTenant>())
|
|
{
|
|
|
|
Validator.CheckSupplierCode(_taVenderRepository, entity.Site, entity.SupplierCode);
|
|
flag =await _tbReceiptRepository.GetCountAsync(ObjectMapper.Map<Receipt, TB_RECEIVE_QAD>(entity));
|
|
if (!flag)
|
|
{
|
|
var tbReceipt = ObjectMapper.Map<Receipt, TB_RECEIVE_QAD>(entity);
|
|
Logger.LogInformation("TB_RECEIVE_QAD存在!Site = " + tbReceipt.Site + " ErpRecvBillNum = " +
|
|
tbReceipt.ErpRecvBillNum + " AsnBillNum = " + tbReceipt.AsnBillNum + " BillType = " + tbReceipt.BillType + " CreateTime = " + tbReceipt.CreateTime +
|
|
" State = " + tbReceipt.State
|
|
);
|
|
}
|
|
await UpsertTbReceiptAndTbReceiptDetailAsync(entity, tenant.Id/*, flag*/);
|
|
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var qad = ObjectMapper.Map<Receipt, TB_RECEIVE_QAD>(entity);
|
|
|
|
Logger.LogInformation("TB_RECEIVE_QAD!Site = " + qad.Site + " ErpRecvBillNum = " +
|
|
qad.ErpRecvBillNum + " AsnBillNum = " + qad.AsnBillNum + " BillType = " + qad.BillType + " CreateTime = " + qad.CreateTime +
|
|
" State = " + qad.State
|
|
);
|
|
var detail_qad = ObjectMapper.Map<Receipt,TB_RECEIVE_DETAIL_QAD>(entity);
|
|
Logger.LogInformation("TB_RECEIVE_DETAIL_QAD!Site = " + detail_qad.Site + " ErpRecvBillNum = " +
|
|
detail_qad.ErpRecvBillNum + " PoLine = " + detail_qad.PoLine + " BillType = " + detail_qad.BillType + " CreateTime = " + detail_qad.CreateTime +
|
|
" State = " + detail_qad.State + " qty = " + detail_qad.Qty + " DockCode = " + detail_qad.DockCode + " Batch =" + detail_qad.Batch +
|
|
" VendBatch = " + detail_qad.VendBatch + " Remark =" + detail_qad.Remark + " PoUnit= " + detail_qad.PoUnit + " Rate =" + detail_qad.Rate
|
|
);
|
|
var baseEx = ex.GetBaseException();
|
|
entity.ErrorCode = 1;
|
|
entity.ErrorMessage = baseEx.Message;
|
|
}
|
|
|
|
var ret = await _receiptRepository.InsertAsync(entity);
|
|
var dto = ObjectMapper.Map<Receipt, ReceiptDTO>(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(Receipt entity, Guid tenantId/*,bool flag*/)
|
|
{
|
|
|
|
//使用AutoMapper执行类型转换
|
|
var tbReceipt = ObjectMapper.Map<Receipt, TB_RECEIVE_QAD>(entity);
|
|
var tbReceiveDetail = ObjectMapper.Map<Receipt, TB_RECEIVE_DETAIL_QAD>(entity);
|
|
tbReceipt.TenantId = tenantId;
|
|
//if (flag)
|
|
//{
|
|
//根据传入数据新增或修改SCP数据
|
|
await _tbReceiptRepository.UpsertAsync(tbReceipt);
|
|
//}
|
|
tbReceiveDetail.TenantId = tenantId;
|
|
//根据传入数据新增或修改SCP数据
|
|
await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail);
|
|
await CurrentUnitOfWork.SaveChangesAsync();
|
|
|
|
}
|
|
}
|
|
}
|