|
@@ -310,51 +310,212 @@ namespace TEAMModelOS.SDK
|
|
|
//学生新加入名单的
|
|
|
foreach (Member member in groupChange.stujoin)
|
|
|
{
|
|
|
- var stucourse = new StuCourse
|
|
|
+ Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(course.id, new PartitionKey($"StuCourse-{member.code.Replace("Base-", "")}-{member.id}"));
|
|
|
+ if (response.Status == 200)
|
|
|
{
|
|
|
- id = course.id,
|
|
|
- scode = course.code,
|
|
|
- name = course.name,
|
|
|
- code = $"StuCourse-{member.code.Replace("Base-", "")}-{member.id}",
|
|
|
- scope = course.scope,
|
|
|
- school = course.school,
|
|
|
- creatorId = course.creatorId,
|
|
|
- pk = "StuCourse",
|
|
|
- stulist = new List<string> { groupChange.listid },
|
|
|
- createTime = nowtime
|
|
|
- };
|
|
|
- try { await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code)); } catch (Exception ) {
|
|
|
- continue;
|
|
|
+ StuCourse stuCourse = JsonDocument.Parse(response.Content).RootElement.Deserialize<StuCourse>();
|
|
|
+ stuCourse.name = course.name;
|
|
|
+ stuCourse.scode = course.code;
|
|
|
+ stuCourse.name = course.name;
|
|
|
+ stuCourse.scope = course.scope;
|
|
|
+ stuCourse.school = course.school;
|
|
|
+ stuCourse.creatorId = course.creatorId;
|
|
|
+ if (groupChange.type.Equals("class"))
|
|
|
+ {
|
|
|
+ if (stuCourse.classId.IsNotEmpty())
|
|
|
+ {
|
|
|
+ if (!stuCourse.classId.Contains(groupChange.listid))
|
|
|
+ {
|
|
|
+ stuCourse.classId.Add(groupChange.listid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ stuCourse.classId = new List<string> { groupChange.listid };
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (stuCourse.stulist.IsNotEmpty())
|
|
|
+ {
|
|
|
+ if (!stuCourse.stulist.Contains(groupChange.listid))
|
|
|
+ {
|
|
|
+ stuCourse.stulist.Add(groupChange.listid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ stuCourse.stulist = new List<string> { groupChange.listid };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(stuCourse, stuCourse.id, new PartitionKey(stuCourse.code));
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var stucourse = new StuCourse
|
|
|
+ {
|
|
|
+ id = course.id,
|
|
|
+ scode = course.code,
|
|
|
+ name = course.name,
|
|
|
+ code = $"StuCourse-{member.code.Replace("Base-", "")}-{member.id}",
|
|
|
+ scope = course.scope,
|
|
|
+ school = course.school,
|
|
|
+ creatorId = course.creatorId,
|
|
|
+ pk = "StuCourse",
|
|
|
+ createTime = nowtime
|
|
|
+ };
|
|
|
+ if (groupChange.type.Equals("class"))
|
|
|
+ {
|
|
|
+ stucourse.classId = new List<string> { groupChange.listid };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ stucourse.stulist = new List<string> { groupChange.listid };
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(stucourse, new PartitionKey(stucourse.code));
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//tmd新加入的
|
|
|
foreach (Member member in groupChange.tmdjoin)
|
|
|
{
|
|
|
- var stucourse = new StuCourse
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(course.id, new PartitionKey($"StuCourse-{member.id}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ StuCourse stuCourse = JsonDocument.Parse(response.Content).RootElement.Deserialize<StuCourse>();
|
|
|
+ stuCourse.name = course.name;
|
|
|
+ stuCourse.scode = course.code;
|
|
|
+ stuCourse.name = course.name;
|
|
|
+ stuCourse.scope = course.scope;
|
|
|
+ stuCourse.school = course.school;
|
|
|
+ stuCourse.creatorId = course.creatorId;
|
|
|
+ if (groupChange.type.Equals("class"))
|
|
|
+ {
|
|
|
+ if (stuCourse.classId.IsNotEmpty())
|
|
|
+ {
|
|
|
+ if (!stuCourse.classId.Contains(groupChange.listid))
|
|
|
+ {
|
|
|
+ stuCourse.classId.Add(groupChange.listid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ stuCourse.classId = new List<string> { groupChange.listid };
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (stuCourse.stulist.IsNotEmpty())
|
|
|
+ {
|
|
|
+ if (!stuCourse.stulist.Contains(groupChange.listid))
|
|
|
+ {
|
|
|
+ stuCourse.stulist.Add(groupChange.listid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ stuCourse.stulist = new List<string> { groupChange.listid };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(stuCourse, stuCourse.id, new PartitionKey(stuCourse.code));
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var stucourse = new StuCourse
|
|
|
+ {
|
|
|
+ id = course.id,
|
|
|
+ scode = course.code,
|
|
|
+ name = course.name,
|
|
|
+ code = $"StuCourse-{member.id}",
|
|
|
+ scope = course.scope,
|
|
|
+ school = course.school,
|
|
|
+ creatorId = course.creatorId,
|
|
|
+ pk = "StuCourse",
|
|
|
+ createTime = nowtime
|
|
|
+ };
|
|
|
+ if (groupChange.type.Equals("class"))
|
|
|
+ {
|
|
|
+ stucourse.classId = new List<string> { groupChange.listid };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ stucourse.stulist = new List<string> { groupChange.listid };
|
|
|
+ }
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(stucourse, new PartitionKey(stucourse.code));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
{
|
|
|
- id = course.id,
|
|
|
- scode = course.code,
|
|
|
- name = course.name,
|
|
|
- code = $"StuCourse-{member.id}",
|
|
|
- scope = course.scope,
|
|
|
- school = course.school,
|
|
|
- creatorId = course.creatorId,
|
|
|
- pk = "StuCourse",
|
|
|
- stulist = new List<string> { groupChange.listid },
|
|
|
- createTime = nowtime
|
|
|
- };
|
|
|
- try { await client.GetContainer(Constant.TEAMModelOS, "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code)); } catch (Exception ) { continue; }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
//移除名单的。 在点击相关的课程,再去二次校验是否存在,不存在则再去删除。
|
|
|
foreach (var delStu in groupChange.stuleave)
|
|
|
{
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"StuCourse-{delStu.code.Replace("Base-", "")}-{delStu.id}"));
|
|
|
+ try {
|
|
|
+ Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(course.id, new PartitionKey($"StuCourse-{delStu.code.Replace("Base-", "")}-{delStu.id}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ StuCourse stuCourse = JsonDocument.Parse(response.Content).RootElement.Deserialize<StuCourse>();
|
|
|
+ stuCourse.stulist.Remove(groupChange.listid);
|
|
|
+ stuCourse.classId.Remove(groupChange.listid);
|
|
|
+ if (stuCourse.stulist.IsNotEmpty() || stuCourse.classId.IsNotEmpty())
|
|
|
+ {
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(stuCourse, stuCourse.id, new PartitionKey(stuCourse.code));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"StuCourse-{delStu.code.Replace("Base-", "")}-{delStu.id}"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception) { continue; }
|
|
|
+
|
|
|
}
|
|
|
foreach (var delTmd in groupChange.tmdleave)
|
|
|
{
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"StuCourse-{delTmd}"));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(course.id, new PartitionKey($"StuCourse-{delTmd.id}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ StuCourse stuCourse = JsonDocument.Parse(response.Content).RootElement.Deserialize<StuCourse>();
|
|
|
+ stuCourse.stulist.Remove(groupChange.listid);
|
|
|
+ stuCourse.classId.Remove(groupChange.listid);
|
|
|
+ if (stuCourse.stulist.IsNotEmpty() || stuCourse.classId.IsNotEmpty())
|
|
|
+ {
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(stuCourse, stuCourse.id, new PartitionKey(stuCourse.code));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemStreamAsync(course.id, new PartitionKey($"StuCourse-{delTmd.id}"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
if (groupChange.status.Equals("delete")) {
|
|
|
foreach (var item in courses)
|