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
64eb10aa
Commit
64eb10aa
authored
Jul 23, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
theme添加字段discussContent
parent
8100aa13
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
71 deletions
+8
-71
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+0
-67
RecommendService.java
...in/java/com/tanpu/community/service/RecommendService.java
+8
-4
No files found.
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
View file @
64eb10aa
...
...
@@ -5,20 +5,14 @@ import com.tanpu.common.exception.BizException;
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.TopicDataAnalysDTO
;
import
com.tanpu.community.api.constants.RedisKeyConstant
;
import
com.tanpu.community.api.enums.CollectionTypeEnum
;
import
com.tanpu.community.api.enums.VisitTypeEnum
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.service.*
;
import
com.tanpu.community.util.PageUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
@Service
public
class
TopicManager
{
...
...
@@ -26,18 +20,6 @@ public class TopicManager {
@Autowired
private
TopicService
topicService
;
@Autowired
private
RedisService
redisService
;
@Autowired
private
ThemeService
themeService
;
@Autowired
private
CollectionService
collectionService
;
@Autowired
private
CommentService
commentService
;
@Autowired
private
VisitSummaryService
visitSummaryService
;
@Autowired
...
...
@@ -74,54 +56,5 @@ public class TopicManager {
}
public
void
refreshRedisCache
()
{
List
<
TopicEntity
>
topicEntities
=
topicService
.
queryAll
();
for
(
TopicEntity
topic
:
topicEntities
)
{
String
topicId
=
topic
.
getTopicId
();
Long
viewCountModify
=
topic
.
getViewCntAdjust
();
List
<
String
>
themeIds
=
themeService
.
queryThemeIdsByTopic
(
topicId
);
Integer
likeCountByThemeIds
=
collectionService
.
getCountByTypeAndIds
(
themeIds
,
CollectionTypeEnum
.
LIKE_THEME
);
Integer
bookCountByThemeIds
=
collectionService
.
getCountByTypeAndIds
(
themeIds
,
CollectionTypeEnum
.
COLLECT_THEME
);
Long
commentCountByThemeIds
=
(
long
)
commentService
.
getCommentCountByThemeIds
(
themeIds
);
Set
<
String
>
postUsers
=
themeService
.
getPostUserCount
(
themeIds
);
Set
<
String
>
commentUsers
=
commentService
.
getCommentUserCount
(
themeIds
);
HashSet
<
String
>
totalUsers
=
new
HashSet
<>(
postUsers
);
totalUsers
.
addAll
(
commentUsers
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_LIKE_COUNT_
+
topicId
,
likeCountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_BOOK_COUNT_
+
topicId
,
bookCountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_COMMENT_COUNT_
+
topicId
,
commentCountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_TOTAL_VIEW_COUNT_
+
topicId
,
commentCountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_THEME_COUNT_
+
topicId
,
commentCountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_DISCUSS_COUNT_
+
topicId
,
commentCountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_POST_USER_COUNT_
+
topicId
,
(
long
)
postUsers
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_COMMENT_USER_COUNT_
+
topicId
,
(
long
)
commentUsers
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_TOTAL_USER_COUNT_
+
topicId
,
(
long
)
totalUsers
.
size
());
}
}
//返回数据分析
public
TopicDataAnalysDTO
queryDataAnalysis
(
String
topicId
)
{
TopicDataAnalysDTO
topicDataAnalysDTO
=
new
TopicDataAnalysDTO
();
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
if
(
topicEntity
==
null
)
{
throw
new
BizException
(
"话题未找到,id:"
+
topicId
);
}
this
.
refreshRedisCache
();
topicDataAnalysDTO
.
setId
(
topicId
);
topicDataAnalysDTO
.
setTopicTitle
(
topicEntity
.
getTopicTitle
());
topicDataAnalysDTO
.
setCommentCount
(
redisService
.
getInteger
(
RedisKeyConstant
.
TOPIC_COMMENT_COUNT_
+
topicId
));
topicDataAnalysDTO
.
setPosterCount
(
redisService
.
getInteger
(
RedisKeyConstant
.
TOPIC_POST_USER_COUNT_
+
topicId
));
topicDataAnalysDTO
.
setReplIierCount
(
redisService
.
getInteger
(
RedisKeyConstant
.
TOPIC_COMMENT_USER_COUNT_
+
topicId
));
topicDataAnalysDTO
.
setThemeCount
(
redisService
.
getInteger
(
RedisKeyConstant
.
TOPIC_THEME_COUNT_
+
topicId
));
topicDataAnalysDTO
.
setUserTotalCount
(
redisService
.
getInteger
(
RedisKeyConstant
.
TOPIC_TOTAL_USER_COUNT_
+
topicId
));
topicDataAnalysDTO
.
setViewTotalCount
(
redisService
.
getInteger
(
RedisKeyConstant
.
TOPIC_TOTAL_VIEW_COUNT_
+
topicId
));
topicDataAnalysDTO
.
setViewPageCount
(
redisService
.
getInteger
(
RedisKeyConstant
.
TOPIC_PAGE_VIEW_COUNT_
+
topicId
));
return
topicDataAnalysDTO
;
}
}
community-service/src/main/java/com/tanpu/community/service/RecommendService.java
View file @
64eb10aa
...
...
@@ -39,6 +39,9 @@ public class RecommendService {
@Autowired
private
ThemeService
themeService
;
@Autowired
private
VisitSummaryService
visitSummaryService
;
//最新
private
List
<
ThemeAnalysDO
>
recentThemeList
=
new
ArrayList
<>();
//推荐
...
...
@@ -65,7 +68,7 @@ public class RecommendService {
//混合
Set
<
String
>
returnedIds
=
(
StringUtils
.
isEmpty
(
lastId
))
?
new
HashSet
<>()
:
returnedIdsMap
.
get
(
userId
);
List
<
String
>
result
=
new
ArrayList
<>();
getResultList
(
hotThemeIds
,
0
,
newThemeIds
,
0
,
recThemeIds
,
0
,
returnedIds
,
result
,
pageSize
);
getResultList
(
hotThemeIds
,
0
,
newThemeIds
,
0
,
recThemeIds
,
0
,
returnedIds
,
result
,
pageSize
,
userId
);
result
=
result
.
stream
().
limit
(
pageSize
).
collect
(
Collectors
.
toList
());
//记录已返回主题id
if
(
StringUtils
.
isEmpty
(
lastId
)){
...
...
@@ -124,7 +127,7 @@ public class RecommendService {
}
//逐个插入
private
void
getResultList
(
List
<
String
>
hotThemeIds
,
Integer
hotTag
,
List
<
String
>
newThemeIds
,
Integer
newTag
,
List
<
String
>
recThemeIds
,
Integer
recTag
,
Set
<
String
>
returnedIds
,
List
<
String
>
result
,
Integer
pageSize
)
{
private
void
getResultList
(
List
<
String
>
hotThemeIds
,
Integer
hotTag
,
List
<
String
>
newThemeIds
,
Integer
newTag
,
List
<
String
>
recThemeIds
,
Integer
recTag
,
Set
<
String
>
returnedIds
,
List
<
String
>
result
,
Integer
pageSize
,
String
userId
)
{
if
(
hotThemeIds
.
size
()
<=
hotTag
&&
newThemeIds
.
size
()
<=
newTag
&&
recThemeIds
.
size
()
<=
recTag
)
{
//所有列表已循环结束,返回
return
;
...
...
@@ -164,10 +167,11 @@ public class RecommendService {
}
}
//TODO 去重已看过(查看正文)
//去重已看过(查看正文)
result
=
visitSummaryService
.
filterUserNotVisited
(
userId
,
result
);
if
(
result
.
size
()
<
pageSize
)
{
getResultList
(
hotThemeIds
,
hotTag
,
newThemeIds
,
newTag
,
recThemeIds
,
recTag
,
returnedIds
,
result
,
pageSize
);
getResultList
(
hotThemeIds
,
hotTag
,
newThemeIds
,
newTag
,
recThemeIds
,
recTag
,
returnedIds
,
result
,
pageSize
,
userId
);
}
}
...
...
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