瀏覽代碼

班级结构调整后续API调整

zhouj1203@hotmail.com 4 年之前
父節點
當前提交
d8cc11810b

+ 14 - 2
TEAMModelFunction/TriggerExam.cs

@@ -168,7 +168,13 @@ namespace TEAMModelFunction
                                             //ans.Add(new List<string>());
                                             //ans.Add(new List<string>());
                                             ansPoint.Add(-1);
                                             ansPoint.Add(-1);
                                         }
                                         }
-                                        foreach (StudentSimple stu in classroom.students)
+                                        //处理班级学生名单
+                                        List<Student> students = new List<Student>();
+                                        await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<Student>(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{code}") }))
+                                        {
+                                            students.Add(item);
+                                        }
+                                        foreach (Student stu in students)
                                         {
                                         {
                                             result.studentIds.Add(stu.id);
                                             result.studentIds.Add(stu.id);
                                             result.studentAnswers.Add(ans);
                                             result.studentAnswers.Add(ans);
@@ -192,7 +198,13 @@ namespace TEAMModelFunction
                                             //ans.Add(new List<string>());
                                             //ans.Add(new List<string>());
                                             ansPoint.Add(-1);
                                             ansPoint.Add(-1);
                                         }
                                         }
-                                        foreach (StudentSimple stu in classroom.students)
+                                        //处理班级学生名单
+                                        List<Student> students = new List<Student>();
+                                        await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<Student>(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{code}") }))
+                                        {
+                                            students.Add(item);
+                                        }
+                                        foreach (Student stu in students)
                                         {
                                         {
                                             result.studentIds.Add(stu.id);
                                             result.studentIds.Add(stu.id);
                                             result.studentAnswers.Add(ans);
                                             result.studentAnswers.Add(ans);

+ 2 - 2
TEAMModelOS.SDK/Models/Cosmos/School/Class.cs

@@ -16,7 +16,7 @@ namespace TEAMModelOS.SDK.Models
         {
         {
             pk = "Class";
             pk = "Class";
             teacher = new Teachers();
             teacher = new Teachers();
-            students = new List<StudentSimple>();
+            //students = new List<StudentSimple>();
         }
         }
         /// <summary>
         /// <summary>
         /// 教室编号
         /// 教室编号
@@ -31,7 +31,7 @@ namespace TEAMModelOS.SDK.Models
         public string gradeId { get; set; }
         public string gradeId { get; set; }
         public string sn { get; set; }
         public string sn { get; set; }
 
 
-        public List<StudentSimple> students { get; set; }
+        //public List<StudentSimple> students { get; set; }
         /// <summary>
         /// <summary>
         /// TBL IRS 类型区分
         /// TBL IRS 类型区分
         /// </summary>
         /// </summary>

+ 8 - 0
TEAMModelOS.SDK/Models/Cosmos/Student/Student.cs

@@ -16,5 +16,13 @@ namespace TEAMModelOS.SDK.Models
         public string pw { get; set; }
         public string pw { get; set; }
         public string salt { get; set; }
         public string salt { get; set; }
         public string year { get; set; }
         public string year { get; set; }
+        //座位号
+        public string no { get; set; }
+        //绑定班级Id
+        public string classId { get; set; }
+        //分组信息
+        public string groupId { get; set; }
+        public string groupName { get; set; }
+
     }
     }
 }
 }

+ 7 - 2
TEAMModelOS/Controllers/Analysis/AchievementController.cs

@@ -1888,8 +1888,13 @@ namespace TEAMModelOS.Controllers.Analysis
                         classes.Add(new { name = classroom.name, id = s });
                         classes.Add(new { name = classroom.name, id = s });
                         //初始化参考人数
                         //初始化参考人数
                         int count = 0;
                         int count = 0;
