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; /// /// QAD客户(Customer) /// //[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; } /// /// 客户(Customer) /// /// QAD客户(Customer) /// [HttpPost("")] [Volo.Abp.Uow.UnitOfWork(isTransactional: false)] public virtual async Task> AddAsync(CustInput input) { var entityObj = ObjectMapper.Map(input); try { Validator.CheckCompany(_configuration, entityObj.Company); var targetObj = ObjectMapper.Map(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(entityObj); dto.CreationTime = Clock.Now; if (dto.ErrorCode != 0) { throw new AbpValidationException(new List { new(dto.ErrorMessage) }); } else { return new OkObjectResult(dto); } } }