|
@@ -2873,6 +2873,19 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
{
|
|
|
teachers.Add(item);
|
|
|
}
|
|
|
+ string sqlTeacherEx = $"SELECT c.id, c.name as realName FROM c WHERE ARRAY_CONTAINS({teaIdListStr}, c.id, true)";
|
|
|
+ await foreach (PurchaseTeacher item in client.GetContainer("Core", "ID2").GetItemQueryIteratorSql<PurchaseTeacher>(queryText: sqlTeacherEx, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("base-ex") }))
|
|
|
+ {
|
|
|
+ PurchaseTeacher teacherExist = teachers.FirstOrDefault(t => t.id.Equals(item.id));
|
|
|
+ if(teacherExist == null)
|
|
|
+ {
|
|
|
+ teachers.Add(item);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ teacherExist.realName = item.realName;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return Ok(new { geo = purchaseSeatsList, school = purchaseSchoolSeatsDic, teacher = teachers });
|
|
|
}
|
|
@@ -2934,6 +2947,249 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
+ #region 業務負責人功能
|
|
|
+ /// <summary>
|
|
|
+ /// 依据学校ID查業務負責人信息 //已对接
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-scsales")]
|
|
|
+ public async Task<IActionResult> GetSchoolsales(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
|
|
|
+ //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ ////分开部署,就不需要,一站多用时,取消注释
|
|
|
+ //if ($"{site}".Equals(BIConst.Global))
|
|
|
+ // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
|
|
|
+
|
|
|
+ List<BaseInfo> scManages = new();
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIteratorSql<BaseInfo>(queryText: $"select c.id,c.name,c.picture from c where ARRAY_CONTAINS(c.roles,'sales',true) and c.code='Teacher-{scId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{scId}") }))
|
|
|
+ {
|
|
|
+ scManages.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, scManages });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 设置業務負責人
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "admin,rdc")]
|
|
|
+ [HttpPost("set-sales")]
|
|
|
+ public async Task<IActionResult> SetSchoolsales(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var (_tmdId, _tmdName, _, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
|
|
|
+
|
|
|
+ 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("scAreaId", out JsonElement scAreaId);
|
|
|
+ jsonElement.TryGetProperty("scPic", out JsonElement scpicture);
|
|
|
+ //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
|
|
|
+
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ var tableClient = _azureStorage.GetCloudTableClient();
|
|
|
+ var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
|
|
|
+
|
|
|
+ ////分开部署,就不需要,一站多用时,取消注释
|
|
|
+ //if ($"{site}".Equals(BIConst.Global))
|
|
|
+ //{
|
|
|
+ // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
|
|
|
+ // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
|
|
|
+ // 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.StatusCode == HttpStatusCode.OK)
|
|
|
+ {
|
|
|
+ using var tchJson = await JsonDocument.ParseAsync(resScInfo.Content);
|
|
|
+ School scInfo = tchJson.ToObject<School>();
|
|
|
+ areaId = scInfo.areaId;
|
|
|
+ }
|
|
|
+ else areaId = $"{scAreaId}";
|
|
|
+ }
|
|
|
+ else { areaId = $"{scAreaId}"; }
|
|
|
+
|
|
|
+ Teacher teacher = new();
|
|
|
+ SchoolTeacher schoolTeacher = new();
|
|
|
+ var resTeacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Base"));
|
|
|
+ if (resTeacher.StatusCode == HttpStatusCode.OK)
|
|
|
+ {
|
|
|
+ using var tchJson = await JsonDocument.ParseAsync(resTeacher.Content);
|
|
|
+ teacher = tchJson.ToObject<Teacher>();
|
|
|
+
|
|
|
+ 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 = areaId });
|
|
|
+ teacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
|
|
|
+ strMsg.Append($"账户基础信息添加学校,{schoolName}【{schoolId}】;");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ 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 = areaId });
|
|
|
+ teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
+ strMsg.Append($"添加基础信息,并添加学校,{schoolName}【{schoolId}】;");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (teacher != null)
|
|
|
+ {
|
|
|
+ var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Teacher-{schoolId}"));
|
|
|
+ if (response.StatusCode == HttpStatusCode.OK)
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(response.Content);
|
|
|
+ schoolTeacher = json.ToObject<SchoolTeacher>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!schoolTeacher.roles.Contains("sales"))
|
|
|
+ {
|
|
|
+ schoolTeacher.roles.Add("sales");
|
|
|
+ schoolTeacher.status = "join";
|
|
|
+ schoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{schoolId}"));
|
|
|
+
|
|
|
+ #region 同時更新teacher的school.status
|
|
|
+ var school = teacher.schools.Find(f => f.schoolId.Equals($"{schoolId}"));
|
|
|
+ school.status = "join";
|
|
|
+ await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
|
|
|
+ #endregion
|
|
|
+ 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", "teacher" },
|
|
|
+ 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", strMsg.ToString(), _dingDing, httpContext: HttpContext);
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, teacher, schoolTeacher });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"BI,{_option.Location} /schoolcheck/set-schoolme \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 移除業務負責人 //已对接
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "admin,rdc")]
|
|
|
+ [HttpPost("del-sales")]
|
|
|
+ public async Task<IActionResult> DelSchoolsales(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ var (_tmdId, _tmdName, _, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
|
|
|
+ if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("scIds", out JsonElement _scIds)) return BadRequest();
|
|
|
+ //bool rmvFromSc = (jsonElement.TryGetProperty("rmvFromSc", out JsonElement rmvFromScJobj)) ? rmvFromScJobj.GetBoolean() : false; //rmvFromSc Bool true:移除SchoolTeacher document false:只移除roles中"admin"身分
|
|
|
+ //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
|
|
|
+
|
|
|
+ List<string> scIds = _scIds.ToObject<List<string>>();
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ var tableClient = _azureStorage.GetCloudTableClient();
|
|
|
+ var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
|
|
|
+ ////分开部署,就不需要,一站多用时,取消注释
|
|
|
+ //if ($"{site}".Equals(BIConst.Global))
|
|
|
+ // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
|
|
|
+ List<string> existScId = new();
|
|
|
+ StringBuilder strMsg = new($"{_tmdName}【{_tmdId}】管理员账户将{tmdId}的账户移除業務負責人:");
|
|
|
+ //老師
|
|
|
+ //if (rmvFromSc) //從老師的學校列表移除該學校
|
|
|
+ //{
|
|
|
+ // var response = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{tmdId}", new PartitionKey("Base"));
|
|
|
+ // if (response.StatusCode == HttpStatusCode.OK)
|
|
|
+ // {
|
|
|
+ // using var json = await JsonDocument.ParseAsync(response.Content);
|
|
|
+ // Teacher teacher = json.ToObject<Teacher>();
|
|
|
+ // teacher.schools.RemoveAll(s => scIds.Contains(s.schoolId));
|
|
|
+ // await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //學校
|
|
|
+ SchoolTeacher scTeacher = null;
|
|
|
+ foreach (var scId in scIds)
|
|
|
+ {
|
|
|
+ var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Teacher-{scId}"));
|
|
|
+ if (response.StatusCode == HttpStatusCode.OK)
|
|
|
+ {
|
|
|
+ //if (rmvFromSc) //將該老師從學校的老師名單中移除
|
|
|
+ //{
|
|
|
+ // //將該老師從學校的老師名單中移除
|
|
|
+ // await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemAsync<SchoolTeacher>($"{tmdId}", new PartitionKey($"Teacher-{scId}"));
|
|
|
+ // strMsg.Append($"{scId},");
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ using var json = await JsonDocument.ParseAsync(response.Content);
|
|
|
+ scTeacher = json.ToObject<SchoolTeacher>();
|
|
|
+ if (scTeacher.roles.Contains("sales"))
|
|
|
+ {
|
|
|
+ scTeacher.roles.Remove("sales");
|
|
|
+ strMsg.Append($"{scId},");
|
|
|
+ scTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(scTeacher, scTeacher.id, new PartitionKey($"Teacher-{scId}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ existScId.Add(scId);
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ else
|
|
|
+ existScId.Add(scId);
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存操作记录
|
|
|
+ await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-updatee", strMsg.ToString(), _dingDing, httpContext: HttpContext);
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, existScId });
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 未加入区域的学校
|
|
|
/// </summary>
|
|
@@ -3006,6 +3262,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
{
|
|
|
public string id { get; set; }
|
|
|
public string name { get; set; }
|
|
|
+ public string realName { get; set; }
|
|
|
}
|
|
|
}
|
|
|
}
|