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; namespace Win_in.Sfs.Wms.DataExchange.Application.Iac.Qad; /// /// QAD供应商物料(vendor part) /// //[Authorize(IncomingToWmsPermissions.Default)] [Microsoft.AspNetCore.Components.Route($"{DataExchangeConsts.RouteRoot}supplier-part")] [ApiExplorerSettings(GroupName = SwaggerGroupConsts.WmsWebApi)] public class SupplierPartAppService : ApplicationService, ISupplierPartAppService { private readonly Basedata.Application.Contracts.ISupplierItemAppService _supplierItemAppService; private readonly IVend_partRepository _vend_partRepository; private readonly IConfiguration _configuration; public SupplierPartAppService( Basedata.Application.Contracts.ISupplierItemAppService supplierItemAppService, IVend_partRepository vend_partRepository, IConfiguration configuration ) { _supplierItemAppService = supplierItemAppService; _vend_partRepository = vend_partRepository; _configuration = configuration; } /// /// 供应商物料(Supplier Part) /// /// QAD供应商物料(Supplier Part) /// [HttpPost("")] [Volo.Abp.Uow.UnitOfWork(isTransactional: false)] public virtual async Task> AddAsync(VendPartInput input) { var entityObj = ObjectMapper.Map(input); try { //调用业务接口前,先做业务数据校验 //数据格式校验使用ABP提供的校验模块(Application.Contract.XXXInputValidator),不需要在这里实现 Validator.CheckSite(_configuration, entityObj.Site); Validator.CheckCompany(_configuration, entityObj.Company); var targetObj = ObjectMapper.Map(entityObj); #region 特殊转换 targetObj.SupplierPackQty = entityObj.VendPackQty; targetObj.SupplierPackUom = entityObj.VendPackUm; #endregion await _supplierItemAppService.UpsertAsync(targetObj).ConfigureAwait(false); } catch (Exception ex) { var baseEx = ex.GetBaseException(); entityObj.ErrorCode = 1; entityObj.ErrorMessage = baseEx.Message; } _ = await _vend_partRepository.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); } } }