LessonSticsController.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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 TEAMModelOS.Models;
  8. using TEAMModelOS.SDK.DI;
  9. using Microsoft.Extensions.Options;
  10. using Azure.Cosmos;
  11. using System.Text.Json;
  12. using TEAMModelOS.SDK.Models.Cosmos.Common;
  13. using TEAMModelOS.SDK.Models;
  14. using TEAMModelBI.Models;
  15. using TEAMModelOS.SDK.Extension;
  16. using System.Text;
  17. using TEAMModelBI.Tool;
  18. using MathNet.Numerics.LinearAlgebra.Double;
  19. using TEAMModelBI.Tool.CosmosBank;
  20. namespace TEAMModelBI.Controllers.Census
  21. {
  22. [Route("lesson")]
  23. [ApiController]
  24. public class LessonSticsController : ControllerBase
  25. {
  26. private readonly AzureCosmosFactory _azureCosmos;
  27. private readonly AzureStorageFactory _azureStorage;
  28. private readonly DingDing _dingDing;
  29. private readonly Option _option;
  30. public LessonSticsController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureFactory, DingDing dingDing, IOptionsSnapshot<Option> option)
  31. {
  32. _azureCosmos = azureCosmos;
  33. _azureStorage = azureFactory;
  34. _dingDing = dingDing;
  35. _option = option?.Value;
  36. }
  37. /// <summary>
  38. /// 查询课例数量
  39. /// </summary>
  40. /// <param name="jsonElement"></param>
  41. /// <returns></returns>
  42. [HttpPost("get-count")]
  43. public async Task<IActionResult> GetCount(JsonElement jsonElement)
  44. {
  45. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  46. if (!jsonElement.TryGetProperty("term", out JsonElement term)) return BadRequest();
  47. var cosmosClient = _azureCosmos.GetCosmosClient();
  48. var (start, end) = TimeHelper.GetTermStartOrEnd(DateTime.Now);
  49. object totals = new();
  50. StringBuilder sqlTxt = new($"select COUNT(c.id) AS totals from c where c.pk='LessonRecord'");
  51. if (!string.IsNullOrEmpty($"{tmdId}"))
  52. {
  53. List<SchoolLen> schoolLens = new();
  54. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  55. foreach (var itemId in schoolIds)
  56. {
  57. School school = new();
  58. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("Base"));
  59. if (response.Status == 200)
  60. {
  61. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  62. school = json.ToObject<School>();
  63. }
  64. SchoolLen schoolLen = new() { id = itemId, name =
  65. school.name != null ? school.name : itemId };
  66. //string sqlTxt = $"SELECT COUNT(c.id) AS totals FROM c WHERE c.code='LessonRecord-{itemId}'";
  67. sqlTxt.Append($" WHERE c.code='LessonRecord-{itemId}'");
  68. if (bool.Parse($"{term}") == true)
  69. {
  70. sqlTxt.Append($" and c.startTime >= {start} and c.startTime <= {end}");
  71. }
  72. schoolLen.totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "School" });
  73. schoolLens.Add(schoolLen);
  74. }
  75. totals = schoolLens;
  76. }
  77. else
  78. {
  79. sqlTxt.Append($" where c.pk='LessonRecord'");
  80. if (bool.Parse($"{term}") == true)
  81. {
  82. sqlTxt.Append($" and c.startTime >= {start} and c.startTime <= {end}");
  83. }
  84. totals = await CommonFind.FindTotals(cosmosClient, sqlTxt.ToString(), new List<string>() { "School","Teacher" });
  85. }
  86. return Ok(new { state = 200, totals });
  87. }
  88. /// <summary>
  89. /// 统计所有课例数量
  90. /// </summary>
  91. /// <returns></returns>
  92. [HttpPost("get-total")]
  93. public async Task<IActionResult> GetCount()
  94. {
  95. try
  96. {
  97. var cosmosClient = _azureCosmos.GetCosmosClient();
  98. string lessonSql = $"select COUNT(c.id) AS totals from c where c.pk='LessonRecord'";
  99. long total = await CommonFind.FindTotals(cosmosClient, lessonSql, new List<string>() { "School","Teacher" });
  100. return Ok(new { state = 200, total });
  101. }
  102. catch (Exception ex)
  103. {
  104. await _dingDing.SendBotMsg($"BI,{_option.Location} /lesson/get-total \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  105. return BadRequest();
  106. }
  107. }
  108. /// <summary>
  109. /// 管家所关联的课例数据
  110. /// </summary>
  111. /// <param name="jsonElement"></param>
  112. /// <returns></returns>
  113. [ProducesDefaultResponseType]
  114. [HttpPost("get-assiist")]
  115. public async Task<IActionResult> GetAssiist(JsonElement jsonElement)
  116. {
  117. try
  118. {
  119. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  120. var cosmosClient = _azureCosmos.GetCosmosClient();
  121. List<SchoolLen> schoolLens = new();
  122. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  123. foreach (var itemId in schoolIds)
  124. {
  125. School school = new();
  126. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("Base"));
  127. if (response.Status == 200)
  128. {
  129. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  130. school = json.ToObject<School>();
  131. }
  132. SchoolLen schoolLen = new() { id = itemId, name = school != null ? school.name : itemId };
  133. string sqlTxt = $"SELECT COUNT(c.id) AS totals FROM c WHERE c.code='LessonRecord-{itemId}'";
  134. schoolLen.totals = await CommonFind.FindTotals(cosmosClient, sqlTxt, new List<string>() { "School" });
  135. schoolLens.Add(schoolLen);
  136. }
  137. return Ok(new { state = 200, schoolLens });
  138. }
  139. catch (Exception ex)
  140. {
  141. await _dingDing.SendBotMsg($"BI, {_option.Location} /lesson/get-assiist {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  142. return BadRequest();
  143. }
  144. }
  145. /// <summary>
  146. /// 统计所有的课例数据
  147. /// </summary>
  148. /// <returns></returns>
  149. [HttpPost("get-diccount")]
  150. public async Task<IActionResult> GetDicCount(JsonElement jsonElement)
  151. {
  152. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  153. var cosmosClient = _azureCosmos.GetCosmosClient();
  154. if (!string.IsNullOrEmpty($"{tmdId}"))
  155. {
  156. jsonElement.TryGetProperty("years", out JsonElement _years);
  157. int years = DateTime.UtcNow.Year;
  158. if (!string.IsNullOrEmpty($"{_years}"))
  159. {
  160. years = _years.GetInt32();
  161. }
  162. List<SchoolLen> schoolLens = new();
  163. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  164. foreach (string schoolId in schoolIds)
  165. {
  166. School school = new();
  167. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(schoolId, new PartitionKey("Base"));
  168. if (response.Status == 200)
  169. {
  170. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  171. school = json.ToObject<School>();
  172. }
  173. SchoolLen schoolLen = new() { id = schoolId, name = school != null ? school.name : schoolId };
  174. List<List<double>> begin = new();
  175. await foreach (var lcount in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessonCount>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{schoolId}-{years}") }))
  176. {
  177. begin.Add(lcount.beginCount);
  178. }
  179. schoolLen.totals = (long)DenseMatrix.OfColumns(begin).ColumnSums().Sum();
  180. schoolLens.Add(schoolLen);
  181. }
  182. return Ok(new { state = 200, schoolLens });
  183. }
  184. else
  185. {
  186. List<List<double>> begin = new();
  187. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessonCount>(queryText: "select value(c) from c where c.pk='LessonCount'", requestOptions: new QueryRequestOptions() { }))
  188. {
  189. begin.Add(item.beginCount);
  190. }
  191. var count = DenseMatrix.OfColumns(begin).ColumnSums().Sum();
  192. return Ok(new { state = 200, count });
  193. }
  194. }
  195. /// <summary>
  196. /// 顾问关联的学校统计本学期的课例
  197. /// </summary>
  198. /// <param name="jsonElement"></param>
  199. /// <returns></returns>
  200. [HttpPost("get-termcount")]
  201. public async Task<IActionResult> GetTermCount(JsonElement jsonElement)
  202. {
  203. if (jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) BadRequest();
  204. var cosmosClient = _azureCosmos.GetCosmosClient();
  205. List<SchoolLen> schoolLens = new();
  206. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  207. foreach (var scid in schoolIds)
  208. {
  209. School school = new();
  210. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(scid, new PartitionKey("Base"));
  211. if (response.Status == 200)
  212. {
  213. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  214. school = json.ToObject<School>();
  215. }
  216. SchoolLen schoolLen = new() { id = scid, name = !string.IsNullOrEmpty(school.name) ? school.name : scid };
  217. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  218. int year = (dateTime.Month <= 8 && dateTime.Month >= 3) ? dateTime.Year : dateTime.Year - 1;
  219. long stime = DateTimeOffset.Parse($"{year}-9-1").ToUnixTimeMilliseconds();
  220. //long etime = DateTimeOffset.Parse($"{year}-2-{((year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 29 : 28)}").ToUnixTimeMilliseconds();
  221. double totals = 0;
  222. var syear = DateTimeOffset.FromUnixTimeMilliseconds(stime).Year;
  223. var tyear = DateTimeOffset.UtcNow.Year;
  224. var tday = DateTimeOffset.UtcNow.DayOfYear;
  225. //今年多少天
  226. int tdays = (tyear % 4 == 0 && tyear % 100 != 0 || tyear % 400 == 0) ? 366 : 365;
  227. //去年多少天
  228. int pydays = (syear % 4 == 0 && syear % 100 != 0 || syear % 400 == 0) ? 366 : 365;
  229. List<LessonCount> scount = new();
  230. List<LessonCount> tcount = new();
  231. DenseMatrix dense = null;
  232. var queryClass = $"select value(c) from c ";
  233. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{scid}-{syear}") }))
  234. {
  235. scount.Add(item);
  236. }
  237. if (tyear > syear)
  238. {
  239. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonCount>(queryText: queryClass, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{scid}-{tyear}") }))
  240. {
  241. tcount.Add(item);
  242. }
  243. if (tcount.Count > 0)
  244. {
  245. List<List<double>> be = new();
  246. foreach (var item in tcount)
  247. {
  248. be.Add(item.beginCount);
  249. }
  250. dense = DenseMatrix.OfColumns(be);
  251. }
  252. }
  253. if (scount.Count > 0)
  254. {
  255. List<List<double>> begin = new();
  256. foreach (LessonCount lesson in scount)
  257. {
  258. begin.Add(lesson.beginCount);
  259. }
  260. var matrix = DenseMatrix.OfColumns(begin);
  261. //求本学期
  262. var sdays = DateTimeOffset.FromUnixTimeMilliseconds(stime).DayOfYear;
  263. if (tday - sdays < 0)
  264. {
  265. //var tmatrix = DenseMatrix.OfColumns(scount.beginCount);
  266. //跨年后开始到本学期结束
  267. double endMonth = 0;
  268. if (null != dense)
  269. {
  270. endMonth = dense.SubMatrix(0, tday, 0, dense.ColumnCount).ColumnSums().Sum();
  271. }
  272. var startMonth = matrix.SubMatrix(sdays - 1, pydays - sdays, 0, matrix.ColumnCount).ColumnSums().Sum();
  273. totals = (endMonth + startMonth);
  274. }
  275. else
  276. {
  277. var allMonth = matrix.SubMatrix(sdays - 1, tday - sdays + 1, 0, matrix.ColumnCount).ColumnSums().Sum();
  278. totals = allMonth;
  279. }
  280. }
  281. schoolLen.totals = (long)totals;
  282. schoolLens.Add(schoolLen);
  283. }
  284. return Ok(new { state = 200, schoolLens });
  285. }
  286. /// <summary>
  287. /// 统计区级课例
  288. /// </summary>
  289. /// <param name="jsonElement"></param>
  290. /// <returns></returns>
  291. [ProducesDefaultResponseType]
  292. [HttpPost("get-areacount")]
  293. public async Task<IActionResult> GetAreaCount(JsonElement jsonElement)
  294. {
  295. if(!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  296. List<string> schools = new();
  297. var cosmosClient = _azureCosmos.GetCosmosClient();
  298. StringBuilder scSqlTxt = new("select c.id from c");
  299. if (!string.IsNullOrEmpty($"{areaId}"))
  300. {
  301. scSqlTxt.Append($" where c.areaId='{areaId}'");
  302. }
  303. schools = await CommonFind.FindSchoolIds(cosmosClient, scSqlTxt.ToString(), "Base");
  304. //所有的课程记录
  305. List<LessonRecord> records = new();
  306. List<string> tecIds = new();
  307. foreach (var school in schools)
  308. {
  309. string sqlTxt = $"select value(c) from c where c.code='LessonRecord-{school}'";
  310. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonRecord>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{school}") }))
  311. {
  312. records.Add(item);
  313. }
  314. }
  315. tecIds = await CommonFind.FindRolesId(cosmosClient, schools);
  316. foreach (var tecId in tecIds)
  317. {
  318. string sqlTxt = $"select value(c) from c where c.id='{tecId}'";
  319. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<LessonRecord>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord") }))
  320. {
  321. records.Add(item);
  322. }
  323. }
  324. int dayCount = 0;
  325. var (dayStart, dayEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow);
  326. records.ForEach(x => { if (x.startTime >= dayStart && x.startTime <= dayEnd) dayCount += 1; });
  327. int weekCount = 0;
  328. var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
  329. records.ForEach(x => { if (x.startTime >= weekStart && x.startTime <= weekEnd) weekCount += 1; });
  330. int monthCount = 0;
  331. var (monthStart, monthEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "month");
  332. records.ForEach(x => { if (x.startTime >= monthStart && x.startTime <= monthEnd) monthCount += 1; });
  333. int termCount = 0;
  334. var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");
  335. records.ForEach(x => { if (x.startTime >= termStart && x.startTime <= termEnd) termCount += 1; });
  336. double teachCount = records.Where(r => r.tmdid != null).Where((x, i) => records.FindIndex(z => z.tmdid == x.tmdid) == i).ToList().Count;
  337. return Ok(new { state = 200, lessonCount = records.Count, teachCount, dayCount, weekCount, monthCount, termCount });
  338. }
  339. /// <summary>
  340. /// 统计区级一年每周的课例数据趋势
  341. /// </summary>
  342. /// <param name="jsonElement"></param>
  343. /// <returns></returns>
  344. [ProducesDefaultResponseType]
  345. [HttpPost("get-weekcount")]
  346. public async Task<IActionResult> GetWeekCount(JsonElement jsonElement)
  347. {
  348. jsonElement.TryGetProperty("areaId", out JsonElement areaId);
  349. //Dictionary<int, double> weeks = new();
  350. List<double> weeks = new();
  351. var cosmosClient = _azureCosmos.GetCosmosClient();
  352. int year = DateTimeOffset.UtcNow.Year;
  353. int dayOfweek = (int)DateTimeOffset.Parse($"{year}-1-1").DayOfWeek;
  354. int currentTime = DateTimeOffset.UtcNow.DayOfYear / 7 + 1;
  355. int currentTime1 = DateTimeOffset.UtcNow.DayOfYear / 7;
  356. var sqlTxts = "select value(c) from c";
  357. List<LessonCount> scount = new();
  358. List<LessonCount> tcount = new();
  359. StringBuilder sqlTxt = new("select c.id from c");
  360. if (!string.IsNullOrEmpty($"{areaId}"))
  361. {
  362. sqlTxt.Append($" where c.areaId='{areaId}'");
  363. }
  364. List<string> schools = await CommonFind.FindSchoolIds(cosmosClient, sqlTxt.ToString(), "Base");
  365. foreach (var sId in schools)
  366. {
  367. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessonCount>(queryText:sqlTxts,requestOptions:new QueryRequestOptions() { PartitionKey =new PartitionKey($"LessonCount-{sId}-{year}")}))
  368. {
  369. scount.Add(item);
  370. }
  371. }
  372. List<string> teacIds = await CommonFind.FindRolesId(cosmosClient, schools);
  373. foreach (var tId in teacIds)
  374. {
  375. var sqlTxtt = $"select value(c) from c where c.id='{tId}'";
  376. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<LessonCount>(queryText: sqlTxtt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{year}") }))
  377. {
  378. tcount.Add(item);
  379. }
  380. }
  381. int days = (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 366 : days = 365;
  382. List<List<double>> lessons = new();
  383. if (scount.Count > 0)
  384. {
  385. foreach (LessonCount item in scount)
  386. {
  387. lessons.Add(item.beginCount);
  388. }
  389. }
  390. if (tcount.Count > 0)
  391. {
  392. foreach (LessonCount item in tcount)
  393. {
  394. lessons.Add(item.beginCount);
  395. }
  396. }
  397. if (lessons.Count > 0)
  398. {
  399. var bmatrix = DenseMatrix.OfColumns(lessons);
  400. //开学第一周周内开课
  401. if (dayOfweek == 0)
  402. {
  403. dayOfweek = 7;
  404. }
  405. //第一周多少天
  406. var dd = 7 - dayOfweek + 1;
  407. //一年有几周
  408. int sweeks = days / 7;
  409. //查询天数
  410. int dayYear = 0;
  411. if (currentTime > 0)
  412. {
  413. for (int i = 0; i <= currentTime; i++)
  414. {
  415. if (i == 0)
  416. {
  417. var bsum = bmatrix.SubMatrix(dayYear, dd, 0, bmatrix.ColumnCount).ColumnSums().Sum();
  418. dayYear += dd;
  419. //weeks.Add(i, bsum);
  420. weeks.Add(bsum);
  421. }
  422. else
  423. {
  424. var bsum = bmatrix.SubMatrix(dayYear, 7, 0, bmatrix.ColumnCount).ColumnSums().Sum();
  425. dayYear += 7;
  426. //weeks.Add(i, bsum);
  427. weeks.Add(bsum);
  428. }
  429. }
  430. }
  431. //最后一周是否有余
  432. int stary = days - dayYear;
  433. if (stary > 0 && stary < 7)
  434. {
  435. var bsum = bmatrix.SubMatrix(dayYear, stary - 1, 0, bmatrix.ColumnCount).ColumnSums().Sum();
  436. //weeks.Add((sweeks + 1), bsum);
  437. weeks.Add(bsum);
  438. }
  439. }
  440. return Ok(new { state = 200, weeks });
  441. }
  442. /// <summary>
  443. /// 统计所有区级的课例和活动
  444. /// </summary>
  445. /// <returns></returns>
  446. [HttpPost("get-allarea")]
  447. public async Task<IActionResult> GetAllArea()
  448. {
  449. var cosmosClient = _azureCosmos.GetCosmosClient();
  450. List<AllAreaInfo> areaInfos = new();
  451. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryIterator<AllAreaInfo>(queryText: $"select c.id,c.name,c.standard,c.standardName from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
  452. {
  453. areaInfos.Add(item);
  454. }
  455. foreach (var area in areaInfos)
  456. {
  457. List<string> schooId = await CommonFind.FindSchoolIds(cosmosClient,$"select c.id from c where c.areaId='{area.id}'","Base");
  458. List<string> tecId = await CommonFind.FindRolesId(cosmosClient, schooId);
  459. area.lessCount = await LessonStatisWay.GetAll(cosmosClient, schooId, tecId);
  460. area.activityCount = await ActivityWay.GetAll(cosmosClient, schooId, tecId);
  461. }
  462. return Ok(new { state = 200 , areaInfos });
  463. }
  464. /// <summary>
  465. /// 依据课例Id获取课例详情 数据管理工具——查询工具
  466. /// </summary>
  467. /// <param name="jsonElement"></param>
  468. /// <returns></returns>
  469. [HttpPost("get-info")]
  470. public async Task<IActionResult> GetInfo(JsonElement jsonElement)
  471. {
  472. if (!jsonElement.TryGetProperty("lessonId", out JsonElement lessonId)) return BadRequest();
  473. var cosmosClient = _azureCosmos.GetCosmosClient();
  474. List<object> lessons = new();
  475. string sqlTxt = $"select * from c where c.id='{lessonId}'";
  476. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { }))
  477. {
  478. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  479. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  480. {
  481. lessons.Add(obj.ToObject<object>());
  482. }
  483. }
  484. return Ok(new { state = 200, lessons });
  485. }
  486. public record AllAreaInfo
  487. {
  488. public string id { get; set; }
  489. public string name { get; set; }
  490. public string standard { get; set; }
  491. public string standardName { get; set; }
  492. public int lessCount { get; set; }
  493. public int activityCount { get; set; }
  494. }
  495. public record SchoolLen
  496. {
  497. public string id { get; set; }
  498. public string name { get; set;}
  499. public long totals { get; set; }
  500. }
  501. }
  502. }