SchoolController.cs 90 KB

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