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.
258 lines
8.4 KiB
258 lines
8.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Threading.Tasks;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
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;
|
|
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
|
|
{
|
|
//private readonly CacheService _cacheService;
|
|
|
|
private new readonly IBomRepository _repository;
|
|
private readonly IBomManager _bomManager;
|
|
|
|
|
|
|
|
public BomAppService(IBomRepository repository
|
|
, IBomManager bomManager
|
|
, IDistributedCache<BomDTO> cache
|
|
//, CacheService cacheService
|
|
) : base(repository, cache)
|
|
{
|
|
_repository = repository;
|
|
_bomManager = bomManager;
|
|
//_cacheService = cacheService;
|
|
base.CreatePolicyName = BomPermissions.Create;
|
|
base.UpdatePolicyName = BomPermissions.Update;
|
|
base.DeletePolicyName = BomPermissions.Delete;
|
|
//_cacheService.StartAsync().ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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
|
|
).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);
|
|
|
|
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);
|
|
|
|
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)
|
|
{
|
|
var entities = await _bomManager.GetRecursiveListAsync(productItemCode, validTime, isStepByStep).ConfigureAwait(false);
|
|
return ObjectMapper.Map<List<Bom>, List<BomDTO>>(entities);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 所有子物料号
|
|
/// </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>
|
|
/// 所有父物料号
|
|
/// </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);
|
|
|
|
return dtos;
|
|
}
|
|
/// <summary>
|
|
/// 获取所有子物料关系
|
|
/// </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);
|
|
|
|
if (entities.Count > 0)
|
|
{
|
|
dto.ComponentDTOs = await GetChildBomsAsync(ObjectMapper.Map<List<Bom>, List<BomDTO>>(entities)).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|
|
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);
|
|
return;
|
|
}
|
|
|
|
[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);
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("add-upsert-lsit")]
|
|
public virtual async Task AddOrUpsertListAsync(List<BomEditInput> inputs)
|
|
{
|
|
List<Bom> entitys = new List<Bom>();
|
|
foreach (var input in inputs)
|
|
{
|
|
var oldBom = await _repository.FirstOrDefaultAsync(t => t.Product == input.Product && t.Component == input.Component).ConfigureAwait(false);
|
|
|
|
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);
|
|
}
|
|
}
|
|
await _repository.BulkMergeAsync(entitys).ConfigureAwait(false);
|
|
return;
|
|
}
|
|
|
|
protected override async Task ValidateImportModelAsync(BomImportInput importInput, List<ValidationResult> validationRresult)
|
|
{
|
|
await base.CheckProductAsync(importInput.Product, validationRresult).ConfigureAwait(false);
|
|
await base.CheckComponentAndComponentQtyAsync(importInput.Component, importInput.ComponentQty, validationRresult).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|