|
@@ -213,6 +213,8 @@ namespace TEAMModelAPI.Controllers
|
|
|
}
|
|
|
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
+ //学校学科发生变化。
|
|
|
+ bool baseChange = false;
|
|
|
foreach (var item in teachers) {
|
|
|
var teacher = teachersList.Find(x => x.id.Equals(item.id));
|
|
|
var coreUser = coreUsers.Find(x => x.id.Equals(item.id));
|
|
@@ -248,37 +250,65 @@ namespace TEAMModelAPI.Controllers
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).CreateItemAsync(teacher, new PartitionKey("Base"));
|
|
|
}
|
|
|
var schoolTeacher = schoolTeachers.Find(x => x.id.Equals(item.id));
|
|
|
- if (schoolTeacher == null)
|
|
|
+ //处理导入的学科
|
|
|
+ List<string> subjectIds = new List<string>();
|
|
|
+ if (item.subjects.IsNotEmpty() && !string.IsNullOrWhiteSpace(item.periodId))
|
|
|
{
|
|
|
- List<string> subjectIds=new List<string>();
|
|
|
- if (item.subjects .IsNotEmpty() && !string.IsNullOrWhiteSpace(item.periodId)) {
|
|
|
- item.subjects.ForEach(s => {
|
|
|
- var subject= data.period.Find(x => x.id.Equals(item.periodId))?.subjects?.Find(x => x.name.Equals(s.name));
|
|
|
- if (subject == null)
|
|
|
+ item.subjects.ForEach(s => {
|
|
|
+ //同名学科
|
|
|
+ var subject = data.period.Find(x => x.id.Equals(item.periodId))?.subjects?.Find(x => x.id.Equals(s.id));
|
|
|
+ if (subject == null)
|
|
|
+ {
|
|
|
+ subject = data.period.Find(x => x.id.Equals(item.periodId))?.subjects?.Find(x => x.name.Equals(s.name));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ subjectIds.Add(subject.id);
|
|
|
+ }
|
|
|
+ if (subject == null)
|
|
|
+ {
|
|
|
+ var period = data.period.Find(x => x.id.Equals(item.periodId));
|
|
|
+ if (period != null)
|
|
|
{
|
|
|
- subject = data.period.Find(x => x.id.Equals(item.periodId))?.subjects?.Find(x => x.id.Equals(s.id));
|
|
|
+ period.subjects.Add(new Subject { id = s.id, name = s.name, type = 2 });
|
|
|
+ subjectIds.Add(s.id);
|
|
|
+ baseChange = true;
|
|
|
}
|
|
|
- else {
|
|
|
- subjectIds.Add(subject.id);
|
|
|
- }
|
|
|
- if (subject == null) {
|
|
|
- var period= data.period.Find(x => x.id.Equals(item.periodId));
|
|
|
- if (period != null) {
|
|
|
- period.subjects.Add(new Subject { id = s.id, name = s.name ,type=2});
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (schoolTeacher == null)
|
|
|
+ {
|
|
|
schoolTeacher = new SchoolTeacher
|
|
|
{
|
|
|
id = item.id,
|
|
|
- name=coreUser.name,
|
|
|
- picture=coreUser.picture,
|
|
|
- job=item.job,
|
|
|
-
|
|
|
+ name = coreUser.name,
|
|
|
+ picture = coreUser.picture,
|
|
|
+ job = item.job,
|
|
|
+ subjectIds = subjectIds,
|
|
|
+ roles = new List<string> { "teacher" },
|
|
|
+ permissions = new List<string> { "content-read", "exercise-read", "knowledge-read", "syllabus-read" },
|
|
|
+ status = "join",
|
|
|
+ code = $"Teacher-{school}",
|
|
|
+ pk = "Teacher",
|
|
|
+ createTime = now,
|
|
|
};
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
}
|
|
|
+ else {
|
|
|
+ if (subjectIds.IsNotEmpty()) {
|
|
|
+ subjectIds.ForEach(x => {
|
|
|
+ if (!schoolTeacher.subjectIds.Contains(x)) {
|
|
|
+ schoolTeacher.subjectIds.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ schoolTeacher.job = string.IsNullOrWhiteSpace(item.job) ? schoolTeacher.job : item.job;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(schoolTeacher,schoolTeacher.id, new PartitionKey(schoolTeacher.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (baseChange) {
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(data, data.id, new PartitionKey("Base"));
|
|
|
}
|
|
|
return Ok();
|
|
|
}
|