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
882eec9e
Commit
882eec9e
authored
Jun 23, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder构造模式
parent
a257696c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
48 deletions
+66
-48
BlackListEntity.java
...tanpu/community/dao/entity/community/BlackListEntity.java
+9
-2
TopicEntity.java
...com/tanpu/community/dao/entity/community/TopicEntity.java
+6
-0
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+32
-39
BlackListService.java
...in/java/com/tanpu/community/service/BlackListService.java
+6
-4
TopicService.java
...c/main/java/com/tanpu/community/service/TopicService.java
+13
-3
No files found.
community-service/src/main/java/com/tanpu/community/dao/entity/community/BlackListEntity.java
View file @
882eec9e
package
com
.
tanpu
.
community
.
dao
.
entity
.
community
;
package
com
.
tanpu
.
community
.
dao
.
entity
.
community
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
java.time.LocalDateTime
;
import
java.io.Serializable
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
/**
/**
* <p>
* <p>
...
@@ -14,6 +18,9 @@ import io.swagger.annotations.ApiModelProperty;
...
@@ -14,6 +18,9 @@ import io.swagger.annotations.ApiModelProperty;
* @author xudong
* @author xudong
* @since 2021-06-10
* @since 2021-06-10
*/
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName
(
"black_list"
)
@TableName
(
"black_list"
)
@ApiModel
(
value
=
"BlackListEntity对象"
,
description
=
"黑名单"
)
@ApiModel
(
value
=
"BlackListEntity对象"
,
description
=
"黑名单"
)
public
class
BlackListEntity
implements
Serializable
{
public
class
BlackListEntity
implements
Serializable
{
...
...
community-service/src/main/java/com/tanpu/community/dao/entity/community/TopicEntity.java
View file @
882eec9e
...
@@ -3,6 +3,9 @@ package com.tanpu.community.dao.entity.community;
...
@@ -3,6 +3,9 @@ package com.tanpu.community.dao.entity.community;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
...
@@ -15,6 +18,9 @@ import java.time.LocalDateTime;
...
@@ -15,6 +18,9 @@ import java.time.LocalDateTime;
* @author xudong
* @author xudong
* @since 2021-06-18
* @since 2021-06-18
*/
*/
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName
(
"topic"
)
@TableName
(
"topic"
)
@ApiModel
(
value
=
"TopicEntity对象"
,
description
=
"话题"
)
@ApiModel
(
value
=
"TopicEntity对象"
,
description
=
"话题"
)
public
class
TopicEntity
implements
Serializable
{
public
class
TopicEntity
implements
Serializable
{
...
...
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
View file @
882eec9e
...
@@ -5,7 +5,6 @@ import com.tanpu.community.api.beans.TopicBriefInfoDTO;
...
@@ -5,7 +5,6 @@ import com.tanpu.community.api.beans.TopicBriefInfoDTO;
import
com.tanpu.community.api.beans.TopicDTO
;
import
com.tanpu.community.api.beans.TopicDTO
;
import
com.tanpu.community.api.beans.TopicDataAnalysDTO
;
import
com.tanpu.community.api.beans.TopicDataAnalysDTO
;
import
com.tanpu.community.api.constants.RedisKeyConstant
;
import
com.tanpu.community.api.constants.RedisKeyConstant
;
import
com.tanpu.community.api.constants.TopicStatusEnum
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.service.*
;
import
com.tanpu.community.service.*
;
...
@@ -34,23 +33,18 @@ public class TopicManager {
...
@@ -34,23 +33,18 @@ public class TopicManager {
@Autowired
@Autowired
private
CommentService
commentService
;
private
CommentService
commentService
;
public
void
insertTopic
(
String
topicTitle
,
String
userId
){
public
void
insertTopic
(
String
topicTitle
,
String
userId
)
{
TopicEntity
topicEntity
=
new
TopicEntity
();
topicService
.
addTopic
(
topicTitle
,
userId
);
topicEntity
.
setCreateBy
(
userId
);
topicEntity
.
setUpdateBy
(
userId
);
topicEntity
.
setTopicTitle
(
topicTitle
);
topicEntity
.
setIsTop
(
TopicStatusEnum
.
FALSE
.
getCode
());
topicEntity
.
setIsConceal
(
TopicStatusEnum
.
FALSE
.
getCode
());
topicEntity
.
setDeleteTag
(
TopicStatusEnum
.
FALSE
.
getCode
());
topicService
.
addTopic
(
topicEntity
);
}
}
//后台管理-话题列表
public
List
<
TopicDTO
>
getAllTopicDetail
()
{
public
List
<
TopicDTO
>
getAllTopicDetail
()
{
return
ConvertUtil
.
topicEntitiesToDTOs
(
topicService
.
queryAll
());
return
ConvertUtil
.
topicEntitiesToDTOs
(
topicService
.
queryAll
());
}
}
//APP-话题列表
public
List
<
TopicBriefInfoDTO
>
getAllTopicBriefInfo
()
{
public
List
<
TopicBriefInfoDTO
>
getAllTopicBriefInfo
()
{
List
<
TopicEntity
>
allTopic
=
topicService
.
queryAll
();
List
<
TopicEntity
>
allTopic
=
topicService
.
queryAll
();
List
<
TopicBriefInfoDTO
>
topicDTOS
=
ConvertUtil
.
topicEntitiesToBriefDTOs
(
allTopic
);
List
<
TopicBriefInfoDTO
>
topicDTOS
=
ConvertUtil
.
topicEntitiesToBriefDTOs
(
allTopic
);
...
@@ -62,26 +56,27 @@ public class TopicManager {
...
@@ -62,26 +56,27 @@ public class TopicManager {
return
topicDTOS
;
return
topicDTOS
;
}
}
public
void
setTopTopic
(
String
topicId
,
boolean
setTop
)
{
public
void
setTopTopic
(
String
topicId
,
boolean
setTop
)
{
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
if
(
topicEntity
==
null
){
if
(
topicEntity
==
null
)
{
throw
new
BizException
(
"
话题id不正确:
"
+
topicId
);
throw
new
BizException
(
"
找不到话题,id:
"
+
topicId
);
}
}
if
(
setTop
){
if
(
setTop
)
{
topicService
.
updateTopicToTop
(
topicId
);
topicService
.
updateTopicToTop
(
topicId
);
}
else
{
}
else
{
topicService
.
updateTopicNotTop
(
topicId
);
topicService
.
updateTopicNotTop
(
topicId
);
}
}
}
}
public
void
setTopicConceal
(
String
topicId
,
boolean
setConceal
)
{
public
void
setTopicConceal
(
String
topicId
,
boolean
setConceal
)
{
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
if
(
topicEntity
==
null
)
{
if
(
topicEntity
==
null
)
{
throw
new
BizException
(
"
话题id不正确:"
+
topicId
);
throw
new
BizException
(
"
找不到话题,id:"
+
topicId
);
}
}
if
(
setConceal
){
if
(
setConceal
)
{
topicService
.
updateTopicToConceal
(
topicId
);
topicService
.
updateTopicToConceal
(
topicId
);
}
else
{
}
else
{
topicService
.
updateTopicNotConceal
(
topicId
);
topicService
.
updateTopicNotConceal
(
topicId
);
}
}
}
}
...
@@ -89,26 +84,24 @@ public class TopicManager {
...
@@ -89,26 +84,24 @@ public class TopicManager {
public
TopicDTO
getDetail
(
String
topicId
)
{
public
TopicDTO
getDetail
(
String
topicId
)
{
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
TopicDTO
topicDTO
=
ConvertUtil
.
topicEntityToDTO
(
topicEntity
);
TopicDTO
topicDTO
=
ConvertUtil
.
topicEntityToDTO
(
topicEntity
);
topicDTO
.
setViewAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_VIEW_AMOUNT_
+
topicId
));
topicDTO
.
setViewAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_VIEW_AMOUNT_
+
topicId
));
topicDTO
.
setLikeAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_LIKE_AMOUNT_
+
topicId
));
topicDTO
.
setLikeAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_LIKE_AMOUNT_
+
topicId
));
topicDTO
.
setUserAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_USER_AMOUNT_
+
topicId
));
topicDTO
.
setUserAmount
(
redisService
.
getLong
(
RedisKeyConstant
.
TOPIC_USER_AMOUNT_
+
topicId
));
return
topicDTO
;
return
topicDTO
;
}
}
public
void
modifyViewAmount
(
String
topicId
,
Long
modifyMount
)
{
public
void
modifyViewAmount
(
String
topicId
,
Long
modifyMount
)
{
topicService
.
modifyViewAmount
(
topicId
,
modifyMount
);
topicService
.
modifyViewAmount
(
topicId
,
modifyMount
);
if
(
modifyMount
>
0
)
{
if
(
modifyMount
>
0
)
{
redisService
.
incr
(
RedisKeyConstant
.
TOPIC_TOTAL_VIEW_AMOUNT_
+
topicId
,
modifyMount
);
redisService
.
incr
(
RedisKeyConstant
.
TOPIC_TOTAL_VIEW_AMOUNT_
+
topicId
,
modifyMount
);
}
else
{
}
else
{
redisService
.
decr
(
RedisKeyConstant
.
TOPIC_TOTAL_VIEW_AMOUNT_
+
topicId
,
-
modifyMount
);
redisService
.
decr
(
RedisKeyConstant
.
TOPIC_TOTAL_VIEW_AMOUNT_
+
topicId
,
-
modifyMount
);
}
}
}
}
public
void
refreshRedisCache
()
{
public
void
refreshRedisCache
(){
List
<
TopicEntity
>
topicEntities
=
topicService
.
queryAll
();
List
<
TopicEntity
>
topicEntities
=
topicService
.
queryAll
();
for
(
TopicEntity
topic
:
topicEntities
)
{
for
(
TopicEntity
topic
:
topicEntities
)
{
String
topicId
=
topic
.
getId
();
String
topicId
=
topic
.
getId
();
...
@@ -118,17 +111,17 @@ public class TopicManager {
...
@@ -118,17 +111,17 @@ public class TopicManager {
Long
likeAmountByThemeIds
=
collectionService
.
getLikeAmountByThemeIds
(
themeIds
);
Long
likeAmountByThemeIds
=
collectionService
.
getLikeAmountByThemeIds
(
themeIds
);
Long
bookAmountByThemeIds
=
collectionService
.
getBookAmountByThemeIds
(
themeIds
);
Long
bookAmountByThemeIds
=
collectionService
.
getBookAmountByThemeIds
(
themeIds
);
Long
commentAmountByThemeIds
=
commentService
.
getCommentAmountByThemeIds
(
themeIds
);
Long
commentAmountByThemeIds
=
commentService
.
getCommentAmountByThemeIds
(
themeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_LIKE_AMOUNT_
+
topicId
,
likeAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_LIKE_AMOUNT_
+
topicId
,
likeAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_BOOK_AMOUNT_
+
topicId
,
bookAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_BOOK_AMOUNT_
+
topicId
,
bookAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_COMMENT_AMOUNT_
+
topicId
,
commentAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_COMMENT_AMOUNT_
+
topicId
,
commentAmountByThemeIds
);
redisService
.
set
(
RedisKeyConstant
.
TOPIC_TOTAL_VIEW_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_TOTAL_VIEW_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_THEME_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_THEME_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_TOTAOL_USER_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_TOTAOL_USER_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_DISCUSS_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_DISCUSS_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_USER_POST_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_USER_POST_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_USER_COMMET_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
redisService
.
set
(
RedisKeyConstant
.
TOPIC_USER_COMMET_AMOUNT_
+
topicId
,
commentAmountByThemeIds
+
themeIds
.
size
());
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/BlackListService.java
View file @
882eec9e
...
@@ -14,10 +14,12 @@ public class BlackListService {
...
@@ -14,10 +14,12 @@ public class BlackListService {
private
BlackListMapper
blackListMapper
;
private
BlackListMapper
blackListMapper
;
public
void
addBlock
(
String
blockId
,
String
userId
,
BlockTypeEnum
type
)
{
public
void
addBlock
(
String
blockId
,
String
userId
,
BlockTypeEnum
type
)
{
BlackListEntity
blackListEntity
=
new
BlackListEntity
();
BlackListEntity
blackListEntity
=
BlackListEntity
.
builder
()
blackListEntity
.
setBlockedId
(
blockId
);
.
blocker
(
userId
)
blackListEntity
.
setBlocker
(
userId
);
.
blockedId
(
blockId
)
blackListEntity
.
setBlockedType
(
type
.
getCode
());
.
blockedType
(
type
.
getCode
())
.
build
();
blackListMapper
.
insert
(
blackListEntity
);
blackListMapper
.
insert
(
blackListEntity
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/TopicService.java
View file @
882eec9e
...
@@ -2,6 +2,7 @@ package com.tanpu.community.service;
...
@@ -2,6 +2,7 @@ package com.tanpu.community.service;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.tanpu.community.api.constants.DeleteTagEnum
;
import
com.tanpu.community.api.constants.TopicStatusEnum
;
import
com.tanpu.community.api.constants.TopicStatusEnum
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.dao.mapper.community.TopicMapper
;
import
com.tanpu.community.dao.mapper.community.TopicMapper
;
...
@@ -22,11 +23,20 @@ public class TopicService {
...
@@ -22,11 +23,20 @@ public class TopicService {
public
List
<
TopicEntity
>
queryAll
(){
public
List
<
TopicEntity
>
queryAll
(){
return
topicMapper
.
selectList
(
new
LambdaQueryWrapper
<
TopicEntity
>()
return
topicMapper
.
selectList
(
new
LambdaQueryWrapper
<
TopicEntity
>()
.
eq
(
TopicEntity:
:
getDeleteTag
,
TopicStatusEnum
.
FALSE
.
getCode
()));
.
eq
(
TopicEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
()));
}
}
public
void
addTopic
(
TopicEntity
topicEntity
){
topicMapper
.
insert
(
topicEntity
);
public
void
addTopic
(
String
topicTitle
,
String
userId
){
TopicEntity
entity
=
TopicEntity
.
builder
()
.
topicTitle
(
topicTitle
)
.
createBy
(
userId
)
.
updateBy
(
userId
)
.
isTop
(
TopicStatusEnum
.
FALSE
.
getCode
())
.
isConceal
(
TopicStatusEnum
.
FALSE
.
getCode
())
.
build
();
topicMapper
.
insert
(
entity
);
}
}
...
...
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