|
@@ -0,0 +1,106 @@
|
|
|
+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 TEAMModelOS.SDK.Context.Constant;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI.BICommon;
|
|
|
+using Azure.Cosmos;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using System.Collections.Generic;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
+using TEAMModelOS.SDK.Models.Service.BI;
|
|
|
+using System.Linq;
|
|
|
+
|
|
|
+namespace TEAMModelBI.Controllers.BICommon
|
|
|
+{
|
|
|
+ [Route("poduct")]
|
|
|
+ [ApiController]
|
|
|
+ public class BIProductUseRecordController : 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 BIProductUseRecordController(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-userecord")]
|
|
|
+ public async Task<IActionResult> GetUseRecord(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ jsonElement.TryGetProperty("year", out JsonElement _year);
|
|
|
+ int year = DateTimeOffset.UtcNow.Year;
|
|
|
+ if (!string.IsNullOrEmpty($"{_year}"))
|
|
|
+ {
|
|
|
+ year = _year.GetInt32();
|
|
|
+ }
|
|
|
+
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ ProductUseRecord productUseRecord = null;
|
|
|
+ UseRecord useRecord = new();
|
|
|
+ var resUseRecord = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync($"{year}", new PartitionKey("ProductUseRecord"));
|
|
|
+ if (resUseRecord.Status == 200)
|
|
|
+ {
|
|
|
+ using var fileJson = await JsonDocument.ParseAsync(resUseRecord.ContentStream);
|
|
|
+ productUseRecord = fileJson.ToObject<ProductUseRecord>();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (productUseRecord != null)
|
|
|
+ {
|
|
|
+ useRecord.hiTaHour = productUseRecord.hiTaHour;
|
|
|
+ useRecord.hiTeachHour = productUseRecord.hiTeachHour;
|
|
|
+ useRecord.hiTeachccHour = productUseRecord.hiTeachccHour;
|
|
|
+ useRecord.hiTaDay = BICommonWay.ManyDoubleMerge(new List<List<double>>() { productUseRecord.hiTaDay });
|
|
|
+ useRecord.hiTeachDay = BICommonWay.ManyDoubleMerge(new List<List<double>>() { productUseRecord.hiTeachccHour });
|
|
|
+ useRecord.hiTeachccDay = BICommonWay.ManyDoubleMerge(new List<List<double>>() { productUseRecord.hiTeachccDay });
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, useRecord });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 使用信息
|
|
|
+ /// </summary>
|
|
|
+ public record UseRecord
|
|
|
+ {
|
|
|
+ public List<double> hiTaHour { get; set; }
|
|
|
+ public List<double> hiTeachHour { get; set; }
|
|
|
+ public List<double> hiTeachccHour { get; set; }
|
|
|
+ public List<double> hiTaDay { get; set; }
|
|
|
+ public List<double> hiTeachDay { get; set; }
|
|
|
+ public List<double> hiTeachccDay { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|