|
@@ -15,108 +15,149 @@ namespace TEAMModelFunction
|
|
|
{
|
|
|
public class StuListService
|
|
|
{
|
|
|
- public static async Task FixActivity(CosmosClient client, StuListChange stuListChange, string type)
|
|
|
+ public static async Task FixActivity(CosmosClient client,DingDing _dingDing, StuListChange stuListChange, string type)
|
|
|
{
|
|
|
- var query = $"SELECT distinct c.owner, c.id,c.code, c.classes,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime FROM c join A1 in c.classes where c.pk='{type}' and A1 in('{stuListChange.listid}') ";
|
|
|
- List<MQActivity> datas = new List<MQActivity>();
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: query,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{stuListChange.originCode}") }))
|
|
|
+ try
|
|
|
{
|
|
|
- datas.Add(item);
|
|
|
- }
|
|
|
- foreach (MQActivity activity in datas)
|
|
|
- {
|
|
|
- //已经完结的不再允许加入
|
|
|
- if (activity.progress.Equals("finish") || activity.progress.Equals("pending"))
|
|
|
- {
|
|
|
- continue;
|
|
|
+ var query = $"SELECT distinct c.owner, c.id,c.code, c.classes,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime FROM c join A1 in c.classes where c.pk='{type}' and A1 in('{stuListChange.listid}') ";
|
|
|
+ List<MQActivity> datas = new List<MQActivity>();
|
|
|
+ if (stuListChange.scope.Equals("school", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(stuListChange.school)) {
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: query,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{stuListChange.school}") }))
|
|
|
+ {
|
|
|
+ datas.Add(item);
|
|
|
+ }
|
|
|
+ ///还要处理该学校每个老师发布的班级的
|
|
|
+ List<SchoolTeacher> teachers = new List<SchoolTeacher>();
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<SchoolTeacher>(queryText: $"SELECT c.id, c.name FROM c",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{stuListChange.school}") }))
|
|
|
+ {
|
|
|
+ teachers.Add(item);
|
|
|
+ }
|
|
|
+ foreach (var techer in teachers) {
|
|
|
+ var queryTech = $"SELECT distinct c.owner, c.id,c.code, c.classes,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime FROM c " +
|
|
|
+ $" join A1 in c.classes where c.school='{stuListChange.school}' and c.pk='{type}' and A1 in('{stuListChange.listid}') ";
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: queryTech,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{techer.id}") }))
|
|
|
+ {
|
|
|
+ datas.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- //学生新加入名单的
|
|
|
- foreach (Students students in stuListChange.stujoin)
|
|
|
+ if (stuListChange.scope.Equals("private", StringComparison.OrdinalIgnoreCase)&&!string.IsNullOrEmpty(stuListChange.creatorId))
|
|
|
{
|
|
|
- var stucourse = new StuActivity
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<MQActivity>(queryText: query,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{stuListChange.creatorId}") }))
|
|
|
{
|
|
|
- id = activity.id,
|
|
|
- scode = activity.code,
|
|
|
- name = activity.name,
|
|
|
- code = $"Activity-{activity.school}-{students.id}",
|
|
|
- scope = activity.scope,
|
|
|
- school = activity.school,
|
|
|
- creatorId = activity.creatorId,
|
|
|
- pk = "Activity",
|
|
|
- type = type,
|
|
|
- subjects = activity.pk.ToLower().Equals("exam") && activity.subjects.IsNotEmpty() ? new List<string>() { activity.subjects[0].id } : new List<string>() { "" },
|
|
|
- startTime = activity.startTime,
|
|
|
- endTime = activity.endTime,
|
|
|
- blob=activity.blob,
|
|
|
- owner= activity.owner
|
|
|
- };
|
|
|
- await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
|
|
|
- }//tmd新加入的
|
|
|
- foreach (string tmdid in stuListChange.tmdjoin)
|
|
|
+ datas.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n名单发生变更 需要处理的活动\n{datas.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ foreach (MQActivity activity in datas)
|
|
|
{
|
|
|
- var stucourse = new StuActivity
|
|
|
+ //已经完结的不再允许加入
|
|
|
+ if (activity.progress.Equals("finish") || activity.progress.Equals("pending"))
|
|
|
{
|
|
|
- id = activity.id,
|
|
|
- scode = activity.code,
|
|
|
- name = activity.name,
|
|
|
- code = $"Activity-{tmdid}",
|
|
|
- scope = activity.scope,
|
|
|
- school = activity.school,
|
|
|
- creatorId = activity.creatorId,
|
|
|
- pk = "Activity",
|
|
|
- type = type,
|
|
|
- subjects = activity.pk.ToLower().Equals("exam") && activity.subjects.IsNotEmpty() ? new List<string>() { activity.subjects[0].id } : new List<string>() { "" },
|
|
|
- startTime = activity.startTime,
|
|
|
- endTime = activity.endTime,
|
|
|
- blob = activity.blob,
|
|
|
- owner = activity.owner
|
|
|
- };
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
|
|
|
- }
|
|
|
- foreach (Students students in stuListChange.stuleave) {
|
|
|
- try {
|
|
|
-
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{activity.school}-{students.id}"));
|
|
|
- } catch {
|
|
|
- //仅处理未写入的数据。
|
|
|
+ continue;
|
|
|
}
|
|
|
- }
|
|
|
- foreach (string tmdid in stuListChange.tmdhleave) {
|
|
|
- try
|
|
|
+ //学生新加入名单的
|
|
|
+ foreach (Students students in stuListChange.stujoin)
|
|
|
+ {
|
|
|
+ var stucourse = new StuActivity
|
|
|
+ {
|
|
|
+ id = activity.id,
|
|
|
+ scode = activity.code,
|
|
|
+ name = activity.name,
|
|
|
+ code = $"Activity-{activity.school}-{students.id}",
|
|
|
+ scope = activity.scope,
|
|
|
+ school = activity.school,
|
|
|
+ creatorId = activity.creatorId,
|
|
|
+ pk = "Activity",
|
|
|
+ type = type,
|
|
|
+ subjects = activity.pk.ToLower().Equals("exam") && activity.subjects.IsNotEmpty() ? new List<string>() { activity.subjects[0].id } : new List<string>() { "" },
|
|
|
+ startTime = activity.startTime,
|
|
|
+ endTime = activity.endTime,
|
|
|
+ blob = activity.blob,
|
|
|
+ owner = activity.owner
|
|
|
+ };
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n名单发生变更 新建活动中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
|
|
|
+ }//tmd新加入的
|
|
|
+ foreach (string tmdid in stuListChange.tmdjoin)
|
|
|
+ {
|
|
|
+ var stucourse = new StuActivity
|
|
|
+ {
|
|
|
+ id = activity.id,
|
|
|
+ scode = activity.code,
|
|
|
+ name = activity.name,
|
|
|
+ code = $"Activity-{tmdid}",
|
|
|
+ scope = activity.scope,
|
|
|
+ school = activity.school,
|
|
|
+ creatorId = activity.creatorId,
|
|
|
+ pk = "Activity",
|
|
|
+ type = type,
|
|
|
+ subjects = activity.pk.ToLower().Equals("exam") && activity.subjects.IsNotEmpty() ? new List<string>() { activity.subjects[0].id } : new List<string>() { "" },
|
|
|
+ startTime = activity.startTime,
|
|
|
+ endTime = activity.endTime,
|
|
|
+ blob = activity.blob,
|
|
|
+ owner = activity.owner
|
|
|
+ };
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixActivity\n名单发生变更 新建活动中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
|
|
|
+ }
|
|
|
+ foreach (Students students in stuListChange.stuleave)
|
|
|
{
|
|
|
+ try
|
|
|
+ {
|
|
|
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{tmdid}"));
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{activity.school}-{students.id}"));
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ //仅处理未写入的数据。
|
|
|
+ }
|
|
|
}
|
|
|
- catch
|
|
|
+ foreach (string tmdid in stuListChange.tmdhleave)
|
|
|
{
|
|
|
- //仅处理未写入的数据。
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{tmdid}"));
|
|
|
+ }
|
|
|
+ catch(CosmosException ex )
|
|
|
+ {
|
|
|
+ //仅处理未写入的数据。
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ catch(Exception ex ) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public static async Task FixStuCourse(CosmosClient client, StuListChange stuListChange)
|
|
|
+ public static async Task FixStuCourse(CosmosClient client,DingDing _dingDing, StuListChange stuListChange)
|
|
|
{
|
|
|
//1.查找学校或教师的课程是否包含该名单的课程。
|
|
|
var query = $"select distinct c.code,c.id,c.no,c.name,c.scope, c.creatorId,c.school from c join A0 in c.schedule where A0.stulist = '{stuListChange.listid}'";
|
|
|
List<Course> courses = new List<Course>();
|
|
|
- if (stuListChange.scope.Equals("school"))
|
|
|
+ if (stuListChange.scope.Equals("school") && !string.IsNullOrEmpty(stuListChange.school))
|
|
|
{
|
|
|
await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Course>(queryText: query,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.originCode}") }))
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.school}") }))
|
|
|
{
|
|
|
courses.Add(item);
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ if (stuListChange.scope.Equals("private") && !string.IsNullOrEmpty(stuListChange.creatorId))
|
|
|
{
|
|
|
await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Course>(queryText: query,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.originCode}") }))
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{stuListChange.creatorId}") }))
|
|
|
{
|
|
|
courses.Add(item);
|
|
|
}
|
|
|
}
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixStuCourse\n名单发生变更 需要处理的课程\n{courses.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
//2.获取课程的id 并尝试添加或移除对应的学生课程记录StuCourse。
|
|
|
foreach (var course in courses)
|
|
|
{
|
|
@@ -134,6 +175,7 @@ namespace TEAMModelFunction
|
|
|
creatorId = course.creatorId,
|
|
|
pk = "StuCourse"
|
|
|
};
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixStuCourse\n名单发生变更 新建课程中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
|
|
|
}
|
|
|
//tmd新加入的
|
|
@@ -150,6 +192,7 @@ namespace TEAMModelFunction
|
|
|
creatorId = course.creatorId,
|
|
|
pk = "StuCourse"
|
|
|
};
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-StuListService-FixStuCourse\n名单发生变更 新建课程中间表\n{stucourse.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
|
|
|
}
|
|
|
//移除名单的。 在点击相关的课程,再去二次校验是否存在,不存在则再去删除。
|