diff --git a/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Application.Contracts/ApplicationContractsSwaggerDoc.xml b/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Application.Contracts/ApplicationContractsSwaggerDoc.xml
index fc82778f..12192b58 100644
--- a/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Application.Contracts/ApplicationContractsSwaggerDoc.xml
+++ b/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Application.Contracts/ApplicationContractsSwaggerDoc.xml
@@ -24,6 +24,71 @@
Comment输入创建对象
+
+
+ 评论id
+
+
+
+
+ 主题id
+
+
+
+
+ 第一层评论id,第一层为0
+
+
+
+
+ 被回复的CommentId,第一层为0
+
+
+
+
+ 评论多反
+
+
+
+
+ 主题id
+
+
+
+
+ 用户,评论人用户信息
+
+
+
+
+ 被评论的用户信息
+
+
+
+
+ 这个不是一个树形,而是存在一个二维数组,该Children只有在顶级时候,只有一层
+
+
+
+
+ 单返回,返回单条评论即可
+
+
+
+
+ 用户id联表为用户对象
+
+
+
+
+ 根节点的评论id
+
+
+
+
+ 被回复的CommentId
+
+
Discuss输入创建对象
diff --git a/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Application/ApplicationSwaggerDoc.xml b/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Application/ApplicationSwaggerDoc.xml
index 18c08834..20162d43 100644
--- a/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Application/ApplicationSwaggerDoc.xml
+++ b/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Application/ApplicationSwaggerDoc.xml
@@ -51,12 +51,12 @@
- Comment服务实现
+ 评论
- 获取改主题下的评论
+ 获取改主题下的评论,结构为二维列表,该查询无分页
diff --git a/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Domain/DomainSwaggerDoc.xml b/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Domain/DomainSwaggerDoc.xml
index 1f66dd82..fc516425 100644
--- a/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Domain/DomainSwaggerDoc.xml
+++ b/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Domain/DomainSwaggerDoc.xml
@@ -21,6 +21,31 @@
+
+
+ 评论表
+
+
+
+
+ 采用二维数组方式,不使用树形方式
+
+
+
+
+ 被回复的CommentId
+
+
+
+
+ 用户,评论人用户信息
+
+
+
+
+ 被评论的用户信息
+
+
论坛模块的领域服务
diff --git a/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Web/yi-sqlsugar-dev.db b/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Web/yi-sqlsugar-dev.db
index a2fe576f..bfc403bb 100644
Binary files a/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Web/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/src/project/BBS/Yi.BBS.Web/yi-sqlsugar-dev.db differ
diff --git a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/ApplicationContractsSwaggerDoc.xml b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/ApplicationContractsSwaggerDoc.xml
index fc82778f..12192b58 100644
--- a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/ApplicationContractsSwaggerDoc.xml
+++ b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/ApplicationContractsSwaggerDoc.xml
@@ -24,6 +24,71 @@
Comment输入创建对象
+
+
+ 评论id
+
+
+
+
+ 主题id
+
+
+
+
+ 第一层评论id,第一层为0
+
+
+
+
+ 被回复的CommentId,第一层为0
+
+
+
+
+ 评论多反
+
+
+
+
+ 主题id
+
+
+
+
+ 用户,评论人用户信息
+
+
+
+
+ 被评论的用户信息
+
+
+
+
+ 这个不是一个树形,而是存在一个二维数组,该Children只有在顶级时候,只有一层
+
+
+
+
+ 单返回,返回单条评论即可
+
+
+
+
+ 用户id联表为用户对象
+
+
+
+
+ 根节点的评论id
+
+
+
+
+ 被回复的CommentId
+
+
Discuss输入创建对象
diff --git a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/Forum/Dtos/Comment/CommentCreateInputVo.cs b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/Forum/Dtos/Comment/CommentCreateInputVo.cs
index 15986756..02002a15 100644
--- a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/Forum/Dtos/Comment/CommentCreateInputVo.cs
+++ b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/Forum/Dtos/Comment/CommentCreateInputVo.cs
@@ -13,17 +13,23 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos
public class CommentCreateInputVo
{
+ ///
+ /// 评论id
+ ///
public string Content { get; set; }
+ ///
+ /// 主题id
+ ///
public long DiscussId { get; set; }
///
- /// 根节点的评论id,这里也可根据树形查询获取到根节点,但是不够优雅,前端是二维数组,选择前端传值即可,如果是根,传0,如果不是
+ /// 第一层评论id,第一层为0
///
public long RootId { get; set; }
///
- /// 被回复的CommentId
+ /// 被回复的CommentId,第一层为0
///
public long ParentId { get; set; }
}
diff --git a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/Forum/Dtos/Comment/CommentGetListOutputDto.cs b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/Forum/Dtos/Comment/CommentGetListOutputDto.cs
index 3a996a46..ae21a61d 100644
--- a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/Forum/Dtos/Comment/CommentGetListOutputDto.cs
+++ b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application.Contracts/Forum/Dtos/Comment/CommentGetListOutputDto.cs
@@ -19,10 +19,6 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos
public DateTime? CreateTime { get; set; }
public string Content { get; set; }
- ///
- /// ڵid
- ///
- public long RootId { get; set; }
///
/// id
@@ -31,16 +27,21 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos
public long ParentId { get; set; }
+ public long RootId { get; set; }
///
- /// û,ûϢ۵ûϢһڵ
+ /// û,ûϢ
///
- public UserGetOutputDto User { get; set; }
+ public UserGetOutputDto CreateUser { get; set; }
+ ///
+ /// ۵ûϢ
+ ///
+ public UserGetOutputDto CommentedUser { get; set; }
///
- /// һΣǴһά飬Childrenֻһ
+ /// һΣǴһά飬Childrenֻڶʱֻһ
///
public List Children { get; set; } = new List();
}
diff --git a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application/ApplicationSwaggerDoc.xml b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application/ApplicationSwaggerDoc.xml
index 18c08834..20162d43 100644
--- a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application/ApplicationSwaggerDoc.xml
+++ b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application/ApplicationSwaggerDoc.xml
@@ -51,12 +51,12 @@
- Comment服务实现
+ 评论
- 获取改主题下的评论
+ 获取改主题下的评论,结构为二维列表,该查询无分页
diff --git a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application/Forum/CommentService.cs b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application/Forum/CommentService.cs
index 3fcfce99..3961633e 100644
--- a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application/Forum/CommentService.cs
+++ b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Application/Forum/CommentService.cs
@@ -46,24 +46,36 @@ namespace Yi.BBS.Application.Forum
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.Content), x => x.Content.Contains(input.Content))
.Where(x => x.DiscussId == discussId)
+ .Includes(x=>x.CreateUser)
.ToListAsync();
- //获取全量主题评论, 先获取顶级的,将其他子组合到顶级下,形成一个二维,先转成dto
- List? items = await MapToGetListOutputDtosAsync(entities);
+ //结果初始值,第一层等于全部根节点
+ var outPut = entities.Where(x => x.ParentId == 0).ToList();
- //这里就是dto的处理啦
+ //将全部数据进行hash
+ var dic = entities.ToDictionary(x => x.Id);
- //获取根节点
- var rootDic = items.Where(x => x.ParentId != 0).ToDictionary(x => x.Id);
- foreach (var comment in items)
+ foreach (var comment in entities)
{
+ //不是根节点,需要赋值 被评论者用户信息等
if (comment.ParentId != 0)
{
- rootDic[comment.Id].Children.Add(comment);
+ var parentComment = dic[comment.ParentId];
+ comment.CommentedUser = parentComment.CreateUser;
}
+
+ //root或者parent id,根节点都是等于0的
+ var id = comment.RootId;
+ if (id is not 0)
+ {
+ dic[id].Children.Add(comment);
+ }
+
}
- return new PagedResultDto(0, items);
+ //获取全量主题评论, 先获取顶级的,将其他子组合到顶级下,形成一个二维,先转成dto
+ List? items = await MapToGetListOutputDtosAsync(outPut);
+ return new PagedResultDto(0, items);
}
@@ -79,7 +91,7 @@ namespace Yi.BBS.Application.Forum
{
throw new UserFriendlyException(DiscussConst.主题不存在);
}
- var entity = await _forumManager.CreateCommentAsync(input.DiscussId, input.Content);
+ var entity = await _forumManager.CreateCommentAsync(input.DiscussId, input.ParentId,input.RootId, input.Content);
return await MapToGetOutputDtoAsync(entity);
}
diff --git a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/DomainSwaggerDoc.xml b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/DomainSwaggerDoc.xml
index 1f66dd82..fc516425 100644
--- a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/DomainSwaggerDoc.xml
+++ b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/DomainSwaggerDoc.xml
@@ -21,6 +21,31 @@
+
+
+ 评论表
+
+
+
+
+ 采用二维数组方式,不使用树形方式
+
+
+
+
+ 被回复的CommentId
+
+
+
+
+ 用户,评论人用户信息
+
+
+
+
+ 被评论的用户信息
+
+
论坛模块的领域服务
diff --git a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/Forum/Entities/CommentEntity.cs b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/Forum/Entities/CommentEntity.cs
index 865920b3..21372609 100644
--- a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/Forum/Entities/CommentEntity.cs
+++ b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/Forum/Entities/CommentEntity.cs
@@ -33,27 +33,34 @@ namespace Yi.BBS.Domain.Forum.Entities
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
public bool IsDeleted { get; set; }
-
- public DateTime? CreateTime { get; set; }
public string Content { get; set; }
public long DiscussId { get; set; }
-
- ///
- /// 根节点的评论id
- ///
- public long RootId { get; set; }
-
///
/// 被回复的CommentId
///
public long ParentId { get; set; }
public DateTime CreationTime { get; set; }
+ public long RootId { get; set; }
+ [SugarColumn(IsIgnore = true)]
+ public List Children { get; set; } = new();
+
+
+ ///
+ /// 用户,评论人用户信息
+ ///
[Navigate(NavigateType.OneToOne, nameof(CreatorId))]
- public UserEntity User { get; set; }
+ public UserEntity CreateUser { get; set; }
+
+ ///
+ /// 被评论的用户信息
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public UserEntity CommentedUser { get; set; }
+
public long? CreatorId { get; set; }
public long? LastModifierId { get; set; }
diff --git a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/Forum/ForumManager.cs b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/Forum/ForumManager.cs
index 270be8b4..dbbce85e 100644
--- a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/Forum/ForumManager.cs
+++ b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Domain/Forum/ForumManager.cs
@@ -40,11 +40,13 @@ namespace Yi.BBS.Domain.Forum
return await _discussRepository.InsertReturnEntityAsync(entity);
}
- public async Task CreateCommentAsync(long discussId, string content)
+ public async Task CreateCommentAsync(long discussId,long parentId,long rootId, string content)
{
var entity = new CommentEntity(discussId);
entity.Id = SnowflakeHelper.NextId;
entity.Content = content;
+ entity.ParentId = parentId;
+ entity.RootId = rootId;
return await _commentRepository.InsertReturnEntityAsync(entity);
}
}
diff --git a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Web/yi-sqlsugar-dev.db b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Web/yi-sqlsugar-dev.db
index a2fe576f..bfc403bb 100644
Binary files a/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Web/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/src/project/bbs/Yi.BBS.Web/yi-sqlsugar-dev.db differ