|
@@ -7,6 +7,7 @@ using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
|
using TEAMModelOS.SDK.DI;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
|
|
|
namespace TEAMModelFunction
|
|
@@ -41,48 +42,295 @@ namespace TEAMModelFunction
|
|
|
if (courseChange == null) {
|
|
|
return;
|
|
|
}
|
|
|
- //根据新增名单获取 新增的学生id 及timdid
|
|
|
- (List<string> addTmdids, List<Students> addStudents) = await TriggerStuActivity.GetStuList(client, _dingDing, courseChange.addList, courseChange.school);
|
|
|
- //根据删除名单获取 新增的学生id 及timdid
|
|
|
- (List<string> delTmdids, List<Students> delStudents) = await TriggerStuActivity.GetStuList(client, _dingDing, courseChange.delList, courseChange.school);
|
|
|
- foreach (var addStu in addStudents)
|
|
|
- {
|
|
|
- var course = new StuCourse
|
|
|
+ foreach (var cls in courseChange.addClass) {
|
|
|
+ (List<string> addTmdidsCls, List<Students> addStudentsCls) = await TriggerStuActivity.GetStuList(client, _dingDing,new List<string> { cls}, courseChange.school);
|
|
|
+ foreach (var stu in addStudentsCls) {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
|
|
|
+ if (!stuCourse.Value.classId.Contains(cls)) {
|
|
|
+ stuCourse.Value.classId.Add(cls);
|
|
|
+ }
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ if (ex.Response.Status == 404)
|
|
|
+ {
|
|
|
+ var course = new StuCourse
|
|
|
+ {
|
|
|
+ id = courseChange.id,
|
|
|
+ scode = courseChange.code,
|
|
|
+ name = courseChange.name,
|
|
|
+ code = $"StuCourse-{courseChange.school}-{stu.id}",
|
|
|
+ scope = courseChange.scope,
|
|
|
+ school = courseChange.school,
|
|
|
+ creatorId = courseChange.creatorId,
|
|
|
+ classId= new List<string> { cls},
|
|
|
+ pk = "StuCourse"
|
|
|
+ };
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(course, new PartitionKey(course.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (var tmd in addTmdidsCls)
|
|
|
{
|
|
|
- id = courseChange.id,
|
|
|
- scode = courseChange.code,
|
|
|
- name = courseChange.name,
|
|
|
- code = $"StuCourse-{courseChange.school}-{addStu.id}",
|
|
|
- scope = courseChange.scope,
|
|
|
- school = courseChange.school,
|
|
|
- creatorId = courseChange.creatorId,
|
|
|
- pk = "StuCourse"
|
|
|
- };
|
|
|
- await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(course, new PartitionKey(course.code));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
|
|
|
+ if (!stuCourse.Value.classId.Contains(cls))
|
|
|
+ {
|
|
|
+ stuCourse.Value.classId.Add(cls);
|
|
|
+ }
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ if (ex.Response.Status == 404)
|
|
|
+ {
|
|
|
+ var course = new StuCourse
|
|
|
+ {
|
|
|
+ id = courseChange.id,
|
|
|
+ scode = courseChange.code,
|
|
|
+ name = courseChange.name,
|
|
|
+ code = $"StuCourse-{tmd}",
|
|
|
+ scope = courseChange.scope,
|
|
|
+ school = courseChange.school,
|
|
|
+ creatorId = courseChange.creatorId,
|
|
|
+ classId = new List<string> { cls },
|
|
|
+ pk = "StuCourse"
|
|
|
+ };
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(course, new PartitionKey(course.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- foreach (var addTmd in addTmdids)
|
|
|
+
|
|
|
+ foreach (var list in courseChange.addList)
|
|
|
{
|
|
|
- var course = new StuCourse
|
|
|
+ (List<string> addTmdidsCls, List<Students> addStudentsCls) = await TriggerStuActivity.GetStuList(client, _dingDing, new List<string> { list }, courseChange.school);
|
|
|
+ foreach (var stu in addStudentsCls)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{stu.schoolId}-{stu.id}"));
|
|
|
+ if (!stuCourse.Value.stulist.Contains(list))
|
|
|
+ {
|
|
|
+ stuCourse.Value.stulist.Add(list);
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{stu.schoolId}-{stu.id}"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ if (ex.Response.Status == 404)
|
|
|
+ {
|
|
|
+ var course = new StuCourse
|
|
|
+ {
|
|
|
+ id = courseChange.id,
|
|
|
+ scode = courseChange.code,
|
|
|
+ name = courseChange.name,
|
|
|
+ code = $"StuCourse-{courseChange.school}-{stu.id}",
|
|
|
+ scope = courseChange.scope,
|
|
|
+ school = courseChange.school,
|
|
|
+ creatorId = courseChange.creatorId,
|
|
|
+ stulist = new List<string> { list },
|
|
|
+ pk = "StuCourse"
|
|
|
+ };
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(course, new PartitionKey(course.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (var tmd in addTmdidsCls)
|
|
|
{
|
|
|
- id = courseChange.id,
|
|
|
- scode = courseChange.code,
|
|
|
- name = courseChange.name,
|
|
|
- code = $"StuCourse-{addTmd}",
|
|
|
- scope = courseChange.scope,
|
|
|
- //school = courseChange.school,
|
|
|
- creatorId = courseChange.creatorId,
|
|
|
- pk = "StuCourse"
|
|
|
- };
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(course, new PartitionKey(course.code));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
|
|
|
+ if (!stuCourse.Value.stulist.Contains(list))
|
|
|
+ {
|
|
|
+ stuCourse.Value.stulist.Add(list);
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ if (ex.Response.Status == 404)
|
|
|
+ {
|
|
|
+ var course = new StuCourse
|
|
|
+ {
|
|
|
+ id = courseChange.id,
|
|
|
+ scode = courseChange.code,
|
|
|
+ name = courseChange.name,
|
|
|
+ code = $"StuCourse-{tmd}",
|
|
|
+ scope = courseChange.scope,
|
|
|
+ school = courseChange.school,
|
|
|
+ creatorId = courseChange.creatorId,
|
|
|
+ stulist = new List<string> { list },
|
|
|
+ pk = "StuCourse"
|
|
|
+ };
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(course, new PartitionKey(course.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- foreach (var delStu in delStudents)
|
|
|
- {
|
|
|
- await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(courseChange.id, new PartitionKey($"Course-{courseChange.school}-{delStu.id}"));
|
|
|
+
|
|
|
+ foreach (var delCls in courseChange.delClass) {
|
|
|
+ (List<string> delTmdidsCls, List<Students> delStudentsCls) = await TriggerStuActivity.GetStuList(client, _dingDing, new List<string> { delCls }, courseChange.school);
|
|
|
+ foreach (var stu in delStudentsCls)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
|
|
|
+
|
|
|
+ if (stuCourse.Value.classId.Contains(delCls))
|
|
|
+ {
|
|
|
+ stuCourse.Value.classId.Remove(delCls);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
|
|
|
+ {
|
|
|
+ //当两个列表都不存在时则直接删除
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").DeleteItemAsync<StuCourse>( courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (var tmd in delTmdidsCls)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
|
|
|
+
|
|
|
+ if (stuCourse.Value.classId.Contains(delCls))
|
|
|
+ {
|
|
|
+ stuCourse.Value.classId.Remove(delCls);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
|
|
|
+ {
|
|
|
+ //当两个列表都不存在时则直接删除
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- foreach (var delTmd in delTmdids)
|
|
|
+ foreach (var delList in courseChange.delList)
|
|
|
{
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(courseChange.id, new PartitionKey($"Course-{delTmd}"));
|
|
|
+ (List<string> delTmdidsCls, List<Students> delStudentsCls) = await TriggerStuActivity.GetStuList(client, _dingDing, new List<string> { delList }, courseChange.school);
|
|
|
+ foreach (var stu in delStudentsCls)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Student").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
|
|
|
+
|
|
|
+ if (stuCourse.Value.stulist.Contains(delList))
|
|
|
+ {
|
|
|
+ stuCourse.Value.stulist.Remove(delList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
|
|
|
+ {
|
|
|
+ //当两个列表都不存在时则直接删除
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").DeleteItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{courseChange.school}-{stu.id}"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (var tmd in delTmdidsCls)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ItemResponse<StuCourse> stuCourse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
|
|
|
+
|
|
|
+ if (stuCourse.Value.stulist.Contains(delList))
|
|
|
+ {
|
|
|
+ stuCourse.Value.stulist.Remove(delList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!stuCourse.Value.classId.IsNotEmpty() && !stuCourse.Value.stulist.IsNotEmpty())
|
|
|
+ {
|
|
|
+ //当两个列表都不存在时则直接删除
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<StuCourse>(courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<StuCourse>(stuCourse, courseChange.id, new PartitionKey($"StuCourse-{tmd}"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ ////根据新增名单获取 新增的学生id 及timdid
|
|
|
+ //(List<string> addTmdids, List<Students> addStudents) = await TriggerStuActivity.GetStuList(client, _dingDing, courseChange.addList, courseChange.school);
|
|
|
+ ////根据删除名单获取 新增的学生id 及timdid
|
|
|
+ //(List<string> delTmdids, List<Students> delStudents) = await TriggerStuActivity.GetStuList(client, _dingDing, courseChange.delList, courseChange.school);
|
|
|
+ //foreach (var addStu in addStudents)
|
|
|
+ //{
|
|
|
+ // var course = new StuCourse
|
|
|
+ // {
|
|
|
+ // id = courseChange.id,
|
|
|
+ // scode = courseChange.code,
|
|
|
+ // name = courseChange.name,
|
|
|
+ // code = $"StuCourse-{courseChange.school}-{addStu.id}",
|
|
|
+ // scope = courseChange.scope,
|
|
|
+ // school = courseChange.school,
|
|
|
+ // creatorId = courseChange.creatorId,
|
|
|
+ // pk = "StuCourse"
|
|
|
+ // };
|
|
|
+ // await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(course, new PartitionKey(course.code));
|
|
|
+ //}
|
|
|
+ //foreach (var addTmd in addTmdids)
|
|
|
+ //{
|
|
|
+ // var course = new StuCourse
|
|
|
+ // {
|
|
|
+ // id = courseChange.id,
|
|
|
+ // scode = courseChange.code,
|
|
|
+ // name = courseChange.name,
|
|
|
+ // code = $"StuCourse-{addTmd}",
|
|
|
+ // scope = courseChange.scope,
|
|
|
+ // //school = courseChange.school,
|
|
|
+ // creatorId = courseChange.creatorId,
|
|
|
+ // pk = "StuCourse"
|
|
|
+ // };
|
|
|
+ // await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(course, new PartitionKey(course.code));
|
|
|
+ //}
|
|
|
+ //foreach (var delStu in delStudents)
|
|
|
+ //{
|
|
|
+ // await client.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync(courseChange.id, new PartitionKey($"Course-{courseChange.school}-{delStu.id}"));
|
|
|
+ //}
|
|
|
+ //foreach (var delTmd in delTmdids)
|
|
|
+ //{
|
|
|
+ // await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemStreamAsync(courseChange.id, new PartitionKey($"Course-{delTmd}"));
|
|
|
+ //}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|