1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Text.Json;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.Models;
- using Azure.Cosmos;
- using Microsoft.Extensions.Options;
- namespace TEAMModeBI.Controllers.BIHome
- {
- [Route("homestatis")]
- [ApiController]
- public class HomeStatisController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- public HomeStatisController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _option = option?.Value;
- }
- /// <summary>
- /// 获取人数
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("numberpeople")]
- public async Task<IActionResult> NumberPeople(JsonElement jsonElement)
- {
- if (!jsonElement.TryGetProperty("schooolId", out JsonElement schoolId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- //依据学校查询教师人数
- List<string> teacherCount_list = new();
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c join S1 in c.schools where S1.schoolId='{schoolId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- teacherCount_list.Add(account.GetProperty("id").GetString());
- }
- }
- }
- //
- List<string> studentCount_List = new();
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- studentCount_List.Add(account.GetProperty("id").GetString());
- }
- }
- }
- return Ok(new { SchoolTeacherCount = teacherCount_list.Count });
- }
- }
- }
|