Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
35986ecc
Commit
35986ecc
authored
Feb 06, 2020
by
胡学良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改删除回复
parent
66cb99ac
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
65 additions
and
121 deletions
+65
-121
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionApi.java
+5
-8
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReplyApi.java
+1
-1
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReplyCommentApi.java
+1
-1
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionErrorCode.java
+6
-0
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionTagErrorCode.java
+2
-2
src/main/java/cn/meteor/beyondclouds/modules/question/form/QuestionUpdateForm.java
+0
-44
src/main/java/cn/meteor/beyondclouds/modules/question/service/IQuestionTagService.java
+0
-7
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyCommentServiceImpl.java
+4
-4
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyServiceImpl.java
+25
-7
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionServiceImpl.java
+21
-32
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionTagServiceImpl.java
+0
-15
No files found.
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionApi.java
View file @
35986ecc
...
@@ -15,20 +15,17 @@ import cn.meteor.beyondclouds.modules.question.exception.QuestionTagServiceExcep
...
@@ -15,20 +15,17 @@ import cn.meteor.beyondclouds.modules.question.exception.QuestionTagServiceExcep
import
cn.meteor.beyondclouds.modules.question.form.QuestionForm
;
import
cn.meteor.beyondclouds.modules.question.form.QuestionForm
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionService
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionService
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionTagService
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionTagService
;
import
cn.meteor.beyondclouds.modules.question.util.QuestionUtils
;
import
cn.meteor.beyondclouds.modules.tag.entity.Tag
;
import
cn.meteor.beyondclouds.modules.tag.entity.Tag
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -59,14 +56,14 @@ public class QuestionApi {
...
@@ -59,14 +56,14 @@ public class QuestionApi {
*/
*/
@ApiOperation
(
"发布问题"
)
@ApiOperation
(
"发布问题"
)
@PostMapping
(
"/question"
)
@PostMapping
(
"/question"
)
public
Response
postQuestion
(
@RequestBody
@Validated
(
InsertGroup
.
class
)
QuestionForm
questionForm
,
BindingResult
result
,
@CurrentSubject
Subject
subject
){
public
Response
postQuestion
(
@RequestBody
@Validated
(
InsertGroup
.
class
)
QuestionForm
questionForm
,
BindingResult
result
,
@CurrentSubject
Subject
subject
)
{
if
(
result
.
hasErrors
())
{
if
(
result
.
hasErrors
())
{
return
Response
.
fieldError
(
result
.
getFieldError
());
return
Response
.
fieldError
(
result
.
getFieldError
());
}
}
//将问题表单转换为问题对象
//将问题表单转换为问题对象
Question
question
=
new
Question
();
Question
question
=
new
Question
();
BeanUtils
.
copyProperties
(
questionForm
,
question
);
BeanUtils
.
copyProperties
(
questionForm
,
question
);
question
.
setCategoryId
(
questionForm
.
getCategoryId
());
question
.
setCategoryId
(
questionForm
.
getCategoryId
());
//设置用户ID(问题发布者ID)
//设置用户ID(问题发布者ID)
...
@@ -90,7 +87,7 @@ public class QuestionApi {
...
@@ -90,7 +87,7 @@ public class QuestionApi {
*/
*/
@ApiOperation
(
"删除问题"
)
@ApiOperation
(
"删除问题"
)
@DeleteMapping
(
"/question/{questionId}"
)
@DeleteMapping
(
"/question/{questionId}"
)
public
Response
deleteQuestion
(
@PathVariable
(
"questionId"
)
String
questionId
,
@CurrentSubject
Subject
subject
){
public
Response
deleteQuestion
(
@PathVariable
(
"questionId"
)
String
questionId
,
@CurrentSubject
Subject
subject
)
{
try
{
try
{
questionService
.
deleteQuestion
(
questionId
,
(
String
)
subject
.
getId
());
questionService
.
deleteQuestion
(
questionId
,
(
String
)
subject
.
getId
());
return
Response
.
success
();
return
Response
.
success
();
...
@@ -110,7 +107,7 @@ public class QuestionApi {
...
@@ -110,7 +107,7 @@ public class QuestionApi {
*/
*/
@ApiOperation
(
"修改问题"
)
@ApiOperation
(
"修改问题"
)
@PutMapping
(
"/question/{questionId}"
)
@PutMapping
(
"/question/{questionId}"
)
public
Response
modifyQuestion
(
@PathVariable
(
"questionId"
)
String
questionId
,
@RequestBody
@Validated
(
UpdateGroup
.
class
)
QuestionForm
questionForm
,
BindingResult
result
,
@CurrentSubject
Subject
subject
){
public
Response
modifyQuestion
(
@PathVariable
(
"questionId"
)
String
questionId
,
@RequestBody
@Validated
(
UpdateGroup
.
class
)
QuestionForm
questionForm
,
BindingResult
result
,
@CurrentSubject
Subject
subject
)
{
if
(
result
.
hasErrors
())
{
if
(
result
.
hasErrors
())
{
return
Response
.
fieldError
(
result
.
getFieldError
());
return
Response
.
fieldError
(
result
.
getFieldError
());
}
}
...
@@ -143,7 +140,7 @@ public class QuestionApi {
...
@@ -143,7 +140,7 @@ public class QuestionApi {
@Anonymous
@Anonymous
@ApiOperation
(
"问题详情"
)
@ApiOperation
(
"问题详情"
)
@GetMapping
(
"/question/{questionId}"
)
@GetMapping
(
"/question/{questionId}"
)
public
Response
<
QuestionDetails
>
questionDetails
(
@PathVariable
(
"questionId"
)
String
questionId
){
public
Response
<
QuestionDetails
>
questionDetails
(
@PathVariable
(
"questionId"
)
String
questionId
)
{
QuestionDetails
questionDetails
=
null
;
QuestionDetails
questionDetails
=
null
;
try
{
try
{
questionDetails
=
questionService
.
questionDetails
(
questionId
);
questionDetails
=
questionService
.
questionDetails
(
questionId
);
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReplyApi.java
View file @
35986ecc
...
@@ -42,7 +42,7 @@ public class QuestionReplyApi {
...
@@ -42,7 +42,7 @@ public class QuestionReplyApi {
*/
*/
@ApiOperation
(
"发布回复"
)
@ApiOperation
(
"发布回复"
)
@PostMapping
(
"/question/{questionId}/reply"
)
@PostMapping
(
"/question/{questionId}/reply"
)
public
Response
replyQuestion
(
@PathVariable
(
"questionId"
)
String
questionId
,
String
reply
,
@CurrentSubject
Subject
subject
){
public
Response
replyQuestion
(
@PathVariable
(
"questionId"
)
String
questionId
,
String
reply
,
@CurrentSubject
Subject
subject
)
{
try
{
try
{
questionReplyService
.
replyQuestion
(
questionId
,
reply
,
(
String
)
subject
.
getId
());
questionReplyService
.
replyQuestion
(
questionId
,
reply
,
(
String
)
subject
.
getId
());
return
Response
.
success
();
return
Response
.
success
();
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReplyCommentApi.java
View file @
35986ecc
...
@@ -46,7 +46,7 @@ public class QuestionReplyCommentApi {
...
@@ -46,7 +46,7 @@ public class QuestionReplyCommentApi {
@ApiOperation
(
"发表评论"
)
@ApiOperation
(
"发表评论"
)
@PostMapping
(
"/question/reply/{replyId}/comment"
)
@PostMapping
(
"/question/reply/{replyId}/comment"
)
public
Response
publishReplyComment
(
@RequestBody
@Valid
QuestionReplyCommentForm
questionReplyCommentForm
,
BindingResult
bindingResult
,
public
Response
publishReplyComment
(
@RequestBody
@Valid
QuestionReplyCommentForm
questionReplyCommentForm
,
BindingResult
bindingResult
,
@PathVariable
(
"replyId"
)
String
replyId
,
@CurrentSubject
Subject
subject
){
@PathVariable
(
"replyId"
)
String
replyId
,
@CurrentSubject
Subject
subject
)
{
if
(
bindingResult
.
hasErrors
())
{
if
(
bindingResult
.
hasErrors
())
{
return
Response
.
fieldError
(
bindingResult
.
getFieldError
());
return
Response
.
fieldError
(
bindingResult
.
getFieldError
());
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionErrorCode.java
View file @
35986ecc
...
@@ -11,7 +11,13 @@ public enum QuestionErrorCode implements IErrorCode {
...
@@ -11,7 +11,13 @@ public enum QuestionErrorCode implements IErrorCode {
* 问题没有以?结尾
* 问题没有以?结尾
*/
*/
QUESTION_END_ERROR
(
3001
,
"问题没有以?结尾"
),
QUESTION_END_ERROR
(
3001
,
"问题没有以?结尾"
),
/**
* 问题的类别ID错误
*/
INCORRECT_CATEGORY
(
3002
,
"问题类别错误"
),
INCORRECT_CATEGORY
(
3002
,
"问题类别错误"
),
/**
* 找不到该问题
*/
QUESTION_NOT_FOUND
(
3003
,
"找不到该问题"
);
QUESTION_NOT_FOUND
(
3003
,
"找不到该问题"
);
private
long
code
;
private
long
code
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionTagErrorCode.java
View file @
35986ecc
...
@@ -19,11 +19,11 @@ public enum QuestionTagErrorCode implements IErrorCode {
...
@@ -19,11 +19,11 @@ public enum QuestionTagErrorCode implements IErrorCode {
@Override
@Override
public
long
code
()
{
public
long
code
()
{
return
0
;
return
code
;
}
}
@Override
@Override
public
String
msg
()
{
public
String
msg
()
{
return
null
;
return
msg
;
}
}
}
}
src/main/java/cn/meteor/beyondclouds/modules/question/form/QuestionUpdateForm.java
deleted
100644 → 0
View file @
66cb99ac
package
cn
.
meteor
.
beyondclouds
.
modules
.
question
.
form
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotEmpty
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Size
;
import
java.util.List
;
/**
* @author 胡学良
* @since 2020/1/31
*/
@ApiModel
(
value
=
"QuestionForm"
,
description
=
"问题表单"
)
@Data
public
class
QuestionUpdateForm
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
"类别ID"
)
@NotNull
(
message
=
"问题类别ID不能为空"
)
private
Integer
categoryId
;
@ApiModelProperty
(
"标题"
)
@NotEmpty
(
message
=
"问题标题不能为空"
)
@Size
(
max
=
256
,
message
=
"问题标题太长"
)
private
String
questionTitle
;
@ApiModelProperty
(
"摘要"
)
@Size
(
max
=
256
,
message
=
"问题摘要太长"
)
private
String
questionAbstract
;
@ApiModelProperty
(
"标签"
)
@Size
(
max
=
12
,
message
=
"问题标签个数不能超过5个"
)
private
List
<
String
>
tagIds
;
@ApiModelProperty
(
"详情"
)
private
String
questionDetail
;
@ApiModelProperty
(
"话题ID"
)
private
List
<
String
>
topicIds
;
}
src/main/java/cn/meteor/beyondclouds/modules/question/service/IQuestionTagService.java
View file @
35986ecc
...
@@ -18,13 +18,6 @@ import java.util.List;
...
@@ -18,13 +18,6 @@ import java.util.List;
*/
*/
public
interface
IQuestionTagService
extends
IService
<
QuestionTag
>
{
public
interface
IQuestionTagService
extends
IService
<
QuestionTag
>
{
/**
* 保存问题标签
* @param tags 问题对应标签
* @param questionId 问题ID
*/
void
saveQuestionTag
(
HashSet
<
String
>
tags
,
String
questionId
);
/**
/**
* 得到问题引用标签
* 得到问题引用标签
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyCommentServiceImpl.java
View file @
35986ecc
...
@@ -71,8 +71,8 @@ public class QuestionReplyCommentServiceImpl extends ServiceImpl<QuestionReplyCo
...
@@ -71,8 +71,8 @@ public class QuestionReplyCommentServiceImpl extends ServiceImpl<QuestionReplyCo
//2.判断父评论是否存在
//2.判断父评论是否存在
if
(!
StringUtils
.
isEmpty
(
parentId
))
{
if
(!
StringUtils
.
isEmpty
(
parentId
))
{
QueryWrapper
<
QuestionReplyComment
>
questionReplyCommentQueryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
QuestionReplyComment
>
questionReplyCommentQueryWrapper
=
new
QueryWrapper
<>();
questionReplyCommentQueryWrapper
.
eq
(
"reply_id"
,
replyId
)
questionReplyCommentQueryWrapper
.
eq
(
"reply_id"
,
replyId
)
.
eq
(
"comment_id"
,
parentId
);
.
eq
(
"comment_id"
,
parentId
);
parentQuestionReplyComment
=
getOne
(
questionReplyCommentQueryWrapper
);
parentQuestionReplyComment
=
getOne
(
questionReplyCommentQueryWrapper
);
//若父评论为空,则抛出父评论不存在异常
//若父评论为空,则抛出父评论不存在异常
if
(
null
==
parentQuestionReplyComment
)
{
if
(
null
==
parentQuestionReplyComment
)
{
...
@@ -95,11 +95,11 @@ public class QuestionReplyCommentServiceImpl extends ServiceImpl<QuestionReplyCo
...
@@ -95,11 +95,11 @@ public class QuestionReplyCommentServiceImpl extends ServiceImpl<QuestionReplyCo
if
(
null
!=
parentQuestionReplyComment
)
{
if
(
null
!=
parentQuestionReplyComment
)
{
//子级评论
//子级评论
questionReplyComment
.
setDepth
(
parentQuestionReplyComment
.
getDepth
()+
1
);
questionReplyComment
.
setDepth
(
parentQuestionReplyComment
.
getDepth
()+
1
);
questionReplyComment
.
setThread
(
parentQuestionReplyComment
.
getThread
()
+
"/"
+
questionReplyComment
.
getCommentId
());
questionReplyComment
.
setThread
(
parentQuestionReplyComment
.
getThread
()
+
"/"
+
questionReplyComment
.
getCommentId
());
}
else
{
}
else
{
//1级评论
//1级评论
questionReplyComment
.
setDepth
(
0
);
questionReplyComment
.
setDepth
(
0
);
questionReplyComment
.
setThread
(
"/"
+
questionReplyComment
.
getCommentId
());
questionReplyComment
.
setThread
(
"/"
+
questionReplyComment
.
getCommentId
());
}
}
updateById
(
questionReplyComment
);
updateById
(
questionReplyComment
);
}
}
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyServiceImpl.java
View file @
35986ecc
...
@@ -20,6 +20,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...
@@ -20,6 +20,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* <p>
* <p>
* 问题回复表 服务实现类
* 问题回复表 服务实现类
...
@@ -86,7 +89,7 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
...
@@ -86,7 +89,7 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
//更新问题的回复数量
//更新问题的回复数量
UpdateWrapper
<
Question
>
questionUpdateWrapper
=
new
UpdateWrapper
<>();
UpdateWrapper
<
Question
>
questionUpdateWrapper
=
new
UpdateWrapper
<>();
questionUpdateWrapper
.
set
(
"reply_number"
,
question
.
getReplyNumber
()
+
1
)
questionUpdateWrapper
.
set
(
"reply_number"
,
question
.
getReplyNumber
()
+
1
)
.
eq
(
"question_id"
,
questionId
);
.
eq
(
"question_id"
,
questionId
);
questionService
.
update
(
questionUpdateWrapper
);
questionService
.
update
(
questionUpdateWrapper
);
}
}
...
@@ -121,14 +124,14 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
...
@@ -121,14 +124,14 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
//4.采纳回复
//4.采纳回复
UpdateWrapper
<
QuestionReply
>
updateWrapper
=
new
UpdateWrapper
<>();
UpdateWrapper
<
QuestionReply
>
updateWrapper
=
new
UpdateWrapper
<>();
updateWrapper
.
set
(
"reply_status"
,
ADOPTED_REPLY_STATUS
).
eq
(
"reply_id"
,
replyId
);
updateWrapper
.
set
(
"reply_status"
,
ADOPTED_REPLY_STATUS
).
eq
(
"reply_id"
,
replyId
);
update
(
updateWrapper
);
update
(
updateWrapper
);
//5.更新问题状态
//5.更新问题状态
if
(!
question
.
getSolved
())
{
if
(!
question
.
getSolved
())
{
UpdateWrapper
<
Question
>
questionUpdateWrapper
=
new
UpdateWrapper
<>();
UpdateWrapper
<
Question
>
questionUpdateWrapper
=
new
UpdateWrapper
<>();
questionUpdateWrapper
.
set
(
"solved"
,
true
)
questionUpdateWrapper
.
set
(
"solved"
,
true
)
.
eq
(
"question_id"
,
questionId
);
.
eq
(
"question_id"
,
questionId
);
questionService
.
update
(
questionUpdateWrapper
);
questionService
.
update
(
questionUpdateWrapper
);
}
}
}
}
...
@@ -145,7 +148,7 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
...
@@ -145,7 +148,7 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
//2.得到页面信息
//2.得到页面信息
IPage
<
QuestionReply
>
questionReplyPage
=
new
Page
<>(
pageNumber
,
pageSize
);
IPage
<
QuestionReply
>
questionReplyPage
=
new
Page
<>(
pageNumber
,
pageSize
);
return
page
(
questionReplyPage
,
QuestionUtils
.
getWrapper
(
"question_id"
,
questionId
));
return
page
(
questionReplyPage
,
QuestionUtils
.
getWrapper
(
"question_id"
,
questionId
));
}
}
@Override
@Override
...
@@ -165,14 +168,29 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
...
@@ -165,14 +168,29 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
}
}
//3.删除该回复及评论
//3.删除该回复及评论
questionReplyCommentService
.
remove
(
QuestionUtils
.
getWrapper
(
"reply_id"
,
replyId
));
questionReplyCommentService
.
remove
(
QuestionUtils
.
getWrapper
(
"reply_id"
,
replyId
));
removeById
(
replyId
);
removeById
(
replyId
);
//4.更新问题的回复数量
//4.更新问题的回复数量
UpdateWrapper
<
Question
>
questionUpdateWrapper
=
new
UpdateWrapper
<>();
UpdateWrapper
<
Question
>
questionUpdateWrapper
=
new
UpdateWrapper
<>();
questionUpdateWrapper
.
set
(
"reply_number"
,
question
.
getReplyNumber
()-
1
)
questionUpdateWrapper
.
set
(
"reply_number"
,
question
.
getReplyNumber
()
-
1
)
.
eq
(
"question_id"
,
question
.
getQuestionId
());
.
eq
(
"question_id"
,
question
.
getQuestionId
());
questionService
.
update
(
questionUpdateWrapper
);
questionService
.
update
(
questionUpdateWrapper
);
//5.更新问题的状态,如果删除回复后问题的采纳回复数为0且问题之前为已解决状态,则需要将其变为未解决
if
(
1
==
questionReply
.
getReplyStatus
())
{
//查询数据库中该问题已采纳回复的数目
QueryWrapper
<
QuestionReply
>
questionReplyQueryWrapper
=
new
QueryWrapper
<>();
questionReplyQueryWrapper
.
eq
(
"question_id"
,
question
.
getQuestionId
())
.
eq
(
"reply_status"
,
1
);
List
<
QuestionReply
>
questionReplies
=
list
(
questionReplyQueryWrapper
);
if
(
questionReplies
.
size
()
==
0
&&
question
.
getSolved
())
{
UpdateWrapper
<
Question
>
solvedUpdateWrapper
=
new
UpdateWrapper
<>();
solvedUpdateWrapper
.
set
(
"solved"
,
false
)
.
eq
(
"question_id"
,
question
.
getQuestionId
());
questionService
.
update
(
solvedUpdateWrapper
);
}
}
}
}
@Override
@Override
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionServiceImpl.java
View file @
35986ecc
...
@@ -29,7 +29,6 @@ import org.springframework.util.CollectionUtils;
...
@@ -29,7 +29,6 @@ import org.springframework.util.CollectionUtils;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -114,7 +113,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
...
@@ -114,7 +113,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
//3.检查问题摘要是否为空,若为空则自动填充
//3.检查问题摘要是否为空,若为空则自动填充
if
(
StringUtils
.
isEmpty
(
question
.
getQuestionAbstract
()))
{
if
(
StringUtils
.
isEmpty
(
question
.
getQuestionAbstract
()))
{
question
.
setQuestionAbstract
(
AbstractUtils
.
extractWithoutHtml
(
questionDetail
,
20
));
question
.
setQuestionAbstract
(
AbstractUtils
.
extractWithoutHtml
(
questionDetail
,
20
));
}
}
//3.保存问题信息
//3.保存问题信息
...
@@ -171,38 +170,37 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
...
@@ -171,38 +170,37 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
@Override
public
void
deleteQuestion
(
String
questionId
,
String
userId
)
throws
QuestionServiceException
{
public
void
deleteQuestion
(
String
questionId
,
String
userId
)
throws
QuestionServiceException
{
//1.判断自己是否发布过此问题
//1.判断自己是否发布过此问题
QueryWrapper
<
Question
>
questionQueryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
Question
>
questionQueryWrapper
=
new
QueryWrapper
<>();
questionQueryWrapper
.
eq
(
"question_id"
,
questionId
)
questionQueryWrapper
.
eq
(
"question_id"
,
questionId
)
.
eq
(
"user_id"
,
userId
);
.
eq
(
"user_id"
,
userId
);
Question
question
=
getOne
(
questionQueryWrapper
);
Question
question
=
getOne
(
questionQueryWrapper
);
if
(
null
==
question
)
{
if
(
null
==
question
)
{
throw
new
QuestionServiceException
(
QuestionErrorCode
.
QUESTION_NOT_FOUND
);
throw
new
QuestionServiceException
(
QuestionErrorCode
.
QUESTION_NOT_FOUND
);
}
}
//2.删除question-tag表中关于该问题的标签
//2.删除question-tag表中关于该问题的标签
questionTagService
.
remove
(
QuestionUtils
.
getWrapper
(
"question_id"
,
questionId
));
questionTagService
.
remove
(
QuestionUtils
.
getWrapper
(
"question_id"
,
questionId
));
//3.获取该问题的所有回复
//3.获取该问题的所有回复
List
<
QuestionReply
>
questionReplies
=
questionReplyService
.
list
(
QuestionUtils
.
getWrapper
(
"question_id"
,
questionId
));
List
<
QuestionReply
>
questionReplies
=
questionReplyService
.
list
(
QuestionUtils
.
getWrapper
(
"question_id"
,
questionId
));
//4.删除question-reply-comment表中关于该问题的所有回复
//4.删除question-reply-comment表中关于该问题的所有回复
for
(
QuestionReply
questionReply
:
questionReplies
){
List
<
String
>
replyIds
=
questionReplies
.
stream
().
map
(
QuestionReply:
:
getReplyId
).
collect
(
Collectors
.
toList
());
questionReplyCommentService
.
remove
(
QuestionUtils
.
getWrapper
(
"reply_id"
,
questionReply
.
getReplyId
()));
questionReplyCommentService
.
removeByIds
(
replyIds
);
}
//5.删除question-reply表中关于该问题的所有回复
//5.删除question-reply表中关于该问题的所有回复
questionReplyService
.
remove
(
QuestionUtils
.
getWrapper
(
"question_id"
,
questionId
));
questionReplyService
.
remove
(
QuestionUtils
.
getWrapper
(
"question_id"
,
questionId
));
//6.删除question-ext表中的问题信息
//6.删除question-ext表中的问题信息
questionExtService
.
remove
(
QuestionUtils
.
getWrapper
(
"question_id"
,
questionId
));
questionExtService
.
remove
(
QuestionUtils
.
getWrapper
(
"question_id"
,
questionId
));
//7.删除question表中的问题信息
//7.删除question表中的问题信息
removeById
(
questionId
);
removeById
(
questionId
);
//8.删除话题引用表中的问题信息
//8.删除话题引用表中的问题信息
topicReferenceService
.
remove
(
QuestionUtils
.
getWrapper
(
"referencer_id"
,
question
.
getQuestionId
()));
topicReferenceService
.
remove
(
QuestionUtils
.
getWrapper
(
"referencer_id"
,
question
.
getQuestionId
()));
}
}
...
@@ -211,8 +209,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
...
@@ -211,8 +209,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
public
void
updateQuestion
(
Question
question
,
String
questionDetail
,
List
<
String
>
tagIds
,
List
<
String
>
topicIds
)
throws
QuestionServiceException
{
public
void
updateQuestion
(
Question
question
,
String
questionDetail
,
List
<
String
>
tagIds
,
List
<
String
>
topicIds
)
throws
QuestionServiceException
{
//1.判断自己是否发布过此问题
//1.判断自己是否发布过此问题
QueryWrapper
<
Question
>
questionQueryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
Question
>
questionQueryWrapper
=
new
QueryWrapper
<>();
questionQueryWrapper
.
eq
(
"question_id"
,
question
.
getQuestionId
())
questionQueryWrapper
.
eq
(
"question_id"
,
question
.
getQuestionId
())
.
eq
(
"user_id"
,
question
.
getUserId
());
.
eq
(
"user_id"
,
question
.
getUserId
());
Question
questionInDb
=
getOne
(
questionQueryWrapper
);
Question
questionInDb
=
getOne
(
questionQueryWrapper
);
if
(
null
==
questionInDb
)
{
if
(
null
==
questionInDb
)
{
throw
new
QuestionServiceException
(
QuestionErrorCode
.
QUESTION_NOT_FOUND
);
throw
new
QuestionServiceException
(
QuestionErrorCode
.
QUESTION_NOT_FOUND
);
...
@@ -220,7 +218,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
...
@@ -220,7 +218,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
//2.检查问题标题是否以?结尾
//2.检查问题标题是否以?结尾
if
(!
StringUtils
.
isEmpty
(
question
.
getQuestionTitle
()))
{
if
(!
StringUtils
.
isEmpty
(
question
.
getQuestionTitle
()))
{
if
(!
question
.
getQuestionTitle
().
endsWith
(
QUESTION_END_EN
)
&&
!
question
.
getQuestionTitle
().
endsWith
(
QUESTION_END_CN
)){
if
(!
question
.
getQuestionTitle
().
endsWith
(
QUESTION_END_EN
)
&&
!
question
.
getQuestionTitle
().
endsWith
(
QUESTION_END_CN
))
{
throw
new
QuestionServiceException
(
QuestionErrorCode
.
QUESTION_END_ERROR
);
throw
new
QuestionServiceException
(
QuestionErrorCode
.
QUESTION_END_ERROR
);
}
}
}
}
...
@@ -239,12 +237,9 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
...
@@ -239,12 +237,9 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
//3.更新问题扩展信息
//3.更新问题扩展信息
if
(!
StringUtils
.
isEmpty
(
questionDetail
))
{
if
(!
StringUtils
.
isEmpty
(
questionDetail
))
{
QuestionExt
questionExt
=
new
QuestionExt
();
questionExt
.
setQuestionId
(
question
.
getQuestionId
());
questionExt
.
setQuestionDetail
(
questionDetail
);
UpdateWrapper
<
QuestionExt
>
updateWrapper
=
new
UpdateWrapper
<>();
UpdateWrapper
<
QuestionExt
>
updateWrapper
=
new
UpdateWrapper
<>();
updateWrapper
.
eq
(
"question_id"
,
question
.
getQuestionId
());
updateWrapper
.
set
(
"question_detail"
,
questionDetail
).
eq
(
"question_id"
,
question
.
getQuestionId
());
questionExtService
.
update
(
questionExt
,
updateWrapper
);
questionExtService
.
update
(
updateWrapper
);
}
}
//5.判断是否引用话题
//5.判断是否引用话题
...
@@ -253,9 +248,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
...
@@ -253,9 +248,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
List
<
String
>
existsTopicIds
=
topicService
.
listByIds
(
topicIds
).
stream
().
map
(
Topic:
:
getTopicId
).
collect
(
Collectors
.
toList
());
List
<
String
>
existsTopicIds
=
topicService
.
listByIds
(
topicIds
).
stream
().
map
(
Topic:
:
getTopicId
).
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
existsTopicIds
))
{
if
(!
CollectionUtils
.
isEmpty
(
existsTopicIds
))
{
// 删除旧话题引用
// 删除旧话题引用
QueryWrapper
<
TopicReference
>
topicReferenceQueryWrapper
=
new
QueryWrapper
<>();
topicReferenceService
.
remove
(
QuestionUtils
.
getWrapper
(
"referencer_id"
,
question
.
getQuestionId
()));
topicReferenceQueryWrapper
.
eq
(
"referencer_id"
,
question
.
getQuestionId
());
topicReferenceService
.
remove
(
topicReferenceQueryWrapper
);
List
<
TopicReference
>
topicReferenceList
=
new
ArrayList
<>();
List
<
TopicReference
>
topicReferenceList
=
new
ArrayList
<>();
...
@@ -281,9 +274,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
...
@@ -281,9 +274,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
List
<
String
>
existsTagIds
=
tagService
.
listByIds
(
tagIds
).
stream
().
filter
(
tag
->
2
==
tag
.
getTagType
()).
map
(
Tag:
:
getTagId
).
collect
(
Collectors
.
toList
());
List
<
String
>
existsTagIds
=
tagService
.
listByIds
(
tagIds
).
stream
().
filter
(
tag
->
2
==
tag
.
getTagType
()).
map
(
Tag:
:
getTagId
).
collect
(
Collectors
.
toList
());
if
(!
CollectionUtils
.
isEmpty
(
existsTagIds
))
{
if
(!
CollectionUtils
.
isEmpty
(
existsTagIds
))
{
// 删除旧标签
// 删除旧标签
QueryWrapper
<
QuestionTag
>
questionTagQueryWrapper
=
new
QueryWrapper
<>();
questionTagService
.
remove
(
QuestionUtils
.
getWrapper
(
"question_id"
,
question
.
getQuestionId
()));
questionTagQueryWrapper
.
eq
(
"question_id"
,
question
.
getQuestionId
());
questionTagService
.
remove
(
questionTagQueryWrapper
);
List
<
QuestionTag
>
questionTagList
=
new
ArrayList
<>();
List
<
QuestionTag
>
questionTagList
=
new
ArrayList
<>();
for
(
String
tagId
:
existsTagIds
)
{
for
(
String
tagId
:
existsTagIds
)
{
...
@@ -320,10 +311,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
...
@@ -320,10 +311,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
//5.获取话题详情
//5.获取话题详情
List
<
TopicReference
>
references
=
topicReferenceService
.
list
(
QuestionUtils
.
getWrapper
(
"referencer_id"
,
question
.
getQuestionId
()));
List
<
TopicReference
>
references
=
topicReferenceService
.
list
(
QuestionUtils
.
getWrapper
(
"referencer_id"
,
question
.
getQuestionId
()));
List
<
Topic
>
topics
=
new
ArrayList
<>();
List
<
String
>
topicIds
=
references
.
stream
().
map
(
TopicReference:
:
getTopicId
).
collect
(
Collectors
.
toList
());
for
(
TopicReference
topicReference
:
references
)
{
List
<
Topic
>
topics
=
topicService
.
listByIds
(
topicIds
);
topics
.
add
(
topicService
.
getById
(
topicReference
.
getTopicId
()));
}
if
(
CollectionUtils
.
isEmpty
(
topics
))
{
if
(
CollectionUtils
.
isEmpty
(
topics
))
{
question
.
setTopics
(
List
.
of
());
question
.
setTopics
(
List
.
of
());
...
@@ -341,7 +330,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
...
@@ -341,7 +330,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
@Override
@Override
public
IPage
<
Question
>
getQuestionPage
(
Integer
pageNumber
,
Integer
pageSize
)
{
public
IPage
<
Question
>
getQuestionPage
(
Integer
pageNumber
,
Integer
pageSize
)
{
IPage
<
Question
>
page
=
new
Page
<>(
pageNumber
,
pageSize
);
IPage
<
Question
>
page
=
new
Page
<>(
pageNumber
,
pageSize
);
QueryWrapper
<
Question
>
questionQueryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
Question
>
questionQueryWrapper
=
new
QueryWrapper
<>();
questionQueryWrapper
.
orderByDesc
(
"q.create_time"
);
questionQueryWrapper
.
orderByDesc
(
"q.create_time"
);
return
questionMapper
.
selectPageWithTags
(
page
,
questionQueryWrapper
);
return
questionMapper
.
selectPageWithTags
(
page
,
questionQueryWrapper
);
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionTagServiceImpl.java
View file @
35986ecc
...
@@ -45,21 +45,6 @@ public class QuestionTagServiceImpl extends ServiceImpl<QuestionTagMapper, Quest
...
@@ -45,21 +45,6 @@ public class QuestionTagServiceImpl extends ServiceImpl<QuestionTagMapper, Quest
this
.
questionService
=
questionService
;
this
.
questionService
=
questionService
;
}
}
@Override
public
void
saveQuestionTag
(
HashSet
<
String
>
tags
,
String
questionId
)
{
Iterator
<
String
>
iterator
=
tags
.
iterator
();
QuestionTag
questionTag
;
while
(
iterator
.
hasNext
()){
Tag
tag
=
tagService
.
getById
(
iterator
.
next
());
if
(
tag
==
null
||
tag
.
getTagType
()
!=
2
)
{
continue
;
}
questionTag
=
new
QuestionTag
();
questionTag
.
setQuestionId
(
questionId
);
questionTag
.
setTagId
(
tag
.
getTagId
());
save
(
questionTag
);
}
}
@Override
@Override
public
List
<
Tag
>
getQuestionTags
(
String
questionId
)
throws
QuestionTagServiceException
{
public
List
<
Tag
>
getQuestionTags
(
String
questionId
)
throws
QuestionTagServiceException
{
...
...
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