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
647df1e7
Commit
647df1e7
authored
Feb 25, 2022
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
递归删除评论的回复
parent
3c7b002a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
20 deletions
+35
-20
ThemeMapper.java
...com/tanpu/community/dao/mapper/community/ThemeMapper.java
+1
-0
CommentManager.java
...main/java/com/tanpu/community/manager/CommentManager.java
+13
-6
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+3
-2
CommentService.java
...main/java/com/tanpu/community/service/CommentService.java
+2
-1
ThemeService.java
...c/main/java/com/tanpu/community/service/ThemeService.java
+1
-1
ThemeEntityMapper.xml
...src/main/resources/mapper/community/ThemeEntityMapper.xml
+15
-10
No files found.
community-service/src/main/java/com/tanpu/community/dao/mapper/community/ThemeMapper.java
View file @
647df1e7
...
...
@@ -43,4 +43,5 @@ public interface ThemeMapper extends BaseMapper<ThemeEntity> {
@Param
(
"pageStart"
)
Integer
pageStart
,
@Param
(
"pageSize"
)
Integer
pageSize
);
}
community-service/src/main/java/com/tanpu/community/manager/CommentManager.java
View file @
647df1e7
...
...
@@ -104,10 +104,10 @@ public class CommentManager {
// 一级回复通知发帖人,二级回复通知一级评论人
if
(
StringUtils
.
isNotBlank
(
req
.
getReplyUserId
())){
if
(
StringUtils
.
isNotBlank
(
req
.
getReplyUserId
()))
{
notificationService
.
insert
(
userId
,
req
.
getReplyUserId
(),
NotificationTypeEnum
.
COMMENT_REPLY
,
commentEntity
.
getCommentId
(),
req
.
getComment
());
notificationService
.
putNotifyCache
(
req
.
getReplyUserId
(),
userId
,
NotificationTypeEnum
.
COMMENT_REPLY
);
}
else
{
}
else
{
notificationService
.
insert
(
userId
,
themeEntity
.
getAuthorId
(),
NotificationTypeEnum
.
COMMENT
,
commentEntity
.
getCommentId
(),
req
.
getComment
());
notificationService
.
putNotifyCache
(
themeEntity
.
getAuthorId
(),
userId
,
NotificationTypeEnum
.
COMMENT
);
...
...
@@ -233,10 +233,17 @@ public class CommentManager {
if
(
StringUtils
.
isBlank
(
commentId
))
{
throw
new
BizException
(
"commentId不能为空"
);
}
commentService
.
delete
(
commentId
,
userId
);
CommentEntity
commentEntity
=
commentService
.
queryByIdIncludeDelete
(
commentId
);
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
commentEntity
.
getThemeId
());
notificationService
.
deleteCommentNotify
(
themeEntity
.
getAuthorId
(),
userId
,
commentId
,
commentEntity
.
getCreateTime
());
// 循环删除二级评论的一级评论
while
(
StringUtils
.
isNotBlank
(
commentId
))
{
// 逻辑删除comment
CommentEntity
commentEntity
=
commentService
.
delete
(
commentId
,
userId
);
// 删除站内信
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
commentEntity
.
getThemeId
());
notificationService
.
deleteCommentNotify
(
themeEntity
.
getAuthorId
(),
userId
,
commentId
,
commentEntity
.
getCreateTime
());
// 递归
commentId
=
commentEntity
.
getReplyId
();
userId
=
commentEntity
.
getReplyUserId
();
}
}
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
647df1e7
...
...
@@ -510,14 +510,15 @@ public class ThemeManager {
}
else
if
(
ThemeListTypeEnum
.
FOLLOW
.
getCode
().
equals
(
req
.
getType
()))
{
if
(
StringUtils
.
isEmpty
(
req
.
getUserId
()
))
{
if
(
StringUtils
.
isEmpty
(
userId
))
{
// 未登录情况下返回空数组
themes
=
Lists
.
newArrayListWithCapacity
(
0
);
}
else
{
// 根据关注列表查询,按时间倒序
List
<
String
>
fansList
=
followRelService
.
queryIdolsByFansId
(
req
.
getUserId
());
fansList
.
add
(
userId
);
// 保证fansList不为空
// 权限控制,筛选出当前用户
有权限
的话题
// 权限控制,筛选出当前用户
关注
的话题
Set
<
String
>
userPermitTopics
=
topicService
.
getUserPermitTopics
(
userId
);
// 查库
...
...
community-service/src/main/java/com/tanpu/community/service/CommentService.java
View file @
647df1e7
...
...
@@ -153,7 +153,7 @@ public class CommentService {
//删除评论
@Transactional
public
void
delete
(
String
commentId
,
String
userId
)
{
public
CommentEntity
delete
(
String
commentId
,
String
userId
)
{
CommentEntity
commentEntity
=
this
.
queryByIdIncludeDelete
(
commentId
);
if
(
commentEntity
==
null
||
!
commentEntity
.
getAuthorId
().
equals
(
userId
))
{
throw
new
BizException
(
"删除评论与用户不匹配,commentId:"
+
commentId
+
",userId:"
+
userId
);
...
...
@@ -162,6 +162,7 @@ public class CommentService {
commentMapper
.
updateById
(
commentEntity
);
//失效缓存
evictThemeCache
(
commentEntity
.
getThemeId
());
return
commentEntity
;
}
// 失效关联主题缓存
...
...
community-service/src/main/java/com/tanpu/community/service/ThemeService.java
View file @
647df1e7
...
...
@@ -227,7 +227,7 @@ public class ThemeService {
* @return
*/
public
List
<
ThemeEntity
>
queryByUserIdsCreateDesc
(
List
<
String
>
userIds
,
Integer
pageStart
,
Integer
pageSize
,
Set
<
String
>
userPermitTopics
)
{
if
(
CollectionUtils
.
isEmpty
(
userIds
))
{
if
(
CollectionUtils
.
isEmpty
(
userIds
)
&&
CollectionUtils
.
isEmpty
(
userPermitTopics
)
)
{
return
Collections
.
emptyList
();
}
userPermitTopics
.
remove
(
""
);
...
...
community-service/src/main/resources/mapper/community/ThemeEntityMapper.xml
View file @
647df1e7
...
...
@@ -64,16 +64,21 @@
select
<include
refid=
"Base_Column_List"
/>
from theme
where delete_tag=0 and ((author_id in
<foreach
item=
"item"
index=
"index"
collection=
"authorIdCollection"
open=
"("
separator=
","
close=
")"
>
#{item}
</foreach>
and topic_id="") or topic_id in
<foreach
item=
"item"
index=
"index"
collection=
"topicIdCollection"
open=
"("
separator=
","
close=
")"
>
#{item}
</foreach>
where delete_tag=0 and (
<if
test=
"authorIdCollection != null and authorIdCollection.size() > 0"
>
author_id in
<foreach
item=
"item"
index=
"index"
collection=
"authorIdCollection"
open=
"("
separator=
","
close=
")"
>
#{item}
</foreach>
</if>
<if
test=
"topicIdCollection != null and topicIdCollection.size() > 0"
>
or topic_id in
<foreach
item=
"item"
index=
"index"
collection=
"topicIdCollection"
open=
"("
separator=
","
close=
")"
>
#{item}
</foreach>
</if>
) order by create_time desc limit #{pageStart}, #{pageSize}
</select>
...
...
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