瀏覽代碼

HiTeach取得學校資訊API 「取得評量結束班級」判斷邏輯修正
統測活動行程修改API 地點、描述 更新邏輯修正

jeff 10 月之前
父節點
當前提交
56d11a6053

+ 35 - 15
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -2335,8 +2335,9 @@ namespace TEAMModelOS.Controllers.Client
                     }
                 }
                 //取得有作答的評測班級
+                string sqltest = $"SELECT c.examId, c.info.id as classId, c.studentAnswers FROM c WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(examIdList)}, c.examId) AND c.progress=true AND CONTAINS(c.code, 'ExamClassResult')";
                 Dictionary<string, List<string>> examClassFinDic = new Dictionary<string, List<string>>();
-                await foreach (var exam in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: $"SELECT  c.examId, c.info.id as classId FROM c where (c.status<>404 or IS_DEFINED(c.status) = false ) and  ARRAY_CONTAINS({JsonSerializer.Serialize(examIdList)}, c.examId) AND c.progress=true", requestOptions: new QueryRequestOptions() { }))
+                await foreach (var exam in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: $"SELECT c.examId, c.info.id as classId, c.studentAnswers FROM c WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(examIdList)}, c.examId) AND c.progress=true AND CONTAINS(c.code, 'ExamClassResult')", requestOptions: new QueryRequestOptions() ))
                 {
                     var jsonecr = await JsonDocument.ParseAsync(exam.Content);
                     if (jsonecr.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
@@ -2345,15 +2346,24 @@ namespace TEAMModelOS.Controllers.Client
                         {
                             string examId = obj.GetProperty("examId").ToString();
                             string classId = obj.GetProperty("classId").ToString();
-                            if (examClassFinDic.ContainsKey(examId) && !examClassFinDic[examId].Contains(classId))
+                            List<List<string>> studentAnswers = obj.GetProperty("studentAnswers").ToObject<List<List<string>>>();
+                            bool isFinish = false; //評量是否已完成 ※有任一學生有作答則視為已完成
+                            foreach (List<string> studentAnswer in studentAnswers)
                             {
-                                examClassFinDic[examId].Add(classId);
+                                if (studentAnswer.Count > 0) { isFinish = true; break; }
                             }
-                            else
+                            if (isFinish)
                             {
-                                List<string> classIdList = new List<string>();
-                                classIdList.Add(classId);
-                                examClassFinDic.Add(examId, classIdList);
+                                if (examClassFinDic.ContainsKey(examId) && !examClassFinDic[examId].Contains(classId))
+                                {
+                                    examClassFinDic[examId].Add(classId);
+                                }
+                                else
+                                {
+                                    List<string> classIdList = new List<string>();
+                                    classIdList.Add(classId);
+                                    examClassFinDic.Add(examId, classIdList);
+                                }
                             }
                         }
                     }
@@ -2875,24 +2885,34 @@ namespace TEAMModelOS.Controllers.Client
                 }
                 //取得有作答的評測班級、已完成的 評測ID、班級ID、科目ID 列表製作
                 List<ExamFinishClassesSubList> examFinClassSubList = new List<ExamFinishClassesSubList>(); //已完成的 評測ID、班級ID、科目ID 列表
-                await foreach (var exam in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: $"SELECT c.examId, c.info.id as classId, c.subjectId FROM c WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(examIdList)}, c.examId) AND c.progress=true", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{school_code}") }))
+                await foreach (var exam in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: $"SELECT c.examId, c.info.id as classId, c.subjectId, c.studentAnswers FROM c WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(examIdList)}, c.examId) AND c.progress=true", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{school_code}") }))
                 {
                     var jsonecr = await JsonDocument.ParseAsync(exam.Content);
                     if (jsonecr.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                     {
                         foreach (var obj in jsonecr.RootElement.GetProperty("Documents").EnumerateArray())
                         {
+                            //追加判斷:是否有作答要看 studentAnswers,若其下的array全部都為空array則視為未完成
                             string examId = obj.GetProperty("examId").ToString();
                             string classId = obj.GetProperty("classId").ToString();
                             string subjectId = obj.GetProperty("subjectId").ToString();
-                            ExamFinishClassesSubList existExamFinishClassesSubRow = examFinClassSubList.Where(e => e.examId == examId && e.classId == classId && e.subjectId == subjectId).FirstOrDefault();
-                            if (existExamFinishClassesSubRow == null)
+                            List<List<string>> studentAnswers = obj.GetProperty("studentAnswers").ToObject<List<List<string>>>();
+                            bool isFinish = false; //評量是否已完成 ※有任一學生有作答則視為已完成
+                            foreach(List<string> studentAnswer in studentAnswers)
+                            {
+                                if(studentAnswer.Count > 0) { isFinish = true; break; }
+                            }
+                            if (isFinish)
                             {
-                                ExamFinishClassesSubList ExamFinishClassesSubRow = new ExamFinishClassesSubList();
-                                ExamFinishClassesSubRow.examId = examId;
-                                ExamFinishClassesSubRow.classId = classId;
-                                ExamFinishClassesSubRow.subjectId = subjectId;
-                                examFinClassSubList.Add(ExamFinishClassesSubRow);
+                                ExamFinishClassesSubList existExamFinishClassesSubRow = examFinClassSubList.Where(e => e.examId == examId && e.classId == classId && e.subjectId == subjectId).FirstOrDefault();
+                                if (existExamFinishClassesSubRow == null)
+                                {
+                                    ExamFinishClassesSubList ExamFinishClassesSubRow = new ExamFinishClassesSubList();
+                                    ExamFinishClassesSubRow.examId = examId;
+                                    ExamFinishClassesSubRow.classId = classId;
+                                    ExamFinishClassesSubRow.subjectId = subjectId;
+                                    examFinClassSubList.Add(ExamFinishClassesSubRow);
+                                }
                             }
                         }
                     }

+ 3 - 3
TEAMModelOS/Controllers/Teacher/JointEventController.cs

@@ -321,9 +321,9 @@ namespace TEAMModelOS.Controllers.Common
                     jointEventSchedule.endTime = schedule.endTime;
                     jointEventSchedule.progress = (schedule.startTime <= now && now <= schedule.endTime) ? "going" : (now < schedule.startTime) ? "pending" : "finish";
                     jointEventSchedule.orderby = schedule.orderby;
-                    if (!string.IsNullOrWhiteSpace(schedule.location)) jointEventSchedule.location = schedule.location;
-                    if (!string.IsNullOrWhiteSpace(schedule.description)) jointEventSchedule.description = schedule.description;
-                    if(schedule.blobs != null) jointEventSchedule.blobs = schedule.blobs;
+                    if (schedule.location != null) jointEventSchedule.location = schedule.location;
+                    if (schedule.description != null) jointEventSchedule.description = schedule.description;
+                    if (schedule.blobs != null) jointEventSchedule.blobs = schedule.blobs;
                     if (mode.Equals("add"))
                     {
                         jointEvent.schedule.Add(jointEventSchedule);