ActivitySticsController.cs 49 KB

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