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.
105 lines
3.9 KiB
105 lines
3.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Volo.Abp.Application.Services;
|
|
using Volo.Abp.Validation;
|
|
using Win_in.Sfs.Wms.DataExchange.Application.Contracts.Iac.Qad;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Iac.Qad;
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
|
using IPurchaseOrderAppService = Win_in.Sfs.Wms.DataExchange.Application.Contracts.Iac.Qad.IPurchaseOrderAppService;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Application.Iac.Qad;
|
|
|
|
/// <summary>
|
|
/// QAD采购订单(PO master)
|
|
/// </summary>
|
|
//[Authorize(IncomingToWmsPermissions.Default)]
|
|
[Microsoft.AspNetCore.Components.Route($"{DataExchangeConsts.RouteRoot}po")]
|
|
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.WmsWebApi)]
|
|
public class PurchaseOrderAppService : ApplicationService, IPurchaseOrderAppService
|
|
{
|
|
//private readonly Store.Application.Contracts.IPurchaseOrderAppService _purchaseOrderAppService;
|
|
|
|
private readonly IPo_mstrRepository _po_mstrRepository;
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public PurchaseOrderAppService(
|
|
Store.Application.Contracts.IPurchaseOrderAppService purchaseOrderAppService,
|
|
IPo_mstrRepository po_mstrRepository,
|
|
IConfiguration configuration
|
|
)
|
|
{
|
|
//_purchaseOrderAppService = purchaseOrderAppService;
|
|
_po_mstrRepository = po_mstrRepository;
|
|
_configuration = configuration;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 采购订单(PO)
|
|
/// </summary>
|
|
/// <param name="input">QAD采购订单(PO)</param>
|
|
/// <returns></returns>
|
|
[HttpPost("")]
|
|
[Volo.Abp.Uow.UnitOfWork(isTransactional: false)]
|
|
public virtual async Task<ActionResult<PoMstrDto>> AddAsync(PoMstrInput input)
|
|
{
|
|
|
|
var entityObj = ObjectMapper.Map<PoMstrInput, PoMstr>(input);
|
|
try
|
|
{
|
|
//调用业务接口前,先做业务数据校验
|
|
//数据格式校验使用ABP提供的校验模块(Application.Contract.XXXInputValidator),不需要在这里实现
|
|
Validator.CheckSite(_configuration, entityObj.Site);
|
|
Validator.CheckCompany(_configuration, entityObj.Company);
|
|
var targetObj = ObjectMapper.Map<PoMstr, PurchaseOrderEditInput>(entityObj);//?? 包含明细列表的源对象 转换成 单一目标对象
|
|
|
|
#region 特殊转换
|
|
string billNum = targetObj.Number;
|
|
foreach (var srcDtlObj in entityObj.Details)
|
|
{
|
|
var tarDtlObj = targetObj.Details.FirstOrDefault(itm => itm.PoLine == srcDtlObj.PoLine.ToString());
|
|
if (tarDtlObj != null)
|
|
{
|
|
tarDtlObj.Uom = srcDtlObj.Um;
|
|
tarDtlObj.Qty = srcDtlObj.RcQty;
|
|
tarDtlObj.StdPackQty = srcDtlObj.StdPackQty ?? 0;
|
|
tarDtlObj.SupplierPackUom = srcDtlObj.VendPackUm;
|
|
tarDtlObj.SupplierPackQty = srcDtlObj.VendPackQty;
|
|
}
|
|
}
|
|
targetObj.ContactName = entityObj.Contacts;
|
|
targetObj.ContactPhone = "";
|
|
targetObj.ContactEmail = "";
|
|
#endregion
|
|
|
|
//await _purchaseOrderAppService.UpsertAsync(targetObj).ConfigureAwait(false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var baseEx = ex.GetBaseException();
|
|
entityObj.ErrorCode = 1;
|
|
entityObj.ErrorMessage = baseEx.Message;
|
|
}
|
|
var ret = await _po_mstrRepository.InsertAsync(entityObj, true).ConfigureAwait(false);
|
|
|
|
var dto = ObjectMapper.Map<PoMstr, PoMstrDto>(entityObj);
|
|
dto.CreationTime = Clock.Now;
|
|
if (dto.ErrorCode != 0)
|
|
{
|
|
throw new AbpValidationException(new List<ValidationResult>
|
|
{
|
|
new(dto.ErrorMessage)
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return new OkObjectResult(dto);
|
|
}
|
|
}
|
|
|
|
}
|
|
|