|
@@ -22,6 +22,7 @@ using TEAMModelBI.Tool.CosmosBank;
|
|
|
using TEAMModelBI.Tool.Extension;
|
|
|
using TEAMModelOS.Models;
|
|
|
using TEAMModelOS.SDK;
|
|
|
+using TEAMModelOS.SDK.Context.Constant;
|
|
|
using TEAMModelOS.SDK.DI;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
@@ -823,16 +824,21 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
/// </summary>
|
|
|
/// <param name="jsonElement"></param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpPost("set-schoolme")]
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "admin,rdc")]
|
|
|
+ [HttpPost("set-manage")]
|
|
|
public async Task<IActionResult> SetSchoolManage(JsonElement jsonElement)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var (_tmdId, _tmdName, _, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
|
|
|
|
|
|
- if (!jsonElement.TryGetProperty("manageId", out JsonElement _adminTmdId)) return BadRequest();
|
|
|
- if (!jsonElement.TryGetProperty("manageName", out JsonElement _adminTmdName)) return BadRequest();
|
|
|
- if (!jsonElement.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("tmdName", out JsonElement tmdName)) return BadRequest();
|
|
|
+ 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("scPic", out JsonElement scpicture);
|
|
|
jsonElement.TryGetProperty("site", out JsonElement site);
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
var tableClient = _azureStorage.GetCloudTableClient();
|
|
@@ -843,47 +849,79 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
|
|
|
blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
|
|
|
}
|
|
|
+ StringBuilder strMsg = new($"{_tmdName}【{_tmdId}】账户将{tmdName}【{tmdId}】");
|
|
|
|
|
|
- var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{_adminTmdId}", new PartitionKey($"Teacher-{_schoolId}"));
|
|
|
- if (response.Status == 200)
|
|
|
+ Teacher teacher = null;
|
|
|
+ SchoolTeacher schoolTeacher = null;
|
|
|
+ var resTeacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Base"));
|
|
|
+ if (resTeacher.Status == 200)
|
|
|
{
|
|
|
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- SchoolTeacher schoolTeacher = json.ToObject<SchoolTeacher>();
|
|
|
- if (!schoolTeacher.roles.Contains("admin"))
|
|
|
- {
|
|
|
- schoolTeacher.roles.Add("admin");
|
|
|
- SchoolTeacher st = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey(schoolTeacher.code));
|
|
|
+ using var tchJson = await JsonDocument.ParseAsync(resTeacher.ContentStream);
|
|
|
+ teacher = tchJson.ToObject<Teacher>();
|
|
|
|
|
|
- //保存操作记录
|
|
|
- //await _azureStorage.SaveBILog("schoolTeacher-update", $"{_tmdName}【{_tmdId}】账户把{_adminTmdName}【{_adminTmdId}】设置学校id为{_schoolId}管理员。", _dingDing, httpContext: HttpContext);
|
|
|
- await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-update", $"{_tmdName}【{_tmdId}】账户把{_adminTmdName}【{_adminTmdId}】设置学校id为{_schoolId}管理员。", _dingDing, httpContext: HttpContext);
|
|
|
- return Ok(new { state = 200, schoolTeacher = st });
|
|
|
+ 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 = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
|
|
|
+ strMsg.Append($"账户基础信息添加学校,");
|
|
|
}
|
|
|
- else
|
|
|
- return Ok(new { state = 201, schoolTeacher = "已经是管理人员" });
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SchoolTeacher schoolTeacher = new SchoolTeacher
|
|
|
- {
|
|
|
- id = $"{_adminTmdId}",
|
|
|
- code = $"Teacher-{_schoolId}",
|
|
|
- roles = new List<string> { "admin" },
|
|
|
- job = "管理员",
|
|
|
- name = $"{_adminTmdName}",
|
|
|
- picture = "",
|
|
|
- status = "join",
|
|
|
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
- pk = "Teacher",
|
|
|
- ttl = -1
|
|
|
- };
|
|
|
-
|
|
|
- schoolTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
- //保存操作记录
|
|
|
- //await _azureStorage.SaveBILog("schoolTeacher-add", $"{_tmdName}【{_tmdId}】账户创建{_adminTmdName}【{_adminTmdId}】账户,并设学校管理员。学校ID:{_schoolId}。", _dingDing, httpContext: HttpContext);
|
|
|
- await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-add", $"{_tmdName}【{_tmdId}】账户创建{_adminTmdName}【{_adminTmdId}】账户,并设学校管理员。学校ID:{_schoolId}。", _dingDing, httpContext: HttpContext);
|
|
|
- return Ok(new { status = 200, schoolTeacher });
|
|
|
+ teacher.id = $"{tmdId}";
|
|
|
+ teacher.name = $"{tmdName}";
|
|
|
+ teacher.picture = string.IsNullOrEmpty($"{picture}") ? "" : $"{picture}";
|
|
|
+ teacher.pk = "Base";
|
|
|
+ teacher.code = "Base";
|
|
|
+ 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 = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
+ strMsg.Append($"添加基础信息,并添加学校");
|
|
|
}
|
|
|
+
|
|
|
+ if (teacher != null)
|
|
|
+ {
|
|
|
+ var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Teacher-{schoolId}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(response.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-{schoolId}"));
|
|
|
+ strMsg.Append($"设置管理员,学校信息{schoolName}【{schoolId}】");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return Ok(new { state = RespondCode.Conflict, schoolTeacher = "已经是该校的管理人员" });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ schoolTeacher = new()
|
|
|
+ {
|
|
|
+ id = $"{tmdId}",
|
|
|
+ code = $"Teacher-{schoolId}",
|
|
|
+ roles = new List<string> { "admin" },
|
|
|
+ job = "管理员",
|
|
|
+ name = $"{tmdName}",
|
|
|
+ picture = string.IsNullOrEmpty($"{picture}") ? "" : $"{picture}",
|
|
|
+ status = "join",
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ pk = "Teacher",
|
|
|
+ ttl = -1
|
|
|
+ };
|
|
|
+
|
|
|
+ schoolTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey($"Teacher-{schoolId}"));
|
|
|
+ strMsg.Append($"新建学校管理员,学校信息{schoolName}【{schoolId}】");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //保存操作记录
|
|
|
+ await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-add", $"{_tmdName}【{_tmdId}】账户创建{tmdName}【{tmdName}】账户,并设学校管理员。学校ID:{schoolId}。", _dingDing, httpContext: HttpContext);
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, teacher, schoolTeacher });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|