|
@@ -6,6 +6,7 @@ using Microsoft.Extensions.Options;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Text;
|
|
|
using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
|
using TEAMModelBI.Filter;
|
|
@@ -19,6 +20,7 @@ using TEAMModelOS.SDK.DI;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
+using Top.Api;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.BINormal
|
|
|
{
|
|
@@ -227,6 +229,8 @@ namespace TEAMModelBI.Controllers.BINormal
|
|
|
jsonElement.TryGetProperty("tmdPic", out JsonElement tmdPic);
|
|
|
if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
|
|
|
if (!jsonElement.TryGetProperty("areaName", out JsonElement areaName)) return BadRequest();
|
|
|
+ jsonElement.TryGetProperty("isSc", out JsonElement isSc);
|
|
|
+ jsonElement.TryGetProperty("scInfos", out JsonElement scInfos);
|
|
|
//jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
var tableClient = _azureStorage.GetCloudTableClient();
|
|
@@ -238,6 +242,10 @@ namespace TEAMModelBI.Controllers.BINormal
|
|
|
// blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
|
|
|
//}
|
|
|
|
|
|
+ SimpleInfo existsArea = null;
|
|
|
+ List<SimpleInfo> existsSc = new();
|
|
|
+ StringBuilder strMsg = new($"{_tmdName}【{_tmdId}】账户将{tmdName}【{tmdId}】");
|
|
|
+
|
|
|
Teacher teacher = null;
|
|
|
var response = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Base"));
|
|
|
if (response.Status == 200)
|
|
@@ -249,9 +257,10 @@ namespace TEAMModelBI.Controllers.BINormal
|
|
|
{
|
|
|
teacher.areas.Add(new Teacher.TeacherArea() { areaId = $"{areaId}", name = $"{areaName}", status = "join" });
|
|
|
teacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
|
|
|
+ strMsg.Append("设置为区管理员!");
|
|
|
}
|
|
|
else
|
|
|
- return Ok(new { state = RespondCode.Conflict, msg = "该账户已是管理员" });
|
|
|
+ existsArea = new() { id = $"{areaId}", name = $"{areaName}" };
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -264,10 +273,73 @@ namespace TEAMModelBI.Controllers.BINormal
|
|
|
teacher.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
//教师存在,在该教师信息中添加要管理的学校信息
|
|
|
teacher.areas.Add(new Teacher.TeacherArea { areaId = $"{areaId}", name = $"{areaName}", status = "join" });
|
|
|
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
+ teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
+ strMsg.Append("设置为区管理员!");
|
|
|
}
|
|
|
|
|
|
- return Ok(new { state = RespondCode.Ok, teacher });
|
|
|
+ if ($"{isSc}".Equals("yesm"))
|
|
|
+ {
|
|
|
+ List<SimpleInfo> schoolMs = scInfos.ToObject<List<SimpleInfo>>();
|
|
|
+ if (schoolMs.Count > 0)
|
|
|
+ {
|
|
|
+ strMsg.Append($"并将改账户设置为学校管理员;修改信息:");
|
|
|
+ foreach (var item in schoolMs)
|
|
|
+ {
|
|
|
+ SchoolTeacher schoolTeacher = null;
|
|
|
+ var resScTch = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Teacher-{item.id}"));
|
|
|
+ if (resScTch.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(resScTch.ContentStream);
|
|
|
+ schoolTeacher = json.ToObject<SchoolTeacher>();
|
|
|
+ if (!schoolTeacher.roles.Contains("admin"))
|
|
|
+ {
|
|
|
+ schoolTeacher.roles.Add("admin");
|
|
|
+ schoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{item.id}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ existsSc.Add(item);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ schoolTeacher = new()
|
|
|
+ {
|
|
|
+ id = $"{tmdId}",
|
|
|
+ code = $"Teacher-{item.id}",
|
|
|
+ roles = new List<string> { "admin", "teacher" },
|
|
|
+ job = "管理员",
|
|
|
+ name = $"{tmdName}",
|
|
|
+ picture = string.IsNullOrEmpty($"{item.picture}") ? "" : $"{item.picture}",
|
|
|
+ status = "join",
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ pk = "Teacher",
|
|
|
+ ttl = -1
|
|
|
+ };
|
|
|
+
|
|
|
+ schoolTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey($"Teacher-{item.id}"));
|
|
|
+ }
|
|
|
+
|
|
|
+ var existArea = teacher.schools.Find(f => f.schoolId.Equals($"{item.id}"));
|
|
|
+ if (existArea == null)
|
|
|
+ {
|
|
|
+ teacher.schools.Add(new Teacher.TeacherSchool { schoolId = $"{item.id}", name = $"{item.name}", status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = string.IsNullOrEmpty($"{item.picture}") ? "" : $"{item.picture}", areaId = $"{areaId}" });
|
|
|
+ }
|
|
|
+
|
|
|
+ strMsg.Append($"{item.name}【{item.id}】|");
|
|
|
+ }
|
|
|
+
|
|
|
+ teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ existsSc = schoolMs;
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存操作记录
|
|
|
+ await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-add", strMsg.ToString(), _dingDing, httpContext: HttpContext);
|
|
|
+
|
|
|
+ if (existsArea != null || existsSc.Count > 0 )
|
|
|
+ return Ok(new { state = RespondCode.Created, teacher, existsArea, existsSc });
|
|
|
+ else
|
|
|
+ return Ok(new { state = RespondCode.Ok, teacher });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|