feat: 完成积分、价值排行榜
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser;
|
||||
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Analyse;
|
||||
|
||||
public class MoneyTopUserDto
|
||||
/// <summary>
|
||||
/// 用户排行榜
|
||||
/// </summary>
|
||||
public class BaseAnalyseTopUserDto
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string? Nick { get; set; }
|
||||
public decimal Money { get; set; }
|
||||
public int Order { get; set; }
|
||||
public string? Icon { get; set; }
|
||||
public int Level { get; set; }
|
||||
@@ -18,5 +21,4 @@ public class MoneyTopUserDto
|
||||
/// 用户限制
|
||||
/// </summary>
|
||||
public UserLimitEnum UserLimit { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Analyse;
|
||||
|
||||
public class MoneyTopUserDto:BaseAnalyseTopUserDto
|
||||
{
|
||||
public decimal Money { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Analyse;
|
||||
|
||||
public class PointsTopUserDto:BaseAnalyseTopUserDto
|
||||
{
|
||||
public int Points { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Analyse;
|
||||
|
||||
public class ValueTopUserDto:BaseAnalyseTopUserDto
|
||||
{
|
||||
public decimal Value { get; set; }
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\digital-collectibles\Yi.Framework.DigitalCollectibles.Application.Contracts\Yi.Framework.DigitalCollectibles.Application.Contracts.csproj" />
|
||||
<ProjectReference Include="..\..\rbac\Yi.Framework.Rbac.Application.Contracts\Yi.Framework.Rbac.Application.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Bbs.Domain.Shared\Yi.Framework.Bbs.Domain.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -9,6 +9,7 @@ using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Entities.Integral;
|
||||
using Yi.Framework.Bbs.Domain.Managers;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.DigitalCollectibles.Application.Contracts.IServices;
|
||||
using Yi.Framework.Rbac.Application.Contracts.IServices;
|
||||
using Yi.Framework.Rbac.Domain.Authorization;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
||||
@@ -20,11 +21,16 @@ namespace Yi.Framework.Bbs.Application.Services.Analyses
|
||||
{
|
||||
private BbsUserManager _bbsUserManager;
|
||||
private IOnlineService _onlineService;
|
||||
private readonly IPointAnalyseService _pointAnalyseService;
|
||||
private readonly IValueAnalyseService _valueAnalyseService;
|
||||
|
||||
public BbsUserAnalyseService(BbsUserManager bbsUserManager, IOnlineService onlineService)
|
||||
public BbsUserAnalyseService(BbsUserManager bbsUserManager, IOnlineService onlineService,
|
||||
IPointAnalyseService pointAnalyseService, IValueAnalyseService valueAnalyseService)
|
||||
{
|
||||
_bbsUserManager = bbsUserManager;
|
||||
_onlineService = onlineService;
|
||||
_pointAnalyseService = pointAnalyseService;
|
||||
_valueAnalyseService = valueAnalyseService;
|
||||
}
|
||||
|
||||
|
||||
@@ -169,5 +175,116 @@ namespace Yi.Framework.Bbs.Application.Services.Analyses
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 积分排行榜
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("analyse/dc-user/points-top/{userId?}")]
|
||||
public async Task<PagedResultDto<PointsTopUserDto>> GetPointsTopAsync([FromQuery] PagedResultRequestDto input,
|
||||
[FromRoute] Guid? userId)
|
||||
{
|
||||
var result = await _pointAnalyseService.GetValueTopAsync(input, null);
|
||||
|
||||
var userIds = result.Items.Select(x => x.UserId).ToList();
|
||||
|
||||
var baseOutput = await _bbsUserManager._userRepository._DbQueryable
|
||||
.Where(u => userIds.Contains(u.Id))
|
||||
.LeftJoin<BbsUserExtraInfoEntity>((u, info) => u.Id == info.UserId)
|
||||
.Select((u, info) =>
|
||||
new BaseAnalyseTopUserDto
|
||||
{
|
||||
UserName = u.UserName,
|
||||
Nick = u.Nick,
|
||||
Icon = u.Icon,
|
||||
Level = info.Level,
|
||||
UserLimit = info.UserLimit,
|
||||
UserId = info.UserId
|
||||
}
|
||||
).ToListAsync();
|
||||
|
||||
|
||||
var output = new List<PointsTopUserDto>();
|
||||
result.Items.ToList().ForEach(x =>
|
||||
{
|
||||
var currentUserInfo = baseOutput.Where(u => u.UserId == x.UserId).FirstOrDefault();
|
||||
|
||||
if (currentUserInfo is not null)
|
||||
{
|
||||
output.Add(new PointsTopUserDto
|
||||
{
|
||||
UserName = currentUserInfo.UserName,
|
||||
Nick = currentUserInfo.Nick,
|
||||
Order = x.Order,
|
||||
Icon = currentUserInfo.Icon,
|
||||
Level = currentUserInfo.Level,
|
||||
LevelName = _bbsUserManager._levelCacheDic[currentUserInfo.Level].Name,
|
||||
UserLimit = UserLimitEnum.Normal,
|
||||
Points = x.Points
|
||||
});
|
||||
}
|
||||
});
|
||||
return new PagedResultDto<PointsTopUserDto>
|
||||
{
|
||||
Items = output,
|
||||
TotalCount = result.TotalCount
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 价值排行榜
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("analyse/dc-user/value-top/{userId?}")]
|
||||
public async Task<PagedResultDto<ValueTopUserDto>> GetValueTopAsync([FromQuery] PagedResultRequestDto input,
|
||||
[FromRoute] Guid? userId)
|
||||
{
|
||||
var result = await _valueAnalyseService.GetValueTopAsync(input, null);
|
||||
|
||||
var userIds = result.Items.Select(x => x.UserId).ToList();
|
||||
|
||||
var baseOutput = await _bbsUserManager._userRepository._DbQueryable
|
||||
.Where(u => userIds.Contains(u.Id))
|
||||
.LeftJoin<BbsUserExtraInfoEntity>((u, info) => u.Id == info.UserId)
|
||||
.Select((u, info) =>
|
||||
new BaseAnalyseTopUserDto
|
||||
{
|
||||
UserName = u.UserName,
|
||||
Nick = u.Nick,
|
||||
Icon = u.Icon,
|
||||
Level = info.Level,
|
||||
UserLimit = info.UserLimit,
|
||||
UserId = info.UserId
|
||||
}
|
||||
).ToListAsync();
|
||||
|
||||
|
||||
var output = new List<ValueTopUserDto>();
|
||||
result.Items.ToList().ForEach(x =>
|
||||
{
|
||||
var currentUserInfo = baseOutput.Where(u => u.UserId == x.UserId).FirstOrDefault();
|
||||
|
||||
if (currentUserInfo is not null)
|
||||
{
|
||||
output.Add(new ValueTopUserDto
|
||||
{
|
||||
UserName = currentUserInfo.UserName,
|
||||
Nick = currentUserInfo.Nick,
|
||||
Order = x.Order,
|
||||
Icon = currentUserInfo.Icon,
|
||||
Level = currentUserInfo.Level,
|
||||
LevelName = _bbsUserManager._levelCacheDic[currentUserInfo.Level].Name,
|
||||
UserLimit = UserLimitEnum.Normal,
|
||||
Value = x.Value
|
||||
});
|
||||
}
|
||||
});
|
||||
return new PagedResultDto<ValueTopUserDto>
|
||||
{
|
||||
Items = output,
|
||||
TotalCount = result.TotalCount
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Analyse;
|
||||
|
||||
public class DcPointsTopUserDto
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public int Points { get; set; }
|
||||
|
||||
public int Order { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Analyse;
|
||||
|
||||
public class DcValueTopUserDto
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public decimal Value { get; set; }
|
||||
|
||||
public int Order { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Analyse;
|
||||
|
||||
namespace Yi.Framework.DigitalCollectibles.Application.Contracts.IServices;
|
||||
|
||||
public interface IPointAnalyseService
|
||||
{
|
||||
/// <summary>
|
||||
/// 积分排行榜
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
// [HttpGet("analyse/dc-user/points-top/{userId?}")]
|
||||
Task<PagedResultDto<DcPointsTopUserDto>> GetValueTopAsync([FromQuery] PagedResultRequestDto input,
|
||||
[FromRoute] Guid? userId);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Yi.Framework.DigitalCollectibles.Application.Contracts.Dtos.Analyse;
|
||||
|
||||
namespace Yi.Framework.DigitalCollectibles.Application.Contracts.IServices;
|
||||
|
||||
public interface IValueAnalyseService
|
||||
{
|
||||
/// <summary>
|
||||
/// 价值排行榜
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
// [HttpGet("analyse/dc-user/value-top/{userId?}")]
|
||||
Task<PagedResultDto<DcValueTopUserDto>> GetValueTopAsync([FromQuery] PagedResultRequestDto input,
|
||||
[FromRoute] Guid? userId);
|
||||
}
|
||||
@@ -7,8 +7,4 @@
|
||||
<ProjectReference Include="..\..\rbac\Yi.Framework.Rbac.Application.Contracts\Yi.Framework.Rbac.Application.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="IServices\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Yi.Framework.DigitalCollectibles.Domain.Shared.Caches;
|
||||
|
||||
public class CollectiblesValueCacheItem
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public decimal Value { get; set; }
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.DigitalCollectibles.Domain.Entities;
|
||||
using Yi.Framework.DigitalCollectibles.Domain.Shared.Caches;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.DigitalCollectibles.Domain.Managers;
|
||||
@@ -11,13 +14,20 @@ namespace Yi.Framework.DigitalCollectibles.Domain.Managers;
|
||||
public class CollectiblesManager:DomainService
|
||||
{
|
||||
private readonly ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> _collectiblesUserStoreRepository;
|
||||
|
||||
public CollectiblesManager(ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> collectiblesUserStoreRepository)
|
||||
private readonly ISqlSugarRepository<CollectiblesAggregateRoot> _collectiblesRepository;
|
||||
private readonly IDistributedCache<List<CollectiblesValueCacheItem>> _distributedCache;
|
||||
public CollectiblesManager(ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> collectiblesUserStoreRepository, ISqlSugarRepository<CollectiblesAggregateRoot> collectiblesRepository, IDistributedCache<List<CollectiblesValueCacheItem>> distributedCache)
|
||||
{
|
||||
_collectiblesUserStoreRepository = collectiblesUserStoreRepository;
|
||||
_collectiblesRepository = collectiblesRepository;
|
||||
_distributedCache = distributedCache;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取某个用户的价值
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<decimal> GetAccountValueAsync(Guid userId)
|
||||
{
|
||||
var collectiblesList = await _collectiblesUserStoreRepository._DbQueryable
|
||||
@@ -30,7 +40,14 @@ public class CollectiblesManager:DomainService
|
||||
c.ValueNumber
|
||||
}
|
||||
).ToListAsync();
|
||||
var groupBy = collectiblesList.GroupBy(x => x.Id);
|
||||
var totalValue=ComputeValue(collectiblesList.Select(x=> (x.Id,x.ValueNumber)).ToList());
|
||||
return totalValue;
|
||||
}
|
||||
|
||||
//计算价值,需要每个藏品的唯一值和藏品的价值即可
|
||||
private decimal ComputeValue(List<(Guid collectiblesId,decimal valueNumber)> data)
|
||||
{
|
||||
var groupBy = data.GroupBy(x => x.collectiblesId);
|
||||
decimal totalValue = 0;
|
||||
|
||||
//首个价值百分之百,后续每个只有百分之40,最大10个
|
||||
@@ -41,7 +58,7 @@ public class CollectiblesManager:DomainService
|
||||
|
||||
if (item.index == 0)
|
||||
{
|
||||
totalValue += item.value.ValueNumber;
|
||||
totalValue += item.value.valueNumber;
|
||||
}
|
||||
else if (item.index == 10)
|
||||
{
|
||||
@@ -50,11 +67,48 @@ public class CollectiblesManager:DomainService
|
||||
}
|
||||
else
|
||||
{
|
||||
totalValue += item.value.ValueNumber * 0.4m;
|
||||
totalValue += item.value.valueNumber * 0.4m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return totalValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全量的排行榜
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CollectiblesValueCacheItem>> GetAllAccountValueByCacheAsync()
|
||||
{
|
||||
return await _distributedCache.GetOrAddAsync("AllAccountValue", async () => await GetAccountValueAsync(),
|
||||
() => new DistributedCacheEntryOptions()
|
||||
{
|
||||
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1)
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<List<CollectiblesValueCacheItem>> GetAccountValueAsync()
|
||||
{
|
||||
var output = new List<CollectiblesValueCacheItem>();
|
||||
//获取全部用户的库存
|
||||
var allStore= await _collectiblesUserStoreRepository._DbQueryable.ToListAsync();
|
||||
//获取全部藏品
|
||||
var allCollectiblesDic= (await _collectiblesRepository._DbQueryable.ToListAsync()).ToDictionary(x=>x.Id,y=>y.ValueNumber);
|
||||
|
||||
//根据用户分组
|
||||
var userGroup= allStore.GroupBy(x => x.UserId);
|
||||
//每个用户进行计算价值
|
||||
foreach (var item in userGroup)
|
||||
{
|
||||
var value= ComputeValue(item.Select(x => (x.CollectiblesId, allCollectiblesDic[x.CollectiblesId])).ToList());
|
||||
output.Add(new CollectiblesValueCacheItem
|
||||
{
|
||||
UserId = item.Key,
|
||||
Value = value
|
||||
});
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user