|
@@ -432,11 +432,18 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
{
|
|
|
try {
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- List<JointEventGroupDb> JointCourse = new List<JointEventGroupDb>();
|
|
|
+ List<JointEventGroupDto> JointCourseDto = new List<JointEventGroupDto>();
|
|
|
StringBuilder stringBuilder = new($"SELECT * FROM c WHERE 1=1 ");
|
|
|
string jointEventId = (request.TryGetProperty("jointEventId", out JsonElement _jointEventId)) ? _jointEventId.ToString() : string.Empty;
|
|
|
string jointGroupId = (request.TryGetProperty("jointGroupId", out JsonElement _jointGroupId)) ? _jointGroupId.ToString() : string.Empty;
|
|
|
if (string.IsNullOrWhiteSpace(jointEventId)) return BadRequest();
|
|
|
+ //取得活動
|
|
|
+ JointEvent jointEvent = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<JointEvent>(jointEventId, new PartitionKey("JointEvent"));
|
|
|
+ if (jointEvent == null)
|
|
|
+ {
|
|
|
+ return Ok(new { errCode = "3", err = "Invalid jointEventId.", data = JointCourseDto });
|
|
|
+ }
|
|
|
+ //取得報名課程
|
|
|
stringBuilder.Append($" AND c.jointEventId = '{jointEventId}' ");
|
|
|
if (!string.IsNullOrWhiteSpace(jointGroupId))
|
|
|
{
|
|
@@ -454,12 +461,24 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
{
|
|
|
foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
{
|
|
|
- JointCourse.Add(obj.ToObject<JointEventGroupDb>());
|
|
|
+ JointEventGroupDto jointEventGroupDto = obj.ToObject<JointEventGroupDto>();
|
|
|
+ foreach(JointEventGroupDto.JointEventGroupCourseDto course in jointEventGroupDto.courseLists)
|
|
|
+ {
|
|
|
+ foreach(JointEventGroupDto.JointEventGroupCourseGroupDto group in course.groupLists)
|
|
|
+ {
|
|
|
+ foreach(JointEventSchedule schedule in jointEvent.schedule)
|
|
|
+ {
|
|
|
+ string scheduleStatus = await GetGroupFinishJointSchedule(jointEventId, jointGroupId, group.id, schedule);
|
|
|
+ group.schedule.Add(new {id = schedule.id, name = schedule.name, status = scheduleStatus });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JointCourseDto.Add(jointEventGroupDto);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return Ok(new { data = JointCourse });
|
|
|
+ return Ok(new { data = JointCourseDto });
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
@@ -501,19 +520,31 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (string.IsNullOrWhiteSpace(jointCourse.id))
|
|
|
+ //刪除
|
|
|
+ if (string.IsNullOrWhiteSpace(jointCourse.id) && jointCourse.courseLists.Count.Equals(0))
|
|
|
+ {
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<JointEventGroupDb>(jointCourse.id, new PartitionKey("JointCourse"));
|
|
|
+ return Ok(new { errCode = "", err = "", jointCourse = new { } });
|
|
|
+ }
|
|
|
+ //新建修改
|
|
|
+ else
|
|
|
{
|
|
|
- jointCourse.scope = scope;
|
|
|
- jointCourse.id = Guid.NewGuid().ToString();
|
|
|
- jointCourse.code = "JointCourse";
|
|
|
- jointCourse.pk = "JointCourse";
|
|
|
- jointCourse.jointEventId = jointEventId;
|
|
|
- jointCourse.jointGroupId = jointGroupId;
|
|
|
- jointCourse.creatorId = creatorId;
|
|
|
- jointCourse.creatorName = creatorName;
|
|
|
+ //新建
|
|
|
+ if (string.IsNullOrWhiteSpace(jointCourse.id))
|
|
|
+ {
|
|
|
+ jointCourse.scope = scope;
|
|
|
+ jointCourse.id = Guid.NewGuid().ToString();
|
|
|
+ jointCourse.code = "JointCourse";
|
|
|
+ jointCourse.pk = "JointCourse";
|
|
|
+ jointCourse.jointEventId = jointEventId;
|
|
|
+ jointCourse.jointGroupId = jointGroupId;
|
|
|
+ jointCourse.creatorId = creatorId;
|
|
|
+ jointCourse.creatorName = creatorName;
|
|
|
+ }
|
|
|
+ //修改
|
|
|
+ jointCourse.courseLists = courseLists;
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<JointEventGroupDb>(jointCourse, new PartitionKey("JointCourse"));
|
|
|
}
|
|
|
- jointCourse.courseLists = courseLists;
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<JointEventGroupDb>(jointCourse, new PartitionKey("JointCourse"));
|
|
|
|
|
|
//取得該老師報名該活動該組別且progress="going"的JointExam並生成Exam
|
|
|
List<JointExam> jointExams = new List<JointExam>();
|
|
@@ -950,11 +981,105 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //以JointSchedule為單位,判斷班級/課程名單是否完成
|
|
|
+ //判斷某groupId在某JointSchedule是否完成
|
|
|
+ private async Task<string> GetGroupFinishJointSchedule(string jointEventId, string jointGroupId, string groupId, JointEventSchedule schedule)
|
|
|
+ {
|
|
|
+ string result = "undo";
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ string scope = "private"; //先只指定個人
|
|
|
+ string container = (scope.Equals("school")) ? Constant.School : Constant.Teacher;
|
|
|
+ switch (schedule.type)
|
|
|
+ {
|
|
|
+ //報名
|
|
|
+ case "join":
|
|
|
+ StringBuilder stringBuilder = new($"SELECT DISTINCT ccg.id FROM c JOIN cc IN c.courseLists JOIN ccg IN cc.groupLists WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND ccg.id = '{groupId}' ");
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, container).GetItemQueryStreamIteratorSql(queryText: stringBuilder.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())
|
|
|
+ {
|
|
|
+ if (obj.GetProperty("id").GetString().Equals(groupId))
|
|
|
+ {
|
|
|
+ result = "complete";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ //競賽
|
|
|
+ case "exam":
|
|
|
+ //取得本Schedule的所有JointExam
|
|
|
+ List<string> jointExamIdList = new List<string>();
|
|
|
+ StringBuilder stringBuilderJointExam = new($"SELECT DISTINCT VALUE c.id FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.jointScheduleId = '{schedule.id}' ");
|
|
|
+ var resultJointExam = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<string>(stringBuilderJointExam.ToString(), $"JointExam");
|
|
|
+ if (resultJointExam.list.IsNotEmpty())
|
|
|
+ {
|
|
|
+ jointExamIdList = new List<string>(resultJointExam.list);
|
|
|
+ }
|
|
|
+ //取得所有個人評量
|
|
|
+ List<string> examIdList = new List<string>();
|
|
|
+ string sqlExam = $"SELECT DISTINCT VALUE c.id FROM c WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(jointExamIdList)}, c.jointExamId) AND ARRAY_CONTAINS(c.stuLists, '{groupId}') AND CONTAINS(c.code, 'Exam-')";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIteratorSql<string>(queryText: sqlExam, requestOptions: new QueryRequestOptions { }))
|
|
|
+ {
|
|
|
+ examIdList.Add(item);
|
|
|
+ }
|
|
|
+ //取得所有考試的作答結果
|
|
|
+ List<string> finishExamIdList = new List<string>();
|
|
|
+ string sqlExamClassResult = $"SELECT c.examId, c.info.id as classId, c.studentAnswers FROM c WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(examIdList)}, c.examId) AND c.info.id = '{groupId}' AND c.progress=true AND CONTAINS(c.code, 'ExamClassResult')";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryStreamIteratorSql(queryText: sqlExamClassResult, requestOptions: new QueryRequestOptions() { }))
|
|
|
+ {
|
|
|
+ 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())
|
|
|
+ {
|
|
|
+ string examId = obj.GetProperty("examId").ToString();
|
|
|
+ string classId = obj.GetProperty("classId").ToString();
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ finishExamIdList.Add(examId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //結果判斷
|
|
|
+ if (jointExamIdList.Count > 0 && jointExamIdList.Count.Equals(finishExamIdList.Count))
|
|
|
+ {
|
|
|
+ result = "complete";
|
|
|
+ }
|
|
|
+ else if (jointExamIdList.Count > 0 && finishExamIdList.Count > 0 && jointExamIdList.Count > finishExamIdList.Count)
|
|
|
+ {
|
|
|
+ result = "doing";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ //以JointSchedule為單位,判斷班級/課程名單是否完成 ※回傳已完成的courseId、groupId
|
|
|
private async Task<List<string>> IfJointScheduleComplete(string jointEventId, string jointGroupId, string jointScheduleId, string scope, string creatorId, string school, List<string> classIds, List<string> groupListIds)
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
List<string> result = new List<string>();
|
|
|
+ //0. 取得jointEvent、JointEventSchedule
|
|
|
+ JointEvent jointEvent = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<JointEvent>(jointEventId, new PartitionKey("JointEvent"));
|
|
|
+ if (jointEvent == null)
|
|
|
+ {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ JointEventSchedule jointEventSchedule = jointEvent.schedule.Where(s => s.id.Equals(jointScheduleId)).FirstOrDefault();
|
|
|
+ if(jointEventSchedule == null)
|
|
|
+ {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
//1. 用jointEventId、jointGroupId 取得所有老師的 班級/課程名單
|
|
|
List<JointEventGroupDb> jointEventCourse = new List<JointEventGroupDb>();
|
|
|
StringBuilder stringBuilderJointCourse = new($"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' ");
|
|
@@ -1006,6 +1131,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
}
|
|
|
//4. 用 IfJointExamComplete 列出完成評量的 班級/課程名單
|
|
|
|
|
|
+
|
|
|
//5. 回傳值
|
|
|
|
|
|
return result;
|
|
@@ -1040,12 +1166,12 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
string infoId = obj.GetProperty("infoId").GetString();
|
|
|
List<string> studentIds = obj.GetProperty("studentIds").ToObject<List<string>>();
|
|
|
List<List<string>> studentAnswers = obj.GetProperty("studentIds").ToObject<List<List<string>>>();
|
|
|
- int hasAnswerCount = 0;
|
|
|
+ bool hasAnswer = false;
|
|
|
foreach(List<string> studentAnswer in studentAnswers)
|
|
|
{
|
|
|
- if (studentAnswer.Count > 0) hasAnswerCount++;
|
|
|
+ if (studentAnswer.Count > 0) hasAnswer = true; break;
|
|
|
}
|
|
|
- if(studentIds.Count.Equals(hasAnswerCount))
|
|
|
+ if(hasAnswer)
|
|
|
{
|
|
|
result.Add(infoId);
|
|
|
}
|
|
@@ -1068,6 +1194,32 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
public string jointGroupId { get; set; }
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 統測活動老師報名課程 API輸出用
|
|
|
+ /// </summary>
|
|
|
+ public class JointEventGroupDto
|
|
|
+ {
|
|
|
+ public string scope { get; set; } //school:學校(選課班) private:個人
|
|
|
+ public string creatorId { get; set; }
|
|
|
+ public string creatorName { get; set; }
|
|
|
+ public string schoolId { get; set; } //老師個人課程時為null
|
|
|
+ public string periodId { get; set; } //老師個人課程時為null
|
|
|
+ public List<JointEventGroupCourseDto> courseLists { get; set; } = new();
|
|
|
+ public class JointEventGroupCourseDto
|
|
|
+ {
|
|
|
+ public string subjectId { get; set; } //老師個人課程時為null
|
|
|
+ public string courseId { get; set; }
|
|
|
+ public string courseName { get; set; }
|
|
|
+ public List<JointEventGroupCourseGroupDto> groupLists { get; set; } = new();
|
|
|
+ }
|
|
|
+ public class JointEventGroupCourseGroupDto
|
|
|
+ {
|
|
|
+ public string id { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ public List<object> schedule { get; set; } = new List<object>(); //已完成的行程
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//以JointEvent.schedule為資訊新建更新JointExam
|
|
|
//public async Task<ItemResponse<JointExam>> upsertJointExamBySchedule(string jointEventId, string creatorId, List<JointEventTGroupBase> groupLists, List<PaperSimple> papers, JointEvent.JointEventSchedule scheduleRow)
|
|
|
//{
|