ActivitySticsController.cs 50 KB

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