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
0efc6dbf
Commit
0efc6dbf
authored
Sep 23, 2021
by
王亚雷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
游客权限
parent
ece385a0
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
18 deletions
+30
-18
ThemeListReq.java
...com/tanpu/community/api/beans/req/theme/ThemeListReq.java
+2
-0
ThemeController.java
.../java/com/tanpu/community/controller/ThemeController.java
+1
-3
TopicController.java
.../java/com/tanpu/community/controller/TopicController.java
+0
-1
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+15
-9
RecommendService.java
...in/java/com/tanpu/community/service/RecommendService.java
+12
-5
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/req/theme/ThemeListReq.java
View file @
0efc6dbf
...
@@ -10,6 +10,8 @@ import javax.validation.constraints.NotNull;
...
@@ -10,6 +10,8 @@ import javax.validation.constraints.NotNull;
@Data
@Data
public
class
ThemeListReq
{
public
class
ThemeListReq
{
@ApiModelProperty
(
value
=
"用户Id"
)
private
String
userId
;
@NotNull
(
message
=
"主题类型不能为空"
)
@NotNull
(
message
=
"主题类型不能为空"
)
@ApiModelProperty
(
value
=
"类型,1:推荐 2:关注 3:话题-热门 4:话题-最新"
)
@ApiModelProperty
(
value
=
"类型,1:推荐 2:关注 3:话题-热门 4:话题-最新"
)
...
...
community-service/src/main/java/com/tanpu/community/controller/ThemeController.java
View file @
0efc6dbf
...
@@ -36,13 +36,11 @@ public class ThemeController {
...
@@ -36,13 +36,11 @@ public class ThemeController {
return
themeManager
.
publishTheme
(
req
,
userId
);
return
themeManager
.
publishTheme
(
req
,
userId
);
}
}
@AuthLogin
@ApiOperation
(
"主题列表-推荐/关注/热门/最新"
)
@ApiOperation
(
"主题列表-推荐/关注/热门/最新"
)
@PostMapping
(
value
=
"/list"
)
@PostMapping
(
value
=
"/list"
)
@ResponseBody
@ResponseBody
public
CommonResp
<
ThemeListResp
>
selectInterestList
(
@Validated
@RequestBody
ThemeListReq
req
)
{
public
CommonResp
<
ThemeListResp
>
selectInterestList
(
@Validated
@RequestBody
ThemeListReq
req
)
{
String
userId
=
userHolder
.
getUserId
();
ThemeListResp
result
=
themeManager
.
queryList
(
req
,
req
.
getUserId
());
ThemeListResp
result
=
themeManager
.
queryList
(
req
,
userId
);
return
CommonResp
.
success
(
result
);
return
CommonResp
.
success
(
result
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/controller/TopicController.java
View file @
0efc6dbf
...
@@ -35,7 +35,6 @@ public class TopicController {
...
@@ -35,7 +35,6 @@ public class TopicController {
return
CommonResp
.
success
(
topicManager
.
getAllTopicBriefInfo
(
req
));
return
CommonResp
.
success
(
topicManager
.
getAllTopicBriefInfo
(
req
));
}
}
@AuthLogin
@GetMapping
(
value
=
"/detailPage"
)
@GetMapping
(
value
=
"/detailPage"
)
@ApiOperation
(
"话题详情页顶部"
)
@ApiOperation
(
"话题详情页顶部"
)
@ResponseBody
@ResponseBody
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
0efc6dbf
...
@@ -2,11 +2,13 @@ package com.tanpu.community.manager;
...
@@ -2,11 +2,13 @@ package com.tanpu.community.manager;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.Sets
;
import
com.tanpu.biz.common.enums.RelTypeEnum
;
import
com.tanpu.biz.common.enums.RelTypeEnum
;
import
com.tanpu.biz.common.enums.community.CollectionTypeEnum
;
import
com.tanpu.biz.common.enums.community.CollectionTypeEnum
;
import
com.tanpu.biz.common.enums.community.ReportTypeEnum
;
import
com.tanpu.biz.common.enums.community.ReportTypeEnum
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.api.ResultCode
;
import
com.tanpu.common.constant.ErrorCodeConstant
;
import
com.tanpu.common.constant.ErrorCodeConstant
;
import
com.tanpu.common.enums.fund.ProductTypeEnum
;
import
com.tanpu.common.enums.fund.ProductTypeEnum
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.common.exception.BizException
;
...
@@ -464,7 +466,7 @@ public class ThemeManager {
...
@@ -464,7 +466,7 @@ public class ThemeManager {
* 查询主题列表:推荐/关注/热门/最新
* 查询主题列表:推荐/关注/热门/最新
*/
*/
// 查询主题列表:推荐/关注/热门/最新
// 查询主题列表:推荐/关注/热门/最新
public
ThemeListResp
queryList
(
ThemeListReq
req
,
String
userId
)
{
public
ThemeListResp
queryList
(
ThemeListReq
req
,
String
userId
111
)
{
List
<
String
>
excludeIds
=
new
ArrayList
<>();
List
<
String
>
excludeIds
=
new
ArrayList
<>();
LocalDateTime
firstThemeTime
=
LocalDateTime
.
now
();
LocalDateTime
firstThemeTime
=
LocalDateTime
.
now
();
if
(
req
.
page
.
pageNumber
>
1
)
{
if
(
req
.
page
.
pageNumber
>
1
)
{
...
@@ -486,14 +488,14 @@ public class ThemeManager {
...
@@ -486,14 +488,14 @@ public class ThemeManager {
if
(
ThemeListTypeEnum
.
RECOMMEND
.
getCode
().
equals
(
req
.
getType
()))
{
if
(
ThemeListTypeEnum
.
RECOMMEND
.
getCode
().
equals
(
req
.
getType
()))
{
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
List
<
String
>
visitedIds
=
visitLogService
.
queryUserRecentVisited
(
userId
);
List
<
String
>
visitedIds
=
StringUtils
.
isEmpty
(
req
.
getUserId
())
?
Lists
.
newArrayListWithCapacity
(
0
)
:
visitLogService
.
queryUserRecentVisited
(
req
.
getUserId
()
);
List
<
String
>
excludes
=
ListUtils
.
union
(
excludeIds
,
visitedIds
);
List
<
String
>
excludes
=
ListUtils
.
union
(
excludeIds
,
visitedIds
);
List
<
String
>
recmdIds
=
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
userId
,
excludes
,
firstThemeTime
);
List
<
String
>
recmdIds
=
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
req
.
getUserId
()
,
excludes
,
firstThemeTime
);
// 加载第一页时,为防止首页显示空列表,从推荐池中再捞出已看过帖子
// 加载第一页时,为防止首页显示空列表,从推荐池中再捞出已看过帖子
if
(
req
.
page
.
pageNumber
<=
3
&&
recmdIds
.
size
()
<
pageSize
)
{
if
(
req
.
page
.
pageNumber
<=
3
&&
recmdIds
.
size
()
<
pageSize
)
{
List
<
String
>
reSearchIds
=
ListUtils
.
union
(
excludeIds
,
recmdIds
);
List
<
String
>
reSearchIds
=
ListUtils
.
union
(
excludeIds
,
recmdIds
);
recmdIds
.
addAll
(
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
userId
,
reSearchIds
,
firstThemeTime
));
recmdIds
.
addAll
(
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
req
.
getUserId
()
,
reSearchIds
,
firstThemeTime
));
}
}
themes
=
themeService
.
queryByThemeIds
(
recmdIds
);
themes
=
themeService
.
queryByThemeIds
(
recmdIds
);
...
@@ -502,14 +504,17 @@ public class ThemeManager {
...
@@ -502,14 +504,17 @@ public class ThemeManager {
}
else
if
(
ThemeListTypeEnum
.
FOLLOW
.
getCode
().
equals
(
req
.
getType
()))
{
}
else
if
(
ThemeListTypeEnum
.
FOLLOW
.
getCode
().
equals
(
req
.
getType
()))
{
if
(
StringUtils
.
isEmpty
(
req
.
getUserId
()))
{
throw
new
BizException
(
ResultCode
.
UNAUTHORIZED
.
getCode
(),
ResultCode
.
UNAUTHORIZED
.
getMsg
());
}
// 根据关注列表查询,按时间倒序
// 根据关注列表查询,按时间倒序
List
<
String
>
fansList
=
followRelService
.
queryIdolsByFansId
(
userId
);
List
<
String
>
fansList
=
followRelService
.
queryIdolsByFansId
(
req
.
getUserId
()
);
themes
=
themeService
.
queryByUserIdsCreateDesc
(
fansList
,
pageStart
,
pageSize
);
themes
=
themeService
.
queryByUserIdsCreateDesc
(
fansList
,
pageStart
,
pageSize
);
if
(
CollectionUtils
.
isEmpty
(
excludeIds
)
&&
!
themes
.
isEmpty
())
{
if
(
CollectionUtils
.
isEmpty
(
excludeIds
)
&&
!
themes
.
isEmpty
())
{
// 说明是从头开始刷,则直接把最新的lastId放到redis中,保留一个月
// 说明是从头开始刷,则直接把最新的lastId放到redis中,保留一个月
Long
lastId
=
themes
.
stream
().
map
(
ThemeEntity:
:
getId
).
max
(
Long:
:
compareTo
).
get
();
Long
lastId
=
themes
.
stream
().
map
(
ThemeEntity:
:
getId
).
max
(
Long:
:
compareTo
).
get
();
redisCache
.
put
(
CACHE_IDOL_THEME_LAST_ID
+
userId
,
lastId
,
60
*
60
*
24
*
7
*
4
);
redisCache
.
put
(
CACHE_IDOL_THEME_LAST_ID
+
req
.
getUserId
()
,
lastId
,
60
*
60
*
24
*
7
*
4
);
// visitLogService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW);
// visitLogService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW);
}
}
...
@@ -534,7 +539,7 @@ public class ThemeManager {
...
@@ -534,7 +539,7 @@ public class ThemeManager {
}
}
ThemeListResp
resp
=
new
ThemeListResp
();
ThemeListResp
resp
=
new
ThemeListResp
();
resp
.
themes
=
convertEntityToQo
(
themes
,
userId
);
resp
.
themes
=
convertEntityToQo
(
themes
,
req
.
getUserId
()
);
excludeIds
.
addAll
(
resp
.
themes
.
stream
().
map
(
ThemeQo:
:
getThemeId
).
collect
(
Collectors
.
toList
()));
excludeIds
.
addAll
(
resp
.
themes
.
stream
().
map
(
ThemeQo:
:
getThemeId
).
collect
(
Collectors
.
toList
()));
redisCache
.
put
(
"queryThemes_"
+
req
.
ident
,
excludeIds
,
60
*
60
*
6
);
redisCache
.
put
(
"queryThemes_"
+
req
.
ident
,
excludeIds
,
60
*
60
*
6
);
...
@@ -556,8 +561,9 @@ public class ThemeManager {
...
@@ -556,8 +561,9 @@ public class ThemeManager {
}
}
// 和用户相关信息
// 和用户相关信息
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
buildThemeExtraInfoByUser
(
userId
,
themeQos
);
buildThemeExtraInfoByUser
(
userId
,
themeQos
);
}
return
themeQos
;
return
themeQos
;
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/RecommendService.java
View file @
0efc6dbf
package
com
.
tanpu
.
community
.
service
;
package
com
.
tanpu
.
community
.
service
;
import
com.google.common.collect.Lists
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.community.api.beans.qo.ThemeAnalysDO
;
import
com.tanpu.community.api.beans.qo.ThemeAnalysDO
;
import
com.tanpu.community.api.beans.resp.PythonResponse
;
import
com.tanpu.community.api.beans.resp.PythonResponse
;
...
@@ -8,6 +9,7 @@ import com.tanpu.community.util.BizUtils;
...
@@ -8,6 +9,7 @@ import com.tanpu.community.util.BizUtils;
import
com.tanpu.community.util.ConvertUtil
;
import
com.tanpu.community.util.ConvertUtil
;
import
com.tanpu.community.util.TimeUtils
;
import
com.tanpu.community.util.TimeUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -72,11 +74,16 @@ public class RecommendService {
...
@@ -72,11 +74,16 @@ public class RecommendService {
newThemeIds
=
BizUtils
.
subList
(
newThemeIds
,
0
,
pageSize
);
newThemeIds
=
BizUtils
.
subList
(
newThemeIds
,
0
,
pageSize
);
//推荐话题
//推荐话题
List
<
String
>
recThemeIds
=
getPythonRecommendList
(
userId
).
stream
()
List
<
String
>
recThemeIds
;
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
recThemeIds
=
getPythonRecommendList
(
userId
).
stream
()
.
filter
(
id
->
{
.
filter
(
id
->
{
return
!
excludeIds
.
contains
(
id
);
return
!
excludeIds
.
contains
(
id
);
}).
collect
(
Collectors
.
toList
());
}).
collect
(
Collectors
.
toList
());
recThemeIds
=
BizUtils
.
subList
(
recThemeIds
,
pageStart
,
pageSize
);
recThemeIds
=
BizUtils
.
subList
(
recThemeIds
,
pageStart
,
pageSize
);
}
else
{
recThemeIds
=
Lists
.
newArrayListWithCapacity
(
0
);
}
// merge
// merge
return
mergeRecommend
(
hotThemeIds
,
newThemeIds
,
recThemeIds
);
return
mergeRecommend
(
hotThemeIds
,
newThemeIds
,
recThemeIds
);
...
...
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