ActivitySticsController.cs 49 KB

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