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.
 
 
 
 
 
 

97 lines
3.3 KiB

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;
/// <summary>
/// QAD物料清单(Bom)
/// </summary>
//[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;
}
/// <summary>
/// 物料清单(Bom)
/// </summary>
/// <param name="input">物料清单(Bom)</param>
/// <returns></returns>
[HttpPost("")]
[Volo.Abp.Uow.UnitOfWork(isTransactional: false)]
public virtual async Task<ActionResult<BomDto>> AddAsync(BomInput input)
{
var entityObj = ObjectMapper.Map<BomInput, Bom>(input);
entityObj.Parent = input.ParentCode;
entityObj.Component = input.ComponentCode;
entityObj.Ref2 = input.Reference;
try
{
Validator.CheckCompany(_configuration, entityObj.Company);
var targetObj = ObjectMapper.Map<Bom, BomEditInput>(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<Bom, BomDto>(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<ValidationResult>
{
new(dto.ErrorMessage)
});
}
else
{
return new OkObjectResult(dto);
}
}
}