|
@@ -1305,9 +1305,19 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
List<string> tmdids = data.GetProperty("tmdids").ToObject<List<string>>();
|
|
|
- string areaId = data.GetProperty("areaId").GetString();
|
|
|
+ data.TryGetProperty("areaId",out JsonElement areaId);
|
|
|
+ data.TryGetProperty("schoolIds", out JsonElement schoolIds);
|
|
|
data.TryGetProperty("areaAdmin", out JsonElement areaAdmin);
|
|
|
- string sql = $"select value(c) from c where c.areaId='{areaId}'";
|
|
|
+ List<string> ids = new List<string>();
|
|
|
+ string idsSql = "";
|
|
|
+ if (schoolIds.ValueKind.Equals(JsonValueKind.Array)) {
|
|
|
+ ids = schoolIds.ToObject<List<string>>();
|
|
|
+ if (ids.IsNotEmpty()) {
|
|
|
+ idsSql = $" or c.id in ({string.Join(",", ids.Select(x=>$"'{x}'"))})";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string areaIdsql = string.IsNullOrWhiteSpace($"{areaId}")?"-0000000":$"{areaId}";
|
|
|
+ string sql = $"select distinct value(c) from c where c.areaId='{areaIdsql}' {idsSql}";
|
|
|
List<School> schools = new List<School>();
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<School>(
|
|
|
queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
|
|
@@ -1315,12 +1325,16 @@ namespace TEAMModelOS.Controllers
|
|
|
schools.Add(item);
|
|
|
}
|
|
|
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- Area area= await client.GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<Area>(areaId, new PartitionKey("Base-Area"));
|
|
|
+ Azure.Response responseArea= await client.GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemStreamAsync($"{areaId}", new PartitionKey("Base-Area"));
|
|
|
+ Area area = null;
|
|
|
+ if (responseArea.Status == 200) {
|
|
|
+ area = JsonDocument.Parse(responseArea.ContentStream).RootElement.ToObject<Area>();
|
|
|
+ }
|
|
|
List<Teacher> teachers = new List<Teacher>();
|
|
|
List<SchoolTeacher> schoolsTeachers = new List<SchoolTeacher>();
|
|
|
foreach (var tmdid in tmdids) {
|
|
|
Teacher teacher= await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>(tmdid, new PartitionKey("Base"));
|
|
|
- if (areaAdmin.ValueKind.Equals(JsonValueKind.True)) {
|
|
|
+ if (areaAdmin.ValueKind.Equals(JsonValueKind.True) && !string.IsNullOrWhiteSpace($"{areaId}") && area!= null) {
|
|
|
if (teacher.areas.IsNotEmpty())
|
|
|
{
|
|
|
if (!teacher.areas.Select(x => x.areaId).Contains(area.id)) {
|
|
@@ -1370,9 +1384,19 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
if (teacher.schools.IsNotEmpty())
|
|
|
{
|
|
|
- if (!teacher.schools.Select(x => x.schoolId).Contains(school .id))
|
|
|
+ if (!teacher.schools.Select(x => x.schoolId).Contains(school.id))
|
|
|
{
|
|
|
- teacher.schools.Add(new Teacher.TeacherSchool { schoolId = school.id, areaId = area.id, picture = school.picture, name = school.name, status = "join", time = now });
|
|
|
+ teacher.schools.Add(new Teacher.TeacherSchool { schoolId = school.id, areaId = school.areaId, picture = school.picture, name = school.name, status = "join", time = now });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var sch= teacher.schools.Find(x => x.schoolId.Equals(school.id));
|
|
|
+ if (sch != null) {
|
|
|
+ sch.time = now;
|
|
|
+ sch.name = school.name;
|
|
|
+ sch.areaId = school.areaId;
|
|
|
+ sch.picture = school.picture;
|
|
|
+ sch.status = "join";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
else
|