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
07d7c66a
Commit
07d7c66a
authored
Jun 11, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
话题相关
parent
3893149c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
296 additions
and
4 deletions
+296
-4
TopicDTO.java
...src/main/java/com/tanpu/community/api/beans/TopicDTO.java
+61
-0
TopicController.java
.../java/com/tanpu/community/controller/TopicController.java
+67
-0
TopicConverter.java
...om/tanpu/community/controller/convert/TopicConverter.java
+29
-0
TopicEntity.java
...com/tanpu/community/dao/entity/community/TopicEntity.java
+3
-3
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+54
-0
BizException.java
...a/com/tanpu/community/manager/exception/BizException.java
+19
-0
TopicService.java
...c/main/java/com/tanpu/community/service/TopicService.java
+62
-0
create.sql
docs/create.sql
+1
-1
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/TopicDTO.java
0 → 100644
View file @
07d7c66a
package
com
.
tanpu
.
community
.
api
.
beans
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
@Data
@ApiModel
(
value
=
"TopicDTO对象"
,
description
=
"话题"
)
public
class
TopicDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"id"
)
private
String
id
;
@ApiModelProperty
(
value
=
"话题名称"
)
private
String
topicTitle
;
@ApiModelProperty
(
value
=
"是否置顶"
)
private
Integer
isTop
;
@ApiModelProperty
(
value
=
"是否隐藏"
)
private
Integer
isConceal
;
private
String
createBy
;
private
LocalDateTime
createTime
;
private
String
updateBy
;
private
LocalDateTime
updateTime
;
private
Integer
deleteTag
;
@ApiModelProperty
(
value
=
"帖子量"
)
private
Long
themeAmount
;
@ApiModelProperty
(
value
=
"浏览量"
)
private
Long
viewAmount
;
@ApiModelProperty
(
value
=
"点赞量"
)
private
Long
likeAmount
;
@Override
public
String
toString
()
{
return
"TopicEntity{"
+
"id="
+
id
+
", topicTitle="
+
topicTitle
+
", isTop="
+
isTop
+
", isConceal="
+
isConceal
+
", createBy="
+
createBy
+
", createTime="
+
createTime
+
", updateBy="
+
updateBy
+
", updateTime="
+
updateTime
+
", deleteTag="
+
deleteTag
+
"}"
;
}
}
community-service/src/main/java/com/tanpu/community/controller/TopicController.java
0 → 100644
View file @
07d7c66a
package
com
.
tanpu
.
community
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.gson.JsonObject
;
import
com.tanpu.community.api.beans.TopicDTO
;
import
com.tanpu.community.controller.convert.TopicConverter
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.manager.TopicManager
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.Value
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.MissingServletRequestParameterException
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@Slf4j
@RequestMapping
(
value
=
"/api/topic"
)
public
class
TopicController
{
@Autowired
private
TopicManager
topicManager
;
@PostMapping
(
value
=
"/queryTopicList"
)
@ApiOperation
(
"查询所有的主题列表"
)
@ResponseBody
public
List
<
TopicDTO
>
getAllTopList
(
@RequestBody
String
content
){
JSONObject
params
=
JSONObject
.
parseObject
(
content
);
List
<
TopicEntity
>
allTopic
=
topicManager
.
getAllTopic
();
List
<
TopicDTO
>
topicDTOS
=
TopicConverter
.
convertToDTOs
(
allTopic
);
return
topicDTOS
;
}
@PostMapping
(
value
=
"/insertTopic"
)
@ResponseBody
public
String
addTopic
(
@RequestBody
String
topicTitle
){
topicManager
.
insertTopic
(
topicTitle
);
return
"success"
;
}
@PostMapping
(
value
=
"/setTop"
)
@ResponseBody
public
String
setTopTopic
(
@RequestBody
String
topicId
,
@RequestBody
boolean
setTop
)
throws
MissingServletRequestParameterException
{
if
(
StringUtils
.
isEmpty
(
topicId
)){
throw
new
MissingServletRequestParameterException
(
"topicId"
,
"Long"
);
}
topicManager
.
setTopTopic
(
topicId
,
setTop
);
return
"success"
;
}
@PostMapping
(
value
=
"/setConceal"
)
@ResponseBody
public
String
setConceal
(
@RequestBody
String
topicId
,
@RequestBody
boolean
setConceal
)
throws
MissingServletRequestParameterException
{
if
(
StringUtils
.
isEmpty
(
topicId
)){
throw
new
MissingServletRequestParameterException
(
"topicId"
,
"Long"
);
}
topicManager
.
setTopicConceal
(
topicId
,
setConceal
);
return
"success"
;
}
}
community-service/src/main/java/com/tanpu/community/controller/convert/TopicConverter.java
0 → 100644
View file @
07d7c66a
package
com
.
tanpu
.
community
.
controller
.
convert
;
import
com.tanpu.community.api.beans.TopicDTO
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
java.util.List
;
import
java.util.stream.Collectors
;
public
class
TopicConverter
{
public
static
TopicDTO
convertToDTO
(
TopicEntity
topicEntity
){
TopicDTO
topicDTO
=
new
TopicDTO
();
topicDTO
.
setTopicTitle
(
topicEntity
.
getTopicTitle
());
topicDTO
.
setId
(
topicEntity
.
getId
());
topicDTO
.
setIsTop
(
topicEntity
.
getIsTop
());
topicDTO
.
setIsConceal
(
topicEntity
.
getIsConceal
());
topicDTO
.
setCreateBy
(
topicEntity
.
getCreateBy
());
topicDTO
.
setCreateTime
(
topicEntity
.
getCreateTime
());
topicDTO
.
setUpdateTime
(
topicEntity
.
getUpdateTime
());
topicDTO
.
setUpdateBy
(
topicEntity
.
getUpdateBy
());
topicDTO
.
setDeleteTag
(
topicEntity
.
getDeleteTag
());
return
topicDTO
;
}
public
static
List
<
TopicDTO
>
convertToDTOs
(
List
<
TopicEntity
>
topicEntities
){
return
topicEntities
.
stream
().
map
(
TopicConverter:
:
convertToDTO
).
collect
(
Collectors
.
toList
());
}
}
community-service/src/main/java/com/tanpu/community/dao/entity/community/TopicEntity.java
View file @
07d7c66a
...
...
@@ -24,7 +24,7 @@ public class TopicEntity implements Serializable {
private
String
id
;
@ApiModelProperty
(
value
=
"话题名称"
)
private
Integer
topicTitle
;
private
String
topicTitle
;
@ApiModelProperty
(
value
=
"是否置顶"
)
private
Integer
isTop
;
...
...
@@ -51,11 +51,11 @@ public class TopicEntity implements Serializable {
this
.
id
=
id
;
}
public
Integer
getTopicTitle
()
{
public
String
getTopicTitle
()
{
return
topicTitle
;
}
public
void
setTopicTitle
(
Integer
topicTitle
)
{
public
void
setTopicTitle
(
String
topicTitle
)
{
this
.
topicTitle
=
topicTitle
;
}
...
...
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
0 → 100644
View file @
07d7c66a
package
com
.
tanpu
.
community
.
manager
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.service.TopicService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
class
TopicManager
{
@Autowired
private
TopicService
topicService
;
public
void
insertTopic
(
String
topicTitle
){
TopicEntity
topicEntity
=
new
TopicEntity
();
topicEntity
.
setTopicTitle
(
topicTitle
);
}
public
List
<
TopicEntity
>
getAllTopic
()
{
return
topicService
.
queryTopicList
();
}
public
void
setTopTopic
(
String
topicId
,
boolean
setTop
)
{
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
if
(
topicEntity
==
null
){
throw
new
BizException
(
"话题id不正确:"
+
topicId
);
}
if
(
setTop
){
topicService
.
updateTopicToTop
(
topicId
);
}
else
{
topicService
.
updateTopicNotTop
(
topicId
);
}
}
public
void
setTopicConceal
(
String
topicId
,
boolean
setConceal
)
{
TopicEntity
topicEntity
=
topicService
.
queryById
(
topicId
);
if
(
topicEntity
==
null
){
throw
new
BizException
(
"话题id不正确:"
+
topicId
);
}
if
(
setConceal
){
topicService
.
updateTopicToConceal
(
topicId
);
}
else
{
topicService
.
updateTopicNotConceal
(
topicId
);
}
}
}
community-service/src/main/java/com/tanpu/community/manager/exception/BizException.java
0 → 100644
View file @
07d7c66a
package
com
.
tanpu
.
community
.
manager
.
exception
;
public
class
BizException
extends
Exception
{
public
BizException
(){
super
();
}
public
BizException
(
String
message
){
super
(
message
);
}
public
BizException
(
String
message
,
Throwable
cause
){
super
(
message
,
cause
);
}
public
BizException
(
Throwable
cause
){
super
(
cause
);
}
}
community-service/src/main/java/com/tanpu/community/service/TopicService.java
0 → 100644
View file @
07d7c66a
package
com
.
tanpu
.
community
.
service
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.dao.mapper.community.TopicMapper
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Service
@EnableCaching
public
class
TopicService
{
@Resource
private
TopicMapper
topicMapper
;
public
List
<
TopicEntity
>
queryTopicList
(){
return
topicMapper
.
selectList
(
new
QueryWrapper
<>());
}
public
void
addTopic
(
TopicEntity
topicEntity
){
topicMapper
.
insert
(
topicEntity
);
}
public
void
updateTopicToTop
(
String
topicId
){
UpdateWrapper
<
TopicEntity
>
updateWrapper
=
new
UpdateWrapper
<>();
updateWrapper
.
eq
(
"id"
,
topicId
);
updateWrapper
.
set
(
"isTop"
,
true
);
topicMapper
.
update
(
null
,
updateWrapper
);
}
public
void
updateTopicNotTop
(
String
topicId
){
UpdateWrapper
<
TopicEntity
>
updateWrapper
=
new
UpdateWrapper
<>();
updateWrapper
.
eq
(
"id"
,
topicId
);
updateWrapper
.
set
(
"isTop"
,
false
);
topicMapper
.
update
(
null
,
updateWrapper
);
}
public
void
updateTopicToConceal
(
String
topicId
){
UpdateWrapper
<
TopicEntity
>
updateWrapper
=
new
UpdateWrapper
<>();
updateWrapper
.
eq
(
"id"
,
topicId
);
updateWrapper
.
set
(
"isConceal"
,
true
);
topicMapper
.
update
(
null
,
updateWrapper
);
}
public
void
updateTopicNotConceal
(
String
topicId
){
UpdateWrapper
<
TopicEntity
>
updateWrapper
=
new
UpdateWrapper
<>();
updateWrapper
.
eq
(
"id"
,
topicId
);
updateWrapper
.
set
(
"isConceal"
,
false
);
topicMapper
.
update
(
null
,
updateWrapper
);
}
public
TopicEntity
queryById
(
String
topicId
)
{
return
topicMapper
.
selectById
(
topicId
);
}
}
docs/create.sql
View file @
07d7c66a
...
...
@@ -82,7 +82,7 @@ CREATE TABLE `collection` (
CREATE
TABLE
`topic`
(
`id`
varchar
(
64
)
PRIMARY
KEY
COMMENT
'id'
,
`topic_title`
int
(
4
)
NOT
NULL
COMMENT
'话题名称'
,
`topic_title`
varchar
(
6
4
)
NOT
NULL
COMMENT
'话题名称'
,
`is_top`
int
(
4
)
NOT
NULL
COMMENT
'是否置顶'
,
`is_conceal`
int
(
4
)
NOT
NULL
COMMENT
'是否隐藏'
,
`create_by`
varchar
(
64
)
DEFAULT
''
,
...
...
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