123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916 |
- 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 Azure.Cosmos;
- using Microsoft.Extensions.Options;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.Models;
- using System.Text;
- using StackExchange.Redis;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelBI.Tool;
- using TEAMModelOS.SDK.Context.BI;
- namespace TEAMModelBI.Controllers.BIHome
- {
- [Route("homestatis")]
- [ApiController]
- public class HomeStatisController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly AzureStorageFactory _azureStorage;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureRedisFactory _azureRedis;
- public HomeStatisController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _option = option?.Value;
- _azureStorage = azureStorage;
- _azureRedis = azureRedis;
- }
- /// <summary>
- /// 获取全部教师数量、学生数量、已创校数量、全部学校总空间大小 //已对接
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-allnumber")]
- public async Task<IActionResult> GetAllNumber(JsonElement jsonElement)
- {
- try
- {
- //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
- var client = _azureCosmos.GetCosmosClient();
- ////分开部署,就不需要,一站多用时,取消注释
- //if ($"{site}".Equals(BIConst.Global))
- // client = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- //查询全部教师人数
- long teacherCount = await CommonFind.GetSqlValueCount(client, "Teacher", "select value(count(c.id)) from c ", "Base");
- //查询全部学生人数
- long studentCount = await CommonFind.GetSqlValueCount(client, "Student", "select value(count(c.id)) from c", "Base");
- //查询已创建多少学校
- long schoolCount = await CommonFind.GetSqlValueCount(client, "School", "select value(count(c.id)) from c ", "Base");
- //空间
- long schoolSize = await CommonFind.GetSqlValueCount(client, "School", "select value(sum(c.size)) from c ", "Base");
- return Ok(new { state = 200, teacherCount, studentCount, schoolCount, schoolSize });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-numberpeople \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 统计所有省份下的数据 //已对接
- /// </summary>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-provincestics")]
- public async Task<IActionResult> GetProvinceStics(JsonElement jsonElement)
- {
- try
- {
- //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
- var cosmosClient = _azureCosmos.GetCosmosClient();
- //if ($"{site}".Equals(BIConst.Global))
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- List<ProvinceStandard> standards = new();
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryStreamIterator(queryText: $"select c.provCode,c.provName,c.standard from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
- {
- 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;
- ProvinceStandard provinceStandard = new()
- {
- provCode = account.GetProperty("provCode").GetString(),
- provName = account.GetProperty("provName").GetString(),
- standard = account.GetProperty("standard").GetString()
- };
- standards.Add(provinceStandard);
- }
- }
- }
- List<ProvinceStics> provinceStics = new();
- foreach (var itemStandard in standards)
- {
- ProvinceStics tempProvinceStics = new();
- //ProvinceStics tempCode = new ProvinceStics();
- var tempCode = provinceStics.Find(x => x.provCode == itemStandard.provCode);
- if (tempCode != null)
- {
- string sqlSc = $"select value(c.id) from c where c.standard='{itemStandard.standard}'";
- List<string> schoolIds = await CommonFind.FindScIds(cosmosClient, sqlSc, "Base");
- tempCode.schoolCount += schoolIds.Count;
- if (schoolIds.Count > 0)
- {
- foreach (var itemSchool in schoolIds)
- {
- //查询学校教师人数
- string sqlT = $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
- tempCode.teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", sqlT, "Base");
- //查询学校学生人数
- string sqlStu = $"select value(count(c.id)) from c";
- tempCode.studentCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", sqlStu, $"Base-{itemSchool}");
- }
- }
- var tempModel = provinceStics.Where(x => x.provCode == tempCode.provCode).FirstOrDefault();
- if (tempModel != null)
- {
- tempModel.schoolCount = tempCode.schoolCount;
- tempModel.teacherCount = tempCode.teacherCount;
- tempModel.studentCount = tempCode.studentCount;
- tempModel.standardCount +=1;
- }
- }
- else
- {
- tempProvinceStics.provCode = itemStandard.provCode;
- tempProvinceStics.provName = itemStandard.provName;
- tempProvinceStics.standardCount += 1;
- string sqlSc = $"select value(c.id) from c where c.standard='{itemStandard.standard}'";
- List<string> schoolIds = await CommonFind.FindScIds(cosmosClient, sqlSc, "Base");
- tempProvinceStics.schoolCount += schoolIds.Count;
-
- if (schoolIds.Count > 0)
- {
- foreach (var itemSchool in schoolIds)
- {
- //查询学校教师人数
- string sqlT = $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
- tempProvinceStics.teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", sqlT, "Base");
- //查询学校学生人数
- string sqlStu = "select value(count(c.id)) from c";
- tempProvinceStics.studentCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", sqlStu, $"Base-{itemSchool}");
- }
- }
- provinceStics.Add(tempProvinceStics);
- }
- }
- return Ok(new { state = 200, provinceStics });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI, {_option.Location} /homestatis/get-provincestics \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 查询所有市级下的学校数量 //已对接
- /// </summary>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-cityschool")]
- public async Task<IActionResult> GetCitySchool(JsonElement jsonElement)
- {
- try
- {
- //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
- var cosmosClient = _azureCosmos.GetCosmosClient();
- ////分开部署,就不需要,一站多用时,取消注释
- //if ($"{site}".Equals(BIConst.Global))
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- List<CityStandard> standards = new();
- //查询省份区域
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select c.id,c.cityCode,c.cityName,c.standard from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
- {
- CityStandard Citystics = new CityStandard
- {
- areaId = item.id,
- cityCode = item.cityCode,
- cityName = item.cityName,
- standard = item.standard
- };
- standards.Add(Citystics);
- }
- List<CitySchool> citySchools = new(); //返回数量
- foreach (var itemStandrd in standards)
- {
- CitySchool citySchool = new();
- var tempCode = citySchools.Find(x => x.cityCode == itemStandrd.cityCode);
- if (tempCode != null)
- {
- //string sqlTxt = $"select count(c.id) totals from c where c.standard='{itemStandrd.standard}'";
- string sqlTxt = $"select value(count(c.id)) from c where c.areaId='{itemStandrd.areaId}' and c.standard='{itemStandrd.standard}'";
- tempCode.schoolCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", sqlTxt, "Base");
- var tempModel = citySchools.Where(x => x.cityCode == tempCode.cityCode).FirstOrDefault();
- if (tempModel != null)
- {
- tempModel.schoolCount = tempCode.schoolCount;
- }
- }
- else
- {
- citySchool.cityCode = itemStandrd.cityCode;
- citySchool.cityName = itemStandrd.cityName;
- string sqlTxt = $"select value(count(c.id)) from c where c.areaId='{itemStandrd.areaId}' and c.standard='{itemStandrd.standard}'";
- citySchool.schoolCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", sqlTxt, "Base");
- citySchools.Add(citySchool);
- }
- }
- return Ok(new { state = 200, citySchools });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI, {_option.Location} /homestatis/get-cityschool \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
-
- /// <summary>
- /// 依据市级ID查询区域(区、县、郡)的学校、教师、学生数量 //已对接
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-districtstics")]
- public async Task<IActionResult> GetDistrictStics(JsonElement jsonElement)
- {
- try
- {
- if (!jsonElement.TryGetProperty("cityCode", out JsonElement _cityCode)) return BadRequest();
- //jsonElement.TryGetProperty("site", out JsonElement site);
- var cosmosClient = _azureCosmos.GetCosmosClient();
- ////分开部署,就不需要,一站多用时,取消注释
- //if ($"{site}".Equals(BIConst.Global))
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- List<DistrictStandard> districtStandards = new();
- //查询省份区域
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select c.id,c.name,c.cityName,c.standard from c where c.cityCode='{_cityCode}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
- {
- DistrictStandard districtStandard = new()
- {
- id = item.id,
- cityName = item.cityName,
- distName = item.name,
- standard = item.standard
- };
- districtStandards.Add(districtStandard);
- }
- List<DistrictStics> districtSticss = new(); //返回数据
- foreach (var itemStandrd in districtStandards)
- {
- DistrictStics districtStics = new()
- {
- cityName = itemStandrd.cityName,
- distName = itemStandrd.distName
- };
- //string sqlTxt = $"select c.id from c where c.standard='{itemStandrd.standard}'";
- string sqlTxt = $"select value(c.id) from c where c.areaId='{itemStandrd.id}' and c.standard='{itemStandrd.standard}'";
- List<string> schoolIds = await CommonFind.FindScIds(cosmosClient,sqlTxt, "Base");
- districtStics.schoolCount += schoolIds.Count;
- if (schoolIds.Count > 0)
- {
- foreach (var itemSchool in schoolIds)
- {
- //查询学校教师人数
- string sqlT = $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
- districtStics.teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", sqlT, "Base");
- //查询学校学生人数
- string sqlS = $"select value(count(c.id)) from c ";
- districtStics.studentCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", sqlS, $"Base-{itemSchool}");
- }
- }
- districtSticss.Add(districtStics);
- }
- return Ok(new { state = 200, districtSticss });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI, {_option.Location} /homestatis/get-districtstics \n {ex.Message}\n{ex.StackTrace} ", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 查询市的学校数据,以及市级下的区中的学校,教师、学生数量
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-cityallstics")]
- public async Task<IActionResult> GetCityAllStics(JsonElement jsonElement)
- {
- try
- {
- //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
- var cosmosClient = _azureCosmos.GetCosmosClient();
- ////分开部署,就不需要,一站多用时,取消注释
- //if ($"{site}".Equals(BIConst.Global))
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- List<AllCityStics> tempAllCityStics = new();
- //查询省份区域
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select c.id,c.name,c.cityCode,c.cityName,c.standard from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
- {
- AllCityStics Citystics = new()
- {
- id = item.id,
- cityCode = item.cityCode,
- cityName = item.cityName,
- distName = item.name,
- standard = item.standard
- };
- tempAllCityStics.Add(Citystics);
- }
- List<SticsCitys> sticsCitys = new();
- foreach(var itemStandrd in tempAllCityStics)
- {
- SticsCitys citySchool = new();
- var tempCode = sticsCitys.Find(x => (x.cityCode) == (itemStandrd.cityCode));
- if (tempCode != null)
- {
- //List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.standard='{itemStandrd.standard}'", "Base");
- List<string> schoolIds = await CommonFind.FindScIds(cosmosClient, $"select value(c.id) from c where c.areaId='{itemStandrd.id}' and c.standard='{itemStandrd.standard}'", "Base");
- tempCode.schoolCount += schoolIds.Count;
- var tempModel = sticsCitys.Where(x => x.cityCode == tempCode.cityCode).FirstOrDefault();
- if (tempModel != null)
- {
- tempModel.schoolCount = tempCode.schoolCount;
- }
- DistrictStics districtStics = new()
- {
- cityName = itemStandrd.cityName,
- distName = itemStandrd.distName,
- schoolCount = schoolIds.Count
- };
- if (schoolIds.Count > 0)
- {
- foreach (var itemSchool in schoolIds)
- {
- //查询学校教师人数
- districtStics.teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'", "Base");
- //查询学校学生人数
- districtStics.studentCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", "select value( count(c.id)) from c", $"Base-{itemSchool}");
- }
- }
- var tempDistrict = sticsCitys.Where(x => x.cityCode == tempCode.cityCode).FirstOrDefault();
- if (tempDistrict != null)
- {
- tempDistrict.districtSticss.Add(districtStics);
- }
- }
- else
- {
- citySchool.cityCode = itemStandrd.cityCode;
- citySchool.cityName = itemStandrd.cityName;
- List<string> schoolIds = await CommonFind.FindScIds(cosmosClient, $"select value(c.id) from c where c.standard='{itemStandrd.standard}'","Base");
- citySchool.schoolCount += schoolIds.Count;
- List<DistrictStics> tempDistrictStics = new();
- if (schoolIds.Count > 0)
- {
- DistrictStics districtStics = new()
- {
- cityName = itemStandrd.cityName,
- distName = itemStandrd.distName,
- schoolCount = schoolIds.Count
- };
- foreach (var itemSchool in schoolIds)
- {
- //查询学校教师人数
- districtStics.teacherCount += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", $"select value(count(c.id)) from c join a1 in c.schools where a1.schoolId='{itemSchool}'", "Base");
- //查询学校学生人数
- districtStics.studentCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", $"select value(count(c.id)) from c", "Base");
- }
- tempDistrictStics.Add(districtStics);
- }
- citySchool.districtSticss = tempDistrictStics;
- sticsCitys.Add(citySchool);
- }
- }
- return Ok(new { state = 200, sticsCitys });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI, {_option.Location} /homestatis/get-cityallstics \n {ex.Message}\n{ex.StackTrace} ", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 统计学校和教师空间类型 //已对接
- /// </summary>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-datatypestics")]
- public async Task<IActionResult> GetDataTypeStics(JsonElement jsonElement)
- {
- try
- {
- //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
- long totalSize = 0; //总空间
- long useSize = 0; //已使用空间
- long teach = 0; //学校已经分配给所有教师的空间大小GB。
- Dictionary<string, long> typeStics = new(); //所有类型
- Dictionary<string, double?> typeStics1 = new(); //所有类型
- List<string> schoolId = new();
- var cosmosClient = _azureCosmos.GetCosmosClient();
- var redisClinet = _azureRedis.GetRedisClient(8);
- ////分开部署,就不需要,一站多用时,取消注释
- //if ($"{site}".Equals(BIConst.Global))
- //{
- // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
- // redisClinet = _azureRedis.GetRedisClient(dbnum: 8, name: BIConst.Global);
- //}
- //查询学校空间和学校Id
- totalSize = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(sum(c.size)) from c", "Base");
- schoolId = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c", "Base");
- //查询学校已使用空间大小
- foreach (var itemId in schoolId)
- {
- await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT sum(c.size) as size FROM c ",
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{itemId}") }))
- {
- var json = await JsonDocument.ParseAsync(item.ContentStream);
- foreach (var elmt in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- if (elmt.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
- {
- teach += _size.GetInt32();
- break;
- }
- }
- }
- long blobsize = 0;
- RedisValue value = default;
- value = redisClinet.HashGet($"Blob:Record", itemId);
- if (value != default && !value.IsNullOrEmpty)
- {
- JsonElement record = value.ToString().ToObject<JsonElement>();
- if (record.TryGetInt64(out blobsize)){}
- }
- else
- {
- var client = _azureStorage.GetBlobContainerClient(itemId);
- ////分开部署,就不需要,一站多用时,取消注释
- //if ($"{site}".Equals(BIConst.Global))
- // client = _azureStorage.GetBlobContainerClient(containerName: itemId, name: BIConst.Global);
- var size = await client.GetBlobsCatalogSize();
- await redisClinet.HashSetAsync($"Blob:Record", itemId, size.Item1);
- foreach (var key in size.Item2.Keys)
- {
- await redisClinet.SortedSetRemoveAsync($"Blob:Catalog:{itemId}", key);
- await redisClinet.SortedSetIncrementAsync($"Blob:Catalog:{itemId}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
- }
- useSize += size.Item1.Value;
- typeStics1 = typeStics1.Concat(size.Item2).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
- //typeStics1 = (from e in typeStics1.Concat(schoolStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
- continue;
- }
- SortedSetEntry[] Scores = redisClinet.SortedSetRangeByScoreWithScores($"Blob:Catalog:{itemId}");
- if (Scores != null)
- {
- Dictionary<string, double?> schoolStics = new(); //学校空间
- foreach (var score in Scores)
- {
- double val = score.Score;
- string key = score.Element.ToString();
- schoolStics.Add(key, val);
- }
- useSize += blobsize;
- typeStics1 = typeStics1.Concat(schoolStics).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
- continue;
- }
- else
- {
- var client = _azureStorage.GetBlobContainerClient(itemId);
- ////分开部署,就不需要,一站多用时,取消注释
- //if ($"{site}".Equals(BIConst.Global))
- // client = _azureStorage.GetBlobContainerClient(containerName: itemId, name: BIConst.Global);
- var size = await client.GetBlobsCatalogSize();
- await redisClinet.HashSetAsync($"Blob:Record", itemId, size.Item1);
- foreach (var key in size.Item2.Keys)
- {
- await redisClinet.SortedSetRemoveAsync($"Blob:Catalog:{itemId}", key);
- await redisClinet.SortedSetIncrementAsync($"Blob:Catalog:{itemId}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
- }
- useSize += size.Item1.Value;
- typeStics1 = typeStics1.Concat(size.Item2).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
- //typeStics1 = (from e in typeStics1.Concat(schoolStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
- continue;
- }
- ////RedisValue value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", itemId);
- //if (!value.IsNullOrEmpty)
- //{
- // useSize += Convert.ToInt64(value);
- // //JsonElement record = value.ToString().ToObject<JsonElement>();
- // //long tempSize = 0;
- // //if (record.TryGetInt64(out tempSize))
- // //{
- // // sizeS += tempSize;
- // //}
- //}
- //else
- //{
- // var client = _azureStorage.GetBlobContainerClient(itemId);
- // var size = await client.GetBlobsCatalogSize();
- // var temp = await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", itemId, size.Item1);
- // foreach (var itemKey in size.Item2.Keys)
- // {
- // var temp1 = await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{itemId}", itemKey);
- // var temp2 = await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{itemId}", itemKey, size.Item2[itemKey].HasValue ? size.Item2[itemKey].Value : 0);
- // useSize += Convert.ToInt64(temp2);
- // }
- //}
- //SortedSetEntry[] sortedSetEntries = await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{itemId}");
- //if (sortedSetEntries != null)
- //{
- // foreach (var tempSorted in sortedSetEntries)
- // {
- // if (typeStics.TryGetValue($"{tempSorted.Element}", out long val))
- // typeStics[$"{tempSorted.Element}"] = Convert.ToInt64(tempSorted.Score) != 0 ? val + Convert.ToInt64(tempSorted.Score) : 0;
- // else
- // typeStics.Add($"{tempSorted.Element}", Convert.ToInt64(tempSorted.Score));
- // }
- //}
- }
-
- ////教师数据
- //List<string> teacherId = new List<string>(); //教师Id集合
- ////查询教师的大小和教师集合信息
- //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id,c.size from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- //{
- // using var json = await JsonDocument.ParseAsync(item.ContentStream);
- // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- // {
- // totalSize += obj.GetProperty("size").GetInt64();
- // teacherId.Add(obj.GetProperty("id").GetString());
- // }
- //}
- ////查询教师已使用空间大小
- //foreach (var itemTeach in teacherId)
- //{
- // Dictionary<string, double?> teachStics = new Dictionary<string, double?>(); //学校空间
- // long blobsize = 0;
- // RedisValue value = default;
- // value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", itemTeach);
- // if (value != default && !value.IsNullOrEmpty)
- // {
- // JsonElement record = value.ToString().ToObject<JsonElement>();
- // if (record.TryGetInt64(out blobsize))
- // {
- // }
- // }
- // else
- // {
- // var client = _azureStorage.GetBlobContainerClient(itemTeach);
- // var size = await client.GetBlobsCatalogSize();
- // await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", itemTeach, size.Item1);
- // foreach (var key in size.Item2.Keys)
- // {
- // await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{itemTeach}", key);
- // await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{itemTeach}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
- // }
- // useSize += (long)size.Item1;
- // teachStics = size.Item2;
- // typeStics1 = (from e in typeStics1.Concat(teachStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
- // continue;
- // }
- // SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{itemTeach}");
- // if (Scores != null)
- // {
- // foreach (var score in Scores)
- // {
- // double val = score.Score;
- // string key = score.Element.ToString();
- // teachStics.Add(key, val);
- // }
- // useSize += blobsize;
- // typeStics1 = (from e in typeStics1.Concat(teachStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
- // continue;
- // }
- // else
- // {
- // var client = _azureStorage.GetBlobContainerClient(itemTeach);
- // var size = await client.GetBlobsCatalogSize();
- // await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", itemTeach, size.Item1);
- // foreach (var key in size.Item2.Keys)
- // {
- // await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{itemTeach}", key);
- // await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{itemTeach}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
- // }
- // useSize += (long)size.Item1;
- // teachStics = size.Item2;
- // typeStics1 = (from e in typeStics1.Concat(teachStics) group e by e.Key into g select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.Count);
- // continue;
- // }
- // //RedisValue tempValue = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", itemTeach);
- // //if (!tempValue.IsNullOrEmpty)
- // //{
- // // useSize += Convert.ToInt64(tempValue);
- // // //JsonElement record = tempValue.ToString().ToObject<JsonElement>();
- // // //long tempSize = 0;
- // // //if (record.TryGetInt64(out tempSize))
- // // //{
- // // // sizeT += tempSize;
- // // //}
- // //}
- // //SortedSetEntry[] tempSorted = await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{itemTeach}");
- // //if (tempSorted != null)
- // //{
- // // foreach (var itemSorted in tempSorted)
- // // {
- // // if (typeStics.TryGetValue($"{itemSorted.Element}", out long val))
- // // typeStics[$"{itemSorted.Element}"] = Convert.ToInt64(itemSorted.Score) != 0 ? val + Convert.ToInt64(itemSorted.Score) : 0;
- // // else
- // // typeStics.Add($"{itemSorted.Element}", Convert.ToInt64(itemSorted.Score));
- // // }
- // //}
- //}
- return Ok(new { state = 200, totalSize, teach, useSize, stics = typeStics1.ToList() });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-datatypestics \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 省的数据标准
- /// </summary>
- public record ProvinceStics
- {
- /// <summary>
- /// 省份ID
- /// </summary>
- public string provCode { get; set; }
- /// <summary>
- /// 省份名称
- /// </summary>
- public string provName { get; set; }
- /// <summary>
- /// 省份下的方案数量
- /// </summary>
- public int standardCount { get; set; }
- /// <summary>
- /// 省份下的学校
- /// </summary>
- public int schoolCount { get; set; }
- /// <summary>
- /// 省份下的教师数量
- /// </summary>
- public int teacherCount { get; set; }
- /// <summary>
- /// 省份下的学生数量
- /// </summary>
- public int studentCount { get; set; }
- }
- /// <summary>
- /// 省以下的区域标准
- /// </summary>
- public record ProvinceStandard
- {
- /// <summary>
- /// 城市Code
- /// </summary>
- public string provCode { get; set; }
- /// <summary>
- /// 城市名称
- /// </summary>
- public string provName { get; set; }
- /// <summary>
- /// 区域标准
- /// </summary>
- public string standard { get; set; }
- }
- /// <summary>
- /// 市的学校数据,及以下数据
- /// </summary>
- public record SticsCitys
- {
- /// <summary>
- /// 市级Code
- /// </summary>
- public string cityCode { get; set; }
- /// <summary>
- /// 市级名称
- /// </summary>
- public string cityName { get; set; }
- /// <summary>
- /// 学校数量
- /// </summary>
- public int schoolCount { get; set; }
- /// <summary>
- /// 市级下的区域,学校、
- /// </summary>
- public List<DistrictStics> districtSticss { get; set; }
- }
- /// <summary>
- /// 所有区域标准
- /// </summary>
- public record AllCityStics
- {
- /// <summary>
- /// 区域ID
- /// </summary>
- public string id { get; set; }
- /// <summary>
- /// 城市Code
- /// </summary>
- public string cityCode { get; set; }
- /// <summary>
- /// 城市名称
- /// </summary>
- public string cityName { get; set; }
- /// <summary>
- /// 区名称
- /// </summary>
- public string distName { get; set; }
- /// <summary>
- /// 区域标准
- /// </summary>
- public string standard { get; set; }
- }
- /// <summary>
- /// 统计区域数量
- /// </summary>
- public record DistrictStics
- {
- /// <summary>
- /// 市级名称
- /// </summary>
- public string cityName { get; set; }
- /// <summary>
- /// 地区名称
- /// </summary>
- public string distName { get; set; }
- /// <summary>
- /// 学校数量
- /// </summary>
- public int schoolCount { get; set; }
- /// <summary>
- /// 教师数量
- /// </summary>
- public int teacherCount { get; set; }
- /// <summary>
- /// 学生数量
- /// </summary>
- public int studentCount { get; set; }
- }
- /// <summary>
- /// 区域标准
- /// </summary>
- public record DistrictStandard()
- {
- /// <summary>
- /// 区域标准
- /// </summary>
- public string id { get; set; }
- /// <summary>
- /// 市名称
- /// </summary>
- public string cityName { get; set; }
- /// <summary>
- /// 区域名称
- /// </summary>
- public string distName { get; set; }
- /// <summary>
- /// 区域标准
- /// </summary>
- public string standard { get; set; }
- }
- /// <summary>
- /// 市级学校数量
- /// </summary>
- public record CitySchool
- {
- /// <summary>
- /// 市级ID
- /// </summary>
- public string cityCode { get; set; }
- /// <summary>
- /// 市级名称
- /// </summary>
- public string cityName { get; set; }
- /// <summary>
- /// 市级学校数量
- /// </summary>
- public int schoolCount { get; set;}
- }
- /// <summary>
- /// 市级信息标准
- /// </summary>
- public record CityStandard
- {
- public string areaId { get; set; }
- /// <summary>
- /// 城市Code
- /// </summary>
- public string cityCode { get; set; }
- /// <summary>
- /// 城市名称
- /// </summary>
- public string cityName { get; set; }
- /// <summary>
- /// 区域标准
- /// </summary>
- public string standard { get; set; }
- }
- }
- }
|