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.
 
 
 
 
 
 

82 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 ICustomerAppService = Win_in.Sfs.Wms.DataExchange.Application.Contracts.Iac.Qad.ICustomerAppService;
namespace Win_in.Sfs.Wms.DataExchange.Application.Iac.Qad;
/// <summary>
/// QAD客户(Customer)
/// </summary>
//[Authorize(IncomingToWmsPermissions.Default)]
[Microsoft.AspNetCore.Components.Route($"{DataExchangeConsts.RouteRoot}customer")]
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.WmsWebApi)]
public class CustomerAppService : ApplicationService, ICustomerAppService
{
private readonly Basedata.Application.Contracts.ICustomerAppService _customerAppService;
private readonly ICustRepository _custRepository;
private readonly IConfiguration _configuration;
public CustomerAppService(
Basedata.Application.Contracts.ICustomerAppService customerAppService,
ICustRepository custRepository,
IConfiguration configuration
)
{
_customerAppService = customerAppService;
_custRepository = custRepository;
_configuration = configuration;
}
/// <summary>
/// 客户(Customer)
/// </summary>
/// <param name="input">QAD客户(Customer)</param>
/// <returns></returns>
[HttpPost("")]
[Volo.Abp.Uow.UnitOfWork(isTransactional: false)]
public virtual async Task<ActionResult<CustDto>> AddAsync(CustInput input)
{
var entityObj = ObjectMapper.Map<CustInput, Cust>(input);
try
{
Validator.CheckCompany(_configuration, entityObj.Company);
var targetObj = ObjectMapper.Map<Cust, CustomerEditInput>(entityObj);
await _customerAppService.UpsertAsync(targetObj).ConfigureAwait(false);
}
catch (Exception ex)
{
var baseEx = ex.GetBaseException();
entityObj.ErrorCode = 1;
entityObj.ErrorMessage = baseEx.Message;
}
_ = await _custRepository.InsertAsync(entityObj, true).ConfigureAwait(false);
var dto = ObjectMapper.Map<Cust, CustDto>(entityObj);
dto.CreationTime = Clock.Now;
if (dto.ErrorCode != 0)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(dto.ErrorMessage)
});
}
else
{
return new OkObjectResult(dto);
}
}
}