From 2feb295a6a723f3debd29789d325840b520ebaae Mon Sep 17 00:00:00 2001 From: zpc Date: Sat, 7 Dec 2024 02:16:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Monitor/GameMonitorProcessor.cs | 14 ++++-- .../Monitor/OrderMonitorProcessor.cs | 50 +++++++++++-------- .../Monitor/UserMonitorProcessor.cs | 15 ++++-- 3 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/CloudGaming/Code/CloudGaming.Code/Monitor/GameMonitorProcessor.cs b/src/CloudGaming/Code/CloudGaming.Code/Monitor/GameMonitorProcessor.cs index 0269da9..c82ee56 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Monitor/GameMonitorProcessor.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Monitor/GameMonitorProcessor.cs @@ -13,7 +13,7 @@ namespace CloudGaming.Code.Monitor /// /// 游戏控制器 /// - [QuartzTrigger("GameMonitorProcessor", "* 05 4 * * ?")] + [QuartzTrigger("GameMonitorProcessor", "* 5 4 * * ?")] public class GameMonitorProcessor : AppJobBase { public GameMonitorProcessor(IServiceScopeFactory scopeFactory) : base(scopeFactory) @@ -71,11 +71,17 @@ namespace CloudGaming.Code.Monitor statisticsUser.UpdatedAt = DateTime.Now; } - foreach (var item in gamePlayCount) + var list = dao.DaoExt.Context.T_App_Channel.ToList(); + foreach (var item in list) { - UpdateStatistics(item.Key, item.Value, gamePlaySeconds.GetValueOrDefault(item.Key, 0), gamePlayLog.GetValueOrDefault(item.Key, 0)); - } + var key = item.ChannelId; + if (string.IsNullOrEmpty(key)) + { + key = "27001"; + } + UpdateStatistics(key, gamePlayCount.GetValueOrDefault(key, 0), gamePlaySeconds.GetValueOrDefault(key, 0), gamePlayLog.GetValueOrDefault(key, 0)); + } await dao.DaoExt.Context.SaveChangesAsync(); } } diff --git a/src/CloudGaming/Code/CloudGaming.Code/Monitor/OrderMonitorProcessor.cs b/src/CloudGaming/Code/CloudGaming.Code/Monitor/OrderMonitorProcessor.cs index 0e48e94..75f73e7 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Monitor/OrderMonitorProcessor.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Monitor/OrderMonitorProcessor.cs @@ -1,3 +1,4 @@ +using CloudGaming.Code.DataAccess; using CloudGaming.DtoModel.Other; using HuanMeng.DotNetCore.QuartzExtend; @@ -39,6 +40,18 @@ public class OrderMonitorProcessor : AppJobBase .Where(it => it.LoginDay == day) .ToDictionaryAsync(it => it.Channel ?? ""); + var list = dao.DaoExt.Context.T_App_Channel.ToList(); + foreach (var item in list) + { + var key = item.ChannelId; + if (string.IsNullOrEmpty(key)) + { + key = "27001"; + } + UpdateStatistics(key, intendedOrder.GetValueOrDefault(key, 0), paidOrders.GetValueOrDefault(key, 0), paidOrdersPrice.GetValueOrDefault(key, 0)); + + } + await dao.DaoExt.Context.SaveChangesAsync(); // 更新或创建统计记录 void UpdateStatistics(string channel, int intendedOrderCount, int paidOrders, decimal rechargeAmount) { @@ -63,12 +76,7 @@ public class OrderMonitorProcessor : AppJobBase statisticsUser.PaidOrders = paidOrders; statisticsUser.UpdatedAt = DateTime.Now; } - foreach (var item in intendedOrder) - { - UpdateStatistics(item.Key, item.Value, paidOrders.GetValueOrDefault(item.Key, 0), paidOrdersPrice.GetValueOrDefault(item.Key, 0)); - } - await dao.DaoExt.Context.SaveChangesAsync(); } } @@ -89,19 +97,32 @@ public class OrderHourMonitorProcessor : AppJobBase int dayHour = int.Parse(now.ToString("yyyyMMddHH")); var nowDay = DateOnly.FromDateTime(now); //意向订单次数 - var intendedOrder = await dao.DaoUser.Context.T_User_IntentOrder.Where(it => it.CreatedDay == day && it.CreatedAt >= newDayHour && it.CreatedAt <= oldDayHour).GroupBy(it => it.Channel).ToDictionaryAsync(it => it.Key ?? "", it => it.Count()); + var intendedOrder = await dao.DaoUser.Context.T_User_IntentOrder.Where(it => it.CreatedDay == day && it.CreatedAt >= newDayHour && it.CreatedAt < oldDayHour).GroupBy(it => it.Channel).ToDictionaryAsync(it => it.Key ?? "", it => it.Count()); //支付订单次数 - var paidOrders = await dao.DaoUser.Context.T_User_Order.Where(it => it.PaymentDay == nowDay && it.CreatedAt >= newDayHour && it.CreatedAt <= oldDayHour).GroupBy(it => it.Channel).ToDictionaryAsync(it => it.Key ?? "", it => it.Count()); + var paidOrders = await dao.DaoUser.Context.T_User_Order.Where(it => it.PaymentDay == nowDay && it.CreatedAt >= newDayHour && it.CreatedAt < oldDayHour).GroupBy(it => it.Channel).ToDictionaryAsync(it => it.Key ?? "", it => it.Count()); //支付金额 - var paidOrdersPrice = await dao.DaoUser.Context.T_User_Order.Where(it => it.PaymentDay == nowDay && it.CreatedAt >= newDayHour && it.CreatedAt <= oldDayHour).GroupBy(it => it.Channel).ToDictionaryAsync(it => it.Key ?? "", it => it.Sum(it => it.TotalPrice)); + var paidOrdersPrice = await dao.DaoUser.Context.T_User_Order.Where(it => it.PaymentDay == nowDay && it.CreatedAt >= newDayHour && it.CreatedAt < oldDayHour).GroupBy(it => it.Channel).ToDictionaryAsync(it => it.Key ?? "", it => it.Sum(it => it.TotalPrice)); //数据源 var orderStatistics = await dao.DaoExt.Context.T_Statistics_OrderHour .Where(it => it.LoginHour == dayHour) .ToDictionaryAsync(it => it.Channel ?? ""); + var list = dao.DaoExt.Context.T_App_Channel.ToList(); + foreach (var item in list) + { + var key = item.ChannelId; + if (string.IsNullOrEmpty(key)) + { + key = "27001"; + } + UpdateStatistics(key, intendedOrder.GetValueOrDefault(key, 0), paidOrders.GetValueOrDefault(key, 0), paidOrdersPrice.GetValueOrDefault(key, 0)); + } + + + await dao.DaoExt.Context.SaveChangesAsync(); + - // 更新或创建统计记录 void UpdateStatistics(string channel, int intendedOrderCount, int paidOrders, decimal rechargeAmount) { if (!orderStatistics.TryGetValue(channel, out var statisticsUser)) @@ -127,17 +148,6 @@ public class OrderHourMonitorProcessor : AppJobBase statisticsUser.PaidOrders = paidOrders; statisticsUser.UpdatedAt = DateTime.Now; } - var list = dao.DaoExt.Context.T_App_Channel.ToList(); - foreach (var item in list) - { - var key = item.ChannelId; - UpdateStatistics(key, intendedOrder.GetValueOrDefault(key, 0), paidOrders.GetValueOrDefault(key, 0), paidOrdersPrice.GetValueOrDefault(key, 0)); - } - foreach (var item in intendedOrder) - { - } - - await dao.DaoExt.Context.SaveChangesAsync(); } } diff --git a/src/CloudGaming/Code/CloudGaming.Code/Monitor/UserMonitorProcessor.cs b/src/CloudGaming/Code/CloudGaming.Code/Monitor/UserMonitorProcessor.cs index a1989f2..290aa6b 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Monitor/UserMonitorProcessor.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Monitor/UserMonitorProcessor.cs @@ -14,7 +14,7 @@ namespace CloudGaming.Code.Monitor; /// /// 用户定时类 /// -[QuartzTrigger("UserMonitorProcessor", "* 15 4 * * ?")] +[QuartzTrigger("UserMonitorProcessor", "* 25 4 * * ?")] public class UserMonitorProcessor : AppJobBase { public UserMonitorProcessor(IServiceScopeFactory scopeFactory) : base(scopeFactory) @@ -72,12 +72,17 @@ public class UserMonitorProcessor : AppJobBase statisticsUser.ActiveCount = activeCount; statisticsUser.UpdatedAt = DateTime.Now; } - - foreach (var item in todayLoggedInUsers) + var list = dao.DaoExt.Context.T_App_Channel.ToList(); + foreach (var item in list) { - UpdateStatistics(item.Key, item.Value, todayRegisteredUsers.GetValueOrDefault(item.Key, 0), todayActionUsers.GetValueOrDefault(item.Key, 0)); - } + var key = item.ChannelId; + if (string.IsNullOrEmpty(key)) + { + key = "27001"; + } + UpdateStatistics(key, todayLoggedInUsers.GetValueOrDefault(key, 0), todayRegisteredUsers.GetValueOrDefault(key, 0), todayActionUsers.GetValueOrDefault(key, 0)); + } await dao.DaoExt.Context.SaveChangesAsync(); }