ActivitySticsController.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  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. using TEAMModelBI.Tool.CosmosBank;
  19. using TEAMModelOS.SDK.Models.Cosmos.BI;
  20. using TEAMModelOS.SDK.Context.BI;
  21. using TEAMModelOS.SDK.Context.Constant;
  22. using TEAMModelOS.SDK.Models.Service.BI;
  23. namespace TEAMModelBI.Controllers.Census
  24. {
  25. [Route("activity")]
  26. [ApiController]
  27. public class ActivitySticsController : ControllerBase
  28. {
  29. private readonly AzureCosmosFactory _azureCosmos;
  30. private readonly AzureStorageFactory _azureStorage;
  31. private readonly DingDing _dingDing;
  32. private readonly Option _option;
  33. private readonly CoreAPIHttpService _coreAPIHttpService;
  34. public ActivitySticsController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, CoreAPIHttpService coreAPIHttpService)
  35. {
  36. _azureCosmos = azureCosmos;
  37. _dingDing = dingDing;
  38. _azureStorage = azureStorage;
  39. _option = option?.Value;
  40. _coreAPIHttpService = coreAPIHttpService;
  41. }
  42. /// <summary>
  43. /// 统计活动 传醍摩豆则查询相关的学校活动
  44. /// </summary>
  45. /// <param name="jsonElement"></param>
  46. /// <returns></returns>
  47. [ProducesDefaultResponseType]
  48. [HttpPost("get-count")]
  49. public async Task<IActionResult> GetCount(JsonElement jsonElement)
  50. {
  51. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  52. if (!jsonElement.TryGetProperty("term", out JsonElement term)) return BadRequest();
  53. jsonElement.TryGetProperty("site", out JsonElement site);
  54. long start = 0, end = 0;
  55. if (bool.Parse($"{term}") == true)
  56. {
  57. (start, end) = TimeHelper.GetTermStartOrEnd(DateTime.Now);
  58. }
  59. var cosmosClient = _azureCosmos.GetCosmosClient();
  60. if ($"{site}".Equals(BIConst.Global))
  61. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  62. List<object> activityCount = new List<object>();
  63. if (!string.IsNullOrEmpty($"{tmdId}"))
  64. {
  65. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  66. foreach (var itemId in schoolIds)
  67. {
  68. School school = new();
  69. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("Base"));
  70. if (response.Status == 200)
  71. {
  72. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  73. school = json.ToObject<School>();
  74. }
  75. ActivityCount tempCount = new ActivityCount() { id = itemId, name = school.name != null ? school.name : itemId };
  76. foreach (var type in StaticValue.activityTypes)
  77. {
  78. StringBuilder sqlTxt = new StringBuilder($"select value(COUNT(c.id)) from c where c.pk='{type}' and c.school='{itemId}' ");
  79. if (bool.Parse($"{term}") == true)
  80. {
  81. sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
  82. }
  83. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", sqlTxt.ToString());
  84. tempCount.census.Add(new KeyValuePair<object, long>(type, totals));
  85. }
  86. activityCount.Add(tempCount);
  87. }
  88. }
  89. else
  90. {
  91. foreach (var type in StaticValue.activityTypes)
  92. {
  93. StringBuilder sqlTxt = new StringBuilder($"SELECT value(COUNT(c.id)) FROM c where c.pk='{type}' ");
  94. if (bool.Parse($"{term}") == true)
  95. {
  96. sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
  97. }
  98. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", sqlTxt.ToString());
  99. activityCount.Add(new KeyValuePair<string, object>(type, totals));
  100. }
  101. }
  102. return Ok(new { state = 200, activityCount });
  103. }
  104. /// <summary>
  105. /// 统计所有的评量活动,问卷调查,投票活动,作业 //已对接
  106. /// </summary>
  107. /// <returns></returns>
  108. [HttpPost("get-allactivity")]
  109. public async Task<IActionResult> GetAllActivity(JsonElement jsonElement)
  110. {
  111. try
  112. {
  113. jsonElement.TryGetProperty("areaId", out JsonElement areaId);
  114. jsonElement.TryGetProperty("site", out JsonElement site);
  115. var cosmosClient = _azureCosmos.GetCosmosClient();
  116. if ($"{site}".Equals(BIConst.Global))
  117. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  118. List<KeyValuePair<string, long>> typeCount = new();
  119. string inSql = null;
  120. List<string> scIds = new();
  121. if (!string.IsNullOrEmpty($"{areaId}"))
  122. {
  123. string areaSc = $"select value(c.id) from c where c.pk='School' and c.areaId='{areaId}'";
  124. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: areaSc, requestOptions: new QueryRequestOptions() { }))
  125. {
  126. scIds.Add(item);
  127. }
  128. inSql = $" and {BICommonWay.ManyScSql("c.school", scIds)}";
  129. }
  130. foreach (var type in StaticValue.activityTypes)
  131. {
  132. string querySql = $"SELECT value(count(c.id)) FROM c where c.pk='{type}' ";
  133. long totals = 0;
  134. if (!string.IsNullOrEmpty($"{areaId}"))
  135. {
  136. if (!string.IsNullOrEmpty(inSql) && scIds.Count > 0)
  137. {
  138. querySql = $"{querySql}{inSql}";
  139. totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", querySql);
  140. }
  141. }
  142. else
  143. totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", querySql);
  144. KeyValuePair<string, long> valuePair = new(type, totals);
  145. typeCount.Add(valuePair);
  146. }
  147. return Ok(new { state = 200, typeCount });
  148. }
  149. catch (Exception ex)
  150. {
  151. await _dingDing.SendBotMsg($"BI,{_option.Location} /activity/get-allactivity \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  152. return BadRequest();
  153. }
  154. }
  155. /// <summary>
  156. /// 统计顾问关联的学校活动数量:评测、问卷、投票、作业
  157. /// </summary>
  158. /// <param name="jsonElement"></param>
  159. /// <returns></returns>
  160. [ProducesDefaultResponseType]
  161. [HttpPost("get-assistactivity")]
  162. public async Task<IActionResult> GetAssistSchoolActivity(JsonElement jsonElement)
  163. {
  164. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  165. jsonElement.TryGetProperty("site", out JsonElement site);
  166. var cosmosClient = _azureCosmos.GetCosmosClient();
  167. if ($"{site}".Equals(BIConst.Global))
  168. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  169. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  170. List<ActivityCount> activityCounts = new List<ActivityCount>();
  171. foreach (var itemId in schoolIds)
  172. {
  173. School school = new();
  174. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, 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 = itemId, name = school.name != null ? school.name : itemId };
  181. foreach (var type in StaticValue.activityTypes)
  182. {
  183. string activitySql = $"SELECT value(count(c.id)) FROM c WHERE c.pk='{type}' AND c.school='{itemId}'";
  184. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", activitySql);
  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. /// <summary>
  192. /// 统计当前学期的活动,传醍摩豆账户则统计该账户当前学期
  193. /// </summary>
  194. /// <param name="jsonElement"></param>
  195. /// <returns></returns>
  196. [HttpPost("get-termactivity")]
  197. public async Task<IActionResult> GetTermActivity(JsonElement jsonElement)
  198. {
  199. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  200. jsonElement.TryGetProperty("site", out JsonElement site);
  201. var cosmosClient = _azureCosmos.GetCosmosClient();
  202. if ($"{site}".Equals(BIConst.Global))
  203. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  204. var (start, end) = TimeHelper.GetTermStartOrEnd(DateTime.Now);
  205. if (!string.IsNullOrEmpty($"{tmdId}"))
  206. {
  207. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  208. List<ActivityCount> activityCounts = new List<ActivityCount>();
  209. foreach (var schoolId in schoolIds)
  210. {
  211. School school = new();
  212. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(schoolId, new PartitionKey("Base"));
  213. if (response.Status == 200)
  214. {
  215. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  216. school = json.ToObject<School>();
  217. }
  218. ActivityCount activityCount = new ActivityCount() { id = schoolId, name = school.name != null ? school.name : schoolId };
  219. foreach (var type in StaticValue.activityTypes)
  220. {
  221. string activitySql = $"SELECT value(COUNT(c.id)) FROM c WHERE c.pk='{type}' AND c.school='{school}' and c.createTime >= {start} and c.createTime <= {end}";
  222. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", activitySql);
  223. activityCount.census.Add(new KeyValuePair<object, long>(type, totals));
  224. }
  225. activityCounts.Add(activityCount);
  226. }
  227. return Ok(new { state = 200, activityCounts });
  228. }
  229. else
  230. {
  231. List<KeyValuePair<string, object>> typeCount = new List<KeyValuePair<string, object>>();
  232. foreach (var type in StaticValue.activityTypes)
  233. {
  234. string querySql = $"SELECT value(COUNT(c.id)) FROM c where c.pk='{type}' and c.createTime >= {start} and c.createTime <= {end}";
  235. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", querySql);
  236. KeyValuePair<string, object> valuePair = new KeyValuePair<string, object>(type, totals);
  237. typeCount.Add(valuePair);
  238. }
  239. return Ok(new { state = 200, typeCount });
  240. }
  241. }
  242. /// <summary>
  243. /// 统计区域的活动
  244. /// </summary>
  245. /// <param name="jsonElement"></param>
  246. /// <returns></returns>
  247. [HttpPost("get-area")]
  248. public async Task<IActionResult> GetAreaActovoty(JsonElement jsonElement)
  249. {
  250. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  251. jsonElement.TryGetProperty("site", out JsonElement site);
  252. var cosmosClient = _azureCosmos.GetCosmosClient();
  253. if ($"{site}".Equals(BIConst.Global))
  254. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  255. List<RecSchool> schools = new();
  256. 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") }))
  257. {
  258. schools.Add(item);
  259. }
  260. long exemAreaCount = 0; //评测活动
  261. long surveyAreaCount = 0; //问卷
  262. long voteAreaCount = 0; //投票
  263. long homeworkAreaCount = 0; //作业活动
  264. List<ActivityCount> activityCount = new();
  265. foreach (var school in schools)
  266. {
  267. ActivityCount tempCount = new ActivityCount() { id = school.id, name = school.name != null ? school.name : school.id };
  268. foreach (var type in StaticValue.activityTypes)
  269. {
  270. StringBuilder sqlTxt = new($"select value(COUNT(c.id)) from c where c.pk='{type}' and c.school='{school.id}' ");
  271. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", sqlTxt.ToString());
  272. switch (type)
  273. {
  274. case "Exam":
  275. exemAreaCount += totals;
  276. break;
  277. case "Survey":
  278. surveyAreaCount += totals;
  279. break;
  280. case "Vote":
  281. voteAreaCount += totals;
  282. break;
  283. case "Homework":
  284. homeworkAreaCount += totals;
  285. break;
  286. }
  287. tempCount.census.Add(new KeyValuePair<object, long>(type, totals));
  288. }
  289. activityCount.Add(tempCount);
  290. }
  291. return Ok(new { state = 200, exemAreaCount, surveyAreaCount, voteAreaCount, homeworkAreaCount, activityCount });
  292. }
  293. /// <summary>
  294. /// 依据区统id分析数据区级数据分析 //已对接
  295. /// </summary>
  296. /// <param name="jsonElement"></param>
  297. /// <returns></returns>
  298. [ProducesDefaultResponseType]
  299. [HttpPost("get-areastics")]
  300. public async Task<IActionResult> GetAreaStics(JsonElement jsonElement)
  301. {
  302. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  303. jsonElement.TryGetProperty("site", out JsonElement site);
  304. var (dayS, dayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow);
  305. var (weekS, weekE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
  306. var (monthS, monthE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "month");
  307. var (termS, termE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");
  308. var cosmosClient = _azureCosmos.GetCosmosClient();
  309. if ($"{site}".Equals(BIConst.Global))
  310. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  311. int scCnt = 0; //学校人数
  312. int weekScCnt = 0; //本周学校人数
  313. int motnhScCnt = 0; //本月学校人数
  314. int tchCnt = 0; //所有区级老师
  315. int weekTchCnt = 0; //所有区级老师
  316. int monthTchCnt = 0; //所有区级老师
  317. int stuCnt = 0; //所有区级学生
  318. int weekStuCnt = 0; //所有区级学生
  319. int monthStuCnt = 0; //所有区级学生
  320. int areaSize = 0; //区级空间
  321. int weekSize = 0; //本周空间
  322. int monthSize = 0; //本月空间
  323. int allLess = 0; //所有课例
  324. int weekLess = 0; //周课例
  325. int monthLess = 0; //月课例
  326. int termLess = 0; //学期课例
  327. int totalTime = 0; //累计学时
  328. int allActCnt = 0; //所有活动
  329. int weekActivity = 0; //周活动数量
  330. int monthActCnt = 0; //月活动数量
  331. int termActivity = 0; //学期活动
  332. int onLineCount = 0; //线上研修人数
  333. int offlineCount = 0; //线下研修人数
  334. int classRoomCount = 0; //课堂实录人数
  335. int submitCount = 0; //认证材料人数
  336. int fulfilCount = 0; //已完成
  337. int carryOnCount = 0; //进行中
  338. int noCount = 0; //未开始
  339. List<AreaStudy> trains = new();
  340. AreaSetting setting = null;
  341. try
  342. {
  343. setting = await cosmosClient.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<AreaSetting>($"{areaId}", new PartitionKey("AreaSetting"));
  344. }
  345. catch (CosmosException)
  346. {
  347. setting = null;
  348. }
  349. if (setting == null)
  350. {
  351. setting = new AreaSetting
  352. {
  353. allTime = 50,
  354. classTime = 5,
  355. submitTime = 15,
  356. onlineTime = 20,
  357. offlineTime = 10,
  358. lessonMinutes = 45,
  359. };
  360. }
  361. string oftenSql = "select value(count(c.id)) from c";
  362. string scSql = $"{oftenSql} where c.areaId='{areaId}'";
  363. List<string> scIds = await CommonFind.GetValueSingle(cosmosClient, "School", $"select value(c.id) from c where c.areaId='{areaId}'", "Base");
  364. if (scIds.Count > 0)
  365. {
  366. string weekWhereSql = $"c.createTime >= {weekS} and c.createTime <= {weekE}";
  367. string monthWhereSql = $"c.createTime >= {monthS} and c.createTime <= {monthE}";
  368. //学校查询拼接
  369. string comSql = BICommonWay.ManyScSql("c.school", scIds);
  370. //学校数据查询
  371. scCnt = scIds.Count;
  372. weekScCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{oftenSql} where {comSql} and {weekWhereSql}", "Base");
  373. motnhScCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{oftenSql} where {comSql} and {monthWhereSql}", "Base");
  374. //查教师
  375. string tchSpl = BICommonWay.ManyScSql("REPLACE(c.code, 'Teacher-', '')", scIds);
  376. string tchSql = $"{oftenSql} where c.pk='Teacher' and {tchSpl}";
  377. tchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", tchSql);
  378. weekTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{tchSql} and {weekWhereSql}");
  379. monthTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{tchSql} and {monthWhereSql}");
  380. string stuSpl = BICommonWay.ManyScSql("REPLACE(c.code, 'Base-', '')", scIds);
  381. //查学生
  382. string stuSql = $"{oftenSql} where c.pk='Base' and {stuSpl}";
  383. stuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", $"{oftenSql} where c.pk='Base' and {stuSpl}");
  384. weekStuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", $"{oftenSql} where c.pk='Base' and {stuSpl} and {weekWhereSql}");
  385. monthStuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", $"{oftenSql} where c.pk='Base' and {stuSpl} and {monthWhereSql}");
  386. //空间
  387. //学校查询拼接
  388. string sizeSpl = BICommonWay.ManyScSql("c.id", scIds);
  389. string sizeSql = "select value(sum(c.size)) from c";
  390. areaSize = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{sizeSql} where {sizeSpl}","Base");
  391. weekSize = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{sizeSql} where {sizeSpl} and {weekWhereSql}", "Base");
  392. monthSize = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{sizeSql} where {sizeSpl} and {monthWhereSql}", "Base");
  393. //课例
  394. allLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{oftenSql} where c.pk='LessonRecord' and {comSql}");
  395. weekLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{oftenSql} where c.pk='LessonRecord' and {comSql} and c.startTime >= {weekS} and c.startTime <= {weekE}");
  396. termLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{oftenSql} where c.pk='LessonRecord' and {comSql} and c.startTime >= {termS} and c.startTime <= {termE}");
  397. monthLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{oftenSql} where c.pk='LessonRecord' and {comSql} and c.startTime >= {monthS} and c.startTime <= {monthE}");
  398. //学时
  399. totalTime = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", $"select value(sum(c.totalTime)) from c where c.pk='TeacherTrain' and {comSql}");
  400. //活动
  401. string actSpl = BICommonWay.ManyScSql(" and c.school", scIds);
  402. allActCnt = await ActivityWay.GetCnt(cosmosClient, condSql: actSpl);
  403. weekActivity = await ActivityWay.GetCnt(cosmosClient, condSql: $"{actSpl} and {weekWhereSql} ");
  404. termActivity = await ActivityWay.GetCnt(cosmosClient, condSql: $"{actSpl} and c.createTime >= {termS} and c.createTime <= {termE}");
  405. monthActCnt = await ActivityWay.GetCnt(cosmosClient, condSql: $"{actSpl} and {monthWhereSql} ");
  406. string onLineSql = $"{oftenSql} where c.TeacherTrain and {comSql} and c.onlineTime = 0 or c.onlineTime >= {setting.onlineTime} ";
  407. onLineCount = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", onLineSql);
  408. //string offLineSql = $"{oftenSql} where c.TeacherTrain and {comSql} and c.offlineTime = 0 or c.offlineTime >= {setting.offlineTime} ";
  409. //offlineCount = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", offLineSql);
  410. //string ctSql = $"{oftenSql} where c.TeacherTrain and {comSql} and c.classTime = 0 or c.classTime >= {setting.classTime} ";
  411. //classRoomCount = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", ctSql);
  412. //string stSql = $"{oftenSql} join s in c.currency where c.TeacherTrain and {comSql} and s.submitTime = 0 or s.submitTime >= {setting.submitTime}";
  413. //submitCount = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", ctSql);
  414. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id,c.code,c.onlineTime,c.offlineTime,c.classTime,c.currency from c where c.pk='TeacherTrain' and {comSql}", requestOptions: new QueryRequestOptions() { }))
  415. {
  416. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  417. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  418. {
  419. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  420. {
  421. trains.Add(obj.ToObject<AreaStudy>());
  422. }
  423. }
  424. }
  425. trains.ForEach(x =>
  426. {
  427. //线上研修
  428. if (x.onlineTime == 0) onLineCount++; else if (x.onlineTime >= setting.onlineTime) onLineCount++; else onLineCount++;
  429. //线下研修
  430. if (x.offlineTime == 0) offlineCount++; else if (x.onlineTime >= setting.offlineTime) offlineCount++; else offlineCount++;
  431. //课堂实录
  432. if (x.classTime == 0) classRoomCount++; else if (x.classTime >= setting.classTime) classRoomCount++; else classRoomCount++;
  433. //认证材料
  434. if (x.currency.submitTime == 0) submitCount++; else if (x.currency.submitTime >= setting.submitTime) submitCount++; else submitCount++;
  435. if (x.currency.submitTime == 0 && x.classTime == 0 && x.offlineTime == 0 && x.onlineTime == 0) noCount++;
  436. else if (x.currency.submitTime >= setting.submitTime && x.classTime >= setting.classTime && x.onlineTime >= setting.offlineTime && x.onlineTime >= setting.onlineTime) fulfilCount++;
  437. else carryOnCount++;
  438. });
  439. }
  440. return Ok(new { state = RespondCode.Ok, scCnt, weekScCnt, motnhScCnt, tchCnt, weekTchCnt, monthTchCnt, stuCnt, weekStuCnt, monthStuCnt, areaSize, weekSize, monthSize, allLess, weekLess, monthLess, termLess, totalTime, allActCnt, weekActivity, monthActCnt, termActivity, study = new { onLineCount, offlineCount, classRoomCount, submitCount, fulfilCount, carryOnCount, noCount } });
  441. //int countArea = 0;//区级人员
  442. //int appraiseArea = 0;//区级评审人员
  443. //long examAreaCount = 0; //试卷活动
  444. //long surveyAreaCount = 0; //问卷活动
  445. //long voteAreaCount = 0; //投票活动
  446. //long homeworkAreaCount = 0; //作业活动
  447. //int basics = 0; //基础版数
  448. //int standard = 0; //标准版数
  449. //int major = 0; //专业版数
  450. //int geCount = 0; //普教
  451. //int heCount = 0; //高教
  452. //int oeCount = 0; //其他教育
  453. //int dayLess = 0; //当天课例
  454. //double teachCount = 0; //课例教师
  455. //List<RecSchool> schools = new();
  456. //StringBuilder scSqlTxt = new("select c.id,c.name,c.picture,c.size,c.scale,c.type from c");
  457. //if (!string.IsNullOrEmpty($"{areaId}"))
  458. //{
  459. // scSqlTxt.Append($" where c.areaId='{areaId}'");
  460. //}
  461. //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecSchool>(queryText: scSqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  462. //{
  463. // schools.Add(item);
  464. //}
  465. //List<SchoolLesson> schoolLessons = new(); //学校课例集合
  466. //List<SchoolInfo> schoolInfos = new();
  467. //List<LessonRecord> records = new();//所有的课程记录
  468. ////List<string> scIds = schools.Select(x => x.id).ToList();
  469. //int totalTime = 0;
  470. //heCount = schools.Select(s => s.type == 2).Count();
  471. //geCount = schools.Select(s => s.type == 1).Count();
  472. //oeCount = schools.Select(s => s.type != 2 && s.type != 1).Count();
  473. //areaSize = schools.Select(s => s.size).Sum();
  474. //foreach (var school in schools)
  475. //{
  476. // int count = 0;
  477. // int appraise = 0;
  478. // 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}") }))
  479. // {
  480. // if (info)
  481. // {
  482. // appraise += 1;
  483. // appraiseArea += 1;
  484. // }
  485. // countArea += 1;
  486. // count += 1;
  487. // }
  488. // //查询学校的总学时
  489. // totalTime += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", "SELECT value(sum(c.totalTime)) FROM c", $"TeacherTrain-{school.id}");
  490. // //查询学校参训人数
  491. // int tempCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(array_length(c.members)) from c where c.type='yxtrain'", $"GroupList-{school.id}");
  492. // //学校学生人数
  493. // long stuCount = await CommonFind.GetSqlValueCount(cosmosClient, "Student", $"select value(count(c.id)) from c", $"Base-{school.id}");
  494. // //查询是否有服务
  495. // int serCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(array_length(c.service)) from c where c.id='{school.id}'", "ProductSum");
  496. // if (serCount > 0)
  497. // major += 1;
  498. // else if (school.size >= 300 && school.scale >= 500)
  499. // standard += 1;
  500. // else basics += 1;
  501. // string sqlTxtSchool = $"select value(c) from c where c.code='LessonRecord-{school}'";
  502. // await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonRecord>(queryText: sqlTxtSchool, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{school}") }))
  503. // {
  504. // records.Add(item);
  505. // }
  506. // //课例
  507. // int lessCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(count(c.id)) from c", $"LessonRecord-{school.id}");
  508. // SchoolLesson schoolLesson = new()
  509. // {
  510. // id = school.id,
  511. // name = school.name,
  512. // picture = school.picture,
  513. // count = lessCount
  514. // };
  515. // SchoolInfo schoolInfo = new()
  516. // {
  517. // id = school.id,
  518. // name = school.name,
  519. // picture = school.picture,
  520. // teacherCount = count,
  521. // studentCount = stuCount,
  522. // appraiseCount = appraise,
  523. // trainCount = tempCount
  524. // };
  525. // ActivityCount tempActivity = new() { id = school.id, name = school.name != null ? school.name : school.id };
  526. // foreach (var type in StaticValue.activityTypes)
  527. // {
  528. // long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"select value(COUNT(c.id)) from c where c.pk='{type}' and c.school='{school.id}' ");
  529. // string weekSql = $"select value(count(c.id)) from c where c.pk='{type}' and c.school='{school.id}' and c.createTime>={weekS} and c.createTime<={weekE}";
  530. // long weekActCount = await CommonFind.GetSqlValueCount(cosmosClient, "Common", weekSql);
  531. // weekActivity += weekActCount;
  532. // string termSql = $"select value(count(c.id)) from c where c.pk='{type}' and c.school='{school.id}' and c.createTime>={termS} and c.createTime<={termE}";
  533. // long termActCount = await CommonFind.GetSqlValueCount(cosmosClient, "Common", termSql);
  534. // termActivity += termActCount;
  535. // switch (type)
  536. // {
  537. // case "Exam":
  538. // examAreaCount += totals;
  539. // break;
  540. // case "Survey":
  541. // surveyAreaCount += totals;
  542. // break;
  543. // case "Vote":
  544. // voteAreaCount += totals;
  545. // break;
  546. // case "Homework":
  547. // homeworkAreaCount += totals;
  548. // break;
  549. // }
  550. // schoolInfo.census.Add(new KeyValuePair<object, long>(type, totals));
  551. // }
  552. // schoolInfos.Add(schoolInfo);
  553. // schoolLessons.Add(schoolLesson);
  554. //}
  555. //List<string> tecIds = await CommonFind.FindRolesId(cosmosClient, scIds);
  556. ////查询去下面所有学校教师课例
  557. //foreach (var tecId in tecIds)
  558. //{
  559. // string sqlTxt = $"select value(c) from c where c.id='{tecId}'";
  560. // await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<LessonRecord>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord") }))
  561. // {
  562. // records.Add(item);
  563. // }
  564. //}
  565. ////课例统计
  566. //if (records.Count > 0)
  567. //{
  568. // records.ForEach(x => { if (x.startTime >= dayS && x.startTime <= dayE) dayLess += 1; });
  569. // records.ForEach(x => { if (x.startTime >= weekS && x.startTime <= weekE) weekLess += 1; });
  570. // records.ForEach(x => { if (x.startTime >= monthS && x.startTime <= monthE) monthLess += 1; });
  571. // records.ForEach(x => { if (x.startTime >= termS && x.startTime <= termE) termLess += 1; });
  572. // teachCount = records.Where(r => r.tmdid != null).Where((x, i) => records.FindIndex(z => z.tmdid == x.tmdid) == i).ToList().Count;
  573. //}
  574. //return Ok(new { state = 200, schoolCount = schools.Count, countArea, weekActivity, termActivity, totalTime, appraiseArea, examAreaCount, surveyAreaCount, voteAreaCount, homeworkAreaCount, major, standard, basics, oeCount, dayLess, weekLess, monthLess, termLess, teachCount, allLess = records.Count, schools = schoolInfos, schoolLessons });
  575. }
  576. /// <summary>
  577. /// 所有区的统计接口 学区情况 //已对接
  578. /// </summary>
  579. /// <returns></returns>
  580. [HttpPost("get-all")]
  581. public async Task<IActionResult> GetAll(JsonElement jsonElement)
  582. {
  583. jsonElement.TryGetProperty("site", out JsonElement site);
  584. var cosmosClient = _azureCosmos.GetCosmosClient();
  585. if ($"{site}".Equals(BIConst.Global))
  586. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  587. var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
  588. var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");
  589. var (monthS, monthE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "month");
  590. int areaCount = 0; //区域数量
  591. int scCount = 0; //学校数量
  592. int tecCount = 0; //教师数量
  593. int stuCount = 0; //学生数量
  594. int allSize = 0; //空间总量
  595. int weekScCnt = 0; //本周学校
  596. int weekTchCnt = 0; //本周教师
  597. int monthScCnt = 0; //本月学校
  598. int monthTchCnt = 0; //本月教师
  599. int heCount = 0;//高教
  600. int geCount = 0;//普教
  601. int oeCount = 0; //其他教育
  602. int allActivity = 0; //活动累计
  603. int weekActivity = 0;//本周活动
  604. int termActivity = 0;//本学期活动
  605. int monthActCnt = 0; //本月活动
  606. int weekLess = 0; //本周课例
  607. int termLess = 0; //本学期课例
  608. int allLess = 0; //所有课例
  609. int monthLesCnt = 0; //本月课例
  610. int resourceCount = 0; //累计资源
  611. int totalTime = 0; //总学时
  612. string commSql = "select value(count(c.id)) from c";
  613. areaCount = await CommonFind.GetSqlValueCount(cosmosClient, "Normal", commSql, "Base-Area");
  614. scCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", commSql, "Base");
  615. tecCount = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", commSql,"Base");
  616. stuCount = await CommonFind.GetSqlValueCount(cosmosClient, "Student", commSql, "Base");
  617. allSize = await CommonFind.GetSqlValueCount(cosmosClient, "School", commSql, "Base");
  618. weekScCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{commSql} where c.createTime >= {termStart} and c.createTime >= {termEnd}", "Base");
  619. monthScCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{commSql} where c.createTime >= {monthS} and c.createTime >= {monthE}", "Base");
  620. weekTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", $"{commSql} where c.createTime >= {termStart} and c.createTime >= {termEnd}", "Base");
  621. monthTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", $"{commSql} where c.createTime >= {monthS} and c.createTime >= {monthE}", "Base");
  622. heCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{commSql} where c.type = 1", "Base");
  623. geCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{commSql} where c.type = 2", "Base");
  624. oeCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{commSql} where c.type != 1 and c.type != 2", "Base");
  625. //活动
  626. allActivity = await ActivityWay.GetCnt(cosmosClient);
  627. string weekSql = $"and c.createTime >= {weekStart} and c.createTime <={weekEnd}";
  628. weekActivity = await ActivityWay.GetCnt(cosmosClient, condSql: weekSql);
  629. string termSql = $"and c.createTime >= {termStart} and c.createTime <={termEnd}";
  630. termActivity = await ActivityWay.GetCnt(cosmosClient, condSql: termSql);
  631. string monthActSql = $"and c.createTime >= {monthS} and c.createTime <={monthE}";
  632. monthActCnt = await ActivityWay.GetCnt(cosmosClient, condSql: monthActSql);
  633. //课例
  634. string allLessSql = $"select value(count(c.id)) from c where c.pk='LessonRecord'";
  635. allLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", allLessSql);
  636. string weekLSql = $"{allLessSql} and c.startTime >= {weekStart} and c.startTime <={weekEnd}";
  637. weekLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", weekLSql);
  638. string termLSql = $"{allLessSql} and c.startTime >= {termStart} and c.startTime <={termEnd}";
  639. termLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", termLSql);
  640. string monthLSql = $"{allLessSql} and c.startTime >= {monthS} and c.startTime <={monthE}";
  641. monthLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", monthLSql);
  642. totalTime = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", "select value(sum(c.totalTime)) from c where c.pk='TeacherTrain'");
  643. resourceCount = await CommonFind.GetSqlValueCount(cosmosClient, new List<string>() { "School", "Teacher" }, "select value(count(c.id)) from c where c.pk='Bloblog'");
  644. return Ok(new { state = RespondCode.Ok, areaCount, scCount, tecCount, stuCount, allSize, weekScCnt, weekTchCnt, monthScCnt, monthTchCnt, heCount, geCount, oeCount, allActivity, weekActivity, termActivity, monthActCnt, weekLess, termLess, allLess, monthLesCnt, resourceCount, totalTime });
  645. }
  646. /// <summary>
  647. /// 分析所有区的人数和学校 学区情况 //已对接
  648. /// </summary>
  649. /// <param name="jsonElement"></param>
  650. /// <returns></returns>
  651. [HttpPost("get-areasanls")]
  652. public async Task<IActionResult> GetAreasAnls(JsonElement jsonElement)
  653. {
  654. jsonElement.TryGetProperty("site", out JsonElement site);
  655. var cosmosClient = _azureCosmos.GetCosmosClient();
  656. if ($"{site}".Equals(BIConst.Global))
  657. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  658. List<AreaInfo> areaInfos = new();
  659. 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") }))
  660. {
  661. areaInfos.Add(item);
  662. }
  663. foreach (var area in areaInfos)
  664. {
  665. string scSql = $"select value(c.id) from c where c.areaId='{area.id}'";
  666. List<string> scIds = await CommonFind.GetValueSingle(cosmosClient, "School", scSql,"Base");
  667. //allSize += recSchools.Select(s => s.size).Sum();
  668. area.scCnt = scIds.Count;
  669. int tTchCnt = 0;
  670. int tStuCnt = 0;
  671. if (scIds.Count > 0)
  672. {
  673. scSql = BICommonWay.ManyScSql("REPLACE(c.code, 'Teacher-', '')", scIds);
  674. //查教师
  675. string tchSql = $"select value(count(c.id)) from c where c.pk='Teacher' and {scSql}";
  676. tTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", tchSql);
  677. scSql = BICommonWay.ManyScSql("REPLACE(c.code, 'Base-', '')", scIds);
  678. //查学生
  679. string stuSql = $"select value(count(c.id)) from c where c.pk='Base' and {scSql}";
  680. tStuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", stuSql);
  681. }
  682. area.tchCnt = tTchCnt;
  683. area.stuCnt = tStuCnt;
  684. }
  685. return Ok(new { state = RespondCode.Ok, areaInfos });
  686. }
  687. /// <summary>
  688. /// 所有活动分析
  689. /// </summary>
  690. /// <param name="jsonElement"></param>
  691. /// <returns></returns>
  692. [HttpPost("get-allanls")]
  693. public async Task<IActionResult> GetAllAnls(JsonElement jsonElement)
  694. {
  695. jsonElement.TryGetProperty("site", out JsonElement site);
  696. var cosmosClient = _azureCosmos.GetCosmosClient();
  697. if ($"{site}".Equals(BIConst.Global))
  698. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  699. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  700. var (weeks, weeke) = TimeHelper.GetStartOrEnd(dateTime, "week");
  701. var (terms, terme) = TimeHelper.GetStartOrEnd(dateTime, "term");
  702. var (months, monthe) = TimeHelper.GetStartOrEnd(dateTime, "month");
  703. int allLess = 0; //所有课例
  704. int weekLess = 0; //本周课例
  705. int termLess = 0; //本学期课例
  706. int monthLessCnt = 0; //本月课例
  707. int actAllCnt = 0; //所有活动
  708. int actWeekCnt = 0; //本周活动
  709. int actTermCnt = 0; //本学期活动
  710. int actMonthCnt = 0; //本月活动
  711. //课例
  712. string allLessSql = $"select value(count(c.id)) from c where c.pk='LessonRecord'";
  713. allLess = await CommonFind.GetSqlValueCount(cosmosClient,"School", allLessSql);
  714. string weekLSql = $"{allLessSql} and c.startTime >= {weeks} and c.startTime <={weeke}";
  715. weekLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", weekLSql);
  716. string termLSql = $"{allLessSql} and c.startTime >= {terms} and c.startTime <={terme}";
  717. termLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", termLSql);
  718. string monthLSql = $"{allLessSql} and c.startTime >= {months} and c.startTime <={monthe}";
  719. monthLessCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", monthLSql);
  720. //活动
  721. actAllCnt = await ActivityWay.GetCnt(cosmosClient);
  722. string weekSql = $"and c.createTime >= {weeks} and c.createTime <={weeke}";
  723. actWeekCnt = await ActivityWay.GetCnt(cosmosClient, condSql: weekSql);
  724. string termSql = $"and c.createTime >= {terms} and c.createTime <={terme}";
  725. actTermCnt = await ActivityWay.GetCnt(cosmosClient, condSql: termSql);
  726. string monthSql = $"and c.createTime >= {months} and c.createTime <={monthe}";
  727. actMonthCnt = await ActivityWay.GetCnt(cosmosClient, condSql: monthSql);
  728. return Ok(new {state = RespondCode.Ok, allLess, weekLess, termLess, monthLessCnt, actAllCnt, actWeekCnt, actTermCnt, actMonthCnt });
  729. }
  730. /// <summary>
  731. /// 依据活动Id查询活动详情信息 数据管理工具——查询工具
  732. /// </summary>
  733. /// <param name="jsonElement"></param>
  734. /// <returns></returns>
  735. [HttpPost("get-info")]
  736. public async Task<IActionResult> GetInfo(JsonElement jsonElement)
  737. {
  738. if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
  739. jsonElement.TryGetProperty("activity", out JsonElement activity);
  740. jsonElement.TryGetProperty("isPersonal", out JsonElement isPersonal);
  741. jsonElement.TryGetProperty("site", out JsonElement site);
  742. //if (jsonElement.TryGetProperty("", out JsonElement code)) return BadRequest();
  743. var cosmosClient = _azureCosmos.GetCosmosClient();
  744. if ($"{site}".Equals(BIConst.Global))
  745. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  746. List<object> infos = new List<object>();
  747. StringBuilder sqlTxt = new StringBuilder($"select * from c where c.id='{id}'");
  748. if (!string.IsNullOrEmpty($"{activity}"))
  749. {
  750. sqlTxt.Append($" and c.pk='{activity}'");
  751. }
  752. if (!string.IsNullOrEmpty($"{isPersonal}"))
  753. {
  754. if (bool.Parse($"{isPersonal}") == true)
  755. {
  756. sqlTxt.Append($" and c.scope='private'");
  757. }
  758. else
  759. {
  760. sqlTxt.Append($" and c.scope='school'");
  761. }
  762. }
  763. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
  764. {
  765. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  766. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  767. {
  768. infos.Add(obj.ToObject<object>());
  769. }
  770. }
  771. return Ok(new { state = 200, infos });
  772. }
  773. /// <summary>
  774. /// 区级信息
  775. /// </summary>
  776. public record AreaInfo
  777. {
  778. public string id { get; set; }
  779. public string name { get; set; }
  780. public string standard { get; set; }
  781. public string standardName { get; set; }
  782. public int scCnt { get; set; } = 0;
  783. public int tchCnt { get; set; } = 0;
  784. public int stuCnt { get; set; } = 0;
  785. }
  786. public class AreaStudy
  787. {
  788. public string id { get; set; }
  789. public string code { get; set; }
  790. /// <summary>
  791. /// 线上观看视频的学时
  792. /// </summary>
  793. public long onlineTime { get; set; }
  794. /// <summary>
  795. /// 线下研修学时
  796. /// </summary>
  797. public long offlineTime { get; set; }
  798. /// <summary>
  799. /// 课堂实录学时
  800. /// </summary>
  801. public long classTime { get; set; }
  802. /// <summary>
  803. /// 必修的
  804. /// </summary>
  805. public Currency currency { get; set; } = new Currency();
  806. }
  807. private class SchoolInfo
  808. {
  809. public string id { get; set; }
  810. public string name { get; set; }
  811. public string picture { get; set; }
  812. //教师人数
  813. public int teacherCount { get; set; }
  814. //学生人数
  815. public long studentCount { get; set; }
  816. //评审人数
  817. public int appraiseCount { get; set; }
  818. //参训人数
  819. public int trainCount { get; set; }
  820. public List<KeyValuePair<object, long>> census { get; set; } = new List<KeyValuePair<object, long>>();
  821. }
  822. private record SchoolLesson
  823. {
  824. public string id { get; set; }
  825. public string name { get; set; }
  826. public string picture { get; set; }
  827. public int count { get; set; }
  828. }
  829. public record ActivityCount
  830. {
  831. public string id { get; set; }
  832. public string name { get; set; }
  833. public List<KeyValuePair<object, long>> census { get; set; } = new List<KeyValuePair<object, long>>();
  834. }
  835. }
  836. }