浏览代码

处理自定义名单BUG

zhouj1203@hotmail.com 3 年之前
父节点
当前提交
527f8a52d6
共有 2 个文件被更改,包括 52 次插入13 次删除
  1. 8 2
      TEAMModelFunction/TriggerExam.cs
  2. 44 11
      TEAMModelOS/Controllers/Common/ExamController.cs

+ 8 - 2
TEAMModelFunction/TriggerExam.cs

@@ -264,7 +264,10 @@ namespace TEAMModelFunction
                                                 foreach (Students stus in stuList.students)
                                                 {
 
-                                                    ids.Add(stus.id);
+                                                    if (!ids.Contains(stus.id))
+                                                    {
+                                                        ids.Add(stus.id);
+                                                    }
                                                 }
                                                 if (stuList.tmids.Count > 0)
                                                 {
@@ -287,7 +290,10 @@ namespace TEAMModelFunction
                                                 //处理发布对象为自选名单(校本)
                                                 foreach (Students stus in stuList.students)
                                                 {
-                                                    ids.Add(stus.id);
+                                                    if (!ids.Contains(stus.id))
+                                                    {
+                                                        ids.Add(stus.id);
+                                                    }
                                                 }
                                             }
                                         }

+ 44 - 11
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -82,7 +82,22 @@ namespace TEAMModelOS.Controllers
                 {
                     request.startTime = now;
                 }
-
+                //查询所有学生名单
+                List<string> sids = new List<string>();
+                //List<Student> students = new List<Student>();
+                await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{request.school}") }))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
+                        while (accounts.MoveNext())
+                        {
+                            JsonElement account = accounts.Current;
+                            sids.Add(account.GetProperty("id").GetString());
+                        }
+                    }
+                }
                 int stuCount = 0;
                 for (int i = 0; i < request.classes.Count; i++)
                 {
@@ -115,18 +130,33 @@ namespace TEAMModelOS.Controllers
                         {
                             foreach (StuList stuList in stuLists)
                             {
-                                foreach (Students students in stuList.students)
+                                /*int index = 0;
+                                foreach (Students stus in stuList.students)
                                 {
-                                    if (students.code.Contains(code))
+                                    if (sids.Contains(stus.id))
+                                    {
+                                        if (!ids.Contains(stus.id))
+                                        {
+                                            ids.Add(stus.id);
+                                        }
+                                    }
+                                    else {
+                                        stuList.students.RemoveAt(index);
+                                    }
+                                    index++;
+                                }*/
+                                for (int j = 0; j < stuList.students.Count; j++) {
+
+                                    if (sids.Contains(stuList.students[j].id))
                                     {
-                                        if (!ids.Contains(students.id))
+                                        if (!ids.Contains(stuList.students[j].id))
                                         {
-                                            ids.Add(students.id);
+                                            ids.Add(stuList.students[j].id);
                                         }
                                     }
                                     else
                                     {
-                                        ids.Add(students.id);
+                                        stuList.students.RemoveAt(j);
                                     }
                                 }
                                 if (stuList.tmids.Count > 0)
@@ -136,6 +166,7 @@ namespace TEAMModelOS.Controllers
                                         ids.Add(tid);
                                     }
                                 }
+                                await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(stuList, stuList.id, new PartitionKey(stuList.code));
                             }
 
                         }
@@ -153,20 +184,22 @@ namespace TEAMModelOS.Controllers
                         {
                             foreach (StuList stuList in stuLists)
                             {
-                                foreach (Students students in stuList.students)
+                                for (int j = 0; j < stuList.students.Count; j++)
                                 {
-                                    if (students.code.Contains(code))
+
+                                    if (sids.Contains(stuList.students[j].id))
                                     {
-                                        if (!ids.Contains(students.id))
+                                        if (!ids.Contains(stuList.students[j].id))
                                         {
-                                            ids.Add(students.id);
+                                            ids.Add(stuList.students[j].id);
                                         }
                                     }
                                     else
                                     {
-                                        ids.Add(students.id);
+                                        stuList.students.RemoveAt(j);
                                     }
                                 }
+                                await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync(stuList, stuList.id, new PartitionKey(stuList.code));
                             }
 
                         }