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
250e1051
Commit
250e1051
authored
Aug 30, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
点赞消息通知
parent
0b6aa523
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
40 deletions
+87
-40
ThemeNotifyQo.java
.../java/com/tanpu/community/api/beans/qo/ThemeNotifyQo.java
+2
-0
CommentManager.java
...main/java/com/tanpu/community/manager/CommentManager.java
+12
-13
NotificationManager.java
...java/com/tanpu/community/manager/NotificationManager.java
+28
-26
NotificationService.java
...java/com/tanpu/community/service/NotificationService.java
+29
-1
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+16
-0
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/ThemeNotifyQo.java
View file @
250e1051
...
...
@@ -49,6 +49,8 @@ public class ThemeNotifyQo {
public
String
topicTitle
;
@ApiModelProperty
(
value
=
"评论/转发内容"
)
private
String
content
;
@ApiModelProperty
(
value
=
"评论Id"
)
private
String
commentId
;
@ApiModelProperty
(
value
=
"转发类型-主题id"
)
private
String
forwardThemeId
;
...
...
community-service/src/main/java/com/tanpu/community/manager/CommentManager.java
View file @
250e1051
...
...
@@ -69,7 +69,7 @@ public class CommentManager {
if
(
StringUtils
.
isEmpty
(
req
.
getComment
()))
{
throw
new
IllegalArgumentException
(
"评论内容不能为空"
);
}
if
(
req
.
getComment
().
length
()
>
500
)
{
if
(
req
.
getComment
().
length
()
>
500
)
{
throw
new
IllegalArgumentException
(
"评论内容不能超过500字"
);
}
...
...
@@ -90,11 +90,11 @@ public class CommentManager {
buildUserInfo
(
commentQo
);
// 消息通知
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
req
.
getThemeId
());
if
(
themeEntity
==
null
)
{
throw
new
BizException
(
ErrorCodeConstant
.
UNREACHABLE
);
if
(
themeEntity
==
null
)
{
throw
new
BizException
(
ErrorCodeConstant
.
UNREACHABLE
);
}
notificationService
.
insert
(
userId
,
themeEntity
.
getAuthorId
(),
NotificationTypeEnum
.
COMMENT
,
commentEntity
.
getCommentId
(),
req
.
getComment
());
notificationService
.
putNotifyCache
(
themeEntity
.
getAuthorId
(),
userId
,
NotificationTypeEnum
.
COMMENT
);
notificationService
.
insert
(
userId
,
themeEntity
.
getAuthorId
(),
NotificationTypeEnum
.
COMMENT
,
commentEntity
.
getCommentId
(),
req
.
getComment
());
notificationService
.
putNotifyCache
(
themeEntity
.
getAuthorId
(),
userId
,
NotificationTypeEnum
.
COMMENT
);
// 评论同步转发并消息通知
if
(
req
.
getSyncForward
()
==
BizConstant
.
SyncForwardType
.
SYNC_FORWARD
)
{
...
...
@@ -102,7 +102,7 @@ public class CommentManager {
// 消息通知
ThemeEntity
formerTheme
=
themeService
.
queryByThemeId
(
req
.
getThemeId
());
notificationService
.
insertForward
(
userId
,
formerTheme
.
getAuthorId
(),
formerTheme
.
getThemeId
(),
""
,
req
.
getComment
(),
themeEntity
.
getThemeId
());
notificationService
.
insertForward
(
userId
,
formerTheme
.
getAuthorId
(),
formerTheme
.
getThemeId
(),
""
,
req
.
getComment
(),
themeEntity
.
getThemeId
());
notificationService
.
putNotifyCache
(
formerTheme
.
getAuthorId
(),
userId
,
NotificationTypeEnum
.
FORWARD
);
}
...
...
@@ -138,7 +138,7 @@ public class CommentManager {
private
void
buildUserInfo
(
CommentQo
commentQo
)
{
String
authorId
=
commentQo
.
getAuthorId
();
UserInfoResp
userInfo
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FEIGN_USER_INFO
,
authorId
),
60
,
()
->
this
.
getUserInfo
(
authorId
)
,
UserInfoResp
.
class
);
60
,
()
->
this
.
getUserInfo
(
authorId
)
,
UserInfoResp
.
class
);
if
(
userInfo
!=
null
)
{
commentQo
.
setUserImg
(
userInfo
.
getHeadImageUrl
());
commentQo
.
setNickName
(
userInfo
.
getNickName
());
...
...
@@ -152,7 +152,7 @@ public class CommentManager {
commentQo
.
setLikeCount
(
0
);
}
private
UserInfoResp
getUserInfo
(
String
authorId
){
private
UserInfoResp
getUserInfo
(
String
authorId
)
{
CommonResp
<
UserInfoResp
>
userInfoNewCommonResp
=
feignClientForFatools
.
queryUserInfoNew
(
authorId
);
if
(
userInfoNewCommonResp
.
isNotSuccess
())
{
throw
new
BizException
(
"内部接口调用失败"
);
...
...
@@ -164,10 +164,9 @@ public class CommentManager {
public
void
likeComment
(
LikeCommentReq
req
,
String
userId
)
{
if
(
OperationTypeEnum
.
CONFIRM
.
getCode
().
equals
(
req
.
getType
()))
{
boolean
b
=
collectionService
.
saveOrUpdate
(
req
.
getCommentId
(),
userId
,
CollectionTypeEnum
.
LIKE_COMMENT
);
if
(
b
){
if
(
b
)
{
CommentEntity
commentEntity
=
commentService
.
queryByCommentId
(
req
.
getCommentId
());
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
commentEntity
.
getThemeId
());
notificationService
.
insert
(
userId
,
commentEntity
.
getAuthorId
(),
NotificationTypeEnum
.
COMMENT_LIKE
,
themeEntity
.
getThemeId
(),
req
.
getCommentId
());
notificationService
.
insertLikeComment
(
userId
,
commentEntity
.
getAuthorId
(),
req
.
getCommentId
());
notificationService
.
putNotifyCache
(
commentEntity
.
getAuthorId
(),
userId
,
NotificationTypeEnum
.
COMMENT_LIKE
);
}
...
...
@@ -190,11 +189,11 @@ public class CommentManager {
//删除评论
public
void
delete
(
String
commentId
,
String
userId
)
{
commentService
.
delete
(
commentId
,
userId
);
commentService
.
delete
(
commentId
,
userId
);
CommentEntity
commentEntity
=
commentService
.
queryByIdIncludeDelete
(
commentId
);
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
commentEntity
.
getThemeId
());
notificationService
.
deleteCommentNotify
(
themeEntity
.
getAuthorId
(),
userId
,
commentId
,
commentEntity
.
getCreateTime
());
notificationService
.
deleteCommentNotify
(
themeEntity
.
getAuthorId
(),
userId
,
commentId
,
commentEntity
.
getCreateTime
());
}
...
...
community-service/src/main/java/com/tanpu/community/manager/NotificationManager.java
View file @
250e1051
...
...
@@ -79,7 +79,7 @@ public class NotificationManager {
List
<
ThemeNotifyQo
>
themeNotifyQos
=
ConvertUtil
.
notificationEntitiy2ThemeQos
(
query
);
UserInfoResp
currentUser
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FEIGN_USER_INFO
,
userId
),
60
,
()
->
this
.
getUserInfo
(
userId
),
UserInfoResp
.
class
);
Set
<
String
>
followUserIds
=
followRelService
.
queryIdolsByFansId
(
userId
).
stream
().
collect
(
Collectors
.
toSet
());
Set
<
String
>
followUserIds
=
followRelService
.
queryIdolsByFansId
(
userId
).
stream
().
collect
(
Collectors
.
toSet
());
for
(
ThemeNotifyQo
themeNotifyQo
:
themeNotifyQos
)
{
// 用户信息
...
...
@@ -95,32 +95,17 @@ public class NotificationManager {
themeNotifyQo
.
setBelongUserOrgName
(
userInfo
.
getBelongUserOrgName
());
// 封装引用对象
if
(
StringUtils
.
isNotEmpty
(
themeNotifyQo
.
getFormerThemeId
()))
{
if
(
NotificationTypeEnum
.
COMMENT
.
getCode
().
equals
(
themeNotifyQo
.
getMessageType
())){
if
(
NotificationTypeEnum
.
COMMENT
.
getCode
().
equals
(
themeNotifyQo
.
getMessageType
()))
{
// 评论类型将commentId替换为themeId
CommentEntity
commentEntity
=
commentService
.
queryByCommentId
(
themeNotifyQo
.
getFormerThemeId
());
themeNotifyQo
.
setFormerThemeId
(
commentEntity
.
getThemeId
());
}
if
(
NotificationTypeEnum
.
COMMENT_LIKE
.
getCode
().
equals
(
themeNotifyQo
.
getMessageType
())){
// 评论点赞类型将commentId替换为themeId
CommentEntity
commentEntity
=
commentService
.
queryByCommentId
(
themeNotifyQo
.
getFormerThemeId
());
themeNotifyQo
.
setFormerThemeId
(
commentEntity
.
getThemeId
());
// todo 评论原贴
themeNotifyQo
.
setContent
(
commentEntity
.
getContent
());
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
commentEntity
.
getThemeId
());
themeNotifyQo
.
setFormerTopicId
(
themeEntity
.
getTopicId
());
// themeNotifyQo.setFormerUserName(themeEntity.getAuthorId());
themeNotifyQo
.
setFormerTopicTitle
(
""
);
themeNotifyQo
.
setFormerUserName
(
currentUser
.
getNickName
());
List
<
ThemeContentQo
>
themeContentQos
=
JsonUtil
.
toBean
(
themeEntity
.
getContent
(),
new
TypeReference
<
List
<
ThemeContentQo
>>()
{
});
themeNotifyQo
.
setFormerContent
(
themeContentQos
.
get
(
0
).
getValue
());
}
ThemeEntity
former
=
themeService
.
queryByThemeId
(
themeNotifyQo
.
getFormerThemeId
());
if
(
former
!=
null
)
{
themeNotifyQo
.
setFormerUserName
(
currentUser
.
getNickName
());
if
(
StringUtils
.
isNotBlank
(
former
.
getTopicId
())){
if
(
StringUtils
.
isNotBlank
(
former
.
getTopicId
()))
{
// 内部话题
themeNotifyQo
.
setFormerTopicId
(
former
.
getTopicId
());
themeNotifyQo
.
setFormerTopicTitle
(
topicService
.
queryTitleById
(
former
.
getTopicId
()));
...
...
@@ -129,21 +114,39 @@ public class NotificationManager {
List
<
ThemeContentQo
>
themeContentQos
=
JsonUtil
.
toBean
(
former
.
getContent
(),
new
TypeReference
<
List
<
ThemeContentQo
>>()
{
});
themeNotifyQo
.
setFormerContent
(
themeContentQos
.
get
(
0
).
getValue
());
}
if
(
ThemeTypeEnum
.
LONG_TEXT
.
getCode
().
equals
(
former
.
getThemeType
()))
{
}
else
if
(
ThemeTypeEnum
.
LONG_TEXT
.
getCode
().
equals
(
former
.
getThemeType
()))
{
themeNotifyQo
.
setFormerContent
(
former
.
getTitle
());
}
}
else
{
}
else
{
// 引用主题已被删除
themeNotifyQo
.
setFormerThemeId
(
null
);
}
}
// 评论点赞类型
if
(
NotificationTypeEnum
.
COMMENT_LIKE
.
getCode
().
equals
(
themeNotifyQo
.
getMessageType
()))
{
CommentEntity
commentEntity
=
commentService
.
queryByCommentId
(
themeNotifyQo
.
getCommentId
());
themeNotifyQo
.
setFormerThemeId
(
commentEntity
.
getThemeId
());
themeNotifyQo
.
setContent
(
commentEntity
.
getContent
());
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
commentEntity
.
getThemeId
());
if
(
themeEntity
!=
null
)
{
themeNotifyQo
.
setFormerUserName
(
currentUser
.
getNickName
());
themeNotifyQo
.
setFormerTopicId
(
themeEntity
.
getTopicId
());
if
(
ThemeTypeEnum
.
DISCUSSION
.
getCode
().
equals
(
themeEntity
.
getThemeType
())
||
ThemeTypeEnum
.
FORWARD
.
getCode
().
equals
(
themeEntity
.
getThemeType
()))
{
List
<
ThemeContentQo
>
themeContentQos
=
JsonUtil
.
toBean
(
themeEntity
.
getContent
(),
new
TypeReference
<
List
<
ThemeContentQo
>>()
{
});
themeNotifyQo
.
setFormerContent
(
themeContentQos
.
get
(
0
).
getValue
());
}
else
if
(
ThemeTypeEnum
.
LONG_TEXT
.
getCode
().
equals
(
themeEntity
.
getThemeType
()))
{
themeNotifyQo
.
setFormerContent
(
themeEntity
.
getTitle
());
}
}
}
// 外部话题
if
(
StringUtils
.
isNotBlank
(
themeNotifyQo
.
getTopicId
()))
{
themeNotifyQo
.
setTopicTitle
(
topicService
.
queryTitleById
(
themeNotifyQo
.
getTopicId
()));
}
// 点赞聚合
if
(
themeNotifyQo
.
getLikeUserCount
()
!=
null
&&
themeNotifyQo
.
getLikeUserCount
()>
1
)
{
if
(
themeNotifyQo
.
getLikeUserCount
()
!=
null
&&
themeNotifyQo
.
getLikeUserCount
()
>
1
)
{
List
<
UserBriefInfoQO
>
likeUsers
=
themeNotifyQo
.
getLikeUsers
();
for
(
UserBriefInfoQO
likeUser
:
likeUsers
)
{
UserInfoResp
luser
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FEIGN_USER_INFO
,
likeUser
.
getUserId
()),
...
...
@@ -159,7 +162,7 @@ public class NotificationManager {
redisCache
.
evict
(
RedisKeyConstant
.
MESSAGE_NOTIFY_COUNT
+
userId
);
// 更新查询时间,用于删除评论
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_QUERY_TIME
+
userId
,
JsonUtil
.
toJson
(
LocalDateTime
.
now
()),
60
*
60
*
24
*
30
);
JsonUtil
.
toJson
(
LocalDateTime
.
now
()),
60
*
60
*
24
*
30
);
return
themeNotifyQos
;
}
...
...
@@ -182,7 +185,7 @@ public class NotificationManager {
notificationService
.
insert
(
followRelEntity
.
getFansId
(),
followRelEntity
.
getIdolId
(),
NotificationTypeEnum
.
FOLLOW
,
followRelEntity
.
getFansId
(),
""
,
followRelEntity
.
getUpdateTime
());
notificationService
.
putNotifyCacheFollow
(
followRelEntity
.
getIdolId
(),
followRelEntity
.
getFansId
(),
followRelEntity
.
getUpdateTime
());
notificationService
.
putNotifyCacheFollow
(
followRelEntity
.
getIdolId
(),
followRelEntity
.
getFansId
(),
followRelEntity
.
getUpdateTime
());
}
// 转发
List
<
ThemeEntity
>
themeEntities
=
themeService
.
queryAllForward
();
...
...
@@ -200,7 +203,7 @@ public class NotificationManager {
.
topicId
(
themeEntity
.
getTopicId
()).
build
();
notificationService
.
insert
(
themeEntity
.
getAuthorId
(),
former
.
getAuthorId
(),
NotificationTypeEnum
.
FORWARD
,
themeEntity
.
getFormerThemeId
(),
JsonUtil
.
toJson
(
content
),
themeEntity
.
getUpdateTime
());
notificationService
.
putNotifyCache
(
former
.
getAuthorId
(),
themeEntity
.
getAuthorId
(),
NotificationTypeEnum
.
FORWARD
,
themeEntity
.
getUpdateTime
());
notificationService
.
putNotifyCache
(
former
.
getAuthorId
(),
themeEntity
.
getAuthorId
(),
NotificationTypeEnum
.
FORWARD
,
themeEntity
.
getUpdateTime
());
}
// 评论
List
<
CommentEntity
>
commentEntities
=
commentService
.
queryAll
();
...
...
@@ -243,7 +246,6 @@ public class NotificationManager {
}
private
UserInfoResp
getUserInfo
(
String
authorId
)
{
CommonResp
<
UserInfoResp
>
userInfoNewCommonResp
=
feignClientForFatools
.
queryUserInfoNew
(
authorId
);
if
(
userInfoNewCommonResp
.
isNotSuccess
())
{
...
...
community-service/src/main/java/com/tanpu/community/service/NotificationService.java
View file @
250e1051
...
...
@@ -84,7 +84,7 @@ public class NotificationService {
}
@Transactional
public
void
insertLike
(
String
operatorId
,
String
notifierId
,
String
targetId
)
{
NotificationEntity
entity
=
notificationMapper
.
selectOne
(
new
LambdaQueryWrapper
<
NotificationEntity
>()
.
eq
(
NotificationEntity:
:
getMessageType
,
NotificationTypeEnum
.
LIKE
.
getCode
())
...
...
@@ -112,6 +112,34 @@ public class NotificationService {
}
@Transactional
public
void
insertLikeComment
(
String
operatorId
,
String
notifierId
,
String
targetId
)
{
NotificationEntity
entity
=
notificationMapper
.
selectOne
(
new
LambdaQueryWrapper
<
NotificationEntity
>()
.
eq
(
NotificationEntity:
:
getMessageType
,
NotificationTypeEnum
.
COMMENT_LIKE
.
getCode
())
.
eq
(
NotificationEntity:
:
getTargetId
,
targetId
)
.
eq
(
NotificationEntity:
:
getNotifiedUserId
,
notifierId
));
if
(
entity
!=
null
)
{
NotificationLikeDO
notificationLikeDO
=
JsonUtil
.
toBean
(
entity
.
getContent
(),
NotificationLikeDO
.
class
);
notificationLikeDO
.
addItem
(
operatorId
);
entity
.
setContent
(
JsonUtil
.
toJson
(
notificationLikeDO
));
entity
.
setUpdateTime
(
LocalDateTime
.
now
());
notificationMapper
.
updateById
(
entity
);
}
else
{
NotificationLikeDO
notificationLikeDO
=
new
NotificationLikeDO
();
notificationLikeDO
.
addItem
(
operatorId
);
NotificationEntity
build
=
NotificationEntity
.
builder
().
operatorId
(
operatorId
)
.
notificationId
(
uuidGenHelper
.
getUuidStr
())
.
messageType
(
NotificationTypeEnum
.
COMMENT_LIKE
.
getCode
())
.
notifiedUserId
(
notifierId
)
.
content
(
JsonUtil
.
toJson
(
notificationLikeDO
))
.
targetId
(
targetId
)
.
operatorId
(
operatorId
)
.
build
();
insert
(
build
);
}
}
@Transactional
public
void
insert
(
NotificationEntity
entity
)
{
notificationMapper
.
insert
(
entity
);
...
...
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
250e1051
...
...
@@ -280,6 +280,22 @@ public class ConvertUtil {
}
}
}
// 点赞评论需要聚合头像和人数,并写入commentId
if
(
entity
.
getMessageType
().
equals
(
NotificationTypeEnum
.
COMMENT_LIKE
.
getCode
()))
{
if
(!
StringUtils
.
isEmpty
(
entity
.
getContent
()))
{
try
{
NotificationLikeDO
notificationLikeDO
=
JsonUtil
.
toBean
(
entity
.
getContent
(),
NotificationLikeDO
.
class
);
themeNotifyQo
.
setLikeUserCount
(
notificationLikeDO
.
getCount
());
ArrayList
<
UserBriefInfoQO
>
likeUsers
=
new
ArrayList
<>();
notificationLikeDO
.
getSet
().
stream
().
forEach
(
o
->
likeUsers
.
add
(
UserBriefInfoQO
.
builder
().
userId
(
o
).
build
()));
themeNotifyQo
.
setLikeUsers
(
likeUsers
);
themeNotifyQo
.
setCommentId
(
entity
.
getTargetId
());
}
catch
(
Exception
e
){
throw
new
BizException
(
"消息通知-点赞类型-反序列化异常:"
+
entity
.
getContent
());
}
}
}
return
themeNotifyQo
;
...
...
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