CrazyIter_Bin 2 years ago
parent
commit
4c45f46175

+ 32 - 4
TEAMModelOS.SDK/Models/Service/Common/SyllabusService.cs

@@ -1,4 +1,5 @@
 using Azure.Cosmos;
+using DocumentFormat.OpenXml.Drawing;
 using DocumentFormat.OpenXml.ExtendedProperties;
 using DocumentFormat.OpenXml.Office2010.Excel;
 using DocumentFormat.OpenXml.Wordprocessing;
@@ -27,7 +28,7 @@ namespace TEAMModelOS.SDK.Services
         /// <param name="pid"></param>
         /// <param name="newNodes"></param>
         /// <returns></returns>
-        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) { 
+        public async static Task<(List<List<IdCode>> idCodes, List<SyllabusTreeNode> tree)> 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}'",
@@ -134,6 +135,7 @@ namespace TEAMModelOS.SDK.Services
                 }
             }
             bool volumeChange=false;
+            List<SyllabusTreeNode> treeNodes = new List<SyllabusTreeNode>();
             foreach (var chapter in chapters)
             {
                 if (!volume.syllabusIds.Contains(chapter.id)) {
@@ -141,11 +143,37 @@ namespace TEAMModelOS.SDK.Services
                     volumeChange = true;
                 }
                 await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(chapter);
+                List<SyllabusTree> trees = SyllabusService.ListToTree(chapter.children);
+                SyllabusTreeNode tree = new SyllabusTreeNode() { id = chapter.id, scope = chapter.scope, trees = trees, volumeId = chapter.volumeId, auth = chapter.auth, codeval = volume.school };
+                treeNodes.Add(tree);
+
+            }
+            if (volumeChange)
+            {
+                await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync(volume, volume.id, new PartitionKey(volume.code));
+            }
+            List<SyllabusTreeNode> redt = new List<SyllabusTreeNode>();
+            //对课纲树形结构排序
+            if (volume.syllabusIds.IsNotEmpty())
+            {
+
+                volume.syllabusIds.ForEach(x =>
+                {
+                    for (int index = 0; index < treeNodes.Count; index++)
+                    {
+                        if (treeNodes[index].id == x)
+                        {
+                            redt.Add(treeNodes[index]);
+                            treeNodes.RemoveAt(index);
+                        }
+                    }
+                });
+                redt.AddRange(treeNodes);
+                return (resNodes, redt);
             }
-            if (volumeChange) {
-                await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync(volume,volume.id,new PartitionKey(volume.code));
+            else {
+                return (resNodes, treeNodes);
             }
-            return (resNodes,chapters);
         }
 
 

+ 2 - 2
TEAMModelOS/Controllers/Both/SyllabusController.cs

@@ -70,8 +70,8 @@ namespace TEAMModelOS.Controllers
             if (request.TryGetProperty("ignoreCharacter", out JsonElement _ignoreCharacter)) {
                 ignoreCharacter = _ignoreCharacter.ValueKind.Equals(JsonValueKind.True)?true:false;
             }
-            (List<List<IdCode>> idCodes, HashSet<Syllabus> syllabuses) data =  await  SyllabusService.ImportSyllabus(nodes, $"{_volumeId}", $"{_scope}", $"{_code}", userid, name,_azureCosmos,ignoreCharacter);
-            return Ok(new {codes= data.idCodes, data.syllabuses });
+            (List<List<IdCode>> idCodes, List<SyllabusTreeNode> tree) data =  await  SyllabusService.ImportSyllabus(nodes, $"{_volumeId}", $"{_scope}", $"{_code}", userid, name,_azureCosmos,ignoreCharacter);
+            return Ok(new {codes= data.idCodes, data.tree });
         }
         /// <summary>
         /// 检查资源链接是否被其他结构关联