using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; 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 Win_in.Sfs.Wms.Store.Application.Contracts; namespace Win_in.Sfs.Wms.DataExchange.Application.Iac.Qad; /// /// QAD采购收货单(Receipt master) /// //[Authorize(IncomingToWmsPermissions.Default)] [Microsoft.AspNetCore.Components.Route($"{DataExchangeConsts.RouteRoot}receipt")] [ApiExplorerSettings(GroupName = SwaggerGroupConsts.WmsWebApi)] public class ReceiptAppService : ApplicationService, IReceiptAppService { private readonly IPurchaseReceiptNoteAppService _purchaseReceiptNoteAppService; private readonly IReceiptRepository _receiptMstrRepository; private readonly IConfiguration _configuration; private readonly IItemBasicAppService _itemBasicAppService; public ReceiptAppService( IPurchaseReceiptNoteAppService purchaseReceiptNoteAppService, IPurchaseReturnNoteAppService purchaseReturnNoteAppService, IItemBasicAppService itemBasicAppService, IReceiptRepository receiptMstrRepository, IConfiguration configuration ) { _purchaseReceiptNoteAppService = purchaseReceiptNoteAppService; _receiptMstrRepository = receiptMstrRepository; _configuration = configuration; _itemBasicAppService = itemBasicAppService; } /// /// 采购收货单(Receipt) /// /// QAD采购收货单(Receipt) /// [HttpPost("")] [Volo.Abp.Uow.UnitOfWork(isTransactional: false)] public virtual async Task> AddAsync(ReceiptMstrInput 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 特殊转换 foreach (var srcDtlObj in entityObj.Details) { var tarDtlObj = targetObj.Details.FirstOrDefault(itm => itm.PoLine == srcDtlObj.PoLine.ToString()); if (tarDtlObj == null) { continue; } tarDtlObj.Uom = srcDtlObj.Um; tarDtlObj.Qty = srcDtlObj.Qty; tarDtlObj.StdPackQty = srcDtlObj.Qty; tarDtlObj.PoNumber = entityObj.PoNbr; //调用业务接口,新增或更新业务数据 var item = await _itemBasicAppService.GetByCodeAsync(tarDtlObj.ItemCode).ConfigureAwait(false); if (item != null) { tarDtlObj.ItemName = item.Name; tarDtlObj.ItemDesc1 = item.Desc1; tarDtlObj.ItemDesc2 = item.Desc2; } } #endregion await _purchaseReceiptNoteAppService.CreateAsync(targetObj).ConfigureAwait(false); } catch (Exception ex) { var baseEx = ex.GetBaseException(); entityObj.ErrorCode = 1; entityObj.ErrorMessage = baseEx.Message; } var ret = await _receiptMstrRepository.InsertAsync(entityObj, true).ConfigureAwait(false); entityObj.SetIdAndDetailId(GuidGenerator); 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); } } }