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.

239 lines
8.2 KiB

2 years ago
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Caching;
using Volo.Abp.Domain.Repositories;
using Win_in.Sfs.Basedata.Application.Contracts;
using Win_in.Sfs.Basedata.Boms;
using Win_in.Sfs.Basedata.Boms.DTOs;
2 years ago
using Win_in.Sfs.Basedata.Domain;
using Win_in.Sfs.Basedata.Domain.Shared;
namespace Win_in.Sfs.Basedata.Application;
[Authorize]
[Route($"{BasedataConsts.RootPath}bom")]
public class BomAppService :
SfsBaseDataAppServiceBase<Bom, BomDTO, SfsBaseDataRequestInputBase, BomEditInput, BomImportInput>,
IBomAppService
{
1 year ago
2 years ago
private new readonly IBomRepository _repository;
private readonly IBomManager _bomManager;
private List<BomComponent> _bomList = new();
1 year ago
2 years ago
public BomAppService(IBomRepository repository
, IBomManager bomManager
, IDistributedCache<BomDTO> cache
) : base(repository, cache)
2 years ago
{
_repository = repository;
_bomManager = bomManager;
base.CreatePolicyName = BomPermissions.Create;
base.UpdatePolicyName = BomPermissions.Update;
base.DeletePolicyName = BomPermissions.Delete;
}
1 year ago
2 years ago
#region Get
[HttpGet("get-by-productitemcode")]
[AllowAnonymous]
public virtual async Task<List<BomDTO>> GetListAsync(string productItemCode, string mfgOp)
{
var entities = await _repository.GetListAsync(p => p.Product == productItemCode
// && p.MFGOp == mfgOp
2 years ago
).ConfigureAwait(false);
return ObjectMapper.Map<List<Bom>, List<BomDTO>>(entities);
}
[HttpGet("list/for-preparation-plan")]
public virtual async Task<List<BomDTO>> GetPlanListAsync(string productItemCode, string mfgOp)
{
var entities = await _bomManager.GetListWithPhantomItemAsync(productItemCode, mfgOp, Clock.Now, true)
.ConfigureAwait(false);
2 years ago
return ObjectMapper.Map<List<Bom>, List<BomDTO>>(entities);
}
[HttpGet("list/for-backflush")]
public virtual async Task<List<BomDTO>> GetBackFlushListAsync(string productItemCode, string mfgOp)
{
var entities = await _bomManager.GetListWithPhantomItemAsync(productItemCode, mfgOp, Clock.Now, false)
.ConfigureAwait(false);
2 years ago
return ObjectMapper.Map<List<Bom>, List<BomDTO>>(entities);
}
[HttpGet("get-by-productitemcode-sbs")]
public virtual async Task<List<BomDTO>> GetBomStepByStepAsync(string productItemCode, DateTime validTime,
bool isStepByStep = true)
2 years ago
{
var entities = await _bomManager.GetRecursiveListAsync(productItemCode, validTime, isStepByStep)
.ConfigureAwait(false);
2 years ago
return ObjectMapper.Map<List<Bom>, List<BomDTO>>(entities);
}
/// <summary>
/// 所有子物料号
2 years ago
/// </summary>
/// <param name="product"></param>
/// <returns></returns>
[HttpGet("get-list-by-product")]
public virtual async Task<List<Bom>> GetListOfProductAsync(string product)
{
return await _bomManager.GetListOfProductAsync(product).ConfigureAwait(false);
}
/// <summary>
/// 所有父物料号
2 years ago
/// </summary>
/// <param name="component"></param>
/// <returns></returns>
[HttpGet("get-list-by-component")]
public virtual async Task<List<Bom>> GetListOfComponentAsync(string component)
{
return await _bomManager.GetListOfComponentAsync(component).ConfigureAwait(false);
}
/// <summary>
/// 获取bomtree
/// </summary>
/// <param name="productCode"></param>
/// <returns></returns>
[HttpGet("get-bom-tree-by-code")]
public virtual async Task<List<BomDTO>> GetBomTreeByCodeAsync(string productCode)
{
var entities = await _bomManager.GetAllItemByCode(productCode).ConfigureAwait(false);
var dtos = ObjectMapper.Map<List<Bom>, List<BomDTO>>(entities);
2 years ago
return dtos;
}
2 years ago
/// <summary>
/// 获取所有子物料关系
2 years ago
/// </summary>
/// <param name="component"></param>
/// <returns></returns>
[HttpGet("get-list-by-component-with-tree")]
public virtual async Task<List<BomDTO>> GetBomTreeAsync(string component)
{
var entities = (await _bomManager.GetListOfProductAsync(component).ConfigureAwait(false))
.FindAll(t => t.Component != component);
var dtos = ObjectMapper.Map<List<Bom>, List<BomDTO>>(entities);
return await GetChildBomsAsync(dtos).ConfigureAwait(false);
}
private async Task<List<BomDTO>> GetChildBomsAsync(List<BomDTO> dtos)
{
foreach (var dto in dtos)
{
var entities = (await _bomManager.GetListOfProductAsync(dto.Component).ConfigureAwait(false))
.FindAll(t => t.Component != dto.Component);
2 years ago
if (entities.Count > 0)
{
dto.ComponentDTOs = await GetChildBomsAsync(ObjectMapper.Map<List<Bom>, List<BomDTO>>(entities))
.ConfigureAwait(false);
2 years ago
}
}
return dtos;
}
#endregion Get
[HttpPost("upsert")]
public virtual async Task UpsertAsync(BomEditInput input)
{
var entity = ObjectMapper.Map<BomEditInput, Bom>(input);
entity.ComponentUom = input.ComponentUom;
entity.ComponentQty = input.ComponentQty;
await _repository.UpsertAsync(entity).ConfigureAwait(false);
}
2 years ago
[HttpPost("upsert-interface")]
public virtual async Task UpsertAsyncByInterface(BomEditInput input)
{
var entity = ObjectMapper.Map<BomEditInput, Bom>(input);
entity.ComponentUom = input.ComponentUom;
entity.ComponentQty = input.ComponentQty;
await _repository.UpsertAsyncByInterface(entity);
}
2 years ago
[HttpPost("add-upsert-lsit")]
public virtual async Task AddOrUpsertListAsync(List<BomEditInput> inputs)
{
var entitys = new List<Bom>();
2 years ago
foreach (var input in inputs)
{
var oldBom = await _repository
.FirstOrDefaultAsync(t => t.Product == input.Product && t.Component == input.Component)
.ConfigureAwait(false);
2 years ago
if (oldBom == null)
{
var entity = ObjectMapper.Map<BomEditInput, Bom>(input);
entity.ComponentUom = input.ComponentUom;
entity.ComponentQty = input.ComponentQty;
entitys.Add(entity);
}
else
{
oldBom.ComponentUom = input.ComponentUom;
oldBom.ComponentQty = input.ComponentQty;
oldBom.BeginTime = input.BeginTime;
oldBom.EndTime = input.EndTime;
entitys.Add(oldBom);
}
}
2 years ago
await _repository.BulkMergeAsync(entitys).ConfigureAwait(false);
}
protected override async Task ValidateImportModelAsync(BomImportInput importInput,
List<ValidationResult> validationRresult)
2 years ago
{
await CheckProductAsync(importInput.Product, validationRresult).ConfigureAwait(false);
await CheckComponentAndComponentQtyAsync(importInput.Component, importInput.ComponentQty, validationRresult)
.ConfigureAwait(false);
2 years ago
}
/// <summary>
/// 根据总成号、总成数量取所有子物料及其汇总数量
/// </summary>
/// <param name="productCode">总成号</param>
/// <param name="productNum">总成数量</param>
/// <returns></returns>
[HttpGet("get-material-total-qty")]
public virtual async Task<List<BomDTO>> GetMaterialTotalQtyAsync(string productCode, int productNum)
{
var entities = await _bomManager.GetMaterialTotalQtyAsync(productCode, productNum).ConfigureAwait(false);
return ObjectMapper.Map<List<Bom>, List<BomDTO>>(entities);
}
[HttpPost("get_bom_sublist")]
public async Task<List<BomComponentDTO>> GetSubcomponentsRecursiveList(List<BomComponentDTO> p_lst,
EnumBomSelectedType p_type
)
{
var entities = ObjectMapper.Map<List<BomComponentDTO>, List<BomComponent>>(p_lst);
var list = await _bomManager.GetSubcomponentsRecursiveList(entities, p_type).ConfigureAwait(false);
var sublist = ObjectMapper.Map<List<BomComponent>, List<BomComponentDTO>>(list);
return sublist;
}
2 years ago
}