SystemService.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using TEAMModelOS.SDK.DI;
  7. using TEAMModelOS.SDK.Extension;
  8. using TEAMModelOS.SDK.Models.Dtos;
  9. using static OpenXmlPowerTools.RevisionProcessor;
  10. namespace TEAMModelOS.SDK.Models.Service
  11. {
  12. public static class SystemService
  13. {
  14. public static async Task RecordAccumulateData(AzureRedisFactory azureRedis,DingDing dingDing, Accumulate accumulate)
  15. {
  16. if (!string.IsNullOrWhiteSpace(accumulate.key) && !string.IsNullOrWhiteSpace(accumulate.target) &&
  17. !string.IsNullOrWhiteSpace(accumulate.id) && !string.IsNullOrWhiteSpace(accumulate.name) &&
  18. !string.IsNullOrWhiteSpace(accumulate.scope) && !string.IsNullOrWhiteSpace(accumulate.client))
  19. {
  20. await RecordAccumulateData(azureRedis, accumulate.key, accumulate.target, accumulate.id, accumulate.name, accumulate.scope, accumulate.client, accumulate.count);
  21. }
  22. else {
  23. await dingDing.SendBotMsg($"IES累计数据变更统计参数异常,{accumulate.ToJsonString()}", GroupNames.成都开发測試群組);
  24. }
  25. }
  26. /// <summary>
  27. /// 记录累计数据
  28. /// </summary>
  29. public static async Task RecordAccumulateData(AzureRedisFactory azureRedis, string key, string target, string id, string name, string scope, string client,int count)
  30. {
  31. if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(target) &&
  32. !string.IsNullOrWhiteSpace(id) && !string.IsNullOrWhiteSpace(name) &&
  33. !string.IsNullOrWhiteSpace(scope)&& !string.IsNullOrWhiteSpace(client)) {
  34. //处理UTC时差
  35. var nowTime = DateTimeOffset.UtcNow.GetGMTTime();
  36. int difference = (DayOfWeek.Sunday - nowTime.DayOfWeek + 7) % 7; //1-7的结果0-6
  37. var day = nowTime.ToString("yyyyMMdd");
  38. string redisKey = $"Accumulate:Daily:{scope}:{key}:{day}";
  39. string member = $"{target}::{id}::{client}::{name}";
  40. await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, count);
  41. await azureRedis.GetRedisClient(8).KeyExpireAsync(redisKey,new TimeSpan((difference+1)*24, 10,0));
  42. //if (key.Equals("lesson") || key.StartsWith("login_"))
  43. //{
  44. // redisKey = $"Accumulate:Daily:ies:{key}:{day}";
  45. // if (scope.Equals("school"))
  46. // {
  47. // member = $"ies::{id}::{name}";
  48. // }
  49. // else {
  50. // member = $"ies::ies::{name}";
  51. // }
  52. // await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, 1);
  53. //}
  54. }
  55. }
  56. }
  57. }