feat: 完成积分、价值排行榜

This commit is contained in:
chenchun
2024-11-13 19:01:23 +08:00
parent f9217dc066
commit bf2bcd1395
14 changed files with 358 additions and 16 deletions

View File

@@ -0,0 +1,54 @@
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Analyse;
using Yi.Framework.DigitalCollectibles.Application.Contracts.IServices;
using Yi.Framework.DigitalCollectibles.Domain.Entities;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.DigitalCollectibles.Application.Services.Analyses;
/// <summary>
/// 用户积分分析
/// </summary>
public class PointAnalyseService: ApplicationService,IPointAnalyseService
{
private readonly ISqlSugarRepository<InvitationCodeAggregateRoot> _repository;
public PointAnalyseService(ISqlSugarRepository<InvitationCodeAggregateRoot> repository)
{
_repository = repository;
}
/// <summary>
/// 积分排行榜
/// </summary>
/// <returns></returns>
// [HttpGet("analyse/dc-user/points-top/{userId?}")]
[RemoteService(isEnabled:false)]
public async Task<PagedResultDto<DcPointsTopUserDto>> GetValueTopAsync([FromQuery] PagedResultRequestDto input,
[FromRoute] Guid? userId)
{
var pageIndex = input.SkipCount;
RefAsync<int> total = 0;
var output = await _repository._DbQueryable
.OrderByDescending(x=>x.PointsNumber)
.Select(x =>
new DcPointsTopUserDto{
UserId = x.UserId,
Points = x.PointsNumber,
Order=SqlFunc.RowNumber(SqlFunc.Desc(x.PointsNumber))
})
.ToPageListAsync(pageIndex, input.MaxResultCount, total);
return new PagedResultDto<DcPointsTopUserDto>
{
Items = output,
TotalCount = total
};
}
}

View File

@@ -0,0 +1,48 @@
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Analyse;
using Yi.Framework.DigitalCollectibles.Application.Contracts.IServices;
using Yi.Framework.DigitalCollectibles.Domain.Entities;
using Yi.Framework.DigitalCollectibles.Domain.Managers;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.DigitalCollectibles.Application.Services.Analyses;
public class ValueAnalyseService: ApplicationService,IValueAnalyseService
{
private readonly CollectiblesManager _manager;
public ValueAnalyseService( CollectiblesManager manager)
{
_manager = manager;
}
/// <summary>
/// 价值排行榜
/// </summary>
/// <returns></returns>
// [HttpGet("analyse/dc-user/value-top/{userId?}")]
[RemoteService(isEnabled:false)]
public async Task<PagedResultDto<DcValueTopUserDto>> GetValueTopAsync([FromQuery] PagedResultRequestDto input,
[FromRoute] Guid? userId)
{
//每个人的价值需要进行计算才能获取,这里计算时间较长,放入缓存,绝对过期
var allValue= await _manager.GetAllAccountValueByCacheAsync();
var output = allValue.OrderByDescending(x => x.value).Select((x, index) => new DcValueTopUserDto
{
UserId = x.userId,
Value = x.value,
Order = index + 1
}).Skip((input.SkipCount - 1) * input.MaxResultCount) // 跳过前面(当前页码 - 1* 每页数量条记录
.Take(input.MaxResultCount).ToList();
return new PagedResultDto<DcValueTopUserDto>
{
Items = output,
TotalCount = allValue.Count
};
}
}