|
@@ -833,6 +833,159 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 將活動預報名轉為正式報名
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="client"></param>
|
|
|
+ /// <param name="jointEventId"></param>
|
|
|
+ /// <param name="jointGroupId"></param>
|
|
|
+ /// <param name="creatorId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static async Task<List<JointEventGroupDb>> JointCoursePreToRegularAsync(CosmosClient client, string jointEventId, string jointGroupId, string creatorId)
|
|
|
+ {
|
|
|
+ long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ List<JointEventGroupDb> result = new List<JointEventGroupDb>();
|
|
|
+ //取得本活動所有預報名
|
|
|
+ List<string> groupIds = new List<string>();
|
|
|
+ List<JointEventGroupDb> jointCourseListPre = new List<JointEventGroupDb>();
|
|
|
+ StringBuilder stringBuilder = new($"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' ");
|
|
|
+ if (!string.IsNullOrWhiteSpace(jointGroupId))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" AND c.jointGroupId = '{jointGroupId}' ");
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(creatorId))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" AND c.creatorId = '{creatorId}' ");
|
|
|
+ }
|
|
|
+ StringBuilder stringBuilderPre = new (stringBuilder.ToString());
|
|
|
+ stringBuilderPre.Append($" AND c.type = 'pre' ");
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIteratorSql(queryText: stringBuilderPre.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("JointCourse") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.Content);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ JointEventGroupDb jcourse = obj.ToObject<JointEventGroupDb>();
|
|
|
+ jointCourseListPre.Add(jcourse);
|
|
|
+ //取得groupList ID
|
|
|
+ foreach (JointEventGroupCourse course in jcourse.courseLists)
|
|
|
+ {
|
|
|
+ foreach (JointEventGroupCourseGroup group in course.groupLists)
|
|
|
+ {
|
|
|
+ if(!groupIds.Contains(group.id))
|
|
|
+ groupIds.Add(group.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //取得所有班級成員
|
|
|
+ List<RGroupList> groupList = new List<RGroupList>();
|
|
|
+ string gids = string.Join(",", groupIds.Select(x => $"'{x}'"));
|
|
|
+ StringBuilder stringBuilderGrp = new($"SELECT * FROM c WHERE c.id IN ({gids}) ");
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIteratorSql(queryText: stringBuilderGrp.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("GroupList") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.Content);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ RGroupList gp = obj.ToObject<RGroupList>();
|
|
|
+ groupList.Add(gp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //刪除本活動所有正式報名
|
|
|
+ List<JointEventGroupDb> jointCourseListRegular = new List<JointEventGroupDb>();
|
|
|
+ StringBuilder stringBuilderRegular = new StringBuilder(stringBuilder.ToString());
|
|
|
+ stringBuilderRegular.Append($" AND c.type = 'regular' ");
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIteratorSql(queryText: stringBuilderRegular.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("JointCourse") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.Content);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ JointEventGroupDb jcourse = obj.ToObject<JointEventGroupDb>();
|
|
|
+ jointCourseListRegular.Add(jcourse);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (jointCourseListRegular.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (JointEventGroupDb jcRegular in jointCourseListRegular)
|
|
|
+ {
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<JointEventGroupDb>(jcRegular.id, new PartitionKey("JointCourse"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //生成本活動所有正式報名:有班級成員者才記入
|
|
|
+ List<JointEventGroupDb> jointCourseListRegularCrt = new List<JointEventGroupDb>();
|
|
|
+ foreach (JointEventGroupDb jcPre in jointCourseListPre)
|
|
|
+ {
|
|
|
+ foreach (JointEventGroupCourse jcPreCourse in jcPre.courseLists)
|
|
|
+ {
|
|
|
+ foreach (JointEventGroupCourseGroup jcPreGroup in jcPreCourse.groupLists)
|
|
|
+ {
|
|
|
+ string groupId = jcPreGroup.id;
|
|
|
+ RGroupList groupInfo = groupList.FirstOrDefault(g => g.id.Equals(groupId));
|
|
|
+ if (groupInfo != null && groupInfo.members.Count > 0)
|
|
|
+ {
|
|
|
+ ///正式報名 JointCourse本體生成
|
|
|
+ JointEventGroupDb jcRegularNow = jointCourseListRegularCrt.FirstOrDefault(j => j.jointEventId.Equals(jcPre.jointEventId) && j.jointGroupId.Equals(jcPre.jointGroupId) && j.creatorId.Equals(jcPre.creatorId));
|
|
|
+ if (jcRegularNow == null)
|
|
|
+ {
|
|
|
+ JointEventGroupDb jcRegularNew = new JointEventGroupDb();
|
|
|
+ jcRegularNew.id = Guid.NewGuid().ToString();
|
|
|
+ jcRegularNew.code = "JointCourse";
|
|
|
+ jcRegularNew.pk = "JointCourse";
|
|
|
+ jcRegularNew.jointEventId = jcPre.jointEventId;
|
|
|
+ jcRegularNew.jointGroupId = jcPre.jointGroupId;
|
|
|
+ jcRegularNew.createTime = now;
|
|
|
+ jcRegularNew.scope = "private";
|
|
|
+ jcRegularNew.type = "regular";
|
|
|
+ jcRegularNew.creatorId = jcPre.creatorId;
|
|
|
+ jcRegularNew.creatorName = jcPre.creatorName;
|
|
|
+ jcRegularNew.creatorEmail = jcPre.creatorEmail;
|
|
|
+ jcRegularNew.schoolId = jcPre.schoolId;
|
|
|
+ jcRegularNew.schoolName = jcPre.schoolName;
|
|
|
+ jointCourseListRegularCrt.Add(jcRegularNew);
|
|
|
+ jcRegularNow = jointCourseListRegularCrt.FirstOrDefault(j => j.jointEventId.Equals(jcPre.jointEventId) && j.jointGroupId.Equals(jcPre.jointGroupId) && j.creatorId.Equals(jcPre.creatorId) && j.type.Equals("regular") && j.scope.Equals("private"));
|
|
|
+ }
|
|
|
+ ///courseLists.row 生成
|
|
|
+ JointEventGroupCourse jcRegularCourseNow = jcRegularNow.courseLists.FirstOrDefault(c => c.courseId.Equals(jcPreCourse.courseId));
|
|
|
+ if (jcRegularCourseNow == null)
|
|
|
+ {
|
|
|
+ JointEventGroupCourse jcRegularCourseNew = new JointEventGroupBase.JointEventGroupCourse();
|
|
|
+ jcRegularCourseNew.courseId = jcPreCourse.courseId;
|
|
|
+ jcRegularCourseNew.courseName = jcPreCourse.courseName;
|
|
|
+ jcRegularNow.courseLists.Add(jcRegularCourseNew);
|
|
|
+ jcRegularCourseNow = jcRegularNow.courseLists.FirstOrDefault(c => c.courseId.Equals(jcPreCourse.courseId));
|
|
|
+ }
|
|
|
+ ///groupLists.row 生成
|
|
|
+ JointEventGroupCourseGroup jcRegularCourseGroupNow = jcRegularCourseNow.groupLists.FirstOrDefault(g => g.id.Equals(jcPreGroup.id));
|
|
|
+ if (jcRegularCourseGroupNow == null)
|
|
|
+ {
|
|
|
+ JointEventGroupCourseGroup jcRegularCourseGroupNew = new JointEventGroupBase.JointEventGroupCourseGroup();
|
|
|
+ jcRegularCourseGroupNew.id = groupInfo.id;
|
|
|
+ jcRegularCourseGroupNew.name = groupInfo.name;
|
|
|
+ jcRegularCourseNow.groupLists.Add(jcRegularCourseGroupNew);
|
|
|
+ jcRegularCourseGroupNow = jcRegularCourseNow.groupLists.FirstOrDefault(g => g.id.Equals(jcPreGroup.id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //計算各活動階段進行狀況
|
|
|
+ foreach (JointEventGroupDb jointCourse in jointCourseListRegularCrt)
|
|
|
+ {
|
|
|
+ string creator = jointCourse.creatorId;
|
|
|
+ JointEventGroupDb jointCourseCrt = await JointService.CalJointCourseGroupScheduleStatusAsync(client, jointEventId, jointGroupId, creator, jointCourse, null);
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).CreateItemAsync<JointEventGroupDb>(jointCourseCrt, new PartitionKey(jointCourseCrt.code));
|
|
|
+ result.Add(jointCourseCrt);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 計算決賽通過的老師課程名單用中間model
|