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
27fdb913
Commit
27fdb913
authored
Jul 27, 2021
by
张辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码风格修正
parent
e80fc01a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
56 additions
and
32 deletions
+56
-32
ThemeAnalysDO.java
.../java/com/tanpu/community/api/beans/qo/ThemeAnalysDO.java
+1
-1
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+2
-2
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+1
-1
FeignService.java
...c/main/java/com/tanpu/community/service/FeignService.java
+23
-0
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+22
-22
RecommendService.java
...in/java/com/tanpu/community/service/RecommendService.java
+6
-5
ThemeService.java
...c/main/java/com/tanpu/community/service/ThemeService.java
+1
-1
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/ThemeAnalysDO.java
View file @
27fdb913
...
@@ -50,7 +50,7 @@ public class ThemeAnalysDO {
...
@@ -50,7 +50,7 @@ public class ThemeAnalysDO {
private
Double
userWeight
=
0.0
;
private
Double
userWeight
=
0.0
;
public
Double
get
Score
()
{
public
Double
calc
Score
()
{
//质量=帖子质量+用户质量
//质量=帖子质量+用户质量
double
w
=
(
double
)
(
viewCount
*
0.1
+
forwardCount
*
3
+
commentCount
*
2
+
likeCount
*
1
+
collectCount
*
3
)
+
userWeight
;
double
w
=
(
double
)
(
viewCount
*
0.1
+
forwardCount
*
3
+
commentCount
*
2
+
likeCount
*
1
+
collectCount
*
3
)
+
userWeight
;
double
i
=
1
;
//初试权重
double
i
=
1
;
//初试权重
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
27fdb913
...
@@ -165,7 +165,7 @@ public class ThemeManager {
...
@@ -165,7 +165,7 @@ public class ThemeManager {
.
themeType
(
ThemeTypeEnum
.
FORWARD
.
getCode
())
.
themeType
(
ThemeTypeEnum
.
FORWARD
.
getCode
())
.
build
();
.
build
();
if
(
StringUtils
.
isEmpty
(
req
.
getEditThemeId
())
||
req
.
getEditThemeId
()
==
req
.
getFormerThemeId
(
))
{
if
(
StringUtils
.
isEmpty
(
req
.
getEditThemeId
())
||
req
.
getEditThemeId
()
.
equals
(
req
.
getFormerThemeId
()
))
{
//新建
//新建
themeService
.
insertTheme
(
themeEntity
);
themeService
.
insertTheme
(
themeEntity
);
}
else
{
}
else
{
...
@@ -183,6 +183,7 @@ public class ThemeManager {
...
@@ -183,6 +183,7 @@ public class ThemeManager {
List
<
ThemeEntity
>
themeEntities
=
new
ArrayList
<>();
List
<
ThemeEntity
>
themeEntities
=
new
ArrayList
<>();
if
(
ThemeListTypeEnum
.
RECOMMEND
.
getCode
().
equals
(
req
.
getType
()))
{
if
(
ThemeListTypeEnum
.
RECOMMEND
.
getCode
().
equals
(
req
.
getType
()))
{
//推荐
//推荐
List
<
String
>
recommendThemeIds
=
recommendService
.
getRecommendThemes
(
req
.
getLastId
(),
req
.
getPageSize
(),
userId
);
List
<
String
>
recommendThemeIds
=
recommendService
.
getRecommendThemes
(
req
.
getLastId
(),
req
.
getPageSize
(),
userId
);
themeEntities
=
themeService
.
queryByThemeIds
(
recommendThemeIds
);
themeEntities
=
themeService
.
queryByThemeIds
(
recommendThemeIds
);
themeEntities
=
RankUtils
.
sortThemeEntityByIds
(
themeEntities
,
recommendThemeIds
);
themeEntities
=
RankUtils
.
sortThemeEntityByIds
(
themeEntities
,
recommendThemeIds
);
...
@@ -271,7 +272,6 @@ public class ThemeManager {
...
@@ -271,7 +272,6 @@ public class ThemeManager {
themeEntities
=
themeService
.
queryThemesByUserId
(
req
.
getUserId
(),
req
.
getLastId
(),
req
.
getPageSize
());
themeEntities
=
themeService
.
queryThemesByUserId
(
req
.
getUserId
(),
req
.
getLastId
(),
req
.
getPageSize
());
break
;
break
;
case
2
:
//回复
case
2
:
//回复
List
<
ThemeQo
>
commentThemeList
=
getCommentThemeQos
(
req
,
userId
);
List
<
ThemeQo
>
commentThemeList
=
getCommentThemeQos
(
req
,
userId
);
return
commentThemeList
;
return
commentThemeList
;
case
3
:
//点赞
case
3
:
//点赞
...
...
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
View file @
27fdb913
...
@@ -30,7 +30,7 @@ public class TopicManager {
...
@@ -30,7 +30,7 @@ public class TopicManager {
// 新增话题
// 新增话题
public
void
insertTopic
(
String
topicTitle
,
String
userId
)
{
public
void
insertTopic
(
String
topicTitle
,
String
userId
)
{
if
(
topicService
.
queryByTitile
(
topicTitle
)
=
=
null
)
{
if
(
topicService
.
queryByTitile
(
topicTitle
)
!
=
null
)
{
throw
new
BizException
(
"话题名称已存在:"
+
topicTitle
);
throw
new
BizException
(
"话题名称已存在:"
+
topicTitle
);
}
}
topicService
.
addTopic
(
topicTitle
,
userId
);
topicService
.
addTopic
(
topicTitle
,
userId
);
...
...
community-service/src/main/java/com/tanpu/community/service/FeignService.java
0 → 100644
View file @
27fdb913
package
com
.
tanpu
.
community
.
service
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNew
;
import
com.tanpu.community.feign.fatools.FeignClientForFatools
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Service
public
class
FeignService
{
@Autowired
private
FeignClientForFatools
fatools
;
public
UserInfoNew
getUserInfoById
(
String
userId
)
{
CommonResp
<
UserInfoNew
>
userInfoNewCommonResp
=
fatools
.
queryUsersListNew
(
userId
);
if
(
userInfoNewCommonResp
.
isNotSuccess
())
{
throw
new
BizException
(
"内部接口调用失败"
);
}
return
userInfoNewCommonResp
.
getData
();
}
}
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
27fdb913
...
@@ -37,6 +37,9 @@ public class RankService {
...
@@ -37,6 +37,9 @@ public class RankService {
@Autowired
@Autowired
private
VisitSummaryService
visitSummaryService
;
private
VisitSummaryService
visitSummaryService
;
@Autowired
private
FeignService
feignService
;
@Autowired
@Autowired
private
RedisCache
redisCache
;
private
RedisCache
redisCache
;
...
@@ -44,7 +47,7 @@ public class RankService {
...
@@ -44,7 +47,7 @@ public class RankService {
private
FeignClientForFatools
feignClientForFatools
;
private
FeignClientForFatools
feignClientForFatools
;
//最热
//最热
private
List
<
ThemeAnalysDO
>
rankThemeList
=
new
ArrayList
<>();
private
List
<
ThemeAnalysDO
>
hotestThemes
=
new
ArrayList
<>();
private
List
<
TopicRankQo
>
rankTopicList
=
new
ArrayList
<>();
private
List
<
TopicRankQo
>
rankTopicList
=
new
ArrayList
<>();
...
@@ -80,28 +83,21 @@ public class RankService {
...
@@ -80,28 +83,21 @@ public class RankService {
//查询用户质量
//查询用户质量
String
authorId
=
theme
.
getAuthorId
();
String
authorId
=
theme
.
getAuthorId
();
UserInfoNew
authorInfo
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
CACHE_FEIGN_USER_INFO
,
authorId
),
UserInfoNew
authorInfo
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
CACHE_FEIGN_USER_INFO
,
authorId
),
60
*
10
,
()
->
this
.
getUserInfo
(
authorId
),
UserInfoNew
.
class
);
60
*
10
,
()
->
feignService
.
getUserInfoById
(
authorId
),
UserInfoNew
.
class
);
if
(
authorInfo
==
null
||
authorInfo
.
getLevelGrade
()
==
null
)
{
if
(
authorInfo
==
null
||
authorInfo
.
getLevelGrade
()
==
null
)
{
theme
.
setUserWeight
(
0.0
);
theme
.
setUserWeight
(
0.0
);
}
else
{
}
else
{
// 设置用户权重
theme
.
setUserWeight
(
authorInfo
.
getLevelGrade
()
*
1.0
);
theme
.
setUserWeight
(
authorInfo
.
getLevelGrade
()
*
1.0
);
}
}
}
}
//打分
//打分
Map
<
ThemeAnalysDO
,
Double
>
map
=
themeAnalysDOS
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
ThemeAnalysDO:
:
get
Score
));
Map
<
ThemeAnalysDO
,
Double
>
map
=
themeAnalysDOS
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
ThemeAnalysDO:
:
calc
Score
));
//排序
//排序
rankThemeList
=
map
.
entrySet
().
stream
().
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
())).
map
(
e
->
e
.
getKey
()).
collect
(
Collectors
.
toList
());
hotestThemes
=
map
.
entrySet
().
stream
()
.
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
()))
}
.
map
(
e
->
e
.
getKey
()).
collect
(
Collectors
.
toList
());
private
UserInfoNew
getUserInfo
(
String
authorId
)
{
CommonResp
<
UserInfoNew
>
userInfoNewCommonResp
=
feignClientForFatools
.
queryUsersListNew
(
authorId
);
if
(
userInfoNewCommonResp
.
isNotSuccess
())
{
throw
new
BizException
(
"内部接口调用失败"
);
}
return
userInfoNewCommonResp
.
getData
();
}
}
...
@@ -123,7 +119,8 @@ public class RankService {
...
@@ -123,7 +119,8 @@ public class RankService {
topic
.
setDisscussCount
(
0
);
topic
.
setDisscussCount
(
0
);
continue
;
continue
;
}
}
//浏览量
// 浏览量
// todo 批量查询
Integer
topicPV
=
visitSummaryService
.
queryTopicDetailVisit
(
topic
.
getTopicId
());
Integer
topicPV
=
visitSummaryService
.
queryTopicDetailVisit
(
topic
.
getTopicId
());
Integer
themePV
=
visitSummaryService
.
queryThemeVisit
(
themeIds
);
Integer
themePV
=
visitSummaryService
.
queryThemeVisit
(
themeIds
);
topic
.
setViewCount
(
topicPV
+
themePV
);
topic
.
setViewCount
(
topicPV
+
themePV
);
...
@@ -132,7 +129,10 @@ public class RankService {
...
@@ -132,7 +129,10 @@ public class RankService {
topic
.
setDisscussCount
(
themeIds
.
size
()
+
commentCount
);
topic
.
setDisscussCount
(
themeIds
.
size
()
+
commentCount
);
}
}
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
().
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
())).
map
(
Map
.
Entry
::
getKey
).
collect
(
Collectors
.
toList
());
List
<
TopicRankQo
>
rankList
=
map
.
entrySet
().
stream
()
.
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
()))
.
map
(
Map
.
Entry
::
getKey
)
.
collect
(
Collectors
.
toList
());
rankList
.
get
(
0
).
setType
(
TopicStatusEnum
.
HOTTEST
.
getCode
());
rankList
.
get
(
0
).
setType
(
TopicStatusEnum
.
HOTTEST
.
getCode
());
this
.
rankTopicList
=
rankList
;
this
.
rankTopicList
=
rankList
;
this
.
rankTopicListTop4
=
rankList
.
stream
().
limit
(
4
).
collect
(
Collectors
.
toList
());
this
.
rankTopicListTop4
=
rankList
.
stream
().
limit
(
4
).
collect
(
Collectors
.
toList
());
...
@@ -148,7 +148,7 @@ public class RankService {
...
@@ -148,7 +148,7 @@ public class RankService {
* @return
* @return
*/
*/
public
List
<
String
>
getHotAndNewThemes
(
Integer
hotCount
,
Integer
newCount
,
String
userId
)
{
public
List
<
String
>
getHotAndNewThemes
(
Integer
hotCount
,
Integer
newCount
,
String
userId
)
{
Set
<
String
>
hotThemeIds
=
this
.
rankThemeList
.
stream
().
limit
(
hotCount
)
Set
<
String
>
hotThemeIds
=
this
.
hotestThemes
.
stream
().
limit
(
hotCount
)
.
filter
(
o
->
!
userId
.
equals
(
o
.
getAuthorId
()))
.
filter
(
o
->
!
userId
.
equals
(
o
.
getAuthorId
()))
.
map
(
ThemeAnalysDO:
:
getThemeId
)
.
map
(
ThemeAnalysDO:
:
getThemeId
)
.
collect
(
Collectors
.
toSet
());
.
collect
(
Collectors
.
toSet
());
...
@@ -193,18 +193,18 @@ public class RankService {
...
@@ -193,18 +193,18 @@ public class RankService {
return
rankTopicListTop4
;
return
rankTopicListTop4
;
}
}
public
List
<
ThemeAnalysDO
>
get
RankThemeList
()
{
public
List
<
ThemeAnalysDO
>
get
HotestThemes
()
{
if
(
this
.
rankThemeList
.
size
()
==
0
)
{
if
(
this
.
hotestThemes
.
size
()
==
0
)
{
rankThemes
();
rankThemes
();
}
}
return
rankThemeList
;
return
hotestThemes
;
}
}
public
List
<
String
>
getRankThemeListByTopic
(
String
topicId
)
{
public
List
<
String
>
getRankThemeListByTopic
(
String
topicId
)
{
if
(
this
.
rankThemeList
.
size
()
==
0
)
{
if
(
this
.
hotestThemes
.
size
()
==
0
)
{
this
.
rankThemes
();
this
.
rankThemes
();
}
}
return
rankThemeList
.
stream
().
filter
(
o
->
topicId
.
equals
(
o
.
getTopicId
()))
return
hotestThemes
.
stream
().
filter
(
o
->
topicId
.
equals
(
o
.
getTopicId
()))
.
map
(
ThemeAnalysDO:
:
getThemeId
)
.
map
(
ThemeAnalysDO:
:
getThemeId
)
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/RecommendService.java
View file @
27fdb913
...
@@ -42,16 +42,16 @@ public class RecommendService {
...
@@ -42,16 +42,16 @@ public class RecommendService {
@Autowired
@Autowired
private
VisitSummaryService
visitSummaryService
;
private
VisitSummaryService
visitSummaryService
;
//最新
//
最新
private
List
<
ThemeAnalysDO
>
recentThemeList
=
new
ArrayList
<>();
private
List
<
ThemeAnalysDO
>
recentThemeList
=
new
ArrayList
<>();
//推荐
//
推荐
private
Map
<
String
,
List
<
String
>>
recommondList
=
new
HashMap
<>();
private
Map
<
String
,
List
<
String
>>
recommondList
=
new
HashMap
<>();
//
//
用户已经看过的
private
Map
<
String
,
Set
<
String
>>
returnedIdsMap
=
new
HashMap
<>();
private
Map
<
String
,
Set
<
String
>>
returnedIdsMap
=
new
HashMap
<>();
public
List
<
String
>
getRecommendThemes
(
String
lastId
,
Integer
pageSize
,
String
userId
)
{
public
List
<
String
>
getRecommendThemes
(
String
lastId
,
Integer
pageSize
,
String
userId
)
{
//最热话题,剔除当前用户的主题
//最热话题,剔除当前用户的主题
List
<
String
>
hotThemeIds
=
rankService
.
get
RankThemeList
().
stream
()
List
<
String
>
hotThemeIds
=
rankService
.
get
HotestThemes
().
stream
()
.
filter
(
o
->
!
userId
.
equals
(
o
.
getAuthorId
()))
.
filter
(
o
->
!
userId
.
equals
(
o
.
getAuthorId
()))
.
map
(
ThemeAnalysDO:
:
getThemeId
)
.
map
(
ThemeAnalysDO:
:
getThemeId
)
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
...
@@ -65,7 +65,7 @@ public class RecommendService {
...
@@ -65,7 +65,7 @@ public class RecommendService {
//推荐话题
//推荐话题
List
<
String
>
recThemeIds
=
getPythonRecommendList
(
userId
);
List
<
String
>
recThemeIds
=
getPythonRecommendList
(
userId
);
//
混合
//
混合 如果重新搜索,则刷新返回id
Set
<
String
>
returnedIds
=
(
StringUtils
.
isEmpty
(
lastId
))
||
!
returnedIdsMap
.
containsKey
(
userId
)
Set
<
String
>
returnedIds
=
(
StringUtils
.
isEmpty
(
lastId
))
||
!
returnedIdsMap
.
containsKey
(
userId
)
||
returnedIdsMap
.
get
(
userId
)
==
null
?
||
returnedIdsMap
.
get
(
userId
)
==
null
?
new
HashSet
<>()
:
returnedIdsMap
.
get
(
userId
);
new
HashSet
<>()
:
returnedIdsMap
.
get
(
userId
);
...
@@ -130,6 +130,7 @@ public class RecommendService {
...
@@ -130,6 +130,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
,
String
userId
)
{
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
)
{
if
(
hotThemeIds
.
size
()
<=
hotTag
&&
newThemeIds
.
size
()
<=
newTag
&&
recThemeIds
.
size
()
<=
recTag
)
{
//所有列表已循环结束,返回
//所有列表已循环结束,返回
return
;
return
;
...
...
community-service/src/main/java/com/tanpu/community/service/ThemeService.java
View file @
27fdb913
...
@@ -47,7 +47,7 @@ public class ThemeService {
...
@@ -47,7 +47,7 @@ public class ThemeService {
themeMapper
.
update
(
themeEntity
,
new
LambdaUpdateWrapper
<
ThemeEntity
>().
eq
(
ThemeEntity:
:
getThemeId
,
themeId
));
themeMapper
.
update
(
themeEntity
,
new
LambdaUpdateWrapper
<
ThemeEntity
>().
eq
(
ThemeEntity:
:
getThemeId
,
themeId
));
}
}
//n天内所有主题
//n天内
发表的
所有主题
public
List
<
ThemeEntity
>
queryRecentdays
(
Integer
days
)
{
public
List
<
ThemeEntity
>
queryRecentdays
(
Integer
days
)
{
LambdaQueryWrapper
<
ThemeEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
LambdaQueryWrapper
<
ThemeEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
())
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
())
...
...
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