OnLineController.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. using Azure.Cosmos;
  2. using Azure.Storage.Blobs;
  3. using Azure.Storage.Blobs.Models;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.AspNetCore.Mvc;
  6. using StackExchange.Redis;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Text.Json;
  13. using System.Threading.Tasks;
  14. using TEAMModelBI.Models.RecordM;
  15. using TEAMModelBI.Tool;
  16. using TEAMModelBI.Tool.Context;
  17. using TEAMModelOS.SDK.DI;
  18. using TEAMModelOS.SDK.Extension;
  19. using TEAMModelOS.SDK.Models;
  20. using TEAMModelOS.SDK.Models.Table;
  21. namespace TEAMModelBI.Controllers.BIHome
  22. {
  23. [Route("online")]
  24. [ApiController]
  25. public class OnLineController : ControllerBase
  26. {
  27. private readonly AzureCosmosFactory _azureCosmos;
  28. private readonly AzureStorageFactory _azureStorage;
  29. private readonly AzureRedisFactory _azureRedis;
  30. public OnLineController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis)
  31. {
  32. _azureCosmos = azureCosmos;
  33. _azureStorage = azureStorage;
  34. _azureRedis = azureRedis;
  35. }
  36. /// <summary>
  37. /// 总数统计
  38. /// </summary>
  39. /// <returns></returns>
  40. [HttpPost("get-count")]
  41. public async Task<IActionResult> GetCount(JsonElement jsonElement)
  42. {
  43. var cosmosClient = _azureCosmos.GetCosmosClient();
  44. var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
  45. var blobClient = _azureStorage.GetBlobContainerClient($"0-public");
  46. jsonElement.TryGetProperty("site", out JsonElement site);
  47. if ($"{site}".Equals(BIConst.GlobalSite))
  48. {
  49. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
  50. table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("IESLogin");
  51. blobClient = _azureStorage.GetBlobContainerClient($"0-public", BIConst.GlobalSite);
  52. }
  53. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  54. string cDay = dateTime.ToString("yyyyMMdd");
  55. var (daySt, dayEt) = TimeHelper.GetStartOrEnd(dateTime); //今天开始时间 13位
  56. var (daySf, dayEf) = TimeHelper.GetStartOrEnd(dateTime, dateLenth: false); //今天开始时间 10位
  57. var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year}-{dateTime.Month}-{dateTime.Day - 1}")); //昨天开始时间
  58. var near7S = dateTime.AddDays(-7).ToUnixTimeMilliseconds(); //前七天的开始时间
  59. var near7E = dateTime.ToUnixTimeMilliseconds(); //当前结束时间
  60. long hour1 = dateTime.AddHours(-1).ToUnixTimeMilliseconds(); //一小时前时间戳
  61. int areaCnt = 0; //学区总数
  62. int scCnt = 0; //学校总数
  63. int tchCnt = 0; //教师总数
  64. int stuCnt = 0; //学生总数
  65. int apiCnt = 0; //当天接口访问总量
  66. int onStuCnt = 0; //学生在线人数
  67. int onTchCnt = 0; //教师在线人数
  68. int todayScCnt = 0; //今日新增学校数
  69. int todayTchCnt = 0; //今日新增教师
  70. int todayStuCnt = 0; //今日新增学生数
  71. string currentSql = "select value(count(c.id)) from c";
  72. areaCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Normal", currentSql, "Base-Area");
  73. scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", currentSql, "Base");
  74. tchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", currentSql, "Base");
  75. stuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", "select value(count(c.id)) from c where c.pk='Base'");
  76. string addSql = $"select value(count(c.id)) from c where c.createTime >={daySt} and c.createTime <= {dayEt}";
  77. todayScCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", addSql, "Base");
  78. todayTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", addSql, "Base");
  79. todayStuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", addSql, "Base");
  80. string onStuSql = $"select value(count(c.id)) from c join t in c.loginInfos where array_length(c.loginInfos) > 0 and t.expire > {hour1}";
  81. onTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", onStuSql, "Base");
  82. onStuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", onStuSql, "Base");
  83. //接口访问量
  84. List<RecCnt> recCnts = new();
  85. await foreach (BlobItem blobItem in blobClient.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"visitCnt/{cDay}"))
  86. {
  87. BlobClient tempBlobClient = blobClient.GetBlobClient(blobItem.Name);
  88. if (await tempBlobClient.ExistsAsync())
  89. {
  90. using (var meomoryStream = new MemoryStream())
  91. {
  92. var response = blobClient.GetBlobClient($"{blobItem.Name}").DownloadTo(meomoryStream);
  93. RecCnt recCnt = Encoding.UTF8.GetString(meomoryStream.ToArray()).ToString().ToObject<RecCnt>();
  94. recCnts.Add(recCnt);
  95. }
  96. }
  97. }
  98. apiCnt = recCnts.Select(x => x.apiCnt.Select(s => s.count).Sum()).Sum();
  99. //List<RecOnLine> recStuOnLines = new();
  100. //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<RecOnLine>(queryText: "select c.id,c.name,c.code,c.loginInfos from c where c.pk='Base' and array_length(c.loginInfos) > 0 ", requestOptions:new QueryRequestOptions() { }))
  101. //{
  102. // recStuOnLines.Add(item);
  103. //}
  104. //List<RecOnLine> recTecOnLines = new();
  105. //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecOnLine>(queryText: "select c.id,c.name,c.code,c.loginInfos from c where array_length(c.loginInfos) > 0 ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  106. //{
  107. // recTecOnLines.Add(item);
  108. //}
  109. ////onStuCnt = (from rs in recStuOnLines from l in rs.loginInfos where l.expire >= hour1 select rs).ToList().Count(); //linq查询 学生在线人数
  110. //onStuCnt = recStuOnLines.Select(rss => new RecOnLine { id = rss.id,code=rss.code, name =rss.name,loginInfos = new List<Teacher.LoginInfo> { rss.loginInfos.Find(f => f.expire >= hour1) } }).Where(w => w.loginInfos.FirstOrDefault() != null).ToList().Count(); //lambda 表达式查询 教师查询人数
  111. ////onTchCnt = (from rs in recTecOnLines from l in rs.loginInfos where l.expire >= hour1 select rs).ToList().Count(); //linq查询 教师查询人数
  112. //onTchCnt = recTecOnLines.Select(rss => new RecOnLine { id = rss.id,code=rss.code, name =rss.name,loginInfos = new List<Teacher.LoginInfo> { rss.loginInfos.Find(f => f.expire >= hour1) } }).Where(w => w.loginInfos.FirstOrDefault() != null).ToList().Count(); //lambda 表达式查询 教师查询人数
  113. return Ok(new { state = 200, areaCnt, scCnt, tchCnt, stuCnt, todayScCnt, todayTchCnt, todayStuCnt, onStuCnt, onTchCnt, apiCnt });
  114. }
  115. /// <summary>
  116. /// 在线人数趋势图
  117. /// </summary>
  118. /// <returns></returns>
  119. [HttpPost("get-trend")]
  120. public async Task<IActionResult> GetTrend(JsonElement jsonElement)
  121. {
  122. var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
  123. var redisClinet = _azureRedis.GetRedisClient(8);
  124. jsonElement.TryGetProperty("site", out JsonElement site);
  125. if ($"{site}".Equals(BIConst.GlobalSite))
  126. {
  127. table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("IESLogin");
  128. redisClinet = _azureRedis.GetRedisClient(dbnum: 8, name: BIConst.GlobalSite);
  129. }
  130. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  131. var (daySt, dayEt) = TimeHelper.GetStartOrEnd(dateTime); //今天开始时间 13位
  132. var (strDaySt, strDayEt) = TimeHelper.GetUnixToDate(daySt, dayEt, "yyyyMMddHH");
  133. var dateDay = dateTime.ToString("yyyyMMdd"); //获取当天的日期
  134. //daySt.ToString("yyyyMMddHH");
  135. Dictionary<long, int> allDays = new(); //所有在线人数
  136. Dictionary<long, int> tchDays = new(); //教师在线人数
  137. Dictionary<long, int> stuDays = new(); //学生在线人数
  138. Dictionary<long, int> tmdDays = new(); //醍摩豆账户学生
  139. SortedSetEntry[] tchDay = redisClinet.SortedSetRangeByScoreWithScores($"Login:IES:teacher:{dateDay}");
  140. if (tchDay.Length > 0)
  141. {
  142. foreach (var item in tchDay)
  143. {
  144. int val = ((int)item.Score);
  145. int key = ((int)item.Element);
  146. var utcTo = new DateTimeOffset(new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, key, 0, 0)).Hour;
  147. //var hour = int.Parse(DateTime.SpecifyKind(Convert.ToDateTime($"{dateTime.Year}/{dateTime.Month}/{ dateTime.Day} {key}:00:00"), DateTimeKind.Utc).ToLocalTime().ToString("HH"));
  148. tchDays.Add(utcTo, val);
  149. if (allDays.ContainsKey(utcTo))
  150. allDays[utcTo] = (allDays[utcTo] + val);
  151. else
  152. allDays.Add(utcTo, val);
  153. }
  154. }
  155. else
  156. {
  157. string tableSqlTch = $"PartitionKey eq 'HourLogin' and RowKey ge '{strDaySt}' and RowKey le '{strDayEt}'";
  158. List<HourLogin> hourLoginsTch = await table.QueryWhereString<HourLogin>(tableSqlTch);
  159. if (hourLoginsTch.Count > 0)
  160. {
  161. foreach (var item in hourLoginsTch)
  162. {
  163. await redisClinet.SortedSetIncrementAsync($"Login:IES:teacher:{dateDay}", $"{item.Hour}", item.Teacher);//存一天24小时
  164. var utcTo = new DateTimeOffset(new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, item.Hour, 0, 0)).Hour;
  165. //var hour = int.Parse(DateTime.SpecifyKind(Convert.ToDateTime($"{dateTime.Year}/{dateTime.Month}/{ dateTime.Day} {item.Hour}:00:00"), DateTimeKind.Utc).ToLocalTime().ToString("HH"));
  166. tchDays.Add(utcTo, item.Teacher);
  167. if (allDays.ContainsKey(utcTo))
  168. allDays[utcTo] = (allDays[utcTo] + item.Teacher);
  169. else
  170. allDays.Add(utcTo, item.Teacher);
  171. }
  172. }
  173. }
  174. SortedSetEntry[] stuDay = redisClinet.SortedSetRangeByScoreWithScores($"Login:IES:student:{dateDay}");
  175. if (stuDay.Length > 0)
  176. {
  177. foreach (var item in stuDay)
  178. {
  179. int val = (int)item.Score;
  180. int key = (int)item.Element;
  181. var utcTo = new DateTimeOffset(new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, key, 0, 0)).Hour;
  182. //var hour = int.Parse(DateTime.SpecifyKind(Convert.ToDateTime($"{dateTime.Year}/{dateTime.Month}/{ dateTime.Day} {key}:00:00"), DateTimeKind.Utc).ToLocalTime().ToString("HH"));
  183. stuDays.Add(utcTo, val);
  184. if (allDays.ContainsKey(utcTo))
  185. allDays[utcTo] = (allDays[utcTo] + val);
  186. else
  187. allDays.Add(utcTo, val);
  188. }
  189. }
  190. else
  191. {
  192. string tableSqlStu = $"PartitionKey eq 'HourLogin' and RowKey ge '{strDaySt}' and RowKey le '{strDayEt}'";
  193. List<HourLogin> hourLoginsStu = await table.QueryWhereString<HourLogin>(tableSqlStu);
  194. //var hourStuCnt = hourLoginsStu.GroupBy(x => x.Hour).Select(k => new { key = int.Parse(k.Key.ToString().Substring(8, 2)), value = k.Count() }).ToList();
  195. if (hourLoginsStu.Count > 0)
  196. {
  197. foreach (var item in hourLoginsStu)
  198. {
  199. await redisClinet.SortedSetIncrementAsync($"Login:IES:student:{dateDay}", $"{item.Hour}", item.Student);//存一天24小时
  200. var utcTo = new DateTimeOffset(new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, item.Hour, 0, 0)).Hour;
  201. //var hour = int.Parse(DateTime.SpecifyKind(Convert.ToDateTime($"{dateTime.Year}/{dateTime.Month}/{ dateTime.Day} {item.Hour}:00:00"), DateTimeKind.Utc).ToLocalTime().ToString("HH"));
  202. stuDays.Add(utcTo, item.Student);
  203. if (allDays.ContainsKey(utcTo))
  204. allDays[utcTo] = (allDays[utcTo] + item.Student);
  205. else
  206. allDays.Add(utcTo, item.Student);
  207. }
  208. }
  209. }
  210. SortedSetEntry[] tmdDay = redisClinet.SortedSetRangeByScoreWithScores($"Login:IES:tmduser:{dateDay}");
  211. if (tmdDay.Length > 0)
  212. {
  213. foreach (var item in stuDay)
  214. {
  215. int val = (int)item.Score;
  216. int key = (int)item.Element;
  217. var utcTo = new DateTimeOffset(new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, key, 00, 00)).Hour;
  218. //var hour = int.Parse(DateTime.SpecifyKind(Convert.ToDateTime($"{dateTime.Year}/{dateTime.Month}/{ dateTime.Day} {key}:00:00"), DateTimeKind.Utc).ToLocalTime().ToString("HH"));
  219. tmdDays.Add(utcTo, val);
  220. if (allDays.ContainsKey(utcTo))
  221. allDays[utcTo] = (allDays[utcTo] + val);
  222. else
  223. allDays.Add(utcTo, val);
  224. }
  225. }
  226. else
  227. {
  228. string tableSqlTmd = $"PartitionKey eq 'HourLogin' and RowKey ge '{strDaySt}' and RowKey le '{strDayEt}'";
  229. List<HourLogin> hourLoginsTmd = await table.QueryWhereString<HourLogin>(tableSqlTmd);
  230. //var hourTmdCnt = hourLoginsTmd.GroupBy(x => x.Hour).Select(k => new { key = int.Parse(k.Key.ToString().Substring(8, 2)), value = k.Count() }).ToList();
  231. if (hourLoginsTmd.Count > 0)
  232. {
  233. foreach (var item in hourLoginsTmd)
  234. {
  235. await redisClinet.SortedSetIncrementAsync($"Login:IES:tmduser:{dateDay}", $"{item.Hour}", item.TmdUser);//存一天24小时
  236. var utcTo = new DateTimeOffset(new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, item.Hour, 00, 00)).Hour;
  237. //var hour = int.Parse(DateTime.SpecifyKind(Convert.ToDateTime($"{dateTime.Year}/{dateTime.Month}/{ dateTime.Day} {item.Hour}:00:00"), DateTimeKind.Utc).ToLocalTime().ToString("HH"));
  238. tmdDays.Add(utcTo, item.TmdUser);
  239. if (allDays.ContainsKey(utcTo))
  240. allDays[utcTo] = (allDays[utcTo] + item.TmdUser);
  241. else
  242. allDays.Add(utcTo, item.TmdUser);
  243. }
  244. }
  245. }
  246. return Ok(new { state = 200,allDays = allDays.OrderBy(o=>o.Key).ToList(), tchDays=tchDays.OrderBy(o => o.Key).ToList(), stuDays= stuDays.OrderBy(o => o.Key).ToList(), tmdDays= tmdDays.OrderBy(o => o.Key).ToList() });
  247. }
  248. /// <summary>
  249. /// 课例趋势图
  250. /// </summary>
  251. /// <returns></returns>
  252. [HttpPost("get-lessontrend")]
  253. public async Task<IActionResult> GetLessonTrend(JsonElement jsonElement)
  254. {
  255. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  256. var cosmosClient = _azureCosmos.GetCosmosClient();
  257. jsonElement.TryGetProperty("site", out JsonElement site);
  258. if ($"{site}".Equals(BIConst.GlobalSite))
  259. {
  260. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
  261. }
  262. int year = dateTime.Year; //当前年
  263. int month = dateTime.Month; //当前月
  264. int day = dateTime.Day; //当天
  265. int hour = int.Parse(DateTime.SpecifyKind(Convert.ToDateTime($"{dateTime.Year}/{dateTime.Month}/{ dateTime.Day} {dateTime.Hour}:00:00"), DateTimeKind.Utc).ToLocalTime().ToString("HH")); //当前小时
  266. var (daySt, dayEt) = TimeHelper.GetStartOrEnd(dateTime); //今天开始时间 13位
  267. var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(DateTimeOffset.Parse($"{dateTime.Year}-{dateTime.Month}-{dateTime.Day - 1}")); //昨天开始时间
  268. Dictionary<int, int> sdOpenLesn = new(); //今日开课
  269. Dictionary<int, int> sdUpdLesn = new(); //今日上传课例
  270. Dictionary<int, int> ydOpenLesn = new(); //昨日开课
  271. Dictionary<int, int> ydUpdLesn = new(); //昨日上传课例
  272. List<RecLesn> sameDayLesn = new(); //今天课例
  273. List<RecLesn> yesterDayLesn = new(); //昨日课例
  274. string lesnSql = $"select c.id,c.name,c.code,c.school,c.scope,c.startTime from c where c.pk='LessonRecord' and c.startTime >={daySt} and c.startTime <= {dayEt}";
  275. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecLesn>(queryText: lesnSql, requestOptions: new QueryRequestOptions() { }))
  276. {
  277. sameDayLesn.Add(item);
  278. }
  279. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecLesn>(queryText: lesnSql, requestOptions: new QueryRequestOptions() { }))
  280. {
  281. sameDayLesn.Add(item);
  282. }
  283. string yesterDayLesnSql = $"select c.id,c.name,c.code,c.school,c.scope,c.startTime from c where c.pk='LessonRecord' and c.startTime >={lastDayS} and c.startTime <= {lastdayE}";
  284. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecLesn>(queryText: yesterDayLesnSql, requestOptions: new QueryRequestOptions() { }))
  285. {
  286. yesterDayLesn.Add(item);
  287. }
  288. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecLesn>(queryText: yesterDayLesnSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("LessonRecord") }))
  289. {
  290. yesterDayLesn.Add(item);
  291. }
  292. for (int i = 0; i < 24; i++)
  293. {
  294. if (hour >= i)
  295. {
  296. DateTimeOffset timeHour = new DateTime(year, month, day, i, 0, 0);
  297. var (hourS, hourE) = TimeHelper.GetStartOrEnd(timeHour, type: "hour");
  298. var openLesn = sameDayLesn.Where(item => item.startTime >= hourS && item.startTime <= hourE && item.upload == 0);
  299. sdOpenLesn.Add(i, openLesn.Count());
  300. var UpdLesn = sameDayLesn.Where(item => item.startTime >= hourS && item.startTime <= hourE && item.upload == 1);
  301. sdUpdLesn.Add(i, openLesn.Count());
  302. }
  303. DateTimeOffset yesterday = new DateTime(year, month, day - 1, i, 0, 0);
  304. var (yHourS, yHourE) = TimeHelper.GetStartOrEnd(yesterday, type: "hour");
  305. var yOpenLesn = yesterDayLesn.Where(item => item.startTime >= yHourS && item.startTime <= yHourE && item.upload == 0).ToList();
  306. ydOpenLesn.Add(i, yOpenLesn.Count);
  307. var yUpdLesn = yesterDayLesn.Where(item => item.startTime >= yHourS && item.startTime <= yHourE && item.upload == 1).ToList();
  308. ydUpdLesn.Add(i, yUpdLesn.Count);
  309. }
  310. return Ok(new { state = 200, sdOpenLesn = sdOpenLesn.ToList(), sdUpdLesn = sdUpdLesn.ToList(), ydOpenLesn = ydOpenLesn.ToList(), ydUpdLesn = ydUpdLesn.ToList() });
  311. }
  312. /// <summary>
  313. /// 版本数量占比
  314. /// </summary>
  315. /// <returns></returns>
  316. [HttpPost("get-edition")]
  317. public async Task<IActionResult> GetEdition(JsonElement jsonElement)
  318. {
  319. var cosmosClient = _azureCosmos.GetCosmosClient();
  320. jsonElement.TryGetProperty("site", out JsonElement site);
  321. if ($"{site}".Equals(BIConst.GlobalSite))
  322. {
  323. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
  324. }
  325. int beCnt = 0; //基础班
  326. int seCnt = 0; //标准版
  327. int peCnt = 0; //专业版
  328. List<RecScEd> scEdCnt = new();
  329. var ScSql = $"select c.id,c.name,c.size,c.scale from c";
  330. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecScEd>(queryText: ScSql, requestOptions:new QueryRequestOptions() { PartitionKey= new PartitionKey("Base")}))
  331. {
  332. scEdCnt.Add(item);
  333. }
  334. scEdCnt.ForEach(async scProCnt =>
  335. {
  336. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(scProCnt.id, new PartitionKey("ProductSum"));
  337. if (response.Status == 200)
  338. {
  339. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  340. SchoolProductSum ScProductSum = json.ToObject<SchoolProductSum>();
  341. //scProCnt.serial = ScProductSum.serial.Count();
  342. //scProCnt.service = ScProductSum.service.Count();
  343. //scProCnt.hard = ScProductSum.hard.Count();
  344. int pSeriCnt = ScProductSum.serial.Count();
  345. int pServCnt = ScProductSum.service.Count();
  346. int pHardCnt = ScProductSum.hard.Count();
  347. scProCnt.serial = pSeriCnt;
  348. scProCnt.service = pServCnt;
  349. scProCnt.hard = pHardCnt;
  350. if (scProCnt.scale >= 500 && (pSeriCnt > 0 || pServCnt > 0 || pHardCnt > 0)) peCnt += 1;
  351. }
  352. if (scProCnt.scale >= 500 && scProCnt.serial == 0 && scProCnt.service == 0 && scProCnt.hard == 0) seCnt += 1;
  353. if (scProCnt.scale == 0) beCnt += 1;
  354. });
  355. return Ok(new { state = 200, beCnt, seCnt, peCnt, scEdCnt });
  356. }
  357. /// <summary>
  358. /// 记录在线人数
  359. /// </summary>
  360. public record RecOnLine
  361. {
  362. public string id { get; set; }
  363. public string name { get; set; }
  364. public string code { get; set; }
  365. public List<Teacher.LoginInfo> loginInfos { get; set; }
  366. }
  367. /// <summary>
  368. /// 记录学校版本信息
  369. /// </summary>
  370. public record RecScEd
  371. {
  372. public string id { get; set; }
  373. public string name { get; set; }
  374. public int size { get; set; }
  375. public int scale { get; set; }
  376. public int serial { get; set; } = 0;//软体
  377. public int service { get; set; } = 0; //服务
  378. public int hard { get; set; } = 0; //硬体
  379. }
  380. /// <summary>
  381. /// 记录课例
  382. /// </summary>
  383. public record RecLesn
  384. {
  385. public string id { get; set; }
  386. public string name { get; set; }
  387. public string code { get; set; }
  388. public string school { get; set; }
  389. public string scope{get;set;}
  390. public long startTime { get; set; }
  391. public int upload { get; set; }
  392. }
  393. }
  394. }