|
@@ -2257,24 +2257,43 @@ namespace TEAMModelOS.SDK
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ var stu = account.Deserialize<Student>();
|
|
|
+ if (stu.guardians.IsNotEmpty() && studentInfos[id].guardians!=null)
|
|
|
+ {
|
|
|
+ var mobiles = stu.guardians.Select(m => m.mobile);
|
|
|
+ var except = mobiles.Except(studentInfos[id].guardians.Select(x => x.mobile));
|
|
|
+ if (except.Any()) {
|
|
|
+ //清除移除的监护人
|
|
|
+ List<Guardian> guardians = new List<Guardian>();
|
|
|
+ string sql = $"select distinct value (c) from c where c.mobile in ({string.Join(",", except.Select(z => $"'{z}'"))} )";
|
|
|
+ await foreach (var guard in cosmosContainer.GetItemQueryIterator<Guardian>(queryText: sql,
|
|
|
+ requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base-Guardian") }))
|
|
|
+ {
|
|
|
+ guard.students.RemoveAll(s => s.id.Equals(id) && s.code.Equals(schoolId));
|
|
|
+ guardians.Add(guard);
|
|
|
+ }
|
|
|
+ guardians.ForEach(async x => {
|
|
|
+ if (x.students.IsNotEmpty())
|
|
|
+ {
|
|
|
+ try{await cosmosContainer.ReplaceItemAsync(x, x.id, new PartitionKey(x.code)); } catch {}
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ await cosmosContainer.DeleteItemStreamAsync(x.id, new PartitionKey(x.code));
|
|
|
+ }
|
|
|
+ catch{
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
if (studentInfos[id].guardians.IsNotEmpty())
|
|
|
{
|
|
|
- writer.WriteStartArray("guardians");
|
|
|
-
|
|
|
- foreach (var guardian in studentInfos[id].guardians)
|
|
|
+
|
|
|
+ foreach (var gtudentGuardian in studentInfos[id].guardians)
|
|
|
{
|
|
|
- writer.WriteStartObject();
|
|
|
- writer.WriteString("relation", guardian.relation);
|
|
|
- writer.WriteString("name", guardian.name);
|
|
|
- writer.WriteString("mobile", guardian.mobile);
|
|
|
- writer.WriteString("mail", guardian.mail);
|
|
|
- writer.WriteString("picture", guardian.picture);
|
|
|
- writer.WriteString("tmdid", guardian.tmdid);
|
|
|
- writer.WriteEndObject();
|
|
|
- }
|
|
|
- writer.WriteEndArray();
|
|
|
-
|
|
|
- foreach (var gtudentGuardian in studentInfos[id].guardians) {
|
|
|
List<Guardian> guardians = new List<Guardian>();
|
|
|
string sql = $"select distinct value (c) from c where c.mobile='{gtudentGuardian.mobile}' ";
|
|
|
await foreach (var guard in cosmosContainer.GetItemQueryIterator<Guardian>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base-Guardian") }))
|
|
@@ -2289,7 +2308,7 @@ namespace TEAMModelOS.SDK
|
|
|
{
|
|
|
x.students.Add(new GuardianStudent { type = 2, id = id, code = schoolId, name = studentInfos[id].name });
|
|
|
}
|
|
|
- await cosmosContainer.ReplaceItemAsync(x, x.id, new PartitionKey(x.code));
|
|
|
+ try { await cosmosContainer.ReplaceItemAsync(x, x.id, new PartitionKey(x.code)); } catch { }
|
|
|
});
|
|
|
}
|
|
|
else
|
|
@@ -2303,9 +2322,25 @@ namespace TEAMModelOS.SDK
|
|
|
name = gtudentGuardian.name,
|
|
|
students = new List<GuardianStudent> { new GuardianStudent { type = 2, id = id, code = schoolId, name = studentInfos[id].name } }
|
|
|
};
|
|
|
- await cosmosContainer.CreateItemAsync(guardian, new PartitionKey(guardian.code));
|
|
|
+ try { await cosmosContainer.CreateItemAsync(guardian, new PartitionKey(guardian.code)); } catch { }
|
|
|
}
|
|
|
}
|
|
|
+ writer.WriteStartArray("guardians");
|
|
|
+
|
|
|
+ foreach (var guardian in studentInfos[id].guardians)
|
|
|
+ {
|
|
|
+ writer.WriteStartObject();
|
|
|
+ writer.WriteString("relation", guardian.relation);
|
|
|
+ writer.WriteString("name", guardian.name);
|
|
|
+ writer.WriteString("mobile", guardian.mobile);
|
|
|
+ writer.WriteString("mail", guardian.mail);
|
|
|
+ writer.WriteString("picture", guardian.picture);
|
|
|
+ writer.WriteString("tmdid", guardian.tmdid);
|
|
|
+ writer.WriteEndObject();
|
|
|
+ }
|
|
|
+ writer.WriteEndArray();
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|