|
@@ -0,0 +1,156 @@
|
|
|
+using Azure.Cosmos;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IdentityModel.Tokens.Jwt;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using TEAMModelOS.Models.Dto;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.SDK;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.StringHelper;
|
|
|
+using System.Dynamic;
|
|
|
+using Azure;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+using Azure.Messaging.ServiceBus;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using TEAMModelOS.Filter;
|
|
|
+using Azure.Storage.Blobs.Models;
|
|
|
+using HTEXLib.COMM.Helpers;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
+using System.Net.Http;
|
|
|
+
|
|
|
+namespace TEAMModelAPI.Controllers
|
|
|
+{
|
|
|
+ [Route("school")]
|
|
|
+ [ApiController]
|
|
|
+ public class TeacherController : ControllerBase
|
|
|
+ {
|
|
|
+ private AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ public IConfiguration _configuration { get; set; }
|
|
|
+ private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
+ public TeacherController(CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration)
|
|
|
+ {
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _option = option?.Value;
|
|
|
+ _serviceBus = serviceBus;
|
|
|
+ _configuration = configuration;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _coreAPIHttpService = coreAPIHttpService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取学校教师列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpGet("get-teacher-list")]
|
|
|
+ [ApiToken(Auth = "1501", Name = "学校教师列表", RW = "R", Limit = false)]
|
|
|
+ public async Task<IActionResult> GetTeacherList(JsonElement json)
|
|
|
+ {
|
|
|
+
|
|
|
+ json.TryGetProperty("searchKey", out JsonElement _searchKey);
|
|
|
+ List<CoreUser> coreUsers = new List<CoreUser>();
|
|
|
+ IEnumerable<string> unexist = null ;
|
|
|
+ if (_searchKey.ValueKind.Equals(JsonValueKind.Array))
|
|
|
+ {
|
|
|
+ List<string> searchKey= _searchKey.ToObject<List<string>>();
|
|
|
+ var keys = searchKey.Where(x => !string.IsNullOrWhiteSpace(x));
|
|
|
+ var content = new StringContent(keys.ToJsonString(), Encoding.UTF8, "application/json");
|
|
|
+ string ujson = await _coreAPIHttpService.GetUserInfos(content);
|
|
|
+ if (!string.IsNullOrWhiteSpace(ujson))
|
|
|
+ {
|
|
|
+ coreUsers = ujson.ToObject<List<CoreUser>>();
|
|
|
+ }
|
|
|
+ if (coreUsers.Any())
|
|
|
+ {
|
|
|
+ unexist = searchKey.Except(coreUsers.Select(x => x.searchKey));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return Ok(new { error = 1, msg = "没有找到对应的教师信息!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
+ List<SchoolTeacher> teachers = new List<SchoolTeacher>();
|
|
|
+ string insql = "";
|
|
|
+ if (coreUsers.Any()) {
|
|
|
+ insql = $" and c.id in ({string.Join(",", coreUsers.Select(x => $"'{ x.id}'"))}) ";
|
|
|
+ }
|
|
|
+ string sql = $"select c.id,c.name ,c.picture,c.job ,c.subjectIds,c.roles from c where c.status='join' {insql}";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolTeacher>
|
|
|
+ (queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Teacher-{school}") }))
|
|
|
+ {
|
|
|
+ teachers.Add(item);
|
|
|
+ }
|
|
|
+ var teacherIds= coreUsers.Select(x => x.id).Except(teachers.Select(x => x.id));
|
|
|
+ List<CoreUser> unjoined = coreUsers.FindAll(x => teacherIds.Contains(x.id));
|
|
|
+
|
|
|
+ return Ok(new
|
|
|
+ {
|
|
|
+ teachers = teachers.Select(x => new {x.id,x.name,x.picture,x.job,x.subjectIds,x.roles }),
|
|
|
+ unjoined= unjoined.Select(x => new {x.id,x.name,x.picture,x.searchKey}),
|
|
|
+ unexist= unexist
|
|
|
+ });
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取学校教师信息
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-teacher-info")]
|
|
|
+ [ApiToken(Auth = "1502", Name = "学校教师信息", RW = "R", Limit = false)]
|
|
|
+ public async Task<IActionResult> GetTeacherInfo(JsonElement json)
|
|
|
+ {
|
|
|
+ json.TryGetProperty("tmdid", out JsonElement _tmdid);
|
|
|
+ var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
+ Azure.Response responseSchoolTch = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School")
|
|
|
+ .ReadItemStreamAsync($"{_tmdid}", new PartitionKey($"Teacher-{school}"));
|
|
|
+ Azure.Response responseTch = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher")
|
|
|
+ .ReadItemStreamAsync($"{_tmdid}", new PartitionKey($"Base"));
|
|
|
+ Teacher teacher = null;
|
|
|
+ if (responseTch.Status == 200)
|
|
|
+ {
|
|
|
+ teacher = JsonDocument.Parse(responseTch.Content).RootElement.Deserialize<Teacher>();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 3, msg = "账号未创建!" });
|
|
|
+ }
|
|
|
+ if (responseSchoolTch.Status == 200 && teacher != null)
|
|
|
+ {
|
|
|
+ SchoolTeacher schoolTeacher = JsonDocument.Parse(responseSchoolTch.Content).RootElement.Deserialize<SchoolTeacher>();
|
|
|
+ if (schoolTeacher.status.Equals("join"))
|
|
|
+ {
|
|
|
+ return Ok(new { teacher.id, teacher.name, teacher.picture, schoolTeacher.job, schoolTeacher.status, schoolTeacher.roles, schoolTeacher.subjectIds, school = teacher.schools?.Find(x => x.schoolId.Equals(school)) });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 2, msg = "教师未加入学校!" });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { error = 1, msg = "教师未就职该学校!" });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|