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
a095d0f4
Commit
a095d0f4
authored
Aug 16, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消息通知 fix
parent
1fc721e0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
33 deletions
+44
-33
NotificationManager.java
...java/com/tanpu/community/manager/NotificationManager.java
+4
-21
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+2
-11
NotificationService.java
...java/com/tanpu/community/service/NotificationService.java
+38
-1
No files found.
community-service/src/main/java/com/tanpu/community/manager/NotificationManager.java
View file @
a095d0f4
...
...
@@ -32,13 +32,11 @@ import com.tanpu.community.service.NotificationService;
import
com.tanpu.community.service.ThemeService
;
import
com.tanpu.community.service.TopicService
;
import
com.tanpu.community.util.ConvertUtil
;
import
com.tanpu.community.util.TimeUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
...
...
@@ -153,7 +151,7 @@ public class NotificationManager {
for
(
FollowRelEntity
followRelEntity
:
followRelEntities
)
{
notificationService
.
insert
(
followRelEntity
.
getFansId
(),
followRelEntity
.
getIdolId
(),
NotificationTypeEnum
.
FOLLOW
,
followRelEntity
.
getFansId
(),
""
,
followRelEntity
.
getUpdateTime
());
messageNotify
Follow
(
followRelEntity
.
getIdolId
(),
followRelEntity
.
getFansId
());
notificationService
.
putNotifyCache
Follow
(
followRelEntity
.
getIdolId
(),
followRelEntity
.
getFansId
());
}
// 转发
List
<
ThemeEntity
>
themeEntities
=
themeService
.
queryAllForward
();
...
...
@@ -168,7 +166,7 @@ public class NotificationManager {
NotificationForwardDO
content
=
NotificationForwardDO
.
builder
().
content
(
s
.
length
()
>
500
?
s
.
substring
(
0
,
500
)
:
s
).
topicId
(
themeEntity
.
getTopicId
()).
build
();
notificationService
.
insert
(
themeEntity
.
getAuthorId
(),
former
.
getAuthorId
(),
NotificationTypeEnum
.
FORWARD
,
themeEntity
.
getFormerThemeId
(),
JsonUtil
.
toJson
(
content
),
themeEntity
.
getUpdateTime
());
messageNotify
(
former
.
getAuthorId
(),
themeEntity
.
getAuthorId
(),
NotificationTypeEnum
.
FORWARD
);
notificationService
.
putNotifyCache
(
former
.
getAuthorId
(),
themeEntity
.
getAuthorId
(),
NotificationTypeEnum
.
FORWARD
);
}
// 评论
List
<
CommentEntity
>
commentEntities
=
commentService
.
queryAll
();
...
...
@@ -180,7 +178,7 @@ public class NotificationManager {
String
s
=
commentEntity
.
getContent
();
notificationService
.
insert
(
commentEntity
.
getAuthorId
(),
themeEntity
.
getAuthorId
(),
NotificationTypeEnum
.
COMMENT
,
commentEntity
.
getThemeId
(),
s
,
commentEntity
.
getUpdateTime
());
messageNotify
(
themeEntity
.
getAuthorId
(),
commentEntity
.
getAuthorId
(),
NotificationTypeEnum
.
COMMENT
);
notificationService
.
putNotifyCache
(
themeEntity
.
getAuthorId
(),
commentEntity
.
getAuthorId
(),
NotificationTypeEnum
.
COMMENT
);
}
// 点赞
...
...
@@ -191,7 +189,7 @@ public class NotificationManager {
continue
;
}
notificationService
.
insertLike
(
collectionEntity
.
getUserId
(),
themeEntity
.
getAuthorId
(),
collectionEntity
.
getTargetId
(),
collectionEntity
.
getUpdateTime
());
messageNotify
(
themeEntity
.
getAuthorId
(),
collectionEntity
.
getUserId
(),
NotificationTypeEnum
.
LIKE
);
notificationService
.
putNotifyCache
(
themeEntity
.
getAuthorId
(),
collectionEntity
.
getUserId
(),
NotificationTypeEnum
.
LIKE
);
}
}
...
...
@@ -211,21 +209,6 @@ public class NotificationManager {
}
// 消息通知队列缓存
private
void
messageNotify
(
String
notifyUserId
,
String
operatorId
,
NotificationTypeEnum
type
)
{
UserInfoResp
userInfo
=
getUserInfo
(
operatorId
);
redisCache
.
incr
(
RedisKeyConstant
.
MESSAGE_NOTIFY_COUNT
+
notifyUserId
);
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_LAST_MSG
+
notifyUserId
,
userInfo
.
getNickName
()
+
type
.
getType
()
+
"了你的内容"
,
60
*
60
*
24
*
30
);
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_LAST_TIME
+
notifyUserId
,
TimeUtils
.
format
(
LocalDateTime
.
now
()),
60
*
60
*
24
*
30
);
}
// 消息通知队列缓存
private
void
messageNotifyFollow
(
String
notifyUserId
,
String
operatorId
)
{
UserInfoResp
userInfo
=
getUserInfo
(
operatorId
);
redisCache
.
incr
(
RedisKeyConstant
.
MESSAGE_NOTIFY_COUNT
+
notifyUserId
);
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_LAST_MSG
+
notifyUserId
,
userInfo
.
getNickName
()
+
"关注了你"
,
60
*
60
*
24
*
30
);
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_LAST_TIME
+
notifyUserId
,
TimeUtils
.
format
(
LocalDateTime
.
now
()),
60
*
60
*
24
*
30
);
}
private
UserInfoResp
getUserInfo
(
String
authorId
)
{
CommonResp
<
UserInfoResp
>
userInfoNewCommonResp
=
feignClientForFatools
.
queryUserInfoNew
(
authorId
);
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
a095d0f4
...
...
@@ -32,7 +32,6 @@ import com.tanpu.community.api.beans.vo.ImagesDTO;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp
;
import
com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedResReq
;
import
com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedSave4NewCommReq
;
import
com.tanpu.community.api.constants.RedisKeyConstant
;
import
com.tanpu.community.api.enums.BlockTypeEnum
;
import
com.tanpu.community.api.enums.DeleteTagEnum
;
import
com.tanpu.community.api.enums.NotificationTypeEnum
;
...
...
@@ -416,7 +415,7 @@ public class ThemeManager {
// 消息通知
ThemeEntity
formerTheme
=
themeService
.
queryByThemeId
(
req
.
getFormerThemeId
());
notificationService
.
insertForward
(
userId
,
formerTheme
.
getAuthorId
(),
formerTheme
.
getThemeId
(),
req
.
getTopicId
(),
req
.
getContent
().
get
(
0
).
getValue
());
messageNotify
(
formerTheme
.
getAuthorId
(),
userId
,
NotificationTypeEnum
.
FORWARD
);
notificationService
.
putNotifyCache
(
formerTheme
.
getAuthorId
(),
userId
,
NotificationTypeEnum
.
FORWARD
);
}
else
{
// 修改
...
...
@@ -672,7 +671,7 @@ public class ThemeManager {
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
req
.
getThemeId
());
// 消息通知
notificationService
.
insertLike
(
userId
,
themeEntity
.
getAuthorId
(),
req
.
getThemeId
());
messageNotify
(
themeEntity
.
getAuthorId
(),
userId
,
NotificationTypeEnum
.
LIKE
);
notificationService
.
putNotifyCache
(
themeEntity
.
getAuthorId
(),
userId
,
NotificationTypeEnum
.
LIKE
);
}
}
else
if
(
OperationTypeEnum
.
CANCEL
.
getCode
().
equals
(
req
.
getType
()))
{
...
...
@@ -927,12 +926,4 @@ public class ThemeManager {
redisCache
.
evict
(
StringUtils
.
joinWith
(
"_"
,
CACHE_THEME_ID
,
themeId
));
}
// 消息通知队列缓存
private
void
messageNotify
(
String
notifyUserId
,
String
operatorId
,
NotificationTypeEnum
type
){
UserInfoResp
userInfo
=
getUserInfo
(
operatorId
);
redisCache
.
incr
(
RedisKeyConstant
.
MESSAGE_NOTIFY_COUNT
+
notifyUserId
);
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_LAST_MSG
+
notifyUserId
,
userInfo
.
getNickName
()+
type
.
getType
()+
"了你的内容"
,
60
*
60
*
24
*
30
);
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_LAST_TIME
+
notifyUserId
,
TimeUtils
.
format
(
LocalDateTime
.
now
()),
60
*
60
*
24
*
30
);
}
}
community-service/src/main/java/com/tanpu/community/service/NotificationService.java
View file @
a095d0f4
package
com
.
tanpu
.
community
.
service
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.common.uuid.UuidGenHelper
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp
;
import
com.tanpu.community.api.constants.RedisKeyConstant
;
import
com.tanpu.community.api.enums.DeleteTagEnum
;
import
com.tanpu.community.api.enums.NotificationTypeEnum
;
import
com.tanpu.community.cache.RedisCache
;
import
com.tanpu.community.dao.entity.NotificationForwardDO
;
import
com.tanpu.community.dao.entity.NotificationLikeDO
;
import
com.tanpu.community.dao.entity.community.NotificationEntity
;
import
com.tanpu.community.dao.mapper.community.NotificationMapper
;
import
com.tanpu.community.feign.fatools.FeignClientForFatools
;
import
com.tanpu.community.util.TimeUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -27,6 +34,13 @@ public class NotificationService {
@Autowired
private
UuidGenHelper
uuidGenHelper
;
@Autowired
private
FeignClientForFatools
feignClientForFatools
;
@Autowired
private
RedisCache
redisCache
;
public
void
insert
(
String
operatorId
,
String
notifierId
,
NotificationTypeEnum
type
,
String
targetId
,
String
content
){
NotificationEntity
entity
=
NotificationEntity
.
builder
().
operatorId
(
operatorId
)
...
...
@@ -79,8 +93,8 @@ public class NotificationService {
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
();
...
...
@@ -164,6 +178,29 @@ public class NotificationService {
}
// 消息通知队列缓存
public
void
putNotifyCache
(
String
notifyUserId
,
String
operatorId
,
NotificationTypeEnum
type
){
UserInfoResp
userInfo
=
getUserInfo
(
operatorId
);
redisCache
.
incr
(
RedisKeyConstant
.
MESSAGE_NOTIFY_COUNT
+
notifyUserId
);
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_LAST_MSG
+
notifyUserId
,
userInfo
.
getNickName
()+
type
.
getType
()+
"了你的内容"
,
60
*
60
*
24
*
30
);
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_LAST_TIME
+
notifyUserId
,
TimeUtils
.
format
(
LocalDateTime
.
now
()),
60
*
60
*
24
*
30
);
}
// 消息通知队列缓存
public
void
putNotifyCacheFollow
(
String
notifyUserId
,
String
operatorId
)
{
UserInfoResp
userInfo
=
getUserInfo
(
operatorId
);
redisCache
.
incr
(
RedisKeyConstant
.
MESSAGE_NOTIFY_COUNT
+
notifyUserId
);
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_LAST_MSG
+
notifyUserId
,
userInfo
.
getNickName
()
+
"关注了你"
,
60
*
60
*
24
*
30
);
redisCache
.
set
(
RedisKeyConstant
.
MESSAGE_NOTIFY_LAST_TIME
+
notifyUserId
,
TimeUtils
.
format
(
LocalDateTime
.
now
()),
60
*
60
*
24
*
30
);
}
private
UserInfoResp
getUserInfo
(
String
authorId
)
{
CommonResp
<
UserInfoResp
>
userInfoNewCommonResp
=
feignClientForFatools
.
queryUserInfoNew
(
authorId
);
if
(
userInfoNewCommonResp
.
isNotSuccess
())
{
throw
new
BizException
(
"内部接口调用失败"
);
}
return
userInfoNewCommonResp
.
getData
();
}
}
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