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
4348dcca
Commit
4348dcca
authored
Jul 30, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
排序落库 fix
parent
d326f0fe
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
59 additions
and
31 deletions
+59
-31
TopicRankQo.java
...in/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
+1
-1
HomePageManager.java
...ain/java/com/tanpu/community/manager/HomePageManager.java
+2
-2
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+26
-10
CollectionService.java
...n/java/com/tanpu/community/service/CollectionService.java
+15
-8
FollowRelService.java
...in/java/com/tanpu/community/service/FollowRelService.java
+1
-1
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+1
-1
RecommendService.java
...in/java/com/tanpu/community/service/RecommendService.java
+1
-2
ThemeService.java
...c/main/java/com/tanpu/community/service/ThemeService.java
+12
-6
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
View file @
4348dcca
...
...
@@ -46,7 +46,7 @@ public class TopicRankQo {
*
* @return
*/
public
Double
get
Score
()
{
public
Double
get
Rank
()
{
double
g
=
0.3
;
//时间系数
//顶置话题
if
(
isTop
>
0
)
{
...
...
community-service/src/main/java/com/tanpu/community/manager/HomePageManager.java
View file @
4348dcca
...
...
@@ -175,7 +175,7 @@ public class HomePageManager {
public
Page
<
FollowQo
>
queryFollow
(
QueryFollowReq
req
,
String
userId
)
{
//TODO 数据库分页
List
<
String
>
userIds
=
QueryFollowTypeEnum
.
QUERY_FANS
.
getCode
().
equals
(
req
.
getQueryType
())
?
followRelService
.
queryFansByIdolId
(
req
.
getUserId
())
:
followRelService
.
query
Fan
sByFollowerId
(
req
.
getUserId
());
followRelService
.
queryFansByIdolId
(
req
.
getUserId
())
:
followRelService
.
query
Idol
sByFollowerId
(
req
.
getUserId
());
List
<
FollowQo
>
followQos
=
new
ArrayList
<>();
if
(!
CollectionUtils
.
isEmpty
(
userIds
))
{
List
<
UserInfoResp
>
userInfoNews
=
feignClientForFatools
.
queryUserListNew
(
userIds
);
...
...
@@ -189,7 +189,7 @@ public class HomePageManager {
//判断返回列表中的用户是否被当前用户关注
public
List
<
FollowQo
>
judgeFollowed
(
List
<
FollowQo
>
followQos
,
String
followerId
)
{
Set
<
String
>
idolSet
=
new
HashSet
<>(
followRelService
.
query
Fan
sByFollowerId
(
followerId
));
Set
<
String
>
idolSet
=
new
HashSet
<>(
followRelService
.
query
Idol
sByFollowerId
(
followerId
));
return
followQos
.
stream
().
map
(
o
->
{
if
(
idolSet
.
contains
(
o
.
getUserId
()))
{
o
.
setFollowed
(
true
);
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
4348dcca
...
...
@@ -258,7 +258,7 @@ public class ThemeManager {
visitLogService
.
addPageView
(
userId
,
userId
,
VisitTypeEnum
.
FOLLOW_THEME_VIEW
);
}
// 根据关注列表查询,按时间倒序
List
<
String
>
fansList
=
followRelService
.
query
Fan
sByFollowerId
(
userId
);
List
<
String
>
fansList
=
followRelService
.
query
Idol
sByFollowerId
(
userId
);
themes
=
themeService
.
queryByUserIdsCreateDesc
(
fansList
,
pageStart
,
pageSize
);
}
else
if
(
ThemeListTypeEnum
.
TOPIC_HOT
.
getCode
().
equals
(
req
.
getType
()))
{
...
...
@@ -301,9 +301,10 @@ public class ThemeManager {
for
(
ThemeQo
themeQO
:
themeQos
)
{
// 通用信息
buildThemeQoExtraInfo
(
themeQO
);
// 和用户相关信息
buildThemeExtraInfoByUser
(
userId
,
themeQO
);
}
// 和用户相关信息
buildThemeExtraInfoByUser
(
userId
,
themeQos
);
return
themeQos
;
}
...
...
@@ -324,23 +325,38 @@ public class ThemeManager {
themeQo
.
setForwardCount
(
forwardCount
);
}
// 组装和当前用户相关信息
// 组装和当前用户相关信息
(单个查询)
private
void
buildThemeExtraInfoByUser
(
String
userId
,
ThemeQo
themeQo
)
{
//todo 批量查询 IN
String
themeId
=
themeQo
.
getThemeId
();
// 是否关注作者
themeQo
.
setFollow
(
followRelService
.
checkFollow
(
themeQo
.
getAuthorId
(),
userId
));
// 是否点赞
CollectionEntity
likeEntity
=
collectionService
.
get
NotDeleteTargetCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
CollectionEntity
likeEntity
=
collectionService
.
get
Target
(
themeId
,
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
themeQo
.
setHasLiked
(
likeEntity
!=
null
);
// 是否转发
Integer
forwardCountByUser
=
themeService
.
getForwardCountByUser
(
themeId
,
userId
);
themeQo
.
setHasForward
(
forwardCountByUser
>
0
);
themeQo
.
setHasForward
(
themeService
.
judgeForwardByUser
(
themeId
,
userId
));
// 是否收藏
CollectionEntity
collectionEntity
=
collectionService
.
get
NotDeleteTargetCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
COLLECT_THEME
);
CollectionEntity
collectionEntity
=
collectionService
.
get
Target
(
themeId
,
userId
,
CollectionTypeEnum
.
COLLECT_THEME
);
themeQo
.
setHasCollect
(
collectionEntity
!=
null
);
}
// 组装和当前用户相关信息(批量查询)
private
void
buildThemeExtraInfoByUser
(
String
userId
,
List
<
ThemeQo
>
themeQos
)
{
// 批量查询
List
<
String
>
themeIds
=
themeQos
.
stream
().
map
(
ThemeQo:
:
getThemeId
).
collect
(
Collectors
.
toList
());
Set
<
String
>
idolSet
=
new
HashSet
<>(
followRelService
.
queryIdolsByFollowerId
(
userId
));
Set
<
String
>
likeSet
=
collectionService
.
getTargets
(
themeIds
,
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
Set
<
String
>
bookSet
=
collectionService
.
getTargets
(
themeIds
,
userId
,
CollectionTypeEnum
.
COLLECT_THEME
);
Set
<
String
>
forwardUsers
=
themeService
.
getForwardUsers
(
themeIds
);
// 从set中查找
for
(
ThemeQo
themeQo
:
themeQos
)
{
themeQo
.
setFollow
(
idolSet
.
contains
(
themeQo
.
getAuthorId
()));
themeQo
.
setHasLiked
(
likeSet
.
contains
(
themeQo
.
getThemeId
()));
themeQo
.
setHasCollect
(
bookSet
.
contains
(
themeQo
.
getThemeId
()));
themeQo
.
setHasForward
(
forwardUsers
.
contains
(
userId
));
}
}
// 返回用户发布、回复、点赞、收藏的主题列表
public
List
<
ThemeQo
>
queryThemesByUser
(
QueryRecordThemeReq
req
,
String
userId
)
{
...
...
@@ -430,7 +446,7 @@ public class ThemeManager {
//关注用户是否有更新
public
Integer
getFollowUpdateCount
(
String
userId
)
{
LocalDateTime
lastViewTime
=
visitLogService
.
queryLatestViewFollow
(
userId
);
List
<
String
>
fansList
=
followRelService
.
query
Fan
sByFollowerId
(
userId
);
List
<
String
>
fansList
=
followRelService
.
query
Idol
sByFollowerId
(
userId
);
return
themeService
.
queryCountFromLastTime
(
fansList
,
lastViewTime
);
}
...
...
community-service/src/main/java/com/tanpu/community/service/CollectionService.java
View file @
4348dcca
...
...
@@ -28,7 +28,11 @@ public class CollectionService {
@Transactional
public
void
saveOrUpdate
(
String
themeId
,
String
userId
,
CollectionTypeEnum
type
)
{
// 判断记录是否存在,无论是否删除
CollectionEntity
queryCollection
=
getTargetCollection
(
themeId
,
userId
,
type
);
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
.
eq
(
CollectionEntity:
:
getTargetId
,
themeId
);
CollectionEntity
queryCollection
=
collectionMapper
.
selectOne
(
queryWrapper
);
if
(
queryCollection
!=
null
)
{
queryCollection
.
setDeleteTag
(
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
queryCollection
.
setCollectionTime
(
LocalDateTime
.
now
());
...
...
@@ -47,7 +51,7 @@ public class CollectionService {
//根据用户、主题、类型查询未删除对象
public
CollectionEntity
get
NotDeleteTargetCollection
(
String
targetId
,
String
userId
,
CollectionTypeEnum
type
)
{
public
CollectionEntity
get
Target
(
String
targetId
,
String
userId
,
CollectionTypeEnum
type
)
{
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
...
...
@@ -56,15 +60,18 @@ public class CollectionService {
return
collectionMapper
.
selectOne
(
queryWrapper
);
}
//根据用户、主题、类型查询
记录,包括已
删除对象
public
CollectionEntity
getTargetCollection
(
String
themeId
,
String
userId
,
CollectionTypeEnum
type
)
{
//根据用户、主题、类型查询
未
删除对象
public
Set
<
String
>
getTargets
(
List
<
String
>
targetIds
,
String
userId
,
CollectionTypeEnum
type
)
{
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
.
eq
(
CollectionEntity:
:
getTargetId
,
themeId
);
return
collectionMapper
.
selectOne
(
queryWrapper
);
.
in
(
CollectionEntity:
:
getTargetId
,
targetIds
)
.
eq
(
CollectionEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
return
collectionMapper
.
selectList
(
queryWrapper
).
stream
().
map
(
CollectionEntity:
:
getTargetId
)
.
collect
(
Collectors
.
toSet
());
}
// 根据用户id和行为type获取target_id列表
public
Set
<
String
>
getSetByUser
(
String
userId
,
CollectionTypeEnum
type
)
{
return
collectionMapper
.
selectList
(
new
LambdaQueryWrapper
<
CollectionEntity
>()
...
...
@@ -95,7 +102,7 @@ public class CollectionService {
// 统计多个对象(主题、评论)的数量(点赞、收藏)
public
Map
<
String
,
Integer
>
getCountMapByType
(
List
<
String
>
targetIds
,
CollectionTypeEnum
type
)
{
if
(
CollectionUtils
.
isEmpty
(
targetIds
)){
if
(
CollectionUtils
.
isEmpty
(
targetIds
))
{
return
new
HashMap
<>();
}
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>().
eq
(
CollectionEntity:
:
getCollectionType
,
1
)
...
...
@@ -116,7 +123,7 @@ public class CollectionService {
//逻辑删除,修改delete_tag
@Transactional
public
void
delete
(
String
themeId
,
String
userId
,
CollectionTypeEnum
type
)
{
CollectionEntity
queryCollection
=
get
NotDeleteTargetCollection
(
themeId
,
userId
,
type
);
CollectionEntity
queryCollection
=
get
Target
(
themeId
,
userId
,
type
);
if
(
queryCollection
!=
null
)
{
queryCollection
.
setDeleteTag
(
DeleteTagEnum
.
DELETED
.
getCode
());
queryCollection
.
setUncollectionTime
(
LocalDateTime
.
now
());
...
...
community-service/src/main/java/com/tanpu/community/service/FollowRelService.java
View file @
4348dcca
...
...
@@ -21,7 +21,7 @@ public class FollowRelService {
@Resource
private
FollowRelMapper
followRelMapper
;
public
List
<
String
>
query
Fan
sByFollowerId
(
String
followerId
)
{
public
List
<
String
>
query
Idol
sByFollowerId
(
String
followerId
)
{
return
followRelMapper
.
selectList
(
new
LambdaQueryWrapper
<
FollowRelEntity
>()
.
eq
(
FollowRelEntity:
:
getFansId
,
followerId
)
.
eq
(
FollowRelEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
()))
...
...
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
4348dcca
...
...
@@ -146,7 +146,7 @@ public class RankService {
topic
.
setFormatViewCount
(
BizUtils
.
formatCountNumber
(
topic
.
getViewCount
()));
topic
.
setFormatDisscussCount
(
BizUtils
.
formatCountNumber
(
topic
.
getDisscussCount
()));
}
Map
<
TopicRankQo
,
Double
>
map
=
topicRankQos
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
TopicRankQo:
:
get
Score
));
Map
<
TopicRankQo
,
Double
>
map
=
topicRankQos
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
TopicRankQo:
:
get
Rank
));
List
<
TopicRankQo
>
rankList
=
map
.
entrySet
().
stream
()
.
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
()))
.
map
(
Map
.
Entry
::
getKey
)
...
...
community-service/src/main/java/com/tanpu/community/service/RecommendService.java
View file @
4348dcca
...
...
@@ -7,8 +7,6 @@ import com.tanpu.community.dao.entity.community.ThemeEntity;
import
com.tanpu.community.util.BizUtils
;
import
com.tanpu.community.util.ConvertUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.ListUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
@@ -180,6 +178,7 @@ public class RecommendService {
if
(
hotStart
>=
hotIds
.
size
()
&&
newestStart
>=
newestIds
.
size
()
&&
recmdStart
>=
recmdIds
.
size
())
{
break
;
}
retList
.
addAll
(
BizUtils
.
subList
(
hotIds
,
hotStart
,
hotStart
+
6
));
retList
.
addAll
(
BizUtils
.
subList
(
newestIds
,
newestStart
,
newestStart
+
3
));
retList
.
addAll
(
BizUtils
.
subList
(
recmdIds
,
recmdStart
,
recmdStart
+
1
));
...
...
community-service/src/main/java/com/tanpu/community/service/ThemeService.java
View file @
4348dcca
...
...
@@ -19,10 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Service
...
...
@@ -256,13 +253,22 @@ public class ThemeService {
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
));
}
public
Integer
getForwardCount
ByUser
(
String
themeId
,
String
userId
)
{
public
boolean
judgeForward
ByUser
(
String
themeId
,
String
userId
)
{
return
themeMapper
.
selectCount
(
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
eq
(
ThemeEntity:
:
getFormerThemeId
,
themeId
)
.
eq
(
ThemeEntity:
:
getAuthorId
,
userId
)
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
));
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
))>
0
;
}
public
Set
<
String
>
getForwardUsers
(
List
<
String
>
themeIds
)
{
return
themeMapper
.
selectList
(
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
in
(
ThemeEntity:
:
getFormerThemeId
,
themeIds
)
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
))
.
stream
().
map
(
ThemeEntity:
:
getAuthorId
).
collect
(
Collectors
.
toSet
());
}
@Transactional
public
void
deleteById
(
String
themeId
,
String
userId
)
{
ThemeEntity
themeEntity
=
themeMapper
.
selectOne
(
new
LambdaQueryWrapper
<
ThemeEntity
>()
...
...
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