HomeStatisController.cs 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using System.Text.Json;
  8. using TEAMModelOS.SDK.DI;
  9. using Azure.Cosmos;
  10. using Microsoft.Extensions.Options;
  11. using TEAMModelOS.SDK.Models;
  12. using TEAMModelOS.Models;
  13. using System.Text;
  14. using StackExchange.Redis;
  15. using TEAMModelOS.SDK.Extension;
  16. using TEAMModelBI.Tool;
  17. using TEAMModelOS.SDK.Context.BI;
  18. namespace TEAMModelBI.Controllers.BIHome
  19. {
  20. [Route("homestatis")]
  21. [ApiController]
  22. public class HomeStatisController : ControllerBase
  23. {
  24. private readonly AzureCosmosFactory _azureCosmos;
  25. private readonly AzureStorageFactory _azureStorage;
  26. private readonly DingDing _dingDing;
  27. private readonly Option _option;
  28. private readonly AzureRedisFactory _azureRedis;
  29. public HomeStatisController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option)
  30. {
  31. _azureCosmos = azureCosmos;
  32. _dingDing = dingDing;
  33. _option = option?.Value;
  34. _azureStorage = azureStorage;
  35. _azureRedis = azureRedis;
  36. }
  37. /// <summary>
  38. /// 获取全部教师数量、学生数量、已创校数量、全部学校总空间大小
  39. /// </summary>
  40. /// <param name="jsonElement"></param>
  41. /// <returns></returns>
  42. [ProducesDefaultResponseType]
  43. [HttpPost("get-allnumber")]
  44. public async Task<IActionResult> GetAllNumber(JsonElement jsonElement)
  45. {
  46. try
  47. {
  48. jsonElement.TryGetProperty("site", out JsonElement site);
  49. var client = _azureCosmos.GetCosmosClient();;
  50. if ($"{site}".Equals(BIConst.Global))
  51. client = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  52. //查询全部教师人数
  53. long teacherCount = await CommonFind.FindTotals(client, "select count(c.id) as totals from c where c.code='Base'", new List<string>() { "Teacher" });
  54. //查询全部教师人数
  55. long studentCount = await CommonFind.FindTotals(client, "select count(c.id) as totals from c where c.pk='Base'", new List<string>() { "Student" });
  56. //查询已创建多少学校
  57. long schoolCount = await CommonFind.FindTotals(client, "select count(c.id) as totals from c where c.code='Base'", new List<string>() { "School" });
  58. //空间
  59. long schoolSize = await CommonFind.FindTotals(client, "select sum(c.size) as totals from c where c.code='Base'", new List<string>() { "School" });
  60. return Ok(new { state = 200, teacherCount, studentCount, schoolCount, schoolSize });
  61. }
  62. catch (Exception ex)
  63. {
  64. await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-numberpeople \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  65. return BadRequest();
  66. }
  67. }
  68. /// <summary>
  69. /// 获取其它类型的统计:问卷调查、评量检测、投票活动
  70. /// </summary>
  71. /// <param name="jsonElement"></param>
  72. /// <returns></returns>
  73. [ProducesDefaultResponseType]
  74. [HttpPost("get-othertypes")]
  75. public async Task<IActionResult> GetOtherTypes(JsonElement jsonElement)
  76. {
  77. try
  78. {
  79. if (!jsonElement.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
  80. jsonElement.TryGetProperty("site", out JsonElement site);
  81. var cosmosClient = _azureCosmos.GetCosmosClient();
  82. if ($"{site}".Equals(BIConst.Global))
  83. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  84. int surveyJoinCount = 0; //调查参加数量
  85. int surveyDoneCount = 0; //调查完成数量
  86. int surveyAreaJoinCount = 0; //调查区域参加数量
  87. int surveyAreaDoneCount = 0; //调查区域完成数量
  88. int examJoinCount = 0; //评量检测参加数量
  89. int examDoneCount = 0; //评量检测完成数量
  90. int examAreaJoinCount = 0; //评量检测区域参加数量
  91. int examAreaDoneCount = 0; //评量检测区域完成数量
  92. int voteJoinCount = 0; //投票参加数量
  93. int voteDoneCount = 0; //投票完成数量
  94. int voteAreaJoinCount = 0; //投票区域参加数量
  95. int voteAreaDoneCount = 0; //投票区域完成数量
  96. //问卷调查
  97. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher")
  98. .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'Survey' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  99. {
  100. if (!string.IsNullOrEmpty(item.owner))
  101. {
  102. if (item.owner.Equals("school"))
  103. {
  104. surveyJoinCount += 1;
  105. if (item.taskStatus > 0)
  106. {
  107. surveyDoneCount += 1;
  108. }
  109. }
  110. else if (item.owner.Equals("area"))
  111. {
  112. surveyAreaJoinCount += 1;
  113. if (item.taskStatus > 0)
  114. {
  115. surveyAreaDoneCount += 1;
  116. }
  117. }
  118. }
  119. }
  120. //评量检测
  121. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher")
  122. .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'ExamLite' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  123. {
  124. if (!string.IsNullOrEmpty(item.owner))
  125. {
  126. if (item.owner.Equals("school"))
  127. {
  128. examJoinCount += 1;
  129. if (item.taskStatus > 0)
  130. {
  131. examDoneCount += 1;
  132. }
  133. }
  134. else if (item.owner.Equals("area"))
  135. {
  136. examAreaJoinCount += 1;
  137. if (item.taskStatus > 0)
  138. {
  139. examAreaDoneCount += 1;
  140. }
  141. }
  142. }
  143. }
  144. //投票活动
  145. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher")
  146. .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'Vote' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
  147. {
  148. if (!string.IsNullOrEmpty(item.owner))
  149. {
  150. if (item.owner.Equals("school"))
  151. {
  152. voteJoinCount += 1;
  153. if (item.taskStatus > 0)
  154. {
  155. voteDoneCount += 1;
  156. }
  157. }
  158. else if (item.owner.Equals("area"))
  159. {
  160. voteAreaJoinCount += 1;
  161. if (item.taskStatus > 0)
  162. {
  163. voteAreaDoneCount += 1;
  164. }
  165. }
  166. }
  167. }
  168. return Ok(new { state = 200, surveyJoinCount, surveyDoneCount, surveyAreaJoinCount, surveyAreaDoneCount, examJoinCount, examDoneCount, examAreaJoinCount, examAreaDoneCount, voteJoinCount, voteDoneCount, voteAreaJoinCount, voteAreaDoneCount });
  169. }
  170. catch (Exception ex)
  171. {
  172. await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-othertypes \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  173. return BadRequest();
  174. }
  175. }
  176. /// <summary>
  177. /// 查询所有区级信息统计数据
  178. /// </summary>
  179. /// <param name="jsonElement"></param>
  180. /// <returns></returns>
  181. [ProducesDefaultResponseType]
  182. [HttpPost("get-alldiststics")]
  183. public async Task<IActionResult> GetAllDistStics(JsonElement jsonElement)
  184. {
  185. try
  186. {
  187. jsonElement.TryGetProperty("site", out JsonElement site);
  188. var cosmosClient = _azureCosmos.GetCosmosClient();
  189. if ($"{site}".Equals(BIConst.Global))
  190. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  191. List<SticsCity> standards = new();
  192. StringBuilder stringBuder = new("select c.id,c.name,c.provName,c.cityName,c.standard from c");
  193. //查询省份区域
  194. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: stringBuder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
  195. {
  196. SticsCity sticsCity = new()
  197. {
  198. areaId = item.id,
  199. provName = item.provName,
  200. cityName = item.cityName,
  201. distName = item.name,
  202. standard = item.standard
  203. };
  204. standards.Add(sticsCity);
  205. }
  206. List<SticsDist> sticsDists = new();
  207. //查询所有下面的学校数量
  208. foreach (var itemStandrds in standards)
  209. {
  210. SticsDist sticsDist = new()
  211. {
  212. provName = itemStandrds.provName,
  213. cityName = itemStandrds.cityName,
  214. distName = itemStandrds.distName,
  215. standard = itemStandrds.standard,
  216. };
  217. //查询区级下的学校ID
  218. string sqlTxt = $"select c.id from c where c.areaId='{itemStandrds.areaId}' and c.standard='{itemStandrds.standard}'";
  219. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, sqlTxt, "Base");
  220. sticsDist.schoolCount = schoolIds.Count;
  221. int teacherCount = 0; //教师数量
  222. int studentCount = 0; //学生数量
  223. //查询学校下面的教师人数
  224. foreach (var itemSchool in schoolIds)
  225. {
  226. //查询全部教师人数
  227. string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
  228. teacherCount += await CommonFind.FindTotals(cosmosClient, sqlT, "Teacher","Base");
  229. //查询全部学生人数
  230. string sqlS = $"select count(c.id) as totals from c";
  231. teacherCount += await CommonFind.FindTotals(cosmosClient, sqlS, "Student", $"Base-{itemSchool}");
  232. }
  233. sticsDist.teacherCount = teacherCount;
  234. sticsDist.studentCount = studentCount;
  235. sticsDists.Add(sticsDist);
  236. }
  237. return Ok(new { state = 200, sticsDists });
  238. }
  239. catch (Exception ex)
  240. {
  241. await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-alldiststics \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  242. return BadRequest();
  243. }
  244. }
  245. /// <summary>
  246. /// 依据城市Code查询学校,教师数量,学生数量
  247. /// </summary>
  248. /// <param name="jsonElement"></param>
  249. /// <returns></returns>
  250. [ProducesDefaultResponseType]
  251. [HttpPost("get-citystics")]
  252. public async Task<IActionResult> GetCityStics(JsonElement jsonElement)
  253. {
  254. try
  255. {
  256. if(!jsonElement.TryGetProperty("cityCode", out JsonElement _cityCode)) return BadRequest();
  257. jsonElement.TryGetProperty("site", out JsonElement site);
  258. var cosmosClient = _azureCosmos.GetCosmosClient();
  259. if ($"{site}".Equals(BIConst.Global))
  260. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  261. List<string> areaStandard = new();
  262. //查询省份区域
  263. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: $"select c.name,c.cityName,c.standard from c where c.cityCode='{_cityCode}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
  264. {
  265. areaStandard.Add(item.standard);
  266. }
  267. int citySchoolCount = 0;
  268. int teachCount = 0;
  269. int stuCount = 0;
  270. foreach (var tempSatndard in areaStandard)
  271. {
  272. string sqlSchool = $"select c.id from c where c.standard='{tempSatndard}'";
  273. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, sqlSchool, "Base");
  274. citySchoolCount += schoolIds.Count;
  275. //查询学校下面的教师人数
  276. foreach (var itemSchool in schoolIds)
  277. {
  278. //查询全部教师人数
  279. string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
  280. teachCount += await CommonFind.FindTotals(cosmosClient, sqlT, "Teacher", "Base");
  281. //查询全部学生人数
  282. string sqlS = $"select count(c.id) as totals from c";
  283. stuCount += await CommonFind.FindTotals(cosmosClient, sqlS, "Student", $"Base-{itemSchool}");
  284. }
  285. }
  286. return Ok(new { state = 200, schoolCount = citySchoolCount, teacherCount = teachCount, tudentCount = stuCount });
  287. }
  288. catch (Exception ex)
  289. {
  290. await _dingDing.SendBotMsg($"BI, {_option.Location} /homestatis/get-citystics \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  291. return BadRequest();
  292. }
  293. }
  294. /// <summary>
  295. /// 统计所有省份下的数据
  296. /// </summary>
  297. /// <returns></returns>
  298. [ProducesDefaultResponseType]
  299. [HttpPost("get-provincestics")]
  300. public async Task<IActionResult> GetProvinceStics(JsonElement jsonElement)
  301. {
  302. try
  303. {
  304. jsonElement.TryGetProperty("site", out JsonElement site);
  305. var cosmosClient = _azureCosmos.GetCosmosClient();
  306. if ($"{site}".Equals(BIConst.Global))
  307. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  308. List<ProvinceStandard> standards = new();
  309. 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") }))
  310. {
  311. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  312. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  313. {
  314. var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
  315. while (accounts.MoveNext())
  316. {
  317. JsonElement account = accounts.Current;
  318. ProvinceStandard provinceStandard = new()
  319. {
  320. provCode = account.GetProperty("provCode").GetString(),
  321. provName = account.GetProperty("provName").GetString(),
  322. standard = account.GetProperty("standard").GetString()
  323. };
  324. standards.Add(provinceStandard);
  325. }
  326. }
  327. }
  328. List<ProvinceStics> provinceStics = new();
  329. foreach (var itemStandard in standards)
  330. {
  331. ProvinceStics tempProvinceStics = new();
  332. //ProvinceStics tempCode = new ProvinceStics();
  333. var tempCode = provinceStics.Find(x => x.provCode == itemStandard.provCode);
  334. if (tempCode != null)
  335. {
  336. string sqlSc = $"select c.id from c where c.standard='{itemStandard.standard}'";
  337. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, sqlSc, "Base");
  338. tempCode.schoolCount += schoolIds.Count;
  339. if (schoolIds.Count > 0)
  340. {
  341. foreach (var itemSchool in schoolIds)
  342. {
  343. //查询学校教师人数
  344. string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
  345. tempCode.teacherCount += await CommonFind.FindTotals(cosmosClient, sqlT, "Teacher", "Base");
  346. //查询学校学生人数
  347. string sqlStu = $"select count(c.id) as totals from c";
  348. tempCode.studentCount += await CommonFind.FindTotals(cosmosClient, sqlStu, "Student", $"Base-{itemSchool}");
  349. }
  350. }
  351. var tempModel = provinceStics.Where(x => x.provCode == tempCode.provCode).FirstOrDefault();
  352. if (tempModel != null)
  353. {
  354. tempModel.schoolCount = tempCode.schoolCount;
  355. tempModel.teacherCount = tempCode.teacherCount;
  356. tempModel.studentCount = tempCode.studentCount;
  357. tempModel.standardCount +=1;
  358. }
  359. }
  360. else
  361. {
  362. tempProvinceStics.provCode = itemStandard.provCode;
  363. tempProvinceStics.provName = itemStandard.provName;
  364. tempProvinceStics.standardCount += 1;
  365. string sqlSc = $"select c.id from c where c.standard='{itemStandard.standard}'";
  366. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, sqlSc, "Base");
  367. tempProvinceStics.schoolCount += schoolIds.Count;
  368. if (schoolIds.Count > 0)
  369. {
  370. foreach (var itemSchool in schoolIds)
  371. {
  372. //查询学校教师人数
  373. string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
  374. tempProvinceStics.teacherCount += await CommonFind.FindTotals(cosmosClient, sqlT, "Teacher", "Base");
  375. //查询学校学生人数
  376. string sqlStu = "select count(c.id) as totals from c";
  377. tempProvinceStics.studentCount += await CommonFind.FindTotals(cosmosClient, sqlStu, "Student", $"Base-{itemSchool}");
  378. }
  379. }
  380. provinceStics.Add(tempProvinceStics);
  381. }
  382. }
  383. return Ok(new { state = 200, provinceStics });
  384. }
  385. catch (Exception ex)
  386. {
  387. await _dingDing.SendBotMsg($"BI, {_option.Location} /homestatis/get-provincestics \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  388. return BadRequest();
  389. }
  390. }
  391. /// <summary>
  392. /// 查询所有市级下的学校数量
  393. /// </summary>
  394. /// <returns></returns>
  395. [ProducesDefaultResponseType]
  396. [HttpPost("get-cityschool")]
  397. public async Task<IActionResult> GetCitySchool(JsonElement jsonElement)
  398. {
  399. try
  400. {
  401. jsonElement.TryGetProperty("site", out JsonElement site);
  402. var cosmosClient = _azureCosmos.GetCosmosClient();
  403. if ($"{site}".Equals(BIConst.Global))
  404. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  405. List<CityStandard> standards = new();
  406. //查询省份区域
  407. 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") }))
  408. {
  409. CityStandard Citystics = new CityStandard
  410. {
  411. areaId = item.id,
  412. cityCode = item.cityCode,
  413. cityName = item.cityName,
  414. standard = item.standard
  415. };
  416. standards.Add(Citystics);
  417. }
  418. List<CitySchool> citySchools = new(); //返回数量
  419. foreach (var itemStandrd in standards)
  420. {
  421. CitySchool citySchool = new();
  422. var tempCode = citySchools.Find(x => x.cityCode == itemStandrd.cityCode);
  423. if (tempCode != null)
  424. {
  425. //string sqlTxt = $"select count(c.id) totals from c where c.standard='{itemStandrd.standard}'";
  426. string sqlTxt = $"select count(c.id) totals from c where c.areaId='{itemStandrd.areaId}' and c.standard='{itemStandrd.standard}'";
  427. tempCode.schoolCount += await CommonFind.FindTotals(cosmosClient, sqlTxt, "School", "Base");
  428. var tempModel = citySchools.Where(x => x.cityCode == tempCode.cityCode).FirstOrDefault();
  429. if (tempModel != null)
  430. {
  431. tempModel.schoolCount = tempCode.schoolCount;
  432. }
  433. }
  434. else
  435. {
  436. citySchool.cityCode = itemStandrd.cityCode;
  437. citySchool.cityName = itemStandrd.cityName;
  438. //string sqlTxt = $"select count(c.id) totals from c where c.standard='{itemStandrd.standard}'";
  439. string sqlTxt = $"select count(c.id) totals from c where c.areaId='{itemStandrd.areaId}' and c.standard='{itemStandrd.standard}'";
  440. citySchool.schoolCount += await CommonFind.FindTotals(cosmosClient, sqlTxt, "School", "Base");
  441. citySchools.Add(citySchool);
  442. }
  443. }
  444. return Ok(new { state = 200, citySchools });
  445. }
  446. catch (Exception ex)
  447. {
  448. await _dingDing.SendBotMsg($"BI, {_option.Location} /homestatis/get-cityschool \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  449. return BadRequest();
  450. }
  451. }
  452. /// <summary>
  453. /// 依据市级ID查询区域(区、县、郡)的学校、教师、学生数量
  454. /// </summary>
  455. /// <param name="jsonElement"></param>
  456. /// <returns></returns>
  457. [ProducesDefaultResponseType]
  458. [HttpPost("get-districtstics")]
  459. public async Task<IActionResult> GetDistrictStics(JsonElement jsonElement)
  460. {
  461. try
  462. {
  463. if (!jsonElement.TryGetProperty("cityCode", out JsonElement _cityCode)) return BadRequest();
  464. jsonElement.TryGetProperty("site", out JsonElement site);
  465. var cosmosClient = _azureCosmos.GetCosmosClient();
  466. if ($"{site}".Equals(BIConst.Global))
  467. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  468. List<DistrictStandard> districtStandards = new();
  469. //查询省份区域
  470. 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") }))
  471. {
  472. DistrictStandard districtStandard = new()
  473. {
  474. id = item.id,
  475. cityName = item.cityName,
  476. distName = item.name,
  477. standard = item.standard
  478. };
  479. districtStandards.Add(districtStandard);
  480. }
  481. List<DistrictStics> districtSticss = new(); //返回数据
  482. foreach (var itemStandrd in districtStandards)
  483. {
  484. DistrictStics districtStics = new()
  485. {
  486. cityName = itemStandrd.cityName,
  487. distName = itemStandrd.distName
  488. };
  489. //string sqlTxt = $"select c.id from c where c.standard='{itemStandrd.standard}'";
  490. string sqlTxt = $"select c.id from c where c.areaId='{itemStandrd.id}' and c.standard='{itemStandrd.standard}'";
  491. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient,sqlTxt, "Base");
  492. districtStics.schoolCount += schoolIds.Count;
  493. if (schoolIds.Count > 0)
  494. {
  495. foreach (var itemSchool in schoolIds)
  496. {
  497. //查询学校教师人数
  498. string sqlT = $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'";
  499. //string sqlT = $"select count(c.id) as totals from c where c.code='Teacher-{itemSchool}' and contains(c.roles,'teacher')";
  500. districtStics.teacherCount += await CommonFind.FindTotals(cosmosClient, sqlT, "Teacher", "Base");
  501. //查询学校学生人数
  502. string sqlS = $"select count(c.id) as totals from c ";
  503. districtStics.studentCount += await CommonFind.FindTotals(cosmosClient, sqlS, "Student", $"Base-{itemSchool}");
  504. }
  505. }
  506. districtSticss.Add(districtStics);
  507. }
  508. return Ok(new { state = 200, districtSticss });
  509. }
  510. catch (Exception ex)
  511. {
  512. await _dingDing.SendBotMsg($"BI, {_option.Location} /homestatis/get-districtstics \n {ex.Message}\n{ex.StackTrace} ", GroupNames.成都开发測試群組);
  513. return BadRequest();
  514. }
  515. }
  516. /// <summary>
  517. /// 查询市的学校数据,以及市级下的区中的学校,教师、学生数量
  518. /// </summary>
  519. /// <param name="jsonElement"></param>
  520. /// <returns></returns>
  521. [ProducesDefaultResponseType]
  522. [HttpPost("get-cityallstics")]
  523. public async Task<IActionResult> GetCityAllStics(JsonElement jsonElement)
  524. {
  525. try
  526. {
  527. jsonElement.TryGetProperty("site", out JsonElement site);
  528. var cosmosClient = _azureCosmos.GetCosmosClient();
  529. if ($"{site}".Equals(BIConst.Global))
  530. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  531. List<AllCityStics> tempAllCityStics = new();
  532. //查询省份区域
  533. 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") }))
  534. {
  535. AllCityStics Citystics = new()
  536. {
  537. id = item.id,
  538. cityCode = item.cityCode,
  539. cityName = item.cityName,
  540. distName = item.name,
  541. standard = item.standard
  542. };
  543. tempAllCityStics.Add(Citystics);
  544. }
  545. List<SticsCitys> sticsCitys = new();
  546. foreach(var itemStandrd in tempAllCityStics)
  547. {
  548. SticsCitys citySchool = new();
  549. var tempCode = sticsCitys.Find(x => (x.cityCode) == (itemStandrd.cityCode));
  550. if (tempCode != null)
  551. {
  552. //List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.standard='{itemStandrd.standard}'", "Base");
  553. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.areaId='{itemStandrd.id}' and c.standard='{itemStandrd.standard}'", "Base");
  554. tempCode.schoolCount += schoolIds.Count;
  555. var tempModel = sticsCitys.Where(x => x.cityCode == tempCode.cityCode).FirstOrDefault();
  556. if (tempModel != null)
  557. {
  558. tempModel.schoolCount = tempCode.schoolCount;
  559. }
  560. DistrictStics districtStics = new()
  561. {
  562. cityName = itemStandrd.cityName,
  563. distName = itemStandrd.distName,
  564. schoolCount = schoolIds.Count
  565. };
  566. if (schoolIds.Count > 0)
  567. {
  568. foreach (var itemSchool in schoolIds)
  569. {
  570. //查询学校教师人数
  571. districtStics.teacherCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'", "Teacher", "Base");
  572. //查询学校学生人数
  573. districtStics.studentCount += await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "Student", $"Base-{itemSchool}");
  574. }
  575. }
  576. var tempDistrict = sticsCitys.Where(x => x.cityCode == tempCode.cityCode).FirstOrDefault();
  577. if (tempDistrict != null)
  578. {
  579. tempDistrict.districtSticss.Add(districtStics);
  580. }
  581. }
  582. else
  583. {
  584. citySchool.cityCode = itemStandrd.cityCode;
  585. citySchool.cityName = itemStandrd.cityName;
  586. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.standard='{itemStandrd.standard}'","Base");
  587. citySchool.schoolCount += schoolIds.Count;
  588. List<DistrictStics> tempDistrictStics = new();
  589. if (schoolIds.Count > 0)
  590. {
  591. DistrictStics districtStics = new()
  592. {
  593. cityName = itemStandrd.cityName,
  594. distName = itemStandrd.distName,
  595. schoolCount = schoolIds.Count
  596. };
  597. foreach (var itemSchool in schoolIds)
  598. {
  599. //查询学校教师人数
  600. districtStics.teacherCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c join a1 in c.schools where a1.schoolId='{itemSchool}'", "Teacher", "Base");
  601. //查询学校学生人数
  602. districtStics.studentCount += await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c", "Student","Base");
  603. }
  604. tempDistrictStics.Add(districtStics);
  605. }
  606. citySchool.districtSticss = tempDistrictStics;
  607. sticsCitys.Add(citySchool);
  608. }
  609. }
  610. return Ok(new { state = 200, sticsCitys });
  611. }
  612. catch (Exception ex)
  613. {
  614. await _dingDing.SendBotMsg($"BI, {_option.Location} /homestatis/get-cityallstics \n {ex.Message}\n{ex.StackTrace} ", GroupNames.成都开发測試群組);
  615. return BadRequest();
  616. }
  617. }
  618. /// <summary>
  619. /// 查询BI权限开放人数
  620. /// </summary>
  621. /// <returns></returns>
  622. [ProducesDefaultResponseType]
  623. [HttpPost("get-sticsbipower")]
  624. public async Task<IActionResult> GetSticsBIPower(JsonElement jsonElement)
  625. {
  626. try
  627. {
  628. jsonElement.TryGetProperty("site", out JsonElement site);
  629. Dictionary<string, object> dic = new() { { "PartitionKey", "authority-bi" } };
  630. var cosmosClient = _azureCosmos.GetCosmosClient();
  631. var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
  632. if ($"{site}".Equals(BIConst.Global))
  633. {
  634. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  635. table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("SchoolSetting");
  636. }
  637. List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
  638. List<PowerStics> powerStics = new();
  639. foreach (var temp in authorityBIList)
  640. {
  641. PowerStics tempPowerStics = new();
  642. tempPowerStics.powerName = temp.Discription;
  643. //查询学校权限
  644. string sqlTxt = $"SELECT DISTINCT REPLACE(c.code, 'Teacher-', '') AS schoolId, c.id, c.name FROM c WHERE ARRAY_CONTAINS(c.permissions, '{temp.RowKey}', true) AND c.pk = 'Teacher' AND c.status = 'join'";
  645. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { }))
  646. {
  647. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  648. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  649. {
  650. tempPowerStics.powerCount += 1;
  651. }
  652. }
  653. powerStics.Add(tempPowerStics);
  654. }
  655. return Ok(new { state = 200, powerStics });
  656. }
  657. catch (Exception ex)
  658. {
  659. await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-sticsbipower \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  660. return BadRequest();
  661. }
  662. }
  663. /// <summary>
  664. /// 统计学校和教师空间类型
  665. /// </summary>
  666. /// <returns></returns>
  667. [HttpPost("get-datatypestics")]
  668. public async Task<IActionResult> GetDataTypeStics(JsonElement jsonElement)
  669. {
  670. try
  671. {
  672. jsonElement.TryGetProperty("site", out JsonElement site);
  673. long totalSize = 0; //总空间
  674. long useSize = 0; //已使用空间
  675. long teach = 0; //学校已经分配给所有教师的空间大小GB。
  676. Dictionary<string, long> typeStics = new(); //所有类型
  677. Dictionary<string, double?> typeStics1 = new(); //所有类型
  678. List<string> schoolId = new();
  679. var cosmosClient = _azureCosmos.GetCosmosClient();
  680. var redisClinet = _azureRedis.GetRedisClient(8);
  681. if ($"{site}".Equals(BIConst.Global))
  682. {
  683. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  684. redisClinet = _azureRedis.GetRedisClient(dbnum: 8, name: BIConst.Global);
  685. }
  686. //查询学校空间和学校Id
  687. totalSize = await CommonFind.FindTotals(cosmosClient, "select sum(c.size) as totals from c", "School", "Base");
  688. schoolId = await CommonFind.FindSchoolIds(cosmosClient, "select c.id,c.size from c", "Base");
  689. //查询学校已使用空间大小
  690. foreach (var itemId in schoolId)
  691. {
  692. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT sum(c.size) as size FROM c ",
  693. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{itemId}") }))
  694. {
  695. var json = await JsonDocument.ParseAsync(item.ContentStream);
  696. foreach (var elmt in json.RootElement.GetProperty("Documents").EnumerateArray())
  697. {
  698. if (elmt.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
  699. {
  700. teach += _size.GetInt32();
  701. break;
  702. }
  703. }
  704. }
  705. long blobsize = 0;
  706. RedisValue value = default;
  707. value = redisClinet.HashGet($"Blob:Record", itemId);
  708. if (value != default && !value.IsNullOrEmpty)
  709. {
  710. JsonElement record = value.ToString().ToObject<JsonElement>();
  711. if (record.TryGetInt64(out blobsize)){}
  712. }
  713. else
  714. {
  715. var client = _azureStorage.GetBlobContainerClient(itemId);
  716. if ($"{site}".Equals(BIConst.Global))
  717. {
  718. client = _azureStorage.GetBlobContainerClient(containerName: itemId, name: BIConst.Global);
  719. }
  720. var size = await client.GetBlobsCatalogSize();
  721. await redisClinet.HashSetAsync($"Blob:Record", itemId, size.Item1);
  722. foreach (var key in size.Item2.Keys)
  723. {
  724. await redisClinet.SortedSetRemoveAsync($"Blob:Catalog:{itemId}", key);
  725. await redisClinet.SortedSetIncrementAsync($"Blob:Catalog:{itemId}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
  726. }
  727. useSize += size.Item1.Value;
  728. typeStics1 = typeStics1.Concat(size.Item2).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
  729. //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);
  730. continue;
  731. }
  732. SortedSetEntry[] Scores = redisClinet.SortedSetRangeByScoreWithScores($"Blob:Catalog:{itemId}");
  733. if (Scores != null)
  734. {
  735. Dictionary<string, double?> schoolStics = new(); //学校空间
  736. foreach (var score in Scores)
  737. {
  738. double val = score.Score;
  739. string key = score.Element.ToString();
  740. schoolStics.Add(key, val);
  741. }
  742. useSize += blobsize;
  743. typeStics1 = typeStics1.Concat(schoolStics).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
  744. //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);
  745. continue;
  746. }
  747. else
  748. {
  749. var client = _azureStorage.GetBlobContainerClient(itemId);
  750. if ($"{site}".Equals(BIConst.Global))
  751. {
  752. client = _azureStorage.GetBlobContainerClient(containerName: itemId, name: BIConst.Global);
  753. }
  754. var size = await client.GetBlobsCatalogSize();
  755. await redisClinet.HashSetAsync($"Blob:Record", itemId, size.Item1);
  756. foreach (var key in size.Item2.Keys)
  757. {
  758. await redisClinet.SortedSetRemoveAsync($"Blob:Catalog:{itemId}", key);
  759. await redisClinet.SortedSetIncrementAsync($"Blob:Catalog:{itemId}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
  760. }
  761. useSize += size.Item1.Value;
  762. typeStics1 = typeStics1.Concat(size.Item2).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
  763. //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);
  764. continue;
  765. }
  766. ////RedisValue value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", itemId);
  767. //if (!value.IsNullOrEmpty)
  768. //{
  769. // useSize += Convert.ToInt64(value);
  770. // //JsonElement record = value.ToString().ToObject<JsonElement>();
  771. // //long tempSize = 0;
  772. // //if (record.TryGetInt64(out tempSize))
  773. // //{
  774. // // sizeS += tempSize;
  775. // //}
  776. //}
  777. //else
  778. //{
  779. // var client = _azureStorage.GetBlobContainerClient(itemId);
  780. // var size = await client.GetBlobsCatalogSize();
  781. // var temp = await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", itemId, size.Item1);
  782. // foreach (var itemKey in size.Item2.Keys)
  783. // {
  784. // var temp1 = await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{itemId}", itemKey);
  785. // var temp2 = await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{itemId}", itemKey, size.Item2[itemKey].HasValue ? size.Item2[itemKey].Value : 0);
  786. // useSize += Convert.ToInt64(temp2);
  787. // }
  788. //}
  789. //SortedSetEntry[] sortedSetEntries = await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{itemId}");
  790. //if (sortedSetEntries != null)
  791. //{
  792. // foreach (var tempSorted in sortedSetEntries)
  793. // {
  794. // if (typeStics.TryGetValue($"{tempSorted.Element}", out long val))
  795. // typeStics[$"{tempSorted.Element}"] = Convert.ToInt64(tempSorted.Score) != 0 ? val + Convert.ToInt64(tempSorted.Score) : 0;
  796. // else
  797. // typeStics.Add($"{tempSorted.Element}", Convert.ToInt64(tempSorted.Score));
  798. // }
  799. //}
  800. }
  801. ////教师数据
  802. //List<string> teacherId = new List<string>(); //教师Id集合
  803. ////查询教师的大小和教师集合信息
  804. //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") }))
  805. //{
  806. // using var json = await JsonDocument.ParseAsync(item.ContentStream);
  807. // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  808. // {
  809. // totalSize += obj.GetProperty("size").GetInt64();
  810. // teacherId.Add(obj.GetProperty("id").GetString());
  811. // }
  812. //}
  813. ////查询教师已使用空间大小
  814. //foreach (var itemTeach in teacherId)
  815. //{
  816. // Dictionary<string, double?> teachStics = new Dictionary<string, double?>(); //学校空间
  817. // long blobsize = 0;
  818. // RedisValue value = default;
  819. // value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", itemTeach);
  820. // if (value != default && !value.IsNullOrEmpty)
  821. // {
  822. // JsonElement record = value.ToString().ToObject<JsonElement>();
  823. // if (record.TryGetInt64(out blobsize))
  824. // {
  825. // }
  826. // }
  827. // else
  828. // {
  829. // var client = _azureStorage.GetBlobContainerClient(itemTeach);
  830. // var size = await client.GetBlobsCatalogSize();
  831. // await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", itemTeach, size.Item1);
  832. // foreach (var key in size.Item2.Keys)
  833. // {
  834. // await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{itemTeach}", key);
  835. // await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{itemTeach}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
  836. // }
  837. // useSize += (long)size.Item1;
  838. // teachStics = size.Item2;
  839. // 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);
  840. // continue;
  841. // }
  842. // SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{itemTeach}");
  843. // if (Scores != null)
  844. // {
  845. // foreach (var score in Scores)
  846. // {
  847. // double val = score.Score;
  848. // string key = score.Element.ToString();
  849. // teachStics.Add(key, val);
  850. // }
  851. // useSize += blobsize;
  852. // 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);
  853. // continue;
  854. // }
  855. // else
  856. // {
  857. // var client = _azureStorage.GetBlobContainerClient(itemTeach);
  858. // var size = await client.GetBlobsCatalogSize();
  859. // await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", itemTeach, size.Item1);
  860. // foreach (var key in size.Item2.Keys)
  861. // {
  862. // await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{itemTeach}", key);
  863. // await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{itemTeach}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
  864. // }
  865. // useSize += (long)size.Item1;
  866. // teachStics = size.Item2;
  867. // 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);
  868. // continue;
  869. // }
  870. // //RedisValue tempValue = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", itemTeach);
  871. // //if (!tempValue.IsNullOrEmpty)
  872. // //{
  873. // // useSize += Convert.ToInt64(tempValue);
  874. // // //JsonElement record = tempValue.ToString().ToObject<JsonElement>();
  875. // // //long tempSize = 0;
  876. // // //if (record.TryGetInt64(out tempSize))
  877. // // //{
  878. // // // sizeT += tempSize;
  879. // // //}
  880. // //}
  881. // //SortedSetEntry[] tempSorted = await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{itemTeach}");
  882. // //if (tempSorted != null)
  883. // //{
  884. // // foreach (var itemSorted in tempSorted)
  885. // // {
  886. // // if (typeStics.TryGetValue($"{itemSorted.Element}", out long val))
  887. // // typeStics[$"{itemSorted.Element}"] = Convert.ToInt64(itemSorted.Score) != 0 ? val + Convert.ToInt64(itemSorted.Score) : 0;
  888. // // else
  889. // // typeStics.Add($"{itemSorted.Element}", Convert.ToInt64(itemSorted.Score));
  890. // // }
  891. // //}
  892. //}
  893. return Ok(new { state = 200, totalSize, teach, useSize, stics = typeStics1.ToList() });
  894. }
  895. catch (Exception ex)
  896. {
  897. await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-datatypestics \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  898. return BadRequest();
  899. }
  900. }
  901. /// <summary>
  902. /// 统计教师的空间类型
  903. /// </summary>
  904. /// <returns></returns>
  905. [HttpPost("get-teachetypestics")]
  906. public async Task<IActionResult> GetTeachDataTypeStics(JsonElement jsonElement)
  907. {
  908. try
  909. {
  910. jsonElement.TryGetProperty("site", out JsonElement site);
  911. long teacheSize = 0; //教师空间
  912. long sizeT = 0; //教师空间
  913. List<string> teacherId = new(); //教师Id集合
  914. Dictionary<string, long> typeStics = new(); //所有类型
  915. var cosmosClient = _azureCosmos.GetCosmosClient();
  916. var redisClinet = _azureRedis.GetRedisClient(8);
  917. if ($"{site}".Equals(BIConst.Global))
  918. {
  919. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  920. redisClinet = _azureRedis.GetRedisClient(dbnum: 8, name: BIConst.Global);
  921. }
  922. //查询教师的大小和教师集合信息
  923. 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") }))
  924. {
  925. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  926. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  927. {
  928. teacheSize += obj.GetProperty("size").GetInt64();
  929. teacherId.Add(obj.GetProperty("id").GetString());
  930. }
  931. }
  932. //查询教师已使用空间大小
  933. foreach (var itemTeach in teacherId)
  934. {
  935. RedisValue tempValue = redisClinet.HashGet($"Blob:Record", itemTeach);
  936. if (!tempValue.IsNullOrEmpty)
  937. {
  938. sizeT += Convert.ToInt64(tempValue);
  939. //JsonElement record = tempValue.ToString().ToObject<JsonElement>();
  940. //long tempSize = 0;
  941. //if (record.TryGetInt64(out tempSize))
  942. //{
  943. // sizeT += tempSize;
  944. //}
  945. }
  946. SortedSetEntry[] tempSorted = await redisClinet.SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{itemTeach}");
  947. if (tempSorted != null)
  948. {
  949. foreach (var itemSorted in tempSorted)
  950. {
  951. if (typeStics.TryGetValue($"{itemSorted.Element}", out long val))
  952. typeStics[$"{itemSorted.Element}"] = Convert.ToInt64(itemSorted.Score) != 0 ? val + Convert.ToInt64(itemSorted.Score) : 0;
  953. else
  954. typeStics.Add($"{itemSorted.Element}", Convert.ToInt64(itemSorted.Score));
  955. }
  956. }
  957. }
  958. return Ok(new { state = 200, teacheSize, sizeT, typeStics });
  959. }
  960. catch (Exception ex)
  961. {
  962. await _dingDing.SendBotMsg($"BI,{_option.Location} /homestatis/get-datatypestics \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  963. return BadRequest();
  964. }
  965. }
  966. /// <summary>
  967. /// 存放的类型
  968. /// </summary>
  969. public record AllDataType
  970. {
  971. public long vote { get; set; }/// 投票josn
  972. public long thum { get; set; }//视频和封面缩略图
  973. public long avatar { get; set; }//学生头像
  974. public long test { get; set; }//
  975. public long survey { get; set; }//问卷调查 josn
  976. public long image { get; set; }// PNG
  977. public long other { get; set; }//其他
  978. public long doc { get; set; }//文档
  979. public long homework { get; set; }//作业 json
  980. public long item { get; set; }// 题库 json
  981. public long paper { get; set; }//试卷 json
  982. public long train { get; set; }// 研修
  983. public long res { get; set; }// 教程 htx
  984. public long exam { get; set; }//评测 json
  985. public long syllabus { get; set; }// 课纲 json
  986. public long video { get; set; }// 视频
  987. public long yxpt { get; set; }//研修平台
  988. public long jyzx { get; set; }// 教研中心
  989. public long records { get; set; } //HiTeach上传的数据
  990. }
  991. /// <summary>
  992. /// 省的数据标准
  993. /// </summary>
  994. public record ProvinceStics
  995. {
  996. /// <summary>
  997. /// 省份ID
  998. /// </summary>
  999. public string provCode { get; set; }
  1000. /// <summary>
  1001. /// 省份名称
  1002. /// </summary>
  1003. public string provName { get; set; }
  1004. /// <summary>
  1005. /// 省份下的方案数量
  1006. /// </summary>
  1007. public int standardCount { get; set; }
  1008. /// <summary>
  1009. /// 省份下的学校
  1010. /// </summary>
  1011. public int schoolCount { get; set; }
  1012. /// <summary>
  1013. /// 省份下的教师数量
  1014. /// </summary>
  1015. public int teacherCount { get; set; }
  1016. /// <summary>
  1017. /// 省份下的学生数量
  1018. /// </summary>
  1019. public int studentCount { get; set; }
  1020. }
  1021. /// <summary>
  1022. /// 省以下的区域标准
  1023. /// </summary>
  1024. public record ProvinceStandard
  1025. {
  1026. /// <summary>
  1027. /// 城市Code
  1028. /// </summary>
  1029. public string provCode { get; set; }
  1030. /// <summary>
  1031. /// 城市名称
  1032. /// </summary>
  1033. public string provName { get; set; }
  1034. /// <summary>
  1035. /// 区域标准
  1036. /// </summary>
  1037. public string standard { get; set; }
  1038. }
  1039. public record PowerStics
  1040. {
  1041. public string powerName { get; set; }
  1042. public int powerCount { get; set; }
  1043. }
  1044. /// <summary>
  1045. /// 市的学校数据,及以下数据
  1046. /// </summary>
  1047. public record SticsCitys
  1048. {
  1049. /// <summary>
  1050. /// 市级Code
  1051. /// </summary>
  1052. public string cityCode { get; set; }
  1053. /// <summary>
  1054. /// 市级名称
  1055. /// </summary>
  1056. public string cityName { get; set; }
  1057. /// <summary>
  1058. /// 学校数量
  1059. /// </summary>
  1060. public int schoolCount { get; set; }
  1061. /// <summary>
  1062. /// 市级下的区域,学校、
  1063. /// </summary>
  1064. public List<DistrictStics> districtSticss { get; set; }
  1065. }
  1066. /// <summary>
  1067. /// 所有区域标准
  1068. /// </summary>
  1069. public record AllCityStics
  1070. {
  1071. /// <summary>
  1072. /// 区域ID
  1073. /// </summary>
  1074. public string id { get; set; }
  1075. /// <summary>
  1076. /// 城市Code
  1077. /// </summary>
  1078. public string cityCode { get; set; }
  1079. /// <summary>
  1080. /// 城市名称
  1081. /// </summary>
  1082. public string cityName { get; set; }
  1083. /// <summary>
  1084. /// 区名称
  1085. /// </summary>
  1086. public string distName { get; set; }
  1087. /// <summary>
  1088. /// 区域标准
  1089. /// </summary>
  1090. public string standard { get; set; }
  1091. }
  1092. /// <summary>
  1093. /// 统计区域数量
  1094. /// </summary>
  1095. public record DistrictStics
  1096. {
  1097. /// <summary>
  1098. /// 市级名称
  1099. /// </summary>
  1100. public string cityName { get; set; }
  1101. /// <summary>
  1102. /// 地区名称
  1103. /// </summary>
  1104. public string distName { get; set; }
  1105. /// <summary>
  1106. /// 学校数量
  1107. /// </summary>
  1108. public int schoolCount { get; set; }
  1109. /// <summary>
  1110. /// 教师数量
  1111. /// </summary>
  1112. public int teacherCount { get; set; }
  1113. /// <summary>
  1114. /// 学生数量
  1115. /// </summary>
  1116. public int studentCount { get; set; }
  1117. }
  1118. /// <summary>
  1119. /// 区域标准
  1120. /// </summary>
  1121. public record DistrictStandard()
  1122. {
  1123. /// <summary>
  1124. /// 区域标准
  1125. /// </summary>
  1126. public string id { get; set; }
  1127. /// <summary>
  1128. /// 市名称
  1129. /// </summary>
  1130. public string cityName { get; set; }
  1131. /// <summary>
  1132. /// 区域名称
  1133. /// </summary>
  1134. public string distName { get; set; }
  1135. /// <summary>
  1136. /// 区域标准
  1137. /// </summary>
  1138. public string standard { get; set; }
  1139. }
  1140. /// <summary>
  1141. /// 市级学校数量
  1142. /// </summary>
  1143. public record CitySchool
  1144. {
  1145. /// <summary>
  1146. /// 市级ID
  1147. /// </summary>
  1148. public string cityCode { get; set; }
  1149. /// <summary>
  1150. /// 市级名称
  1151. /// </summary>
  1152. public string cityName { get; set; }
  1153. /// <summary>
  1154. /// 市级学校数量
  1155. /// </summary>
  1156. public int schoolCount { get; set;}
  1157. }
  1158. /// <summary>
  1159. /// 市级信息标准
  1160. /// </summary>
  1161. public record CityStandard
  1162. {
  1163. public string areaId { get; set; }
  1164. /// <summary>
  1165. /// 城市Code
  1166. /// </summary>
  1167. public string cityCode { get; set; }
  1168. /// <summary>
  1169. /// 城市名称
  1170. /// </summary>
  1171. public string cityName { get; set; }
  1172. /// <summary>
  1173. /// 区域标准
  1174. /// </summary>
  1175. public string standard { get; set; }
  1176. }
  1177. /// <summary>
  1178. /// 区域
  1179. /// </summary>
  1180. public record SticsCity
  1181. {
  1182. /// <summary>
  1183. /// 区域Id
  1184. /// </summary>
  1185. public string areaId { get; set; }
  1186. /// <summary>
  1187. /// 省份
  1188. /// </summary>
  1189. public string provName { get; set; }
  1190. /// <summary>
  1191. /// 市名称
  1192. /// </summary>
  1193. public string cityName { get; set; }
  1194. /// <summary>
  1195. /// 区域名称
  1196. /// </summary>
  1197. public string distName { get; set; }
  1198. /// <summary>
  1199. /// 区域标准
  1200. /// </summary>
  1201. public string standard { get; set; }
  1202. }
  1203. /// <summary>
  1204. /// 返回统计数据
  1205. /// </summary>
  1206. public record SticsDist
  1207. {
  1208. /// <summary>
  1209. /// 省份
  1210. /// </summary>
  1211. public string provName { get; set; }
  1212. /// <summary>
  1213. /// 市名
  1214. /// </summary>
  1215. public string cityName { get; set; }
  1216. /// <summary>
  1217. /// 区域标准名称
  1218. /// </summary>
  1219. public string distName { get; set; }
  1220. /// <summary>
  1221. /// 区域标准
  1222. /// </summary>
  1223. public string standard { get; set; }
  1224. /// <summary>
  1225. /// 学校数量
  1226. /// </summary>
  1227. public int schoolCount { get; set; }
  1228. /// <summary>
  1229. /// 教师人数
  1230. /// </summary>
  1231. public int teacherCount { get; set; }
  1232. /// <summary>
  1233. /// 学生人数
  1234. /// </summary>
  1235. public int studentCount { get; set; }
  1236. }
  1237. }
  1238. }