SchoolController.cs 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395
  1. using Azure.Cosmos;
  2. using DocumentFormat.OpenXml.Bibliography;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Options;
  6. using NUnit.Framework.Constraints;
  7. using Pipelines.Sockets.Unofficial.Arenas;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Diagnostics;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Text.Json;
  14. using System.Threading.Tasks;
  15. using TEAMModelBI.Models;
  16. using TEAMModelBI.Tool;
  17. using TEAMModelBI.Tool.CosmosBank;
  18. using TEAMModelOS.Models;
  19. using TEAMModelOS.SDK.Context.BI;
  20. using TEAMModelOS.SDK.Context.Constant;
  21. using TEAMModelOS.SDK.DI;
  22. using TEAMModelOS.SDK.Extension;
  23. using TEAMModelOS.SDK.Models;
  24. using TEAMModelOS.SDK.Models.Cosmos.BI;
  25. using TEAMModelOS.SDK.Models.Cosmos.BI.BISchool;
  26. using TEAMModelOS.SDK.Models.Service.BI;
  27. using TEAMModelOS.SDK.Models.Service.BIStatsWay;
  28. using static TEAMModelBI.Controllers.Census.ActivitySticsController;
  29. using static TEAMModelBI.Controllers.Census.SchoolController;
  30. using LessonStats = TEAMModelOS.SDK.Models.Cosmos.BI.LessonStats;
  31. namespace TEAMModelBI.Controllers.Census
  32. {
  33. [Route("school")]
  34. [ApiController]
  35. public class SchoolController : ControllerBase
  36. {
  37. private readonly AzureCosmosFactory _azureCosmos;
  38. private readonly AzureStorageFactory _azureStorage;
  39. private readonly DingDing _dingDing;
  40. private readonly Option _option;
  41. private readonly HttpTrigger _httpTrigger;
  42. public SchoolController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, HttpTrigger httpTrigger)
  43. {
  44. _azureCosmos = azureCosmos;
  45. _azureStorage = azureStorage;
  46. _dingDing = dingDing;
  47. _option = option?.Value;
  48. _httpTrigger = httpTrigger;
  49. }
  50. /// <summary>
  51. /// 统计所有分析:基础、课例、活动、资源
  52. /// </summary>
  53. /// <param name="jsonElement"></param>
  54. /// <returns></returns>
  55. [ProducesDefaultResponseType]
  56. [HttpPost("get-all")]
  57. public async Task<IActionResult> GetAll(JsonElement jsonElement)
  58. {
  59. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  60. var cosmosClient = _azureCosmos.GetCosmosClient();
  61. //////分开部署,就不需要,一站多用时,取消注释
  62. //if ($"{site}".Equals(BIConst.Global))
  63. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  64. long schoolCount = 0; //学校数量
  65. int tecCount = 0; //教师数量
  66. int stuCount = 0; //学生数量
  67. long roomCount = 0; //教室数量
  68. long wisdomRoomCount = 0; //智慧教室数量
  69. long allClassCount = 0; //所有班级
  70. long allLessCount = 0; //所有课例
  71. long lastYearLessCount = 0; //去年课例
  72. long yearLessCount = 0;//今年课例
  73. long lastWeekLessCount = 0; //上周课例
  74. long weekLessCount = 0; //本周课例
  75. long lastTermLessCount = 0; //上学期课例
  76. long termLessCount = 0; //本学期课例
  77. long allActivityCount = 0; //所有活动
  78. long lastActivityCount = 0; //去年活动
  79. long activityCount = 0; //今年活动
  80. long lastWeekActivitCount = 0; //上周活动
  81. long weekActivitCount = 0; //本周活动
  82. long lastTermActivitCount = 0; //上学期活动
  83. long TermActivitCount = 0; //本学期学期活动
  84. long rercCount = 0; //所有资源数量
  85. long weekRercCount = 0; //本周资源数量
  86. long lastWeekRercCount = 0; //上周资源数量
  87. long lastTermRercCount = 0; //上学期资源
  88. long termRercCount = 0; //本学期资源
  89. long lastYearRercCount = 0; //去年资源
  90. long yearRercCount = 0; //去年资源
  91. var (lastYearStart, lastYearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{DateTimeOffset.UtcNow.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
  92. var (yearStart, yearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "year"); //计算今年开始/结束时间
  93. var (lastWeekStart, lastWeekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastweek"); //计算上周开始/结束时间
  94. var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week"); //计算本周开始/结束时间
  95. var (lastTermStart, lastTermEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastterm"); //计算上学期开始/结束时间
  96. var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term"); //计算本学期开始/结束时间
  97. schoolCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(count(c.id)) from c", "Base"); //所有学校数量
  98. tecCount = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", "select value(count(c.id)) from c", "Base"); //所有教师数量
  99. stuCount = await CommonFind.GetSqlValueCount(cosmosClient, "Student", "select value(count(c.id)) from c", "Base"); //所有学生数量
  100. allClassCount = await CommonFind.GetSqlValueCount(cosmosClient, new List<string>() { "School" }, "select count(c.id) totals from c where c.pk = 'Class'"); //所有班级数量
  101. roomCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(count(c.id)) from c where c.pk = 'Room'"); //所有教室数量
  102. wisdomRoomCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(count(c.id)) from c where c.pk = 'Room' and c.serial != null"); //智慧教室数量
  103. List<string> containers = new() { "School", "Teacher" };
  104. string lessSqlTxt = "select value(count(c.id)) from c where c.pk='LessonRecord' and c.startTime>={0} and c.startTime<={1}";
  105. allLessCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, $"select count(c.id) as totals from c where c.pk='LessonRecord'");//所有课例
  106. lastYearLessCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(lessSqlTxt, lastYearStart, lastYearEnd)); //去年课例
  107. yearLessCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(lessSqlTxt, yearStart, yearEnd)); //今年课例
  108. lastWeekLessCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(lessSqlTxt, lastWeekStart, lastWeekEnd)); //上周课例
  109. weekLessCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(lessSqlTxt, weekStart, weekEnd)); //本周课例
  110. lastTermLessCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(lessSqlTxt, lastTermStart, lastTermEnd)); //上学期课例
  111. termLessCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(lessSqlTxt, termStart, termEnd)); //上学期课例
  112. string typeSqlTxt = "select value(count(c.id)) from c where c.pk='{0}' and c.createTime >={1} and c.createTime<= {2}";
  113. foreach (var type in StaticValue.activityTypes)
  114. {
  115. allActivityCount += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"select value(count(c.id)) from c where c.pk='{type}' ");//所有活动
  116. lastActivityCount += await CommonFind.GetSqlValueCount(cosmosClient, "Common", string.Format(typeSqlTxt, type, lastYearStart, lastYearEnd)); //去年活动
  117. activityCount += await CommonFind.GetSqlValueCount(cosmosClient, "Common", string.Format(typeSqlTxt, type, yearStart, yearEnd)); //今年活动
  118. lastWeekActivitCount += await CommonFind.GetSqlValueCount(cosmosClient, "Common", string.Format(typeSqlTxt, type, lastWeekStart, lastWeekEnd)); //上周活动
  119. weekActivitCount += await CommonFind.GetSqlValueCount(cosmosClient, "Common", string.Format(typeSqlTxt, type, weekStart, weekEnd)); //本周活动
  120. lastTermActivitCount += await CommonFind.GetSqlValueCount(cosmosClient, "Common", string.Format(typeSqlTxt, type, lastTermStart, lastTermEnd)); //上学期活动
  121. TermActivitCount += await CommonFind.GetSqlValueCount(cosmosClient, "Common", string.Format(typeSqlTxt, type, termStart, termEnd)); //本学期学期活动
  122. }
  123. string bloblSqlTxt = "select value(count(c.id)) from c where c.pk='Bloblog' and c.time>={0} and c.time<={1}";
  124. rercCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, "select value(count(c.id)) from c where c.pk='Bloblog'"); //所有资源
  125. lastWeekRercCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(bloblSqlTxt, lastWeekStart, lastWeekEnd)); //上周资源
  126. weekRercCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(bloblSqlTxt, weekStart, weekEnd)); //本周资源
  127. lastTermRercCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(bloblSqlTxt, lastTermStart, lastTermEnd)); //上学期资源
  128. termRercCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(bloblSqlTxt, termStart, termEnd)); //这学期资源
  129. lastYearRercCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(bloblSqlTxt, lastYearStart, lastYearEnd)); //去年资源
  130. yearRercCount = await CommonFind.GetSqlValueCount(cosmosClient, containers, string.Format(bloblSqlTxt, yearStart, yearEnd)); //今年资源
  131. return Ok(new { state = 200, schoolCount, tecCount, stuCount, allClassCount, roomCount, wisdomRoomCount, allLessCount, lastYearLessCount, yearLessCount, lastWeekLessCount, weekLessCount, lastTermLessCount, termLessCount, allActivityCount, lastActivityCount, activityCount, lastWeekActivitCount, weekActivitCount, lastTermActivitCount, TermActivitCount, rercCount, lastWeekRercCount, weekRercCount, lastTermRercCount, termRercCount, lastYearRercCount, yearRercCount });
  132. }
  133. /// <summary>
  134. /// 查询顾问相关的学校统计数据
  135. /// </summary>
  136. /// <param name="jsonElement"></param>
  137. /// <returns></returns>
  138. [ProducesDefaultResponseType]
  139. [HttpPost("get-assist")]
  140. public async Task<IActionResult> GetAssistStatis(JsonElement jsonElement)
  141. {
  142. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  143. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  144. int tecCount = 0; //教师数量
  145. int stuCount = 0; //学校数量
  146. int classCount = 0; //班级数量
  147. int roomCount = 0; //智慧教师数量
  148. int allLessonCount = 0; //课例数量
  149. int lastWeekLessCount = 0;// 上周课例数
  150. int weekLessCount = 0; //本周课例
  151. int lastTermLessCount = 0;// 上学期课例数
  152. int termLessCount = 0; //本学期课例
  153. int lastYearLessCount = 0; //去年课例
  154. int yearLessCount = 0; //今年课例
  155. int allBloblog = 0; //学校资源
  156. int lastYearBloblog = 0; //去年学校资源
  157. int yearBloblog = 0; //今年学校资源
  158. long allActivity = 0; //学校所有活动
  159. long lastYearActivity = 0; //去年学校所有活动
  160. long yearActivity = 0; //今年学校所有活动
  161. long lastWeekActivity = 0; //上周学校所有活动
  162. long weekActivity = 0; //本周学校所有活动
  163. var cosmosClient = _azureCosmos.GetCosmosClient();
  164. ////分开部署,就不需要,一站多用时,取消注释
  165. //if ($"{site}".Equals(BIConst.Global))
  166. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  167. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  168. var (lastWeekStart, lastWeekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastweek"); //计算上周开始/结束时间
  169. var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week"); //计算本周开始/结束时间
  170. var (lastTermStart, lastTermEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastterm"); //计算上学期开始/结束时间
  171. var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term"); //计算本学期开始/结束时间
  172. var (lastYearStart, lastYearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{DateTimeOffset.UtcNow.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
  173. var (yearStart, yearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "year"); //计算今年开始/结束时间
  174. string unifySqlTxt = "select value(count(c.id)) from c";
  175. string unifyTimeSql = "select value(count(c.id)) from c where c.startTime>={0} and c.startTime<={1}";
  176. string blobTimeSql = "select value(count(c.id)) from c where c.time>={0} and c.time<={1}";
  177. List<RecSchoolDate> recSchoolDates = new();
  178. foreach (var itemId in schoolIds)
  179. {
  180. School school = new();
  181. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("Base"));
  182. if (response.Status == 200)
  183. {
  184. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  185. school = json.ToObject<School>();
  186. }
  187. tecCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c where ARRAY_CONTAINS(c.roles,'teacher',true) and c.status = 'join'", $"Teacher-{itemId}");
  188. stuCount += await CommonFind.GetSqlValueCount(cosmosClient, "Student", unifySqlTxt, $"Base-{itemId}");
  189. classCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", unifySqlTxt, $"Class-{itemId}");
  190. roomCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", unifySqlTxt, $"Room-{itemId}");
  191. //学校所有课例
  192. int tempLessCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", unifySqlTxt, $"LessonRecord-{itemId}");
  193. lastWeekLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, lastWeekStart, lastWeekEnd), $"LessonRecord-{itemId}");
  194. weekLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, weekStart, weekEnd), $"LessonRecord-{itemId}");
  195. lastTermLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, lastTermStart, lastTermEnd), $"LessonRecord-{itemId}");
  196. termLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, termStart, termEnd), $"LessonRecord-{itemId}");
  197. lastYearLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, lastYearStart, lastYearEnd), $"LessonRecord-{itemId}");
  198. yearLessCount += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(unifyTimeSql, yearStart, yearEnd), $"LessonRecord-{itemId}");
  199. //学校资源
  200. int tempBloblog = await CommonFind.GetSqlValueCount(cosmosClient, "School", unifySqlTxt, $"Bloblog-{itemId}");
  201. lastYearBloblog += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(blobTimeSql, lastYearStart, lastYearEnd), $"Bloblog-{itemId}");
  202. yearBloblog += await CommonFind.GetSqlValueCount(cosmosClient, "School", string.Format(blobTimeSql, yearStart, yearEnd), $"Bloblog-{itemId}");
  203. //学校活动
  204. long tempallActivity = 0;
  205. //统计活动
  206. foreach (var type in StaticValue.activityTypes)
  207. {
  208. string sqlTime = "SELECT value(count(c.id)) FROM c where c.pk = '{0}' and c.school = '{1}' and c.createTime>={2} and c.createTime<={3}";
  209. tempallActivity += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"SELECT value(count(c.id)) FROM c where c.pk = '{type}' and c.school = '{itemId}'");
  210. lastYearActivity += await CommonFind.GetSqlValueCount(cosmosClient, "Common", string.Format(sqlTime, type, itemId, lastYearStart, lastYearEnd));
  211. yearActivity += await CommonFind.GetSqlValueCount(cosmosClient, "Common", string.Format(sqlTime, type, itemId, yearStart, yearEnd));
  212. lastWeekActivity += await CommonFind.GetSqlValueCount(cosmosClient, "Common", string.Format(sqlTime, type, itemId, lastWeekStart, lastWeekEnd));
  213. weekActivity += await CommonFind.GetSqlValueCount(cosmosClient, "Common", string.Format(sqlTime, type, itemId, weekStart, weekEnd));
  214. }
  215. allLessonCount += tempLessCount;
  216. allActivity += tempallActivity;
  217. allBloblog += tempBloblog;
  218. recSchoolDates.Add(new RecSchoolDate() { id = school.id, name = school.name, dataCount = (tempLessCount + tempallActivity + tempBloblog) });
  219. }
  220. return Ok(new { state = 200, schoolCount = schoolIds.Count, tecCount, stuCount, classCount, roomCount, allLessonCount, lastWeekLessCount, weekLessCount, lastTermLessCount, termLessCount, lastYearLessCount, yearLessCount, allBloblog, lastYearBloblog, yearBloblog, allActivity, lastYearActivity, yearActivity, lastWeekActivity, weekActivity, recSchoolDates });
  221. }
  222. /// <summary>
  223. /// 依据学校Id统计学校分析
  224. /// </summary>
  225. /// <param name="jsonElement"></param>
  226. /// <returns></returns>
  227. [ProducesDefaultResponseType]
  228. [HttpPost("get-idstatis")]
  229. public async Task<IActionResult> GetIdStatis(JsonElement jsonElement)
  230. {
  231. if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
  232. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  233. int tecCount = 0; //学校教师数量
  234. int stuCount = 0; //学校学生数量
  235. int classCount = 0; //班级数量
  236. int roomCount = 0; //教室教师数量
  237. long allLessCount = 0; //课例总数
  238. int lastWeekLess = 0; //上周的总数
  239. int weekLess = 0; //本周的总数
  240. int lastTermLess = 0; //上学期的总数
  241. int termLess = 0; //本学期的总数
  242. int lessYearLess = 0; //去年的总数
  243. int yearLess = 0; //去年的总数
  244. int allActivity = 0; //学校所有活动
  245. int lastYearActivity = 0; //去年学校所有活动
  246. int yearActivity = 0; //今年学校所有活动
  247. int lastWeekActivity = 0; //上周学校所有活动
  248. int weekActivity = 0; //本周学校所有活动
  249. int allBlob = 0; //所有资源
  250. int lastYearBlob = 0; //去年的资源
  251. int yearBlob = 0; //去年的资源
  252. var cosmosClient = _azureCosmos.GetCosmosClient();
  253. ////分开部署,就不需要,一站多用时,取消注释
  254. //if ($"{site}".Equals(BIConst.Global))
  255. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  256. var (lastWeekStart, lastWeekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastweek"); //计算上周开始/结束时间
  257. var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week"); //计算本周开始/结束时间
  258. var (lastTermStart, lastTermEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "lastterm"); //计算上学期开始/结束时间
  259. var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term"); //计算本学期开始/结束时间
  260. var (lastYearStart, lastYearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{DateTimeOffset.UtcNow.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
  261. var (yearStart, yearEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "year"); //计算今年开始/结束时间
  262. tecCount = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Teacher-{schoolId}", "SELECT value(count(c.id)) FROM c WHERE ARRAY_CONTAINS(c.roles, 'teacher', true) AND c.status = 'join'");
  263. stuCount = await JointlySingleQuery.GetValueInt(cosmosClient, "Student", $"Base-{schoolId}");
  264. classCount = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Class-{schoolId}");
  265. roomCount = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Room-{schoolId}");
  266. string unifyTimeSql = "select value(count(c.id)) from c where c.startTime>={0} and c.startTime<={1}";
  267. allLessCount = await LessonStatisWay.GetSchoolIdLessonCount(cosmosClient, $"{schoolId}");
  268. lastWeekLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"LessonRecord-{schoolId}", string.Format(unifyTimeSql, lastWeekStart, lastWeekEnd));
  269. weekLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"LessonRecord-{schoolId}", string.Format(unifyTimeSql, weekStart, lastWeekEnd));
  270. lastTermLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"LessonRecord-{schoolId}", string.Format(unifyTimeSql, lastTermStart, lastTermEnd));
  271. termLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"LessonRecord-{schoolId}", string.Format(unifyTimeSql, termStart, termEnd));
  272. lessYearLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"LessonRecord-{schoolId}", string.Format(unifyTimeSql, lastYearStart, lastYearEnd));
  273. yearLess = await JointlySingleQuery.GetValueInt(cosmosClient, "School", string.Format(unifyTimeSql, yearStart, yearEnd), $"LessonRecord-{schoolId}");
  274. //统计活动
  275. foreach (var type in StaticValue.activityTypes)
  276. {
  277. string sqlTime = "select value(count(c.id)) from c where c.pk = '{0}' and c.school = '{1}' and c.createTime>={2} and c.createTime<={3}";
  278. allActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{type}-{schoolId}", $"select value(count(c.id)) from c where c.pk = '{type}' and c.school = '{schoolId}'");
  279. lastYearActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{type}-{schoolId}", string.Format(sqlTime, type, schoolId, lastYearStart, lastYearEnd));
  280. yearActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{type}-{schoolId}", string.Format(sqlTime, type, schoolId, yearStart, yearEnd));
  281. lastWeekActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{type}-{schoolId}", string.Format(sqlTime, type, schoolId, lastWeekStart, lastWeekEnd));
  282. weekActivity += await JointlySingleQuery.GetValueInt(cosmosClient, "Common", $"{type}-{schoolId}", string.Format(sqlTime, type, schoolId, weekStart, weekEnd));
  283. }
  284. //学校资源
  285. string blobTimeSql = "select value(count(c.id)) from c where c.time>={0} and c.time<={1}";
  286. allBlob = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Bloblog-{schoolId}");
  287. lastYearBlob = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Bloblog-{schoolId}", string.Format(blobTimeSql, lastYearStart, lastYearEnd));
  288. yearBlob = await JointlySingleQuery.GetValueInt(cosmosClient, "School", $"Bloblog-{schoolId}", string.Format(blobTimeSql, yearStart, yearEnd));
  289. //获取所有的课程记录
  290. List<LessonRecord> records = new();
  291. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessonRecord>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{schoolId}") }))
  292. {
  293. records.Add(item);
  294. }
  295. List<(string name, int count)> gradeCount = new();
  296. if (records.Count > 0)
  297. {
  298. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{schoolId}", new PartitionKey($"Base"));
  299. School sc = new();
  300. if (response.Status == 200)
  301. {
  302. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  303. sc = json.ToObject<School>();
  304. }
  305. List<string> grades = new();
  306. foreach (var item in records)
  307. {
  308. foreach (string gId in item.grade)
  309. {
  310. if (!grades.Contains(gId))
  311. {
  312. grades.Add(gId);
  313. }
  314. }
  315. }
  316. foreach (var gId in grades)
  317. {
  318. var c = records.Where(r => r.grade.Contains(gId)).Count();
  319. gradeCount.Add((gId, c));
  320. }
  321. }
  322. return Ok(new { state = 200, tecCount, stuCount, classCount, roomCount, allLessCount, lastWeekLess, weekLess, lastTermLess, termLess, lessYearLess, yearLess, allActivity, lastYearActivity, yearActivity, lastWeekActivity, weekActivity, allBlob, lastYearBlob, yearBlob });
  323. }
  324. /// <summary>
  325. /// 未区域学校统计
  326. /// </summary>
  327. /// <param name="jsonElement"></param>
  328. /// <returns></returns>
  329. [ProducesDefaultResponseType]
  330. [HttpPost("get-noarea")]
  331. public async Task<IActionResult> GetNoAreaCnt(JsonElement jsonElement)
  332. {
  333. var cosmosClient = _azureCosmos.GetCosmosClient();
  334. int tLessCnt = 0; //课例
  335. int tActCnt = 0; //活动
  336. List<string> scIds = new(); //学校id集合
  337. string scIdSql = "select value(c.id) from c where c.areaId=null or c.areaId=''";
  338. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scIdSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  339. {
  340. scIds.Add(item);
  341. }
  342. string comSql = BICommonWay.ManyScSql("c.school", scIds);
  343. string lesSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and {comSql}";
  344. tLessCnt = await CommonFind.GetSqlValueCount(cosmosClient, new List<string>() { "School", "Teacher" }, lesSql);
  345. comSql = BICommonWay.ManyScSql(" and c.school", scIds);
  346. tActCnt = await ActivityWay.GetCnt(cosmosClient, condSql: comSql);
  347. return Ok(new { state = 200, scCnt = scIds.Count(), tLessCnt, tActCnt });
  348. }
  349. /// <summary>
  350. /// 未加区的学校统计
  351. /// </summary>
  352. /// <param name="jsonElement"></param>
  353. /// <returns></returns>
  354. [ProducesDefaultResponseType]
  355. [HttpPost("get-noareasc")]
  356. public async Task<IActionResult> GetNoAareaScCnt(JsonElement jsonElement)
  357. {
  358. var cosmosClient = _azureCosmos.GetCosmosClient();
  359. var tableClient = _azureStorage.GetCloudTableClient();
  360. var table = tableClient.GetTableReference("BIDDUserInfo");
  361. var (dayS, dayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow);
  362. var (weekS, weekE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
  363. var (monthS, monthE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "month");
  364. var (termS, termE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");
  365. List<AreaAssist> areaAssists = new(); //顾问信息
  366. int tchCnt = 0; //所有区级老师
  367. int stuCnt = 0; //所有区级学生
  368. int tLessCnt = 0; //课例数量
  369. int tActCnt = 0; //活动数量
  370. HashSet<string> tchIds = new();
  371. List<string> scIds = new(); //学校id集合
  372. string scIdSql = "select value(c.id) from c where c.areaId=null or c.areaId=''";
  373. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scIdSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  374. {
  375. scIds.Add(item);
  376. }
  377. string scsSql = BICommonWay.ManyScSql("c.school", scIds);
  378. string cntSql = $"select value(count(c.id)) from c where {scsSql}";
  379. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<int>(queryText: cntSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  380. {
  381. tchCnt += item;
  382. }
  383. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<int>(queryText: cntSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  384. {
  385. stuCnt += item;
  386. }
  387. foreach (var scId in scIds)
  388. {
  389. string tchIdSql = $"select value(c.id) from c where array_contains(c.roles,'assist',true) and c.pk='Teacher'";
  390. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: tchIdSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{scId}") }))
  391. {
  392. tchIds.Add(item);
  393. }
  394. }
  395. List<string> noIds = new();
  396. foreach (var item in tchIds)
  397. {
  398. List<DingDingUserInfo> ddUsers = await table.QueryWhereString<DingDingUserInfo>($"PartitionKey eq '{_option.Location}' and tmdId eq '{item}'");
  399. if (ddUsers.Count > 0)
  400. {
  401. foreach (var dduser in ddUsers)
  402. {
  403. AreaAssist areaAssist = new()
  404. {
  405. userId = dduser.userId,
  406. unionId = dduser.unionId,
  407. name = dduser.name,
  408. mobile = dduser.mobile,
  409. avatar = dduser.avatar,
  410. tmdId = dduser.tmdId,
  411. tmdName = dduser.tmdName,
  412. tmdMobile = dduser.tmdMobile,
  413. picture = dduser.picture,
  414. roles = dduser.roles,
  415. schoolIds = dduser.schoolIds
  416. };
  417. areaAssists.Add(areaAssist);
  418. }
  419. }
  420. else { noIds.Add(item); }
  421. }
  422. if (scIds.Count > 0)
  423. {
  424. string lesSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and {scsSql}";
  425. tLessCnt = await CommonFind.GetSqlValueCount(cosmosClient, new List<string>() { "School", "Teacher" }, lesSql);
  426. string actComSql = BICommonWay.ManyScSql(" and c.school", scIds);
  427. tActCnt = await ActivityWay.GetCnt(cosmosClient, condSql: actComSql);
  428. }
  429. return Ok(new { state = RespondCode.Ok, scCnt = scIds.Count, tchCnt, stuCnt, allCnt = tLessCnt + tActCnt, tLessCnt, tActCnt });
  430. }
  431. /// <summary>
  432. /// 学校统计
  433. /// 新的数据结构
  434. /// </summary>
  435. /// <param name="jsonElement"></param>
  436. /// <returns></returns>
  437. [ProducesDefaultResponseType]
  438. [HttpPost("get-scstats")]
  439. public async Task<IActionResult> GetSchoolStats(JsonElement jsonElement)
  440. {
  441. if (!jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
  442. var cosmosClient = _azureCosmos.GetCosmosClient();
  443. School school = new();
  444. ScStats scStats = new();
  445. var respSc = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{scId}", new PartitionKey($"Base"));
  446. if (respSc.Status == 200)
  447. {
  448. using var fileJson = await JsonDocument.ParseAsync(respSc.ContentStream);
  449. school = fileJson.ToObject<School>();
  450. }
  451. else
  452. return Ok(new { state = RespondCode.NotFound, msg = $"未找到id:{scId};相关的学校,请检查" });
  453. try
  454. {
  455. bool isExist = true;
  456. StatsInfo statsInfo = new();
  457. var scDataStats = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{DateTimeOffset.UtcNow.Year}-{scId}", new PartitionKey("Statistics"));
  458. if (scDataStats.Status == 200)
  459. {
  460. using var fileJson = await JsonDocument.ParseAsync(scDataStats.ContentStream);
  461. statsInfo = fileJson.ToObject<StatsInfo>();
  462. }
  463. else
  464. {
  465. scStats.id = school.id;
  466. isExist = false;
  467. }
  468. List<LastYearLessAndAct> lastYear = new();
  469. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LastYearLessAndAct>(queryText: $"select c.lesson,c.activity from c where c.id='{DateTimeOffset.UtcNow.Year - 1}-{scId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
  470. {
  471. lastYear.Add(item);
  472. }
  473. bool isnew = false;
  474. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  475. long now = dateTime.ToUnixTimeMilliseconds();
  476. if (!string.IsNullOrEmpty(statsInfo.id))
  477. {
  478. scStats.id = statsInfo.id;
  479. scStats.schoolId = statsInfo.schoolId;
  480. scStats.name = statsInfo.name;
  481. scStats.picture = statsInfo.picture;
  482. scStats.areaId = statsInfo.areaId;
  483. scStats.tch = statsInfo.tch;
  484. scStats.dayTch = statsInfo.dayTch;
  485. scStats.weekTch = statsInfo.weekTch;
  486. scStats.monthTch = statsInfo.monthTch;
  487. scStats.stu = statsInfo.stu;
  488. scStats.dayStu = statsInfo.dayStu;
  489. scStats.weekStu = statsInfo.weekStu;
  490. scStats.monthStu = statsInfo.monthStu;
  491. scStats.room = statsInfo.room;
  492. scStats.witRoom = statsInfo.witRoom;
  493. scStats.size = statsInfo.size;
  494. scStats.scCreateTime = statsInfo.scCreateTime;
  495. scStats.upTime = statsInfo.upTime;
  496. scStats.lessStats.all = statsInfo.lesson.all;
  497. scStats.lessStats.open = statsInfo.lesson.open;
  498. scStats.lessStats.less = statsInfo.lesson.less;
  499. scStats.lessStats.lastDay = statsInfo.lesson.lastDay;
  500. scStats.lessStats.day = statsInfo.lesson.day;
  501. scStats.lessStats.lastWeek = statsInfo.lesson.lastWeek;
  502. scStats.lessStats.week = statsInfo.lesson.week;
  503. scStats.lessStats.lastTerm = statsInfo.lesson.lastTerm;
  504. scStats.lessStats.term = statsInfo.lesson.term;
  505. scStats.lessStats.month = statsInfo.lesson.month;
  506. scStats.lessStats.lastMonth = statsInfo.lesson.lastMonth;
  507. scStats.lessStats.lastDayInter = statsInfo.lesson.lastDayInter;
  508. scStats.lessStats.dayInter = statsInfo.lesson.dayInter;
  509. scStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
  510. scStats.lessStats.monthInter = statsInfo.lesson.monthInter;
  511. scStats.lessStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList()).Sum());
  512. scStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
  513. scStats.lessStats.yearInter = statsInfo.lesson.yearInter;
  514. scStats.lessStats.yearInters = TimeHelper.GetYearMonth(statsInfo.lesson.yearInters, dateTime.Year, dateTime.Month);
  515. scStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
  516. scStats.actStats.all = statsInfo.activity.all;
  517. scStats.actStats.exam = statsInfo.activity.exam;
  518. scStats.actStats.survey = statsInfo.activity.survey;
  519. scStats.actStats.vote = statsInfo.activity.vote;
  520. scStats.actStats.homework = statsInfo.activity.homework;
  521. scStats.actStats.lastDay = statsInfo.activity.lastDay;
  522. scStats.actStats.dayCnt = statsInfo.activity.dayCnt;
  523. scStats.actStats.lastWeek = statsInfo.activity.lastWeek;
  524. scStats.actStats.week = statsInfo.activity.week;
  525. scStats.actStats.lastTerm = statsInfo.activity.lastTerm;
  526. scStats.actStats.term = statsInfo.activity.term;
  527. scStats.actStats.lastMonth = statsInfo.activity.lastMonth;
  528. scStats.actStats.month = statsInfo.activity.month;
  529. scStats.actStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.activity.year).Where(w => w.Count > 0).ToList()).Sum());
  530. scStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
  531. if (statsInfo.study != null)
  532. {
  533. scStats.srStats.learnTime = statsInfo.study.learnTime;
  534. scStats.srStats.online = statsInfo.study.online;
  535. scStats.srStats.offline = statsInfo.study.offline;
  536. scStats.srStats.classRoom = statsInfo.study.classRoom;
  537. scStats.srStats.submit = statsInfo.study.submit;
  538. scStats.srStats.notStarted = statsInfo.study.notStarted;
  539. scStats.srStats.ongoing = statsInfo.study.ongoing;
  540. scStats.srStats.finish = statsInfo.study.finish;
  541. }
  542. }
  543. //if(statsInfo.upTime > 0 && !isnew) {
  544. // long timedis = 20 * 60 * 1000;//20分钟
  545. // if (now - statsInfo.upTime < timedis)
  546. // isnew = true;
  547. //}
  548. //if (statsInfo.upTime == 0 && isnew)
  549. // statsInfo.upTime = now;
  550. //if (statsInfo.upTime == 0 && isnew)
  551. // statsInfo.upTime = DateTimeOffset.UtcNow.Add(new TimeSpan(-1, 0, 0, 0)).ToUnixTimeMilliseconds();
  552. //if (!isnew)
  553. //{
  554. // //Function 处理Function 更新或者新增
  555. // //_ = _httpTrigger.RequestHttpTrigger(new { schoolId = $"{school.id}"}, _option.Location, "stats-sc-info");
  556. // //异步方法处理 同步更新
  557. // statsInfo = await SchoolStatsWay.GetSingleSc(cosmosClient, school.id);
  558. // statsInfo.upTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  559. // if (isExist)
  560. // statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<StatsInfo>(statsInfo, statsInfo.id, new PartitionKey("Stats"));
  561. // else
  562. // statsInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<StatsInfo>(statsInfo, new PartitionKey("Stats"));
  563. //}
  564. return Ok(new { state = RespondCode.Ok, scStats });
  565. }
  566. catch (Exception ex)
  567. {
  568. //await _dingDing.SendBotMsg($"BI,{_option.Location} /school/set-scstats \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  569. return BadRequest();
  570. }
  571. }
  572. /// <summary>
  573. /// 依据身份统计学校
  574. /// 新的数据结构
  575. /// </summary>
  576. /// <param name="jsonElement"></param>
  577. /// <returns></returns>
  578. [ProducesDefaultResponseType]
  579. [HttpPost("get-rolestats")]
  580. public async Task<IActionResult> GetRoleStats(JsonElement jsonElement)
  581. {
  582. //jsonElement.TryGetProperty("areaId", out JsonElement areaId);
  583. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  584. jsonElement.TryGetProperty("role", out JsonElement role);
  585. //if (string.IsNullOrEmpty($"{areaId}") && string.IsNullOrEmpty($"{tmdId}"))
  586. // return Ok(new { stats = RespondCode.ParamsError, msg = "areaId/tmdId两者参数不能都为空!" });
  587. var cosmosClient = _azureCosmos.GetCosmosClient();
  588. Area area = null;
  589. ScStats areaScStats = new();
  590. List<string> scIds = new();
  591. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  592. List<ScStats> scStatss = new();
  593. List<StatsInfo> statsInfos = new();
  594. StringBuilder scSql = new("select value(c.id) from c");
  595. StringBuilder lastScSql = new("select value(c.id) from c");
  596. //if (!string.IsNullOrEmpty($"{areaId}"))
  597. //{
  598. // scSql.Append($" where c.areaId='{areaId}'");
  599. // lastScSql.Append($" where c.areaId='{areaId}'");
  600. // var respSc = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{areaId}", new PartitionKey($"Base-Area"));
  601. // if (respSc.Status == 200)
  602. // {
  603. // using var fileJson = await JsonDocument.ParseAsync(respSc.ContentStream);
  604. // area = fileJson.ToObject<Area>();
  605. // }
  606. // else
  607. // return Ok(new { state = RespondCode.NotFound, msg = $"未找到id:{areaId};相关的学区,请检查!" });
  608. //}
  609. if (!string.IsNullOrEmpty($"{tmdId}"))
  610. {
  611. switch ($"{role}")
  612. {
  613. case "assists":
  614. scSql.Append($" join a in c.assists where a.id='{tmdId}'");
  615. lastScSql.Append($" join a in c.assists where a.id='{tmdId}'");
  616. break;
  617. case "sales":
  618. scSql.Append($" join a in c.sales where a.id='{tmdId}'");
  619. lastScSql.Append($" join a in c.sales where a.id='{tmdId}'");
  620. break;
  621. default:
  622. return Ok(new { state = RespondCode.ParamsError, msg = "role参数错误" });
  623. }
  624. }
  625. scIds = await CommonFind.FindScIds(cosmosClient, scSql.ToString(), "BIRel");
  626. StringBuilder statsSql = new($"select value(c) from c where c.year={dateTime.Year}");
  627. if (scIds.Count > 0)
  628. {
  629. statsSql.Append($" and {BICommonWay.ManyScSql("c.id", scIds, $"{dateTime.Year}-")}");
  630. }
  631. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StatsInfo>(queryText: statsSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
  632. {
  633. statsInfos.Add(item);
  634. }
  635. StringBuilder lastStsSql = new($"select c.lesson,c.activity from c where c.year={dateTime.Year}");
  636. if (scIds.Count > 0)
  637. {
  638. lastStsSql.Append($" and {BICommonWay.ManyScSql("c.id", scIds, $"{DateTimeOffset.UtcNow.Year - 1}-")}");
  639. }
  640. List<LastYearLessAndAct> lastYear = new();
  641. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LastYearLessAndAct>(queryText: lastStsSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
  642. {
  643. lastYear.Add(item);
  644. }
  645. StatsInfo statsInfo = null;
  646. statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos, scIds, area);
  647. if (statsInfo != null)
  648. {
  649. areaScStats.id = statsInfo.id;
  650. areaScStats.schoolId = statsInfo.schoolId;
  651. areaScStats.name = statsInfo.name;
  652. areaScStats.picture = statsInfo.picture;
  653. areaScStats.areaId = statsInfo.areaId;
  654. areaScStats.tch = statsInfo.tch;
  655. areaScStats.dayTch = statsInfo.dayTch;
  656. areaScStats.weekTch = statsInfo.weekTch;
  657. areaScStats.monthTch = statsInfo.monthTch;
  658. areaScStats.stu = statsInfo.stu;
  659. areaScStats.dayStu = statsInfo.dayStu;
  660. areaScStats.weekStu = statsInfo.weekStu;
  661. areaScStats.monthStu = statsInfo.monthStu;
  662. areaScStats.room = statsInfo.room;
  663. areaScStats.witRoom = statsInfo.witRoom;
  664. areaScStats.size = statsInfo.size;
  665. areaScStats.scCreateTime = statsInfo.scCreateTime;
  666. areaScStats.upTime = statsInfo.upTime;
  667. areaScStats.lessStats.open = statsInfo.lesson.all;
  668. areaScStats.lessStats.open = statsInfo.lesson.open;
  669. areaScStats.lessStats.less = statsInfo.lesson.less;
  670. areaScStats.lessStats.lastDay = statsInfo.lesson.lastDay;
  671. areaScStats.lessStats.day = statsInfo.lesson.day;
  672. areaScStats.lessStats.lastWeek = statsInfo.lesson.lastWeek;
  673. areaScStats.lessStats.week = statsInfo.lesson.week;
  674. areaScStats.lessStats.lastTerm = statsInfo.lesson.lastTerm;
  675. areaScStats.lessStats.term = statsInfo.lesson.term;
  676. areaScStats.lessStats.lastDayInter = statsInfo.lesson.lastDayInter;
  677. areaScStats.lessStats.dayInter = statsInfo.lesson.dayInter;
  678. areaScStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
  679. areaScStats.lessStats.monthInter = statsInfo.lesson.monthInter;
  680. areaScStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
  681. areaScStats.lessStats.yearInter = statsInfo.lesson.yearInter;
  682. areaScStats.lessStats.yearInters = TimeHelper.GetYearMonth(statsInfo.lesson.yearInters, dateTime.Year, dateTime.Month);
  683. areaScStats.lessStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList()).Sum());
  684. areaScStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
  685. areaScStats.actStats.all = statsInfo.activity.all;
  686. areaScStats.actStats.exam = statsInfo.activity.exam;
  687. areaScStats.actStats.survey = statsInfo.activity.survey;
  688. areaScStats.actStats.vote = statsInfo.activity.vote;
  689. areaScStats.actStats.homework = statsInfo.activity.homework;
  690. areaScStats.actStats.lastDay = statsInfo.activity.lastDay;
  691. areaScStats.actStats.dayCnt = statsInfo.activity.dayCnt;
  692. areaScStats.actStats.lastWeek = statsInfo.activity.lastWeek;
  693. areaScStats.actStats.week = statsInfo.activity.week;
  694. areaScStats.actStats.lastTerm = statsInfo.activity.lastTerm;
  695. areaScStats.actStats.term = statsInfo.activity.term;
  696. areaScStats.actStats.lastMonth = statsInfo.activity.lastMonth;
  697. areaScStats.actStats.month = statsInfo.activity.month;
  698. areaScStats.actStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.activity.year).Where(w => w.Count > 0).ToList()).Sum());
  699. areaScStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
  700. if (statsInfo.study != null)
  701. {
  702. areaScStats.srStats.learnTime = statsInfo.study.learnTime;
  703. areaScStats.srStats.online = statsInfo.study.online;
  704. areaScStats.srStats.offline = statsInfo.study.offline;
  705. areaScStats.srStats.classRoom = statsInfo.study.classRoom;
  706. areaScStats.srStats.submit = statsInfo.study.submit;
  707. areaScStats.srStats.notStarted = statsInfo.study.notStarted;
  708. areaScStats.srStats.ongoing = statsInfo.study.ongoing;
  709. areaScStats.srStats.finish = statsInfo.study.finish;
  710. }
  711. }
  712. var scInfos = statsInfos.Select(s => new { s.id, s.schoolId, s.name, s.picture, actLess = (s.lesson.all + s.activity.all), actCnt = s.activity.all, lessCnt = s.lesson.all, lessOpen = s.lesson.open, lessUp = s.lesson.less }).ToList();
  713. return Ok(new { state = RespondCode.Ok, areaScStats, scInfos });
  714. }
  715. /// <summary>
  716. /// 依据区级Id统计 新数据结构
  717. /// </summary>
  718. /// <param name="jsonElement"></param>
  719. /// <returns></returns>
  720. [ProducesDefaultResponseType]
  721. [HttpPost("get-areastats")]
  722. public async Task<IActionResult> GetAreaStats(JsonElement jsonElement)
  723. {
  724. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  725. var cosmosClient = _azureCosmos.GetCosmosClient();
  726. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  727. Area area = null;
  728. AreaStats areaScStats = new();
  729. List<string> scIds = new();
  730. List<SchoolInfo> schoolInfos = new();
  731. List<ScStats> scStatss = new();
  732. List<StatsInfo> statsInfos = new();
  733. var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week"); //计算本周开始/结束时间
  734. var (mthS, mthE) = TimeHelper.GetStartOrEnd(dateTime, "month"); //本月开始/结束时间
  735. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolInfo>(queryText: $"select c.id,c.name,c.picture,c.areaId,c.areaName,c.size,c.scale,c.assists,c.sales,c.createDate,c.serial,c.service,c.hard from c where c.areaId='{areaId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("BIRel") }))
  736. {
  737. schoolInfos.Add(item);
  738. }
  739. if (schoolInfos.Count > 0)
  740. scIds = schoolInfos.Select(s => s.id).ToList();
  741. StringBuilder statsSql = new($"select value(c) from c where c.year={dateTime.Year}");
  742. if (scIds.Count > 0)
  743. statsSql.Append($" {BICommonWay.ManyScSql("c.id", scIds, $"{dateTime.Year}-")}");
  744. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StatsInfo>(queryText: statsSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
  745. {
  746. statsInfos.Add(item);
  747. }
  748. StringBuilder lastStsSql = new($"select c.lesson,c.activity from c where c.year={dateTime.Year}");
  749. if (scIds.Count > 0)
  750. {
  751. lastStsSql.Append($" where {BICommonWay.ManyScSql("c.id", scIds, $"{dateTime.Year - 1}-")}");
  752. }
  753. List<LastYearLessAndAct> lastYear = new();
  754. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LastYearLessAndAct>(queryText: lastStsSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
  755. {
  756. lastYear.Add(item);
  757. }
  758. StatsInfo statsInfo = null;
  759. statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos, scIds, area);
  760. if (statsInfo != null)
  761. {
  762. //areaScStats = new
  763. //{
  764. // statsInfo.id,
  765. // statsInfo.schoolId,
  766. // statsInfo.name,
  767. // statsInfo.picture,
  768. // statsInfo.areaId,
  769. // weekSc = schoolInfos.Where(w => w.createDate >= weekS && w.createDate <= weekE).Count(),
  770. // monthSc = schoolInfos.Where(w => w.createDate >= mthS && w.createDate <= mthE).Count(),
  771. // statsInfo.tch,
  772. // statsInfo.dayTch,
  773. // statsInfo.weekTch,
  774. // statsInfo.monthTch,
  775. // statsInfo.stu,
  776. // statsInfo.dayStu,
  777. // statsInfo.weekStu,
  778. // statsInfo.monthStu,
  779. // statsInfo.room,
  780. // statsInfo.witRoom,
  781. // statsInfo.size,
  782. // statsInfo.scCreateTime,
  783. // statsInfo.upTime,
  784. // lessStats = new
  785. // {
  786. // statsInfo.lesson.all,
  787. // statsInfo.lesson.open,
  788. // statsInfo.lesson.less,
  789. // statsInfo.lesson.lastDay,
  790. // statsInfo.lesson.day,
  791. // statsInfo.lesson.lastWeek,
  792. // statsInfo.lesson.week,
  793. // statsInfo.lesson.lastTerm,
  794. // statsInfo.lesson.term,
  795. // statsInfo.lesson.lastDayInter,
  796. // statsInfo.lesson.dayInter,
  797. // statsInfo.lesson.lastMonthInter,
  798. // statsInfo.lesson.monthInter,
  799. // statsInfo.lesson.lastYearInter,
  800. // statsInfo.lesson.yearInter,
  801. // yearInters = TimeHelper.GetYearMonth(statsInfo.lesson.yearInters, dateTime.Year, dateTime.Month),
  802. // lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList()).Sum()),
  803. // year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month)
  804. // },
  805. // actStats = new
  806. // {
  807. // statsInfo.activity.all,
  808. // statsInfo.activity.exam,
  809. // statsInfo.activity.survey,
  810. // statsInfo.activity.vote,
  811. // statsInfo.activity.homework,
  812. // statsInfo.activity.lastDay,
  813. // statsInfo.activity.dayCnt,
  814. // statsInfo.activity.lastWeek,
  815. // statsInfo.activity.week,
  816. // statsInfo.activity.lastTerm,
  817. // statsInfo.activity.term,
  818. // lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.activity.year).Where(w => w.Count > 0).ToList()).Sum()),
  819. // year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month)
  820. // },
  821. // srStats = new
  822. // {
  823. // statsInfo.study.learnTime,
  824. // statsInfo.study.online,
  825. // statsInfo.study.offline,
  826. // statsInfo.study.classRoom,
  827. // statsInfo.study.submit,
  828. // statsInfo.study.notStarted,
  829. // statsInfo.study.ongoing,
  830. // statsInfo.study.finish
  831. // }
  832. //};
  833. areaScStats.id = statsInfo.id;
  834. areaScStats.name = statsInfo.name;
  835. areaScStats.weekSc = schoolInfos.Where(w => w.createDate >= weekS && w.createDate <= weekE).Count();
  836. areaScStats.monthSc = schoolInfos.Where(w => w.createDate >= mthS && w.createDate <= mthE).Count();
  837. areaScStats.tch = statsInfo.tch;
  838. areaScStats.dayTch = statsInfo.dayTch;
  839. areaScStats.weekTch = statsInfo.weekTch;
  840. areaScStats.monthTch = statsInfo.monthTch;
  841. areaScStats.stu = statsInfo.stu;
  842. areaScStats.dayStu = statsInfo.dayStu;
  843. areaScStats.weekStu = statsInfo.weekStu;
  844. areaScStats.monthStu = statsInfo.monthStu;
  845. areaScStats.room = statsInfo.room;
  846. areaScStats.witRoom = statsInfo.witRoom;
  847. areaScStats.size = statsInfo.size;
  848. areaScStats.lessStats.open = statsInfo.lesson.all;
  849. areaScStats.lessStats.open = statsInfo.lesson.open;
  850. areaScStats.lessStats.less = statsInfo.lesson.less;
  851. areaScStats.lessStats.lastDay = statsInfo.lesson.lastDay;
  852. areaScStats.lessStats.day = statsInfo.lesson.day;
  853. areaScStats.lessStats.lastWeek = statsInfo.lesson.lastWeek;
  854. areaScStats.lessStats.week = statsInfo.lesson.week;
  855. areaScStats.lessStats.lastTerm = statsInfo.lesson.lastTerm;
  856. areaScStats.lessStats.term = statsInfo.lesson.term;
  857. areaScStats.lessStats.lastDayInter = statsInfo.lesson.lastDayInter;
  858. areaScStats.lessStats.dayInter = statsInfo.lesson.dayInter;
  859. areaScStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
  860. areaScStats.lessStats.monthInter = statsInfo.lesson.monthInter;
  861. areaScStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
  862. areaScStats.lessStats.yearInter = statsInfo.lesson.yearInter;
  863. areaScStats.lessStats.yearInters = TimeHelper.GetYearMonth(statsInfo.lesson.yearInters, dateTime.Year, dateTime.Month);
  864. areaScStats.lessStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList()).Sum());
  865. areaScStats.lessStats.year = TimeHelper.GetYearMonth(statsInfo.lesson.year, dateTime.Year, dateTime.Month);
  866. areaScStats.actStats.all = statsInfo.activity.all;
  867. areaScStats.actStats.exam = statsInfo.activity.exam;
  868. areaScStats.actStats.survey = statsInfo.activity.survey;
  869. areaScStats.actStats.vote = statsInfo.activity.vote;
  870. areaScStats.actStats.homework = statsInfo.activity.homework;
  871. areaScStats.actStats.lastDay = statsInfo.activity.lastDay;
  872. areaScStats.actStats.dayCnt = statsInfo.activity.dayCnt;
  873. areaScStats.actStats.lastWeek = statsInfo.activity.lastWeek;
  874. areaScStats.actStats.week = statsInfo.activity.week;
  875. areaScStats.actStats.lastTerm = statsInfo.activity.lastTerm;
  876. areaScStats.actStats.term = statsInfo.activity.term;
  877. areaScStats.actStats.lastMonth = statsInfo.activity.lastMonth;
  878. areaScStats.actStats.month = statsInfo.activity.month;
  879. areaScStats.actStats.lastYear = ((int)BICommonWay.ManyDoubleMerge(lastYear.Select(s => s.activity.year).Where(w => w.Count > 0).ToList()).Sum());
  880. areaScStats.actStats.year = TimeHelper.GetYearMonth(statsInfo.activity.year, dateTime.Year, dateTime.Month);
  881. if (statsInfo.study != null)
  882. {
  883. areaScStats.srStats.learnTime = statsInfo.study.learnTime;
  884. areaScStats.srStats.online = statsInfo.study.online;
  885. areaScStats.srStats.offline = statsInfo.study.offline;
  886. areaScStats.srStats.classRoom = statsInfo.study.classRoom;
  887. areaScStats.srStats.submit = statsInfo.study.submit;
  888. areaScStats.srStats.notStarted = statsInfo.study.notStarted;
  889. areaScStats.srStats.ongoing = statsInfo.study.ongoing;
  890. areaScStats.srStats.finish = statsInfo.study.finish;
  891. }
  892. }
  893. List<double> weekLess = BICommonWay.weekDoubleMerge(statsInfos.Select(s => s.lesson.year).Where(w => w.Count > 0).ToList(), dateTime);
  894. schoolInfos.ForEach(fe =>
  895. {
  896. var tempSts = statsInfos.Find(f => f.schoolId.Equals(fe.id));
  897. if (tempSts != null)
  898. {
  899. fe.less = tempSts.lesson.all;
  900. fe.lastWeekLess = tempSts.lesson.lastWeek;
  901. fe.monthLess = tempSts.lesson.month;
  902. }
  903. });
  904. List<IdInfo> assits = new();
  905. schoolInfos.ForEach(fe => assits.AddRange(fe.assists));
  906. List<IdInfo> saless = new();
  907. schoolInfos.ForEach(fe => saless.AddRange(fe.sales));
  908. return Ok(new { state = RespondCode.Ok, areaScStats, schoolInfos, weekLess, assists = assits.Where((w, i) => assits.FindIndex(s => s.id.Equals(w.id)) == i).ToList(), saless = saless.Where((w, i) => saless.FindIndex(f => f.id.Equals(w.id)) == i).ToList() });
  909. }
  910. /// <summary>
  911. /// 学校信息中间件查询接口
  912. /// </summary>
  913. /// <param name="jsonElement"></param>
  914. /// <returns></returns>
  915. [ProducesDefaultResponseType]
  916. [HttpPost("get-scinfos")]
  917. public async Task<IActionResult> GetScInfos(JsonElement jsonElement)
  918. {
  919. var cosmosClient = _azureCosmos.GetCosmosClient();
  920. jsonElement.TryGetProperty("role", out JsonElement role);
  921. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  922. jsonElement.TryGetProperty("areaId", out JsonElement areaId);
  923. StringBuilder sql = new($"select value(c) from c");
  924. if (!string.IsNullOrEmpty($"{role}") && !string.IsNullOrEmpty($"{tmdId}") && string.IsNullOrEmpty($"{areaId}"))
  925. {
  926. switch ($"{role}")
  927. {
  928. case "assist":
  929. sql.Append($" join a in c.assist where a.id='{tmdId}'");
  930. break;
  931. case "sales":
  932. sql.Append($" join a in c.sales where a.id='{tmdId}'");
  933. break;
  934. }
  935. }
  936. if (!string.IsNullOrEmpty($"{areaId}") && !string.IsNullOrEmpty($"{role}"))
  937. {
  938. sql.Append($" where c.areaId ='{areaId}'");
  939. }
  940. //List<string> scId = await CommonFind.FindScIds(cosmosClient, "select value(c.id) from c ", "Base");
  941. List<BIRelation> scInfos = new();
  942. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<BIRelation>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("BIRel") }))
  943. {
  944. scInfos.Add(item);
  945. }
  946. return Ok(new { state = RespondCode.Ok, allCnt = scInfos.Count, scInfos });
  947. }
  948. [ProducesDefaultResponseType]
  949. [HttpPost("get-allscstats")]
  950. public async Task<IActionResult> GetAllAreaStats(JsonElement jsonElement)
  951. {
  952. var cosmosClient = _azureCosmos.GetCosmosClient();
  953. AllScStats allScStats = new();
  954. List<StatsInfo> statsInfos = new();
  955. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  956. var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1)); //昨天开始时间
  957. var (dayS, dayE) = TimeHelper.GetStartOrEnd(dateTime); //今天开始时间
  958. var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dateTime, "lastweek"); //计算上周开始/结束时间
  959. var (weekS, weekE) = TimeHelper.GetStartOrEnd(dateTime, "week"); //计算本周开始/结束时间
  960. var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dateTime, "lastterm"); //计算上学期开始/结束时间
  961. var (termS, termE) = TimeHelper.GetStartOrEnd(dateTime, "term"); //计算本学期开始/结束时间
  962. var (lastMthS, LastmthE) = TimeHelper.GetStartOrEnd(dateTime, "lastMonth"); //上月开始/结束时间
  963. var (mthS, mthE) = TimeHelper.GetStartOrEnd(dateTime, "month"); //本月开始/结束时间
  964. var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year - 1}-1-1"), "year"); //计算去年开始/结束时间
  965. var (yearS, yearE) = TimeHelper.GetStartOrEnd(dateTime, "year"); //计算今年开始/结束时间
  966. string sql = "select value(count(c.id)) from c ";
  967. int areaCnt = await JointlySingleQuery.GetValueInt(cosmosClient, "Normal", "Base-Area", sql);
  968. int scCnt = await JointlySingleQuery.GetValueInt(cosmosClient, "Normal", "Base", sql);
  969. int scWeekCnt = await JointlySingleQuery.GetValueInt(cosmosClient, "Normal", "Base", $"{sql} where c.createTime >= {weekS} and c.createTime <= {weekE}");
  970. int scMonthCnt = await JointlySingleQuery.GetValueInt(cosmosClient, "Normal", "Base", $"{sql} where c.createTime >= {mthS} and c.createTime <= {mthE}");
  971. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<StatsInfo>(queryText: $"select value(c) from c where c.year={dateTime.Year}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Statistics") }))
  972. {
  973. statsInfos.Add(item);
  974. }
  975. var areaGroup = statsInfos.GroupBy(g => g.areaId).ToList().Select(s => s.Where(w => w.areaId.Equals(s.Key)));
  976. StatsInfo statsInfo = null;
  977. statsInfo = SchoolStatsWay.GetAreaStats(cosmosClient, _httpTrigger, _option, statsInfos);
  978. if (statsInfo != null)
  979. {
  980. allScStats.areaCnt = areaCnt;
  981. allScStats.sc = scCnt;
  982. allScStats.weekSc = scWeekCnt;
  983. allScStats.monthSc = scMonthCnt;
  984. allScStats.tch = statsInfo.tch;
  985. allScStats.dayTch = statsInfo.dayTch;
  986. allScStats.weekTch = statsInfo.weekTch;
  987. allScStats.monthTch = statsInfo.monthTch;
  988. allScStats.stu = statsInfo.stu;
  989. allScStats.dayStu = statsInfo.dayStu;
  990. allScStats.weekStu = statsInfo.weekStu;
  991. allScStats.monthStu = statsInfo.monthStu;
  992. allScStats.room = statsInfo.room;
  993. allScStats.witRoom = statsInfo.witRoom;
  994. allScStats.size = statsInfo.size;
  995. allScStats.scCreateTime = statsInfo.scCreateTime;
  996. allScStats.upTime = statsInfo.upTime;
  997. allScStats.lessStats.open = statsInfo.lesson.all;
  998. allScStats.lessStats.open = statsInfo.lesson.open;
  999. allScStats.lessStats.less = statsInfo.lesson.less;
  1000. allScStats.lessStats.lastDay = statsInfo.lesson.lastDay;
  1001. allScStats.lessStats.day = statsInfo.lesson.day;
  1002. allScStats.lessStats.lastWeek = statsInfo.lesson.lastWeek;
  1003. allScStats.lessStats.week = statsInfo.lesson.week;
  1004. allScStats.lessStats.lastTerm = statsInfo.lesson.lastTerm;
  1005. allScStats.lessStats.term = statsInfo.lesson.term;
  1006. allScStats.lessStats.lastDayInter = statsInfo.lesson.lastDayInter;
  1007. allScStats.lessStats.dayInter = statsInfo.lesson.dayInter;
  1008. allScStats.lessStats.lastMonthInter = statsInfo.lesson.lastMonthInter;
  1009. allScStats.lessStats.monthInter = statsInfo.lesson.monthInter;
  1010. allScStats.lessStats.lastYearInter = statsInfo.lesson.lastYearInter;
  1011. allScStats.lessStats.yearInter = statsInfo.lesson.yearInter;
  1012. allScStats.actStats.all = statsInfo.activity.all;
  1013. allScStats.actStats.exam = statsInfo.activity.exam;
  1014. allScStats.actStats.survey = statsInfo.activity.survey;
  1015. allScStats.actStats.vote = statsInfo.activity.vote;
  1016. allScStats.actStats.homework = statsInfo.activity.homework;
  1017. allScStats.actStats.lastDay = statsInfo.activity.lastDay;
  1018. allScStats.actStats.dayCnt = statsInfo.activity.dayCnt;
  1019. allScStats.actStats.lastWeek = statsInfo.activity.lastWeek;
  1020. allScStats.actStats.week = statsInfo.activity.week;
  1021. allScStats.actStats.lastTerm = statsInfo.activity.lastTerm;
  1022. allScStats.actStats.term = statsInfo.activity.term;
  1023. allScStats.actStats.lastMonth = statsInfo.activity.lastMonth;
  1024. allScStats.actStats.month = statsInfo.activity.month;
  1025. if (statsInfo.study != null)
  1026. {
  1027. allScStats.srStats.learnTime = statsInfo.study.learnTime;
  1028. allScStats.srStats.online = statsInfo.study.online;
  1029. allScStats.srStats.offline = statsInfo.study.offline;
  1030. allScStats.srStats.classRoom = statsInfo.study.classRoom;
  1031. allScStats.srStats.submit = statsInfo.study.submit;
  1032. allScStats.srStats.notStarted = statsInfo.study.notStarted;
  1033. allScStats.srStats.ongoing = statsInfo.study.ongoing;
  1034. allScStats.srStats.finish = statsInfo.study.finish;
  1035. }
  1036. }
  1037. return Ok(new { state = RespondCode.Ok, allScStats });
  1038. }
  1039. /// <summary>
  1040. /// 依据Id查询School容器 数据管理工具——查询工具
  1041. /// </summary>
  1042. /// <param name="jsonElement"></param>
  1043. /// <returns></returns>
  1044. [ProducesDefaultResponseType]
  1045. [HttpPost("get-info")]
  1046. public async Task<IActionResult> GetSchool(JsonElement jsonElement)
  1047. {
  1048. if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
  1049. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  1050. var cosmosClient = _azureCosmos.GetCosmosClient();
  1051. //if ($"{site}".Equals(BIConst.Global))
  1052. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1053. List<object> infos = new List<object>();
  1054. string sqlTxt = $"select value(c) from c where c.id='{id}'";
  1055. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { }))
  1056. {
  1057. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  1058. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  1059. {
  1060. infos.Add(obj.ToObject<object>());
  1061. }
  1062. }
  1063. return Ok(new { state = 200, infos });
  1064. }
  1065. public record RecSchoolDate
  1066. {
  1067. public string id { get; set; }
  1068. public string name { get; set; }
  1069. public long dataCount { get; set; }
  1070. }
  1071. /// <summary>
  1072. /// 学校列表信息
  1073. /// </summary>
  1074. public record SchoolInfo
  1075. {
  1076. public string id { get; set; }
  1077. public string name { get; set; }
  1078. public string picture { get; set; }
  1079. public string areaId { get; set; }
  1080. public string areaName { get; set; }
  1081. public int size { get; set; }
  1082. public int scale { get; set; }
  1083. public long createDate { get; set; }
  1084. public List<IdInfo> assists { get; set; } = new List<IdInfo>();
  1085. public List<IdInfo> sales { get; set; } = new List<IdInfo>();
  1086. public List<string> serial { get; set; } = new List<string>();
  1087. public List<string> service { get; set; } = new List<string>();
  1088. public List<string> hard { get; set; } = new List<string>();
  1089. public int less { get; set; }
  1090. public int lastWeekLess { get; set; }
  1091. public int monthLess { get; set; }
  1092. }
  1093. /// <summary>
  1094. /// 区级信息
  1095. /// </summary>
  1096. public record AreaStats
  1097. {
  1098. public string id { get; set; }
  1099. public string name { get; set; }
  1100. public int weekSc { get; set; }
  1101. public int monthSc{ get; set; }
  1102. public int tch { get; set; }
  1103. public int dayTch { get; set; }
  1104. public int weekTch { get; set; }
  1105. public int monthTch { get; set; }
  1106. public int room { get; set; }
  1107. public int witRoom { get; set; }
  1108. public int size { get; set; }
  1109. public int stu { get; set; }
  1110. public int dayStu { get; set; }
  1111. public int weekStu { get; set; }
  1112. public int monthStu { get; set; }
  1113. public ManyLessStats lessStats { get; set; } = new ManyLessStats();
  1114. public ManyScActStats actStats { get; set; } = new ManyScActStats();
  1115. public ScSRStats srStats { get; set; } = new ScSRStats();
  1116. }
  1117. /// <summary>
  1118. /// 前端显示学校统计数据
  1119. /// </summary>
  1120. public record ScStats
  1121. {
  1122. public string id { get; set; }
  1123. public string schoolId { get; set; }
  1124. public string name { get; set; }
  1125. public string picture { get; set; }
  1126. public string areaId { get; set; }
  1127. public int tch { get; set; }
  1128. public int dayTch { get; set; }
  1129. public int weekTch { get; set; }
  1130. public int monthTch { get; set; }
  1131. public int stu { get; set; }
  1132. public int dayStu { get; set; }
  1133. public int weekStu { get; set; }
  1134. public int monthStu { get; set; }
  1135. public int room { get; set; }
  1136. public int witRoom { get; set; }
  1137. public int size { get; set; }
  1138. public long scCreateTime { get; set; }
  1139. public long upTime { get; set; }
  1140. public ManyLessStats lessStats { get; set; } = new ManyLessStats();
  1141. public ManyScActStats actStats { get; set; } = new ManyScActStats();
  1142. public ScSRStats srStats { get; set; } = new ScSRStats();
  1143. }
  1144. /// <summary>
  1145. /// 所有
  1146. /// </summary>
  1147. public record AllScStats
  1148. {
  1149. public int areaCnt { get; set; }
  1150. public int sc { get; set; }
  1151. public int weekSc { get; set; }
  1152. public int monthSc { get; set; }
  1153. public int tch { get; set; }
  1154. public int dayTch { get; set; }
  1155. public int weekTch { get; set; }
  1156. public int monthTch { get; set; }
  1157. public int stu { get; set; }
  1158. public int dayStu { get; set; }
  1159. public int weekStu { get; set; }
  1160. public int monthStu { get; set; }
  1161. public int room { get; set; }
  1162. public int witRoom { get; set; }
  1163. public int size { get; set; }
  1164. public long scCreateTime { get; set; }
  1165. public long upTime { get; set; }
  1166. public ScLessStats lessStats { get; set; } = new ScLessStats();
  1167. public ScActStats actStats { get; set; } = new ScActStats();
  1168. public ScSRStats srStats { get; set; } = new ScSRStats();
  1169. }
  1170. /// <summary>
  1171. /// 课例活动数据
  1172. /// </summary>
  1173. public record ScLessStats
  1174. {
  1175. public int all { get; set; }
  1176. public int open { get; set; }
  1177. public int less { get; set; }
  1178. public int lastDay { get; set; }
  1179. public int day { get; set; }
  1180. public int lastWeek { get; set; }
  1181. public int week { get; set; }
  1182. public int lastTerm { get; set; }
  1183. public int term { get; set; }
  1184. public int month { get; set; }
  1185. public int lastMonth { get; set; }
  1186. public int lastDayInter { get; set; }
  1187. public int dayInter { get; set; }
  1188. public int lastMonthInter { get; set; }
  1189. public int monthInter { get; set; }
  1190. public int lastYearInter { get; set; }
  1191. public int yearInter { get; set; }
  1192. }
  1193. /// <summary>
  1194. /// 课例活动数据
  1195. /// </summary>
  1196. public record ManyLessStats : ScLessStats
  1197. {
  1198. public int lastYear { get; set; }
  1199. public List<YearMonth> yearInters { get; set; } = new List<YearMonth>();//12个月
  1200. public List<YearMonth> year { get; set; } = new List<YearMonth>(); //12个月
  1201. }
  1202. public record ScActStats
  1203. {
  1204. public int all { get; set; }
  1205. public int exam { get; set; }
  1206. public int survey { get; set; }
  1207. public int vote { get; set; }
  1208. public int homework { get; set; }
  1209. public int lastDay { get; set; }
  1210. public int dayCnt { get; set; }
  1211. public int lastWeek { get; set; }
  1212. public int week { get; set; }
  1213. public int lastTerm { get; set; }
  1214. public int term { get; set; }
  1215. public int lastMonth { get; set; }
  1216. public int month { get; set; }
  1217. }
  1218. /// <summary>
  1219. /// 学校活动数据
  1220. /// </summary>
  1221. public record ManyScActStats : ScActStats
  1222. {
  1223. public int lastYear { get; set; }
  1224. public List<YearMonth> year { get; set; } = new List<YearMonth>(); //12个月
  1225. }
  1226. /// <summary>
  1227. /// 研修统计数据
  1228. /// </summary>
  1229. public record ScSRStats
  1230. {
  1231. public int learnTime { get; set; }
  1232. public int online { get; set; }
  1233. public int offline { get; set; }
  1234. public int classRoom { get; set; }
  1235. public int submit { get; set; }
  1236. public int notStarted { get; set; }
  1237. public int ongoing { get; set; }
  1238. public int finish { get; set; }
  1239. }
  1240. /// <summary>
  1241. /// 查询去年的统计
  1242. /// </summary>
  1243. public record LastYearLessAndAct
  1244. {
  1245. /// <summary>
  1246. /// 课例活动
  1247. /// </summary>
  1248. public LessonStats lesson { get; set; } = new LessonStats();
  1249. /// <summary>
  1250. /// 活动
  1251. /// </summary>
  1252. public ActivityStats activity { get; set; } = new ActivityStats();
  1253. }
  1254. }
  1255. }