Selaa lähdekoodia

活動報名班級追加紀錄各活動階段架構 - 各班級熱身賽、決賽更新評量後,改變活動階段資料 (進行中)

jeff 3 kuukautta sitten
vanhempi
commit
3a1d7b5956

+ 74 - 1
TEAMModelOS.Function/CosmosDBTriggers/TriggerExam.cs

@@ -235,7 +235,6 @@ namespace TEAMModelOS.CosmosDBTriggers
                                             var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new PartitionKey($"Class-{info.school}"));
                                             if (sresponse.StatusCode == System.Net.HttpStatusCode.OK)
                                             {
-
                                                 using var json = await JsonDocument.ParseAsync(sresponse.Content);
                                                 Class classroom = json.ToObject<Class>();
 
@@ -393,6 +392,43 @@ namespace TEAMModelOS.CosmosDBTriggers
                                         await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
                                     }
                                 }*/
+
+                                //統測活動處理
+                                if(!string.IsNullOrWhiteSpace(info.jointExamId))
+                                {
+                                    JointEventGroupDb jointCourse = new JointEventGroupDb();
+                                    string jointEventId = string.Empty;
+                                    string jointGroupId = string.Empty;
+                                    string examCreatorId = string.Empty;
+                                    ///取得統測活動、老師報名班級
+                                    var jexamResponse = await client.GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(info.jointExamId, new PartitionKey($"JointExam"));
+                                    if (jexamResponse.StatusCode == System.Net.HttpStatusCode.OK)
+                                    {
+                                        using var json = await JsonDocument.ParseAsync(jexamResponse.Content);
+                                        JointExam jointExam = json.ToObject<JointExam>();
+                                        jointEventId = jointExam.jointEventId;
+                                        jointGroupId = jointExam.jointGroupId;
+                                        examCreatorId = jointExam.creatorId;
+                                        string jcSql = $"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.creatorId = '{examCreatorId}' AND c.type = 'regular' ";
+                                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryStreamIteratorSql(queryText: jcSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"JointCourse") }))
+                                        {
+                                            using var jsonJc = await JsonDocument.ParseAsync(item.Content);
+                                            if (jsonJc.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                                            {
+                                                foreach (var obj in jsonJc.RootElement.GetProperty("Documents").EnumerateArray())
+                                                {
+                                                    jointCourse = obj.ToObject<JointEventGroupDb>();
+                                                }
+                                            }
+                                        }
+                                    }
+                                    ///更新 JointCourse
+                                    if(!string.IsNullOrWhiteSpace(jointCourse.id))
+                                    {
+                                        jointCourse = await JointService.CalJointCourseGroupScheduleStatusAsync(client, jointEventId, jointGroupId, examCreatorId, jointCourse, null); //各Schedule Status計算
+                                        await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<JointEventGroupDb>(jointCourse, jointCourse.id, new PartitionKey(jointCourse.code));
+                                    }
+                                }
                             }
                             catch (Exception e)
                             {
@@ -554,6 +590,43 @@ namespace TEAMModelOS.CosmosDBTriggers
                                     await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
                                 }
                                 await SetLearnRecordContent(info, data, _azureStorage, _azureCosmos);
+
+                                //統測活動處理
+                                if (!string.IsNullOrWhiteSpace(info.jointExamId))
+                                {
+                                    JointEventGroupDb jointCourse = new JointEventGroupDb();
+                                    string jointEventId = string.Empty;
+                                    string jointGroupId = string.Empty;
+                                    string examCreatorId = string.Empty;
+                                    ///取得統測活動、老師報名班級
+                                    var jexamResponse = await client.GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(info.jointExamId, new PartitionKey($"JointExam"));
+                                    if (jexamResponse.StatusCode == System.Net.HttpStatusCode.OK)
+                                    {
+                                        using var json = await JsonDocument.ParseAsync(jexamResponse.Content);
+                                        JointExam jointExam = json.ToObject<JointExam>();
+                                        jointEventId = jointExam.jointEventId;
+                                        jointGroupId = jointExam.jointGroupId;
+                                        examCreatorId = jointExam.creatorId;
+                                        string jcSql = $"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.creatorId = '{examCreatorId}' AND c.type = 'regular' ";
+                                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryStreamIteratorSql(queryText: jcSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"JointCourse") }))
+                                        {
+                                            using var jsonJc = await JsonDocument.ParseAsync(item.Content);
+                                            if (jsonJc.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                                            {
+                                                foreach (var obj in jsonJc.RootElement.GetProperty("Documents").EnumerateArray())
+                                                {
+                                                    jointCourse = obj.ToObject<JointEventGroupDb>();
+                                                }
+                                            }
+                                        }
+                                    }
+                                    ///更新 JointCourse
+                                    if (!string.IsNullOrWhiteSpace(jointCourse.id))
+                                    {
+                                        jointCourse = await JointService.CalJointCourseGroupScheduleStatusAsync(client, jointEventId, jointGroupId, examCreatorId, jointCourse, null); //各Schedule Status計算
+                                        await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<JointEventGroupDb>(jointCourse, jointCourse.id, new PartitionKey(jointCourse.code));
+                                    }
+                                }
                             }
                             catch (Exception e)
                             {

+ 1 - 1
TEAMModelOS.SDK/Models/Cosmos/Teacher/JointEvent.cs

@@ -50,7 +50,7 @@ namespace TEAMModelOS.SDK.Models
             public string name { get; set; } //檔案名稱
             public string blob { get; set; } //檔案Blob路徑
         }
-        public List<string> loginType { get; set; } // 登入類型
+        public List<string> loginType { get; set; } = new(); // 登入類型
     }
 
     /// <summary>