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
4fd648e9
Commit
4fd648e9
authored
Aug 13, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
圈子消息通知
parent
f3513709
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
754 additions
and
19 deletions
+754
-19
NotificationQo.java
...java/com/tanpu/community/api/beans/qo/NotificationQo.java
+24
-0
ThemeNotifyQo.java
.../java/com/tanpu/community/api/beans/qo/ThemeNotifyQo.java
+83
-0
NotifyQueryReq.java
.../community/api/beans/req/notification/NotifyQueryReq.java
+18
-0
Pageable.java
...java/com/tanpu/community/api/beans/req/page/Pageable.java
+5
-8
NotificationTypeEnum.java
...a/com/tanpu/community/api/enums/NotificationTypeEnum.java
+36
-0
NotificationController.java
...om/tanpu/community/controller/NotificationController.java
+50
-0
CodeAutoGenerator.java
.../main/java/com/tanpu/community/dao/CodeAutoGenerator.java
+1
-1
NotificationForwardDO.java
...com/tanpu/community/dao/entity/NotificationForwardDO.java
+18
-0
NotificationLikeDO.java
...va/com/tanpu/community/dao/entity/NotificationLikeDO.java
+27
-0
NotificationEntity.java
...pu/community/dao/entity/community/NotificationEntity.java
+155
-0
NotificationMapper.java
...pu/community/dao/mapper/community/NotificationMapper.java
+16
-0
CommentManager.java
...main/java/com/tanpu/community/manager/CommentManager.java
+4
-0
NotificationManager.java
...java/com/tanpu/community/manager/NotificationManager.java
+111
-0
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+11
-1
CollectionService.java
...n/java/com/tanpu/community/service/CollectionService.java
+5
-1
NotificationService.java
...java/com/tanpu/community/service/NotificationService.java
+106
-0
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+65
-8
NotificationEntityMapper.xml
...n/resources/mapper/community/NotificationEntityMapper.xml
+19
-0
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/NotificationQo.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
api
.
beans
.
qo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
(
value
=
"圈子消息通知-概要"
)
public
class
NotificationQo
{
@ApiModelProperty
(
value
=
"未读条数"
)
private
Integer
updateCount
;
@ApiModelProperty
(
value
=
"最新消息"
)
private
String
message
;
}
community-api/src/main/java/com/tanpu/community/api/beans/qo/ThemeNotifyQo.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
api
.
beans
.
qo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
(
value
=
"圈子消息通知-详情"
)
public
class
ThemeNotifyQo
{
@ApiModelProperty
(
value
=
"通知主键Id"
)
private
String
notificationId
;
@ApiModelProperty
(
value
=
"被通知的用户id"
)
private
String
notifiedUserId
;
@ApiModelProperty
(
value
=
"1:转发 2:点赞 3:评论 4:关注"
)
private
Integer
messageType
;
@ApiModelProperty
(
value
=
"作者id"
)
public
String
authorId
;
@ApiModelProperty
(
value
=
"用户头像"
)
public
String
userImg
;
@ApiModelProperty
(
value
=
"用户简介"
)
private
String
userIntroduction
;
@ApiModelProperty
(
value
=
"当前用户是否关注该作者"
)
public
boolean
follow
;
@ApiModelProperty
(
value
=
"认证机构"
)
private
String
authOrg
;
@ApiModelProperty
(
value
=
"发表时间-距今"
)
public
String
upToNowTime
;
@ApiModelProperty
(
value
=
"发表时间-标准格式化"
)
public
String
formatTime
;
// 内容、话题
@ApiModelProperty
(
value
=
"所属的话题"
)
public
String
topicId
;
@ApiModelProperty
(
value
=
"话题名称"
)
public
String
topicTitle
;
@ApiModelProperty
(
value
=
"昵称"
)
public
String
nickName
;
@ApiModelProperty
(
value
=
"转发内容"
)
private
String
content
;
@ApiModelProperty
(
value
=
"被转发的主题"
)
public
String
formerThemeId
;
@ApiModelProperty
(
value
=
"转发的主题"
)
public
FormerThemeQo
formerTheme
;
// 点赞聚合
@ApiModelProperty
(
value
=
"用户头像"
)
public
List
<
String
>
likeUserIds
;
@ApiModelProperty
(
value
=
"用户头像"
)
public
List
<
String
>
likeUserImgs
;
@ApiModelProperty
(
value
=
"点赞人数"
)
public
Integer
likeUserCount
;
// 认证标签相关
@ApiModelProperty
(
"认证标签用-用户等级体系 0 游客 1注册用户 10投资人 20 探普理顾 30 探普专家理顾 40 交易理财师 50 首席投顾"
)
private
Integer
levelGrade
;
@ApiModelProperty
(
"认证标签用-当levelGrade=10有值 1投资萌新 2投资达人"
)
private
Integer
userInvestorType
;
@ApiModelProperty
(
"认证标签用-用户类型 1普通账号 2机构账号 3机构人员"
)
private
Integer
userType
;
@ApiModelProperty
(
"认证标签用-所属机构id"
)
private
String
belongUserOrgId
;
@ApiModelProperty
(
"认证标签用-所属机构名"
)
private
String
belongUserOrgName
;
}
community-api/src/main/java/com/tanpu/community/api/beans/req/notification/NotifyQueryReq.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
api
.
beans
.
req
.
notification
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@Data
public
class
NotifyQueryReq
{
@ApiModelProperty
(
value
=
"1:转发 2:点赞 3:评论 4:关注 0:全部"
)
private
Integer
type
;
@ApiModelProperty
(
value
=
"最后一条通知"
)
private
String
lastId
;
@ApiModelProperty
(
value
=
"页幅"
)
public
Integer
pageSize
=
20
;
}
community-api/src/main/java/com/tanpu/community/api/beans/req/page/Pageable.java
View file @
4fd648e9
package
com
.
tanpu
.
community
.
api
.
beans
.
req
.
page
;
package
com
.
tanpu
.
community
.
api
.
beans
.
req
.
page
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Builder
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.Data
;
import
javax.validation.constraints.NotEmpty
;
@Data
@Data
@Builder
@Builder
@ApiModel
(
value
=
"分页"
)
@ApiModel
(
value
=
"分页"
)
public
class
Pageable
{
public
class
Pageable
{
public
static
final
Integer
DEFAULT_PAGE_SIZE
=
10
;
public
static
final
Integer
DEFAULT_PAGE_SIZE
=
20
;
public
static
final
Integer
MAX_PAGE_SIZE
=
9999
;
public
static
final
Integer
DEFAULT_PAGE_NUMBER
=
0
;
public
static
final
Integer
DEFAULT_PAGE_NUMBER
=
1
;
@
NotEmpty
(
message
=
"分页Number不能为空
"
)
@
ApiModelProperty
(
value
=
"页码
"
)
public
Integer
pageNumber
=
DEFAULT_PAGE_NUMBER
;
public
Integer
pageNumber
=
DEFAULT_PAGE_NUMBER
;
@
NotEmpty
(
message
=
"分页pageSize不能为空
"
)
@
ApiModelProperty
(
value
=
"页幅
"
)
public
Integer
pageSize
=
DEFAULT_PAGE_SIZE
;
public
Integer
pageSize
=
DEFAULT_PAGE_SIZE
;
public
Pageable
()
{
public
Pageable
()
{
...
...
community-api/src/main/java/com/tanpu/community/api/enums/NotificationTypeEnum.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
api
.
enums
;
/**
* 通用操作类型枚举,包括点赞/取消点赞,收藏/取消收藏,关注/取消关注
*/
public
enum
NotificationTypeEnum
{
FORWARD
(
1
,
"转发"
),
LIKE
(
2
,
"点赞"
),
COMMENT
(
3
,
"评论"
),
FOLLOW
(
4
,
"关注"
),
ALL
(
0
,
"全部"
);
private
Integer
code
;
private
String
type
;
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
NotificationTypeEnum
(
Integer
code
,
String
type
)
{
this
.
code
=
code
;
this
.
type
=
type
;
}
}
community-service/src/main/java/com/tanpu/community/controller/NotificationController.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
controller
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.auth.AuthLogin
;
import
com.tanpu.common.auth.UserHolder
;
import
com.tanpu.community.api.beans.qo.NotificationQo
;
import
com.tanpu.community.api.beans.qo.ThemeNotifyQo
;
import
com.tanpu.community.api.beans.req.notification.NotifyQueryReq
;
import
com.tanpu.community.manager.NotificationManager
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
* 消息通知
*/
@Slf4j
@RestController
@RequestMapping
(
"/notification"
)
public
class
NotificationController
{
@Autowired
private
UserHolder
userHolder
;
@Autowired
private
NotificationManager
notificationManager
;
@AuthLogin
@PostMapping
(
"/query"
)
@ResponseBody
public
CommonResp
<
List
<
ThemeNotifyQo
>>
query
(
NotifyQueryReq
req
){
List
<
ThemeNotifyQo
>
query
=
notificationManager
.
queryList
(
req
,
userHolder
.
getUserId
());
return
CommonResp
.
success
(
query
);
}
@AuthLogin
@PostMapping
(
"/updateCount"
)
@ResponseBody
public
CommonResp
<
NotificationQo
>
query
(){
NotificationQo
notificationQO
=
notificationManager
.
queryBriefInfo
(
userHolder
.
getUserId
());
return
CommonResp
.
success
(
notificationQO
);
}
}
community-service/src/main/java/com/tanpu/community/dao/CodeAutoGenerator.java
View file @
4fd648e9
...
@@ -23,7 +23,7 @@ public class CodeAutoGenerator {
...
@@ -23,7 +23,7 @@ public class CodeAutoGenerator {
String
mysqlPassword
=
"@imeng123"
;
String
mysqlPassword
=
"@imeng123"
;
String
jdbcUrl
=
"jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community"
;
String
jdbcUrl
=
"jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community"
;
// String[] tables = new String[]{"theme"};
// String[] tables = new String[]{"theme"};
String
[]
tables
=
new
String
[]{
"
message_queue
"
};
String
[]
tables
=
new
String
[]{
"
notification
"
};
String
basePackage
=
"com.tanpu.community"
;
String
basePackage
=
"com.tanpu.community"
;
String
mapperPackage
=
"dao.mapper.community"
;
String
mapperPackage
=
"dao.mapper.community"
;
String
entityPackage
=
"dao.entity.community"
;
String
entityPackage
=
"dao.entity.community"
;
...
...
community-service/src/main/java/com/tanpu/community/dao/entity/NotificationForwardDO.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
dao
.
entity
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public
class
NotificationForwardDO
{
private
String
content
;
private
String
topicId
;
}
community-service/src/main/java/com/tanpu/community/dao/entity/NotificationLikeDO.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
dao
.
entity
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.TreeSet
;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public
class
NotificationLikeDO
{
private
Integer
count
;
private
TreeSet
<
String
>
set
;
public
void
addItem
(
String
item
){
if
(
this
.
set
.
size
()>=
3
){
set
.
pollFirst
();
}
set
.
add
(
item
);
count
++;
}
}
community-service/src/main/java/com/tanpu/community/dao/entity/community/NotificationEntity.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
dao
.
entity
.
community
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
/**
* <p>
* 消息通知记录
* </p>
*
* @author xudong
* @since 2021-08-13
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName
(
"notification"
)
@ApiModel
(
value
=
"NotificationEntity对象"
,
description
=
"消息通知记录"
)
public
class
NotificationEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"id"
)
private
Long
id
;
@ApiModelProperty
(
value
=
"通知主键Id"
)
private
String
notificationId
;
@ApiModelProperty
(
value
=
"被通知的用户id"
)
private
String
notifiedUserId
;
@ApiModelProperty
(
value
=
"1:转发 2:点赞 3:评论 4:关注"
)
private
Integer
messageType
;
@ApiModelProperty
(
value
=
"目标id,类型是转发、点赞、评论时为themeId,关注则为user_id"
)
private
String
targetId
;
@ApiModelProperty
(
value
=
"评论:评论内容 转发:topicId+内容 点赞:人数+最近3个用户"
)
private
String
content
;
@ApiModelProperty
(
value
=
"操作者id"
)
private
String
operatorId
;
private
LocalDateTime
createTime
;
private
LocalDateTime
updateTime
;
private
Integer
deleteTag
;
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getNotificationId
()
{
return
notificationId
;
}
public
void
setNotificationId
(
String
notificationId
)
{
this
.
notificationId
=
notificationId
;
}
public
String
getNotifiedUserId
()
{
return
notifiedUserId
;
}
public
void
setNotifiedUserId
(
String
notifiedUserId
)
{
this
.
notifiedUserId
=
notifiedUserId
;
}
public
Integer
getMessageType
()
{
return
messageType
;
}
public
void
setMessageType
(
Integer
messageType
)
{
this
.
messageType
=
messageType
;
}
public
String
getTargetId
()
{
return
targetId
;
}
public
void
setTargetId
(
String
targetId
)
{
this
.
targetId
=
targetId
;
}
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
String
getOperatorId
()
{
return
operatorId
;
}
public
void
setOperatorId
(
String
operatorId
)
{
this
.
operatorId
=
operatorId
;
}
public
LocalDateTime
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
LocalDateTime
createTime
)
{
this
.
createTime
=
createTime
;
}
public
LocalDateTime
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
LocalDateTime
updateTime
)
{
this
.
updateTime
=
updateTime
;
}
public
Integer
getDeleteTag
()
{
return
deleteTag
;
}
public
void
setDeleteTag
(
Integer
deleteTag
)
{
this
.
deleteTag
=
deleteTag
;
}
@Override
public
String
toString
()
{
return
"NotificationEntity{"
+
"id="
+
id
+
", notificationId="
+
notificationId
+
", notifiedUserId="
+
notifiedUserId
+
", messageType="
+
messageType
+
", targetId="
+
targetId
+
", content="
+
content
+
", operatorId="
+
operatorId
+
", createTime="
+
createTime
+
", updateTime="
+
updateTime
+
", deleteTag="
+
deleteTag
+
"}"
;
}
}
community-service/src/main/java/com/tanpu/community/dao/mapper/community/NotificationMapper.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
dao
.
mapper
.
community
;
import
com.tanpu.community.dao.entity.community.NotificationEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
/**
* <p>
* 消息通知记录 Mapper 接口
* </p>
*
* @author xudong
* @since 2021-08-13
*/
public
interface
NotificationMapper
extends
BaseMapper
<
NotificationEntity
>
{
}
community-service/src/main/java/com/tanpu/community/manager/CommentManager.java
View file @
4fd648e9
...
@@ -16,6 +16,7 @@ import com.tanpu.community.dao.entity.community.CommentEntity;
...
@@ -16,6 +16,7 @@ import com.tanpu.community.dao.entity.community.CommentEntity;
import
com.tanpu.community.feign.fatools.FeignClientForFatools
;
import
com.tanpu.community.feign.fatools.FeignClientForFatools
;
import
com.tanpu.community.service.CollectionService
;
import
com.tanpu.community.service.CollectionService
;
import
com.tanpu.community.service.CommentService
;
import
com.tanpu.community.service.CommentService
;
import
com.tanpu.community.service.NotificationService
;
import
com.tanpu.community.service.ReportLogService
;
import
com.tanpu.community.service.ReportLogService
;
import
com.tanpu.community.util.ConvertUtil
;
import
com.tanpu.community.util.ConvertUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -50,6 +51,8 @@ public class CommentManager {
...
@@ -50,6 +51,8 @@ public class CommentManager {
@Autowired
@Autowired
private
RedisCache
redisCache
;
private
RedisCache
redisCache
;
// 评论(对主题)
// 评论(对主题)
// 发表评论(对主题)
// 发表评论(对主题)
public
CommentQo
comment
(
CreateCommentReq
req
,
String
userId
)
{
public
CommentQo
comment
(
CreateCommentReq
req
,
String
userId
)
{
...
@@ -133,6 +136,7 @@ public class CommentManager {
...
@@ -133,6 +136,7 @@ public class CommentManager {
public
void
likeComment
(
LikeCommentReq
req
,
String
userId
)
{
public
void
likeComment
(
LikeCommentReq
req
,
String
userId
)
{
if
(
OperationTypeEnum
.
CONFIRM
.
getCode
().
equals
(
req
.
getType
()))
{
if
(
OperationTypeEnum
.
CONFIRM
.
getCode
().
equals
(
req
.
getType
()))
{
collectionService
.
saveOrUpdate
(
req
.
getCommentId
(),
userId
,
CollectionTypeEnum
.
LIKE_COMMENT
);
collectionService
.
saveOrUpdate
(
req
.
getCommentId
(),
userId
,
CollectionTypeEnum
.
LIKE_COMMENT
);
}
else
if
(
OperationTypeEnum
.
CANCEL
.
getCode
().
equals
(
req
.
getType
()))
{
}
else
if
(
OperationTypeEnum
.
CANCEL
.
getCode
().
equals
(
req
.
getType
()))
{
collectionService
.
delete
(
req
.
getCommentId
(),
userId
,
CollectionTypeEnum
.
LIKE_COMMENT
);
collectionService
.
delete
(
req
.
getCommentId
(),
userId
,
CollectionTypeEnum
.
LIKE_COMMENT
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/manager/NotificationManager.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
manager
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.qo.FormerThemeQo
;
import
com.tanpu.community.api.beans.qo.NotificationQo
;
import
com.tanpu.community.api.beans.qo.ThemeNotifyQo
;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
import
com.tanpu.community.api.beans.req.notification.NotifyQueryReq
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp
;
import
com.tanpu.community.cache.RedisCache
;
import
com.tanpu.community.dao.entity.community.NotificationEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.feign.fatools.FeignClientForFatools
;
import
com.tanpu.community.service.BatchFeignCallService
;
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
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
static
com
.
tanpu
.
community
.
api
.
constants
.
RedisKeyConstant
.
CACHE_FEIGN_USER_INFO
;
import
static
com
.
tanpu
.
community
.
api
.
constants
.
RedisKeyConstant
.
CACHE_FORWARD_THEME_ID
;
@Service
public
class
NotificationManager
{
@Autowired
private
NotificationService
notificationService
;
@Autowired
private
TopicService
topicService
;
@Autowired
private
ThemeService
themeService
;
@Resource
private
BatchFeignCallService
batchFeignCallService
;
@Autowired
private
FeignClientForFatools
feignClientForFatools
;
@Autowired
private
RedisCache
redisCache
;
public
List
<
ThemeNotifyQo
>
queryList
(
NotifyQueryReq
req
,
String
userId
){
List
<
NotificationEntity
>
query
=
notificationService
.
query
(
userId
,
req
.
getType
(),
req
.
getLastId
(),
req
.
getPageSize
());
List
<
ThemeNotifyQo
>
themeNotifyQos
=
ConvertUtil
.
notificationEntitiy2ThemeQos
(
query
);
for
(
ThemeNotifyQo
themeNotifyQo
:
themeNotifyQos
)
{
// 用户信息
UserInfoResp
userInfo
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FEIGN_USER_INFO
,
themeNotifyQo
.
getAuthorId
()),
60
,
()
->
this
.
getUserInfo
(
themeNotifyQo
.
getAuthorId
()),
UserInfoResp
.
class
);
themeNotifyQo
.
setAuthorId
(
userInfo
.
getUserId
());
themeNotifyQo
.
setNickName
(
userInfo
.
getNickName
());
themeNotifyQo
.
setUserImg
(
userInfo
.
getHeadImageUrl
());
themeNotifyQo
.
setUserType
(
userInfo
.
getUserType
());
themeNotifyQo
.
setLevelGrade
(
userInfo
.
getLevelGrade
());
themeNotifyQo
.
setUserInvestorType
(
userInfo
.
getUserInvestorType
());
themeNotifyQo
.
setBelongUserOrgId
(
userInfo
.
getBelongUserOrgId
());
themeNotifyQo
.
setBelongUserOrgName
(
userInfo
.
getBelongUserOrgName
());
// 封装转发对象
if
(
StringUtils
.
isNotEmpty
(
themeNotifyQo
.
getFormerThemeId
())){
FormerThemeQo
former
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FORWARD_THEME_ID
,
themeNotifyQo
.
getFormerThemeId
()),
60
,
()
->
this
.
getFormerTheme
(
themeNotifyQo
.
getFormerThemeId
()),
FormerThemeQo
.
class
);
themeNotifyQo
.
setFormerTheme
(
former
);
}
if
(
StringUtils
.
isNotEmpty
(
themeNotifyQo
.
getTopicId
())){
TopicEntity
topicEntity
=
topicService
.
queryById
(
themeNotifyQo
.
getTopicId
());
themeNotifyQo
.
setTopicTitle
(
topicEntity
.
getTopicTitle
());
}
}
return
themeNotifyQos
;
}
private
UserInfoResp
getUserInfo
(
String
authorId
)
{
CommonResp
<
UserInfoResp
>
userInfoNewCommonResp
=
feignClientForFatools
.
queryUserInfoNew
(
authorId
);
if
(
userInfoNewCommonResp
.
isNotSuccess
())
{
throw
new
BizException
(
"内部接口调用失败"
);
}
return
userInfoNewCommonResp
.
getData
();
}
public
NotificationQo
queryBriefInfo
(
String
userId
){
return
NotificationQo
.
builder
().
message
(
" {用户名}关注了你"
).
updateCount
(
99
).
build
();
}
//返回被转发主题
private
FormerThemeQo
getFormerTheme
(
String
formerThemeId
)
{
if
(
StringUtils
.
isNotBlank
(
formerThemeId
))
{
ThemeQo
formerTheme
=
ConvertUtil
.
themeEntityToQo
(
themeService
.
queryByThemeId
(
formerThemeId
));
if
(
formerTheme
!=
null
)
{
batchFeignCallService
.
getAttachDetail
(
formerTheme
);
FormerThemeQo
f
=
ConvertUtil
.
themeQo2FormerThemeQo
(
formerTheme
);
return
f
;
}
}
return
null
;
}
}
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
4fd648e9
...
@@ -135,6 +135,9 @@ public class ThemeManager {
...
@@ -135,6 +135,9 @@ public class ThemeManager {
@Resource
@Resource
private
RestTemplate
restTemplate
;
private
RestTemplate
restTemplate
;
@Autowired
private
NotificationService
notificationService
;
@PostConstruct
@PostConstruct
public
void
init
()
throws
IOException
{
public
void
init
()
throws
IOException
{
File
f
=
new
File
(
tmpDir
);
File
f
=
new
File
(
tmpDir
);
...
@@ -408,6 +411,9 @@ public class ThemeManager {
...
@@ -408,6 +411,9 @@ public class ThemeManager {
if
(
StringUtils
.
isBlank
(
req
.
getEditThemeId
())
||
req
.
getEditThemeId
().
equals
(
req
.
getFormerThemeId
()))
{
if
(
StringUtils
.
isBlank
(
req
.
getEditThemeId
())
||
req
.
getEditThemeId
().
equals
(
req
.
getFormerThemeId
()))
{
// 新建
// 新建
themeService
.
insertTheme
(
themeEntity
);
themeService
.
insertTheme
(
themeEntity
);
// 消息通知
ThemeEntity
formerTheme
=
themeService
.
queryByThemeId
(
req
.
getFormerThemeId
());
notificationService
.
insertForward
(
userId
,
formerTheme
.
getAuthorId
(),
formerTheme
.
getThemeId
(),
req
.
getTopicId
(),
req
.
getContent
().
get
(
0
).
getValue
());
}
else
{
}
else
{
// 修改
// 修改
themeService
.
update
(
themeEntity
,
req
.
getEditThemeId
());
themeService
.
update
(
themeEntity
,
req
.
getEditThemeId
());
...
@@ -658,7 +664,11 @@ public class ThemeManager {
...
@@ -658,7 +664,11 @@ public class ThemeManager {
// 点赞/取消点赞
// 点赞/取消点赞
public
void
like
(
LikeThemeReq
req
,
String
userId
)
{
public
void
like
(
LikeThemeReq
req
,
String
userId
)
{
if
(
OperationTypeEnum
.
CONFIRM
.
getCode
().
equals
(
req
.
getType
()))
{
if
(
OperationTypeEnum
.
CONFIRM
.
getCode
().
equals
(
req
.
getType
()))
{
collectionService
.
saveOrUpdate
(
req
.
getThemeId
(),
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
if
(
collectionService
.
saveOrUpdate
(
req
.
getThemeId
(),
userId
,
CollectionTypeEnum
.
LIKE_THEME
)){
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
req
.
getThemeId
());
notificationService
.
insertLike
(
userId
,
themeEntity
.
getAuthorId
(),
req
.
getThemeId
());
}
}
else
if
(
OperationTypeEnum
.
CANCEL
.
getCode
().
equals
(
req
.
getType
()))
{
}
else
if
(
OperationTypeEnum
.
CANCEL
.
getCode
().
equals
(
req
.
getType
()))
{
collectionService
.
delete
(
req
.
getThemeId
(),
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
collectionService
.
delete
(
req
.
getThemeId
(),
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/CollectionService.java
View file @
4fd648e9
...
@@ -27,9 +27,11 @@ public class CollectionService {
...
@@ -27,9 +27,11 @@ public class CollectionService {
private
CollectionMapper
collectionMapper
;
private
CollectionMapper
collectionMapper
;
// 若不存在则新增,若存在则修改deleteTag
// 若不存在则新增,若存在则修改deleteTag
@Transactional
@Transactional
public
void
saveOrUpdate
(
String
themeId
,
String
userId
,
CollectionTypeEnum
type
)
{
public
boolean
saveOrUpdate
(
String
themeId
,
String
userId
,
CollectionTypeEnum
type
)
{
// 判断记录是否存在,无论是否删除
// 判断记录是否存在,无论是否删除
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>()
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
...
@@ -40,6 +42,7 @@ public class CollectionService {
...
@@ -40,6 +42,7 @@ public class CollectionService {
queryCollection
.
setDeleteTag
(
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
queryCollection
.
setDeleteTag
(
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
queryCollection
.
setCollectionTime
(
LocalDateTime
.
now
());
queryCollection
.
setCollectionTime
(
LocalDateTime
.
now
());
collectionMapper
.
updateById
(
queryCollection
);
collectionMapper
.
updateById
(
queryCollection
);
return
false
;
}
else
{
}
else
{
CollectionEntity
entity
=
CollectionEntity
.
builder
()
CollectionEntity
entity
=
CollectionEntity
.
builder
()
.
collectionType
(
type
.
getCode
())
.
collectionType
(
type
.
getCode
())
...
@@ -49,6 +52,7 @@ public class CollectionService {
...
@@ -49,6 +52,7 @@ public class CollectionService {
.
build
();
.
build
();
collectionMapper
.
insert
(
entity
);
collectionMapper
.
insert
(
entity
);
return
true
;
}
}
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/NotificationService.java
0 → 100644
View file @
4fd648e9
package
com
.
tanpu
.
community
.
service
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.common.uuid.UuidGenHelper
;
import
com.tanpu.community.api.enums.NotificationTypeEnum
;
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
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Service
public
class
NotificationService
{
@Resource
private
NotificationMapper
notificationMapper
;
@Autowired
private
UuidGenHelper
uuidGenHelper
;
public
void
insert
(
String
operatorId
,
String
notifierId
,
NotificationTypeEnum
type
,
String
targetId
,
String
content
){
NotificationEntity
.
builder
().
operatorId
(
operatorId
)
.
notificationId
(
uuidGenHelper
.
getUuidStr
())
.
notifiedUserId
(
notifierId
)
.
messageType
(
type
.
getCode
())
.
content
(
content
)
.
operatorId
(
targetId
).
build
();
}
public
void
insertForward
(
String
operatorId
,
String
notifierId
,
String
themeId
,
String
topicId
,
String
text
){
NotificationForwardDO
forwardDO
=
NotificationForwardDO
.
builder
().
topicId
(
topicId
).
content
(
text
).
build
();
NotificationEntity
.
builder
().
operatorId
(
operatorId
)
.
notificationId
(
uuidGenHelper
.
getUuidStr
())
.
notifiedUserId
(
notifierId
)
.
messageType
(
NotificationTypeEnum
.
LIKE
.
getCode
())
.
content
(
JsonUtil
.
toJson
(
forwardDO
))
.
operatorId
(
operatorId
)
.
targetId
(
themeId
)
.
build
();
}
public
void
insertLike
(
String
operatorId
,
String
notifierId
,
String
targetId
){
NotificationEntity
entity
=
notificationMapper
.
selectOne
(
new
LambdaQueryWrapper
<
NotificationEntity
>()
.
eq
(
NotificationEntity:
:
getMessageType
,
NotificationTypeEnum
.
LIKE
.
getCode
())
.
eq
(
NotificationEntity:
:
getNotifiedUserId
,
notifierId
));
if
(
entity
!=
null
){
NotificationLikeDO
notificationLikeDO
=
JsonUtil
.
toBean
(
entity
.
getContent
(),
NotificationLikeDO
.
class
);
notificationLikeDO
.
addItem
(
operatorId
);
entity
.
setContent
(
JsonUtil
.
toJson
(
notificationLikeDO
));
notificationMapper
.
updateById
(
entity
);
}
else
{
NotificationLikeDO
notificationLikeDO
=
new
NotificationLikeDO
();
notificationLikeDO
.
addItem
(
operatorId
);
NotificationEntity
.
builder
().
operatorId
(
operatorId
)
.
notificationId
(
uuidGenHelper
.
getUuidStr
())
.
messageType
(
NotificationTypeEnum
.
LIKE
.
getCode
())
.
notifiedUserId
(
notifierId
)
.
content
(
JsonUtil
.
toJson
(
notificationLikeDO
))
.
targetId
(
targetId
)
.
operatorId
(
operatorId
)
.
build
();
}
}
public
void
insert
(
NotificationEntity
entity
){
notificationMapper
.
insert
(
entity
);
}
public
NotificationEntity
queryById
(
String
notificationId
){
return
notificationMapper
.
selectOne
(
new
LambdaQueryWrapper
<
NotificationEntity
>()
.
eq
(
NotificationEntity:
:
getNotificationId
,
notificationId
));
}
public
List
<
NotificationEntity
>
query
(
String
userId
,
Integer
type
,
String
lastId
,
Integer
pageSize
){
NotificationEntity
lastOne
=
notificationMapper
.
selectOne
(
new
LambdaQueryWrapper
<
NotificationEntity
>()
.
eq
(
NotificationEntity:
:
getNotificationId
,
lastId
));
LambdaQueryWrapper
<
NotificationEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
NotificationEntity
>()
.
eq
(
NotificationEntity:
:
getNotifiedUserId
,
userId
)
.
lt
(
NotificationEntity:
:
getCreateTime
,
lastOne
.
getCreateTime
())
.
last
(
"limit "
+
pageSize
);
if
(!
NotificationTypeEnum
.
ALL
.
getCode
().
equals
(
type
)){
queryWrapper
.
eq
(
NotificationEntity:
:
getMessageType
,
type
);
}
return
notificationMapper
.
selectList
(
queryWrapper
);
}
}
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
4fd648e9
...
@@ -4,14 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
...
@@ -4,14 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import
com.tanpu.biz.common.enums.RelTypeEnum
;
import
com.tanpu.biz.common.enums.RelTypeEnum
;
import
com.tanpu.biz.common.enums.community.TopicStatusEnum
;
import
com.tanpu.biz.common.enums.community.TopicStatusEnum
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.community.api.beans.qo.CommentQo
;
import
com.tanpu.community.api.beans.qo.*
;
import
com.tanpu.community.api.beans.qo.ESThemeQo
;
import
com.tanpu.community.api.beans.qo.FollowQo
;
import
com.tanpu.community.api.beans.qo.FormerThemeQo
;
import
com.tanpu.community.api.beans.qo.ThemeAnalysDO
;
import
com.tanpu.community.api.beans.qo.ThemeContentQo
;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
import
com.tanpu.community.api.beans.qo.TopicRankQo
;
import
com.tanpu.community.api.beans.req.theme.CreateThemeReq
;
import
com.tanpu.community.api.beans.req.theme.CreateThemeReq
;
import
com.tanpu.community.api.beans.req.theme.ThemeContentReq
;
import
com.tanpu.community.api.beans.req.theme.ThemeContentReq
;
import
com.tanpu.community.api.beans.resp.FileUploadResp
;
import
com.tanpu.community.api.beans.resp.FileUploadResp
;
...
@@ -19,8 +12,12 @@ import com.tanpu.community.api.beans.vo.ImagesDTO;
...
@@ -19,8 +12,12 @@ import com.tanpu.community.api.beans.vo.ImagesDTO;
import
com.tanpu.community.api.beans.vo.KafkaDurationUptMsg
;
import
com.tanpu.community.api.beans.vo.KafkaDurationUptMsg
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp
;
import
com.tanpu.community.api.enums.DeleteTagEnum
;
import
com.tanpu.community.api.enums.DeleteTagEnum
;
import
com.tanpu.community.api.enums.NotificationTypeEnum
;
import
com.tanpu.community.dao.entity.NotificationLikeDO
;
import
com.tanpu.community.dao.entity.NotificationForwardDO
;
import
com.tanpu.community.dao.entity.community.CommentEntity
;
import
com.tanpu.community.dao.entity.community.CommentEntity
;
import
com.tanpu.community.dao.entity.community.FileRecordEntity
;
import
com.tanpu.community.dao.entity.community.FileRecordEntity
;
import
com.tanpu.community.dao.entity.community.NotificationEntity
;
import
com.tanpu.community.dao.entity.community.ThemeAttachmentEntity
;
import
com.tanpu.community.dao.entity.community.ThemeAttachmentEntity
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
...
@@ -34,6 +31,7 @@ import java.util.ArrayList;
...
@@ -34,6 +31,7 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.TreeSet
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
public
class
ConvertUtil
{
public
class
ConvertUtil
{
...
@@ -237,5 +235,64 @@ public class ConvertUtil {
...
@@ -237,5 +235,64 @@ public class ConvertUtil {
return
resp
;
return
resp
;
}
}
public
static
ThemeNotifyQo
notificationEntitiy2ThemeQo
(
NotificationEntity
entity
)
{
ThemeNotifyQo
themeNotifyQo
=
new
ThemeNotifyQo
();
BeanUtils
.
copyProperties
(
entity
,
themeNotifyQo
);
// 操作者
themeNotifyQo
.
setAuthorId
(
entity
.
getOperatorId
());
// 转、评、赞 有原贴
if
(
entity
.
getMessageType
().
equals
(
NotificationTypeEnum
.
FORWARD
.
getCode
())
||
entity
.
getMessageType
().
equals
(
NotificationTypeEnum
.
LIKE
.
getCode
())
||
entity
.
getMessageType
().
equals
(
NotificationTypeEnum
.
COMMENT
.
getCode
())
)
{
themeNotifyQo
.
setFormerThemeId
(
entity
.
getTargetId
());
}
// 转发有话题信息
if
(
entity
.
getMessageType
().
equals
(
NotificationTypeEnum
.
FORWARD
.
getCode
()))
{
themeNotifyQo
.
setFormerThemeId
(
entity
.
getTargetId
());
if
(!
StringUtils
.
isEmpty
(
entity
.
getContent
()))
{
NotificationForwardDO
forwardDO
=
JsonUtil
.
toBean
(
entity
.
getContent
(),
NotificationForwardDO
.
class
);
themeNotifyQo
.
setContent
(
forwardDO
.
getContent
());
themeNotifyQo
.
setTopicId
(
forwardDO
.
getTopicId
());
}
}
// 点赞需要聚合头像和人数
if
(
entity
.
getMessageType
().
equals
(
NotificationTypeEnum
.
LIKE
.
getCode
()))
{
if
(!
StringUtils
.
isEmpty
(
entity
.
getContent
()))
{
NotificationLikeDO
notificationLikeDO
=
JsonUtil
.
toBean
(
entity
.
getContent
(),
NotificationLikeDO
.
class
);
themeNotifyQo
.
setLikeUserCount
(
notificationLikeDO
.
getCount
());
themeNotifyQo
.
setLikeUserIds
(
new
ArrayList
<>(
notificationLikeDO
.
getSet
()));
}
}
return
themeNotifyQo
;
}
public
static
List
<
ThemeNotifyQo
>
notificationEntitiy2ThemeQos
(
List
<
NotificationEntity
>
entities
)
{
return
entities
.
stream
().
map
(
ConvertUtil:
:
notificationEntitiy2ThemeQo
).
collect
(
Collectors
.
toList
());
}
public
static
void
main
(
String
[]
args
)
{
NotificationLikeDO
notificationLikeDO
=
new
NotificationLikeDO
();
notificationLikeDO
.
setCount
(
1
);
TreeSet
<
String
>
set
=
new
TreeSet
<>();
set
.
add
(
"aaa"
);
set
.
add
(
"bbb"
);
set
.
add
(
"ccc"
);
set
.
pollFirst
();
set
.
add
(
"ddd"
);
notificationLikeDO
.
setSet
(
set
);
String
x
=
JsonUtil
.
toJson
(
notificationLikeDO
);
System
.
out
.
println
(
x
);
NotificationLikeDO
notificationLikeDO1
=
JsonUtil
.
toBean
(
x
,
NotificationLikeDO
.
class
);
System
.
out
.
println
(
notificationLikeDO1
);
}
}
}
community-service/src/main/resources/mapper/community/NotificationEntityMapper.xml
0 → 100644
View file @
4fd648e9
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.tanpu.community.dao.mapper.community.NotificationMapper"
>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"com.tanpu.community.dao.entity.community.NotificationEntity"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"notification_id"
property=
"notificationId"
/>
<result
column=
"notified_user_id"
property=
"notifiedUserId"
/>
<result
column=
"message_type"
property=
"messageType"
/>
<result
column=
"target_id"
property=
"targetId"
/>
<result
column=
"content"
property=
"content"
/>
<result
column=
"operator_id"
property=
"operatorId"
/>
<result
column=
"create_time"
property=
"createTime"
/>
<result
column=
"update_time"
property=
"updateTime"
/>
<result
column=
"delete_tag"
property=
"deleteTag"
/>
</resultMap>
</mapper>
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