CrazyIter_Bin 2 năm trước cách đây
mục cha
commit
08573e06f2

+ 50 - 2
TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

@@ -82,6 +82,54 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             var response = req.CreateResponse(HttpStatusCode.OK);
             string data = await new StreamReader(req.Body).ReadToEndAsync();
             var json = JsonDocument.Parse(data).RootElement;
+            List<TagOldNew> old_new = null;
+            string school = null;
+            if (json.TryGetProperty("school", out JsonElement _school))
+            {
+                school = _school.GetString();
+            }
+            if (json.TryGetProperty("old_new", out JsonElement _old_new))
+            {
+                old_new = _old_new.ToObject<List<TagOldNew>>();
+            }
+            if (old_new.IsNotEmpty() && !string.IsNullOrWhiteSpace(school))
+            {
+                foreach (var on in old_new)
+                {
+                    List<LessonRecord> lessonRecords = new List<LessonRecord>();
+                    string sql = $"select value(c) from c    where array_contains(c.category,'{on._old}') ";
+                    await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonRecord>
+                        (queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{_school}") }))
+                    {
+                        lessonRecords.Add(item);
+                    }
+
+                    lessonRecords.ForEach(item =>
+                    {
+                        //修改知识点
+                        if (!string.IsNullOrEmpty(on._new))
+                        {
+                            for (int i = 0; i < item.category.Count; i++)
+                            {
+                                if (item.category[i].Equals(on._old))
+                                {
+                                    item.category[i] = on._new;
+                                }
+                            }
+                        }
+                        else
+                        {
+                            //表示删除知识点
+                            item.category.RemoveAll(x => x.Equals(on._old));
+                        }
+                    });
+                    foreach (var item in lessonRecords)
+                    {
+                        await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
+                    }
+                }
+            }
+            await response.WriteAsJsonAsync(new { data = json });
             return response;
         }
         /// <summary>
@@ -96,7 +144,7 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             var response = req.CreateResponse(HttpStatusCode.OK);
             string data = await new StreamReader(req.Body).ReadToEndAsync();
             var json = JsonDocument.Parse(data).RootElement;
-            List<KnowledgeOldNew> old_new = null;
+            List<TagOldNew> old_new = null;
             string school = null;
             if (json.TryGetProperty("school", out JsonElement _school))
             {
@@ -104,7 +152,7 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
             }
             if (json.TryGetProperty("old_new", out JsonElement _old_new))
             {
-                old_new = _old_new.ToObject<List<KnowledgeOldNew>>();
+                old_new = _old_new.ToObject<List<TagOldNew>>();
             }
             if (old_new.IsNotEmpty() && !string.IsNullOrWhiteSpace(school))
             {

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/School/Knowledge.cs

@@ -39,7 +39,7 @@ namespace TEAMModelOS.SDK.Models
         public List<Block> blocks { get; set; } = new List<Block>();
 
     }
-    public class KnowledgeOldNew
+    public class TagOldNew
     {
         [Required(ErrorMessage = "_old 必须设置")]
         public string _old { get; set; }

+ 2 - 2
TEAMModelOS/Controllers/School/KnowledgesController.cs

@@ -122,10 +122,10 @@ namespace TEAMModelOS.Controllers
         {
             if (!json.TryGetProperty("school", out JsonElement school)) return BadRequest();
             Knowledge knowledge = json.GetProperty("knowledge").ToObject<Knowledge>();
-            List<KnowledgeOldNew> old_new = null;
+            List<TagOldNew> old_new = null;
             if (json.TryGetProperty("old_new", out JsonElement _old_new))
             {
-                old_new = _old_new.ToObject<List<KnowledgeOldNew>>();
+                old_new = _old_new.ToObject<List<TagOldNew>>();
             }
             ValidResult validResult = knowledge.Valid();
             if (!validResult.isVaild)