123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using HTEXLib.COMM.Helpers;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- namespace TEAMModelOS.SDK
- {
- public static class ActivityService
- {
- public static async Task<ReviewRule> UpsertReviewRule(ReviewRuleTree reviewRuleTree,Activity activity,AzureCosmosFactory _azureCosmos)
- {
- var nodes = new List<RuleConfig>();
- nodes= TreeToList(reviewRuleTree.trees, nodes);
- ReviewRule reviewRule = new ReviewRule() {
- id= activity.id,
- code="ReviewRule-disposable",
- pk="ReviewRule",
- name=reviewRuleTree.name,
- owner=activity.owner,
- type="disposable",
- configs=nodes,
- sourceName=activity.name
- };
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.Normal).UpsertItemAsync(reviewRule);
- if (reviewRuleTree.upsertAsTemplate==1) {
- reviewRule.code="ReviewRule-template";
- reviewRule.type="template";
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).UpsertItemAsync(reviewRule);
- }
- return reviewRule;
- }
- public static List<RuleConfig> TreeToList(List<RuleConfigTree> trees, List<RuleConfig> nodes) {
- trees = trees.OrderBy(x => x.order).ToList();
- List<RuleConfig> list = new List<RuleConfig>();
- trees.ForEach(x => {
- List<string> cids = new List<string>();
- if (x.children.IsNotEmpty())
- {
- x.children.ForEach(y => cids.Add(y.id));
- }
- var node = new RuleConfig
- {
-
- id = x.id,
- pid = x.pid,
- cids= cids,
- label = x.label,
- score = x.score,
- order = x.order,
- };
- list.Add(node);
- });
- nodes.AddRange(list);
- foreach (RuleConfigTree tree in trees)
- {
- if (null != tree.children && tree.children.Count > 0)
- {
- TreeToList(tree.children, nodes);
- }
- }
- return nodes;
- }
- public static List<RuleConfigTree> ListToTree(List<RuleConfig> noes)
- {
- List<RuleConfigTree> list = noes.ToJsonString().ToObject<List<RuleConfigTree>>();
- var res = from r in list group r by r.id into g select g;
- Dictionary<string, RuleConfigTree> blockDict = new Dictionary<string, RuleConfigTree>();
- foreach (var s in res)
- {
- blockDict.TryAdd(s.First().id, s.First());
- }
- return GetChild(list, blockDict);
- }
- private static List<RuleConfigTree> GetChild(List<RuleConfigTree> list, Dictionary<string, RuleConfigTree> dict)
- {
- List<RuleConfigTree> trees = new List<RuleConfigTree>();
- trees = trees.OrderBy(x => x.order).ToList();
- foreach (RuleConfigTree node in list)
- {
- bool flag = dict.TryGetValue(node.pid, out RuleConfigTree syllabus);
- if (flag && syllabus != null)
- {
- syllabus.children.Add(node);
- }
- else
- {
- trees.Add(node);
- }
- }
- return trees;
- }
- }
- }
|