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
c9d39e6a
Commit
c9d39e6a
authored
Jul 29, 2021
by
张辰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
http://47.100.44.39:10001/tp-backend/tanpu-community
into dev
parents
76f15fb0
4d81b0e8
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
16 deletions
+45
-16
TopicRankQo.java
...in/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
+7
-3
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+6
-7
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+5
-0
ThemeService.java
...c/main/java/com/tanpu/community/service/ThemeService.java
+1
-0
RankUtils.java
...ice/src/main/java/com/tanpu/community/util/RankUtils.java
+11
-2
TimeUtils.java
...ice/src/main/java/com/tanpu/community/util/TimeUtils.java
+15
-4
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
View file @
c9d39e6a
...
@@ -29,15 +29,19 @@ public class TopicRankQo {
...
@@ -29,15 +29,19 @@ public class TopicRankQo {
@ApiModelProperty
(
value
=
"浏览量调整基数"
)
@ApiModelProperty
(
value
=
"浏览量调整基数"
)
private
Integer
viewCntAdjust
;
private
Integer
viewCntAdjust
;
@ApiModelProperty
(
value
=
"话题下的帖子权重"
)
private
Integer
themeWeight
;
/**
/**
* TODO 热度计算算法
* TODO 热度计算算法
*
* @return
* @return
*/
*/
public
Integer
getRank
(){
public
Integer
getRank
()
{
//顶置话题
//顶置话题
if
(
isTop
>
0
)
{
if
(
isTop
>
0
)
{
return
Integer
.
MAX_VALUE
;
return
Integer
.
MAX_VALUE
;
}
}
return
this
.
viewCount
+
this
.
disscussCount
*
3
+
viewCoun
t
;
return
this
.
viewCount
+
this
.
disscussCount
*
3
+
viewCount
+
themeWeigh
t
;
}
}
}
}
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
c9d39e6a
package
com
.
tanpu
.
community
.
manager
;
package
com
.
tanpu
.
community
.
manager
;
import
com.alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.google.common.collect.Sets
;
import
com.google.common.collect.Sets
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.api.CommonResp
;
...
@@ -216,20 +215,20 @@ public class ThemeManager {
...
@@ -216,20 +215,20 @@ public class ThemeManager {
Integer
pageStart
=
(
req
.
page
.
pageNumber
-
1
)
*
req
.
page
.
pageSize
;
Integer
pageStart
=
(
req
.
page
.
pageNumber
-
1
)
*
req
.
page
.
pageSize
;
Integer
pageSize
=
req
.
page
.
pageSize
;
Integer
pageSize
=
req
.
page
.
pageSize
;
Integer
querySize
=
pageSize
*
3
;
List
<
ThemeEntity
>
themes
=
new
ArrayList
<>();
List
<
ThemeEntity
>
themes
=
new
ArrayList
<>();
if
(
ThemeListTypeEnum
.
RECOMMEND
.
getCode
().
equals
(
req
.
getType
()))
{
if
(
ThemeListTypeEnum
.
RECOMMEND
.
getCode
().
equals
(
req
.
getType
()))
{
//推荐
//
推荐
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
List
<
String
>
visitedIds
=
visitLogService
.
queryUserRecentVisited
(
userId
);
List
<
String
>
visitedIds
=
visitLogService
.
queryUserRecentVisited
(
userId
);
List
<
String
>
excludes
=
ListUtils
.
union
(
excludeIds
,
visitedIds
);
List
<
String
>
excludes
=
ListUtils
.
union
(
excludeIds
,
visitedIds
);
List
<
String
>
recmdIds
=
recommendService
.
getRecommendThemes
(
pageStart
,
query
Size
,
userId
,
excludes
);
List
<
String
>
recmdIds
=
recommendService
.
getRecommendThemes
(
pageStart
,
page
Size
,
userId
,
excludes
);
recmdIds
=
BizUtils
.
subList
(
recmdIds
,
pageStart
,
pageSize
);
themes
=
themeService
.
queryByThemeIds
(
recmdIds
);
themes
=
themeService
.
queryByThemeIds
(
recmdIds
);
themes
=
RankUtils
.
sortThemeEntityByIds
(
themes
,
recmdIds
);
themes
=
RankUtils
.
sortThemeEntityByIds
(
themes
,
recmdIds
).
stream
().
limit
(
pageSize
).
collect
(
Collectors
.
toList
());
}
else
if
(
ThemeListTypeEnum
.
FOLLOW
.
getCode
().
equals
(
req
.
getType
()))
{
}
else
if
(
ThemeListTypeEnum
.
FOLLOW
.
getCode
().
equals
(
req
.
getType
()))
{
// TODO 临时埋点,接入新埋点后删除
// TODO 临时埋点,接入新埋点后删除
...
@@ -257,7 +256,7 @@ public class ThemeManager {
...
@@ -257,7 +256,7 @@ public class ThemeManager {
if
(
StringUtils
.
isEmpty
(
req
.
getTopicId
()))
{
if
(
StringUtils
.
isEmpty
(
req
.
getTopicId
()))
{
throw
new
BizException
(
"TopicId为空"
);
throw
new
BizException
(
"TopicId为空"
);
}
}
themes
=
themeService
.
queryNewestByTopic
(
req
.
topicId
,
pageStart
,
query
Size
,
excludeIds
);
themes
=
themeService
.
queryNewestByTopic
(
req
.
topicId
,
pageStart
,
page
Size
,
excludeIds
);
}
}
ThemeListResp
resp
=
new
ThemeListResp
();
ThemeListResp
resp
=
new
ThemeListResp
();
...
...
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
c9d39e6a
...
@@ -124,6 +124,11 @@ public class RankService {
...
@@ -124,6 +124,11 @@ public class RankService {
//讨论数=发布主题贴数+回复总数
//讨论数=发布主题贴数+回复总数
Integer
commentCount
=
commentService
.
getTotalCountByThemeIds
(
themeIds
);
Integer
commentCount
=
commentService
.
getTotalCountByThemeIds
(
themeIds
);
topic
.
setDisscussCount
(
themeIds
.
size
()
+
commentCount
);
topic
.
setDisscussCount
(
themeIds
.
size
()
+
commentCount
);
//帖子权重,求和
double
themeSum
=
getHotestThemes
().
stream
().
filter
(
o
->
topic
.
getTopicId
().
equals
(
o
.
getTopicId
()))
.
mapToDouble
(
ThemeAnalysDO:
:
calcScore
)
.
sum
();
topic
.
setThemeWeight
((
int
)
themeSum
);
}
}
Map
<
TopicRankQo
,
Integer
>
map
=
topicRankQos
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
TopicRankQo:
:
getRank
));
Map
<
TopicRankQo
,
Integer
>
map
=
topicRankQos
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
TopicRankQo:
:
getRank
));
List
<
TopicRankQo
>
rankList
=
map
.
entrySet
().
stream
()
List
<
TopicRankQo
>
rankList
=
map
.
entrySet
().
stream
()
...
...
community-service/src/main/java/com/tanpu/community/service/ThemeService.java
View file @
c9d39e6a
...
@@ -240,6 +240,7 @@ public class ThemeService {
...
@@ -240,6 +240,7 @@ public class ThemeService {
if
(
CollectionUtils
.
isEmpty
(
userIds
)){
if
(
CollectionUtils
.
isEmpty
(
userIds
)){
return
Collections
.
emptyList
();
return
Collections
.
emptyList
();
}
}
//TODO 索引优化
LambdaQueryWrapper
<
ThemeEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
LambdaQueryWrapper
<
ThemeEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
in
(
ThemeEntity:
:
getAuthorId
,
userIds
)
.
in
(
ThemeEntity:
:
getAuthorId
,
userIds
)
.
last
(
"limit "
+
pageStart
+
", "
+
pageSize
)
.
last
(
"limit "
+
pageStart
+
", "
+
pageSize
)
...
...
community-service/src/main/java/com/tanpu/community/util/RankUtils.java
View file @
c9d39e6a
...
@@ -10,13 +10,22 @@ import java.util.stream.Collectors;
...
@@ -10,13 +10,22 @@ import java.util.stream.Collectors;
public
class
RankUtils
{
public
class
RankUtils
{
/**
* 根据id排序主题对象
* @param list 主题
* @param ids 主题Id,list中可重复
* @return
*/
public
static
List
<
ThemeEntity
>
sortThemeEntityByIds
(
List
<
ThemeEntity
>
list
,
List
<
String
>
ids
){
public
static
List
<
ThemeEntity
>
sortThemeEntityByIds
(
List
<
ThemeEntity
>
list
,
List
<
String
>
ids
){
int
count
=
0
;
int
count
=
0
;
HashMap
<
String
,
Integer
>
indexMap
=
new
HashMap
<>();
HashMap
<
String
,
Integer
>
indexMap
=
new
HashMap
<>();
for
(
String
id
:
ids
)
{
for
(
String
id
:
ids
)
{
//list中出现重复元素时,优化取第一次出现的顺序
if
(!
indexMap
.
containsKey
(
id
)){
indexMap
.
put
(
id
,
count
++);
indexMap
.
put
(
id
,
count
++);
}
}
}
List
<
ThemeEntity
>
collect
=
list
.
stream
().
filter
(
o
->
indexMap
.
containsKey
(
o
.
getThemeId
()))
List
<
ThemeEntity
>
collect
=
list
.
stream
().
filter
(
o
->
indexMap
.
containsKey
(
o
.
getThemeId
()))
.
sorted
(
Comparator
.
comparingInt
(
o
->
indexMap
.
get
(
o
.
getThemeId
())))
.
sorted
(
Comparator
.
comparingInt
(
o
->
indexMap
.
get
(
o
.
getThemeId
())))
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
...
...
community-service/src/main/java/com/tanpu/community/util/TimeUtils.java
View file @
c9d39e6a
...
@@ -29,10 +29,12 @@ public class TimeUtils {
...
@@ -29,10 +29,12 @@ public class TimeUtils {
return
duration
+
"分钟前"
;
return
duration
+
"分钟前"
;
}
else
if
(
duration
<
60
*
24
)
{
}
else
if
(
duration
<
60
*
24
)
{
return
duration
/
60
+
"小时前"
;
return
duration
/
60
+
"小时前"
;
}
else
if
(
start
.
getYear
()
==
LocalDateTime
.
now
().
getYear
())
{
}
else
if
(
duration
<
60
*
48
)
{
return
start
.
format
(
DateTimeFormatter
.
ofPattern
(
"MM-dd HH:mm:ss"
));
return
"1天前"
;
}
else
if
(
duration
<
60
*
24
*
180
)
{
return
start
.
format
(
DateTimeFormatter
.
ofPattern
(
"MM-dd HH:mm"
));
}
}
return
start
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm
:ss
"
));
return
start
.
format
(
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm"
));
}
}
//计算迄今时间
//计算迄今时间
...
@@ -43,8 +45,17 @@ public class TimeUtils {
...
@@ -43,8 +45,17 @@ public class TimeUtils {
//计算n天前的时间
//计算n天前的时间
public
static
LocalDateTime
getDaysBefore
(
Integer
number
){
public
static
LocalDateTime
getDaysBefore
(
Integer
number
)
{
return
LocalDateTime
.
now
().
minusDays
(
number
);
return
LocalDateTime
.
now
().
minusDays
(
number
);
}
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
calUpToNowTime
(
LocalDateTime
.
now
().
minusDays
(
180
)));
System
.
out
.
println
(
calUpToNowTime
(
LocalDateTime
.
now
().
minusDays
(
1
)));
System
.
out
.
println
(
calUpToNowTime
(
LocalDateTime
.
now
().
minusDays
(
18
)));
System
.
out
.
println
(
calUpToNowTime
(
LocalDateTime
.
now
().
minusHours
(
2
)));
System
.
out
.
println
(
calUpToNowTime
(
LocalDateTime
.
now
().
minusMinutes
(
12
)));
System
.
out
.
println
(
calUpToNowTime
(
LocalDateTime
.
now
().
minusSeconds
(
12
)));
}
}
}
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