HomeStatisController.cs 60 KB

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