HomeStatisController.cs 63 KB

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