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
7ba6467d
Commit
7ba6467d
authored
Feb 11, 2020
by
胡学良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
取消回复的采纳
parent
bbced110
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
2 deletions
+80
-2
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReplyApi.java
+12
-0
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionReplyErrorCode.java
+5
-1
src/main/java/cn/meteor/beyondclouds/modules/question/service/IQuestionReplyService.java
+10
-0
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyServiceImpl.java
+52
-0
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReplyApi.java
View file @
7ba6467d
...
...
@@ -114,4 +114,16 @@ public class QuestionReplyApi {
return
Response
.
error
(
e
);
}
}
@ApiOperation
(
"取消采纳回复"
)
@PutMapping
(
"/question/reply/{replyId}/cancelAdoption"
)
public
Response
cancelQuestionAdoption
(
String
questionId
,
@PathVariable
(
"replyId"
)
String
replyId
,
@CurrentSubject
Subject
subject
)
{
try
{
questionReplyService
.
cancelReplyAdoption
(
questionId
,
replyId
,
(
String
)
subject
.
getId
());
return
Response
.
success
();
}
catch
(
QuestionReplyServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
}
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionReplyErrorCode.java
View file @
7ba6467d
...
...
@@ -18,7 +18,11 @@ public enum QuestionReplyErrorCode implements IErrorCode {
/**
* 无权删除评论
*/
NO_DELETE_PRIVILEGES
(
4003
,
"无权删除该回复"
);
NO_DELETE_PRIVILEGES
(
4003
,
"无权删除该回复"
),
/**
* 回复未被采纳
*/
REPLY_NOT_ADOPTED
(
4004
,
"回复未被采纳"
);
private
long
code
;
private
String
msg
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/question/service/IQuestionReplyService.java
View file @
7ba6467d
...
...
@@ -2,6 +2,7 @@ package cn.meteor.beyondclouds.modules.question.service;
import
cn.meteor.beyondclouds.modules.question.entity.QuestionReply
;
import
cn.meteor.beyondclouds.modules.question.exception.QuestionReplyServiceException
;
import
cn.meteor.beyondclouds.modules.question.exception.QuestionServiceException
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.IService
;
...
...
@@ -70,4 +71,13 @@ public interface IQuestionReplyService extends IService<QuestionReply> {
* @param userId 用户ID
*/
void
updateQuestionReplyUserAvatar
(
String
userId
);
/**
* 取消采纳回复
* @param questionId 问题ID
* @param replyId 回复ID
* @param userId 用户ID
* @throws QuestionReplyServiceException 问题回复业务异常
*/
void
cancelReplyAdoption
(
String
questionId
,
String
replyId
,
String
userId
)
throws
QuestionReplyServiceException
;
}
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyServiceImpl.java
View file @
7ba6467d
...
...
@@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -36,6 +37,8 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
private
int
ADOPTED_REPLY_STATUS
=
1
;
private
int
NOT_ADOPTED_REPLY_STATUS
=
0
;
private
IQuestionService
questionService
;
private
IQuestionReplyCommentService
questionReplyCommentService
;
...
...
@@ -219,4 +222,53 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
update
(
questionReplyUpdateWrapper
);
}
}
@Override
public
void
cancelReplyAdoption
(
String
questionId
,
String
replyId
,
String
userId
)
throws
QuestionReplyServiceException
{
//1.判断用户是否发布过该问题
QueryWrapper
<
Question
>
questionQueryWrapper
=
new
QueryWrapper
<>();
questionQueryWrapper
.
eq
(
"user_id"
,
userId
)
.
eq
(
"question_id"
,
questionId
);
Question
question
=
questionService
.
getOne
(
questionQueryWrapper
);
//若问题不存在,则抛出问题不存在异常
if
(
null
==
question
)
{
throw
new
QuestionReplyServiceException
(
QuestionErrorCode
.
QUESTION_NOT_FOUND
);
}
//2.判断该问题的回复是否存在
QueryWrapper
<
QuestionReply
>
questionReplyQueryWrapper
=
new
QueryWrapper
<>();
questionReplyQueryWrapper
.
eq
(
"question_id"
,
questionId
)
.
eq
(
"reply_id"
,
replyId
);
QuestionReply
questionReply
=
getOne
(
questionReplyQueryWrapper
);
//若该回复不存在,则抛出回复不存在异常
if
(
null
==
questionReply
)
{
throw
new
QuestionReplyServiceException
(
QuestionReplyErrorCode
.
REPLY_NOT_FOUND
);
}
//3.判断该回复之前是否已被采纳,若未被采纳,则抛出回复未被采纳异常
if
(
0
==
questionReply
.
getReplyStatus
())
{
throw
new
QuestionReplyServiceException
(
QuestionReplyErrorCode
.
REPLY_NOT_ADOPTED
);
}
//4.取消采纳回复
UpdateWrapper
<
QuestionReply
>
updateWrapper
=
new
UpdateWrapper
<>();
updateWrapper
.
set
(
"reply_status"
,
NOT_ADOPTED_REPLY_STATUS
).
eq
(
"reply_id"
,
questionReply
.
getReplyId
());
update
(
updateWrapper
);
//5.更新问题解决状态
QueryWrapper
<
QuestionReply
>
replyQueryWrapper
=
new
QueryWrapper
<>();
replyQueryWrapper
.
eq
(
"question_id"
,
question
.
getQuestionId
())
.
eq
(
"reply_status"
,
ADOPTED_REPLY_STATUS
);
List
<
QuestionReply
>
questionReplies
=
list
(
replyQueryWrapper
);
//若questionReplies为空,则需要更新问题的解决状态
if
(
CollectionUtils
.
isEmpty
(
questionReplies
))
{
UpdateWrapper
<
Question
>
questionUpdateWrapper
=
new
UpdateWrapper
<>();
questionUpdateWrapper
.
set
(
"solved"
,
false
)
.
eq
(
"question_id"
,
question
.
getQuestionId
());
questionService
.
update
(
questionUpdateWrapper
);
}
}
}
src/main/resources/application.yml
View file @
7ba6467d
...
...
@@ -4,7 +4,7 @@ spring:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username
:
root
password
:
1
00Centa30821%mysql
password
:
1
97442
# 邮箱
mail
:
...
...
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