-
-                        foreach (StudentSimple stu in classroom.students)
+                        //处理班级学生名单
+                        List<Student> students = new List<Student>();
+                        await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<Student>(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{code}") }))
+                        {
+                            students.Add(item);
+                        }
+                        foreach (Student stu in students)
                         {
                         {
                             if (idName.Contains(stu.id))
                             if (idName.Contains(stu.id))
                             {
                             {

+ 6 - 2
TEAMModelOS/Controllers/Analysis/AnalysisController.cs

@@ -339,13 +339,17 @@ namespace TEAMModelOS.Controllers.Analysis
                         fieldClassTotal.Add(new KeyValuePair<string, List<double>>(sub, fields));
                         fieldClassTotal.Add(new KeyValuePair<string, List<double>>(sub, fields));
 
 
                     });
                     });
-
+                    List<Student> stus = new List<Student>();
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<Student>(queryText: $"select c.id,c.name,c.no from c where c.classId = '{classId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{code}") }))
+                    {
+                        stus.Add(item);
+                    }
                     classStudents.ForEach(x => {
                     classStudents.ForEach(x => {
                         studentIds.Add(x.id);
                         studentIds.Add(x.id);
                         x.classId = classId;
                         x.classId = classId;
                         x.className = classroom.name;
                         x.className = classroom.name;
                         x.gradeId = classroom.gradeId;
                         x.gradeId = classroom.gradeId;
-                        var stu = classroom.students.Where(s => s.id == x.id).FirstOrDefault();
+                        var stu = stus.Where(s => s.id == x.id).FirstOrDefault();
                         if (stu != null)
                         if (stu != null)
                         {
                         {
                             x.name = stu.name;
                             x.name = stu.name;

+ 10 - 4
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -69,14 +69,14 @@ namespace TEAMModelOS.Controllers
                 int count = 0;
                 int count = 0;
                 for (int i = 0; i < request.targetClassIds.Count; i++)
                 for (int i = 0; i < request.targetClassIds.Count; i++)
                 {
                 {
-                    if (request.scope.Equals("private"))
+                    /*if (request.scope.Equals("private"))
                     {
                     {
                         var sresponse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(request.targetClassIds[i], new PartitionKey($"Class-{request.creatorId}"));
                         var sresponse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(request.targetClassIds[i], new PartitionKey($"Class-{request.creatorId}"));
                         if (sresponse.Status == 200)
                         if (sresponse.Status == 200)
                         {
                         {
                             using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
                             using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
                             Class classroom = json.ToObject<Class>();
                             Class classroom = json.ToObject<Class>();
-                            count += classroom.students.Count;
+                            
                         }
                         }
                     }
                     }
                     else
                     else
@@ -85,10 +85,16 @@ namespace TEAMModelOS.Controllers
                         if (sresponse.Status == 200)
                         if (sresponse.Status == 200)
                         {
                         {
                             using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
                             using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
-                            Class classroom = json.ToObject<Class>();
-                            count += classroom.students.Count;
+                            Class classroom = json.ToObject<Class>();                          
                         }
                         }
+                    }*/
+                    //处理班级人数
+                    List<Student> students = new List<Student>();
+                    await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<Student>(queryText: $"select c.id from c where c.classId = '{request.targetClassIds[i]}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{code}") }))
+                    {
+                        students.Add(item);
                     }
                     }
+                    count += students.Count;
                 }
                 }
                 request.stuCount = count;
                 request.stuCount = count;
                 if (string.IsNullOrEmpty(request.id))
                 if (string.IsNullOrEmpty(request.id))

+ 22 - 7
TEAMModelOS/Controllers/School/ClassRoomController.cs

@@ -194,7 +194,7 @@ namespace TEAMModelOS.Controllers
                             {
                             {
                                 return Ok(new { error = ResponseCode.DATA_EXIST, V = "班级编码已经存在!" });
                                 return Ok(new { error = ResponseCode.DATA_EXIST, V = "班级编码已经存在!" });
                             }
                             }
-                            List<StudentSimple> studentSimples = new List<StudentSimple>();
+                            /*List<StudentSimple> studentSimples = new List<StudentSimple>();
                             StringBuilder sql = new StringBuilder();
                             StringBuilder sql = new StringBuilder();
                             sql.Append("select A0.id,A0.name,A0.no from c join A0 in c.students ");
                             sql.Append("select A0.id,A0.name,A0.no from c join A0 in c.students ");
                             Dictionary<string, object> dict = new Dictionary<string, object>();
                             Dictionary<string, object> dict = new Dictionary<string, object>();
@@ -212,7 +212,7 @@ namespace TEAMModelOS.Controllers
                                     }
                                     }
                                 }
                                 }
                             }
                             }
-                            classroom.students = studentSimples;
+                            classroom.students = studentSimples;*/
 
 
                             List<TeacherCourse> course = new List<TeacherCourse>();
                             List<TeacherCourse> course = new List<TeacherCourse>();
                             await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c join A0 in c.classes where A0.id = '{classroom.id}'"))
                             await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c join A0 in c.classes where A0.id = '{classroom.id}'"))
@@ -295,20 +295,35 @@ namespace TEAMModelOS.Controllers
         {
         {
             try
             try
             {
             {
-                Class classroom = new Class();
+                List<Student> students = new List<Student>();
+                if (!requert.TryGetProperty("students", out JsonElement stus)) return BadRequest();
+                students = stus.ToObject<List<Student>>();
+                var client = _azureCosmos.GetCosmosClient();
+                foreach (Student stu in students) {
+                    var response = await client.GetContainer("TEAMModelOS", "Student").ReadItemStreamAsync(stu.id, new PartitionKey($"{stu.code}"));
+                    if (response.Status == 200)
+                    {
+                        using var json = await JsonDocument.ParseAsync(response.ContentStream);
+                        Student stuInfo = json.ToObject<Student>();
+                        stuInfo.groupId = stu.groupId;
+                        stuInfo.groupName = stu.groupName;
+                        await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(stuInfo, stuInfo.id, new PartitionKey($"{stuInfo.code}"));
+                    }
+                }
+                /*Class classroom = new Class();
                 if (!requert.TryGetProperty("classroom", out JsonElement room)) return BadRequest();
                 if (!requert.TryGetProperty("classroom", out JsonElement room)) return BadRequest();
                 //if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 //if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 classroom = room.ToObject<Class>();
                 classroom = room.ToObject<Class>();
-                var client = _azureCosmos.GetCosmosClient();
+               
                 var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(classroom.id, new PartitionKey($"{classroom.code}"));
                 var sresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(classroom.id, new PartitionKey($"{classroom.code}"));
                 if (sresponse.Status == 200)
                 if (sresponse.Status == 200)
                 {
                 {
                     using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
                     using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
                     Class classroom1 = json.ToObject<Class>();
                     Class classroom1 = json.ToObject<Class>();
-                    classroom1.students = classroom.students;
+                    //classroom1.students = classroom.students;
                     var response = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(classroom1, classroom1.id, new PartitionKey($"{classroom.code}"));
                     var response = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(classroom1, classroom1.id, new PartitionKey($"{classroom.code}"));
-                }
-                return Ok(new { classroom });
+                }*/
+                return Ok(new { students });
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {

+ 3 - 3
TEAMModelOS/Controllers/School/CourseController.cs

@@ -618,14 +618,14 @@ namespace TEAMModelOS.Controllers
                                     newCla.code = cla.pk + "-" + code;
                                     newCla.code = cla.pk + "-" + code;
                                     newCla.name = classSimple.name;
                                     newCla.name = classSimple.name;
                                     newCla.scope = classSimple.scope;
                                     newCla.scope = classSimple.scope;
-                                    foreach (StudentSimple student in cla.students)
+                                    /*foreach (StudentSimple student in cla.students)
                                     {
                                     {
                                         StudentSimple studentSimple = new StudentSimple();
                                         StudentSimple studentSimple = new StudentSimple();
                                         studentSimple.id = student.id;
                                         studentSimple.id = student.id;
                                         studentSimple.name = student.name;
                                         studentSimple.name = student.name;
                                         studentSimple.no = student.no;
                                         studentSimple.no = student.no;
                                         newCla.students.Add(studentSimple);
                                         newCla.students.Add(studentSimple);
-                                    }
+                                    }*/
                                     newCla.teacher.id = classSimple.teacher.id;
                                     newCla.teacher.id = classSimple.teacher.id;
                                     newCla.teacher.name = classSimple.teacher.name;
                                     newCla.teacher.name = classSimple.teacher.name;
                                     await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(newCla, new PartitionKey($"Class-{code}"));
                                     await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(newCla, new PartitionKey($"Class-{code}"));
@@ -640,7 +640,7 @@ namespace TEAMModelOS.Controllers
                                     newCla.name = classSimple.name;
                                     newCla.name = classSimple.name;
                                     newCla.scope = classSimple.scope;
                                     newCla.scope = classSimple.scope;
 
 
-                                    newCla.students = cla.students;
+                                    //newCla.students = cla.students;
                                     newCla.teacher.id = classSimple.teacher.id;
                                     newCla.teacher.id = classSimple.teacher.id;
                                     newCla.teacher.name = classSimple.teacher.name;
                                     newCla.teacher.name = classSimple.teacher.name;
                                     await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(newCla, new PartitionKey($"Class-{code}"));
                                     await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(newCla, new PartitionKey($"Class-{code}"));