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
edf9acf2
Commit
edf9acf2
authored
Jul 28, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加注释
parent
16b5ae0a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
33 deletions
+35
-33
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+33
-32
CollectionService.java
...n/java/com/tanpu/community/service/CollectionService.java
+2
-1
No files found.
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
edf9acf2
...
@@ -124,35 +124,36 @@ public class ThemeManager {
...
@@ -124,35 +124,36 @@ public class ThemeManager {
@Transactional
@Transactional
public
CreateThemeResp
publishTheme
(
CreateThemeReq
req
,
String
userId
)
{
public
CreateThemeResp
publishTheme
(
CreateThemeReq
req
,
String
userId
)
{
//保存主题表
//
保存主题表
ThemeEntity
themeEntity
=
new
ThemeEntity
();
ThemeEntity
themeEntity
=
new
ThemeEntity
();
BeanUtils
.
copyProperties
(
req
,
themeEntity
);
BeanUtils
.
copyProperties
(
req
,
themeEntity
);
themeEntity
.
setAuthorId
(
userId
);
themeEntity
.
setAuthorId
(
userId
);
themeEntity
.
setContent
(
JsonUtil
.
toJson
(
req
.
getContent
()));
themeEntity
.
setContent
(
JsonUtil
.
toJson
(
req
.
getContent
()));
//讨论类型,将讨论中的文本放入到discussContent中
//
讨论类型,将讨论中的文本放入到discussContent中
if
(
ThemeTypeEnum
.
DISCUSSION
.
getCode
().
equals
(
themeEntity
.
getThemeType
()))
{
if
(
ThemeTypeEnum
.
DISCUSSION
.
getCode
().
equals
(
themeEntity
.
getThemeType
()))
{
String
content
=
req
.
getContent
().
get
(
0
).
getValue
();
String
content
=
req
.
getContent
().
get
(
0
).
getValue
();
if
(
content
.
length
()>
256
){
// discuss_content字段上限为256个字符
content
=
content
.
substring
(
0
,
255
);
if
(
content
.
length
()
>
256
)
{
content
=
content
.
substring
(
0
,
255
);
}
}
themeEntity
.
setDiscussContent
(
content
);
themeEntity
.
setDiscussContent
(
content
);
}
}
//腾讯云敏感词校验
//
腾讯云敏感词校验
checkContent
(
themeEntity
.
getContent
());
checkContent
(
themeEntity
.
getContent
());
if
(
StringUtils
.
isEmpty
(
req
.
getEditThemeId
()))
{
if
(
StringUtils
.
isEmpty
(
req
.
getEditThemeId
()))
{
//新建
//
新建
themeService
.
insertTheme
(
themeEntity
);
themeService
.
insertTheme
(
themeEntity
);
}
else
{
}
else
{
//修改
//
修改
themeService
.
update
(
themeEntity
,
req
.
getEditThemeId
());
themeService
.
update
(
themeEntity
,
req
.
getEditThemeId
());
themeEntity
.
setThemeId
(
req
.
getEditThemeId
());
themeEntity
.
setThemeId
(
req
.
getEditThemeId
());
}
}
//保存附件表
//
保存附件表
List
<
ThemeAttachmentEntity
>
themeAttachments
=
ConvertUtil
.
themeReqToAttachmentList
(
req
,
themeEntity
.
getThemeId
());
List
<
ThemeAttachmentEntity
>
themeAttachments
=
ConvertUtil
.
themeReqToAttachmentList
(
req
,
themeEntity
.
getThemeId
());
if
(
StringUtils
.
isNotEmpty
(
req
.
getEditThemeId
()))
{
if
(
StringUtils
.
isNotEmpty
(
req
.
getEditThemeId
()))
{
//修改需要刪除
//
修改需要刪除
themeAttachmentService
.
deleteByThemeId
(
req
.
getEditThemeId
());
themeAttachmentService
.
deleteByThemeId
(
req
.
getEditThemeId
());
}
}
themeAttachmentService
.
insertList
(
themeAttachments
);
themeAttachmentService
.
insertList
(
themeAttachments
);
...
@@ -180,10 +181,10 @@ public class ThemeManager {
...
@@ -180,10 +181,10 @@ public class ThemeManager {
.
build
();
.
build
();
if
(
StringUtils
.
isEmpty
(
req
.
getEditThemeId
())
||
req
.
getEditThemeId
().
equals
(
req
.
getFormerThemeId
()))
{
if
(
StringUtils
.
isEmpty
(
req
.
getEditThemeId
())
||
req
.
getEditThemeId
().
equals
(
req
.
getFormerThemeId
()))
{
//新建
//
新建
themeService
.
insertTheme
(
themeEntity
);
themeService
.
insertTheme
(
themeEntity
);
}
else
{
}
else
{
//修改
//
修改
themeService
.
update
(
themeEntity
,
req
.
getEditThemeId
());
themeService
.
update
(
themeEntity
,
req
.
getEditThemeId
());
themeEntity
.
setThemeId
(
req
.
getEditThemeId
());
themeEntity
.
setThemeId
(
req
.
getEditThemeId
());
...
@@ -252,31 +253,31 @@ public class ThemeManager {
...
@@ -252,31 +253,31 @@ public class ThemeManager {
return
resp
;
return
resp
;
}
}
//主题Entity转QO,组装所有信息
//
主题Entity转QO,组装所有信息
private
List
<
ThemeQo
>
convertEntityToQo
(
List
<
ThemeEntity
>
themeEntities
,
String
userId
)
{
private
List
<
ThemeQo
>
convertEntityToQo
(
List
<
ThemeEntity
>
themeEntities
,
String
userId
)
{
//Entity转Qo
//Entity转Qo
List
<
ThemeQo
>
themeQos
=
ConvertUtil
.
themeEntitiesToDTOs
(
themeEntities
);
List
<
ThemeQo
>
themeQos
=
ConvertUtil
.
themeEntitiesToDTOs
(
themeEntities
);
//批量查询附件detail
//
批量查询附件detail
batchFeignCallService
.
getAttachDetailByBatch
(
themeQos
);
batchFeignCallService
.
getAttachDetailByBatch
(
themeQos
);
//其他信息
//其他信息
for
(
ThemeQo
themeQO
:
themeQos
)
{
for
(
ThemeQo
themeQO
:
themeQos
)
{
//通用信息
//
通用信息
buildThemeQoExtraInfo
(
themeQO
);
buildThemeQoExtraInfo
(
themeQO
);
//和用户相关信息
//
和用户相关信息
buildThemeExtraInfoByUser
(
userId
,
themeQO
);
buildThemeExtraInfoByUser
(
userId
,
themeQO
);
}
}
return
themeQos
;
return
themeQos
;
}
}
//转发对象、点赞、收藏、转发数
//
转发对象、点赞、收藏、转发数
private
void
buildThemeQoExtraInfo
(
ThemeQo
themeQo
)
{
private
void
buildThemeQoExtraInfo
(
ThemeQo
themeQo
)
{
String
themeId
=
themeQo
.
getThemeId
();
String
themeId
=
themeQo
.
getThemeId
();
//封装转发对象
//
封装转发对象
FormerThemeQo
former
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FORMER_THEME_ID
,
themeId
),
60
,
FormerThemeQo
former
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
"_"
,
CACHE_FORMER_THEME_ID
,
themeId
),
60
,
()
->
this
.
getFormerTheme
(
themeQo
.
getFormerThemeId
()),
FormerThemeQo
.
class
);
()
->
this
.
getFormerTheme
(
themeQo
.
getFormerThemeId
()),
FormerThemeQo
.
class
);
themeQo
.
setFormerTheme
(
former
);
themeQo
.
setFormerTheme
(
former
);
//点赞,收藏,转发
//
点赞,收藏,转发
Integer
likeCount
=
collectionService
.
getCountByTypeAndId
(
themeId
,
CollectionTypeEnum
.
LIKE_THEME
);
Integer
likeCount
=
collectionService
.
getCountByTypeAndId
(
themeId
,
CollectionTypeEnum
.
LIKE_THEME
);
Integer
commentCount
=
commentService
.
getCommentCountByThemeId
(
themeId
);
Integer
commentCount
=
commentService
.
getCommentCountByThemeId
(
themeId
);
Integer
forwardCount
=
themeService
.
getForwardCountById
(
themeId
);
Integer
forwardCount
=
themeService
.
getForwardCountById
(
themeId
);
...
@@ -285,18 +286,18 @@ public class ThemeManager {
...
@@ -285,18 +286,18 @@ public class ThemeManager {
themeQo
.
setForwardCount
(
forwardCount
);
themeQo
.
setForwardCount
(
forwardCount
);
}
}
//组装和当前用户相关信息
//
组装和当前用户相关信息
private
void
buildThemeExtraInfoByUser
(
String
userId
,
ThemeQo
themeQo
)
{
private
void
buildThemeExtraInfoByUser
(
String
userId
,
ThemeQo
themeQo
)
{
String
themeId
=
themeQo
.
getThemeId
();
String
themeId
=
themeQo
.
getThemeId
();
//是否关注作者
//
是否关注作者
themeQo
.
setFollow
(
followRelService
.
checkFollow
(
themeQo
.
getAuthorId
(),
userId
));
themeQo
.
setFollow
(
followRelService
.
checkFollow
(
themeQo
.
getAuthorId
(),
userId
));
//是否点赞
//
是否点赞
CollectionEntity
likeEntity
=
collectionService
.
getNotDeleteTargetCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
CollectionEntity
likeEntity
=
collectionService
.
getNotDeleteTargetCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
LIKE_THEME
);
themeQo
.
setHasLiked
(
likeEntity
!=
null
);
themeQo
.
setHasLiked
(
likeEntity
!=
null
);
//是否转发
//
是否转发
Integer
forwardCountByUser
=
themeService
.
getForwardCountByUser
(
themeId
,
userId
);
Integer
forwardCountByUser
=
themeService
.
getForwardCountByUser
(
themeId
,
userId
);
themeQo
.
setHasForward
(
forwardCountByUser
>
0
);
themeQo
.
setHasForward
(
forwardCountByUser
>
0
);
//是否收藏
//
是否收藏
CollectionEntity
collectionEntity
=
collectionService
.
getNotDeleteTargetCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
COLLECT_THEME
);
CollectionEntity
collectionEntity
=
collectionService
.
getNotDeleteTargetCollection
(
themeId
,
userId
,
CollectionTypeEnum
.
COLLECT_THEME
);
themeQo
.
setHasCollect
(
collectionEntity
!=
null
);
themeQo
.
setHasCollect
(
collectionEntity
!=
null
);
}
}
...
@@ -329,19 +330,19 @@ public class ThemeManager {
...
@@ -329,19 +330,19 @@ public class ThemeManager {
}
}
//查询正文
//
查询正文
public
ThemeQo
getThemeDetail
(
String
themeId
,
String
userId
)
{
public
ThemeQo
getThemeDetail
(
String
themeId
,
String
userId
)
{
//TODO 临时埋点,接入新埋点后删除
//TODO 临时埋点,接入新埋点后删除
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
.
getDetailCommon
(
themeId
),
ThemeQo
.
class
);
()
->
this
.
getDetailCommon
(
themeId
),
ThemeQo
.
class
);
//添加用户相关信息
//
添加用户相关信息
buildThemeExtraInfoByUser
(
userId
,
themeQo
);
buildThemeExtraInfoByUser
(
userId
,
themeQo
);
return
themeQo
;
return
themeQo
;
}
}
//正文通用信息,与用户无关,可使用缓存
//
正文通用信息,与用户无关,可使用缓存
private
ThemeQo
getDetailCommon
(
String
themeId
)
{
private
ThemeQo
getDetailCommon
(
String
themeId
)
{
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
themeId
);
ThemeEntity
themeEntity
=
themeService
.
queryByThemeId
(
themeId
);
if
(
themeEntity
==
null
)
{
if
(
themeEntity
==
null
)
{
...
@@ -477,9 +478,9 @@ public class ThemeManager {
...
@@ -477,9 +478,9 @@ public class ThemeManager {
private
List
<
ThemeQo
>
getCommentThemeQos
(
QueryRecordThemeReq
req
,
String
userId
)
{
private
List
<
ThemeQo
>
getCommentThemeQos
(
QueryRecordThemeReq
req
,
String
userId
)
{
List
<
ThemeQo
>
commentThemeList
=
new
ArrayList
<>();
List
<
ThemeQo
>
commentThemeList
=
new
ArrayList
<>();
List
<
ThemeEntity
>
themeEntities
;
List
<
ThemeEntity
>
themeEntities
;
//评论列表
//
评论列表
List
<
CommentEntity
>
commentEntities
=
commentService
.
queryCommentsByUserId
(
req
.
getUserId
(),
req
.
getLastId
(),
req
.
getPageSize
());
List
<
CommentEntity
>
commentEntities
=
commentService
.
queryCommentsByUserId
(
req
.
getUserId
(),
req
.
getLastId
(),
req
.
getPageSize
());
//当前用户信息
//
当前用户信息
UserInfoNew
userInfo
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
CACHE_FEIGN_USER_INFO
,
req
.
getUserId
()),
UserInfoNew
userInfo
=
redisCache
.
getObject
(
StringUtils
.
joinWith
(
CACHE_FEIGN_USER_INFO
,
req
.
getUserId
()),
60
*
10
,
()
->
this
.
getUserInfo
(
req
.
getUserId
()),
UserInfoNew
.
class
);
60
*
10
,
()
->
this
.
getUserInfo
(
req
.
getUserId
()),
UserInfoNew
.
class
);
Set
<
String
>
replyThemeIds
=
commentEntities
.
stream
().
map
(
CommentEntity:
:
getThemeId
).
collect
(
Collectors
.
toSet
());
Set
<
String
>
replyThemeIds
=
commentEntities
.
stream
().
map
(
CommentEntity:
:
getThemeId
).
collect
(
Collectors
.
toSet
());
...
@@ -488,12 +489,12 @@ public class ThemeManager {
...
@@ -488,12 +489,12 @@ public class ThemeManager {
}
}
themeEntities
=
themeService
.
queryByThemeIds
(
new
ArrayList
<>(
replyThemeIds
));
themeEntities
=
themeService
.
queryByThemeIds
(
new
ArrayList
<>(
replyThemeIds
));
List
<
ThemeQo
>
themeQos
=
convertEntityToQo
(
themeEntities
,
userId
);
List
<
ThemeQo
>
themeQos
=
convertEntityToQo
(
themeEntities
,
userId
);
//组装附件
//
组装附件
batchFeignCallService
.
getAttachDetailByBatch
(
themeQos
);
batchFeignCallService
.
getAttachDetailByBatch
(
themeQos
);
//主题列表
//
主题列表
Map
<
String
,
ThemeQo
>
themeMap
=
themeQos
.
stream
()
Map
<
String
,
ThemeQo
>
themeMap
=
themeQos
.
stream
()
.
collect
(
Collectors
.
toMap
(
ThemeQo:
:
getThemeId
,
o
->
o
));
.
collect
(
Collectors
.
toMap
(
ThemeQo:
:
getThemeId
,
o
->
o
));
//主题+评论封装转发对象
//
主题+评论封装转发对象
for
(
CommentEntity
commentEntity
:
commentEntities
)
{
for
(
CommentEntity
commentEntity
:
commentEntities
)
{
String
themeId
=
commentEntity
.
getThemeId
();
String
themeId
=
commentEntity
.
getThemeId
();
//评论内容包装到ThemeContentQo里
//评论内容包装到ThemeContentQo里
...
...
community-service/src/main/java/com/tanpu/community/service/CollectionService.java
View file @
edf9acf2
...
@@ -79,7 +79,8 @@ public class CollectionService {
...
@@ -79,7 +79,8 @@ public class CollectionService {
return
collectionMapper
.
selectList
(
new
LambdaQueryWrapper
<
CollectionEntity
>()
return
collectionMapper
.
selectList
(
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
()))
.
eq
(
CollectionEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
())
.
orderByDesc
(
CollectionEntity:
:
getCollectionTime
))
.
stream
().
map
(
CollectionEntity:
:
getTargetId
).
collect
(
Collectors
.
toList
());
.
stream
().
map
(
CollectionEntity:
:
getTargetId
).
collect
(
Collectors
.
toList
());
}
}
...
...
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