WeeklyPrizeScheduler.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //using System.Data;
  2. //using Common;
  3. //using Common.Soap;
  4. //using Database;
  5. //using Database.Database;
  6. //using GuesssongNC.Worker.Utils;
  7. //using Quartz;
  8. //namespace GuesssongNC.Worker;
  9. //class WeeklyPrizeScheduler : IJob
  10. //{
  11. // private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
  12. // typeof(WeeklyPrizeScheduler)
  13. // );
  14. // IConfiguration configuration;
  15. // ModelContext dbContext;
  16. // public WeeklyPrizeScheduler(IConfiguration _configuration)
  17. // {
  18. // configuration = _configuration;
  19. // dbContext = new DbHelper().GetDbContext(configuration.GetSection("Connection").Value!);
  20. // }
  21. // public async Task Execute(IJobExecutionContext context)
  22. // {
  23. // log.Info("Start WeeklyPrizeScheduler ...");
  24. // try
  25. // {
  26. // var result = await CommonSoapHandler.ExecuteAsync(
  27. // "http://127.0.0.1:8510/WsMytel?wsdl",
  28. // @"<?xml version='1.0' ?>
  29. //<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'>
  30. //<S:Body>
  31. //<subRequest xmlns='http://resultws/xsd'>
  32. //<username>ws_guesssong</username>
  33. //<password>guesssong@2025#</password>
  34. //<serviceid>GUESSSONG_PACKAGEDAILY</serviceid>
  35. //<msisdn>9665750225</msisdn>
  36. //<chargetime>20250114090157</chargetime>
  37. //<params>0</params>
  38. //<mode>REAL</mode>
  39. //<amount>149</amount>
  40. //<transactionid>0400000220250114090156769</transactionid>
  41. //<command>MONFEE</command>
  42. //<content>#CONTENT</content>
  43. //</subRequest>
  44. //</S:Body>
  45. //</S:Envelope>'"
  46. // );
  47. // var prizes1 = dbContext
  48. // .Prizes.Where(x => x.Type == CommonConstants.MonthlyPrize)
  49. // .OrderBy(x => x.Priority)
  50. // .ToList();
  51. // // foreach (var p in prizes1)
  52. // // {
  53. // // // send sms to user
  54. // // var msg = dbContext
  55. // // .Configs.Where(x => x.ParamName == (CommonConstants.Monthly + "_" + p.Amount))
  56. // // .FirstOrDefault();
  57. // // if (msg != null)
  58. // // {
  59. // // await CommonLogic.SendMtToUserAsync(
  60. // // dbContext,
  61. // // "959665750225",
  62. // // msg.ParamValueFr
  63. // // );
  64. // // }
  65. // // }
  66. // // send sms to user
  67. // var msg = dbContext
  68. // .Configs.Where(x => x.ParamName == (CommonConstants.Monthly + "_500000"))
  69. // .FirstOrDefault();
  70. // if (msg != null)
  71. // {
  72. // await CommonLogic.SendMtToUserAsync(dbContext, "959698091436", msg.ParamValueFr);
  73. // }
  74. // // check in monday
  75. // DateTime now = DateTime.Now;
  76. // var dayOfWeek = now.DayOfWeek;
  77. // if (dayOfWeek != DayOfWeek.Monday)
  78. // {
  79. // // return;
  80. // }
  81. // List<List<DateTime>> timeWeekly = CommonLogic.GetTimeWeekly(1);
  82. // log.Debug($"WEEKLY from {timeWeekly[0][0]} to {timeWeekly[0][1]}");
  83. // var weeklyTerm = dbContext
  84. // .Terms.Where(
  85. // x =>
  86. // x.Type == CommonConstants.Weekly
  87. // && x.Status == CommonConstants.ActiveInt
  88. // && x.DrawTime >= timeWeekly[0][0]
  89. // && x.DrawTime <= timeWeekly[0][1]
  90. // )
  91. // .FirstOrDefault();
  92. // if (weeklyTerm == null)
  93. // {
  94. // log.Info("No weekly term found.");
  95. // weeklyTerm = new Term()
  96. // {
  97. // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "term_seq"),
  98. // Name = "Weekly Term",
  99. // Code = CommonConstants.Weekly,
  100. // FromTime = timeWeekly[0][0],
  101. // ToTime = timeWeekly[0][1],
  102. // DrawTime = timeWeekly[0][1].AddMinutes(-30),
  103. // Status = CommonConstants.ActiveInt,
  104. // Type = CommonConstants.Weekly
  105. // };
  106. // dbContext.Terms.Add(weeklyTerm);
  107. // await dbContext.SaveChangesAsync();
  108. // }
  109. // // check highest point
  110. // var termUserPrize = dbContext
  111. // .TermUserPrizes.Where(
  112. // x =>
  113. // x.TimeCalculate >= weeklyTerm.FromTime
  114. // && x.TimeCalculate <= weeklyTerm.ToTime
  115. // )
  116. // .Count();
  117. // if (termUserPrize > 0)
  118. // {
  119. // log.Info($"Term {weeklyTerm.Id} has {termUserPrize} prize");
  120. // return;
  121. // }
  122. // // get point
  123. // var userHighestPoint = dbContext
  124. // .PlayTransactions.Where(
  125. // x =>
  126. // x.Status == CommonConstants.Submited
  127. // && x.TimeSubmit > weeklyTerm.FromTime
  128. // && x.TimeSubmit < weeklyTerm.ToTime
  129. // )
  130. // .GroupBy(x => x.Msisdn)
  131. // .Select(x => new { Msisdn = x.Key, Points = x.Sum(y => y.TotalPoint) })
  132. // .OrderByDescending(x => x.Points)
  133. // .Skip(0)
  134. // .Take(10)
  135. // .ToList();
  136. // var prizes = dbContext
  137. // .Prizes.Where(x => x.Type == CommonConstants.WeeklyPrize)
  138. // .OrderBy(x => x.Priority)
  139. // .ToList();
  140. // for (int i = 0; i < prizes.Count(); i++)
  141. // {
  142. // var prize = prizes[i];
  143. // if (userHighestPoint.Count <= i)
  144. // {
  145. // continue;
  146. // }
  147. // var user = userHighestPoint[i];
  148. // bool addPoint = await LogicUtils.AddingPointForUserAsync(
  149. // configuration,
  150. // dbContext,
  151. // user.Msisdn,
  152. // user.Points ?? 0,
  153. // weeklyTerm,
  154. // prize
  155. // );
  156. // }
  157. // }
  158. // catch (Exception exception)
  159. // {
  160. // log.Error("Exception: ", exception);
  161. // }
  162. // }
  163. //}