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
8100aa13
Commit
8100aa13
authored
Jul 23, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
theme添加字段discussContent
parent
4351eb3f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
130 deletions
+53
-130
ThemeController.java
.../java/com/tanpu/community/controller/ThemeController.java
+1
-36
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+52
-94
HomePageService.java
...ain/java/com/tanpu/community/service/HomePageService.java
+0
-0
No files found.
community-service/src/main/java/com/tanpu/community/controller/ThemeController.java
View file @
8100aa13
...
@@ -4,16 +4,13 @@ package com.tanpu.community.controller;
...
@@ -4,16 +4,13 @@ package com.tanpu.community.controller;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.auth.AuthLogin
;
import
com.tanpu.common.auth.AuthLogin
;
import
com.tanpu.common.auth.UserHolder
;
import
com.tanpu.common.auth.UserHolder
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
import
com.tanpu.community.api.beans.req.theme.*
;
import
com.tanpu.community.api.beans.req.theme.*
;
import
com.tanpu.community.api.beans.resp.CreateThemeResp
;
import
com.tanpu.community.api.beans.resp.CreateThemeResp
;
import
com.tanpu.community.cache.RedisCache
;
import
com.tanpu.community.cache.RedisCache
;
import
com.tanpu.community.manager.ThemeManager
;
import
com.tanpu.community.manager.ThemeManager
;
import
com.tanpu.community.service.RecommendService
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -33,9 +30,6 @@ public class ThemeController {
...
@@ -33,9 +30,6 @@ public class ThemeController {
@Autowired
@Autowired
private
RedisCache
redisCache
;
private
RedisCache
redisCache
;
@Autowired
private
RecommendService
recommendService
;
@AuthLogin
@AuthLogin
@ApiOperation
(
"发表主题"
)
@ApiOperation
(
"发表主题"
)
@PostMapping
(
value
=
"/publish"
)
@PostMapping
(
value
=
"/publish"
)
...
@@ -51,9 +45,6 @@ public class ThemeController {
...
@@ -51,9 +45,6 @@ public class ThemeController {
@ResponseBody
@ResponseBody
public
CommonResp
<
List
<
ThemeQo
>>
selectInterestList
(
@Validated
@RequestBody
ThemeListReq
req
)
{
public
CommonResp
<
List
<
ThemeQo
>>
selectInterestList
(
@Validated
@RequestBody
ThemeListReq
req
)
{
String
userId
=
userHolder
.
getUserId
();
String
userId
=
userHolder
.
getUserId
();
if
(
StringUtils
.
isEmpty
(
userId
)){
throw
new
BizException
(
"用户为空"
);
}
List
<
ThemeQo
>
result
=
themeManager
.
queryThemes
(
req
,
userId
);
List
<
ThemeQo
>
result
=
themeManager
.
queryThemes
(
req
,
userId
);
return
CommonResp
.
success
(
result
);
return
CommonResp
.
success
(
result
);
}
}
...
@@ -64,7 +55,7 @@ public class ThemeController {
...
@@ -64,7 +55,7 @@ public class ThemeController {
@ResponseBody
@ResponseBody
public
CommonResp
<
ThemeQo
>
getThemeMainText
(
@RequestParam
String
themeId
)
{
public
CommonResp
<
ThemeQo
>
getThemeMainText
(
@RequestParam
String
themeId
)
{
String
userId
=
userHolder
.
getUserId
();
String
userId
=
userHolder
.
getUserId
();
return
CommonResp
.
success
(
themeManager
.
getDetail
(
themeId
,
userId
));
return
CommonResp
.
success
(
themeManager
.
get
Theme
Detail
(
themeId
,
userId
));
}
}
@AuthLogin
@AuthLogin
...
@@ -116,23 +107,6 @@ public class ThemeController {
...
@@ -116,23 +107,6 @@ public class ThemeController {
return
CommonResp
.
success
();
return
CommonResp
.
success
();
}
}
@AuthLogin
@ApiOperation
(
"分享主题"
)
@GetMapping
(
value
=
"/share"
)
@ResponseBody
public
CommonResp
<
Void
>
shareTheme
(
String
themeId
)
{
return
CommonResp
.
failed
(
"功能暂未开放"
);
}
@AuthLogin
@ApiOperation
(
"屏蔽"
)
@GetMapping
(
value
=
"/block"
)
@ResponseBody
public
CommonResp
concealTheme
(
String
themeId
)
{
String
userId
=
userHolder
.
getUserId
();
return
CommonResp
.
success
();
}
@AuthLogin
@AuthLogin
@ApiOperation
(
"关注主题更新数量"
)
@ApiOperation
(
"关注主题更新数量"
)
@GetMapping
(
value
=
"/updateCount"
)
@GetMapping
(
value
=
"/updateCount"
)
...
@@ -142,13 +116,4 @@ public class ThemeController {
...
@@ -142,13 +116,4 @@ public class ThemeController {
return
CommonResp
.
success
(
themeManager
.
getFollowUpdateCount
(
userId
));
return
CommonResp
.
success
(
themeManager
.
getFollowUpdateCount
(
userId
));
}
}
@AuthLogin
@GetMapping
(
value
=
"/test"
)
@ResponseBody
public
CommonResp
<
Integer
>
test
()
{
String
userId
=
userHolder
.
getUserId
();
System
.
out
.
println
(
recommendService
.
getRecommendThemes
(
""
,
20
,
userId
));
return
CommonResp
.
success
();
}
}
}
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
8100aa13
...
@@ -108,7 +108,7 @@ public class ThemeManager {
...
@@ -108,7 +108,7 @@ public class ThemeManager {
/**
/**
* 发表主题(
可
修改)
* 发表主题(修改)
*/
*/
@Transactional
@Transactional
public
CreateThemeResp
publishTheme
(
CreateThemeReq
req
,
String
userId
)
{
public
CreateThemeResp
publishTheme
(
CreateThemeReq
req
,
String
userId
)
{
...
@@ -211,12 +211,54 @@ public class ThemeManager {
...
@@ -211,12 +211,54 @@ public class ThemeManager {
return
convertEntityToQo
(
themeEntities
,
userId
);
return
convertEntityToQo
(
themeEntities
,
userId
);
}
}
public
List
<
ThemeQo
>
searchThemes
(
ThemeSearchReq
req
,
String
userId
)
{
//主题Entity转QO
private
List
<
ThemeQo
>
convertEntityToQo
(
List
<
ThemeEntity
>
themeEntities
,
String
userId
)
{
//Entity转Qo
List
<
ThemeQo
>
themeQos
=
ConvertUtil
.
themeEntitiesToDTOs
(
themeEntities
);
//批量查询附件detail
batchFeignCallService
.
getAttachDetailByBatch
(
themeQos
);
//其他信息
for
(
ThemeQo
themeQO
:
themeQos
)
{
buildThemeQoExtraInfo
(
themeQO
);
buildThemeExtraInfoByUser
(
userId
,
themeQO
);
}
List
<
ThemeEntity
>
themeEntities
=
themeService
.
search
(
req
.
getKeyword
(),
req
.
getLastId
(),
req
.
getPageSize
());
return
themeQos
;
return
convertEntityToQo
(
themeEntities
,
userId
);
}
//转发对象、点赞、收藏、转发数
private
void
buildThemeQoExtraInfo
(
ThemeQo
themeQo
)
{
String
themeId
=
themeQo
.
getThemeId
();
//封装转发对象
FormerThemeQo
former
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FORMER_THEME_ID
,
themeId
),
60
,
()
->
this
.
getFormerTheme
(
themeQo
.
getFormerThemeId
()),
FormerThemeQo
.
class
);
themeQo
.
setFormerTheme
(
former
);
//点赞,收藏,转发
Integer
likeCount
=
collectionService
.
getCountByTypeAndId
(
themeId
,
CollectionTypeEnum
.
LIKE_THEME
);
Integer
commentCount
=
commentService
.
getCommentCountByThemeId
(
themeId
);
Integer
forwardCount
=
themeService
.
getForwardCountById
(
themeId
);
themeQo
.
setCommentCount
(
commentCount
);
themeQo
.
setLikeCount
(
likeCount
);
themeQo
.
setForwardCount
(
forwardCount
);
}
}
//组装和当前用户相关信息
private
void
buildThemeExtraInfoByUser
(
String
userId
,
ThemeQo
themeQo
)
{
String
themeId
=
themeQo
.
getThemeId
();
//是否关注作者
String
authorId
=
themeQo
.
getAuthorId
();
Set
<
String
>
fansSet
=
new
HashSet
<>(
followRelService
.
queryFansByFollowerId
(
userId
));
themeQo
.
setFollow
(
fansSet
.
contains
(
authorId
));
//是否点赞
CollectionEntity
likeEntity
=
collectionService
.
getNotDeleteTargetCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
themeQo
.
setHasLiked
(
likeEntity
!=
null
);
//是否转发
Integer
forwardCountByUser
=
themeService
.
getForwardCountByUser
(
themeId
,
userId
);
themeQo
.
setHasForward
(
forwardCountByUser
>
0
);
//是否收藏
CollectionEntity
collectionEntity
=
collectionService
.
getNotDeleteTargetCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
COLLECT_THEME
);
themeQo
.
setHasCollect
(
collectionEntity
!=
null
);
}
// 返回用户发布、回复、点赞、收藏的主题列表
// 返回用户发布、回复、点赞、收藏的主题列表
public
List
<
ThemeQo
>
queryThemesByUser
(
QueryRecordThemeReq
req
,
String
userId
)
{
public
List
<
ThemeQo
>
queryThemesByUser
(
QueryRecordThemeReq
req
,
String
userId
)
{
...
@@ -245,19 +287,19 @@ public class ThemeManager {
...
@@ -245,19 +287,19 @@ public class ThemeManager {
//查询正文
//查询正文
public
ThemeQo
getDetail
(
String
themeId
,
String
userId
)
{
public
ThemeQo
get
Theme
Detail
(
String
themeId
,
String
userId
)
{
//进入详情
//进入详情
visitSummaryService
.
addPageView
(
userId
,
themeId
,
VisitTypeEnum
.
THEME_PAGE_VIEW
);
visitSummaryService
.
addPageView
(
userId
,
themeId
,
VisitTypeEnum
.
THEME_PAGE_VIEW
);
//查询详情
ThemeQo
themeQo
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_THEME_ID
,
themeId
),
60
,
ThemeQo
themeQo
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_THEME_ID
,
themeId
),
60
,
()
->
this
.
getDetail
For
Common
(
themeId
),
ThemeQo
.
class
);
()
->
this
.
getDetailCommon
(
themeId
),
ThemeQo
.
class
);
//添加用户相关信息
buildThemeExtraInfoByUser
(
userId
,
themeQo
);
buildThemeExtraInfoByUser
(
userId
,
themeQo
);
return
themeQo
;
return
themeQo
;
}
}
//正文通用信息,与用户无关,可使用缓存
//正文通用信息,与用户无关,可使用缓存
private
ThemeQo
getDetail
For
Common
(
String
themeId
)
{
private
ThemeQo
getDetailCommon
(
String
themeId
)
{
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
themeId
);
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
themeId
);
if
(
themeEntity
==
null
)
{
if
(
themeEntity
==
null
)
{
throw
new
BizException
(
"找不到帖子id:"
+
themeId
);
throw
new
BizException
(
"找不到帖子id:"
+
themeId
);
...
@@ -317,90 +359,6 @@ public class ThemeManager {
...
@@ -317,90 +359,6 @@ public class ThemeManager {
}
}
}
}
// 屏蔽(主题)
public
void
blockTheme
(
String
themeId
,
String
userId
)
{
blackListService
.
addBlock
(
themeId
,
userId
,
BlockTypeEnum
.
THEME
);
BlackListEntity
selectOne
=
blackListService
.
selectOne
(
themeService
.
queryByThemeId
(
themeId
).
getAuthorId
(),
userId
,
BlockTypeEnum
.
USER
.
getCode
());
if
(
selectOne
==
null
)
{
blackListService
.
addBlock
(
themeService
.
queryByThemeId
(
themeId
).
getAuthorId
(),
userId
,
BlockTypeEnum
.
USER
);
}
}
// 解除屏蔽(主题)
public
void
unblockTheme
(
String
themeId
,
String
userId
)
{
blackListService
.
removeBlackList
(
themeId
,
userId
,
BlockTypeEnum
.
USER
);
}
//主题Entity转QO
private
List
<
ThemeQo
>
convertEntityToQo
(
List
<
ThemeEntity
>
themeEntities
,
String
userId
)
{
//Entity转Qo
List
<
ThemeQo
>
themeQos
=
ConvertUtil
.
themeEntitiesToDTOs
(
themeEntities
);
//批量查询附件detail
batchFeignCallService
.
getAttachDetailByBatch
(
themeQos
);
//其他信息
for
(
ThemeQo
themeQO
:
themeQos
)
{
buildThemeQoExtraInfo
(
themeQO
);
buildThemeExtraInfoByUser
(
userId
,
themeQO
);
}
return
themeQos
;
}
//转发对象、点赞、收藏、转发数
private
void
buildThemeQoExtraInfo
(
ThemeQo
themeQo
)
{
String
themeId
=
themeQo
.
getThemeId
();
//封装转发对象
FormerThemeQo
former
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FORMER_THEME_ID
,
themeId
),
60
,
()
->
this
.
getFormerTheme
(
themeQo
.
getFormerThemeId
()),
FormerThemeQo
.
class
);
themeQo
.
setFormerTheme
(
former
);
//点赞,收藏,转发
Integer
likeCount
=
collectionService
.
getCountByTypeAndId
(
themeId
,
CollectionTypeEnum
.
LIKE_THEME
);
Integer
commentCount
=
commentService
.
getCommentCountByThemeId
(
themeId
);
Integer
forwardCount
=
themeService
.
getForwardCountById
(
themeId
);
themeQo
.
setCommentCount
(
commentCount
);
themeQo
.
setLikeCount
(
likeCount
);
themeQo
.
setForwardCount
(
forwardCount
);
}
//组装和当前用户相关信息
private
void
buildThemeExtraInfoByUser
(
String
userId
,
ThemeQo
themeQo
)
{
String
themeId
=
themeQo
.
getThemeId
();
//是否关注作者
String
authorId
=
themeQo
.
getAuthorId
();
Set
<
String
>
fansSet
=
new
HashSet
<>(
followRelService
.
queryFansByFollowerId
(
userId
));
themeQo
.
setFollow
(
fansSet
.
contains
(
authorId
));
//是否点赞
CollectionEntity
likeEntity
=
collectionService
.
getNotDeleteTargetCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
themeQo
.
setHasLiked
(
likeEntity
!=
null
);
//是否转发
Integer
forwardCountByUser
=
themeService
.
getForwardCountByUser
(
themeId
,
userId
);
themeQo
.
setHasForward
(
forwardCountByUser
>
0
);
//是否收藏
CollectionEntity
collectionEntity
=
collectionService
.
getNotDeleteTargetCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
COLLECT_THEME
);
themeQo
.
setHasCollect
(
collectionEntity
!=
null
);
}
//组装被转发主题
private
void
buildFormerTheme
(
ThemeQo
themeQo
)
{
String
formerThemeId
=
themeQo
.
getFormerThemeId
();
if
(
StringUtils
.
isNotEmpty
(
formerThemeId
))
{
ThemeQo
formerTheme
=
ConvertUtil
.
themeEntityToQo
(
themeService
.
queryByThemeId
(
formerThemeId
));
if
(
formerTheme
!=
null
)
{
//单个查询详情
batchFeignCallService
.
getAttachDetail
(
formerTheme
);
FormerThemeQo
f
=
ConvertUtil
.
themeQo2FormerThemeQo
(
formerTheme
);
themeQo
.
setFormerTheme
(
f
);
}
}
}
//返回被转发主题
//返回被转发主题
private
FormerThemeQo
getFormerTheme
(
String
formerThemeId
)
{
private
FormerThemeQo
getFormerTheme
(
String
formerThemeId
)
{
...
@@ -417,7 +375,7 @@ public class ThemeManager {
...
@@ -417,7 +375,7 @@ public class ThemeManager {
}
}
//逻辑删除
//逻辑删除
主题
public
void
delete
(
String
themeId
)
{
public
void
delete
(
String
themeId
)
{
themeService
.
deleteById
(
themeId
);
themeService
.
deleteById
(
themeId
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/HomePageService.java
deleted
100644 → 0
View file @
4351eb3f
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