SystemService.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. var day = nowTime.ToString("yyyyMMdd");
  37. ///一周的第一天
  38. if (nowTime.DayOfWeek.Equals(DayOfWeek.Monday))
  39. {
  40. }
  41. string redisKey = $"Accumulate:Daily:{scope}:{key}:{day}";
  42. string member = $"{target}::{id}::{client}::{name}";
  43. await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, count);
  44. //if (key.Equals("lesson") || key.StartsWith("login_"))
  45. //{
  46. // redisKey = $"Accumulate:Daily:ies:{key}:{day}";
  47. // if (scope.Equals("school"))
  48. // {
  49. // member = $"ies::{id}::{name}";
  50. // }
  51. // else {
  52. // member = $"ies::ies::{name}";
  53. // }
  54. // await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, 1);
  55. //}
  56. }
  57. }
  58. }
  59. }