123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- using System.Collections.Generic;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using Microsoft.Azure.Cosmos;
- namespace TEAMModelBI.Controllers.BICommon
- {
- [Route("jointly")]
- [ApiController]
- public class JointlyController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly AzureStorageFactory _azureStorage;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- public readonly List<string> _containers = new() { "Teacher", "School", "Student", "Normal", "Common" };
- public JointlyController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _azureStorage = azureStorage;
- _option = option?.Value;
- }
- /// <summary>
- /// 容器合一通过ID查询详情 //已对接
- /// </summary>
- /// <param name="jsonEmelent"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-info")]
- public async Task<IActionResult> GetInfo(JsonElement jsonEmelent)
- {
- if (!jsonEmelent.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!jsonEmelent.TryGetProperty("type", out JsonElement type)) return BadRequest();
- jsonEmelent.TryGetProperty("code", out JsonElement code);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- List<object> objs = new();
- List<int> types = type.ToObject<List<int>>();
- if (types.Count > 0)
- {
- foreach (var temp in types)
- {
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", _containers[temp]).GetItemQueryStreamIteratorSql(queryText: $"select value(c) from c where c.id='{id}'", requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.Content);
- 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>());
- }
- }
- }
- }
- }
- else
- {
- foreach (var contaoner in _containers)
- {
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", contaoner).GetItemQueryStreamIteratorSql(queryText: $"select value(c) from c where c.id='{id}'", requestOptions: string.IsNullOrEmpty($"{code}") ? new QueryRequestOptions() { } : new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.Content);
- 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, infos = objs });
- }
- }
- }
|