Browse Source

处理初始化班级作答记录

zhouj1203@hotmail.com 4 years ago
parent
commit
66309d92d8
1 changed files with 40 additions and 11 deletions
  1. 40 11
      TEAMModelFunction/TriggerExam.cs

+ 40 - 11
TEAMModelFunction/TriggerExam.cs

@@ -169,6 +169,7 @@ namespace TEAMModelFunction
                                     {
                                         using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
                                         Class classroom = json.ToObject<Class>();
+                                        result.info.id = classroom.id;
                                         result.info.name = classroom.name;
                                         result.gradeId = classroom.gradeId;
                                         //处理班级人数
@@ -190,6 +191,7 @@ namespace TEAMModelFunction
                                     if (sresponse.Status == 200) {
                                         using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
                                         StuList stuList = json.ToObject<StuList>();
+                                        result.info.id = stuList.id;
                                         result.info.name = stuList.name;
                                         //处理发布对象为自选名单(个人)
 
@@ -224,22 +226,24 @@ namespace TEAMModelFunction
                                         result.sum.Add(0);
                                     }
                                 }
-                                else {
+                                else {                                   
+                                    List<string> ans = new List<string>();
+                                    List<double> ansPoint = new List<double>();
+                                    List<string> ids = new List<string>();
                                     var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"Class-{info.school}"));
                                     if (sresponse.Status == 200)
                                     {
                                         using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
                                         Class classroom = json.ToObject<Class>();
                                         result.info.name = classroom.name;
+                                        result.info.id = classroom.id;
                                         result.gradeId = classroom.gradeId;
-                                        List<string> ans = new List<string>();
-                                        List<double> ansPoint = new List<double>();
+                                        
                                         foreach (double p in info.papers[m].point)
                                         {
                                             //ans.Add(new List<string>());
                                             ansPoint.Add(-1);
-                                        }
-                                        List<string> ids = new List<string>();
+                                        }                                     
                                         //处理班级人数
                                         await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{info.school}") }))
                                         {
@@ -254,13 +258,38 @@ namespace TEAMModelFunction
                                                 }
                                             }
                                         }
-                                        foreach (string stu in ids)
+                                        
+                                    }
+                                    var stuResponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"StuList-{info.school}"));
+                                    if (sresponse.Status == 200)
+                                    {
+                                        using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
+                                        StuList stuList = json.ToObject<StuList>();
+                                        result.info.id = stuList.id;
+                                        result.info.name = stuList.name;
+                                        //处理发布对象为自选名单(校本)
+
+                                        foreach (Students students in stuList.students)
                                         {
-                                            result.studentIds.Add(stu);
-                                            result.studentAnswers.Add(ans);
-                                            result.studentScores.Add(ansPoint);
-                                            result.sum.Add(0);
-                                        }
+                                            if (students.code.Contains(code))
+                                            {
+                                                if (!ids.Contains(students.id))
+                                                {
+                                                    ids.Add(students.id);
+                                                }
+                                            }
+                                            else
+                                            {
+                                                ids.Add(students.id);
+                                            }
+                                        }                                      
+                                    }
+                                    foreach (string stu in ids)
+                                    {
+                                        result.studentIds.Add(stu);
+                                        result.studentAnswers.Add(ans);
+                                        result.studentScores.Add(ansPoint);
+                                        result.sum.Add(0);
                                     }
                                 }