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.
 
 
 
 
 
 

83 lines
2.7 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.Basedata.Application.Contracts;
using Win_in.Sfs.Wms.DataExchange.Application.Contracts.Iac.Qad;
using Win_in.Sfs.Wms.DataExchange.Domain.Iac.Qad;
using ISupplierAppService = Win_in.Sfs.Wms.DataExchange.Application.Contracts.Iac.Qad.ISupplierAppService;
namespace Win_in.Sfs.Wms.DataExchange.Application.Iac.Qad;
/// <summary>
/// QAD供应商(Vendor)
/// </summary>
//[Authorize(IncomingToWmsPermissions.Default)]
[Microsoft.AspNetCore.Components.Route($"{DataExchangeConsts.RouteRoot}supplier")]
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.WmsWebApi)]
public class SupplierAppService : ApplicationService, ISupplierAppService
{
private readonly Basedata.Application.Contracts.ISupplierAppService _supplierAppService;
private readonly IVendRepository _vendRepository;
private readonly IConfiguration _configuration;
public SupplierAppService(
Basedata.Application.Contracts.ISupplierAppService supplierAppService,
IVendRepository vendRepository,
IConfiguration configuration
)
{
_supplierAppService = supplierAppService;
_vendRepository = vendRepository;
_configuration = configuration;
}
/// <summary>
/// 供应商(Supplier)
/// </summary>
/// <param name="input">QAD供应商(Supplier)</param>
/// <returns></returns>
[HttpPost("")]
[Volo.Abp.Uow.UnitOfWork(isTransactional: false)]
public virtual async Task<ActionResult<VendDto>> AddAsync(VendInput input)
{
var entityObj = ObjectMapper.Map<VendInput, Vend>(input);
try
{
Validator.CheckCompany(_configuration, entityObj.Company);
var targetObj = ObjectMapper.Map<Vend, SupplierEditInput>(entityObj);
//targetObj.Type = entityObj.Type;
await _supplierAppService.UpsertAsync(targetObj).ConfigureAwait(false);
}
catch (Exception ex)
{
var baseEx = ex.GetBaseException();
entityObj.ErrorCode = 1;
entityObj.ErrorMessage = baseEx.Message;
}
_ = await _vendRepository.InsertAsync(entityObj, true).ConfigureAwait(false);
var dto = ObjectMapper.Map<Vend, VendDto>(entityObj);
dto.CreationTime = Clock.Now;
if (dto.ErrorCode != 0)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(dto.ErrorMessage)
});
}
else
{
return new OkObjectResult(dto);
}
}
}