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
611177be
Commit
611177be
authored
Aug 09, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推荐列表 fix
parent
16f7e25e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
14 deletions
+36
-14
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+13
-8
RecommendService.java
...in/java/com/tanpu/community/service/RecommendService.java
+11
-6
TimeUtils.java
...ice/src/main/java/com/tanpu/community/util/TimeUtils.java
+12
-0
No files found.
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
611177be
...
...
@@ -77,6 +77,7 @@ import javax.annotation.PostConstruct;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.io.IOException
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -142,7 +143,7 @@ public class ThemeManager {
FileUtils
.
forceMkdir
(
f
);
}
}
// 专栏
@Autowired
private
FeignClientForCommunity
feignClientForCommunity
;
...
...
@@ -403,15 +404,19 @@ public class ThemeManager {
*/
// 查询主题列表:推荐/关注/热门/最新
public
ThemeListResp
queryList
(
ThemeListReq
req
,
String
userId
)
{
List
<
String
>
excludeIds
;
List
<
String
>
excludeIds
=
new
ArrayList
<>();
LocalDateTime
firstThemeTime
=
LocalDateTime
.
now
();
if
(
req
.
page
.
pageNumber
>
1
)
{
String
l
=
redisCache
.
get
(
"queryThemes_"
+
req
.
ident
);
excludeIds
=
StringUtils
.
isBlank
(
l
)
?
new
ArrayList
<>()
:
JsonUtil
.
toBean
(
l
,
new
TypeReference
<
List
<
String
>>()
{
});
}
else
{
excludeIds
=
new
ArrayList
<>();
if
(
StringUtils
.
isBlank
(
l
))
{
excludeIds
=
JsonUtil
.
toBean
(
l
,
new
TypeReference
<
List
<
String
>>()
{
});
firstThemeTime
=
themeService
.
queryByThemeIdIgnoreDelete
(
excludeIds
.
get
(
0
)).
getCreateTime
();
}
}
Integer
pageStart
=
(
req
.
page
.
pageNumber
-
1
)
*
req
.
page
.
pageSize
;
Integer
pageSize
=
req
.
page
.
pageSize
;
...
...
@@ -422,11 +427,11 @@ public class ThemeManager {
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
List
<
String
>
visitedIds
=
visitLogService
.
queryUserRecentVisited
(
userId
);
List
<
String
>
excludes
=
ListUtils
.
union
(
excludeIds
,
visitedIds
);
List
<
String
>
recmdIds
=
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
userId
,
excludes
);
List
<
String
>
recmdIds
=
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
userId
,
excludes
,
firstThemeTime
);
// 加载第一页时,为防止首页显示空列表,从推荐池中再捞出已看过帖子
if
(
req
.
page
.
pageNumber
==
1
&&
recmdIds
.
size
()
<
pageSize
)
{
recmdIds
.
addAll
(
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
userId
,
recmdIds
));
recmdIds
.
addAll
(
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
userId
,
recmdIds
,
firstThemeTime
));
}
themes
=
themeService
.
queryByThemeIds
(
recmdIds
);
...
...
community-service/src/main/java/com/tanpu/community/service/RecommendService.java
View file @
611177be
...
...
@@ -6,6 +6,7 @@ import com.tanpu.community.api.beans.resp.PythonResponse;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.util.BizUtils
;
import
com.tanpu.community.util.ConvertUtil
;
import
com.tanpu.community.util.TimeUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -13,6 +14,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -49,22 +51,25 @@ public class RecommendService {
// 推荐
private
Map
<
String
,
List
<
String
>>
recommondList
=
new
HashMap
<>();
public
List
<
String
>
getRecommendThemes
(
Integer
pageStart
,
Integer
pageSize
,
String
userId
,
List
<
String
>
excludeIds
)
{
public
List
<
String
>
getRecommendThemes
(
Integer
pageStart
,
Integer
pageSize
,
String
userId
,
List
<
String
>
excludeIds
,
LocalDateTime
timeAfter
)
{
// 最热话题,筛掉用户发表的 & 最近看过的 & excludeIds
List
<
String
>
hotThemeIds
=
rankService
.
getHotestThemes
().
stream
()
.
filter
(
theme
->
{
return
!
excludeIds
.
contains
(
theme
.
getThemeId
())
&&
!
userId
.
equals
(
theme
.
getAuthorId
());
// 暂时不过滤用户自己发的 !userId.equals(theme.getAuthorId());
return
!
excludeIds
.
contains
(
theme
.
getThemeId
());
})
.
map
(
ThemeAnalysDO:
:
getThemeId
).
collect
(
Collectors
.
toList
());
hotThemeIds
=
BizUtils
.
subList
(
hotThemeIds
,
pageStart
,
pageSize
);
hotThemeIds
=
BizUtils
.
subList
(
hotThemeIds
,
0
,
pageSize
);
//最新话题,筛掉用户发表的 & 最近看过的 & excludeIds
//最新话题,筛掉用户发表的 & 最近看过的 & excludeIds && 上次查询后发帖的
long
margin
=
TimeUtils
.
calMinuteTillNow
(
timeAfter
);
List
<
String
>
newThemeIds
=
getNewestThemes
().
stream
()
.
filter
(
theme
->
{
return
!
excludeIds
.
contains
(
theme
.
getThemeId
())
&&
!
userId
.
equals
(
theme
.
getAuthorId
());
// 暂时不过滤用户自己发的 !userId.equals(theme.getAuthorId());
return
!
excludeIds
.
contains
(
theme
.
getThemeId
())
&&
theme
.
getMinutesTillNow
()
>
margin
;
})
.
map
(
ThemeAnalysDO:
:
getThemeId
).
collect
(
Collectors
.
toList
());
newThemeIds
=
BizUtils
.
subList
(
newThemeIds
,
pageStart
,
pageSize
);
newThemeIds
=
BizUtils
.
subList
(
newThemeIds
,
0
,
pageSize
);
//推荐话题
List
<
String
>
recThemeIds
=
getPythonRecommendList
(
userId
).
stream
()
...
...
community-service/src/main/java/com/tanpu/community/util/TimeUtils.java
View file @
611177be
...
...
@@ -44,24 +44,36 @@ public class TimeUtils {
//计算迄今分钟
public
static
long
calMinuteTillNow
(
LocalDateTime
start
)
{
if
(
start
==
null
){
return
0L
;
}
Duration
between
=
Duration
.
between
(
start
,
LocalDateTime
.
now
());
return
between
.
toMinutes
();
}
//计算迄今毫秒数
public
static
long
calMillisTillNow
(
LocalDateTime
start
)
{
if
(
start
==
null
){
return
0L
;
}
Duration
between
=
Duration
.
between
(
start
,
LocalDateTime
.
now
());
return
between
.
toMillis
();
}
//计算迄今天数
public
static
long
calDaysTillNow
(
LocalDateTime
start
)
{
if
(
start
==
null
){
return
0L
;
}
Duration
between
=
Duration
.
between
(
start
,
LocalDateTime
.
now
());
return
between
.
toDays
();
}
//计算迄今小时数
public
static
long
calHoursTillNow
(
LocalDateTime
start
)
{
if
(
start
==
null
){
return
0L
;
}
Duration
between
=
Duration
.
between
(
start
,
LocalDateTime
.
now
());
return
between
.
toHours
();
}
...
...
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