Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
cce8401b
Commit
cce8401b
authored
Feb 25, 2022
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
递归改造队列
parent
887a46c8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
11 deletions
+11
-11
CommentManager.java
...main/java/com/tanpu/community/manager/CommentManager.java
+9
-5
CommentService.java
...main/java/com/tanpu/community/service/CommentService.java
+2
-6
No files found.
community-service/src/main/java/com/tanpu/community/manager/CommentManager.java
View file @
cce8401b
...
...
@@ -34,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.ArrayDeque
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Set
;
...
...
@@ -233,17 +234,20 @@ public class CommentManager {
if
(
StringUtils
.
isBlank
(
commentId
))
{
throw
new
BizException
(
"commentId不能为空"
);
}
ArrayDeque
<
CommentEntity
>
queue
=
new
ArrayDeque
<>();
queue
.
add
(
commentService
.
queryByIdIncludeDelete
(
commentId
));
// 循环删除二级评论的一级评论
while
(
StringUtils
.
isNotBlank
(
commentId
))
{
while
(!
queue
.
isEmpty
())
{
CommentEntity
pop
=
queue
.
pop
();
// 逻辑删除comment
CommentEntity
commentEntity
=
commentService
.
delete
(
commentId
,
userId
);
CommentEntity
commentEntity
=
commentService
.
delete
(
pop
.
getCommentId
(),
pop
.
getAuthorId
()
);
// 删除站内信
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
commentEntity
.
getThemeId
());
notificationService
.
deleteCommentNotify
(
themeEntity
.
getAuthorId
(),
userId
,
commentId
,
commentEntity
.
getCreateTime
());
// 递归
CommentEntity
replyForComment
=
commentService
.
queryReplyForComment
(
commentId
);
commentId
=
replyForComment
.
getCommentId
();
userId
=
replyForComment
.
getAuthorId
();
queue
.
addAll
(
commentService
.
queryReplyForComment
(
commentEntity
.
getCommentId
()));
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/CommentService.java
View file @
cce8401b
...
...
@@ -230,14 +230,10 @@ public class CommentService {
* @param commentId
* @return
*/
public
CommentEntity
queryReplyForComment
(
String
commentId
)
{
public
List
<
CommentEntity
>
queryReplyForComment
(
String
commentId
)
{
List
<
CommentEntity
>
replies
=
commentMapper
.
selectList
(
new
LambdaQueryWrapper
<
CommentEntity
>()
.
eq
(
CommentEntity:
:
getReplyId
,
commentId
)
.
eq
(
CommentEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
));
if
(
CollectionUtils
.
isNotEmpty
(
replies
)){
return
replies
.
get
(
0
);
}
else
{
return
new
CommentEntity
();
}
return
replies
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment