| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- //using System.Data;
- //using Common;
- //using Database;
- //using Database.Database;
- //using GuesssongNC.Worker.Utils;
- //using Quartz;
- //namespace GuesssongNC.Worker;
- //class MonthlyPrizeScheduler : IJob
- //{
- // private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
- // typeof(MonthlyPrizeScheduler)
- // );
- // IConfiguration configuration;
- // ModelContext dbContext;
- // public MonthlyPrizeScheduler(IConfiguration _configuration)
- // {
- // configuration = _configuration;
- // dbContext = new DbHelper().GetDbContext(configuration.GetSection("Connection").Value!);
- // }
- // public async Task Execute(IJobExecutionContext context)
- // {
- // log.Info("Start MonthlyPrizeScheduler ...");
- // try
- // {
- // DateTime now = DateTime.Now;
- // var dayOfMonth = now.Day;
- // if (dayOfMonth != 1)
- // {
- // return;
- // }
- // List<List<DateTime>> timeMonthly = CommonLogic.GetTimeMonthly(1);
- // var monthlyTerm = dbContext
- // .Terms.Where(
- // x =>
- // x.Type == CommonConstants.Monthly
- // && x.Status == CommonConstants.ActiveInt
- // && x.DrawTime >= timeMonthly[0][0]
- // && x.DrawTime <= timeMonthly[0][1]
- // )
- // .FirstOrDefault();
- // if (monthlyTerm == null)
- // {
- // log.Info("No monthly term found.");
- // monthlyTerm = new Term()
- // {
- // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "term_seq"),
- // Name = "Weekly Term",
- // Code = CommonConstants.Monthly,
- // FromTime = timeMonthly[0][0],
- // ToTime = timeMonthly[0][1],
- // DrawTime = timeMonthly[0][1].AddMinutes(-30),
- // Status = CommonConstants.ActiveInt,
- // Type = CommonConstants.Monthly
- // };
- // dbContext.Terms.Add(monthlyTerm);
- // await dbContext.SaveChangesAsync();
- // }
- // // check highest point
- // var termUserPrizeHis = dbContext
- // .TermUserPrizes.Where(
- // x =>
- // x.TimeCalculate >= monthlyTerm.FromTime
- // && x.TimeCalculate <= monthlyTerm.ToTime
- // )
- // .Count();
- // if (termUserPrizeHis > 0)
- // {
- // log.Info($"Term {monthlyTerm.Id} has {termUserPrizeHis} prize");
- // return;
- // }
- // // get point
- // var userHighestPoint = dbContext
- // .PlayTransactions.Where(
- // x =>
- // x.Status == CommonConstants.Submited
- // && x.TimeSubmit > monthlyTerm.FromTime
- // && x.TimeSubmit < monthlyTerm.ToTime
- // )
- // .GroupBy(x => x.Msisdn)
- // .Select(x => new { Msisdn = x.Key, Points = x.Sum(y => y.TotalPoint) })
- // .OrderByDescending(x => x.Points)
- // .Skip(0)
- // .Take(10)
- // .ToList();
- // var prizes = dbContext
- // .Prizes.Where(x => x.Type == CommonConstants.MonthlyPrize)
- // .OrderBy(x => x.Priority)
- // .ToList();
- // for (int i = 0; i < prizes.Count(); i++)
- // {
- // var prize = prizes[i];
- // if (userHighestPoint.Count <= i)
- // {
- // continue;
- // }
- // var user = userHighestPoint[i];
- // TermUserPrize termUserPrize = new TermUserPrize()
- // {
- // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "term_user_prize_seq"),
- // Msisdn = user.Msisdn,
- // Priority = prize.Priority,
- // TermId = monthlyTerm.Id,
- // PrizeId = prize.Id,
- // TimeCalculate = DateTime.Now,
- // Status = CommonErrorCode.SUCCESS,
- // TotalPoints = user.Points,
- // };
- // dbContext.TermUserPrizes.Add(termUserPrize);
- // await dbContext.SaveChangesAsync();
- // // send sms to user
- // var msg = dbContext
- // .Configs.Where(
- // x => x.ParamName == (CommonConstants.Monthly + "_" + prize.Amount)
- // )
- // .FirstOrDefault();
- // if (msg != null)
- // {
- // await CommonLogic.SendMtToUserAsync(dbContext, user.Msisdn, msg.ParamValueFr);
- // }
- // }
- // }
- // catch (Exception exception)
- // {
- // log.Error("Exception: ", exception);
- // }
- // }
- //}
|