123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using System.Net.Http;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK;
- using TEAMModelOS.Models;
- using Microsoft.Extensions.Options;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.Context.Constant;
- using System;
- using Microsoft.Azure.Cosmos;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models.Cosmos.BI.BICommon;
- using System.Collections.Generic;
- using System.Text;
- namespace TEAMModelBI.Controllers.BICommon
- {
- [Route("statsnotice")]
- [ApiController]
- public class StatsNoticeController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureStorageFactory _azureStorage;
- private readonly IConfiguration _configuration;
- private readonly AzureServiceBusFactory _serviceBus;
- private readonly IHttpClientFactory _http;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly IWebHostEnvironment _environment; //读取文件
- private readonly HttpClient _httpClient;
- public StatsNoticeController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, AzureServiceBusFactory serviceBus, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService, IWebHostEnvironment hostingEnvironment, HttpClient httpClient)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _azureStorage = azureStorage;
- _option = option?.Value;
- _configuration = configuration;
- _serviceBus = serviceBus;
- _http = http;
- _coreAPIHttpService = coreAPIHttpService;
- _environment = hostingEnvironment;
- _httpClient = httpClient;
- }
- /// <summary>
- /// 获取统计通知
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-infos")]
- public async Task<IActionResult> GetInfos(JsonElement jsonElement)
- {
- try
- {
- jsonElement.TryGetProperty("dateTime", out JsonElement dateTime);
- jsonElement.TryGetProperty("id", out JsonElement id);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- string dt = "";
- if (string.IsNullOrEmpty($"{dateTime}"))
- {
- dt = DateTimeOffset.UtcNow.ToString("yyyyMMdd");
- }
- else
- {
- dt = $"{dateTime}";
- }
- StringBuilder sqlTxt = new($"select value(c) from c where c.day='{dt}'");
- if (!string.IsNullOrEmpty($"{id}"))
- {
- sqlTxt.Append($" and c.rangeId = '{id}'");
- }
- List<StatsNotice> statsNotices = new();
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<StatsNotice>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("StatsNotice") }))
- {
- statsNotices.Add(item);
- }
- return Ok(new { state = RespondCode.Ok, statsNotices });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location},/statsnotice/get-infos \n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- }
- }
|