ActivitySticsController.cs 51 KB

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