浏览代码

处理设置学校id

Li 2 年之前
父节点
当前提交
f5a69cec69
共有 1 个文件被更改,包括 16 次插入2 次删除
  1. 16 2
      TEAMModelBI/Controllers/BISchool/SchoolController.cs

+ 16 - 2
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -670,6 +670,7 @@ namespace TEAMModelBI.Controllers.BISchool
                 jsonElement.TryGetProperty("tmdPic", out JsonElement picture);
                 if (!jsonElement.TryGetProperty("scId", out JsonElement schoolId)) return BadRequest();
                 if (!jsonElement.TryGetProperty("scName", out JsonElement schoolName)) return BadRequest();
+                jsonElement.TryGetProperty("scAreaId", out JsonElement scAreaId);
                 jsonElement.TryGetProperty("scPic", out JsonElement scpicture);
                 //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
                 var cosmosClient = _azureCosmos.GetCosmosClient();
@@ -683,6 +684,19 @@ namespace TEAMModelBI.Controllers.BISchool
                 //    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
                 //}
                 StringBuilder strMsg = new($"{_tmdName}【{_tmdId}】账户将{tmdName}【{tmdId}】");
+                string areaId = null;
+                if (string.IsNullOrEmpty($"{scAreaId}"))
+                {
+                    var resScInfo = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{schoolId}", new PartitionKey("Base"));
+
+                    if (resScInfo.Status == 200)
+                    {
+                        using var tchJson = await JsonDocument.ParseAsync(resScInfo.ContentStream);
+                        School scInfo = tchJson.ToObject<School>();
+                        areaId = scInfo.areaId;
+                    }else areaId = $"{scAreaId}";
+                }
+                else { areaId = $"{scAreaId}"; }
 
                 Teacher teacher = null;
                 SchoolTeacher schoolTeacher = null;
@@ -695,7 +709,7 @@ namespace TEAMModelBI.Controllers.BISchool
                     var existArea = teacher.schools.Find(f => f.schoolId.Equals($"{schoolId}"));
                     if (existArea == null)
                     {
-                        teacher.schools.Add(new Teacher.TeacherSchool { schoolId = $"{schoolId}", name = $"{schoolName}", status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = string.IsNullOrEmpty($"{scpicture}") ? "" : $"{scpicture}", areaId = "" });
+                        teacher.schools.Add(new Teacher.TeacherSchool { schoolId = $"{schoolId}", name = $"{schoolName}", status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = string.IsNullOrEmpty($"{scpicture}") ? "" : $"{scpicture}", areaId = areaId });
                         teacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
                         strMsg.Append($"账户基础信息添加学校,");
                     }
@@ -710,7 +724,7 @@ namespace TEAMModelBI.Controllers.BISchool
                     teacher.size = 1;
                     teacher.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                     //教师存在,在该教师信息中添加要管理的学校信息
-                    teacher.schools.Add(new Teacher.TeacherSchool { schoolId = $"{schoolId}", name = $"{schoolName}", status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = string.IsNullOrEmpty($"{scpicture}") ? "" : $"{scpicture}", areaId = "" });
+                    teacher.schools.Add(new Teacher.TeacherSchool { schoolId = $"{schoolId}", name = $"{schoolName}", status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = string.IsNullOrEmpty($"{scpicture}") ? "" : $"{scpicture}", areaId = areaId });
                     teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
                     strMsg.Append($"添加基础信息,并添加学校");
                 }