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
2a77678a
Commit
2a77678a
authored
Jul 21, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
topic返回对象优化
parent
914e30e9
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
43 additions
and
73 deletions
+43
-73
TopicRankQo.java
...in/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
+1
-1
CreateThemeReq.java
...m/tanpu/community/api/beans/req/theme/CreateThemeReq.java
+1
-1
TopicController.java
.../java/com/tanpu/community/controller/TopicController.java
+7
-11
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+4
-1
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+15
-45
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+9
-7
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+6
-7
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/Topic
Hot
Qo.java
→
community-api/src/main/java/com/tanpu/community/api/beans/qo/Topic
Rank
Qo.java
View file @
2a77678a
...
...
@@ -6,7 +6,7 @@ import lombok.Data;
@Data
@ApiModel
(
"热点话题对象"
)
public
class
Topic
Hot
Qo
{
public
class
Topic
Rank
Qo
{
@ApiModelProperty
(
value
=
"话题ID"
)
private
String
topicId
;
...
...
community-api/src/main/java/com/tanpu/community/api/beans/req/theme/CreateThemeReq.java
View file @
2a77678a
...
...
@@ -14,7 +14,7 @@ public class CreateThemeReq {
@NotNull
(
message
=
"类型不能为空"
)
@ApiModelProperty
(
value
=
"类型 1:讨论无标题 2:长文有标题
3:转发
"
)
@ApiModelProperty
(
value
=
"类型 1:讨论无标题 2:长文有标题"
)
private
Integer
themeType
;
...
...
community-service/src/main/java/com/tanpu/community/controller/TopicController.java
View file @
2a77678a
...
...
@@ -2,9 +2,7 @@ package com.tanpu.community.controller;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.auth.UserHolder
;
import
com.tanpu.community.api.beans.qo.TopicDetailQo
;
import
com.tanpu.community.api.beans.qo.TopicHotQo
;
import
com.tanpu.community.api.beans.qo.TopicTitileQo
;
import
com.tanpu.community.api.beans.qo.TopicRankQo
;
import
com.tanpu.community.api.beans.req.page.Page
;
import
com.tanpu.community.api.beans.req.topic.TopicSearchReq
;
import
com.tanpu.community.manager.TopicManager
;
...
...
@@ -30,25 +28,23 @@ public class TopicController {
@PostMapping
(
value
=
"/list"
)
@ApiOperation
(
"APP全部话题页面,可搜索"
)
@ResponseBody
public
CommonResp
<
Page
<
TopicTitileQo
>>
getTopicBriefInfoList
(
@RequestBody
TopicSearchReq
req
){
Page
<
TopicTitileQo
>
allTopic
=
topicManager
.
getAllTopicBriefInfo
(
req
);
return
CommonResp
.
success
(
allTopic
);
public
CommonResp
<
Page
<
TopicRankQo
>>
getTopicBriefInfoList
(
@RequestBody
TopicSearchReq
req
){
return
CommonResp
.
success
(
topicManager
.
getAllTopicBriefInfo
(
req
));
}
@GetMapping
(
value
=
"/detailPage"
)
@ApiOperation
(
"话题详情页顶部"
)
@ResponseBody
public
CommonResp
<
TopicDetailQo
>
gethotThemes
(
@RequestParam
String
topicId
){
TopicDetailQo
detail
=
topicManager
.
getDetail
(
topicId
);
return
CommonResp
.
success
(
detail
);
public
CommonResp
<
TopicRankQo
>
gethotThemes
(
@RequestParam
String
topicId
){
return
CommonResp
.
success
(
topicManager
.
getDetail
(
topicId
));
}
@GetMapping
(
value
=
"/titleList"
)
@ApiOperation
(
"首页顶部话题标题列"
)
@ResponseBody
public
CommonResp
<
List
<
Topic
Hot
Qo
>>
getTitleList
(){
return
CommonResp
.
success
(
topicManager
.
get
Hot
TopicTitles
());
public
CommonResp
<
List
<
Topic
Rank
Qo
>>
getTitleList
(){
return
CommonResp
.
success
(
topicManager
.
get
Top4
TopicTitles
());
}
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
2a77678a
...
...
@@ -96,6 +96,9 @@ public class ThemeManager {
}
@Transactional
/**
* 发表主题(可修改)
*/
public
CreateThemeResp
publishTheme
(
CreateThemeReq
req
,
String
userId
)
{
//直播类型做转播检查
List
<
ThemeContentReq
>
contents
=
req
.
getContent
();
...
...
@@ -117,7 +120,7 @@ public class ThemeManager {
themeEntity
.
setAuthorId
(
userId
);
themeEntity
.
setContent
(
JsonUtil
.
toJson
(
req
.
getContent
()));
//
TODO 敏感词过滤
//
腾讯云敏感词校验
checkContent
(
themeEntity
.
getContent
());
if
(
StringUtils
.
isEmpty
(
req
.
getEditThemeId
()))
{
...
...
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
View file @
2a77678a
package
com
.
tanpu
.
community
.
manager
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.qo.TopicDetailQo
;
import
com.tanpu.community.api.beans.qo.TopicHotQo
;
import
com.tanpu.community.api.beans.qo.TopicTitileQo
;
import
com.tanpu.community.api.beans.qo.TopicRankQo
;
import
com.tanpu.community.api.beans.req.page.Page
;
import
com.tanpu.community.api.beans.req.topic.TopicSearchReq
;
import
com.tanpu.community.api.beans.vo.TopicDTO
;
...
...
@@ -14,14 +12,13 @@ import com.tanpu.community.dao.entity.community.TopicEntity;
import
com.tanpu.community.service.*
;
import
com.tanpu.community.util.ConvertUtil
;
import
com.tanpu.community.util.PageUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
@Service
public
class
TopicManager
{
...
...
@@ -62,56 +59,29 @@ public class TopicManager {
//话题简介列表
public
Page
<
TopicTitileQo
>
getAllTopicBriefInfo
(
TopicSearchReq
req
)
{
List
<
TopicEntity
>
allTopic
=
topicService
.
queryByKeyword
(
req
.
getSearchKeyword
());
List
<
TopicTitileQo
>
topicTitileQos
=
ConvertUtil
.
topicEntitiesToBriefDTOs
(
allTopic
);
for
(
TopicTitileQo
topicQo
:
topicTitileQos
)
{
//讨论数=发布主题贴数+回复总数
List
<
String
>
themeIds
=
themeService
.
queryThemeIdsByTopic
(
topicQo
.
getTopicId
());
Integer
commentCount
=
commentService
.
getCommentCountByThemeIds
(
themeIds
);
topicQo
.
setDiscussionCount
(
String
.
valueOf
(
themeIds
.
size
()
+
commentCount
));
//浏览量
Integer
topicPV
=
visitSummaryService
.
queryTopicDetailVisit
(
topicQo
.
getTopicId
());
Integer
themePV
=
visitSummaryService
.
queryThemeVisit
(
themeIds
);
topicQo
.
setViewCount
(
String
.
valueOf
(
topicPV
+
themePV
));
public
Page
<
TopicRankQo
>
getAllTopicBriefInfo
(
TopicSearchReq
req
)
{
if
(
rankService
.
rankTopicList
.
size
()==
0
){
rankService
.
rankTopics
();
}
//TODO 判断顶置
return
PageUtils
.
page
(
req
.
getPage
(),
topicTitileQos
);
return
PageUtils
.
page
(
req
.
getPage
(),
rankService
.
rankTopicList
);
}
//话题详情页
public
TopicDetailQo
getDetail
(
String
topicId
)
{
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
if
(
topicEntity
==
null
)
{
throw
new
BizException
(
"找不到话题,id:"
+
topicId
);
}
TopicDetailQo
topicDetailQo
=
new
TopicDetailQo
();
BeanUtils
.
copyProperties
(
topicEntity
,
topicDetailQo
);
List
<
String
>
themeIds
=
themeService
.
queryThemeIdsByTopic
(
topicId
);
if
(
CollectionUtils
.
isEmpty
(
themeIds
))
{
topicDetailQo
.
setViewCount
(
visitSummaryService
.
queryTopicDetailVisit
(
topicId
));
topicDetailQo
.
setDisscussCount
(
0
);
return
topicDetailQo
;
public
TopicRankQo
getDetail
(
String
topicId
)
{
if
(
rankService
.
rankTopicList
.
size
()==
0
){
rankService
.
rankTopics
();
}
//浏览量
Integer
topicPV
=
visitSummaryService
.
queryTopicDetailVisit
(
topicId
);
Integer
themePV
=
visitSummaryService
.
queryThemeVisit
(
themeIds
);
topicDetailQo
.
setViewCount
(
topicPV
+
themePV
);
//讨论数=发布主题贴数+回复总数
Integer
commentCount
=
commentService
.
getCommentCountByThemeIds
(
themeIds
);
topicDetailQo
.
setDisscussCount
(
themeIds
.
size
()
+
commentCount
);
return
topicDetailQo
;
List
<
TopicRankQo
>
matchTopic
=
rankService
.
rankTopicList
.
stream
().
filter
(
o
->
o
.
getTopicId
().
equals
(
topicId
)).
limit
(
1
).
collect
(
Collectors
.
toList
());
matchTopic
.
add
(
new
TopicRankQo
());
return
matchTopic
.
get
(
0
);
}
public
List
<
TopicHotQo
>
getHotTopicTitles
()
{
List
<
TopicHotQo
>
rankTopicList
=
rankService
.
rankTopicList
;
if
(
rankTopicList
.
size
()==
0
){
public
List
<
TopicRankQo
>
getTop4TopicTitles
()
{
if
(
rankService
.
rankTopicList
.
size
()==
0
){
rankService
.
rankTopics
();
}
return
rankService
.
rankTopicList
;
return
rankService
.
rankTopicList
Top4
;
}
public
void
setTopTopic
(
String
topicId
,
boolean
setTop
)
{
...
...
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
2a77678a
package
com
.
tanpu
.
community
.
service
;
import
com.tanpu.community.api.beans.qo.ThemeAnalysDO
;
import
com.tanpu.community.api.beans.qo.Topic
Hot
Qo
;
import
com.tanpu.community.api.beans.qo.Topic
Rank
Qo
;
import
com.tanpu.community.api.enums.CollectionTypeEnum
;
import
com.tanpu.community.api.enums.TopicStatusEnum
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
...
...
@@ -30,7 +30,8 @@ public class RankService {
public
List
<
String
>
rankThemeList
=
new
ArrayList
<>();
public
List
<
TopicHotQo
>
rankTopicList
=
new
ArrayList
<>();
public
List
<
TopicRankQo
>
rankTopicList
=
new
ArrayList
<>();
public
List
<
TopicRankQo
>
rankTopicListTop4
=
new
ArrayList
<>();
public
void
rankThemes
()
{
...
...
@@ -61,11 +62,11 @@ public class RankService {
*/
public
void
rankTopics
()
{
List
<
TopicEntity
>
topicEntities
=
topicService
.
queryAll
();
List
<
Topic
HotQo
>
topicHot
Qos
=
ConvertUtil
.
topicEntityToHotQos
(
topicEntities
);
if
(
topic
Hot
Qos
.
size
()
==
0
)
{
List
<
Topic
RankQo
>
topicRank
Qos
=
ConvertUtil
.
topicEntityToHotQos
(
topicEntities
);
if
(
topic
Rank
Qos
.
size
()
==
0
)
{
return
;
}
for
(
Topic
HotQo
topic
:
topicHot
Qos
)
{
for
(
Topic
RankQo
topic
:
topicRank
Qos
)
{
List
<
String
>
themeIds
=
themeService
.
queryThemeIdsByTopic
(
topic
.
getTopicId
());
if
(
CollectionUtils
.
isEmpty
(
themeIds
)){
topic
.
setViewCount
(
0
);
...
...
@@ -80,10 +81,11 @@ public class RankService {
Integer
commentCount
=
commentService
.
getCommentCountByThemeIds
(
themeIds
);
topic
.
setDisscussCount
(
themeIds
.
size
()
+
commentCount
);
}
Map
<
Topic
HotQo
,
Integer
>
map
=
topicHotQos
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
TopicHot
Qo:
:
getRank
));
List
<
Topic
HotQo
>
rankList
=
map
.
entrySet
().
stream
().
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
())).
map
(
e
->
e
.
getKey
()).
limit
(
4
).
collect
(
Collectors
.
toList
());
Map
<
Topic
RankQo
,
Integer
>
map
=
topicRankQos
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
TopicRank
Qo:
:
getRank
));
List
<
Topic
RankQo
>
rankList
=
map
.
entrySet
().
stream
().
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
())).
map
(
Map
.
Entry
::
getKey
).
collect
(
Collectors
.
toList
());
rankList
.
get
(
0
).
setType
(
TopicStatusEnum
.
HOTTEST
.
getCode
());
rankTopicList
=
rankList
;
rankTopicListTop4
=
rankList
.
stream
().
limit
(
4
).
collect
(
Collectors
.
toList
());
return
;
}
...
...
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
2a77678a
...
...
@@ -18,7 +18,6 @@ import org.springframework.util.StringUtils;
import
java.time.LocalDateTime
;
import
java.time.ZoneOffset
;
import
java.time.temporal.TemporalField
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
...
...
@@ -94,17 +93,17 @@ public class ConvertUtil {
return
topicDTO
;
}
public
static
Topic
Hot
Qo
topicEntityToHotQo
(
TopicEntity
topicEntity
)
{
Topic
HotQo
topicHotQo
=
new
TopicHot
Qo
();
BeanUtils
.
copyProperties
(
topicEntity
,
topic
Hot
Qo
);
public
static
Topic
Rank
Qo
topicEntityToHotQo
(
TopicEntity
topicEntity
)
{
Topic
RankQo
topicRankQo
=
new
TopicRank
Qo
();
BeanUtils
.
copyProperties
(
topicEntity
,
topic
Rank
Qo
);
//2小时内发帖,添加新话题标签
if
(
TimeUtil
.
calMinuteTillNow
(
topicEntity
.
getCreateTime
())<
120
){
topic
Hot
Qo
.
setType
(
TopicStatusEnum
.
NEWEST
.
getCode
());
topic
Rank
Qo
.
setType
(
TopicStatusEnum
.
NEWEST
.
getCode
());
}
return
topic
Hot
Qo
;
return
topic
Rank
Qo
;
}
public
static
List
<
Topic
Hot
Qo
>
topicEntityToHotQos
(
List
<
TopicEntity
>
topicEntities
)
{
public
static
List
<
Topic
Rank
Qo
>
topicEntityToHotQos
(
List
<
TopicEntity
>
topicEntities
)
{
if
(
topicEntities
==
null
){
return
Collections
.
emptyList
();
}
...
...
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