|
@@ -1,7 +1,11 @@
|
|
|
using Azure.Cosmos;
|
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
|
+using DocumentFormat.OpenXml.ExtendedProperties;
|
|
|
+using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
+using Microsoft.Azure.Cosmos.Linq;
|
|
|
+using OpenXmlPowerTools;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -24,34 +28,116 @@ namespace TEAMModelOS.SDK.Services
|
|
|
/// <param name="pid"></param>
|
|
|
/// <param name="newNodes"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async static Task<HashSet<Tnode>> ImportSyllabus(List<List<string>> nodes,string volumeId,string scope ,string code , AzureCosmosFactory azureCosmos) {
|
|
|
- List<Syllabus> syllabuses= new List<Syllabus>();
|
|
|
+ public async static Task<(List<List<IdCode>> idCodes, HashSet<Syllabus> syllabus)> ImportSyllabus(List<List<string>> nodes,string volumeId,string scope ,string code,string creatorId ,string creatorName, AzureCosmosFactory azureCosmos, bool ignoreCharacter = true) {
|
|
|
+ HashSet<Syllabus> syllabuses= new HashSet<Syllabus>();
|
|
|
string tbname = scope.Equals("school", StringComparison.OrdinalIgnoreCase) ? Constant.School : Constant.Teacher;
|
|
|
await foreach (var item in azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<Syllabus>(queryText: $"select value(c) from c where c.volumeId='{volumeId}'",
|
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{code}") })) {
|
|
|
syllabuses.Add(item);
|
|
|
}
|
|
|
-
|
|
|
+ HashSet<Syllabus> chapters = new HashSet<Syllabus>();
|
|
|
+ long now= DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ List<List<IdCode> > resNodes = new List<List<IdCode>>();
|
|
|
foreach (var points in nodes) {
|
|
|
+ // points 作为 层级路径 ["汽车考照", "汽车法规","驾驶道德、交通安全常识及行车安全检查与维护"]
|
|
|
int level = 0;
|
|
|
+ // 根节点 作为章节进行当前 路径操作的主要对象
|
|
|
Syllabus chapter = null;
|
|
|
+ //用于记录 ["汽车考照", "汽车法规","驾驶道德、交通安全常识及行车安全检查与维护"] 标题的id 路径
|
|
|
+ List<(string title, string id)> nodesVal = new List<(string title, string id)>();
|
|
|
+ //上一次操作的 id 用于方便检索下一层级时作为pid
|
|
|
+ string lastId =null;
|
|
|
foreach (var point in points) {
|
|
|
- string pt = Regex.Replace(point, "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
|
|
|
+ string express = "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]";
|
|
|
+ //是否开启特殊符号的正则过滤
|
|
|
+ string pt = ignoreCharacter? Regex.Replace(point, express, ""):point;
|
|
|
if (level == 0)
|
|
|
{
|
|
|
- var sylbs = syllabuses.SelectMany(z => z.children).Where(c => c.pid.Equals(volumeId) && c.title.Equals(Regex.Replace(point, "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ")));
|
|
|
+ var sylbs = syllabuses.SelectMany(z => z.children).Where(c => c.pid.Equals(volumeId) && pt.Equals(ignoreCharacter? Regex.Replace(c.title, express, ""): c.title));
|
|
|
if (sylbs.Any())
|
|
|
{
|
|
|
- chapter = syllabuses.Find(z=>z.id.Equals(sylbs.First().id));
|
|
|
- if (chapter == null) { }
|
|
|
+ //找到相关的章节
|
|
|
+ chapter = syllabuses.Where(z=>z.id.Equals(sylbs.First().id)).FirstOrDefault();
|
|
|
+ if (chapter == null )
|
|
|
+ {
|
|
|
+ foreach (var item in syllabuses)
|
|
|
+ {
|
|
|
+ var it = item.children.Find(z => z.id.Equals(sylbs.First().id));
|
|
|
+ if (it != null)
|
|
|
+ {
|
|
|
+ item.id = sylbs.First().id;
|
|
|
+ chapter = item;
|
|
|
+ chapters.Add(chapter);
|
|
|
+ lastId = item.id;
|
|
|
+ nodesVal.Add((point, item.id));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ chapters.Add(chapter);
|
|
|
+ lastId = chapter.id;
|
|
|
+ nodesVal.Add((point, sylbs.First().id));
|
|
|
+ }
|
|
|
}
|
|
|
+ else {
|
|
|
+ //未找到相关的章节
|
|
|
+ string id = id = Guid.NewGuid().ToString();
|
|
|
+ lastId= id;
|
|
|
+ chapter = new Syllabus {
|
|
|
+ id = id,
|
|
|
+ volumeId = volumeId,
|
|
|
+ code = $"Syllabus-{code}",
|
|
|
+ pk = "Syllabus",
|
|
|
+ ttl = -1,
|
|
|
+ scope= scope,
|
|
|
+ children= new List<Tnode> { new Tnode {id = id ,pid=volumeId, creatorId = creatorId,
|
|
|
+ creatorName = creatorName,title=pt,updateTime= now} }
|
|
|
+ };
|
|
|
+ chapters.Add(chapter);
|
|
|
+ syllabuses.Add(chapter);
|
|
|
+ nodesVal.Add((point, id));
|
|
|
+ }
|
|
|
+ //下钻一层
|
|
|
+ level += 1;
|
|
|
}
|
|
|
- else {
|
|
|
-
|
|
|
+ else {
|
|
|
+ if (!string.IsNullOrWhiteSpace(lastId))
|
|
|
+ {
|
|
|
+ var child = chapter.children.Find(child => child.pid.Equals(lastId) && pt.Equals(ignoreCharacter ? Regex.Replace(child.title, express, "") : child.title));
|
|
|
+ if (child == null)
|
|
|
+ {
|
|
|
+ string id = id = Guid.NewGuid().ToString();
|
|
|
+ child = new Tnode {
|
|
|
+ id = id,
|
|
|
+ pid = lastId,
|
|
|
+ creatorId = creatorId,
|
|
|
+ creatorName = creatorName,
|
|
|
+ title = pt,
|
|
|
+ updateTime = now
|
|
|
+ };
|
|
|
+ chapter.children.Add(child);
|
|
|
+ lastId = child.id;
|
|
|
+ nodesVal.Add((point, child.id));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ lastId= child.id;
|
|
|
+ nodesVal.Add((point, child.id));
|
|
|
+ }
|
|
|
+ level += 1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if (chapter != null) {
|
|
|
+ resNodes.Add(nodesVal.Select(z => new IdCode { id = z.id, code = z.title }).ToList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach(var chapter in chapters)
|
|
|
+ {
|
|
|
+ await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(chapter);
|
|
|
}
|
|
|
- return null;
|
|
|
+
|
|
|
+ return (resNodes,chapters);
|
|
|
}
|
|
|
|
|
|
|