HomeStatisController.cs 74 KB

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