|
@@ -244,6 +244,7 @@ namespace TEAMModelBI.Controllers.BINormal
|
|
|
|
|
|
SimpleInfo existsArea = null;
|
|
|
List<SimpleInfo> existsSc = new();
|
|
|
+ List<SimpleInfo> errorSc = new();
|
|
|
StringBuilder strMsg = new($"{_tmdName}【{_tmdId}】账户将{tmdName}【{tmdId}】");
|
|
|
|
|
|
Teacher teacher = null;
|
|
@@ -285,46 +286,52 @@ namespace TEAMModelBI.Controllers.BINormal
|
|
|
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)
|
|
|
+ var resSc = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{item.id}", new PartitionKey($"Base"));
|
|
|
+ if (resSc.Status == 200)
|
|
|
{
|
|
|
- using var json = await JsonDocument.ParseAsync(resScTch.ContentStream);
|
|
|
- schoolTeacher = json.ToObject<SchoolTeacher>();
|
|
|
- if (!schoolTeacher.roles.Contains("admin"))
|
|
|
+ SchoolTeacher schoolTeacher = null;
|
|
|
+ var resScTch = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Teacher-{item.id}"));
|
|
|
+ if (resScTch.Status == 200)
|
|
|
{
|
|
|
- schoolTeacher.roles.Add("admin");
|
|
|
- schoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{item.id}"));
|
|
|
+ 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
|
|
|
- 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 = 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}"));
|
|
|
+ }
|
|
|
|
|
|
- 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}" });
|
|
|
+ }
|
|
|
|
|
|
- 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}】|");
|
|
|
}
|
|
|
-
|
|
|
- strMsg.Append($"{item.name}【{item.id}】|");
|
|
|
+ else
|
|
|
+ errorSc.Add(item);
|
|
|
}
|
|
|
|
|
|
teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
|
|
@@ -336,8 +343,8 @@ namespace TEAMModelBI.Controllers.BINormal
|
|
|
//保存操作记录
|
|
|
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 });
|
|
|
+ if (existsArea != null || existsSc.Count > 0 || errorSc.Count > 0)
|
|
|
+ return Ok(new { state = RespondCode.Created, teacher, existsArea, existsSc, errorSc });
|
|
|
else
|
|
|
return Ok(new { state = RespondCode.Ok, teacher });
|
|
|
}
|