ActivitySticsController.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. using Microsoft.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").GetItemQueryIteratorSql<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 = '' or IS_DEFINED(c.areaId) = false)";
  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").GetItemQueryStreamIteratorSql(queryText: $"select c.id,c.code,c.totalTime,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.Content);
  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. //学时
  241. totalTime = trains.Select(s => s.totalTime).Sum();
  242. trains.ForEach(x =>
  243. {
  244. //线上研修
  245. if (x.onlineTime == 0) onLineCount++; else if (x.onlineTime >= setting.onlineTime) onLineCount++; else onLineCount++;
  246. //线下研修
  247. if (x.offlineTime == 0) offlineCount++; else if (x.onlineTime >= setting.offlineTime) offlineCount++; else offlineCount++;
  248. //课堂实录
  249. if (x.classTime == 0) classRoomCount++; else if (x.classTime >= setting.classTime) classRoomCount++; else classRoomCount++;
  250. //认证材料
  251. if (x.currency.submitTime == 0) submitCount++; else if (x.currency.submitTime >= setting.submitTime) submitCount++; else submitCount++;
  252. if (x.currency.submitTime == 0 && x.classTime == 0 && x.offlineTime == 0 && x.onlineTime == 0) noCount++;
  253. else if (x.currency.submitTime >= setting.submitTime && x.classTime >= setting.classTime && x.onlineTime >= setting.offlineTime && x.onlineTime >= setting.onlineTime) fulfilCount++;
  254. else carryOnCount++;
  255. });
  256. }
  257. 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 } });
  258. //int countArea = 0;//区级人员
  259. //int appraiseArea = 0;//区级评审人员
  260. //long examAreaCount = 0; //试卷活动
  261. //long surveyAreaCount = 0; //问卷活动
  262. //long voteAreaCount = 0; //投票活动
  263. //long homeworkAreaCount = 0; //作业活动
  264. //int basics = 0; //基础版数
  265. //int standard = 0; //标准版数
  266. //int major = 0; //专业版数
  267. //int geCount = 0; //普教
  268. //int heCount = 0; //高教
  269. //int oeCount = 0; //其他教育
  270. //int dayLess = 0; //当天课例
  271. //double teachCount = 0; //课例教师
  272. //List<RecSchool> schools = new();
  273. //StringBuilder scSqlTxt = new("select c.id,c.name,c.picture,c.size,c.scale,c.type from c");
  274. //if (!string.IsNullOrEmpty($"{areaId}"))
  275. //{
  276. // scSqlTxt.Append($" where c.areaId='{areaId}'");
  277. //}
  278. //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIteratorSql<RecSchool>(queryText: scSqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  279. //{
  280. // schools.Add(item);
  281. //}
  282. //List<SchoolLesson> schoolLessons = new(); //学校课例集合
  283. //List<SchoolInfo> schoolInfos = new();
  284. //List<LessonRecord> records = new();//所有的课程记录
  285. ////List<string> scIds = schools.Select(x => x.id).ToList();
  286. //int totalTime = 0;
  287. //heCount = schools.Select(s => s.type == 2).Count();
  288. //geCount = schools.Select(s => s.type == 1).Count();
  289. //oeCount = schools.Select(s => s.type != 2 && s.type != 1).Count();
  290. //areaSize = schools.Select(s => s.size).Sum();
  291. //foreach (var school in schools)
  292. //{
  293. // int count = 0;
  294. // int appraise = 0;
  295. // await foreach (var info in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIteratorSql<bool>(queryText: $"select value(array_contains(c.permissions,'train-appraise')) from c", requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Teacher-{school.id}") }))
  296. // {
  297. // if (info)
  298. // {
  299. // appraise += 1;
  300. // appraiseArea += 1;
  301. // }
  302. // countArea += 1;
  303. // count += 1;
  304. // }
  305. // //查询学校的总学时
  306. // totalTime += await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", "SELECT value(sum(c.totalTime)) FROM c", $"TeacherTrain-{school.id}");
  307. // //查询学校参训人数
  308. // int tempCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(array_length(c.members)) from c where c.type='yxtrain'", $"GroupList-{school.id}");
  309. // //学校学生人数
  310. // long stuCount = await CommonFind.GetSqlValueCount(cosmosClient, "Student", $"select value(count(c.id)) from c", $"Base-{school.id}");
  311. // //查询是否有服务
  312. // int serCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(array_length(c.service)) from c where c.id='{school.id}'", "ProductSum");
  313. // if (serCount > 0)
  314. // major += 1;
  315. // else if (school.size >= 300 && school.scale >= 500)
  316. // standard += 1;
  317. // else basics += 1;
  318. // string sqlTxtSchool = $"select value(c) from c where c.code='LessonRecord-{school}'";
  319. // await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql<LessonRecord>(queryText: sqlTxtSchool, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{school}") }))
  320. // {
  321. // records.Add(item);
  322. // }
  323. // //课例
  324. // int lessCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(count(c.id)) from c", $"LessonRecord-{school.id}");
  325. // SchoolLesson schoolLesson = new()
  326. // {
  327. // id = school.id,
  328. // name = school.name,
  329. // picture = school.picture,
  330. // count = lessCount
  331. // };
  332. // SchoolInfo schoolInfo = new()
  333. // {
  334. // id = school.id,
  335. // name = school.name,
  336. // picture = school.picture,
  337. // teacherCount = count,
  338. // studentCount = stuCount,
  339. // appraiseCount = appraise,
  340. // trainCount = tempCount
  341. // };
  342. // ActivityCount tempActivity = new() { id = school.id, name = school.name != null ? school.name : school.id };
  343. // foreach (var type in StaticValue.activityTypes)
  344. // {
  345. // long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"select value(COUNT(c.id)) from c where c.pk='{type}' and c.school='{school.id}' ");
  346. // 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}";
  347. // long weekActCount = await CommonFind.GetSqlValueCount(cosmosClient, "Common", weekSql);
  348. // weekActivity += weekActCount;
  349. // 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}";
  350. // long termActCount = await CommonFind.GetSqlValueCount(cosmosClient, "Common", termSql);
  351. // termActivity += termActCount;
  352. // switch (type)
  353. // {
  354. // case "Exam":
  355. // examAreaCount += totals;
  356. // break;
  357. // case "Survey":
  358. // surveyAreaCount += totals;
  359. // break;
  360. // case "Vote":
  361. // voteAreaCount += totals;
  362. // break;
  363. // case "Homework":
  364. // homeworkAreaCount += totals;
  365. // break;
  366. // }
  367. // schoolInfo.census.Add(new KeyValuePair<object, long>(type, totals));
  368. // }
  369. // schoolInfos.Add(schoolInfo);
  370. // schoolLessons.Add(schoolLesson);
  371. //}
  372. //List<string> tecIds = await CommonFind.FindRolesId(cosmosClient, scIds);
  373. ////查询去下面所有学校教师课例
  374. //foreach (var tecId in tecIds)
  375. //{
  376. // string sqlTxt = $"select value(c) from c where c.id='{tecId}'";
  377. // await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIteratorSql<LessonRecord>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord") }))
  378. // {
  379. // records.Add(item);
  380. // }
  381. //}
  382. ////课例统计
  383. //if (records.Count > 0)
  384. //{
  385. // records.ForEach(x => { if (x.startTime >= dayS && x.startTime <= dayE) dayLess += 1; });
  386. // records.ForEach(x => { if (x.startTime >= weekS && x.startTime <= weekE) weekLess += 1; });
  387. // records.ForEach(x => { if (x.startTime >= monthS && x.startTime <= monthE) monthLess += 1; });
  388. // records.ForEach(x => { if (x.startTime >= termS && x.startTime <= termE) termLess += 1; });
  389. // teachCount = records.Where(r => r.tmdid != null).Where((x, i) => records.FindIndex(z => z.tmdid == x.tmdid) == i).ToList().Count;
  390. //}
  391. //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 });
  392. }
  393. /// <summary>
  394. /// 所有区的统计接口 学区情况 //已对接
  395. /// </summary>
  396. /// <returns></returns>
  397. [ProducesDefaultResponseType]
  398. [HttpPost("get-all")]
  399. public async Task<IActionResult> GetAll(JsonElement jsonElement)
  400. {
  401. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  402. var cosmosClient = _azureCosmos.GetCosmosClient();
  403. ////分开部署,就不需要,一站多用时,取消注释
  404. //if ($"{site}".Equals(BIConst.Global))
  405. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  406. var (weekStart, weekEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "week");
  407. var (termStart, termEnd) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "term");
  408. var (monthS, monthE) = TimeHelper.GetStartOrEnd(DateTimeOffset.UtcNow, "month");
  409. int areaCount = 0; //区域数量
  410. int scCount = 0; //学校数量
  411. int tecCount = 0; //教师数量
  412. int stuCount = 0; //学生数量
  413. int allSize = 0; //空间总量
  414. int weekScCnt = 0; //本周学校
  415. int weekTchCnt = 0; //本周教师
  416. int monthScCnt = 0; //本月学校
  417. int monthTchCnt = 0; //本月教师
  418. int heCount = 0;//高教
  419. int geCount = 0;//普教
  420. int oeCount = 0; //其他教育
  421. int allActivity = 0; //活动累计
  422. int weekActivity = 0;//本周活动
  423. int termActivity = 0;//本学期活动
  424. int monthActCnt = 0; //本月活动
  425. int weekLess = 0; //本周课例
  426. int termLess = 0; //本学期课例
  427. int allLess = 0; //所有课例
  428. int monthLesCnt = 0; //本月课例
  429. int resourceCount = 0; //累计资源
  430. int totalTime = 0; //总学时
  431. string commSql = "select value(count(c.id)) from c";
  432. areaCount = await CommonFind.GetSqlValueCount(cosmosClient, "Normal", commSql, "Base-Area");
  433. scCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", commSql, "Base");
  434. tecCount = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", commSql,"Base");
  435. stuCount = await CommonFind.GetSqlValueCount(cosmosClient, "Student", commSql, "Base");
  436. string sizeSql = "select value(sum(c.size)) from c";
  437. allSize = await CommonFind.GetSqlValueCount(cosmosClient, "School", sizeSql, "Base");
  438. weekScCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{commSql} where c.createTime >= {weekStart} and c.createTime <= {weekEnd}", "Base");
  439. monthScCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{commSql} where c.createTime >= {monthS} and c.createTime <= {monthE}", "Base");
  440. weekTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", $"{commSql} where c.createTime >= {weekStart} and c.createTime <= {weekEnd}", "Base");
  441. monthTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", $"{commSql} where c.createTime >= {monthS} and c.createTime <= {monthE}", "Base");
  442. heCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{commSql} where c.type = 1", "Base");
  443. geCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{commSql} where c.type = 2", "Base");
  444. oeCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{commSql} where c.type != 1 and c.type != 2", "Base");
  445. //活动
  446. allActivity = await ActivityWay.GetCnt(cosmosClient);
  447. string weekSql = $"and c.createTime >= {weekStart} and c.createTime <={weekEnd}";
  448. weekActivity = await ActivityWay.GetCnt(cosmosClient, condSql: weekSql);
  449. string termSql = $"and c.createTime >= {termStart} and c.createTime <={termEnd}";
  450. termActivity = await ActivityWay.GetCnt(cosmosClient, condSql: termSql);
  451. string monthActSql = $"and c.createTime >= {monthS} and c.createTime <={monthE}";
  452. monthActCnt = await ActivityWay.GetCnt(cosmosClient, condSql: monthActSql);
  453. //课例
  454. string allLessSql = $"select value(count(c.id)) from c where c.pk='LessonRecord'";
  455. allLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", allLessSql);
  456. string weekLSql = $"{allLessSql} and c.startTime >= {weekStart} and c.startTime <={weekEnd}";
  457. weekLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", weekLSql);
  458. string termLSql = $"{allLessSql} and c.startTime >= {termStart} and c.startTime <={termEnd}";
  459. termLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", termLSql);
  460. string monthLSql = $"{allLessSql} and c.startTime >= {monthS} and c.startTime <={monthE}";
  461. monthLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", monthLSql);
  462. totalTime = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", "select value(sum(c.totalTime)) from c where c.pk='TeacherTrain'");
  463. resourceCount = await CommonFind.GetSqlValueCount(cosmosClient, new List<string>() { "School", "Teacher" }, "select value(count(c.id)) from c where c.pk='Bloblog'");
  464. 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 });
  465. }
  466. /// <summary>
  467. /// 分析所有区的人数和学校 学区情况 //已对接
  468. /// </summary>
  469. /// <param name="jsonElement"></param>
  470. /// <returns></returns>
  471. [ProducesDefaultResponseType]
  472. [HttpPost("get-areasanls")]
  473. public async Task<IActionResult> GetAreasAnls(JsonElement jsonElement)
  474. {
  475. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  476. var cosmosClient = _azureCosmos.GetCosmosClient();
  477. ////分开部署,就不需要,一站多用时,取消注释
  478. //if ($"{site}".Equals(BIConst.Global))
  479. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  480. List<AreaInfo> areaInfos = new();
  481. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryIteratorSql<AreaInfo>(queryText: $"select c.id,c.name,c.standard,c.standardName from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base-Area") }))
  482. {
  483. areaInfos.Add(item);
  484. }
  485. foreach (var area in areaInfos)
  486. {
  487. //string scSql = $"select value(c.id) from c where c.areaId='{area.id}'";
  488. //List<string> scIds = await CommonFind.GetValueSingle(cosmosClient, "School", scSql,"Base");
  489. //allSize += recSchools.Select(s => s.size).Sum();
  490. area.scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c where c.areaId='{area.id}'", "Base");
  491. //area.scCnt = scIds.Count;
  492. //int tTchCnt = 0;
  493. //int tStuCnt = 0;
  494. //if (scIds.Count > 0)
  495. //{
  496. // scSql = BICommonWay.ManyScSql("REPLACE(c.code, 'Teacher-', '')", scIds);
  497. // //查教师
  498. // string tchSql = $"select value(count(c.id)) from c where c.pk='Teacher' and {scSql}";
  499. // tTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", tchSql);
  500. // scSql = BICommonWay.ManyScSql("REPLACE(c.code, 'Base-', '')", scIds);
  501. // //查学生
  502. // string stuSql = $"select value(count(c.id)) from c where c.pk='Base' and {scSql}";
  503. // tStuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", stuSql);
  504. ////}
  505. //area.tchCnt = tTchCnt;
  506. //area.stuCnt = tStuCnt;
  507. }
  508. return Ok(new { state = RespondCode.Ok, areaInfos });
  509. }
  510. /// <summary>
  511. /// 所有活动分析
  512. /// </summary>
  513. /// <param name="jsonElement"></param>
  514. /// <returns></returns>
  515. [ProducesDefaultResponseType]
  516. [HttpPost("get-allanls")]
  517. public async Task<IActionResult> GetAllAnls(JsonElement jsonElement)
  518. {
  519. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  520. var cosmosClient = _azureCosmos.GetCosmosClient();
  521. //if ($"{site}".Equals(BIConst.Global))
  522. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  523. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  524. var (weeks, weeke) = TimeHelper.GetStartOrEnd(dateTime, "week");
  525. var (terms, terme) = TimeHelper.GetStartOrEnd(dateTime, "term");
  526. var (months, monthe) = TimeHelper.GetStartOrEnd(dateTime, "month");
  527. int allLess = 0; //所有课例
  528. int weekLess = 0; //本周课例
  529. int termLess = 0; //本学期课例
  530. int monthLessCnt = 0; //本月课例
  531. int actAllCnt = 0; //所有活动
  532. int actWeekCnt = 0; //本周活动
  533. int actTermCnt = 0; //本学期活动
  534. int actMonthCnt = 0; //本月活动
  535. //课例
  536. string allLessSql = $"select value(count(c.id)) from c where c.pk='LessonRecord'";
  537. allLess = await CommonFind.GetSqlValueCount(cosmosClient,"School", allLessSql);
  538. string weekLSql = $"{allLessSql} and c.startTime >= {weeks} and c.startTime <={weeke}";
  539. weekLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", weekLSql);
  540. string termLSql = $"{allLessSql} and c.startTime >= {terms} and c.startTime <={terme}";
  541. termLess = await CommonFind.GetSqlValueCount(cosmosClient, "School", termLSql);
  542. string monthLSql = $"{allLessSql} and c.startTime >= {months} and c.startTime <={monthe}";
  543. monthLessCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", monthLSql);
  544. //活动
  545. actAllCnt = await ActivityWay.GetCnt(cosmosClient);
  546. string weekSql = $"and c.createTime >= {weeks} and c.createTime <={weeke}";
  547. actWeekCnt = await ActivityWay.GetCnt(cosmosClient, condSql: weekSql);
  548. string termSql = $"and c.createTime >= {terms} and c.createTime <={terme}";
  549. actTermCnt = await ActivityWay.GetCnt(cosmosClient, condSql: termSql);
  550. string monthSql = $"and c.createTime >= {months} and c.createTime <={monthe}";
  551. actMonthCnt = await ActivityWay.GetCnt(cosmosClient, condSql: monthSql);
  552. return Ok(new {state = RespondCode.Ok, allLess, weekLess, termLess, monthLessCnt, actAllCnt, actWeekCnt, actTermCnt, actMonthCnt });
  553. }
  554. /// <summary>
  555. /// 统计活动 传醍摩豆则查询相关的学校活动
  556. /// </summary>
  557. /// <param name="jsonElement"></param>
  558. /// <returns></returns>
  559. [ProducesDefaultResponseType]
  560. [HttpPost("get-count")]
  561. public async Task<IActionResult> GetCount(JsonElement jsonElement)
  562. {
  563. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  564. if (!jsonElement.TryGetProperty("term", out JsonElement term)) return BadRequest();
  565. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  566. long start = 0, end = 0;
  567. if (bool.Parse($"{term}") == true)
  568. {
  569. (start, end) = TimeHelper.GetTermStartOrEnd(DateTime.Now);
  570. }
  571. var cosmosClient = _azureCosmos.GetCosmosClient();
  572. ////分开部署,就不需要,一站多用时,取消注释
  573. //if ($"{site}".Equals(BIConst.Global))
  574. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  575. List<object> activityCount = new List<object>();
  576. if (!string.IsNullOrEmpty($"{tmdId}"))
  577. {
  578. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  579. foreach (var itemId in schoolIds)
  580. {
  581. School school = new();
  582. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("Base"));
  583. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  584. {
  585. using var json = await JsonDocument.ParseAsync(response.Content);
  586. school = json.ToObject<School>();
  587. }
  588. ActivityCount tempCount = new ActivityCount() { id = itemId, name = school.name != null ? school.name : itemId };
  589. foreach (var type in StaticValue.activityTypes)
  590. {
  591. StringBuilder sqlTxt = new StringBuilder($"select value(COUNT(c.id)) from c where c.pk='{type}' and c.school='{itemId}' ");
  592. if (bool.Parse($"{term}") == true)
  593. {
  594. sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
  595. }
  596. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", sqlTxt.ToString());
  597. tempCount.census.Add(new KeyValuePair<object, long>(type, totals));
  598. }
  599. activityCount.Add(tempCount);
  600. }
  601. }
  602. else
  603. {
  604. foreach (var type in StaticValue.activityTypes)
  605. {
  606. StringBuilder sqlTxt = new StringBuilder($"SELECT value(COUNT(c.id)) FROM c where c.pk='{type}' ");
  607. if (bool.Parse($"{term}") == true)
  608. {
  609. sqlTxt.Append($" and c.createTime >= {start} and c.createTime <= {end}");
  610. }
  611. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", sqlTxt.ToString());
  612. activityCount.Add(new KeyValuePair<string, object>(type, totals));
  613. }
  614. }
  615. return Ok(new { state = 200, activityCount });
  616. }
  617. /// <summary>
  618. /// 统计顾问关联的学校活动数量:评测、问卷、投票、作业
  619. /// </summary>
  620. /// <param name="jsonElement"></param>
  621. /// <returns></returns>
  622. [ProducesDefaultResponseType]
  623. [HttpPost("get-assistactivity")]
  624. public async Task<IActionResult> GetAssistSchoolActivity(JsonElement jsonElement)
  625. {
  626. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  627. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  628. var cosmosClient = _azureCosmos.GetCosmosClient();
  629. ////分开部署,就不需要,一站多用时,取消注释
  630. //if ($"{site}".Equals(BIConst.Global))
  631. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  632. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  633. List<ActivityCount> activityCounts = new();
  634. foreach (var itemId in schoolIds)
  635. {
  636. School school = new();
  637. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemId, new PartitionKey("Base"));
  638. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  639. {
  640. using var json = await JsonDocument.ParseAsync(response.Content);
  641. school = json.ToObject<School>();
  642. }
  643. ActivityCount activityCount = new() { id = itemId, name = school.name != null ? school.name : itemId };
  644. foreach (var type in StaticValue.activityTypes)
  645. {
  646. string activitySql = $"SELECT value(count(c.id)) FROM c WHERE c.pk='{type}' AND c.school='{itemId}'";
  647. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", activitySql);
  648. activityCount.census.Add(new KeyValuePair<object, long>(type, totals));
  649. }
  650. activityCounts.Add(activityCount);
  651. }
  652. return Ok(new { state = 200, activityCounts });
  653. }
  654. /// <summary>
  655. /// 统计当前学期的活动,传醍摩豆账户则统计该账户当前学期
  656. /// </summary>
  657. /// <param name="jsonElement"></param>
  658. /// <returns></returns>
  659. [ProducesDefaultResponseType]
  660. [HttpPost("get-termactivity")]
  661. public async Task<IActionResult> GetTermActivity(JsonElement jsonElement)
  662. {
  663. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  664. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  665. var cosmosClient = _azureCosmos.GetCosmosClient();
  666. //if ($"{site}".Equals(BIConst.Global))
  667. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  668. var (start, end) = TimeHelper.GetTermStartOrEnd(DateTime.Now);
  669. if (!string.IsNullOrEmpty($"{tmdId}"))
  670. {
  671. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  672. List<ActivityCount> activityCounts = new();
  673. foreach (var schoolId in schoolIds)
  674. {
  675. School school = new();
  676. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(schoolId, new PartitionKey("Base"));
  677. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  678. {
  679. using var json = await JsonDocument.ParseAsync(response.Content);
  680. school = json.ToObject<School>();
  681. }
  682. ActivityCount activityCount = new() { id = schoolId, name = school.name != null ? school.name : schoolId };
  683. foreach (var type in StaticValue.activityTypes)
  684. {
  685. 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}";
  686. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", activitySql);
  687. activityCount.census.Add(new KeyValuePair<object, long>(type, totals));
  688. }
  689. activityCounts.Add(activityCount);
  690. }
  691. return Ok(new { state = 200, activityCounts });
  692. }
  693. else
  694. {
  695. List<KeyValuePair<string, object>> typeCount = new List<KeyValuePair<string, object>>();
  696. foreach (var type in StaticValue.activityTypes)
  697. {
  698. string querySql = $"SELECT value(COUNT(c.id)) FROM c where c.pk='{type}' and c.createTime >= {start} and c.createTime <= {end}";
  699. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", querySql);
  700. KeyValuePair<string, object> valuePair = new(type, totals);
  701. typeCount.Add(valuePair);
  702. }
  703. return Ok(new { state = 200, typeCount });
  704. }
  705. }
  706. /// <summary>
  707. /// 统计区域的活动
  708. /// </summary>
  709. /// <param name="jsonElement"></param>
  710. /// <returns></returns>
  711. [ProducesDefaultResponseType]
  712. [HttpPost("get-area")]
  713. public async Task<IActionResult> GetAreaActovoty(JsonElement jsonElement)
  714. {
  715. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  716. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  717. var cosmosClient = _azureCosmos.GetCosmosClient();
  718. //if ($"{site}".Equals(BIConst.Global))
  719. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  720. List<RecSchool> schools = new();
  721. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIteratorSql<RecSchool>(queryText: $"select c.id,c.name,c.picture,c.scale from c where c.areaId='{areaId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  722. {
  723. schools.Add(item);
  724. }
  725. long exemAreaCount = 0; //评测活动
  726. long surveyAreaCount = 0; //问卷
  727. long voteAreaCount = 0; //投票
  728. long homeworkAreaCount = 0; //作业活动
  729. List<ActivityCount> activityCount = new();
  730. foreach (var school in schools)
  731. {
  732. ActivityCount tempCount = new() { id = school.id, name = school.name != null ? school.name : school.id };
  733. foreach (var type in StaticValue.activityTypes)
  734. {
  735. StringBuilder sqlTxt = new($"select value(COUNT(c.id)) from c where c.pk='{type}' and c.school='{school.id}' ");
  736. long totals = await CommonFind.GetSqlValueCount(cosmosClient, "Common", sqlTxt.ToString());
  737. switch (type)
  738. {
  739. case "Exam":
  740. exemAreaCount += totals;
  741. break;
  742. case "Survey":
  743. surveyAreaCount += totals;
  744. break;
  745. case "Vote":
  746. voteAreaCount += totals;
  747. break;
  748. case "Homework":
  749. homeworkAreaCount += totals;
  750. break;
  751. }
  752. tempCount.census.Add(new KeyValuePair<object, long>(type, totals));
  753. }
  754. activityCount.Add(tempCount);
  755. }
  756. return Ok(new { state = 200, exemAreaCount, surveyAreaCount, voteAreaCount, homeworkAreaCount, activityCount });
  757. }
  758. /// <summary>
  759. /// 依据活动Id查询活动详情信息 数据管理工具——查询工具
  760. /// </summary>
  761. /// <param name="jsonElement"></param>
  762. /// <returns></returns>
  763. [ProducesDefaultResponseType]
  764. [HttpPost("get-info")]
  765. public async Task<IActionResult> GetInfo(JsonElement jsonElement)
  766. {
  767. if (!jsonElement.TryGetProperty("id", out JsonElement id)) return BadRequest();
  768. jsonElement.TryGetProperty("activity", out JsonElement activity);
  769. jsonElement.TryGetProperty("isPersonal", out JsonElement isPersonal);
  770. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  771. //if (jsonElement.TryGetProperty("", out JsonElement code)) return BadRequest();
  772. var cosmosClient = _azureCosmos.GetCosmosClient();
  773. ////分开部署,就不需要,一站多用时,取消注释
  774. //if ($"{site}".Equals(BIConst.Global))
  775. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  776. List<object> infos = new();
  777. StringBuilder sqlTxt = new($"select * from c where c.id='{id}'");
  778. if (!string.IsNullOrEmpty($"{activity}"))
  779. {
  780. sqlTxt.Append($" and c.pk='{activity}'");
  781. }
  782. if (!string.IsNullOrEmpty($"{isPersonal}"))
  783. {
  784. if (bool.Parse($"{isPersonal}") == true)
  785. {
  786. sqlTxt.Append($" and c.scope='private'");
  787. }
  788. else
  789. {
  790. sqlTxt.Append($" and c.scope='school'");
  791. }
  792. }
  793. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIteratorSql(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { }))
  794. {
  795. using var json = await JsonDocument.ParseAsync(item.Content);
  796. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  797. {
  798. infos.Add(obj.ToObject<object>());
  799. }
  800. }
  801. return Ok(new { state = 200, infos });
  802. }
  803. /// <summary>
  804. /// 区级信息
  805. /// </summary>
  806. public record AreaInfo
  807. {
  808. public string id { get; set; }
  809. public string name { get; set; }
  810. public string standard { get; set; }
  811. public string standardName { get; set; }
  812. public int scCnt { get; set; } = 0;
  813. //public int tchCnt { get; set; } = 0;
  814. //public int stuCnt { get; set; } = 0;
  815. }
  816. private class SchoolInfo
  817. {
  818. public string id { get; set; }
  819. public string name { get; set; }
  820. public string picture { get; set; }
  821. //教师人数
  822. public int teacherCount { get; set; }
  823. //学生人数
  824. public long studentCount { get; set; }
  825. //评审人数
  826. public int appraiseCount { get; set; }
  827. //参训人数
  828. public int trainCount { get; set; }
  829. public List<KeyValuePair<object, long>> census { get; set; } = new List<KeyValuePair<object, long>>();
  830. }
  831. private record SchoolLesson
  832. {
  833. public string id { get; set; }
  834. public string name { get; set; }
  835. public string picture { get; set; }
  836. public int count { get; set; }
  837. }
  838. public record ActivityCount
  839. {
  840. public string id { get; set; }
  841. public string name { get; set; }
  842. public List<KeyValuePair<object, long>> census { get; set; } = new List<KeyValuePair<object, long>>();
  843. }
  844. }
  845. }