using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; 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 IBomAppService = Win_in.Sfs.Wms.DataExchange.Application.Contracts.Iac.Qad.IBomAppService; namespace Win_in.Sfs.Wms.DataExchange.Application.Iac.Qad; /// /// QAD物料清单(Bom) /// //[Authorize(IncomingToWmsPermissions.Default)] [Authorize] [Microsoft.AspNetCore.Components.Route($"{DataExchangeConsts.RouteRoot}bom")] [ApiExplorerSettings(GroupName = SwaggerGroupConsts.WmsWebApi)] public class BomAppService : ApplicationService, IBomAppService { private readonly Basedata.Application.Contracts.IBomAppService _bomAppService; private readonly IBomRepository _bomRepository; private readonly IConfiguration _configuration; public BomAppService( Basedata.Application.Contracts.IBomAppService bomAppService, IBomRepository bomRepository, IConfiguration configuration ) { _bomAppService = bomAppService; _bomRepository = bomRepository; _configuration = configuration; } /// /// 物料清单(Bom) /// /// 物料清单(Bom) /// [HttpPost("")] [Volo.Abp.Uow.UnitOfWork(isTransactional: false)] public virtual async Task> AddAsync(BomInput input) { var entityObj = ObjectMapper.Map(input); entityObj.Parent = input.ParentCode; entityObj.Component = input.ComponentCode; entityObj.Ref2 = input.Reference; try { Validator.CheckCompany(_configuration, entityObj.Company); var targetObj = ObjectMapper.Map(entityObj); #region 特殊转换 targetObj.ComponentQty = entityObj.PerQty; targetObj.BeginTime = entityObj.StartDate; targetObj.EndTime = entityObj.EndDate; //targetObj.Product = entityObj.Parent; //CreateMap_bom方法中已经配置 //targetObj.Component = entityObj.Component; #endregion await _bomAppService.UpsertAsync(targetObj).ConfigureAwait(false); } catch (Exception ex) { var baseEx = ex.GetBaseException(); entityObj.ErrorCode = 1; entityObj.ErrorMessage = baseEx.Message; } _ = await _bomRepository.InsertAsync(entityObj, true).ConfigureAwait(false); var dto = ObjectMapper.Map(entityObj); dto.ParentCode = entityObj.Parent; dto.ComponentCode = entityObj.Component; dto.Reference = entityObj.Ref2; dto.CreationTime = Clock.Now; if (dto.ErrorCode != 0) { throw new AbpValidationException(new List { new(dto.ErrorMessage) }); } else { return new OkObjectResult(dto); } } }