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
057956f1
Commit
057956f1
authored
Sep 29, 2021
by
王亚雷
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/v2.2.7'
parents
ece385a0
a20c600c
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
187 additions
and
78 deletions
+187
-78
ThemeListReq.java
...com/tanpu/community/api/beans/req/theme/ThemeListReq.java
+2
-0
RedisKeyConstant.java
...a/com/tanpu/community/api/constants/RedisKeyConstant.java
+8
-0
CommentController.java
...ava/com/tanpu/community/controller/CommentController.java
+2
-3
HomePageController.java
...va/com/tanpu/community/controller/HomePageController.java
+16
-13
ThemeController.java
.../java/com/tanpu/community/controller/ThemeController.java
+3
-6
TopicController.java
.../java/com/tanpu/community/controller/TopicController.java
+0
-1
FeignClientForActivity.java
...anpu/community/feign/activity/FeignClientForActivity.java
+1
-1
FeignClientForFatools.java
.../tanpu/community/feign/fatools/FeignClientForFatools.java
+3
-6
CommentManager.java
...main/java/com/tanpu/community/manager/CommentManager.java
+7
-1
HomePageManager.java
...ain/java/com/tanpu/community/manager/HomePageManager.java
+23
-22
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+29
-19
RecommendService.java
...in/java/com/tanpu/community/service/RecommendService.java
+12
-5
HttpServletHelper.java
...main/java/com/tanpu/community/util/HttpServletHelper.java
+70
-0
application-test.yml
community-service/src/main/resources/application-test.yml
+11
-1
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/req/theme/ThemeListReq.java
View file @
057956f1
...
...
@@ -10,6 +10,8 @@ import javax.validation.constraints.NotNull;
@Data
public
class
ThemeListReq
{
@ApiModelProperty
(
value
=
"用户Id"
)
private
String
userId
;
@NotNull
(
message
=
"主题类型不能为空"
)
@ApiModelProperty
(
value
=
"类型,1:推荐 2:关注 3:话题-热门 4:话题-最新"
)
...
...
community-api/src/main/java/com/tanpu/community/api/constants/RedisKeyConstant.java
View file @
057956f1
...
...
@@ -2,6 +2,14 @@ package com.tanpu.community.api.constants;
public
class
RedisKeyConstant
{
public
static
final
String
ENV
=
"env"
;
// token app 小程序用
public
static
final
String
TAMP_TOKEN
=
"tampToken"
;
// H5 cookie
public
static
final
String
SESSION_COOKIE_NAME
=
"qimsession"
;
// redis token 前缀
public
static
final
String
REDIS_PREFIX_TOKEN
=
"s:sid:"
;
//点赞量
public
static
final
String
THEME_LIKE_COUNT
=
"THEME_LIKE_COUNT_"
;
//收藏量
...
...
community-service/src/main/java/com/tanpu/community/controller/CommentController.java
View file @
057956f1
...
...
@@ -42,12 +42,11 @@ public class CommentController {
}
@ApiOperation
(
"评论列表"
)
@AuthLogin
@PostMapping
(
value
=
"/queryComment"
)
@ResponseBody
public
CommonResp
<
Page
<
CommentQo
>>
queryComment
(
@Validated
@RequestBody
QueryCommentReq
req
)
{
String
u
serId
=
userHolder
.
getUserId
();
List
<
CommentQo
>
result
=
commentManager
.
queryComments
(
req
.
getThemeId
(),
u
serId
);
String
selfU
serId
=
userHolder
.
getUserId
();
List
<
CommentQo
>
result
=
commentManager
.
queryComments
(
req
.
getThemeId
(),
selfU
serId
);
return
CommonResp
.
success
(
PageUtils
.
page
(
req
.
getPage
(),
result
));
}
...
...
community-service/src/main/java/com/tanpu/community/controller/HomePageController.java
View file @
057956f1
...
...
@@ -15,14 +15,19 @@ import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNewChief;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp
;
import
com.tanpu.community.manager.HomePageManager
;
import
com.tanpu.community.manager.ThemeManager
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
com.tanpu.community.util.HttpServletHelper
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.util.List
;
...
...
@@ -41,13 +46,13 @@ public class HomePageController {
@Resource
private
UserHolder
userHolder
;
// 用户信息查询 (供圈子服务调用)
@ApiOperation
(
value
=
"个人中心 查询"
)
@GetMapping
(
value
=
"/queryUserInfoNew"
)
@AuthLogin
public
CommonResp
<
UserInfoResp
>
queryUsersListNew
(
@RequestParam
(
value
=
"userId"
,
required
=
false
)
String
userId
)
{
String
userIdMyself
=
userHolder
.
getUserId
();
return
CommonResp
.
success
(
homePageManager
.
queryUsersInfo
(
userIdMyself
,
userId
));
public
CommonResp
<
UserInfoResp
>
queryUsersListNew
(
@RequestParam
(
value
=
"userId"
)
String
userId
)
{
String
selfUserId
=
userHolder
.
getUserId
();
return
CommonResp
.
success
(
homePageManager
.
queryUsersInfo
(
selfUserId
,
userId
));
}
// 理财师客户列表查询 (供圈子服务调用)
...
...
@@ -69,10 +74,9 @@ public class HomePageController {
@PostMapping
(
value
=
"/followList"
)
@ApiOperation
(
"查询关注/粉丝列表"
)
@ResponseBody
@AuthLogin
public
CommonResp
<
Page
<
FollowQo
>>
queryFollowList
(
@RequestBody
QueryFollowReq
req
)
{
String
u
serId
=
userHolder
.
getUserId
();
return
CommonResp
.
success
(
homePageManager
.
queryFollow
(
req
,
u
serId
));
String
selfU
serId
=
userHolder
.
getUserId
();
return
CommonResp
.
success
(
homePageManager
.
queryFollow
(
req
,
selfU
serId
));
}
@PostMapping
(
value
=
"/addIdol"
)
...
...
@@ -88,10 +92,9 @@ public class HomePageController {
@PostMapping
(
value
=
"/themeList"
)
@ApiOperation
(
"用户的帖子列表"
)
@ResponseBody
@AuthLogin
public
CommonResp
<
List
<
ThemeQo
>>
likeList
(
@Validated
@RequestBody
QueryRecordThemeReq
req
)
{
String
u
serId
=
userHolder
.
getUserId
();
return
CommonResp
.
success
(
themeManager
.
queryThemesByUser
(
req
,
u
serId
));
String
selfU
serId
=
userHolder
.
getUserId
();
return
CommonResp
.
success
(
themeManager
.
queryThemesByUser
(
req
,
selfU
serId
));
}
}
community-service/src/main/java/com/tanpu/community/controller/ThemeController.java
View file @
057956f1
...
...
@@ -36,22 +36,19 @@ public class ThemeController {
return
themeManager
.
publishTheme
(
req
,
userId
);
}
@AuthLogin
@ApiOperation
(
"主题列表-推荐/关注/热门/最新"
)
@PostMapping
(
value
=
"/list"
)
@ResponseBody
public
CommonResp
<
ThemeListResp
>
selectInterestList
(
@Validated
@RequestBody
ThemeListReq
req
)
{
String
userId
=
userHolder
.
getUserId
();
ThemeListResp
result
=
themeManager
.
queryList
(
req
,
userId
);
ThemeListResp
result
=
themeManager
.
queryList
(
req
,
req
.
getUserId
());
return
CommonResp
.
success
(
result
);
}
@AuthLogin
@ApiOperation
(
"主题正文"
)
@GetMapping
(
value
=
"/detail"
)
@ResponseBody
public
CommonResp
<
ThemeQo
>
getDetail
(
@RequestParam
(
value
=
"themeId"
)
String
themeId
)
{
String
userId
=
userHolder
.
getUserId
();
public
CommonResp
<
ThemeQo
>
getDetail
(
@RequestParam
(
value
=
"themeId"
)
String
themeId
,
@RequestParam
(
value
=
"userId"
,
required
=
false
)
String
userId
)
{
return
themeManager
.
getThemeDetail
(
themeId
,
userId
);
}
...
...
community-service/src/main/java/com/tanpu/community/controller/TopicController.java
View file @
057956f1
...
...
@@ -35,7 +35,6 @@ public class TopicController {
return
CommonResp
.
success
(
topicManager
.
getAllTopicBriefInfo
(
req
));
}
@AuthLogin
@GetMapping
(
value
=
"/detailPage"
)
@ApiOperation
(
"话题详情页顶部"
)
@ResponseBody
...
...
community-service/src/main/java/com/tanpu/community/feign/activity/FeignClientForActivity.java
View file @
057956f1
...
...
@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import
java.util.List
;
@FeignClient
(
value
=
"service-jifen"
,
contextId
=
"jifen"
,
fallbackFactory
=
FeignBackClientForActivity
.
class
,
url
=
"
http://tp-jifen-svc
"
,
path
=
"/jifen"
)
@FeignClient
(
value
=
"service-jifen"
,
contextId
=
"jifen"
,
fallbackFactory
=
FeignBackClientForActivity
.
class
,
url
=
"
${tanpu.jifen.svc:http://tp-jifen-svc}
"
,
path
=
"/jifen"
)
// @FeignClient(value = "service-jifen", contextId = "jifen", fallbackFactory = FeignBackClientForActivity.class, url = "http://127.0.0.1:8202/community")
public
interface
FeignClientForActivity
{
...
...
community-service/src/main/java/com/tanpu/community/feign/fatools/FeignClientForFatools.java
View file @
057956f1
...
...
@@ -2,27 +2,24 @@ package com.tanpu.community.feign.fatools;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.community.api.beans.req.page.Page
;
import
com.tanpu.community.api.beans.req.page.Pageable
;
import
com.tanpu.community.api.beans.vo.feign.course.ShortVideoBaseInfoResp
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNewChief
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoOrg
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp
;
import
com.tanpu.community.api.beans.vo.feign.user.FileQueryResp
;
import
com.tanpu.community.api.beans.vo.feign.user.UserInfoVo
;
import
com.tanpu.community.config.FeignConfiguration
;
import
com.tanpu.community.feign.diagnose.FeignBackClientForDiagnose
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
@FeignClient
(
value
=
"fatools"
,
contextId
=
"fatools"
,
fallbackFactory
=
FeignbackForFatools
.
class
,
url
=
"
http://tp-fatools-svc
"
,
path
=
"/fatools"
)
@FeignClient
(
value
=
"fatools"
,
contextId
=
"fatools"
,
fallbackFactory
=
FeignbackForFatools
.
class
,
url
=
"
${tanpu.fatools.svc:http://tp-fatools-svc}
"
,
path
=
"/fatools"
)
//@FeignClient(value = "fatools", contextId = "fatoolsUser", fallbackFactory = FeignbackForFatools.class, path = "/fatools")
public
interface
FeignClientForFatools
{
...
...
@@ -44,7 +41,7 @@ public interface FeignClientForFatools {
// 用户信息查询 (供圈子服务调用)
@ApiOperation
(
value
=
"查询用户信息"
)
@GetMapping
(
value
=
"/queryUserInfoNew"
)
@GetMapping
(
value
=
"/queryUserInfoNew"
,
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
}
)
CommonResp
<
UserInfoResp
>
queryUserInfoNew
(
@RequestParam
(
"userId"
)
String
userId
);
@ApiOperation
(
value
=
"批量查询查询基本信息"
)
...
...
community-service/src/main/java/com/tanpu/community/manager/CommentManager.java
View file @
057956f1
package
com
.
tanpu
.
community
.
manager
;
import
com.google.common.collect.Sets
;
import
com.tanpu.biz.common.enums.community.CollectionTypeEnum
;
import
com.tanpu.biz.common.enums.community.CommentTypeEnum
;
import
com.tanpu.biz.common.enums.community.ReportTypeEnum
;
...
...
@@ -116,7 +117,12 @@ public class CommentManager {
List
<
CommentEntity
>
commentEntities
=
commentService
.
selectByThemeId
(
themeId
);
List
<
CommentQo
>
commentQos
=
ConvertUtil
.
commentEntity2Qos
(
commentEntities
);
Set
<
String
>
likeCommentList
=
collectionService
.
getSetByUser
(
userId
,
CollectionTypeEnum
.
LIKE_COMMENT
);
Set
<
String
>
likeCommentList
;
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
likeCommentList
=
collectionService
.
getSetByUser
(
userId
,
CollectionTypeEnum
.
LIKE_COMMENT
);
}
else
{
likeCommentList
=
Sets
.
newHashSetWithExpectedSize
(
0
);
}
for
(
CommentQo
commentQo
:
commentQos
)
{
// 封装用户信息
...
...
community-service/src/main/java/com/tanpu/community/manager/HomePageManager.java
View file @
057956f1
package
com
.
tanpu
.
community
.
manager
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.google.common.collect.Lists
;
import
com.tanpu.biz.common.enums.user.UserLevelEnum
;
import
com.tanpu.biz.common.enums.user.UserTypeEnum
;
import
com.tanpu.common.api.CommonResp
;
...
...
@@ -46,6 +47,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.validation.constraints.NotEmpty
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.Date
;
...
...
@@ -88,23 +90,22 @@ public class HomePageManager {
//查询 个人中心 相关信息
public
UserInfoResp
queryUsersInfo
(
String
userIdMyself
,
String
userId
)
{
CommonResp
<
UserInfoResp
>
queryUsersListNew
=
feignClientForFatools
.
queryUserInfoNew
(
StringUtils
.
isNotBlank
(
userId
)
?
userId
:
userIdMyself
);
CommonResp
<
UserInfoResp
>
queryUsersListNew
=
feignClientForFatools
.
queryUserInfoNew
(
userId
);
if
(
queryUsersListNew
.
isNotSuccess
()
||
!
ObjectUtils
.
anyNotNull
(
queryUsersListNew
.
getData
()))
throw
new
BizException
(
"内部接口调用失败"
);
UserInfoResp
userInfoNew
=
queryUsersListNew
.
getData
();
if
(
StringUtils
.
isNotBlank
(
userId
)
&&
!
StringUtils
.
equals
(
userIdMyself
,
userId
))
{
//查询别人的个人主页
userInfoNew
.
setShowFollowStatus
(
ShowFollowStatusEnum
.
NOT_FOLLOWED
.
getCode
());
if
(
StringUtils
.
isNotBlank
(
userIdMyself
))
{
if
(!
StringUtils
.
equals
(
userIdMyself
,
userId
))
{
// 查询别人的个人主页
// 关注 按钮的显示逻辑
FollowRelEntity
followRelEntity
=
followRelService
.
queryRecord
(
userId
,
userIdMyself
);
if
(
ObjectUtils
.
allNotNull
(
followRelEntity
)
&&
BizStatus
.
DeleteTag
.
tag_init
==
followRelEntity
.
getDeleteTag
())
{
userInfoNew
.
setShowFollowStatus
(
ShowFollowStatusEnum
.
FOLLOWED
.
getCode
());
// 已关注
}
else
{
userInfoNew
.
setShowFollowStatus
(
ShowFollowStatusEnum
.
NOT_FOLLOWED
.
getCode
());
// 未关注
}
if
(
userInfoNew
.
getWorkshopStatus
()
==
2
)
userInfoNew
.
setWorkshopStatus
(
1
);
//别人的主页不需要展示 工作室
}
else
{
// 查询自己的主页
userId
=
userIdMyself
;
}
}
//获取粉丝数 关注数
getFansNUmAndFollowNum
(
userInfoNew
);
...
...
@@ -257,26 +258,26 @@ public class HomePageManager {
Page
<
String
>
userIdsPage
=
QueryFollowTypeEnum
.
QUERY_FANS
.
getCode
().
equals
(
req
.
getQueryType
())
?
followRelService
.
queryFansByIdolId
(
req
.
userId
,
pageNumber
,
pageSize
)
:
followRelService
.
queryIdolsByFansId
(
req
.
userId
,
pageNumber
,
pageSize
);
List
<
FollowQo
>
followQos
=
new
ArrayList
<>();
if
(!
CollectionUtils
.
isEmpty
(
userIdsPage
.
getContent
()))
{
if
(
CollectionUtils
.
isEmpty
(
userIdsPage
.
getContent
()))
{
return
PageUtils
.
page
(
userIdsPage
,
Lists
.
newArrayListWithCapacity
(
0
));
}
List
<
UserInfoResp
>
userInfoNews
=
feignClientForFatools
.
queryUserListNew
(
userIdsPage
.
getContent
());
List
<
FollowQo
>
collect
=
userInfoNews
.
stream
().
map
(
ConvertUtil:
:
userInfoNew2FollowQo
).
collect
(
Collectors
.
toList
());
followQos
=
judgeFollowed
(
collect
,
userId
);
List
<
FollowQo
>
followQos
=
userInfoNews
.
stream
().
map
(
ConvertUtil:
:
userInfoNew2FollowQo
).
collect
(
Collectors
.
toList
());
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
judgeFollowed
(
followQos
,
userId
);
}
return
PageUtils
.
page
(
userIdsPage
,
followQos
);
}
//判断返回列表中的用户是否被当前用户关注
public
List
<
FollowQo
>
judgeFollowed
(
List
<
FollowQo
>
followQos
,
String
followerId
)
{
public
void
judgeFollowed
(
List
<
FollowQo
>
followQos
,
@NotEmpty
String
followerId
)
{
Set
<
String
>
idolSet
=
new
HashSet
<>(
followRelService
.
queryIdolsByFansId
(
followerId
));
return
followQos
.
stream
().
map
(
o
->
{
followQos
.
stream
().
peek
(
o
->
{
if
(
idolSet
.
contains
(
o
.
getUserId
()))
{
o
.
setFollowed
(
true
);
}
return
o
;
}).
collect
(
Collectors
.
toList
());
});
}
public
void
addFollowRel
(
FollowRelReq
req
,
String
followerId
)
{
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
057956f1
...
...
@@ -2,11 +2,13 @@ package com.tanpu.community.manager;
import
com.alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Sets
;
import
com.tanpu.biz.common.enums.RelTypeEnum
;
import
com.tanpu.biz.common.enums.community.CollectionTypeEnum
;
import
com.tanpu.biz.common.enums.community.ReportTypeEnum
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.api.ResultCode
;
import
com.tanpu.common.constant.ErrorCodeConstant
;
import
com.tanpu.common.enums.fund.ProductTypeEnum
;
import
com.tanpu.common.exception.BizException
;
...
...
@@ -464,7 +466,7 @@ public class ThemeManager {
* 查询主题列表:推荐/关注/热门/最新
*/
// 查询主题列表:推荐/关注/热门/最新
public
ThemeListResp
queryList
(
ThemeListReq
req
,
String
userId
)
{
public
ThemeListResp
queryList
(
ThemeListReq
req
,
String
userId
111
)
{
List
<
String
>
excludeIds
=
new
ArrayList
<>();
LocalDateTime
firstThemeTime
=
LocalDateTime
.
now
();
if
(
req
.
page
.
pageNumber
>
1
)
{
...
...
@@ -486,14 +488,14 @@ public class ThemeManager {
if
(
ThemeListTypeEnum
.
RECOMMEND
.
getCode
().
equals
(
req
.
getType
()))
{
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
List
<
String
>
visitedIds
=
visitLogService
.
queryUserRecentVisited
(
userId
);
List
<
String
>
visitedIds
=
StringUtils
.
isEmpty
(
req
.
getUserId
())
?
Lists
.
newArrayListWithCapacity
(
0
)
:
visitLogService
.
queryUserRecentVisited
(
req
.
getUserId
()
);
List
<
String
>
excludes
=
ListUtils
.
union
(
excludeIds
,
visitedIds
);
List
<
String
>
recmdIds
=
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
userId
,
excludes
,
firstThemeTime
);
List
<
String
>
recmdIds
=
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
req
.
getUserId
()
,
excludes
,
firstThemeTime
);
// 加载第一页时,为防止首页显示空列表,从推荐池中再捞出已看过帖子
if
(
req
.
page
.
pageNumber
<=
3
&&
recmdIds
.
size
()
<
pageSize
)
{
List
<
String
>
reSearchIds
=
ListUtils
.
union
(
excludeIds
,
recmdIds
);
recmdIds
.
addAll
(
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
userId
,
reSearchIds
,
firstThemeTime
));
recmdIds
.
addAll
(
recommendService
.
getRecommendThemes
(
pageStart
,
pageSize
,
req
.
getUserId
()
,
reSearchIds
,
firstThemeTime
));
}
themes
=
themeService
.
queryByThemeIds
(
recmdIds
);
...
...
@@ -502,17 +504,21 @@ public class ThemeManager {
}
else
if
(
ThemeListTypeEnum
.
FOLLOW
.
getCode
().
equals
(
req
.
getType
()))
{
if
(
StringUtils
.
isEmpty
(
req
.
getUserId
()))
{
// 未登录情况下返回空数组
themes
=
Lists
.
newArrayListWithCapacity
(
0
);
}
else
{
// 根据关注列表查询,按时间倒序
List
<
String
>
fansList
=
followRelService
.
queryIdolsByFansId
(
userId
);
List
<
String
>
fansList
=
followRelService
.
queryIdolsByFansId
(
req
.
getUserId
()
);
themes
=
themeService
.
queryByUserIdsCreateDesc
(
fansList
,
pageStart
,
pageSize
);
if
(
CollectionUtils
.
isEmpty
(
excludeIds
)
&&
!
themes
.
isEmpty
())
{
// 说明是从头开始刷,则直接把最新的lastId放到redis中,保留一个月
Long
lastId
=
themes
.
stream
().
map
(
ThemeEntity:
:
getId
).
max
(
Long:
:
compareTo
).
get
();
redisCache
.
put
(
CACHE_IDOL_THEME_LAST_ID
+
userId
,
lastId
,
60
*
60
*
24
*
7
*
4
);
redisCache
.
put
(
CACHE_IDOL_THEME_LAST_ID
+
req
.
getUserId
()
,
lastId
,
60
*
60
*
24
*
7
*
4
);
// visitLogService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW);
}
}
}
else
if
(
ThemeListTypeEnum
.
TOPIC_HOT
.
getCode
().
equals
(
req
.
getType
()))
{
// 根据话题查询热门
if
(
StringUtils
.
isEmpty
(
req
.
getTopicId
()))
{
...
...
@@ -534,7 +540,7 @@ public class ThemeManager {
}
ThemeListResp
resp
=
new
ThemeListResp
();
resp
.
themes
=
convertEntityToQo
(
themes
,
userId
);
resp
.
themes
=
convertEntityToQo
(
themes
,
req
.
getUserId
()
);
excludeIds
.
addAll
(
resp
.
themes
.
stream
().
map
(
ThemeQo:
:
getThemeId
).
collect
(
Collectors
.
toList
()));
redisCache
.
put
(
"queryThemes_"
+
req
.
ident
,
excludeIds
,
60
*
60
*
6
);
...
...
@@ -556,8 +562,9 @@ public class ThemeManager {
}
// 和用户相关信息
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
buildThemeExtraInfoByUser
(
userId
,
themeQos
);
}
return
themeQos
;
}
...
...
@@ -647,7 +654,7 @@ public class ThemeManager {
}
List
<
ThemeQo
>
themeQos
=
convertEntityToQo
(
themeEntities
,
userId
);
if
(
userId
.
equals
(
req
.
getUserId
()))
{
if
(
StringUtils
.
equals
(
userId
,
req
.
getUserId
()))
{
//如果用户是查询自己的帖子,需要实时查询用户自己的个人信息,防止数据不一致(非收藏类型)
CommonResp
<
UserInfoResp
>
userInfoNewCommonResp
=
feignClientForFatools
.
queryUserInfoNew
(
userId
);
if
(
userInfoNewCommonResp
.
isNotSuccess
())
{
...
...
@@ -684,7 +691,9 @@ public class ThemeManager {
buildThemeQoExtraInfo
(
themeQo
);
// 添加用户相关信息
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
buildThemeExtraInfoByUser
(
userId
,
themeQo
);
}
return
CommonResp
.
success
(
themeQo
);
}
...
...
@@ -905,7 +914,8 @@ public class ThemeManager {
.
content
(
Collections
.
singletonList
(
commentContent
))
.
commentId
(
commentEntity
.
getCommentId
())
.
themeType
(
ThemeTypeEnum
.
RES_COMMENT
.
getCode
())
.
follow
(
followRelService
.
checkFollow
(
userId
,
userId
))
// 回复列表不需要关注按钮
// .follow(followRelService.checkFollow(userInfo.getUserId(), userId))
.
upToNowTime
(
TimeUtils
.
calUpToNowTime
(
commentEntity
.
getCreateTime
()))
.
build
();
...
...
community-service/src/main/java/com/tanpu/community/service/RecommendService.java
View file @
057956f1
package
com
.
tanpu
.
community
.
service
;
import
com.google.common.collect.Lists
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.community.api.beans.qo.ThemeAnalysDO
;
import
com.tanpu.community.api.beans.resp.PythonResponse
;
...
...
@@ -8,6 +9,7 @@ import com.tanpu.community.util.BizUtils;
import
com.tanpu.community.util.ConvertUtil
;
import
com.tanpu.community.util.TimeUtils
;
import
lombok.extern.slf4j.Slf4j
;
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
;
...
...
@@ -72,11 +74,16 @@ public class RecommendService {
newThemeIds
=
BizUtils
.
subList
(
newThemeIds
,
0
,
pageSize
);
//推荐话题
List
<
String
>
recThemeIds
=
getPythonRecommendList
(
userId
).
stream
()
List
<
String
>
recThemeIds
;
if
(
StringUtils
.
isNotEmpty
(
userId
))
{
recThemeIds
=
getPythonRecommendList
(
userId
).
stream
()
.
filter
(
id
->
{
return
!
excludeIds
.
contains
(
id
);
}).
collect
(
Collectors
.
toList
());
recThemeIds
=
BizUtils
.
subList
(
recThemeIds
,
pageStart
,
pageSize
);
}
else
{
recThemeIds
=
Lists
.
newArrayListWithCapacity
(
0
);
}
// merge
return
mergeRecommend
(
hotThemeIds
,
newThemeIds
,
recThemeIds
);
...
...
community-service/src/main/java/com/tanpu/community/util/HttpServletHelper.java
0 → 100644
View file @
057956f1
package
com
.
tanpu
.
community
.
util
;
import
com.tanpu.common.redis.RedisHelper
;
import
com.tanpu.community.api.constants.RedisKeyConstant
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpCookie
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.annotation.Resource
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Arrays
;
import
java.util.Optional
;
/**
* @Description TODO
* @Author wangyalei
* @Date 2021/9/23 下午8:31
**/
@Slf4j
@Service
public
class
HttpServletHelper
{
@Resource
private
RedisHelper
redisHelper
;
public
String
getCurrentUserId
()
{
String
userId
=
null
;
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
currentRequestAttributes
()).
getRequest
();
String
clientEnv
=
request
.
getHeader
(
RedisKeyConstant
.
ENV
);
if
(
isAndroid
(
clientEnv
)
||
isIOS
(
clientEnv
)
||
isPc
(
clientEnv
)
||
isMiniProgram
(
clientEnv
))
{
// android,ios,pc,小程序用token
String
token
=
request
.
getHeader
(
RedisKeyConstant
.
TAMP_TOKEN
);
// redis获取的value,都带有 "",这里去掉
userId
=
StringUtils
.
remove
(
redisHelper
.
get
(
RedisKeyConstant
.
REDIS_PREFIX_TOKEN
+
token
),
"\""
);
}
else
{
// 用cookie
Cookie
[]
cookies
=
request
.
getCookies
();
if
(
cookies
!=
null
)
{
Optional
<
Cookie
>
first
=
Arrays
.
stream
(
request
.
getCookies
())
.
filter
(
cookie
->
StringUtils
.
equalsIgnoreCase
(
RedisKeyConstant
.
SESSION_COOKIE_NAME
,
cookie
.
getName
()))
.
findFirst
();
if
(
first
.
isPresent
())
{
userId
=
first
.
get
().
getValue
();
}
}
}
log
.
debug
(
"当前登录用户Id: {}"
,
userId
);
return
userId
;
}
public
static
boolean
isAndroid
(
String
clientEnv
)
{
return
"android"
.
equalsIgnoreCase
(
clientEnv
);
}
public
static
boolean
isIOS
(
String
clientEnv
)
{
return
"ios"
.
equalsIgnoreCase
(
clientEnv
);
}
public
static
boolean
isPc
(
String
clientEnv
)
{
return
"pc"
.
equalsIgnoreCase
(
clientEnv
);
}
public
static
boolean
isMiniProgram
(
String
clientEnv
)
{
return
"xcx"
.
equalsIgnoreCase
(
clientEnv
);
}
}
community-service/src/main/resources/application-test.yml
View file @
057956f1
...
...
@@ -97,3 +97,13 @@ recommend:
python
:
enable
:
false
url
:
http://172.168.0.164:9000/api/get_recommend?user_id=2431614397151511
tmpfile
:
dir
:
/data/tmp
tanpu
:
fatools
:
svc
:
https://testtamper.tanpuyun.com
jifen
:
svc
:
https://testtamper.tanpuyun.com
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