t提交4
This commit is contained in:
parent
6953cb1bb5
commit
f8c1ab1bf7
@ -13,6 +13,7 @@ using System.Linq;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Mapster;
|
||||
using System.Xml.Linq;
|
||||
using static Org.BouncyCastle.Crypto.Engines.SM2Engine;
|
||||
|
||||
|
||||
namespace DOAN.Service.MES.base_
|
||||
@ -132,7 +133,7 @@ namespace DOAN.Service.MES.base_
|
||||
/// <returns></returns>
|
||||
public int ADDBOMBind(string id, string parent_id)
|
||||
{
|
||||
BaseMaterialBom bom=new BaseMaterialBom();
|
||||
BaseMaterialBom bom = new BaseMaterialBom();
|
||||
bom.FkId = id;
|
||||
bom.FkParentId = parent_id;
|
||||
bom.CreatedTime = DateTime.Now;
|
||||
@ -147,52 +148,75 @@ namespace DOAN.Service.MES.base_
|
||||
/// <returns></returns>
|
||||
public List<BaseMaterialListDto> Achieve_BOM_no_bind(BaseMaterialListQueryDto3 query)
|
||||
{
|
||||
string[] binded_array= Context.Queryable<BaseMaterialBom>().Where(it => it.FkId == query.Id).Select(it=>it.FkId).ToArray();
|
||||
string[] binded_array = Context.Queryable<BaseMaterialBom>().Where(it => it.FkId == query.Id).Select(it => it.FkId).ToArray();
|
||||
if (binded_array != null && binded_array.Count() > 0)
|
||||
{
|
||||
//在原材料和半成品中 选择
|
||||
List<BaseMaterialType> typeList= Context.Queryable<BaseMaterialType>().Where(it => it.Id == 5).Where(it => it.Id == 1).ToList();
|
||||
int[] leaf= FindLeafNodes(typeList).Select(it=>it.Id).ToArray();
|
||||
List<BaseMaterialType> typeList = Context.Queryable<BaseMaterialType>().ToList();
|
||||
int[] leaf = FindLeafNodes(typeList, 1).Select(it => it.Id).ToArray();
|
||||
int[] leaf2 = FindLeafNodes(typeList, 5).Select(it => it.Id).ToArray();
|
||||
int[] leaf3 = leaf.Concat(leaf2).ToArray();
|
||||
var predicate = Expressionable.Create<BaseMaterialList>()
|
||||
.AndIF(!string.IsNullOrEmpty(query.Name),it=>it.Name.Contains(query.Name))
|
||||
.AndIF(!string.IsNullOrEmpty(query.Code),it=>it.Name.Contains(query.Code))
|
||||
.AndIF(!string.IsNullOrEmpty(query.CustomerCode),it=>it.Name.Contains(query.CustomerCode))
|
||||
.AndIF(!string.IsNullOrEmpty(query.Name), it => it.Name.Contains(query.Name))
|
||||
.AndIF(!string.IsNullOrEmpty(query.Code), it => it.Name.Contains(query.Code))
|
||||
.AndIF(!string.IsNullOrEmpty(query.CustomerCode), it => it.Name.Contains(query.CustomerCode))
|
||||
;
|
||||
|
||||
return Context.Queryable<BaseMaterialList>().Where(it => !binded_array.Contains(it.Id))
|
||||
.Where(it => leaf.Contains(it.FkTypeId.Value)).ToList().Adapt<List<BaseMaterialListDto>>();
|
||||
return Context.Queryable<BaseMaterialList>().Where(it => !binded_array.Contains(it.Id))
|
||||
.Where(it => leaf3.Contains(it.FkTypeId.Value)).ToList().Adapt<List<BaseMaterialListDto>>();
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
|
||||
|
||||
return new List<BaseMaterialListDto>();
|
||||
}
|
||||
|
||||
// 假设nodes是一个列表,包含了所有的Node对象
|
||||
public static List<BaseMaterialType> FindLeafNodes(List<BaseMaterialType> nodes, int parentId = 0)
|
||||
public static List<BaseMaterialType> FindLeafNodes(List<BaseMaterialType> nodes, int ancestorId)
|
||||
{
|
||||
List<BaseMaterialType> leafNodes = new List<BaseMaterialType>();
|
||||
List<BaseMaterialType> leaves = new List<BaseMaterialType>();
|
||||
|
||||
// 查找当前parentId下的所有子节点
|
||||
var children = nodes.FindAll(node => node.ParentId == parentId);
|
||||
|
||||
// 如果没有子节点,说明是叶子节点
|
||||
if (children.Count == 0)
|
||||
return leafNodes;
|
||||
|
||||
// 对每个子节点递归查找其下的叶子节点
|
||||
foreach (var child in children)
|
||||
bool IsLeaf(BaseMaterialType node, Dictionary<int, BaseMaterialType> nodeMap)
|
||||
{
|
||||
var subLeafNodes = FindLeafNodes(nodes, child.Id);
|
||||
leafNodes.AddRange(subLeafNodes);
|
||||
return !nodeMap.Values.Any(child => child.ParentId == node.Id);
|
||||
}
|
||||
|
||||
// 如果这个节点没有子节点(即所有子节点都是叶子节点),则它本身也是叶子节点
|
||||
if (leafNodes.Count == children.Count)
|
||||
leafNodes.Add(nodes.FirstOrDefault(n => n.Id == parentId));
|
||||
void TraverseForLeaves(BaseMaterialType node, int targetAncestorId, Dictionary<int, BaseMaterialType> nodeMap, List<BaseMaterialType> currentPath)
|
||||
{
|
||||
currentPath.Add(node);
|
||||
if (node.Id == targetAncestorId)
|
||||
{
|
||||
// 如果当前节点是目标祖先节点,开始检查路径上的节点是否为叶子
|
||||
foreach (var pathNode in currentPath)
|
||||
{
|
||||
if (IsLeaf(pathNode, nodeMap))
|
||||
{
|
||||
leaves.Add(pathNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (nodeMap.ContainsKey(node.Id))
|
||||
{
|
||||
// 继续递归遍历子节点
|
||||
foreach (var child in nodeMap.Values.Where(child => child.ParentId == node.Id))
|
||||
{
|
||||
TraverseForLeaves(child, targetAncestorId, nodeMap, new List<BaseMaterialType>(currentPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return leafNodes;
|
||||
// 构建节点ID到节点对象的映射,便于查找
|
||||
Dictionary<int, BaseMaterialType> nodeMap = new Dictionary<int, BaseMaterialType>();
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
nodeMap[node.Id] = node;
|
||||
}
|
||||
|
||||
// 从根节点开始遍历
|
||||
foreach (var root in nodeMap.Values.Where(n => n.ParentId == 0)) // 假设根节点的ParentId为0
|
||||
{
|
||||
TraverseForLeaves(root, ancestorId, nodeMap, new List<BaseMaterialType>());
|
||||
}
|
||||
|
||||
return leaves;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user