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
0e96088d
Commit
0e96088d
authored
Jul 29, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
主题推荐优化
parent
4d81b0e8
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
14 deletions
+31
-14
TopicRankQo.java
...in/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
+7
-1
ThemeListReq.java
...com/tanpu/community/api/beans/req/theme/ThemeListReq.java
+1
-4
ThemeController.java
.../java/com/tanpu/community/controller/ThemeController.java
+1
-1
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+1
-4
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+6
-2
BizUtils.java
...vice/src/main/java/com/tanpu/community/util/BizUtils.java
+15
-2
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
View file @
0e96088d
...
@@ -23,6 +23,12 @@ public class TopicRankQo {
...
@@ -23,6 +23,12 @@ public class TopicRankQo {
@ApiModelProperty
(
value
=
"讨论量"
)
@ApiModelProperty
(
value
=
"讨论量"
)
private
Integer
disscussCount
;
private
Integer
disscussCount
;
@ApiModelProperty
(
value
=
"阅读量-格式化"
)
private
String
formatViewCount
;
@ApiModelProperty
(
value
=
"讨论量-格式化"
)
private
String
formatDisscussCount
;
@ApiModelProperty
(
value
=
"是否置顶"
)
@ApiModelProperty
(
value
=
"是否置顶"
)
private
Integer
isTop
;
private
Integer
isTop
;
...
@@ -42,6 +48,6 @@ public class TopicRankQo {
...
@@ -42,6 +48,6 @@ public class TopicRankQo {
if
(
isTop
>
0
)
{
if
(
isTop
>
0
)
{
return
Integer
.
MAX_VALUE
;
return
Integer
.
MAX_VALUE
;
}
}
return
this
.
viewCount
+
this
.
disscussCount
*
3
+
viewCount
+
themeWeight
;
return
this
.
disscussCount
*
3
+
viewCount
+
themeWeight
;
}
}
}
}
community-api/src/main/java/com/tanpu/community/api/beans/req/theme/ThemeListReq.java
View file @
0e96088d
...
@@ -6,7 +6,6 @@ import io.swagger.annotations.ApiModelProperty;
...
@@ -6,7 +6,6 @@ import io.swagger.annotations.ApiModelProperty;
import
lombok.Data
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.NotNull
;
import
java.util.List
;
@Data
@Data
public
class
ThemeListReq
{
public
class
ThemeListReq
{
...
@@ -19,11 +18,9 @@ public class ThemeListReq {
...
@@ -19,11 +18,9 @@ public class ThemeListReq {
@ApiModelProperty
(
value
=
"话题Id"
)
@ApiModelProperty
(
value
=
"话题Id"
)
public
String
topicId
;
public
String
topicId
;
@ApiModelProperty
(
value
=
"当前浏览的最后一个themeId,可以为空"
)
public
String
lastId
=
""
;
@NotNull
(
message
=
"分页"
)
@NotNull
(
message
=
"分页"
)
public
Pageable
page
;
public
Pageable
page
;
@ApiModelProperty
(
value
=
"session_id"
)
public
String
ident
;
public
String
ident
;
}
}
community-service/src/main/java/com/tanpu/community/controller/ThemeController.java
View file @
0e96088d
...
@@ -42,7 +42,7 @@ public class ThemeController {
...
@@ -42,7 +42,7 @@ public class ThemeController {
@ResponseBody
@ResponseBody
public
CommonResp
<
ThemeListResp
>
selectInterestList
(
@Validated
@RequestBody
ThemeListReq
req
)
{
public
CommonResp
<
ThemeListResp
>
selectInterestList
(
@Validated
@RequestBody
ThemeListReq
req
)
{
String
userId
=
userHolder
.
getUserId
();
String
userId
=
userHolder
.
getUserId
();
ThemeListResp
result
=
themeManager
.
query
Themes
(
req
,
userId
);
ThemeListResp
result
=
themeManager
.
query
List
(
req
,
userId
);
return
CommonResp
.
success
(
result
);
return
CommonResp
.
success
(
result
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
0e96088d
...
@@ -60,9 +60,6 @@ public class ThemeManager {
...
@@ -60,9 +60,6 @@ public class ThemeManager {
@Autowired
@Autowired
private
BlackListService
blackListService
;
private
BlackListService
blackListService
;
@Autowired
private
UserInfoService
userInfoService
;
@Autowired
@Autowired
private
ThemeAttachmentService
themeAttachmentService
;
private
ThemeAttachmentService
themeAttachmentService
;
...
@@ -203,7 +200,7 @@ public class ThemeManager {
...
@@ -203,7 +200,7 @@ public class ThemeManager {
* 推荐:由最热,最新和python推荐三个部分组成,比例为6,3,1
* 推荐:由最热,最新和python推荐三个部分组成,比例为6,3,1
*/
*/
// 查询主题列表:推荐/关注/热门/最新
// 查询主题列表:推荐/关注/热门/最新
public
ThemeListResp
query
Themes
(
ThemeListReq
req
,
String
userId
)
{
public
ThemeListResp
query
List
(
ThemeListReq
req
,
String
userId
)
{
List
<
String
>
excludeIds
;
List
<
String
>
excludeIds
;
if
(
req
.
page
.
pageNumber
>
1
)
{
if
(
req
.
page
.
pageNumber
>
1
)
{
String
l
=
redisCache
.
get
(
"queryThemes_"
+
req
.
ident
);
String
l
=
redisCache
.
get
(
"queryThemes_"
+
req
.
ident
);
...
...
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
0e96088d
...
@@ -10,6 +10,7 @@ import com.tanpu.community.cache.RedisCache;
...
@@ -10,6 +10,7 @@ import com.tanpu.community.cache.RedisCache;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.feign.fatools.FeignClientForFatools
;
import
com.tanpu.community.feign.fatools.FeignClientForFatools
;
import
com.tanpu.community.util.BizUtils
;
import
com.tanpu.community.util.ConvertUtil
;
import
com.tanpu.community.util.ConvertUtil
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -120,7 +121,7 @@ public class RankService {
...
@@ -120,7 +121,7 @@ public class RankService {
// 浏览量
// 浏览量
Integer
topicPV
=
countMapByTargetIds
.
getOrDefault
(
topic
.
getTopicId
(),
0
);
Integer
topicPV
=
countMapByTargetIds
.
getOrDefault
(
topic
.
getTopicId
(),
0
);
Integer
themePV
=
visitLogService
.
queryThemeVisit
(
themeIds
);
Integer
themePV
=
visitLogService
.
queryThemeVisit
(
themeIds
);
topic
.
setViewCount
(
topicPV
+
themePV
);
topic
.
setViewCount
(
topicPV
+
themePV
+
topic
.
getViewCntAdjust
()
);
//讨论数=发布主题贴数+回复总数
//讨论数=发布主题贴数+回复总数
Integer
commentCount
=
commentService
.
getTotalCountByThemeIds
(
themeIds
);
Integer
commentCount
=
commentService
.
getTotalCountByThemeIds
(
themeIds
);
topic
.
setDisscussCount
(
themeIds
.
size
()
+
commentCount
);
topic
.
setDisscussCount
(
themeIds
.
size
()
+
commentCount
);
...
@@ -128,7 +129,10 @@ public class RankService {
...
@@ -128,7 +129,10 @@ public class RankService {
double
themeSum
=
getHotestThemes
().
stream
().
filter
(
o
->
topic
.
getTopicId
().
equals
(
o
.
getTopicId
()))
double
themeSum
=
getHotestThemes
().
stream
().
filter
(
o
->
topic
.
getTopicId
().
equals
(
o
.
getTopicId
()))
.
mapToDouble
(
ThemeAnalysDO:
:
calcScore
)
.
mapToDouble
(
ThemeAnalysDO:
:
calcScore
)
.
sum
();
.
sum
();
topic
.
setThemeWeight
((
int
)
themeSum
);
topic
.
setThemeWeight
((
int
)
themeSum
);
//格式化浏览量、讨论量
topic
.
setFormatViewCount
(
BizUtils
.
formatCountNumber
(
topic
.
getViewCount
()));
topic
.
setFormatDisscussCount
(
BizUtils
.
formatCountNumber
(
topic
.
getDisscussCount
()));
}
}
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/util/BizUtils.java
View file @
0e96088d
package
com
.
tanpu
.
community
.
util
;
package
com
.
tanpu
.
community
.
util
;
import
com.alibaba.fastjson.JSON
;
import
com.tanpu.community.api.beans.qo.ThemeContentQo
;
import
com.tanpu.community.api.beans.qo.ThemeContentQo
;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
import
com.tanpu.community.api.enums.RelTypeEnum
;
import
com.tanpu.community.api.enums.RelTypeEnum
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -37,4 +35,19 @@ public class BizUtils {
...
@@ -37,4 +35,19 @@ public class BizUtils {
}
}
return
""
;
return
""
;
}
}
public
static
String
formatCountNumber
(
Integer
number
)
{
if
(
number
<
10000
)
{
return
number
.
toString
();
}
else
{
double
d
=
number
*
1.0
/
10000
;
return
String
.
format
(
"%.1f"
,
d
)+
"w"
;
}
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
formatCountNumber
(
110400
));
System
.
out
.
println
(
formatCountNumber
(
111100
));
System
.
out
.
println
(
formatCountNumber
(
1000
));
}
}
}
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