Jelajahi Sumber

update 册别增加新增的课纲章节id

CrazyIter_Bin 2 tahun lalu
induk
melakukan
44fa2244df
1 mengubah file dengan 11 tambahan dan 3 penghapusan
  1. 11 3
      TEAMModelOS.SDK/Models/Service/Common/SyllabusService.cs

+ 11 - 3
TEAMModelOS.SDK/Models/Service/Common/SyllabusService.cs

@@ -1,5 +1,4 @@
 using Azure.Cosmos;
-using DocumentFormat.OpenXml.Bibliography;
 using DocumentFormat.OpenXml.ExtendedProperties;
 using DocumentFormat.OpenXml.Office2010.Excel;
 using DocumentFormat.OpenXml.Wordprocessing;
@@ -35,6 +34,8 @@ namespace TEAMModelOS.SDK.Services
                         requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Syllabus-{code}") })) {
                 syllabuses.Add(item);
             }
+            Volume volume = await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<Volume>($"{volumeId}", new PartitionKey($"Volume-{code}"));
+
             HashSet<Syllabus> chapters = new HashSet<Syllabus>();
             long now= DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
             List<List<IdCode> > resNodes = new List<List<IdCode>>();
@@ -132,11 +133,18 @@ namespace TEAMModelOS.SDK.Services
                     resNodes.Add(nodesVal.Select(z => new IdCode { id = z.id, code = z.title }).ToList());
                 }
             }
-            foreach(var chapter in chapters)
+            bool volumeChange=false;
+            foreach (var chapter in chapters)
             {
+                if (!volume.syllabusIds.Contains(chapter.id)) {
+                    volume.syllabusIds.Add(chapter.id);
+                    volumeChange = true;
+                }
                 await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(chapter);
             }
-          
+            if (volumeChange) {
+                await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync(volume,volume.id,new PartitionKey(volume.code));
+            }
             return (resNodes,chapters);
         }