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.
 
 
 
 
 
 

95 lines
3.4 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
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.Inventory.Application.Contracts;
using IInventoryBalanceAppService = Win_in.Sfs.Wms.DataExchange.Application.Contracts.Iac.Qad.IBalanceAppService;
namespace Win_in.Sfs.Wms.DataExchange.Application.Iac.Qad;
/// <summary>
/// QAD实时库存(Inventory balance)
/// </summary>
//[Authorize(IncomingToWmsPermissions.Default)]
[Microsoft.AspNetCore.Components.Route($"{DataExchangeConsts.RouteRoot}inventory")]
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.WmsWebApi)]
public class InventoryBalanceAppService : ApplicationService, IInventoryBalanceAppService
{
private readonly IErpBalanceAppService _erpBalanceAppService;
private readonly IInventoryRepository _inventoryRepository;
private readonly IConfiguration _configuration;
public InventoryBalanceAppService(
IErpBalanceAppService erpBalanceAppService,
IInventoryRepository inventoryRepository,
IConfiguration configuration
)
{
_erpBalanceAppService = erpBalanceAppService;
_inventoryRepository = inventoryRepository;
_configuration = configuration;
}
/// <summary>
/// 库存余额(Inventory Balance)
/// </summary>
/// <param name="input">QAD实时库存(Inventory balance)</param>
/// <returns></returns>
[HttpPost("")]
[Volo.Abp.Uow.UnitOfWork(isTransactional: false)]
public virtual async Task<ActionResult<InventoryDto>> AddAsync(InventoryInput input)
{
var entityObj = ObjectMapper.Map<InventoryInput, Domain.Iac.Qad.Inventory>(input);
try
{
//调用业务接口前,先做业务数据校验
//数据格式校验使用ABP提供的校验模块(Application.Contract.XXXInputValidator),不需要在这里实现
Validator.CheckSite(_configuration, entityObj.Site);
Validator.CheckCompany(_configuration, entityObj.Company);
var targetObj = ObjectMapper.Map<Domain.Iac.Qad.Inventory, ErpBalanceEditInput>(entityObj);
targetObj.Qty = entityObj.Qty;
targetObj.Uom = entityObj.Um;
targetObj.Lot ??= string.Empty;
//try
//{
await _erpBalanceAppService.UpsertAsync(targetObj).ConfigureAwait(false);
//}
//catch //??
//{
// Console.WriteLine("_erpBalanceAppService.UpsertAsync报错!");
//}
}
catch (Exception ex)
{
var baseEx = ex.GetBaseException();
entityObj.ErrorCode = 1;
entityObj.ErrorMessage = baseEx.Message;
}
_ = await _inventoryRepository.InsertAsync(entityObj, true).ConfigureAwait(false);
var dto = ObjectMapper.Map<Domain.Iac.Qad.Inventory, InventoryDto>(entityObj);
dto.CreationTime = Clock.Now;
if (dto.ErrorCode != 0)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(dto.ErrorMessage)
});
}
else
{
return new OkObjectResult(dto);
}
}
}