HomeStatisController.cs 60 KB

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