1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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.nodes.IsNotEmpty())
- {
- x.nodes.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.nodes && tree.nodes.Count > 0)
- {
- TreeToList(tree.nodes, 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.nodes.Add(node);
- }
- else
- {
- trees.Add(node);
- }
- }
- return trees;
- }
- }
- }
|