ActivitySticsController.cs 51 KB

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