feat: 添加等级名称显示
This commit is contained in:
@@ -30,5 +30,10 @@ namespace Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser
|
||||
/// 经验
|
||||
/// </summary>
|
||||
public long Experience { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户等级名称
|
||||
/// </summary>
|
||||
public string LevelName { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Linq;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using TencentCloud.Pds.V20210701.Models;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Application.Dtos;
|
||||
using Volo.Abp.EventBus.Local;
|
||||
@@ -32,12 +33,14 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
IDiscussService
|
||||
{
|
||||
private ISqlSugarRepository<DiscussTopEntity> _discussTopEntityRepository;
|
||||
public DiscussService(ForumManager forumManager, ISqlSugarRepository<DiscussTopEntity> discussTopEntityRepository, ISqlSugarRepository<PlateEntity> plateEntityRepository, ILocalEventBus localEventBus) : base(forumManager._discussRepository)
|
||||
private BbsUserManager _bbsUserManager;
|
||||
public DiscussService(BbsUserManager bbsUserManager, ForumManager forumManager, ISqlSugarRepository<DiscussTopEntity> discussTopEntityRepository, ISqlSugarRepository<PlateEntity> plateEntityRepository, ILocalEventBus localEventBus) : base(forumManager._discussRepository)
|
||||
{
|
||||
_forumManager = forumManager;
|
||||
_plateEntityRepository = plateEntityRepository;
|
||||
_localEventBus = localEventBus;
|
||||
_discussTopEntityRepository = discussTopEntityRepository;
|
||||
_bbsUserManager=bbsUserManager;
|
||||
}
|
||||
private readonly ILocalEventBus _localEventBus;
|
||||
private ForumManager _forumManager { get; set; }
|
||||
@@ -143,6 +146,8 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
|
||||
//查询完主题之后,要过滤一下私有的主题信息
|
||||
items.ApplyPermissionTypeFilter(CurrentUser.Id ?? Guid.Empty);
|
||||
|
||||
items?.ForEach(x => x.User.LevelName = _bbsUserManager._levelCacheDic[x.User.Level].Name);
|
||||
return new PagedResultDto<DiscussGetListOutputDto>(total, items);
|
||||
}
|
||||
|
||||
@@ -178,11 +183,11 @@ namespace Yi.Framework.Bbs.Application.Services.Forum
|
||||
Remark = user.Remark,
|
||||
UserLimit = info.UserLimit,
|
||||
Money = info.Money,
|
||||
Experience = info.Experience
|
||||
|
||||
Experience = info.Experience,
|
||||
}
|
||||
}, true)
|
||||
.ToListAsync();
|
||||
output?.ForEach(x => x.User.LevelName = _bbsUserManager._levelCacheDic[x.User.Level].Name);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Shared.Caches
|
||||
{
|
||||
public class LevelCacheItem
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前等级
|
||||
/// </summary>
|
||||
public int CurrentLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最小所需经验值
|
||||
/// </summary>
|
||||
public decimal MinExperience { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 等级名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 等级称号
|
||||
/// </summary>
|
||||
public string? Nick { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 等候logo
|
||||
/// </summary>
|
||||
public string? Logo { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Shared.Consts
|
||||
{
|
||||
public class LevelConst
|
||||
{
|
||||
public const string LevelCacheKey=nameof(LevelCacheKey);
|
||||
}
|
||||
}
|
||||
@@ -48,4 +48,5 @@ namespace Yi.Framework.Bbs.Domain.Entities.Integral
|
||||
public string? Logo { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Yi.Framework.Bbs.Domain.Entities;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Caches;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.Rbac.Domain.Entities;
|
||||
using Yi.Framework.Rbac.Domain.Shared.Enums;
|
||||
@@ -16,43 +14,60 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
||||
{
|
||||
public ISqlSugarRepository<UserEntity> _userRepository;
|
||||
public ISqlSugarRepository<BbsUserExtraInfoEntity> _bbsUserInfoRepository;
|
||||
public BbsUserManager(ISqlSugarRepository<UserEntity> userRepository, ISqlSugarRepository<BbsUserExtraInfoEntity> bbsUserInfoRepository)
|
||||
public Dictionary<int,LevelCacheItem> _levelCacheDic;
|
||||
public BbsUserManager(ISqlSugarRepository<UserEntity> userRepository,
|
||||
ISqlSugarRepository<BbsUserExtraInfoEntity> bbsUserInfoRepository,
|
||||
IDistributedCache<List<LevelCacheItem>> levelCache
|
||||
)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_bbsUserInfoRepository = bbsUserInfoRepository;
|
||||
_levelCacheDic = levelCache.Get(LevelConst.LevelCacheKey).ToDictionary(x => x.CurrentLevel);
|
||||
}
|
||||
|
||||
public async Task<BbsUserInfoDto?> GetBbsUserInfoAsync(Guid userId)
|
||||
{
|
||||
return await _userRepository._DbQueryable.LeftJoin<BbsUserExtraInfoEntity>((user, info) => user.Id == info.UserId)
|
||||
.Select((user, info) => new BbsUserInfoDto {
|
||||
Id = user.Id ,
|
||||
Icon=user.Icon,
|
||||
Level=info.Level,
|
||||
UserLimit=info.UserLimit,
|
||||
Money = info.Money,
|
||||
Experience = info.Experience,
|
||||
AgreeNumber=info.AgreeNumber,
|
||||
CommentNumber=info.CommentNumber,
|
||||
DiscussNumber=info.DiscussNumber
|
||||
}, true)
|
||||
.FirstAsync(user => user.Id==userId);
|
||||
}
|
||||
|
||||
public async Task<List<BbsUserInfoDto>> GetBbsUserInfoAsync(List<Guid> userIds)
|
||||
{
|
||||
return await _userRepository._DbQueryable
|
||||
.Where(user => userIds.Contains(user.Id))
|
||||
.LeftJoin<BbsUserExtraInfoEntity>((user, info) => user.Id == info.UserId)
|
||||
.Select((user, info) => new BbsUserInfoDto { Id = user.Id , Icon = user.Icon , Level = info.Level, UserLimit = info.UserLimit,
|
||||
var userInfo = await _userRepository._DbQueryable.LeftJoin<BbsUserExtraInfoEntity>((user, info) => user.Id == info.UserId)
|
||||
.Select((user, info) => new BbsUserInfoDto
|
||||
{
|
||||
Id = user.Id,
|
||||
Icon = user.Icon,
|
||||
Level = info.Level,
|
||||
UserLimit = info.UserLimit,
|
||||
Money = info.Money,
|
||||
Experience = info.Experience,
|
||||
AgreeNumber = info.AgreeNumber,
|
||||
CommentNumber = info.CommentNumber,
|
||||
DiscussNumber = info.DiscussNumber
|
||||
},true)
|
||||
|
||||
}, true)
|
||||
.FirstAsync(user => user.Id == userId);
|
||||
|
||||
userInfo.LevelName = _levelCacheDic[userInfo.Level].Name;
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
public async Task<List<BbsUserInfoDto>> GetBbsUserInfoAsync(List<Guid> userIds)
|
||||
{
|
||||
var userInfos= await _userRepository._DbQueryable
|
||||
.Where(user => userIds.Contains(user.Id))
|
||||
.LeftJoin<BbsUserExtraInfoEntity>((user, info) => user.Id == info.UserId)
|
||||
.Select((user, info) => new BbsUserInfoDto
|
||||
{
|
||||
Id = user.Id,
|
||||
Icon = user.Icon,
|
||||
Level = info.Level,
|
||||
UserLimit = info.UserLimit,
|
||||
Money = info.Money,
|
||||
Experience = info.Experience,
|
||||
AgreeNumber = info.AgreeNumber,
|
||||
CommentNumber = info.CommentNumber,
|
||||
DiscussNumber = info.DiscussNumber
|
||||
}, true)
|
||||
|
||||
.ToListAsync();
|
||||
userInfos?.ForEach(userInfo => userInfo.LevelName = _levelCacheDic[userInfo.Level].Name);
|
||||
|
||||
return userInfos??new List<BbsUserInfoDto>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +94,11 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
||||
/// </summary>
|
||||
public int Level { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户等级名称
|
||||
/// </summary>
|
||||
public string LevelName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户限制
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
using Volo.Abp.Modularity;
|
||||
using System.Collections.Generic;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.Modularity;
|
||||
using Yi.Framework.Bbs.Domain.Entities.Integral;
|
||||
using Yi.Framework.Bbs.Domain.Shared;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Caches;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Consts;
|
||||
using Yi.Framework.Rbac.Domain;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain
|
||||
@@ -11,6 +20,14 @@ namespace Yi.Framework.Bbs.Domain
|
||||
)]
|
||||
public class YiFrameworkBbsDomainModule : AbpModule
|
||||
{
|
||||
|
||||
public override async Task OnPostApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
//加载等级缓存
|
||||
var services = context.ServiceProvider;
|
||||
var levelRepository = services.GetRequiredService<IRepository<LevelEntity>>();
|
||||
var levelCache = services.GetRequiredService<IDistributedCache<List<LevelCacheItem>>>();
|
||||
var cacheItem = (await levelRepository.GetListAsync()).Adapt<List<LevelCacheItem>>();
|
||||
await levelCache.SetAsync(LevelConst.LevelCacheKey, cacheItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user