TeamTopService.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. using System.Linq;
  4. using Microsoft.Extensions.Hosting;
  5. using MySystem.PxcModels;
  6. using MySystem;
  7. public class TeamTopService : BackgroundService
  8. {
  9. protected override async Task ExecuteAsync(CancellationToken stoppingToken)
  10. {
  11. while (!stoppingToken.IsCancellationRequested)
  12. {
  13. int timespan = 1000 * 60 * 60;
  14. await Task.Delay(timespan).ContinueWith(tsk =>
  15. {
  16. WebCMSEntities db = new WebCMSEntities();
  17. //首页-特训营-排行榜-个人
  18. var personTops = db.TeamPersonDayTop.Select(m => new { m.Id, m.ActMerNum }).OrderByDescending(m => m.ActMerNum).ToList();
  19. RedisDbconn.Instance.Clear("TeamPersonDayTop");
  20. foreach (var sub in personTops)
  21. {
  22. RedisDbconn.Instance.AddList("TeamPersonDayTop", sub.Id);
  23. }
  24. //首页-特训营-排行榜-团队
  25. var teamTops = db.TeamDayTop.Select(m => new { m.Id, m.ActMerNum }).OrderByDescending(m => m.ActMerNum).ToList();
  26. RedisDbconn.Instance.Clear("TeamDayTop");
  27. foreach (var sub in teamTops)
  28. {
  29. RedisDbconn.Instance.AddList("TeamDayTop", sub.Id);
  30. }
  31. db.Dispose();
  32. });
  33. }
  34. }
  35. }