| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- //using System.Data;
- //using Common;
- //using Common.Soap;
- //using Database;
- //using Database.Database;
- //using GuesssongNC.Worker.Utils;
- //using Quartz;
- //namespace GuesssongNC.Worker;
- //class WeeklyPrizeScheduler : IJob
- //{
- // private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
- // typeof(WeeklyPrizeScheduler)
- // );
- // IConfiguration configuration;
- // ModelContext dbContext;
- // public WeeklyPrizeScheduler(IConfiguration _configuration)
- // {
- // configuration = _configuration;
- // dbContext = new DbHelper().GetDbContext(configuration.GetSection("Connection").Value!);
- // }
- // public async Task Execute(IJobExecutionContext context)
- // {
- // log.Info("Start WeeklyPrizeScheduler ...");
- // try
- // {
- // var result = await CommonSoapHandler.ExecuteAsync(
- // "http://127.0.0.1:8510/WsMytel?wsdl",
- // @"<?xml version='1.0' ?>
- //<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'>
- //<S:Body>
- //<subRequest xmlns='http://resultws/xsd'>
- //<username>ws_guesssong</username>
- //<password>guesssong@2025#</password>
- //<serviceid>GUESSSONG_PACKAGEDAILY</serviceid>
- //<msisdn>9665750225</msisdn>
- //<chargetime>20250114090157</chargetime>
- //<params>0</params>
- //<mode>REAL</mode>
- //<amount>149</amount>
- //<transactionid>0400000220250114090156769</transactionid>
- //<command>MONFEE</command>
- //<content>#CONTENT</content>
- //</subRequest>
- //</S:Body>
- //</S:Envelope>'"
- // );
- // var prizes1 = dbContext
- // .Prizes.Where(x => x.Type == CommonConstants.MonthlyPrize)
- // .OrderBy(x => x.Priority)
- // .ToList();
- // // foreach (var p in prizes1)
- // // {
- // // // send sms to user
- // // var msg = dbContext
- // // .Configs.Where(x => x.ParamName == (CommonConstants.Monthly + "_" + p.Amount))
- // // .FirstOrDefault();
- // // if (msg != null)
- // // {
- // // await CommonLogic.SendMtToUserAsync(
- // // dbContext,
- // // "959665750225",
- // // msg.ParamValueFr
- // // );
- // // }
- // // }
- // // send sms to user
- // var msg = dbContext
- // .Configs.Where(x => x.ParamName == (CommonConstants.Monthly + "_500000"))
- // .FirstOrDefault();
- // if (msg != null)
- // {
- // await CommonLogic.SendMtToUserAsync(dbContext, "959698091436", msg.ParamValueFr);
- // }
- // // check in monday
- // DateTime now = DateTime.Now;
- // var dayOfWeek = now.DayOfWeek;
- // if (dayOfWeek != DayOfWeek.Monday)
- // {
- // // return;
- // }
- // List<List<DateTime>> timeWeekly = CommonLogic.GetTimeWeekly(1);
- // log.Debug($"WEEKLY from {timeWeekly[0][0]} to {timeWeekly[0][1]}");
- // var weeklyTerm = dbContext
- // .Terms.Where(
- // x =>
- // x.Type == CommonConstants.Weekly
- // && x.Status == CommonConstants.ActiveInt
- // && x.DrawTime >= timeWeekly[0][0]
- // && x.DrawTime <= timeWeekly[0][1]
- // )
- // .FirstOrDefault();
- // if (weeklyTerm == null)
- // {
- // log.Info("No weekly term found.");
- // weeklyTerm = new Term()
- // {
- // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "term_seq"),
- // Name = "Weekly Term",
- // Code = CommonConstants.Weekly,
- // FromTime = timeWeekly[0][0],
- // ToTime = timeWeekly[0][1],
- // DrawTime = timeWeekly[0][1].AddMinutes(-30),
- // Status = CommonConstants.ActiveInt,
- // Type = CommonConstants.Weekly
- // };
- // dbContext.Terms.Add(weeklyTerm);
- // await dbContext.SaveChangesAsync();
- // }
- // // check highest point
- // var termUserPrize = dbContext
- // .TermUserPrizes.Where(
- // x =>
- // x.TimeCalculate >= weeklyTerm.FromTime
- // && x.TimeCalculate <= weeklyTerm.ToTime
- // )
- // .Count();
- // if (termUserPrize > 0)
- // {
- // log.Info($"Term {weeklyTerm.Id} has {termUserPrize} prize");
- // return;
- // }
- // // get point
- // var userHighestPoint = dbContext
- // .PlayTransactions.Where(
- // x =>
- // x.Status == CommonConstants.Submited
- // && x.TimeSubmit > weeklyTerm.FromTime
- // && x.TimeSubmit < weeklyTerm.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.WeeklyPrize)
- // .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];
- // bool addPoint = await LogicUtils.AddingPointForUserAsync(
- // configuration,
- // dbContext,
- // user.Msisdn,
- // user.Points ?? 0,
- // weeklyTerm,
- // prize
- // );
- // }
- // }
- // catch (Exception exception)
- // {
- // log.Error("Exception: ", exception);
- // }
- // }
- //}
|