IESHttpTrigger.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. using Azure.Cosmos;
  2. using Azure.Storage.Blobs.Models;
  3. using HTEXLib.COMM.Helpers;
  4. using Microsoft.Azure.Cosmos.Table;
  5. using Microsoft.Azure.Functions.Worker;
  6. using Microsoft.Azure.Functions.Worker.Http;
  7. using StackExchange.Redis;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Net;
  13. using System.Reflection;
  14. using System.Text;
  15. using System.Text.Json;
  16. using System.Threading.Tasks;
  17. using TEAMModelOS.SDK;
  18. using TEAMModelOS.SDK.DI;
  19. using TEAMModelOS.SDK.Extension;
  20. using TEAMModelOS.SDK.Models;
  21. using TEAMModelOS.SDK.Models.Cosmos.Teacher;
  22. using TEAMModelOS.SDK.Models.Table;
  23. using static TEAMModelOS.SDK.Models.Teacher;
  24. namespace TEAMModelOS.FunctionV4.HttpTrigger
  25. {
  26. public class IESHttpTrigger
  27. {
  28. private readonly AzureCosmosFactory _azureCosmos;
  29. private readonly DingDing _dingDing;
  30. private readonly AzureStorageFactory _azureStorage;
  31. private readonly AzureRedisFactory _azureRedis;
  32. public IESHttpTrigger(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage
  33. , AzureRedisFactory azureRedis)
  34. {
  35. _azureCosmos = azureCosmos;
  36. _dingDing = dingDing;
  37. _azureStorage = azureStorage;
  38. _azureRedis = azureRedis;
  39. }
  40. /// <summary>
  41. /// </summary>
  42. /// <param name="req"></param>
  43. /// <param name="log"></param>
  44. /// <returns></returns>
  45. [Function("system-info-function")]
  46. public async Task<HttpResponseData> SystemInfo([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestData req)
  47. {
  48. var response = req.CreateResponse(HttpStatusCode.OK);
  49. Type attr = this.GetType();
  50. string currentDirectory = Path.GetDirectoryName(attr.Assembly.Location);
  51. Assembly assembly = Assembly.LoadFrom($"{currentDirectory}\\TEAMModelOS.FunctionV4.dll");
  52. var description = assembly.GetCustomAttribute<AssemblyDescriptionAttribute>().Description;
  53. //var v1 = Assembly.GetEntryAssembly().GetName().Version;
  54. //var v2 = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
  55. // var description = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyDescriptionAttribute>().Description;
  56. var version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
  57. long nowtime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  58. //Console.WriteLine($"Assembly.GetEntryAssembly().GetName().Version: " +
  59. // $"{Assembly.GetEntryAssembly().GetName().Version}");5.2107.12.1
  60. //Console.WriteLine($"Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version:" +
  61. // $"{Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version}");5.2107.12.1
  62. //Console.WriteLine($"Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion:" +
  63. // $"{Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion}");5.2107.12
  64. await response.WriteAsJsonAsync(new { version, description, nowtime });
  65. return response;
  66. }
  67. /// <summary>
  68. /// 数据推送接口
  69. /// </summary>
  70. /// <param name="req"></param>
  71. /// <param name="log"></param>
  72. /// <returns></returns>
  73. [Function("lesson-tag-change")]
  74. public async Task<HttpResponseData> LessonTagChange([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req) {
  75. var response = req.CreateResponse(HttpStatusCode.OK);
  76. string data = await new StreamReader(req.Body).ReadToEndAsync();
  77. var json = JsonDocument.Parse(data).RootElement;
  78. return response;
  79. }
  80. /// <summary>
  81. /// 数据推送接口
  82. /// </summary>
  83. /// <param name="req"></param>
  84. /// <param name="log"></param>
  85. /// <returns></returns>
  86. [Function("knowledge-change")]
  87. public async Task<HttpResponseData> KnowledgeChange([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req)
  88. {
  89. var response = req.CreateResponse(HttpStatusCode.OK);
  90. string data = await new StreamReader(req.Body).ReadToEndAsync();
  91. var json = JsonDocument.Parse(data).RootElement;
  92. List<KnowledgeOldNew> old_new = null;
  93. string school = null;
  94. if (json.TryGetProperty("school", out JsonElement _school))
  95. {
  96. school = _school.GetString();
  97. }
  98. if (json.TryGetProperty("old_new", out JsonElement _old_new))
  99. {
  100. old_new = _old_new.ToObject<List<KnowledgeOldNew>>();
  101. }
  102. if (old_new.IsNotEmpty() && !string.IsNullOrWhiteSpace(school))
  103. {
  104. foreach (var on in old_new)
  105. {
  106. List<ItemInfo> items = new List<ItemInfo>();
  107. string sql = $"select value(c) from c where array_contains(c.knowledge,'{on._old}') ";
  108. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>
  109. (queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{_school}") }))
  110. {
  111. items.Add(item);
  112. }
  113. items.ForEach(item =>
  114. {
  115. //修改知识点
  116. if (!string.IsNullOrEmpty(on._new))
  117. {
  118. for (int i = 0; i < item.knowledge.Count; i++)
  119. {
  120. if (item.knowledge[i].Equals(on._old))
  121. {
  122. item.knowledge[i] = on._new;
  123. }
  124. }
  125. }
  126. else
  127. {
  128. //表示删除知识点
  129. item.knowledge.RemoveAll(x => x.Equals(on._old));
  130. }
  131. });
  132. foreach (var item in items)
  133. {
  134. ItemBlob itemBlob = null;
  135. try
  136. {
  137. BlobDownloadInfo blobDownloadResult = await _azureStorage.GetBlobContainerClient($"{school}").GetBlobClient($"/item/{item.id}/{item.id}.json").DownloadAsync();
  138. if (blobDownloadResult != null)
  139. {
  140. var blob = JsonDocument.Parse(blobDownloadResult.Content);
  141. itemBlob = blob.RootElement.ToObject<ItemBlob>();
  142. itemBlob.exercise.knowledge = item.knowledge;
  143. await _azureStorage.GetBlobContainerClient($"{school}").UploadFileByContainer(itemBlob.ToJsonString(), "item", $"{item.id}/{item.id}.json", true);
  144. }
  145. }
  146. catch (Exception ex)
  147. {
  148. itemBlob = null;
  149. }
  150. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
  151. }
  152. }
  153. }
  154. await response.WriteAsJsonAsync(new { data = json });
  155. return response;
  156. }
  157. /// <summary>
  158. /// 在线人数记录
  159. /// </summary>
  160. /// <param name="msg"></param>
  161. /// <returns></returns>
  162. [Function("online-record")]
  163. public async Task<HttpResponseData> OnlineRecord([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req)
  164. {
  165. var response = req.CreateResponse(HttpStatusCode.OK);
  166. string data = await new StreamReader(req.Body).ReadToEndAsync();
  167. var json = JsonDocument.Parse(data).RootElement;
  168. try
  169. {
  170. string school = null;
  171. string scope = null;
  172. string id = null;
  173. string ip = null;
  174. int expire = 1;
  175. if (json.TryGetProperty("school", out JsonElement _school))
  176. school = _school.GetString();
  177. if (json.TryGetProperty("scope", out JsonElement _scope))
  178. scope = _scope.GetString();
  179. if (json.TryGetProperty("id", out JsonElement _id))
  180. id = _id.GetString();
  181. if (json.TryGetProperty("ip", out JsonElement _ip))
  182. ip = _ip.GetString();
  183. if (json.TryGetProperty("expire", out JsonElement _expire))
  184. expire = _expire.GetInt32();
  185. var table = _azureStorage.GetCloudTableClient().GetTableReference("IESLogin");
  186. var cosmosClient = _azureCosmos.GetCosmosClient();
  187. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  188. var dateHour = dateTime.ToString("yyyyMMddHH"); //获取当天的小时
  189. var dateDay = dateTime.ToString("yyyyMMdd"); //获取当天的日期
  190. var dateMonth = dateTime.ToString("yyyyMM");//获取当月的日期
  191. var currentHour = dateTime.Hour; //当前小时
  192. var currentDay = dateTime.Day; //当前天
  193. long Expire = dateTime.AddHours(expire).ToUnixTimeMilliseconds(); //token到期时间
  194. long now = dateTime.ToUnixTimeMilliseconds(); //当前时间戳
  195. DateTime hour = DateTime.UtcNow.AddHours(25); //25小时到期
  196. DateTime month = DateTime.UtcNow.AddDays(32); //一个月到期
  197. var delTbHour = dateTime.AddHours(-168).ToString("yyyyMMddHH"); //168小时前
  198. var delTbDay = dateTime.AddDays(-180).ToString("yyyyMMdd"); //180天前
  199. switch (scope)
  200. {
  201. case "teacher":
  202. try
  203. {
  204. Teacher teacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
  205. teacher.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
  206. await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
  207. }
  208. catch { }
  209. break;
  210. case "student":
  211. try
  212. {
  213. Student student = await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReadItemAsync<Student>(id, new PartitionKey($"Base-{school}"));
  214. student.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
  215. await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReplaceItemAsync<Student>(student, student.id, new PartitionKey($"Base-{school}"));
  216. }
  217. catch { }
  218. break;
  219. case "tmduser":
  220. try
  221. {
  222. TmdUser tmdUser = await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReadItemAsync<TmdUser>(id, new PartitionKey("Base"));
  223. tmdUser.loginInfos = new List<LoginInfo>() { new LoginInfo { expire = Expire, ip = ip, time = now } };
  224. await cosmosClient.GetContainer("TEAMModelOS", Constant.Student).ReplaceItemAsync<TmdUser>(tmdUser, tmdUser.id, new PartitionKey("Base"));
  225. }
  226. catch { }
  227. break;
  228. }
  229. //天
  230. SortedSetEntry[] dayCnt = null;
  231. //月
  232. SortedSetEntry[] monthCnt = null;
  233. try
  234. {
  235. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:IES:{scope}:{dateDay}", $"{currentHour}", 1);//一天24小时 小时为单位
  236. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:IES:{scope}:{dateMonth}", $"{currentDay}", 1); //一天的累计 天为单位
  237. var resDay = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:IES:{scope}:{dateDay}");
  238. if (resDay == null)
  239. await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:IES:{scope}:{dateDay}", hour); //设置到期时间
  240. var rspMonth = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:IES:{scope}:{dateMonth}");
  241. if (rspMonth == null)
  242. await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:IES:{scope}:{dateMonth}", month); //设置到期时间
  243. //保存当前小时统计
  244. dayCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateDay}");
  245. //保存当前的统计数据
  246. monthCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:IES:{scope}:{dateMonth}");
  247. }
  248. catch { }
  249. if (dayCnt != null && dayCnt.Length > 0)
  250. {
  251. List<HourLogin> hourLogins = new();
  252. foreach (var dCnt in dayCnt)
  253. {
  254. if (((int)dCnt.Element) == currentHour)
  255. {
  256. var tphourLogins = await table.QueryWhereString<HourLogin>($"PartitionKey eq 'HourLogin' and RowKey eq '{dateHour}'");
  257. if (tphourLogins.Count > 0)
  258. {
  259. foreach (var hourLogin in tphourLogins)
  260. {
  261. if (scope.Equals("teacher"))
  262. hourLogin.Teacher = (int)dCnt.Score;
  263. else if (scope.Equals("student"))
  264. hourLogin.Student = (int)dCnt.Score;
  265. else
  266. hourLogin.TmdUser = (int)dCnt.Score;
  267. hourLogins.Add(hourLogin);
  268. }
  269. }
  270. else
  271. {
  272. HourLogin hourLogin = new() { PartitionKey = $"HourLogin", RowKey = dateHour, Hour = currentHour };
  273. if (scope.Equals("teacher"))
  274. {
  275. hourLogin.Teacher = 1;
  276. hourLogin.Student = 0;
  277. hourLogin.TmdUser = 0;
  278. }
  279. else if (scope.Equals("student"))
  280. {
  281. hourLogin.Teacher = 0;
  282. hourLogin.Student = 1;
  283. hourLogin.TmdUser = 0;
  284. }
  285. else
  286. {
  287. hourLogin.Teacher = 0;
  288. hourLogin.Student = 0;
  289. hourLogin.TmdUser = 1;
  290. }
  291. hourLogins.Add(hourLogin);
  292. }
  293. }
  294. }
  295. await table.SaveOrUpdateAll(hourLogins); //保存和更新保存当前小时登录次数
  296. }
  297. if (monthCnt != null && monthCnt.Length > 0)
  298. {
  299. List<DayLogin> dayLogins = new();
  300. foreach (var mCnt in monthCnt)
  301. {
  302. if (((int)mCnt.Element) == currentDay)
  303. {
  304. //保存当天的峰值
  305. var tbDays = await table.QueryWhereString<DayLogin>($"PartitionKey eq 'DayLogin' and RowKey eq '{dateDay}'");
  306. if (tbDays.Count > 0)
  307. {
  308. foreach (var dayLogin in tbDays)
  309. {
  310. if (scope.Equals("teacher"))
  311. dayLogin.Teacher = (int)mCnt.Score;
  312. else if (scope.Equals("student"))
  313. dayLogin.Student = (int)mCnt.Score;
  314. else
  315. dayLogin.TmdUser = (int)mCnt.Score;
  316. dayLogins.Add(dayLogin);
  317. }
  318. }
  319. else
  320. {
  321. //保存当月每天的峰值
  322. DayLogin dayLogin = new() { PartitionKey = $"DayLogin", RowKey = dateDay, Day = currentDay };
  323. if (scope.Equals("teacher"))
  324. {
  325. dayLogin.Teacher = 1;
  326. dayLogin.Student = 0;
  327. dayLogin.TmdUser = 0;
  328. }
  329. else if (scope.Equals("student"))
  330. {
  331. dayLogin.Teacher = 0;
  332. dayLogin.Student = 1;
  333. dayLogin.TmdUser = 0;
  334. }
  335. else
  336. {
  337. dayLogin.Teacher = 0;
  338. dayLogin.Student = 0;
  339. dayLogin.TmdUser = 1;
  340. }
  341. dayLogins.Add(dayLogin);
  342. }
  343. }
  344. }
  345. await table.SaveOrUpdateAll(dayLogins);// 保存当月每天在线数据
  346. }
  347. string tbHourSql = $"PartitionKey eq 'HourLogin' and RowKey le '{delTbHour}'";
  348. string tbDaySql = $"PartitionKey eq 'DayLogin' and RowKey le '{delTbDay}'";
  349. try
  350. {
  351. await table.DeleteStringWhere<HourLogin>(rowKey: tbHourSql); //删除168小时前的数据
  352. await table.DeleteStringWhere<DayLogin>(rowKey: tbDaySql); //删除180天前的数据
  353. }
  354. catch { }
  355. if (!string.IsNullOrWhiteSpace(school))
  356. {
  357. //天
  358. SortedSetEntry[] scDayCnt = null;
  359. //月
  360. SortedSetEntry[] scMonthCnt = null;
  361. try
  362. {
  363. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:School:{school}:{scope}:{dateDay}", $"{currentHour}", 1);//当天当前小时在线人加1
  364. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Login:School:{school}:{scope}:{dateMonth}", $"{currentDay}", 1); //当天的在线加1
  365. var reScDay = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:School:{school}:{scope}:{dateDay}");
  366. if (reScDay == null)
  367. await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:School:{school}:{scope}:{dateDay}", hour); //设置到期时间
  368. var reScMonth = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync($"Login:School:{school}:{scope}:{dateMonth}");
  369. if (reScMonth == null)
  370. await _azureRedis.GetRedisClient(8).KeyExpireAsync($"Login:School:{school}:{scope}:{dateMonth}", month); //设置到期时间
  371. //保存学校当天每小时的
  372. scDayCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateDay}");
  373. //学校天峰值
  374. scMonthCnt = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Login:School:{school}:{scope}:{dateMonth}");
  375. }
  376. catch { }
  377. if (scDayCnt != null && scDayCnt.Length > 0)
  378. {
  379. List<HourLoginSchool> hourLoginSchools = new();
  380. foreach (var scDCnt in scDayCnt)
  381. {
  382. if (((int)scDCnt.Element) == currentHour)
  383. {
  384. var tmpHour = await table.QueryWhereString<HourLoginSchool>($"PartitionKey eq 'HourLogin-{school}' and RowKey eq '{dateHour}'");
  385. if (tmpHour.Count > 0)
  386. {
  387. foreach (var hLoginSc in tmpHour)
  388. {
  389. if (scope.Equals("teacher"))
  390. hLoginSc.Teacher = (int)scDCnt.Score;
  391. else if (scope.Equals("student"))
  392. hLoginSc.Student = (int)scDCnt.Score;
  393. else
  394. hLoginSc.TmdUser = (int)scDCnt.Score;
  395. hourLoginSchools.Add(hLoginSc);
  396. }
  397. }
  398. else
  399. {
  400. //学校小时峰值
  401. HourLoginSchool hourLoginSc = new() { PartitionKey = $"HourLogin-{school}", RowKey = dateHour, Hour = currentHour, School = school };
  402. if (scope.Equals("teacher"))
  403. {
  404. hourLoginSc.Teacher = 1;
  405. hourLoginSc.Student = 0;
  406. hourLoginSc.TmdUser = 0;
  407. }
  408. else if (scope.Equals("student"))
  409. {
  410. hourLoginSc.Teacher = 0;
  411. hourLoginSc.Student = 1;
  412. hourLoginSc.TmdUser = 0;
  413. }
  414. else
  415. {
  416. hourLoginSc.Teacher = 0;
  417. hourLoginSc.Student = 0;
  418. hourLoginSc.TmdUser = 1;
  419. }
  420. hourLoginSchools.Add(hourLoginSc);
  421. }
  422. }
  423. }
  424. await table.SaveOrUpdateAll(hourLoginSchools);
  425. }
  426. if (scMonthCnt != null && scMonthCnt.Length > 0)
  427. {
  428. List<DayLoginSchool> DayLoginSchools = new();
  429. foreach (var scMCnt in scMonthCnt)
  430. {
  431. if (((int)scMCnt.Element) == currentDay)
  432. {
  433. var tempDays = await table.QueryWhereString<DayLoginSchool>($"PartitionKey eq 'DayLogin-{school}' and RowKey eq '{dateDay}'");
  434. if (tempDays.Count > 0)
  435. {
  436. foreach (var dLoginSc in tempDays)
  437. {
  438. if (scope.Equals("teacher"))
  439. dLoginSc.Teacher = (int)scMCnt.Score;
  440. else if (scope.Equals("student"))
  441. dLoginSc.Student = (int)scMCnt.Score;
  442. else
  443. dLoginSc.TmdUser = (int)scMCnt.Score;
  444. DayLoginSchools.Add(dLoginSc);
  445. }
  446. }
  447. else
  448. {
  449. //学校天峰值
  450. DayLoginSchool dayLoginSc = new() { PartitionKey = $"DayLogin-{school}", RowKey = dateDay, Day = currentDay, School = school };
  451. if (scope.Equals("teacher"))
  452. {
  453. dayLoginSc.Teacher = 1;
  454. dayLoginSc.Student = 0;
  455. dayLoginSc.TmdUser = 0;
  456. }
  457. else if (scope.Equals("student"))
  458. {
  459. dayLoginSc.Teacher = 0;
  460. dayLoginSc.Student = 1;
  461. dayLoginSc.TmdUser = 0;
  462. }
  463. else
  464. {
  465. dayLoginSc.Teacher = 0;
  466. dayLoginSc.Student = 0;
  467. dayLoginSc.TmdUser = 1;
  468. }
  469. DayLoginSchools.Add(dayLoginSc);
  470. }
  471. }
  472. }
  473. await table.SaveOrUpdateAll(DayLoginSchools);//保存学校当月在线数据
  474. }
  475. string tbScHourSql = $"PartitionKey eq 'HourLogin-{school}' and RowKey le '{delTbHour}'";
  476. List<HourLogin> scHourLog = await table.QueryWhereString<HourLogin>(tbScHourSql);
  477. if (scHourLog.Count > 0)
  478. try
  479. {
  480. //await table.DeleteStringWhere<HourLogin>(tbScHourSql); //删除学校168小时前的数据
  481. await table.DeleteAll(scHourLog);
  482. }
  483. catch { }
  484. string tbScDaySql = $"PartitionKey eq 'DayLogin-{school}' and RowKey le '{delTbDay}'";
  485. List<DayLogin> scDayLog = await table.QueryWhereString<DayLogin>(tbScDaySql);
  486. if (scDayLog.Count > 0)
  487. try
  488. {
  489. //await table.DeleteStringWhere<DayLogin>(tbScDaySql); //删除学校180天前的数据
  490. await table.DeleteAll(scDayLog);
  491. }
  492. catch { }
  493. }
  494. await response.WriteAsJsonAsync(new { data = json });
  495. return response;
  496. }
  497. catch (Exception ex)
  498. {
  499. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-online-record 人数记录异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  500. await response.WriteAsJsonAsync(new { data = json });
  501. return response;
  502. }
  503. }
  504. }
  505. }