ActivitySticsController.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. using Azure.Cosmos;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.Extensions.Options;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using TEAMModelOS.Models;
  10. using TEAMModelOS.SDK.DI;
  11. using TEAMModelOS.SDK.Models;
  12. using System.Text.Json;
  13. using TEAMModelBI.Tool;
  14. using System.Text;
  15. using TEAMModelOS.SDK.Extension;
  16. using TEAMModelBI.Models;
  17. using TEAMModelOS.SDK;
  18. namespace TEAMModelBI.Controllers.Census
  19. {
  20. [Route("activity")]
  21. [ApiController]
  22. public class ActivitySticsController : 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 CoreAPIHttpService _coreAPIHttpService;
  29. public readonly List<string> types = new List<string> { "Exam", "Survey", "Vote", "Homework" };
  30. public ActivitySticsController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, CoreAPIHttpService coreAPIHttpService)
  31. {
  32. _azureCosmos = azureCosmos;
  33. _dingDing = dingDing;
  34. _azureStorage = azureStorage;
  35. _option = option?.Value;
  36. _coreAPIHttpService = coreAPIHttpService;
  37. }
  38. /// <summary>
  39. /// 统计活动 传醍摩豆则查询相关的学校活动
  40. /// </summary>
  41. /// <param name="jsonElement"></param>
  42. /// <returns></returns>
  43. [ProducesDefaultResponseType]
  44. [HttpPost("get-count")]
  45. public async Task<IActionResult> GetCount(JsonElement jsonElement)
  46. {
  47. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  48. if(!jsonElement.TryGetProperty("term", out JsonElement term)) return BadRequest();
  49. long start = 0, end = 0;
  50. if (bool.Parse($"{term}") == true)
  51. {
  52. (start, end) = TimeHelper.GetTermStartOrEnd(DateTime.Now);
  53. }
  54. var cosmosClient = _azureCosmos.GetCosmosClient();
  55. List<object> activityCount = new List<object>();
  56. if (!string.IsNullOrEmpty($"{tmdId}"))
  57. {
  58. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  59. foreach (var itemId in schoolIds)
  60. {
  61. School school = new();
  62. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("Base"));
  63. if (response.Status == 200)
  64. {
  65. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  66. school = json.ToObject<School>();
  67. }
  68. ActivityCount tempCount = new ActivityCount() { id = itemId, name = school.name != null ? school.name : itemId };
  69. foreach (var type in types)
  70. {
  71. StringBuilder sqlTxt = new StringBuilder($"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.school='{itemId}' ");
  72. if (bool.Parse($"{term}") == true)
  73. {
  74. sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
  75. }
  76. long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "Common" });
  77. tempCount.census.Add(new KeyValuePair<object, long>(type, totals));
  78. }
  79. activityCount.Add(tempCount);
  80. }
  81. }
  82. else
  83. {
  84. foreach (var type in types)
  85. {
  86. StringBuilder sqlTxt = new StringBuilder($"SELECT COUNT(c.id) AS totals FROM c where c.pk='{type}' ");
  87. if (bool.Parse($"{term}") == true)
  88. {
  89. sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
  90. }
  91. long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "Common" });
  92. activityCount.Add(new KeyValuePair<string, object>(type, totals));
  93. }
  94. }
  95. return Ok(new { state = 200, activityCount });
  96. }
  97. /// <summary>
  98. /// 统计所有的评量活动,问卷调查,投票活动,作业
  99. /// </summary>
  100. /// <returns></returns>
  101. [HttpPost("get-allactivity")]
  102. public async Task<IActionResult> GetAllActivity()
  103. {
  104. try
  105. {
  106. var cosmosClient = _azureCosmos.GetCosmosClient();
  107. List<KeyValuePair<string, long>> typeCount = new List<KeyValuePair<string, long>>();
  108. foreach (var type in types)
  109. {
  110. string querySql = $"SELECT Count(c.id) as totals FROM c where c.pk='{type}' ";
  111. long totals = await CommonFind.FindTotals(cosmosClient, querySql, new List<string>() { "Common" });
  112. KeyValuePair<string, long> valuePair = new KeyValuePair<string, long>(type, totals);
  113. typeCount.Add(valuePair);
  114. }
  115. return Ok(new { state = 200, typeCount });
  116. }
  117. catch (Exception ex)
  118. {
  119. await _dingDing.SendBotMsg($"BI,{_option.Location} /activity/get-allactivity \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
  120. return BadRequest();
  121. }
  122. }
  123. /// <summary>
  124. /// 统计顾问关联的学校活动数量:评测、问卷、投票、作业
  125. /// </summary>
  126. /// <param name="jsonElement"></param>
  127. /// <returns></returns>
  128. [ProducesDefaultResponseType]
  129. [HttpPost("get-assistactivity")]
  130. public async Task<IActionResult> GetAssistSchoolActivity(JsonElement jsonElement)
  131. {
  132. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  133. var cosmosClient = _azureCosmos.GetCosmosClient();
  134. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  135. List<ActivityCount> activityCounts = new List<ActivityCount>();
  136. foreach (var itemId in schoolIds)
  137. {
  138. School school = new();
  139. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("Base"));
  140. if (response.Status == 200)
  141. {
  142. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  143. school = json.ToObject<School>();
  144. }
  145. ActivityCount activityCount = new ActivityCount() { id = itemId, name = school.name != null ? school.name : itemId };
  146. foreach (var type in types)
  147. {
  148. string activitySql = $"SELECT Count(c.id) as totals FROM c WHERE c.pk='{type}' AND c.school='{itemId}'";
  149. long totals = await CommonFind.FindTotals(cosmosClient, activitySql, new List<string>() { "Common" });
  150. activityCount.census.Add(new KeyValuePair<object, long>(type, totals));
  151. }
  152. activityCounts.Add(activityCount);
  153. }
  154. return Ok(new { state = 200, activityCounts });
  155. }
  156. /// <summary>
  157. /// 统计当前学期的活动,传醍摩豆账户则统计该账户当前学期
  158. /// </summary>
  159. /// <param name="jsonElement"></param>
  160. /// <returns></returns>
  161. [HttpPost("get-termactivity")]
  162. public async Task<IActionResult> GetTermActivity(JsonElement jsonElement)
  163. {
  164. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  165. var cosmosClient = _azureCosmos.GetCosmosClient();
  166. var (start, end) = TimeHelper.GetTermStartOrEnd(DateTime.Now);
  167. if (!string.IsNullOrEmpty($"{tmdId}"))
  168. {
  169. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  170. List<ActivityCount> activityCounts = new List<ActivityCount>();
  171. foreach (var schoolId in schoolIds)
  172. {
  173. School school = new();
  174. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(schoolId, new PartitionKey("Base"));
  175. if (response.Status == 200)
  176. {
  177. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  178. school = json.ToObject<School>();
  179. }
  180. ActivityCount activityCount = new ActivityCount() { id = schoolId, name = school.name != null ? school.name : schoolId };
  181. foreach (var type in types)
  182. {
  183. string activitySql = $"SELECT COUNT(c.id) AS totals FROM c WHERE c.pk='{type}' AND c.school='{school}' and c.createTime >= {start} and c.createTime <= {end}";
  184. long totals = await CommonFind.FindTotals(cosmosClient, activitySql, new List<string>() { "Common" });
  185. activityCount.census.Add(new KeyValuePair<object, long>(type, totals));
  186. }
  187. activityCounts.Add(activityCount);
  188. }
  189. return Ok(new { state = 200, activityCounts });
  190. }
  191. else
  192. {
  193. List<KeyValuePair<string, object>> typeCount = new List<KeyValuePair<string, object>>();
  194. foreach (var type in types)
  195. {
  196. string querySql = $"SELECT COUNT(c.id) AS totals FROM c where c.pk='{type}' and c.createTime >= {start} and c.createTime <= {end}";
  197. long totals = await CommonFind.FindTotals(cosmosClient, querySql, new List<string>() { "Common" });
  198. KeyValuePair<string, object> valuePair = new KeyValuePair<string, object>(type, totals);
  199. typeCount.Add(valuePair);
  200. }
  201. return Ok(new { state = 200, typeCount });
  202. }
  203. }
  204. /// <summary>
  205. /// 统计区域的活动
  206. /// </summary>
  207. /// <param name="jsonElement"></param>
  208. /// <returns></returns>
  209. [HttpPost("get-area")]
  210. public async Task<IActionResult> GetAreaActovoty(JsonElement jsonElement)
  211. {
  212. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  213. var cosmosClient = _azureCosmos.GetCosmosClient();
  214. List<RecSchool> schools = new();
  215. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecSchool>(queryText: $"select c.id,c.name,c.picture,c.scale from c where c.areaId='{areaId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  216. {
  217. schools.Add(item);
  218. }
  219. long exemAreaCount = 0;
  220. long surveyAreaCount = 0;
  221. long voteAreaCount = 0;
  222. long homeworkAreaCount = 0;
  223. List<ActivityCount> activityCount = new();
  224. foreach (var school in schools)
  225. {
  226. ActivityCount tempCount = new ActivityCount() { id = school.id, name = school.name != null ? school.name : school.id };
  227. foreach (var type in types)
  228. {
  229. StringBuilder sqlTxt = new($"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.school='{school.id}' ");
  230. long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "Common" });
  231. switch (type)
  232. {
  233. case "Exam":
  234. exemAreaCount += totals;
  235. break;
  236. case "Survey":
  237. surveyAreaCount += totals;
  238. break;
  239. case "Vote":
  240. voteAreaCount += totals;
  241. break;
  242. case "Homework":
  243. homeworkAreaCount += totals;
  244. break;
  245. }
  246. tempCount.census.Add(new KeyValuePair<object, long>(type, totals));
  247. }
  248. activityCount.Add(tempCount);
  249. }
  250. return Ok(new { state = 200, exemAreaCount, surveyAreaCount, voteAreaCount, homeworkAreaCount, activityCount });
  251. }
  252. /// <summary>
  253. /// 依据区统计区级相关信息包括活动统计
  254. /// </summary>
  255. /// <param name="jsonElement"></param>
  256. /// <returns></returns>
  257. [HttpPost("get-areastics")]
  258. public async Task<IActionResult> GetAreaStics(JsonElement jsonElement)
  259. {
  260. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  261. var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
  262. var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");
  263. var cosmosClient = _azureCosmos.GetCosmosClient();
  264. List<RecSchool> schools = new();
  265. StringBuilder scSqlTxt = new("select c.id,c.name,c.picture,c.size,c.scale,c.type from c");
  266. if (!string.IsNullOrEmpty($"{areaId}"))
  267. {
  268. scSqlTxt.Append($" where c.areaId='{areaId}'");
  269. }
  270. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecSchool>(queryText: scSqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  271. {
  272. schools.Add(item);
  273. }
  274. int countArea = 0;//区级人员
  275. int appraiseArea = 0;//区级评审人员
  276. int areaSize = 0; //区级空间
  277. long examAreaCount = 0; //试卷活动
  278. long surveyAreaCount = 0; //问卷活动
  279. long voteAreaCount = 0; //投票活动
  280. long homeworkAreaCount = 0; //作业活动
  281. long weekActivity = 0; //周活动数量
  282. long termActivity=0; //学期活动
  283. int Basics = 0; //基础版数
  284. int standard = 0; //标准版数
  285. int major = 0; //专业版数
  286. int geCount = 0; //普教
  287. int heCount = 0; //高教
  288. int oeCount = 0; //其他教育
  289. List<SchoolLesson> schoolLessons = new(); //学校课例集合
  290. List<SchoolInfo> schoolInfos = new();
  291. int totalTime = 0;
  292. foreach (var school in schools)
  293. {
  294. if (school.type == 2)
  295. heCount += 1;
  296. else if (school.type == 1)
  297. geCount += 1;
  298. else oeCount += 1;
  299. areaSize += school.size;
  300. int count = 0;
  301. int appraise = 0;
  302. await foreach (var info in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<bool>(queryText: $"select value(array_contains(c.permissions,'train-appraise')) from c", requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Teacher-{school.id}") }))
  303. {
  304. if (info)
  305. {
  306. appraise += 1;
  307. appraiseArea += 1;
  308. }
  309. countArea += 1;
  310. count += 1;
  311. }
  312. //查询学校的总学时
  313. totalTime += await CommonFind.FindTotals(cosmosClient, "SELECT sum(c.totalTime) as totals FROM c", "Teacher", $"TeacherTrain-{school.id}");
  314. //查询学校参训人数
  315. int tempCount = await CommonFind.FindTotals(cosmosClient, $"select array_length(c.members) as totals from c where c.type='yxtrain'", "School", $"GroupList-{school.id}");
  316. //学校学生人数
  317. long stuCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c", "Student", $"Base-{school.id}");
  318. //查询是否有服务
  319. int serCount = await CommonFind.FindTotals(cosmosClient, $"select array_length(c.service) as totals from c where c.id='{school.id}'", "School", "ProductSum");
  320. if (serCount > 0)
  321. major += 1;
  322. else if (school.size >= 300 && school.scale >= 500)
  323. standard += 1;
  324. else Basics += 1;
  325. //课例
  326. int lessCount = await CommonFind.FindTotals(cosmosClient, "select count(c.id) totals from c", "School", $"LessonRecord-{school.id}");
  327. SchoolLesson schoolLesson = new()
  328. {
  329. id = school.id,
  330. name = school.name,
  331. picture = school.picture,
  332. count = lessCount
  333. };
  334. SchoolInfo schoolInfo = new() {
  335. id = school.id,
  336. name = school.name,
  337. picture = school.picture,
  338. teacherCount = count,
  339. studentCount = stuCount,
  340. appraiseCount = appraise,
  341. trainCount = tempCount
  342. };
  343. ActivityCount tempActivity = new ActivityCount() { id = school.id, name = school.name != null ? school.name : school.id };
  344. foreach (var type in types)
  345. {
  346. long totals = await CommonFind.FindTotals(cosmosClient, $"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.school='{school.id}' ", new List<string>() { "Common" });
  347. string weekSql= $"select count(c.id) as totals from c where c.pk='{type}' and c.school='{school.id}' and c.createTime>={weekStart} and c.createTime<={weekEnd}";
  348. long weekCount = await CommonFind.FindTotals(cosmosClient, weekSql, new List<string>() { "Common" });
  349. weekActivity += weekCount;
  350. string termSql = $"select count(c.id) as totals from c where c.pk='{type}' and c.school='{school.id}' and c.createTime>={termStart} and c.createTime<={termEnd}";
  351. long termCount = await CommonFind.FindTotals(cosmosClient, termSql, new List<string>() { "Common" });
  352. termActivity += termCount;
  353. switch (type)
  354. {
  355. case "Exam":
  356. examAreaCount += totals;
  357. break;
  358. case "Survey":
  359. surveyAreaCount += totals;
  360. break;
  361. case "Vote":
  362. voteAreaCount += totals;
  363. break;
  364. case "Homework":
  365. homeworkAreaCount += totals;
  366. break;
  367. }
  368. schoolInfo.census.Add(new KeyValuePair<object, long>(type, totals));
  369. }
  370. schoolInfos.Add(schoolInfo);
  371. schoolLessons.Add(schoolLesson);
  372. }
  373. return Ok(new { state = 200, schoolCount = schools.Count, countArea, weekActivity, termActivity, totalTime, appraiseArea, examAreaCount, surveyAreaCount, voteAreaCount, homeworkAreaCount, schools = schoolInfos, schoolLessons });
  374. }
  375. /// <summary>
  376. /// 所有区的统计接口
  377. /// </summary>
  378. /// <returns></returns>
  379. [HttpPost("get-all")]
  380. public async Task<IActionResult> GetAll()
  381. {
  382. var cosmosClient = _azureCosmos.GetCosmosClient();
  383. List<AreaInfo> areaInfos = new();
  384. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryIterator<AreaInfo>(queryText: $"select c.id,c.name,c.standard,c.standardName from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
  385. {
  386. areaInfos.Add(item);
  387. }
  388. var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
  389. var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");
  390. int heCount = 0;//高教
  391. int geCount = 0;//普教
  392. int oeCount = 0; //其他教育
  393. int allSize = 0;//空间总量
  394. Dictionary<string, long> activitys = new(); //活动类型集合
  395. long allActivity = 0; //活动累计
  396. long weekActivity = 0;//本周活动
  397. long termActivity = 0;//本学期活动
  398. long weekLess = 0; //本周课例
  399. long termLess = 0; //本学期课例
  400. long allLess = 0; //所有课例
  401. int tecCount = 0; //教师数量
  402. int scCount = 0; //学校数量
  403. foreach (var area in areaInfos)
  404. {
  405. List<RecSchool> recSchools = new();
  406. await foreach (var school in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecSchool>(queryText: $"select c.id,c.name,c.picture,c.type,c.size,c.scale from c where c.areaId='{area.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  407. {
  408. recSchools.Add(school);
  409. }
  410. scCount += recSchools.Count;
  411. recSchools.ForEach(x => { if (x.type == 2) heCount += 1; else if (x.type == 1) geCount += 1; else oeCount += 1; });
  412. allSize += recSchools.Select(s => s.size).Sum();
  413. area.schoolCount = recSchools.Count;
  414. int tempCount = await CommonFind.GetPeopleNumber(cosmosClient, "School", recSchools?.Select(x => x.id).ToList(), "Teacher");
  415. tecCount += tempCount;
  416. //查教师
  417. area.techCount = tempCount;
  418. //查询学生
  419. area.stuCount = await CommonFind.GetPeopleNumber(cosmosClient, "Student", recSchools?.Select(x => x.id).ToList(), "Base");
  420. }
  421. //统计活动
  422. foreach (var type in types)
  423. {
  424. string sqlTxt = $"select COUNT(c.id) AS totals from c where c.pk='{type}'";
  425. long totals = await CommonFind.FindTotals(cosmosClient, sqlTxt, new List<string>() { "Common" });
  426. string weekSql = $"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.createTime>={weekStart} and c.createTime<={weekStart} ";
  427. weekActivity += await CommonFind.FindTotals(cosmosClient, weekSql,new List<string> { "Common" });
  428. string termSql = $"select COUNT(c.id) AS totals from c where c.pk='{type}' and c.createTime>={termStart} and c.createTime<={termEnd} ";
  429. termActivity += await CommonFind.FindTotals(cosmosClient, termSql, new List<string> { "Common" });
  430. allActivity += totals;
  431. activitys.Add(type, totals);
  432. }
  433. allLess = await CommonFind.FindTotals(cosmosClient, "select count(c.id) as totals from c where c.pk='LessonRecord'", new List<string>() { "School" });
  434. weekLess = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='LessonRecord' and c.startTime>={weekStart} and c.startTime <={weekEnd}", new List<string>() { "School", "Teacher" });
  435. termLess = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c where c.pk='LessonRecord' and c.startTime>={termStart} and c.startTime <={termEnd}", new List<string>() { "School","Teacher" });
  436. return Ok(new { state = 200, areaCount = areaInfos.Count, allSize, heCount, geCount, oeCount, allLess, termLess, weekLess, allActivity, termActivity, weekActivity, areaInfos });
  437. }
  438. /// <summary>
  439. /// 依据活动Id查询活动详情信息 数据管理工具——查询工具
  440. /// </summary>
  441. /// <param name="jsonElement"></param>
  442. /// <returns></returns>
  443. [HttpPost("get-info")]
  444. public async Task<IActionResult> GetInfo(JsonElement jsonElement)
  445. {
  446. if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
  447. jsonElement.TryGetProperty("activity", out JsonElement activity);
  448. jsonElement.TryGetProperty("isPersonal", out JsonElement isPersonal);
  449. //if (jsonElement.TryGetProperty("", out JsonElement code)) return BadRequest();
  450. var cosmosClient = _azureCosmos.GetCosmosClient();
  451. List<object> infos = new List<object>();
  452. StringBuilder sqlTxt = new StringBuilder($"select * from c where c.id='{id}'");
  453. if (!string.IsNullOrEmpty($"{activity}"))
  454. {
  455. sqlTxt.Append($" and c.pk='{activity}'");
  456. }
  457. if (!string.IsNullOrEmpty($"{isPersonal}"))
  458. {
  459. if (bool.Parse($"{isPersonal}") == true)
  460. {
  461. sqlTxt.Append($" and c.scope='private'");
  462. }
  463. else
  464. {
  465. sqlTxt.Append($" and c.scope='school'");
  466. }
  467. }
  468. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
  469. {
  470. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  471. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  472. {
  473. infos.Add(obj.ToObject<object>());
  474. }
  475. }
  476. return Ok(new { state = 200, infos });
  477. }
  478. /// <summary>
  479. /// 区级信息
  480. /// </summary>
  481. public record AreaInfo
  482. {
  483. public string id { get; set; }
  484. public string name { get; set; }
  485. public string standard { get; set; }
  486. public string standardName { get; set; }
  487. public int schoolCount { get; set; }
  488. public int techCount { get; set;}
  489. public int stuCount { get; set; }
  490. }
  491. /// <summary>
  492. /// 区级下学校信息显示
  493. /// </summary>
  494. public record RecSchool
  495. {
  496. public string id { get; set; }
  497. public string name { get; set; }
  498. public string picture { get; set; }
  499. public int type { get; set; }
  500. public int size { get; set; }
  501. public int scale { get; set; }
  502. }
  503. private class SchoolInfo
  504. {
  505. public string id { get; set; }
  506. public string name { get; set; }
  507. public string picture { get; set; }
  508. //教师人数
  509. public int teacherCount { get; set; }
  510. //学生人数
  511. public long studentCount { get; set; }
  512. //评审人数
  513. public int appraiseCount { get; set; }
  514. //参训人数
  515. public int trainCount { get; set; }
  516. public List<KeyValuePair<object, long>> census { get; set; } = new List<KeyValuePair<object, long>>();
  517. }
  518. private record SchoolLesson
  519. {
  520. public string id { get; set; }
  521. public string name { get; set; }
  522. public string picture { get; set; }
  523. public int count { get; set; }
  524. }
  525. public record ActivityCount
  526. {
  527. public string id { get; set; }
  528. public string name { get; set; }
  529. public List<KeyValuePair<object, long>> census { get; set; } = new List<KeyValuePair<object, long>>();
  530. }
  531. }
  532. }