OnLineController.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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.Global))
  48. {
  49. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  50. table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("IESLogin");
  51. blobClient = _azureStorage.GetBlobContainerClient($"0-public", BIConst.Global);
  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(dateTime.AddDays(-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} and c.pk='Base'";
  81. onTchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Teacher", onStuSql);
  82. onStuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", onStuSql);
  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.Global))
  126. {
  127. table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("IESLogin");
  128. redisClinet = _azureRedis.GetRedisClient(dbnum: 8, name: BIConst.Global);
  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(key, val);
  149. if (allDays.ContainsKey(key))
  150. allDays[key] = (allDays[key] + val);
  151. else
  152. allDays.Add(key, 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(item.Hour, item.Teacher);
  167. if (allDays.ContainsKey(item.Hour))
  168. allDays[item.Hour] = (allDays[item.Hour] + item.Teacher);
  169. else
  170. allDays.Add(item.Hour, 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(key, val);
  184. if (allDays.ContainsKey(key))
  185. allDays[key] = (allDays[key] + val);
  186. else
  187. allDays.Add(key, 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(item.Hour, item.Student);
  203. if (allDays.ContainsKey(item.Hour))
  204. allDays[item.Hour] = (allDays[item.Hour] + item.Student);
  205. else
  206. allDays.Add(item.Hour, 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 tmdDay)
  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(key, val);
  220. if (allDays.ContainsKey(key))
  221. allDays[key] = (allDays[key] + val);
  222. else
  223. allDays.Add(key, 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.Global))
  259. {
  260. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  261. }
  262. int year = dateTime.Year; //当前年
  263. int month = dateTime.Month; //当前月
  264. int day = dateTime.Day; //当天
  265. var lestDate = dateTime.AddDays(-1); //昨天
  266. int hour = int.Parse(DateTime.SpecifyKind(Convert.ToDateTime($"{dateTime.Year}/{dateTime.Month}/{ dateTime.Day} {dateTime.Hour}:00:00"), DateTimeKind.Utc).ToLocalTime().ToString("HH")); //当前小时
  267. var (daySt, dayEt) = TimeHelper.GetStartOrEnd(dateTime); //今天开始时间 13位
  268. var (lastDayS, lastdayE) = TimeHelper.GetStartOrEnd(lestDate); //昨天开始时间
  269. Dictionary<int, int> sdOpenLesn = new(); //今日开课
  270. Dictionary<int, int> sdUpdLesn = new(); //今日上传课例
  271. Dictionary<int, int> ydOpenLesn = new(); //昨日开课
  272. Dictionary<int, int> ydUpdLesn = new(); //昨日上传课例
  273. List<RecLesn> sameDayLesn = new(); //今天课例
  274. List<RecLesn> yesterDayLesn = new(); //昨日课例
  275. 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}";
  276. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecLesn>(queryText: lesnSql, requestOptions: new QueryRequestOptions() { }))
  277. {
  278. sameDayLesn.Add(item);
  279. }
  280. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecLesn>(queryText: lesnSql, requestOptions: new QueryRequestOptions() { }))
  281. {
  282. sameDayLesn.Add(item);
  283. }
  284. 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}";
  285. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecLesn>(queryText: yesterDayLesnSql, requestOptions: new QueryRequestOptions() { }))
  286. {
  287. yesterDayLesn.Add(item);
  288. }
  289. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<RecLesn>(queryText: yesterDayLesnSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("LessonRecord") }))
  290. {
  291. yesterDayLesn.Add(item);
  292. }
  293. for (int i = 0; i < 24; i++)
  294. {
  295. if (hour >= i)
  296. {
  297. DateTimeOffset timeHour = new DateTime(year, month, day, i, 0, 0);
  298. var (hourS, hourE) = TimeHelper.GetStartOrEnd(timeHour, type: "hour");
  299. var openLesn = sameDayLesn.Where(item => item.startTime >= hourS && item.startTime <= hourE && item.upload == 0);
  300. sdOpenLesn.Add(i, openLesn.Count());
  301. var UpdLesn = sameDayLesn.Where(item => item.startTime >= hourS && item.startTime <= hourE && item.upload == 1);
  302. sdUpdLesn.Add(i, openLesn.Count());
  303. }
  304. DateTimeOffset yesterday = new DateTime(lestDate.Year, lestDate.Month, lestDate.Day, i, 0, 0);
  305. var (yHourS, yHourE) = TimeHelper.GetStartOrEnd(yesterday, type: "hour");
  306. var yOpenLesn = yesterDayLesn.Where(item => item.startTime >= yHourS && item.startTime <= yHourE && item.upload == 0).ToList();
  307. ydOpenLesn.Add(i, yOpenLesn.Count);
  308. var yUpdLesn = yesterDayLesn.Where(item => item.startTime >= yHourS && item.startTime <= yHourE && item.upload == 1).ToList();
  309. ydUpdLesn.Add(i, yUpdLesn.Count);
  310. }
  311. return Ok(new { state = 200, sdOpenLesn = sdOpenLesn.ToList(), sdUpdLesn = sdUpdLesn.ToList(), ydOpenLesn = ydOpenLesn.ToList(), ydUpdLesn = ydUpdLesn.ToList() });
  312. }
  313. /// <summary>
  314. /// 版本数量占比
  315. /// </summary>
  316. /// <returns></returns>
  317. [HttpPost("get-edition")]
  318. public async Task<IActionResult> GetEdition(JsonElement jsonElement)
  319. {
  320. var cosmosClient = _azureCosmos.GetCosmosClient();
  321. jsonElement.TryGetProperty("site", out JsonElement site);
  322. if ($"{site}".Equals(BIConst.Global))
  323. {
  324. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  325. }
  326. int beCnt = 0; //基础班
  327. int seCnt = 0; //标准版
  328. int peCnt = 0; //专业版
  329. List<RecScEd> scEdCnt = new();
  330. var ScSql = $"select c.id,c.name,c.size,c.scale from c";
  331. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<RecScEd>(queryText: ScSql, requestOptions:new QueryRequestOptions() { PartitionKey= new PartitionKey("Base")}))
  332. {
  333. scEdCnt.Add(item);
  334. }
  335. scEdCnt.ForEach(async scProCnt =>
  336. {
  337. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(scProCnt.id, new PartitionKey("ProductSum"));
  338. if (response.Status == 200)
  339. {
  340. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  341. SchoolProductSum ScProductSum = json.ToObject<SchoolProductSum>();
  342. //scProCnt.serial = ScProductSum.serial.Count();
  343. //scProCnt.service = ScProductSum.service.Count();
  344. //scProCnt.hard = ScProductSum.hard.Count();
  345. int pSeriCnt = ScProductSum.serial.Count();
  346. int pServCnt = ScProductSum.service.Count();
  347. int pHardCnt = ScProductSum.hard.Count();
  348. scProCnt.serial = pSeriCnt;
  349. scProCnt.service = pServCnt;
  350. scProCnt.hard = pHardCnt;
  351. if (scProCnt.scale >= 500 && (pSeriCnt > 0 || pServCnt > 0 || pHardCnt > 0)) peCnt += 1;
  352. }
  353. if (scProCnt.scale >= 500 && scProCnt.serial == 0 && scProCnt.service == 0 && scProCnt.hard == 0) seCnt += 1;
  354. if (scProCnt.scale == 0) beCnt += 1;
  355. });
  356. return Ok(new { state = 200, beCnt, seCnt, peCnt, scEdCnt });
  357. }
  358. /// <summary>
  359. /// 开课
  360. /// </summary>
  361. /// <param name="jsonElement"></param>
  362. /// <returns></returns>
  363. public async Task<IActionResult> GetTmdCount(JsonElement jsonElement)
  364. {
  365. if(jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  366. var cosmosClient = _azureCosmos.GetCosmosClient();
  367. var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
  368. var blobClient = _azureStorage.GetBlobContainerClient($"0-public");
  369. jsonElement.TryGetProperty("site", out JsonElement site);
  370. if ($"{site}".Equals(BIConst.Global))
  371. {
  372. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  373. table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("IESLogin");
  374. blobClient = _azureStorage.GetBlobContainerClient($"0-public", BIConst.Global);
  375. }
  376. List<string> schools = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  377. return Ok(new { state = 200 });
  378. }
  379. /// <summary>
  380. /// 记录在线人数
  381. /// </summary>
  382. public record RecOnLine
  383. {
  384. public string id { get; set; }
  385. public string name { get; set; }
  386. public string code { get; set; }
  387. public List<Teacher.LoginInfo> loginInfos { get; set; }
  388. }
  389. /// <summary>
  390. /// 记录学校版本信息
  391. /// </summary>
  392. public record RecScEd
  393. {
  394. public string id { get; set; }
  395. public string name { get; set; }
  396. public int size { get; set; }
  397. public int scale { get; set; }
  398. public int serial { get; set; } = 0;//软体
  399. public int service { get; set; } = 0; //服务
  400. public int hard { get; set; } = 0; //硬体
  401. }
  402. /// <summary>
  403. /// 记录课例
  404. /// </summary>
  405. public record RecLesn
  406. {
  407. public string id { get; set; }
  408. public string name { get; set; }
  409. public string code { get; set; }
  410. public string school { get; set; }
  411. public string scope{get;set;}
  412. public long startTime { get; set; }
  413. public int upload { get; set; }
  414. }
  415. }
  416. }