123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- using Azure.Cosmos;
- using System.Text.Json;
- using System.Threading.Tasks;
- using System.Collections.Generic;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Context.BI;
- namespace TEAMModelBI.Controllers.BITeacher
- {
- [Route("teacher")]
- [ApiController]
- public class TeacherController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly AzureStorageFactory _azureStorage;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- public TeacherController(AzureCosmosFactory azureCosmos,AzureStorageFactory azureStorage,DingDing dingDing, IOptionsSnapshot<Option> option)
- {
- _azureCosmos = azureCosmos;
- _azureStorage = azureStorage;
- _dingDing = dingDing;
- _option = option?.Value;
- }
- /// <summary>
- /// 查询学校教师列表
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-teachers")]
- public async Task<IActionResult> GetTeachers(JsonElement jsonElement)
- {
- jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
- jsonElement.TryGetProperty("schoolCode", out JsonElement schoolCode);
- jsonElement.TryGetProperty("site", out JsonElement site);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- if ($"{site}".Equals(BIConst.Global))
- cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
-
- List<SchoolTeacher> teachers = new();
- string sqlTxt = "";
- if (!string.IsNullOrEmpty($"{tmdId}"))
- {
- sqlTxt = $"select c.id,c.name,c.code,c.picture from c where c.id='{tmdId}'";
- }
- if (!string.IsNullOrEmpty($"{schoolCode}"))
- {
- sqlTxt = $"select c.id,c.name,c.code,c.picture from c join a1 in c.schools where a1.schoolId='{schoolCode}'";
- }
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- SchoolTeacher schoolTeacher = new();
- schoolTeacher.id = obj.GetProperty("id").GetString();
- schoolTeacher.code = obj.GetProperty("code").GetString();
- schoolTeacher.name = obj.GetProperty("name").GetString();
- schoolTeacher.picture = obj.GetProperty("picture").GetString();
- teachers.Add(schoolTeacher);
- }
- }
- }
- return Ok(new { state = 200, teachers });
- }
- /// <summary>
- /// 通过教师Id查询详情 数据管理工具——查询工具
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-info")]
- public async Task<IActionResult> GetInfo(JsonElement jsonElement)
- {
- if (!jsonElement.TryGetProperty("teacherId", out JsonElement teacherId)) return BadRequest();
- jsonElement.TryGetProperty("code", out JsonElement code);
- jsonElement.TryGetProperty("site", out JsonElement site);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- if ($"{site}".Equals(BIConst.Global))
- cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- List<object> objs = new();
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.id='{teacherId}'", requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- objs.Add(obj.ToObject<object>());
- }
- }
- }
- return Ok(new { state = 200, teachers = objs });
- }
- public record SchoolTeacher
- {
- public string id { get; set; }
- public string code { get; set; }
- public string picture { get; set; }
- public string name { get; set; }
- }
- }
- }
|