123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using HTEXLib.COMM.Helpers;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.Extension;
- namespace TEAMModelOS.SDK.Models.Service
- {
- public sealed class KnowledgeService
- {
- public static List<PointNode> TreeToList(List<PointTree> trees, List<PointNode> nodes/*, List<Block> blocks,HashSet<string> points*/)
- {
- List<PointNode> list = new List<PointNode>();
- trees.ForEach(x => {
- List<string> cids = new List<string>();
- if (x.children.IsNotEmpty())
- {
- x.children.ForEach(y => { cids.Add(y.id); /*points.Add(y.name); */y.pid=x.id; });
- }
- var node = new PointNode
- {
- name = x.name,
- id = x.id,
- pid = x.pid,
- cids= cids,
- used =x.used,
- link = x.link,
- };
- list.Add(node);
- //blocks.Add(new Block { name= x.name,points=x.nodes.Select(x=>x.name).ToList() });
- //points.Add(x.name);
- });
-
- nodes.AddRange(list);
- foreach (PointTree tree in trees)
- {
- if (null != tree.children && tree.children.Count > 0)
- {
- TreeToList(tree.children, nodes/*, blocks, points*/);
- }
- }
- return nodes;
- }
- public static List<PointTree> ListToTree(List<PointNode> noes)
- {
- List<PointTree> list = noes.ToJsonString().ToObject<List<PointTree>>();
- var res = from r in list group r by r.id into g select g;
- Dictionary<string, PointTree> blockDict = new Dictionary<string, PointTree>();
- foreach (var s in res)
- {
- blockDict.TryAdd(s.First().id, s.First());
- }
- return GetChild(list, blockDict);
- }
- private static List<PointTree> GetChild(List<PointTree> list, Dictionary<string, PointTree> dict)
- {
- // list = list.OrderBy(m => m.Order).ToList();
- List<PointTree> trees = new List<PointTree>();
- foreach (PointTree node in list)
- {
- bool flag = dict.TryGetValue(node.pid, out PointTree syllabus);
- if (flag && syllabus != null)
- {
- syllabus.children.Add(node);
- }
- else
- {
- trees.Add(node);
- }
- }
- return trees;
- }
- static public List<string> GetChildIds(PointTree node)
- {
- List<string> childIds = new List<string>();
- if (node.children != null)
- {
- foreach (PointTree child in node.children)
- {
- childIds.Add(child.id);
- var cids = GetChildIds(child);
- childIds.AddRange(cids);
- child.cids=cids.Count>100 ? child.children.Select(x => x.id).ToList() : cids;
- }
- }
- return childIds;
- }
- }
- }
|