diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/BbsUser/BbsUserGetOutputDto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/BbsUser/BbsUserGetOutputDto.cs index b0167102..cce27810 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/BbsUser/BbsUserGetOutputDto.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/BbsUser/BbsUserGetOutputDto.cs @@ -3,11 +3,21 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Yi.Framework.Bbs.Domain.Shared.Enums; using Yi.Framework.Rbac.Application.Contracts.Dtos.User; namespace Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser { public class BbsUserGetOutputDto: UserGetOutputDto { + /// + /// 用户等级 + /// + public int Level { get; set; } + + /// + /// 用户限制 + /// + public UserLimitEnum UserLimit { get; set; } } } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/CommentService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/CommentService.cs index 534141db..e0f20f18 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/CommentService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/CommentService.cs @@ -1,7 +1,9 @@ +using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; using Volo.Abp; using Volo.Abp.Application.Dtos; +using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser; using Yi.Framework.Bbs.Application.Contracts.Dtos.Comment; using Yi.Framework.Bbs.Application.Contracts.IServices; using Yi.Framework.Bbs.Domain.Entities; @@ -19,12 +21,14 @@ namespace Yi.Framework.Bbs.Application.Services ICommentService { private readonly ISqlSugarRepository _repository; - public CommentService(ForumManager forumManager, ISqlSugarRepository discussRepository, IDiscussService discussService, ISqlSugarRepository CommentRepository) : base(CommentRepository) + private readonly BbsUserManager _bbsUserManager; + public CommentService(ForumManager forumManager, ISqlSugarRepository discussRepository, IDiscussService discussService, ISqlSugarRepository CommentRepository, BbsUserManager bbsUserManager) : base(CommentRepository) { _forumManager = forumManager; _discussRepository = discussRepository; _discussService = discussService; _repository = CommentRepository; + _bbsUserManager=bbsUserManager; } private ForumManager _forumManager { get; set; } @@ -51,12 +55,25 @@ namespace Yi.Framework.Bbs.Application.Services //结果初始值,第一层等于全部根节点 var outPut = entities.Where(x => x.ParentId == Guid.Empty).OrderByDescending(x => x.CreationTime).ToList(); + //获取全量主题评论, 先获取顶级的,将其他子组合到顶级下,形成一个二维,先转成dto + List outoutDto = await MapToGetListOutputDtosAsync(outPut); - //将全部数据进行hash - var dic = entities.ToDictionary(x => x.Id); + //同时为所有用户id进行bbs的扩展即可 + List userIds = outoutDto.Select(x => x.CommentedUser.Id).Union(outoutDto.Select(x => x.CreateUser.Id)).ToList(); + var bbsUserInfoDic=( await _bbsUserManager.GetBbsUserInfoAsync(userIds)).ToDictionary(x=>x.Id); + + foreach (var singleOutput in outoutDto) + { + singleOutput.CommentedUser = bbsUserInfoDic[singleOutput.CommentedUser.Id].Adapt(); + singleOutput.CreateUser = bbsUserInfoDic[singleOutput.CommentedUser.Id].Adapt(); + } + //数据查询完成 - foreach (var comment in entities) + //开始组装dto的层级关系 + //将全部数据进行hash + var dic = outoutDto.ToDictionary(x => x.Id); + foreach (var comment in outoutDto) { //不是根节点,需要赋值 被评论者用户信息等 if (comment.ParentId != Guid.Empty) @@ -71,7 +88,6 @@ namespace Yi.Framework.Bbs.Application.Services continue; } } - //root或者parent id,根节点都是等于0的 var id = comment.RootId; if (id != Guid.Empty) @@ -88,11 +104,9 @@ namespace Yi.Framework.Bbs.Application.Services }); - //获取全量主题评论, 先获取顶级的,将其他子组合到顶级下,形成一个二维,先转成dto - List items = await MapToGetListOutputDtosAsync(outPut); - //最后将用户信息进行补全即可 + - return new PagedResultDto(entities.Count(), items); + return new PagedResultDto(entities.Count(), outoutDto); } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BbsUserManager.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BbsUserManager.cs new file mode 100644 index 00000000..c84d63a3 --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/BbsUserManager.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Services; +using Yi.Framework.Bbs.Domain.Entities; +using Yi.Framework.Bbs.Domain.Shared.Enums; +using Yi.Framework.Rbac.Domain.Entities; +using Yi.Framework.Rbac.Domain.Shared.Enums; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace Yi.Framework.Bbs.Domain.Managers +{ + public class BbsUserManager : DomainService + { + public ISqlSugarRepository _userRepository; + public ISqlSugarRepository _bbsUserInfoRepository; + public BbsUserManager(ISqlSugarRepository userRepository, ISqlSugarRepository bbsUserInfoRepository) + { + _userRepository = userRepository; + _bbsUserInfoRepository = bbsUserInfoRepository; + } + + public async Task GetBbsUserInfoAsync(Guid userId) + { + return await _userRepository._DbQueryable.LeftJoin((user, info) => user.Id == info.Id) + .Select((user, info) => new BbsUserInfoDto { Id = user.Id }) + .FirstAsync(x=>x.Id==userId); + } + + public async Task> GetBbsUserInfoAsync(List userIds) + { + return await _userRepository._DbQueryable.LeftJoin((user, info) => user.Id == info.Id) + .Select((user, info) => new BbsUserInfoDto { Id = user.Id }) + .Where(x=>userIds.Contains(x.Id)) + .ToListAsync(); + } + } + + public class BbsUserInfoDto + { + public Guid Id { get; set; } + public string? Name { get; set; } + public int? Age { get; set; } + public string UserName { get; set; } = string.Empty; + public string? Icon { get; set; } + public string? Nick { get; set; } + public string? Email { get; set; } + public string? Ip { get; set; } + public string? Address { get; set; } + public long? Phone { get; set; } + public string? Introduction { get; set; } + public string? Remark { get; set; } + public SexEnum Sex { get; set; } = SexEnum.Unknown; + public bool State { get; set; } + public DateTime CreationTime { get; set; } + + /// + /// 用户等级 + /// + public int Level { get; set; } + + /// + /// 用户限制 + /// + public UserLimitEnum UserLimit { get; set; } + + } +}