|
@@ -45,6 +45,7 @@ using System.Net.Http.Json;
|
|
|
using System.Net;
|
|
|
using TEAMModelBI.Tool.CosmosBank;
|
|
|
using System.Diagnostics;
|
|
|
+using StackExchange.Redis;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.BITest
|
|
|
{
|
|
@@ -54,20 +55,22 @@ namespace TEAMModelBI.Controllers.BITest
|
|
|
{
|
|
|
|
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ private readonly AzureRedisFactory _azureRedis;
|
|
|
private readonly DingDing _dingDing;
|
|
|
private readonly Option _option;
|
|
|
- private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly IWebHostEnvironment _environment; //读取文件
|
|
|
//读取配置文件
|
|
|
private readonly IConfiguration _configuration;
|
|
|
private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
private readonly HttpClient _httpClient;
|
|
|
|
|
|
- public TestController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, HttpClient httpClient)
|
|
|
+ public TestController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, HttpClient httpClient)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
- _dingDing = dingDing;
|
|
|
_azureStorage = azureStorage;
|
|
|
+ _azureRedis = azureRedis;
|
|
|
+ _dingDing = dingDing;
|
|
|
_option = option?.Value;
|
|
|
_environment = hostingEnvironment;
|
|
|
_configuration = configuration;
|
|
@@ -1263,30 +1266,97 @@ namespace TEAMModelBI.Controllers.BITest
|
|
|
return Ok(new { state = 200, linqTests, set });
|
|
|
}
|
|
|
|
|
|
- [HttpPost("get-cosmosdb")]
|
|
|
+ /// <summary>
|
|
|
+ /// 多个连接字符串方式
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("get-manydb")]
|
|
|
public async Task<IActionResult> GetMany()
|
|
|
{
|
|
|
- var cosmos = _configuration.GetValue<string>("Azure:Cosmos:ConnectionString");
|
|
|
|
|
|
+ #region 依赖注入的方式
|
|
|
|
|
|
- var clientUrl = _configuration.GetValue<string>("Azure:CosmosUrl:ConnectionString");
|
|
|
- var clientKey = _configuration.GetValue<string>("Azure:CosmosKey:ConnectionString");
|
|
|
+ DateTimeOffset dateTime = DateTimeOffset.UtcNow;
|
|
|
+ var dateDay = dateTime.ToString("yyyyMMdd"); //获取当天的日期
|
|
|
+ Dictionary<long, int> allDays = new(); //所有在线人数
|
|
|
+ Dictionary<long, int> tchDays = new(); //教师在线人数
|
|
|
+ SortedSetEntry[] tchDay = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:teacher:{dateDay}");
|
|
|
+ if (tchDay.Length > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in tchDay)
|
|
|
+ {
|
|
|
+ int val = ((int)item.Score);
|
|
|
+ int key = ((int)item.Element);
|
|
|
+ var utcTo = new DateTimeOffset(new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, key, 0, 0)).Hour;
|
|
|
+ //var hour = int.Parse(DateTime.SpecifyKind(Convert.ToDateTime($"{dateTime.Year}/{dateTime.Month}/{ dateTime.Day} {key}:00:00"), DateTimeKind.Utc).ToLocalTime().ToString("HH"));
|
|
|
+ tchDays.Add(utcTo, val);
|
|
|
+ if (allDays.ContainsKey(utcTo))
|
|
|
+ allDays[utcTo] = (allDays[utcTo] + val);
|
|
|
+ else
|
|
|
+ allDays.Add(utcTo, val);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var redisGl = _azureRedis.GetRedisClient(dbnum: 0, name: "Global");
|
|
|
|
|
|
+ var temps= await _azureRedis.GetRedisClient(dbnum: 0, name: "Global").SortedSetIncrementAsync($"Login:IES:Test", $"1", 1);//一天24小时 小时为单位
|
|
|
|
|
|
- CosmosClient cosmosClient = new(clientUrl, clientKey);
|
|
|
- //var cosmosClient = _azureCosmos.GetCosmosClient(region:client,name: cosmos);
|
|
|
|
|
|
- var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync("hbcn", new PartitionKey("Base"));
|
|
|
- School school = new();
|
|
|
- if (response.Status == 200)
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
- school = json.ToObject<School>();
|
|
|
|
|
|
+ var cosmosDefaulat = _azureCosmos.GetCosmosClient(); //默认数据库
|
|
|
+ List<School> schools = new();
|
|
|
+ await foreach (var item in cosmosDefaulat.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<School>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ schools.Add(item);
|
|
|
+ }
|
|
|
+ var cosmosGlobal = _azureCosmos.GetCosmosClient(name: "Global"); //默认数据库
|
|
|
+ List<School> schoolGlobals = new();
|
|
|
+ await foreach (var item in cosmosGlobal.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<School>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ schoolGlobals.Add(item);
|
|
|
}
|
|
|
+ return Ok(new { state = 200, dcnt = schools.Count, schools, dgcnt = schoolGlobals.Count, schoolGlobals });
|
|
|
+
|
|
|
+
|
|
|
+ ////table多库连接
|
|
|
+ //var tableDefulat = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin"); //Table默认表
|
|
|
+ //List<DayLogin> hourLoginsDefualt = await tableDefulat.FindListByDict<DayLogin>(new Dictionary<string, object> { { "PartitionKey", $"DayLogin" } });
|
|
|
+
|
|
|
+ //var table = _azureStorage.GetCloudTableClient("Global").GetTableReference("IESLogin"); //Table国际站
|
|
|
+ //List<DayLogin> hourLogins= await table.FindListByDict<DayLogin>(new Dictionary<string, object> { { "PartitionKey", $"DayLogin" } });
|
|
|
+
|
|
|
+ //return Ok(new { state = 200, hourLogins, hourLoginsDefualt });
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 原始方式
|
|
|
+ //cosmosDB连接字符串
|
|
|
+ //var clientUrl = _configuration.GetValue<string>("Azure:CosmosUrl:ConnectionString");
|
|
|
+ //var clientKey = _configuration.GetValue<string>("Azure:CosmosKey:ConnectionString");
|
|
|
+ //CosmosClient cosmosClient = new(clientUrl, clientKey);
|
|
|
+ //var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync("hbcn", new PartitionKey("Base"));
|
|
|
+ //School school = new();
|
|
|
+ //if (response.Status == 200)
|
|
|
+ //{
|
|
|
+ // using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ // school = json.ToObject<School>();
|
|
|
+ //}
|
|
|
+
|
|
|
+ //Table连接字符串
|
|
|
+ //var tableUrl = _configuration.GetValue<string>("Azure:StorageUrl:ConnectionString");
|
|
|
+ //Uri url = new(tableUrl, UriKind.Absolute);
|
|
|
+ //var tableKey = _configuration.GetValue<string>("Azure:StorageKey:ConnectionString");
|
|
|
+ //StorageCredentials sta = new StorageCredentials("teammodeltest", tableKey);
|
|
|
+ //CloudTableClient cloudTableClient = new CloudTableClient(url, sta);
|
|
|
+ //var table1 = cloudTableClient.GetTableReference("IESLogin");
|
|
|
+ //var tableGlobal = _configuration.GetValue<string>("AzureGlobal");
|
|
|
+
|
|
|
+ //Dictionary<string, object> dic = new() { { "PartitionKey", $"HourLogin" } };
|
|
|
+ //List<HourLogin> hourLogin = await table1.FindListByDict<HourLogin>(dic);
|
|
|
|
|
|
+ //List<HourLogin> hourLogin1= await table.FindListByDict<HourLogin>(dic);
|
|
|
|
|
|
- return Ok(new { state = 200, school });
|
|
|
+ //var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
|
|
|
+ //return Ok(new { state = 200 });
|
|
|
+ #endregion
|
|
|
}
|
|
|
|
|
|
public class linqTest
|