MonthlyPrizeScheduler.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //using System.Data;
  2. //using Common;
  3. //using Database;
  4. //using Database.Database;
  5. //using GuesssongNC.Worker.Utils;
  6. //using Quartz;
  7. //namespace GuesssongNC.Worker;
  8. //class MonthlyPrizeScheduler : IJob
  9. //{
  10. // private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
  11. // typeof(MonthlyPrizeScheduler)
  12. // );
  13. // IConfiguration configuration;
  14. // ModelContext dbContext;
  15. // public MonthlyPrizeScheduler(IConfiguration _configuration)
  16. // {
  17. // configuration = _configuration;
  18. // dbContext = new DbHelper().GetDbContext(configuration.GetSection("Connection").Value!);
  19. // }
  20. // public async Task Execute(IJobExecutionContext context)
  21. // {
  22. // log.Info("Start MonthlyPrizeScheduler ...");
  23. // try
  24. // {
  25. // DateTime now = DateTime.Now;
  26. // var dayOfMonth = now.Day;
  27. // if (dayOfMonth != 1)
  28. // {
  29. // return;
  30. // }
  31. // List<List<DateTime>> timeMonthly = CommonLogic.GetTimeMonthly(1);
  32. // var monthlyTerm = dbContext
  33. // .Terms.Where(
  34. // x =>
  35. // x.Type == CommonConstants.Monthly
  36. // && x.Status == CommonConstants.ActiveInt
  37. // && x.DrawTime >= timeMonthly[0][0]
  38. // && x.DrawTime <= timeMonthly[0][1]
  39. // )
  40. // .FirstOrDefault();
  41. // if (monthlyTerm == null)
  42. // {
  43. // log.Info("No monthly term found.");
  44. // monthlyTerm = new Term()
  45. // {
  46. // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "term_seq"),
  47. // Name = "Weekly Term",
  48. // Code = CommonConstants.Monthly,
  49. // FromTime = timeMonthly[0][0],
  50. // ToTime = timeMonthly[0][1],
  51. // DrawTime = timeMonthly[0][1].AddMinutes(-30),
  52. // Status = CommonConstants.ActiveInt,
  53. // Type = CommonConstants.Monthly
  54. // };
  55. // dbContext.Terms.Add(monthlyTerm);
  56. // await dbContext.SaveChangesAsync();
  57. // }
  58. // // check highest point
  59. // var termUserPrizeHis = dbContext
  60. // .TermUserPrizes.Where(
  61. // x =>
  62. // x.TimeCalculate >= monthlyTerm.FromTime
  63. // && x.TimeCalculate <= monthlyTerm.ToTime
  64. // )
  65. // .Count();
  66. // if (termUserPrizeHis > 0)
  67. // {
  68. // log.Info($"Term {monthlyTerm.Id} has {termUserPrizeHis} prize");
  69. // return;
  70. // }
  71. // // get point
  72. // var userHighestPoint = dbContext
  73. // .PlayTransactions.Where(
  74. // x =>
  75. // x.Status == CommonConstants.Submited
  76. // && x.TimeSubmit > monthlyTerm.FromTime
  77. // && x.TimeSubmit < monthlyTerm.ToTime
  78. // )
  79. // .GroupBy(x => x.Msisdn)
  80. // .Select(x => new { Msisdn = x.Key, Points = x.Sum(y => y.TotalPoint) })
  81. // .OrderByDescending(x => x.Points)
  82. // .Skip(0)
  83. // .Take(10)
  84. // .ToList();
  85. // var prizes = dbContext
  86. // .Prizes.Where(x => x.Type == CommonConstants.MonthlyPrize)
  87. // .OrderBy(x => x.Priority)
  88. // .ToList();
  89. // for (int i = 0; i < prizes.Count(); i++)
  90. // {
  91. // var prize = prizes[i];
  92. // if (userHighestPoint.Count <= i)
  93. // {
  94. // continue;
  95. // }
  96. // var user = userHighestPoint[i];
  97. // TermUserPrize termUserPrize = new TermUserPrize()
  98. // {
  99. // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "term_user_prize_seq"),
  100. // Msisdn = user.Msisdn,
  101. // Priority = prize.Priority,
  102. // TermId = monthlyTerm.Id,
  103. // PrizeId = prize.Id,
  104. // TimeCalculate = DateTime.Now,
  105. // Status = CommonErrorCode.SUCCESS,
  106. // TotalPoints = user.Points,
  107. // };
  108. // dbContext.TermUserPrizes.Add(termUserPrize);
  109. // await dbContext.SaveChangesAsync();
  110. // // send sms to user
  111. // var msg = dbContext
  112. // .Configs.Where(
  113. // x => x.ParamName == (CommonConstants.Monthly + "_" + prize.Amount)
  114. // )
  115. // .FirstOrDefault();
  116. // if (msg != null)
  117. // {
  118. // await CommonLogic.SendMtToUserAsync(dbContext, user.Msisdn, msg.ParamValueFr);
  119. // }
  120. // }
  121. // }
  122. // catch (Exception exception)
  123. // {
  124. // log.Error("Exception: ", exception);
  125. // }
  126. // }
  127. //}