|
@@ -112,331 +112,5 @@ namespace TEAMModelOS.Controllers.XTest
|
|
|
return BadRequest(e.StackTrace);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "teacher")]
|
|
|
- [HttpPost("fix-stu-course")]
|
|
|
- public async Task<IActionResult> fixStuCourse(JsonElement request) {
|
|
|
-
|
|
|
- string originCode = request.GetProperty("originCode").GetString();
|
|
|
- List<Course> courses = new List<Course>();
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- var query = $"select * from c ";
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Course>(queryText: query,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{originCode}") }))
|
|
|
- {
|
|
|
- courses.Add(item);
|
|
|
- }
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Course>(queryText: query,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{originCode}") }))
|
|
|
- {
|
|
|
- courses.Add(item);
|
|
|
- }
|
|
|
- //2.获取课程的id 并尝试添加或移除对应的学生课程记录StuCourse。
|
|
|
- foreach (var course in courses)
|
|
|
- {
|
|
|
- if (course.schedule.IsNotEmpty())
|
|
|
- {
|
|
|
- foreach (var sc in course.schedule)
|
|
|
- {
|
|
|
- if (!string.IsNullOrEmpty(sc.stulist))
|
|
|
- {
|
|
|
- (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, new List<string>() { sc.stulist }, course.school);
|
|
|
- foreach (var addStu in studentss)
|
|
|
- {
|
|
|
- var stuCourse = new StuCourse
|
|
|
- {
|
|
|
- id = course.id,
|
|
|
- scode = course.code,
|
|
|
- name = course.name,
|
|
|
- code = $"StuCourse-{course.school}-{addStu.id}",
|
|
|
- scope = course.scope,
|
|
|
- school = course.school,
|
|
|
- creatorId = course.creatorId,
|
|
|
- pk = "StuCourse"
|
|
|
- };
|
|
|
- await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stuCourse, new PartitionKey(stuCourse.code));
|
|
|
- }
|
|
|
- foreach (var addTmd in tmdids)
|
|
|
- {
|
|
|
- var tmdCourse = new StuCourse
|
|
|
- {
|
|
|
- id = course.id,
|
|
|
- scode = course.code,
|
|
|
- name = course.name,
|
|
|
- code = $"StuCourse-{addTmd}",
|
|
|
- scope = course.scope,
|
|
|
- //school = courseChange.school,
|
|
|
- creatorId = course.creatorId,
|
|
|
- pk = "StuCourse"
|
|
|
- };
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(tmdCourse, new PartitionKey(tmdCourse.code));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return new OkObjectResult(new { });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "teacher")]
|
|
|
- [HttpPost("fix-exam-activity")]
|
|
|
- public async Task<IActionResult> ExamActivity(JsonElement request)
|
|
|
- {
|
|
|
-
|
|
|
- var datas = request.ToObject<List<string>>();
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
-
|
|
|
- var query = $"select * from c ";
|
|
|
- foreach (string data in datas)
|
|
|
- {
|
|
|
- List<ExamInfo> exams = new List<ExamInfo>();
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(
|
|
|
- queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{data}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- exams.Add(obj.ToObject<ExamInfo>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- foreach (var info in exams)
|
|
|
- {
|
|
|
- if (!info.classes.IsNotEmpty())
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
- List<string> sub = new List<string>();
|
|
|
- foreach (ExamSubject subject in info.subjects)
|
|
|
- {
|
|
|
- sub.Add(subject.id);
|
|
|
- }
|
|
|
- (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
|
|
|
- List<StuActivity> stuActivities = new List<StuActivity>();
|
|
|
- List<StuActivity> tmdActivities = new List<StuActivity>();
|
|
|
- if (tmdids.IsNotEmpty())
|
|
|
- {
|
|
|
- tmdids.ForEach(x => {
|
|
|
- tmdActivities.Add(new StuActivity
|
|
|
- {
|
|
|
- pk = "Activity",
|
|
|
- id = info.id,
|
|
|
- code = $"Activity-{x}",
|
|
|
- type = "exam",
|
|
|
- name = info.name,
|
|
|
- startTime = info.startTime,
|
|
|
- endTime = info.endTime,
|
|
|
- scode = info.code,
|
|
|
- scope = info.scope,
|
|
|
- school = info.school,
|
|
|
- creatorId = info.creatorId,
|
|
|
- subjects = sub,
|
|
|
- blob = null,
|
|
|
- owner = info.owner
|
|
|
-
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- if (studentss.IsNotEmpty())
|
|
|
- {
|
|
|
- studentss.ForEach(x => {
|
|
|
- stuActivities.Add(new StuActivity
|
|
|
- {
|
|
|
- pk = "Activity",
|
|
|
- id = info.id,
|
|
|
- code = $"Activity-{info.school}-{x.id}",
|
|
|
- type = "exam",
|
|
|
- name = info.name,
|
|
|
- startTime = info.startTime,
|
|
|
- endTime = info.endTime,
|
|
|
- scode = info.code,
|
|
|
- scope = info.scope,
|
|
|
- school = info.school,
|
|
|
- creatorId = info.creatorId,
|
|
|
- subjects = sub,
|
|
|
- blob = null,
|
|
|
- owner = info.owner
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
|
|
|
- }
|
|
|
- }
|
|
|
- return new OkObjectResult(new { });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "teacher")]
|
|
|
- [HttpPost("fix-vote-activity")]
|
|
|
- public async Task<IActionResult> VoteActivity(JsonElement request)
|
|
|
- {
|
|
|
-
|
|
|
- var datas = request.ToObject<List<string>>();
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
-
|
|
|
- var query = $"select * from c ";
|
|
|
- foreach (string data in datas)
|
|
|
- {
|
|
|
- List<Vote> votes = new List<Vote>();
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(
|
|
|
- queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Vote-{data}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- votes.Add(obj.ToObject<Vote>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- foreach (var info in votes)
|
|
|
- {
|
|
|
- if (!info.classes.IsNotEmpty())
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
|
|
|
- List<StuActivity> stuActivities = new List<StuActivity>();
|
|
|
- List<StuActivity> tmdActivities = new List<StuActivity>();
|
|
|
- if (tmdids.IsNotEmpty())
|
|
|
- {
|
|
|
- tmdids.ForEach(x => {
|
|
|
- tmdActivities.Add(new StuActivity
|
|
|
- {
|
|
|
- pk = "Activity",
|
|
|
- id = info.id,
|
|
|
- code = $"Activity-{x}",
|
|
|
- type = "vote",
|
|
|
- name = info.name,
|
|
|
- startTime = info.startTime,
|
|
|
- endTime = info.endTime,
|
|
|
- scode = info.code,
|
|
|
- scope = info.scope,
|
|
|
- school = info.school,
|
|
|
- creatorId = info.creatorId,
|
|
|
- subjects = new List<string>() { "" },
|
|
|
- blob = null,
|
|
|
- owner = info.owner
|
|
|
-
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- if (studentss.IsNotEmpty())
|
|
|
- {
|
|
|
- studentss.ForEach(x => {
|
|
|
- stuActivities.Add(new StuActivity
|
|
|
- {
|
|
|
- pk = "Activity",
|
|
|
- id = info.id,
|
|
|
- code = $"Activity-{info.school}-{x.id}",
|
|
|
- type = "vote",
|
|
|
- name = info.name,
|
|
|
- startTime = info.startTime,
|
|
|
- endTime = info.endTime,
|
|
|
- scode = info.code,
|
|
|
- scope = info.scope,
|
|
|
- school = info.school,
|
|
|
- creatorId = info.creatorId,
|
|
|
- subjects = new List<string>() { "" },
|
|
|
- blob = null,
|
|
|
- owner = info.owner
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
|
|
|
- }
|
|
|
- }
|
|
|
- return new OkObjectResult(new { });
|
|
|
- }
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "teacher")]
|
|
|
- [HttpPost("fix-survey-activity")]
|
|
|
- public async Task<IActionResult> SurveyActivity(JsonElement request)
|
|
|
- {
|
|
|
- var datas = request.ToObject<List<string>>();
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- var query = $"select * from c ";
|
|
|
- foreach (string data in datas)
|
|
|
- {
|
|
|
- List<Survey> surveys = new List<Survey>();
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(
|
|
|
- queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Survey-{data}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
- {
|
|
|
- surveys.Add(obj.ToObject<Survey>());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- foreach (var info in surveys)
|
|
|
- {
|
|
|
- if (!info.classes.IsNotEmpty())
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
- (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
|
|
|
- List<StuActivity> stuActivities = new List<StuActivity>();
|
|
|
- List<StuActivity> tmdActivities = new List<StuActivity>();
|
|
|
- if (tmdids.IsNotEmpty())
|
|
|
- {
|
|
|
- tmdids.ForEach(x => {
|
|
|
- tmdActivities.Add(new StuActivity
|
|
|
- {
|
|
|
- pk = "Activity",
|
|
|
- id = info.id,
|
|
|
- code = $"Activity-{x}",
|
|
|
- type = "survey",
|
|
|
- name = info.name,
|
|
|
- startTime = info.startTime,
|
|
|
- endTime = info.endTime,
|
|
|
- scode = info.code,
|
|
|
- scope = info.scope,
|
|
|
- school = info.school,
|
|
|
- creatorId = info.creatorId,
|
|
|
- subjects = new List<string>() { "" },
|
|
|
- blob = info.blob
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- if (studentss.IsNotEmpty())
|
|
|
- {
|
|
|
- studentss.ForEach(x => {
|
|
|
- stuActivities.Add(new StuActivity
|
|
|
- {
|
|
|
- pk = "Activity",
|
|
|
- id = info.id,
|
|
|
- code = $"Activity-{info.school}-{x.id}",
|
|
|
- type = "survey",
|
|
|
- name = info.name,
|
|
|
- startTime = info.startTime,
|
|
|
- endTime = info.endTime,
|
|
|
- scode = info.code,
|
|
|
- scope = info.scope,
|
|
|
- school = info.school,
|
|
|
- creatorId = info.creatorId,
|
|
|
- subjects = new List<string>() { "" },
|
|
|
- blob = info.blob
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
|
|
|
- }
|
|
|
- }
|
|
|
- return new OkObjectResult(new { });
|
|
|
- }
|
|
|
}
|
|
|
}
|