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
d94a0dfb
Commit
d94a0dfb
authored
Jun 18, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ConvertUtil
parent
da0e6fa9
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
155 additions
and
44 deletions
+155
-44
TopicBriefInfoDTO.java
...java/com/tanpu/community/api/beans/TopicBriefInfoDTO.java
+8
-0
TopicDataAnalysDTO.java
...ava/com/tanpu/community/api/beans/TopicDataAnalysDTO.java
+31
-0
RedisKeyConstant.java
...a/com/tanpu/community/api/constants/RedisKeyConstant.java
+20
-1
TopicController.java
.../java/com/tanpu/community/controller/TopicController.java
+19
-26
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+49
-11
TopicService.java
...c/main/java/com/tanpu/community/service/TopicService.java
+17
-6
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+11
-0
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/TopicBriefInfoDTO.java
View file @
d94a0dfb
package
com
.
tanpu
.
community
.
api
.
beans
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* APP端话题列表页
*/
@Data
public
class
TopicBriefInfoDTO
{
private
String
topicId
;
@ApiModelProperty
(
"话题名称"
)
private
String
title
;
@ApiModelProperty
(
"讨论数"
)
private
Long
discussionAmount
;
}
community-api/src/main/java/com/tanpu/community/api/beans/TopicDataAnalysDTO.java
0 → 100644
View file @
d94a0dfb
package
com
.
tanpu
.
community
.
api
.
beans
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* 管理后台:话题数据分析
*/
@Data
public
class
TopicDataAnalysDTO
{
@ApiModelProperty
(
value
=
"id"
)
private
String
id
;
@ApiModelProperty
(
value
=
"话题名称"
)
private
String
topicTitle
;
@ApiModelProperty
(
value
=
"总浏览量"
)
private
Long
viewTotalAmount
;
@ApiModelProperty
(
value
=
"话题页面浏览量"
)
private
Long
viewPageAmount
;
@ApiModelProperty
(
value
=
"发帖数"
)
private
Long
themeAmount
;
@ApiModelProperty
(
value
=
"回帖数"
)
private
Long
commentAmount
;
@ApiModelProperty
(
value
=
"总用户数"
)
private
Long
userTotalAmount
;
@ApiModelProperty
(
value
=
"发帖人数"
)
private
Long
posterAmount
;
@ApiModelProperty
(
value
=
"回帖人数"
)
private
Long
replIierAmount
;
}
community-api/src/main/java/com/tanpu/community/api/constants/RedisKeyConstant.java
View file @
d94a0dfb
...
...
@@ -2,11 +2,30 @@ package com.tanpu.community.api.constants;
public
class
RedisKeyConstant
{
public
static
final
String
TOPIC_VIEW_AMOUNT_
=
"TOPIC_VIEW_AMOUNT_"
;
//话题页浏览量
public
static
final
String
TOPIC_VIEW_AMOUNT_
=
"TOPIC_PAGE_VIEW_AMOUNT_"
;
//话题总浏览量
public
static
final
String
TOPIC_TOTAL_VIEW_AMOUNT_
=
"TOPIC_TOTAL_VIEW_AMOUNT_"
;
//点赞量
public
static
final
String
TOPIC_LIKE_AMOUNT_
=
"TOPIC_LIKE_AMOUNT_"
;
//收藏量
public
static
final
String
TOPIC_BOOK_AMOUNT_
=
"TOPIC_BOOK_AMOUNT_"
;
//评论数
public
static
final
String
TOPIC_COMMENT_AMOUNT_
=
"TOPIC_COMMENT_AMOUNT_"
;
//用户数
public
static
final
String
TOPIC_USER_AMOUNT_
=
"TOPIC_USER_AMOUNT_"
;
//讨论量
public
static
final
String
TOPIC_DISCUSS_AMOUNT_
=
"TOPIC_DISCUSS_AMOUNT_"
;
//发帖数
public
static
final
String
TOPIC_THEME_AMOUNT_
=
"TOPIC_THEME_AMOUNT_"
;
//回帖数
public
static
final
String
TOPIC_COMENT_AMOUNT_
=
"TOPIC_COMENT_AMOUNT_"
;
//总用户数
public
static
final
String
TOPIC_TOTAOL_USER_AMOUNT_
=
"TOPIC_TOTAOL_USER_AMOUNT_"
;
//发帖人数
public
static
final
String
TOPIC_POSTER_AMOUNT_
=
"TOPIC_POSTER_AMOUNT_"
;
//回帖人数
public
static
final
String
TOPIC_REPLIER_AMOUNT_
=
"TOPIC_REPLIER_AMOUNT_"
;
public
static
final
String
THEME_VIEW_AMOUNT_
=
"THEME_VIEW_AMOUNT_"
;
public
static
final
String
THEME_LIKE_AMOUNT_
=
"THEME_LIKE_AMOUNT_"
;
...
...
community-service/src/main/java/com/tanpu/community/controller/TopicController.java
View file @
d94a0dfb
...
...
@@ -2,12 +2,11 @@ package com.tanpu.community.controller;
import
com.tanpu.community.api.beans.TopicBriefInfoDTO
;
import
com.tanpu.community.api.beans.TopicDTO
;
import
com.tanpu.community.
dao.entity.community.TopicEntity
;
import
com.tanpu.community.
api.beans.TopicDataAnalysDTO
;
import
com.tanpu.community.manager.TopicManager
;
import
com.tanpu.community.model.req.topic.TopicConcealReq
;
import
com.tanpu.community.model.req.topic.TopicModifyMountReq
;
import
com.tanpu.community.model.req.topic.TopicTopReq
;
import
com.tanpu.community.util.ConvertUtil
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -16,7 +15,6 @@ import org.springframework.web.bind.MissingServletRequestParameterException;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@RestController
@Slf4j
...
...
@@ -30,33 +28,22 @@ public class TopicController {
@GetMapping
(
value
=
"/queryTopicInfoList"
)
@ApiOperation
(
"APP全部话题页面,可搜索"
)
@ResponseBody
public
List
<
Topic
BriefInfo
DTO
>
getTopicBriefInfoList
(){
List
<
Topic
BriefInfoDTO
>
allTopic
=
topicManager
.
getBreifInfoTopic
();
public
List
<
TopicDTO
>
getTopicBriefInfoList
(){
List
<
Topic
DTO
>
allTopic
=
topicManager
.
getAllTopicDetail
();
return
allTopic
;
}
@GetMapping
(
value
=
"/admin/queryTopicDetailList"
)
@ApiOperation
(
"查询所有的
主
题详情"
)
@ApiOperation
(
"查询所有的
话
题详情"
)
@ResponseBody
public
List
<
TopicDTO
>
getAllTopicList
(){
List
<
TopicEntity
>
allTopic
=
topicManager
.
getAllTopic
();
List
<
TopicDTO
>
topicDTOS
=
ConvertUtil
.
topicEntitiesToDTOs
(
allTopic
);
//获取浏览数据:浏览、发帖、回帖
return
topicDTOS
;
public
List
<
TopicBriefInfoDTO
>
getAllTopicList
(){
List
<
TopicBriefInfoDTO
>
allTopic
=
topicManager
.
getAllTopicBriefInfo
();
return
allTopic
;
}
@PostMapping
(
value
=
"/admin/queryTopicNameList"
)
@ApiOperation
(
"查询所有的主题名称列表"
)
@ResponseBody
public
List
<
String
>
getTopicNameList
(){
List
<
TopicEntity
>
allTopic
=
topicManager
.
getAllTopic
();
List
<
String
>
topictitiles
=
allTopic
.
stream
().
map
(
TopicEntity:
:
getTopicTitle
).
collect
(
Collectors
.
toList
());
//获取浏览数据:浏览、发帖、回帖
return
topictitiles
;
}
@PostMapping
(
value
=
"/admin/insertTopic"
)
@ApiOperation
(
"新增
主题主
题"
)
@ApiOperation
(
"新增
话
题"
)
@ResponseBody
public
String
addTopic
(
@RequestParam
String
topicTitle
){
//TODO:获取登录用户信息
...
...
@@ -77,7 +64,7 @@ public class TopicController {
}
@PostMapping
(
value
=
"/admin/setTop"
)
@ApiOperation
(
"顶置/取消顶置
主
题"
)
@ApiOperation
(
"顶置/取消顶置
话
题"
)
@ResponseBody
public
String
setTopTopic
(
@RequestBody
TopicTopReq
req
)
throws
MissingServletRequestParameterException
{
topicManager
.
setTopTopic
(
req
.
getTopicId
(),
req
.
isTop
());
...
...
@@ -85,7 +72,7 @@ public class TopicController {
}
@PostMapping
(
value
=
"/admin/setConceal"
)
@ApiOperation
(
"隐藏/显示
主
题"
)
@ApiOperation
(
"隐藏/显示
话
题"
)
@ResponseBody
public
String
setConceal
(
@RequestBody
TopicConcealReq
req
)
throws
MissingServletRequestParameterException
{
topicManager
.
setTopicConceal
(
req
.
getTopicId
(),
req
.
isConceal
());
...
...
@@ -93,14 +80,20 @@ public class TopicController {
}
@PostMapping
(
value
=
"/admin/modifyViewNum"
)
@ApiOperation
(
"
主
题浏览数调整"
)
@ApiOperation
(
"
话
题浏览数调整"
)
@ResponseBody
public
String
modifyViewNum
(
@RequestBody
TopicModifyMountReq
req
)
throws
MissingServletRequestParameterException
{
topicManager
.
modify
PV
(
req
.
getTopicId
(),
req
.
getModifyMount
());
topicManager
.
modify
ViewAmount
(
req
.
getTopicId
(),
req
.
getModifyMount
());
return
"success"
;
}
@PostMapping
(
value
=
"/admin/dataAnalys"
)
@ApiOperation
(
"话题数据分析"
)
@ResponseBody
public
TopicDataAnalysDTO
dataAnalys
(
@RequestParam
String
topicId
)
throws
MissingServletRequestParameterException
{
TopicDataAnalysDTO
result
=
topicManager
.
queryDataAnalysis
(
topicId
);
return
result
;
}
...
...
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
View file @
d94a0dfb
...
...
@@ -3,6 +3,7 @@ package com.tanpu.community.manager;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.TopicBriefInfoDTO
;
import
com.tanpu.community.api.beans.TopicDTO
;
import
com.tanpu.community.api.beans.TopicDataAnalysDTO
;
import
com.tanpu.community.api.constants.RedisKeyConstant
;
import
com.tanpu.community.api.constants.TopicStatusEnum
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
...
...
@@ -40,12 +41,25 @@ public class TopicManager {
topicEntity
.
setTopicTitle
(
topicTitle
);
topicEntity
.
setIsTop
(
TopicStatusEnum
.
FALSE
.
getCode
());
topicEntity
.
setIsConceal
(
TopicStatusEnum
.
FALSE
.
getCode
());
topicEntity
.
setDeleteTag
(
TopicStatusEnum
.
FALSE
.
getCode
());
topicService
.
addTopic
(
topicEntity
);
}
public
List
<
TopicEntity
>
getAllTopic
()
{
return
topicService
.
queryTopicList
();
public
List
<
TopicDTO
>
getAllTopicDetail
()
{
return
ConvertUtil
.
topicEntitiesToDTOs
(
topicService
.
queryTopicList
());
}
public
List
<
TopicBriefInfoDTO
>
getAllTopicBriefInfo
()
{
List
<
TopicEntity
>
allTopic
=
topicService
.
queryTopicList
();
List
<
TopicBriefInfoDTO
>
topicDTOS
=
ConvertUtil
.
topicEntitiesToBriefDTOs
(
allTopic
);
//讨论数=发布主题贴数+回复总数
for
(
TopicBriefInfoDTO
topicDTO
:
topicDTOS
)
{
Long
discussAmount
=
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_DISCUSS_AMOUNT_
+
topicDTO
.
getTopicId
());
topicDTO
.
setDiscussionAmount
(
discussAmount
);
}
return
topicDTOS
;
}
public
void
setTopTopic
(
String
topicId
,
boolean
setTop
)
{
...
...
@@ -75,25 +89,26 @@ public class TopicManager {
public
TopicDTO
getDetail
(
String
topicId
)
{
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
TopicDTO
topicDTO
=
ConvertUtil
.
topicEntityToDTO
(
topicEntity
);
//TODO:添加实时数据(浏览量,点赞量,评论量,收藏量)
topicDTO
.
setViewAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_VIEW_AMOUNT_
+
topicId
));
topicDTO
.
setLikeAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_LIKE_AMOUNT_
+
topicId
));
topicDTO
.
setUserAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_USER_AMOUNT_
+
topicId
));
return
topicDTO
;
}
public
void
modifyPV
(
String
topicId
,
Long
modifyMount
)
{
public
void
modifyViewAmount
(
String
topicId
,
Long
modifyMount
)
{
topicService
.
modifyViewAmount
(
topicId
,
modifyMount
);
if
(
modifyMount
>
0
){
redisService
.
incr
(
RedisKeyConstant
.
TOPIC_VIEW_AMOUNT_
+
topicId
,
modifyMount
);
redisService
.
incr
(
RedisKeyConstant
.
TOPIC_
TOTAL_
VIEW_AMOUNT_
+
topicId
,
modifyMount
);
}
else
{
redisService
.
decr
(
RedisKeyConstant
.
TOPIC_VIEW_AMOUNT_
+
topicId
,-
modifyMount
);
redisService
.
decr
(
RedisKeyConstant
.
TOPIC_
TOTAL_
VIEW_AMOUNT_
+
topicId
,-
modifyMount
);
}
}
public
void
calculate
(){
public
void
refreshRedisCache
(){
List
<
String
>
topicIds
=
topicService
.
queryTopicList
().
stream
().
map
(
TopicEntity:
:
getId
).
collect
(
Collectors
.
toList
());
for
(
String
topicId
:
topicIds
)
{
List
<
ThemeEntity
>
themeEntities
=
themeService
.
selectByTopic
(
topicId
);
...
...
@@ -104,14 +119,37 @@ public class TopicManager {
redisService
.
set
(
RedisKeyConstant
.
TOPIC_LIKE_AMOUNT_
+
topicId
,
likeAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_BOOK_AMOUNT_
+
topicId
,
bookAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_COMMENT_AMOUNT_
+
topicId
,
commentAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_DISCUSS_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_TOTAL_VIEW_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_THEME_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_COMENT_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_TOTAOL_USER_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_DISCUSS_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_POSTER_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_REPLIER_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
}
}
public
List
<
TopicBriefInfoDTO
>
getBreifInfoTopic
()
{
topicService
.
queryTopicList
();
return
null
;
//后台管理:返回数据分析
public
TopicDataAnalysDTO
queryDataAnalysis
(
String
topicId
)
{
TopicDataAnalysDTO
topicDataAnalysDTO
=
new
TopicDataAnalysDTO
();
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
this
.
refreshRedisCache
();
topicDataAnalysDTO
.
setId
(
topicId
);
topicDataAnalysDTO
.
setTopicTitle
(
topicEntity
.
getTopicTitle
());
// topicDataAnalysDTO.setCommentAmount();
// topicDataAnalysDTO.setPosterAmount();
// topicDataAnalysDTO.setReplIierAmount();
// topicDataAnalysDTO.setThemeAmount();
// topicDataAnalysDTO.setUserTotalAmount();
// topicDataAnalysDTO.setViewTotalAmount();
// topicDataAnalysDTO.setViewPageAmount();
// topicDataAnalysDTO.setCommentAmount();
return
topicDataAnalysDTO
;
}
}
community-service/src/main/java/com/tanpu/community/service/TopicService.java
View file @
d94a0dfb
package
com
.
tanpu
.
community
.
service
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.
Lambda
QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.tanpu.community.api.constants.TopicStatusEnum
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
...
...
@@ -21,7 +21,8 @@ public class TopicService {
public
List
<
TopicEntity
>
queryTopicList
(){
return
topicMapper
.
selectList
(
new
QueryWrapper
<>());
return
topicMapper
.
selectList
(
new
LambdaQueryWrapper
<
TopicEntity
>()
.
eq
(
TopicEntity:
:
getDeleteTag
,
TopicStatusEnum
.
FALSE
.
getCode
()));
}
public
void
addTopic
(
TopicEntity
topicEntity
){
...
...
@@ -32,28 +33,38 @@ public class TopicService {
public
void
updateTopicToTop
(
String
topicId
){
TopicEntity
topicEntity
=
new
TopicEntity
();
topicEntity
.
setIsTop
(
TopicStatusEnum
.
TRUE
.
getCode
());
topicMapper
.
update
(
topicEntity
,
new
LambdaUpdateWrapper
<
TopicEntity
>().
eq
(
TopicEntity:
:
getId
,
topicId
));
topicMapper
.
update
(
topicEntity
,
new
LambdaUpdateWrapper
<
TopicEntity
>()
.
eq
(
TopicEntity:
:
getId
,
topicId
));
}
public
void
updateTopicNotTop
(
String
topicId
){
TopicEntity
topicEntity
=
new
TopicEntity
();
topicEntity
.
setIsTop
(
TopicStatusEnum
.
FALSE
.
getCode
());
topicMapper
.
update
(
topicEntity
,
new
LambdaUpdateWrapper
<
TopicEntity
>().
eq
(
TopicEntity:
:
getId
,
topicId
));
topicMapper
.
update
(
topicEntity
,
new
LambdaUpdateWrapper
<
TopicEntity
>()
.
eq
(
TopicEntity:
:
getId
,
topicId
));
}
public
void
updateTopicToConceal
(
String
topicId
){
TopicEntity
topicEntity
=
new
TopicEntity
();
topicEntity
.
setIsConceal
(
TopicStatusEnum
.
TRUE
.
getCode
());
topicMapper
.
update
(
topicEntity
,
new
LambdaUpdateWrapper
<
TopicEntity
>().
eq
(
TopicEntity:
:
getId
,
topicId
));
topicMapper
.
update
(
topicEntity
,
new
LambdaUpdateWrapper
<
TopicEntity
>()
.
eq
(
TopicEntity:
:
getId
,
topicId
));
}
public
void
updateTopicNotConceal
(
String
topicId
){
TopicEntity
topicEntity
=
new
TopicEntity
();
topicEntity
.
setIsConceal
(
TopicStatusEnum
.
FALSE
.
getCode
());
topicMapper
.
update
(
topicEntity
,
new
LambdaUpdateWrapper
<
TopicEntity
>().
eq
(
TopicEntity:
:
getId
,
topicId
));
topicMapper
.
update
(
topicEntity
,
new
LambdaUpdateWrapper
<
TopicEntity
>()
.
eq
(
TopicEntity:
:
getId
,
topicId
));
}
public
TopicEntity
queryById
(
String
topicId
)
{
return
topicMapper
.
selectById
(
topicId
);
}
public
void
modifyViewAmount
(
String
topicId
,
long
amount
){
TopicEntity
topicEntity
=
topicMapper
.
selectById
(
topicId
);
return
;
}
}
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
d94a0dfb
package
com
.
tanpu
.
community
.
util
;
import
com.tanpu.community.api.beans.ThemeDTO
;
import
com.tanpu.community.api.beans.TopicBriefInfoDTO
;
import
com.tanpu.community.api.beans.TopicDTO
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
...
...
@@ -40,7 +41,17 @@ public class ConvertUtil {
return
topicDTO
;
}
public
static
TopicBriefInfoDTO
topicToBriefInfoDTO
(
TopicEntity
topicEntity
){
TopicBriefInfoDTO
topicBriefInfoDTO
=
new
TopicBriefInfoDTO
();
BeanUtils
.
copyProperties
(
topicEntity
,
topicBriefInfoDTO
);
return
topicBriefInfoDTO
;
}
public
static
List
<
TopicDTO
>
topicEntitiesToDTOs
(
List
<
TopicEntity
>
topicEntities
){
return
topicEntities
.
stream
().
map
(
ConvertUtil:
:
topicEntityToDTO
).
collect
(
Collectors
.
toList
());
}
public
static
List
<
TopicBriefInfoDTO
>
topicEntitiesToBriefDTOs
(
List
<
TopicEntity
>
topicEntities
)
{
return
topicEntities
.
stream
().
map
(
ConvertUtil:
:
topicToBriefInfoDTO
).
collect
(
Collectors
.
toList
());
}
}
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