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
44b86aed
Commit
44b86aed
authored
Aug 03, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
帖子列表分页功能 fix
parent
6a50f127
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
8 deletions
+44
-8
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+5
-5
CollectionService.java
...n/java/com/tanpu/community/service/CollectionService.java
+39
-3
No files found.
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
44b86aed
...
@@ -377,12 +377,12 @@ public class ThemeManager {
...
@@ -377,12 +377,12 @@ public class ThemeManager {
// 是否关注作者
// 是否关注作者
themeQo
.
setFollow
(
followRelService
.
checkFollow
(
themeQo
.
getAuthorId
(),
userId
));
themeQo
.
setFollow
(
followRelService
.
checkFollow
(
themeQo
.
getAuthorId
(),
userId
));
// 是否点赞
// 是否点赞
CollectionEntity
likeEntity
=
collectionService
.
getTarget
(
themeId
,
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
CollectionEntity
likeEntity
=
collectionService
.
queryCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
themeQo
.
setHasLiked
(
likeEntity
!=
null
);
themeQo
.
setHasLiked
(
likeEntity
!=
null
);
// 是否转发
// 是否转发
themeQo
.
setHasForward
(
themeService
.
judgeForwardByUser
(
themeId
,
userId
));
themeQo
.
setHasForward
(
themeService
.
judgeForwardByUser
(
themeId
,
userId
));
// 是否收藏
// 是否收藏
CollectionEntity
collectionEntity
=
collectionService
.
getTarget
(
themeId
,
userId
,
CollectionTypeEnum
.
COLLECT_THEME
);
CollectionEntity
collectionEntity
=
collectionService
.
queryCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
COLLECT_THEME
);
themeQo
.
setHasCollect
(
collectionEntity
!=
null
);
themeQo
.
setHasCollect
(
collectionEntity
!=
null
);
}
}
...
@@ -421,13 +421,13 @@ public class ThemeManager {
...
@@ -421,13 +421,13 @@ public class ThemeManager {
List
<
ThemeQo
>
commentThemeList
=
getCommentThemeQos
(
req
,
userId
);
List
<
ThemeQo
>
commentThemeList
=
getCommentThemeQos
(
req
,
userId
);
return
commentThemeList
;
return
commentThemeList
;
case
3
:
//点赞
case
3
:
//点赞
List
<
String
>
likeThemeIds
=
collectionService
.
getListByUser
(
req
.
getUserId
(),
CollectionTypeEnum
.
LIKE_THEME
);
List
<
String
>
likeThemeIds
=
collectionService
.
getListByUser
(
req
.
getUserId
(),
CollectionTypeEnum
.
LIKE_THEME
,
req
.
getLastId
(),
req
.
getPageSize
()
);
themeEntities
=
themeService
.
queryByThemeIds
(
likeThemeIds
,
req
.
getLastId
(),
req
.
getPageSize
()
);
themeEntities
=
themeService
.
queryByThemeIds
(
likeThemeIds
);
themeEntities
=
RankUtils
.
sortThemeEntityByIds
(
themeEntities
,
likeThemeIds
);
themeEntities
=
RankUtils
.
sortThemeEntityByIds
(
themeEntities
,
likeThemeIds
);
break
;
break
;
case
4
:
//收藏
case
4
:
//收藏
List
<
String
>
collectThemeIds
=
collectionService
.
getListByUser
(
req
.
getUserId
(),
CollectionTypeEnum
.
COLLECT_THEME
);
List
<
String
>
collectThemeIds
=
collectionService
.
getListByUser
(
req
.
getUserId
(),
CollectionTypeEnum
.
COLLECT_THEME
,
req
.
getLastId
(),
req
.
getPageSize
()
);
themeEntities
=
themeService
.
queryByThemeIds
(
collectThemeIds
,
req
.
getLastId
(),
req
.
getPageSize
());
themeEntities
=
themeService
.
queryByThemeIds
(
collectThemeIds
,
req
.
getLastId
(),
req
.
getPageSize
());
themeEntities
=
RankUtils
.
sortThemeEntityByIds
(
themeEntities
,
collectThemeIds
);
themeEntities
=
RankUtils
.
sortThemeEntityByIds
(
themeEntities
,
collectThemeIds
);
break
;
break
;
...
...
community-service/src/main/java/com/tanpu/community/service/CollectionService.java
View file @
44b86aed
...
@@ -7,12 +7,18 @@ import com.tanpu.community.dao.entity.community.CollectionEntity;
...
@@ -7,12 +7,18 @@ import com.tanpu.community.dao.entity.community.CollectionEntity;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
com.tanpu.community.dao.mapper.community.CollectionMapper
;
import
com.tanpu.community.dao.mapper.community.CollectionMapper
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Service
@Service
...
@@ -48,7 +54,7 @@ public class CollectionService {
...
@@ -48,7 +54,7 @@ public class CollectionService {
//根据用户、主题、类型查询未删除对象
//根据用户、主题、类型查询未删除对象
public
CollectionEntity
getTarget
(
String
targetId
,
String
userId
,
CollectionTypeEnum
type
)
{
public
CollectionEntity
queryCollection
(
String
targetId
,
String
userId
,
CollectionTypeEnum
type
)
{
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>()
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
...
@@ -57,6 +63,15 @@ public class CollectionService {
...
@@ -57,6 +63,15 @@ public class CollectionService {
return
collectionMapper
.
selectOne
(
queryWrapper
);
return
collectionMapper
.
selectOne
(
queryWrapper
);
}
}
//根据用户、主题、类型查询未删除对象
public
CollectionEntity
queryIncludeDelete
(
String
targetId
,
String
userId
,
CollectionTypeEnum
type
)
{
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
.
eq
(
CollectionEntity:
:
getTargetId
,
targetId
);
return
collectionMapper
.
selectOne
(
queryWrapper
);
}
//根据用户、主题、类型查询未删除对象
//根据用户、主题、类型查询未删除对象
public
Set
<
String
>
getTargets
(
List
<
String
>
targetIds
,
String
userId
,
CollectionTypeEnum
type
)
{
public
Set
<
String
>
getTargets
(
List
<
String
>
targetIds
,
String
userId
,
CollectionTypeEnum
type
)
{
if
(
CollectionUtils
.
isEmpty
(
targetIds
)){
if
(
CollectionUtils
.
isEmpty
(
targetIds
)){
...
@@ -91,6 +106,27 @@ public class CollectionService {
...
@@ -91,6 +106,27 @@ public class CollectionService {
.
stream
().
map
(
CollectionEntity:
:
getTargetId
).
collect
(
Collectors
.
toList
());
.
stream
().
map
(
CollectionEntity:
:
getTargetId
).
collect
(
Collectors
.
toList
());
}
}
// 根据用户id和行为type获取target_id列表
public
List
<
String
>
getListByUser
(
String
userId
,
CollectionTypeEnum
type
,
String
lastId
,
Integer
pageSize
)
{
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
())
.
orderByDesc
(
CollectionEntity:
:
getCollectionTime
);
if
(
StringUtils
.
isNotEmpty
(
lastId
))
{
CollectionEntity
target
=
queryIncludeDelete
(
lastId
,
userId
,
type
);
if
(
target
==
null
)
return
Collections
.
emptyList
();
queryWrapper
.
lt
(
CollectionEntity:
:
getCollectionType
,
target
.
getCollectionTime
());
}
if
(
pageSize
!=
null
)
{
queryWrapper
.
last
(
"limit "
+
pageSize
);
}
return
collectionMapper
.
selectList
(
queryWrapper
)
.
stream
().
map
(
CollectionEntity:
:
getTargetId
).
collect
(
Collectors
.
toList
());
}
// 统计单个对象(主题、评论)的数量(点赞、收藏)
// 统计单个对象(主题、评论)的数量(点赞、收藏)
public
Integer
getCountByTypeAndId
(
String
targetId
,
CollectionTypeEnum
type
)
{
public
Integer
getCountByTypeAndId
(
String
targetId
,
CollectionTypeEnum
type
)
{
...
@@ -123,7 +159,7 @@ public class CollectionService {
...
@@ -123,7 +159,7 @@ public class CollectionService {
//逻辑删除,修改delete_tag
//逻辑删除,修改delete_tag
@Transactional
@Transactional
public
void
delete
(
String
themeId
,
String
userId
,
CollectionTypeEnum
type
)
{
public
void
delete
(
String
themeId
,
String
userId
,
CollectionTypeEnum
type
)
{
CollectionEntity
queryCollection
=
getTarget
(
themeId
,
userId
,
type
);
CollectionEntity
queryCollection
=
queryCollection
(
themeId
,
userId
,
type
);
if
(
queryCollection
!=
null
)
{
if
(
queryCollection
!=
null
)
{
queryCollection
.
setDeleteTag
(
DeleteTagEnum
.
DELETED
.
getCode
());
queryCollection
.
setDeleteTag
(
DeleteTagEnum
.
DELETED
.
getCode
());
queryCollection
.
setUncollectionTime
(
LocalDateTime
.
now
());
queryCollection
.
setUncollectionTime
(
LocalDateTime
.
now
());
...
...
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