From 87b0ae0a2aca16763bf054c4c785323e36f68387 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期三, 11 六月 2025 17:46:28 +0800 Subject: [PATCH] fix:用户端--我的--数据看板,昨日活跃用户数据统计不正确,统计的是登录账号所配置的渠道中昨日进行充值且充值成功的用户记录 --- LifePayment/LifePayment.Domain/LogRecord/LogFrontRecord.cs | 41 +++++++++++++ LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml | 7 ++ LifePayment/LifePayment.HttpApi/LifePay/LogController.cs | 27 ++------ LifePayment/LifePayment.Application.Contracts/LogRecord/ILogService.cs | 19 ++++++ LifePayment/LifePayment.Host/appsettings.Development.json | 4 + LifePayment/LifePayment.Application/LogRecord/LogService.cs | 51 +++++++++++++++++ LifePayment/LifePayment.EntityFrameworkCore/LifePaymentServicesDbContext.cs | 2 LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml | 2 LifePayment/LifePayment.Application/LifePay/StatisticsService.cs | 9 ++ LifePayment/LifePayment.Application/LifePaymentServicesApplicationModuleAutoMapperProfile.cs | 3 + 10 files changed, 141 insertions(+), 24 deletions(-) diff --git a/LifePayment/LifePayment.Application.Contracts/LogRecord/ILogService.cs b/LifePayment/LifePayment.Application.Contracts/LogRecord/ILogService.cs new file mode 100644 index 0000000..7f21789 --- /dev/null +++ b/LifePayment/LifePayment.Application.Contracts/LogRecord/ILogService.cs @@ -0,0 +1,19 @@ +锘縰sing LifePayment.Domain.Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LifePayment.Application.Contracts +{ + public interface ILogService + { + /// <summary> + /// 璁板綍鍓嶇鏃ュ織 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + Task LogFront(LogFrontInput input); + } +} diff --git a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs index 7438b91..24dd202 100644 --- a/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs +++ b/LifePayment/LifePayment.Application/LifePay/StatisticsService.cs @@ -347,8 +347,13 @@ /// 鏄ㄦ棩娲昏穬鐢ㄦ埛 var yesterdayActiveUsers = await (from a in _lifePayUserRepository join b in _lifePayOrderRepository on a.Id equals b.UserId - where b.CreationTime >= today.AddDays(-1) && b.CreationTime < today - && (b.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�间腑 || b.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�兼垚鍔� || b.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� || b.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�) + where + b.CreationTime >= today.AddDays(-1) + && b.CreationTime < today + && (channleId == null || channleId == "" || a.CreationChannleNum == channleId) + && (b.ACOOLYStatus == ACOOLYStatusEnum.鍏呭�兼垚鍔� + || b.ACOOLYStatus == ACOOLYStatusEnum.宸插畬鎴� + || b.ACOOLYStatus == ACOOLYStatusEnum.閮ㄥ垎鍏呭�兼垚鍔�) select b).Distinct().CountAsync(); /// 绱浣i噾 var accumulatedChannlesRakePrice = await _lifePayChannlesRakeRepository.Where(x => x.FinishTime < today) diff --git a/LifePayment/LifePayment.Application/LifePaymentServicesApplicationModuleAutoMapperProfile.cs b/LifePayment/LifePayment.Application/LifePaymentServicesApplicationModuleAutoMapperProfile.cs index 8dce535..12a9b84 100644 --- a/LifePayment/LifePayment.Application/LifePaymentServicesApplicationModuleAutoMapperProfile.cs +++ b/LifePayment/LifePayment.Application/LifePaymentServicesApplicationModuleAutoMapperProfile.cs @@ -4,6 +4,7 @@ using LifePayment.Domain; using LifePayment.Domain.LifePay; using LifePayment.Domain.Models; +using LifePayment.Domain.Shared; namespace LifePayment.Application { @@ -37,6 +38,8 @@ CreateMap<CreateChannelConsultationInput, LifePayChannelConsultation>(MemberList.None); CreateMap<CreateChannelConsultationFollowupInput, LifePayChannelConsultationFollowup>(MemberList.None); + + CreateMap<LogFrontInput, LogFrontRecord>(MemberList.None); } } } \ No newline at end of file diff --git a/LifePayment/LifePayment.Application/LogRecord/LogService.cs b/LifePayment/LifePayment.Application/LogRecord/LogService.cs new file mode 100644 index 0000000..dc7b840 --- /dev/null +++ b/LifePayment/LifePayment.Application/LogRecord/LogService.cs @@ -0,0 +1,51 @@ +锘� + +using LifePayment.Application.Contracts; +using LifePayment.Domain; +using LifePayment.Domain.Shared; +using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; + +namespace LifePayment.Application +{ + public class LogService : ApplicationService, ILogService + { + private readonly ILogger<LogService> logger; + private readonly IHttpContextAccessor httpContextAccessor; + private readonly IRepository<LogFrontRecord, Guid> logFrontRepository; + + public LogService( + ILogger<LogService> logger, + IHttpContextAccessor httpContextAccessor, + IRepository<LogFrontRecord, Guid> logFrontRepository) + { + this.logger = logger; + this.httpContextAccessor = httpContextAccessor; + this.logFrontRepository = logFrontRepository; + } + + /// <summary> + /// 璁板綍鍓嶇鏃ュ織 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + public async Task LogFront(LogFrontInput input) + { + var log = new LogFrontRecord(); + ObjectMapper.Map(input, log); + if (log.UserId == null) + { + log.UserId = CurrentUser?.Id; + } + log.IpAddress = httpContextAccessor.HttpContext?.Connection?.RemoteIpAddress?.ToString(); + logger.LogInformation($"鍓嶇鏃ュ織锛歿log.IpAddress}-{log.UserId}-{log.Url}-{log.RequestTime}-{log.Message}"); + + //await logFrontRepository.InsertAsync(log); + } + } +} diff --git a/LifePayment/LifePayment.Domain/LogRecord/LogFrontRecord.cs b/LifePayment/LifePayment.Domain/LogRecord/LogFrontRecord.cs new file mode 100644 index 0000000..63b3903 --- /dev/null +++ b/LifePayment/LifePayment.Domain/LogRecord/LogFrontRecord.cs @@ -0,0 +1,41 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Domain.Entities.Auditing; + +namespace LifePayment.Domain +{ + /// <summary> + /// 鍓嶇鏃ュ織 + /// </summary> + public class LogFrontRecord : FullAuditedEntity<Guid>, IDataUserFilter + { + /// <summary> + /// 鐢ㄦ埛Id + /// </summary> + public Guid? UserId { get; set; } + + /// <summary> + /// 娑堟伅 + /// </summary> + public string Message { get; set; } + + /// <summary> + /// 鍦板潃 + /// </summary> + public string Url { get; set; } + + /// <summary> + /// 璇锋眰鏃堕棿 + /// </summary> + public DateTime? RequestTime { get; set; } + + /// <summary> + /// IP鍦板潃 + /// </summary> + public string IpAddress { get; set; } + } +} diff --git a/LifePayment/LifePayment.EntityFrameworkCore/LifePaymentServicesDbContext.cs b/LifePayment/LifePayment.EntityFrameworkCore/LifePaymentServicesDbContext.cs index ff2b377..b8a7052 100644 --- a/LifePayment/LifePayment.EntityFrameworkCore/LifePaymentServicesDbContext.cs +++ b/LifePayment/LifePayment.EntityFrameworkCore/LifePaymentServicesDbContext.cs @@ -17,6 +17,8 @@ { } + public virtual DbSet<LogFrontRecord> LogFrontRecord { get; set; } + public virtual DbSet<LifePayPromoter> LifePayPromoter { get; set; } public virtual DbSet<LifePayChannelConsultation> LifePayChannelConsultation { get; set; } diff --git a/LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml b/LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml index c7324dc..59af98a 100644 --- a/LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml +++ b/LifePayment/LifePayment.Host/LifePaymentService.HttpApi.xml @@ -513,7 +513,7 @@ <param name="input"></param> <returns></returns> </member> - <member name="M:LifePayment.HttpApi.LifePay.LogController.LogFront(LifePayment.Domain.Shared.LogFrontInput)"> + <member name="M:LifePayment.HttpApi.LogController.LogFront(LifePayment.Domain.Shared.LogFrontInput)"> <summary> 璁板綍鍓嶇鏃ュ織 </summary> diff --git a/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml b/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml index fd6f6ef..ae83b50 100644 --- a/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml +++ b/LifePayment/LifePayment.Host/LifePaymentServices.Application.Contracts.xml @@ -2239,6 +2239,13 @@ 缁撶畻鏃堕棿 </summary> </member> + <member name="M:LifePayment.Application.Contracts.ILogService.LogFront(LifePayment.Domain.Shared.LogFrontInput)"> + <summary> + 璁板綍鍓嶇鏃ュ織 + </summary> + <param name="input"></param> + <returns></returns> + </member> <member name="P:LifePayment.Application.Contracts.GetChannelConsultationsInput.StartDate"> <summary> 鍒涘缓鐨勫紑濮嬫椂闂� diff --git a/LifePayment/LifePayment.Host/appsettings.Development.json b/LifePayment/LifePayment.Host/appsettings.Development.json index 8983e0f..529dcbb 100644 --- a/LifePayment/LifePayment.Host/appsettings.Development.json +++ b/LifePayment/LifePayment.Host/appsettings.Development.json @@ -3,7 +3,9 @@ "LogLevel": { "Default": "Information", "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.Hosting.Lifetime": "Information", + "Microsoft.EntityFrameworkCore": "Debug", + "Microsoft.EntityFrameworkCore.Database.Command": "Trace" } } } diff --git a/LifePayment/LifePayment.HttpApi/LifePay/LogController.cs b/LifePayment/LifePayment.HttpApi/LifePay/LogController.cs index 33d74d0..c00fb9a 100644 --- a/LifePayment/LifePayment.HttpApi/LifePay/LogController.cs +++ b/LifePayment/LifePayment.HttpApi/LifePay/LogController.cs @@ -1,31 +1,19 @@ -锘縰sing Castle.Core.Logging; -using LifePayment.Application.Sync; +锘縰sing LifePayment.Application.Contracts; using LifePayment.Domain.Shared; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Volo.Abp.AspNetCore.Mvc; -using ZeroD.Util; -namespace LifePayment.HttpApi.LifePay +namespace LifePayment.HttpApi { [Route("api/[controller]/[action]")] [ApiController] public class LogController : AbpController { - private readonly ILogger<LogController> logger; - private readonly IHttpContextAccessor httpContextAccessor; + private readonly ILogService logService; - public LogController( - ILogger<LogController> logger, - IHttpContextAccessor httpContextAccessor) + public LogController(ILogService logService) { - this.logger = logger; - this.httpContextAccessor = httpContextAccessor; + this.logService = logService; } /// <summary> @@ -33,10 +21,9 @@ /// </summary> /// <returns></returns> [HttpPost] - public void LogFront(LogFrontInput message) + public async void LogFront(LogFrontInput message) { - string ip = httpContextAccessor.HttpContext?.Connection?.RemoteIpAddress?.ToString(); - logger.LogInformation($"鍓嶇鏃ュ織锛圛P-{ip}锛夛細{message.ToJson()}"); + await logService.LogFront(message); } } } -- Gitblit v1.9.1