|
@@ -27,6 +27,7 @@ using TEAMModelOS.SDK.Models.Cosmos;
|
|
using Azure.Messaging.ServiceBus;
|
|
using Azure.Messaging.ServiceBus;
|
|
using Azure.Storage.Sas;
|
|
using Azure.Storage.Sas;
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
|
+using TEAMModelFunction;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
@@ -502,63 +503,65 @@ namespace TEAMModelOS.Controllers
|
|
//[AuthToken(Roles = "teacher,student")]
|
|
//[AuthToken(Roles = "teacher,student")]
|
|
public async Task<IActionResult> StuList(JsonElement request)
|
|
public async Task<IActionResult> StuList(JsonElement request)
|
|
{
|
|
{
|
|
- List<string> classes = new List<string>();
|
|
|
|
- if (request.TryGetProperty("classes", out JsonElement cs)) {
|
|
|
|
- classes = cs.ToObject<List<string>>();
|
|
|
|
- }
|
|
|
|
- if (request.TryGetProperty("school", out JsonElement school))
|
|
|
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id))
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ return BadRequest();
|
|
}
|
|
}
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
|
- List<Students> studentss = new List<Students>();
|
|
|
|
- List<string> sqlList = new List<string>();
|
|
|
|
- classes.ForEach(x => { sqlList.Add($" '{x}' "); });
|
|
|
|
- string sql = string.Join(" , ", sqlList);
|
|
|
|
- List<StuList> schList = new List<StuList>();
|
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
|
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList-{school}") }))
|
|
|
|
|
|
+ //活动分区
|
|
|
|
+ if (!request.TryGetProperty("code", out JsonElement code))
|
|
{
|
|
{
|
|
- schList.Add(item);
|
|
|
|
|
|
+ return BadRequest();
|
|
}
|
|
}
|
|
- List<StuList> tchLists = new List<StuList>();
|
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<StuList>(queryText: $"select value(c) from c where c.id in ({sql})",
|
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
|
|
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+ Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>($"{id}", new Azure.Cosmos.PartitionKey($"{code}"));
|
|
|
|
+
|
|
|
|
+ (List<string> tmdids, List<Students> students) = await TriggerStuActivity.GetStuList(client, survey.classes, survey.school);
|
|
|
|
+ List<StuActivity> stuActivities = new List<StuActivity>();
|
|
|
|
+ List<StuActivity> tmdActivities = new List<StuActivity>();
|
|
|
|
+ if (tmdids.IsNotEmpty())
|
|
{
|
|
{
|
|
- tchLists.Add(item);
|
|
|
|
|
|
+ tmdids.ForEach(x => {
|
|
|
|
+ tmdActivities.Add(new StuActivity
|
|
|
|
+ {
|
|
|
|
+ pk = "Activity",
|
|
|
|
+ id = survey.id,
|
|
|
|
+ code = $"Activity-{x}",
|
|
|
|
+ type = "survey",
|
|
|
|
+ name = survey.name,
|
|
|
|
+ startTime = survey.startTime,
|
|
|
|
+ endTime = survey.endTime,
|
|
|
|
+ scode = survey.code,
|
|
|
|
+ scope = survey.scope,
|
|
|
|
+ school = survey.school,
|
|
|
|
+ creatorId = survey.creatorId,
|
|
|
|
+ subjects = new List<string> { "" }
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- List<Student> students = new List<Student>();
|
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
|
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
|
|
|
|
|
|
+ if (students.IsNotEmpty())
|
|
{
|
|
{
|
|
- students.Add(item);
|
|
|
|
|
|
+ students.ForEach(x => {
|
|
|
|
+ stuActivities.Add(new StuActivity
|
|
|
|
+ {
|
|
|
|
+ pk = "Activity",
|
|
|
|
+ id = survey.id,
|
|
|
|
+ code = $"Activity-{survey.school}-{x.id}",
|
|
|
|
+ type = "survey",
|
|
|
|
+ name = survey.name,
|
|
|
|
+ startTime = survey.startTime,
|
|
|
|
+ endTime = survey.endTime,
|
|
|
|
+ scode = survey.code,
|
|
|
|
+ scope = survey.scope,
|
|
|
|
+ school = survey.school,
|
|
|
|
+ creatorId = survey.creatorId,
|
|
|
|
+ subjects = new List<string> { "" }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- List<string> tmdids = new List<string>();
|
|
|
|
- schList.ForEach(x => {
|
|
|
|
- if (x.students.IsNotEmpty())
|
|
|
|
- {
|
|
|
|
- studentss.AddRange(x.students);
|
|
|
|
- }
|
|
|
|
- if (x.tmids.IsNotEmpty())
|
|
|
|
- {
|
|
|
|
- tmdids.AddRange(x.tmids);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- tchLists.ForEach(x =>
|
|
|
|
- {
|
|
|
|
- if (x.students.IsNotEmpty())
|
|
|
|
- {
|
|
|
|
- studentss.AddRange(x.students);
|
|
|
|
- }
|
|
|
|
- if (x.tmids.IsNotEmpty())
|
|
|
|
- {
|
|
|
|
- tmdids.AddRange(x.tmids);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- students.ForEach(x => {
|
|
|
|
- studentss.Add(new Students { id = x.id, code = x.code });
|
|
|
|
- });
|
|
|
|
- return Ok(new { tmdids, studentss });
|
|
|
|
|
|
+ await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
|
|
|
|
+
|
|
|
|
+ return Ok(new { tmdids });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public class QuestionRecord
|
|
public class QuestionRecord
|