|
|
@ -4,9 +4,13 @@ using System.Linq; |
|
|
|
using System.Linq.Expressions; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using NetTopologySuite.Geometries; |
|
|
|
using Omu.ValueInjecter; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp.Domain.Services; |
|
|
|
using Win_in.Sfs.Basedata.Boms; |
|
|
|
using Win_in.Sfs.Basedata.Domain.Shared; |
|
|
|
using Win_in.Sfs.Shared.Domain; |
|
|
|
using Win_in.Sfs.Shared.Domain.Shared; |
|
|
|
|
|
|
@ -213,4 +217,132 @@ public class BomManager : DomainService, IBomManager |
|
|
|
} |
|
|
|
return lst; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Bom操作
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p_component"></param>
|
|
|
|
/// <param name="p_type"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task<List<Bom>> GetSubcomponentsRecursiveLast(BomComponent p_component, EnumBomSelectedType p_type |
|
|
|
) |
|
|
|
{ |
|
|
|
List<BomComponent> lastList = new List<BomComponent>(); |
|
|
|
List<BomComponent> dimensionList=new List<BomComponent>(); |
|
|
|
var treeList=await GetSubcomponentsRecursive(p_component, 1, p_component.ComponentQty, p_component.Component, |
|
|
|
(rs) => lastList.Add(rs) |
|
|
|
, |
|
|
|
(rs1)=>{ |
|
|
|
dimensionList.Add(rs1); |
|
|
|
}).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Bom> lastBomList = new List<Bom>(); |
|
|
|
List<Bom> dimensionBomList = new List<Bom>(); |
|
|
|
List<Bom> treeBomList = new List<Bom>(); |
|
|
|
foreach (var itm in dimensionList) |
|
|
|
{ |
|
|
|
Bom bom = new Bom(); |
|
|
|
bom.InjectFrom(itm); |
|
|
|
dimensionBomList.Add(bom); |
|
|
|
} |
|
|
|
foreach (var itm in lastList) |
|
|
|
{ |
|
|
|
Bom bom = new Bom(); |
|
|
|
bom.InjectFrom(itm); |
|
|
|
lastBomList.Add(bom); |
|
|
|
} |
|
|
|
foreach (var itm in treeList) |
|
|
|
{ |
|
|
|
Bom bom = new Bom(); |
|
|
|
bom.InjectFrom(itm); |
|
|
|
treeBomList.Add(bom); |
|
|
|
} |
|
|
|
List<Bom> returnList=new List<Bom>(); |
|
|
|
switch (p_type) |
|
|
|
{ |
|
|
|
case EnumBomSelectedType.Last: |
|
|
|
returnList.AddRange(lastBomList); |
|
|
|
break; |
|
|
|
case EnumBomSelectedType.Tree: |
|
|
|
returnList.AddRange(treeBomList); |
|
|
|
break; |
|
|
|
case EnumBomSelectedType.Dimension: |
|
|
|
returnList.AddRange(dimensionBomList); |
|
|
|
break; |
|
|
|
} |
|
|
|
return returnList; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 层级、拆解、一维结构、树状结构
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p_component">上级组件(初始时为根元素)</param>
|
|
|
|
/// <param name="level">层级一般为1</param>
|
|
|
|
/// <param name="sumQty">累计数量</param>
|
|
|
|
/// <param name="root">根</param>
|
|
|
|
/// <param name="p_actionLast">拆解到最终零件时</param>
|
|
|
|
/// <param name="p_actionDimension">树型转成一维表用</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task<List<BomComponent>> GetSubcomponentsRecursive(BomComponent p_component, int level, decimal sumQty, string root, Action<BomComponent> p_actionLast, |
|
|
|
Action<BomComponent> p_actionDimension |
|
|
|
) |
|
|
|
{ |
|
|
|
List<BomComponent> subComponents = new List<BomComponent>(); |
|
|
|
// 假设 GetComponentsByProduct 方法可获取某个物料号下的所有子零件
|
|
|
|
List<BomComponent> directSubComponents =await GetComponentsByProduct(p_component.Component).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (!directSubComponents.Any() && level != 1)//不是根元素
|
|
|
|
{ |
|
|
|
p_actionLast(p_component); |
|
|
|
} |
|
|
|
foreach (var component in directSubComponents) |
|
|
|
{ |
|
|
|
component.Root = root; |
|
|
|
component.SumQty = sumQty * component.ComponentQty; |
|
|
|
component.ParentComponent = p_component.Component; |
|
|
|
component.Level = level; |
|
|
|
component.SubComponents =await GetSubcomponentsRecursive(component, level + 1, sumQty * component.ComponentQty, component.Root, p_actionLast, p_actionDimension).ConfigureAwait(false); |
|
|
|
p_actionDimension(component); |
|
|
|
subComponents.Add(component); |
|
|
|
} |
|
|
|
return subComponents; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<List<BomComponent>> GetComponentsByProduct(string product) |
|
|
|
{ |
|
|
|
|
|
|
|
var list= await _repository.GetListAsync(p => p.Product == product).ConfigureAwait(false); |
|
|
|
List<BomComponent> components = new List<BomComponent>(); |
|
|
|
foreach (var component in list) |
|
|
|
{ |
|
|
|
BomComponent bomComponent = new BomComponent(); |
|
|
|
bomComponent.InjectFrom(component); |
|
|
|
components.Add(bomComponent); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 其他物料号的子零件信息类似添加
|
|
|
|
return components; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|