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
bebce5f3
Commit
bebce5f3
authored
Feb 02, 2020
by
胡学良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
采纳回复
parent
d59d9d2c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
10 deletions
+99
-10
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionApi.java
+19
-2
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReply.java
+20
-4
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionReplyErrorCode.java
+10
-3
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
+39
-0
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionApi.java
View file @
bebce5f3
...
@@ -21,6 +21,7 @@ import io.swagger.annotations.Api;
...
@@ -21,6 +21,7 @@ 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.data.domain.Page
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -216,8 +217,8 @@ public class QuestionApi {
...
@@ -216,8 +217,8 @@ public class QuestionApi {
@GetMapping
(
"/my/question/participated"
)
@GetMapping
(
"/my/question/participated"
)
public
Response
<
PageVO
<
QuestionReply
>>
getMyParticipateQuestions
(
@Valid
PageForm
pageForm
,
@CurrentSubject
Subject
subject
)
{
public
Response
<
PageVO
<
QuestionReply
>>
getMyParticipateQuestions
(
@Valid
PageForm
pageForm
,
@CurrentSubject
Subject
subject
)
{
//获取我的列表并返回
//获取我的列表并返回
IPage
<
QuestionReply
>
user
ParticipateQuestionReplyPage
=
questionService
.
getUserParticipateQuestionReplyPage
(
pageForm
.
getPage
(),
pageForm
.
getSize
(),
(
String
)
subject
.
getId
());
IPage
<
QuestionReply
>
my
ParticipateQuestionReplyPage
=
questionService
.
getUserParticipateQuestionReplyPage
(
pageForm
.
getPage
(),
pageForm
.
getSize
(),
(
String
)
subject
.
getId
());
PageVO
<
QuestionReply
>
questionReplyPageVO
=
new
PageVO
<>(
user
ParticipateQuestionReplyPage
);
PageVO
<
QuestionReply
>
questionReplyPageVO
=
new
PageVO
<>(
my
ParticipateQuestionReplyPage
);
return
Response
.
success
(
questionReplyPageVO
);
return
Response
.
success
(
questionReplyPageVO
);
}
}
...
@@ -237,5 +238,21 @@ public class QuestionApi {
...
@@ -237,5 +238,21 @@ public class QuestionApi {
return
Response
.
success
(
questionPageVO
);
return
Response
.
success
(
questionPageVO
);
}
}
/**
* 用户参与的问答列表
* @param pageForm 分页表单
* @param userId 用户ID
* @return 用户参与的问答列表
*/
@Anonymous
@ApiOperation
(
"用户参与的问答列表"
)
@GetMapping
(
"/user/{userId}/question/participated"
)
public
Response
<
PageVO
<
QuestionReply
>>
getUserParticipateQuestions
(
@Valid
PageForm
pageForm
,
@PathVariable
(
"userId"
)
String
userId
)
{
//获取用户参与的问答列表并返回
IPage
<
QuestionReply
>
userParticipateQuestionReplyPage
=
questionService
.
getUserParticipateQuestionReplyPage
(
pageForm
.
getPage
(),
pageForm
.
getSize
(),
userId
);
PageVO
<
QuestionReply
>
questionReplyPageVO
=
new
PageVO
<>(
userParticipateQuestionReplyPage
);
return
Response
.
success
(
questionReplyPageVO
);
}
}
}
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReply.java
View file @
bebce5f3
...
@@ -8,10 +8,7 @@ import cn.meteor.beyondclouds.modules.question.service.IQuestionReplyService;
...
@@ -8,10 +8,7 @@ import cn.meteor.beyondclouds.modules.question.service.IQuestionReplyService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
/**
* @author 胡学良
* @author 胡学良
...
@@ -47,4 +44,23 @@ public class QuestionReply {
...
@@ -47,4 +44,23 @@ public class QuestionReply {
return
Response
.
error
(
e
);
return
Response
.
error
(
e
);
}
}
}
}
/**
* 采纳回复
* @param questionId 问题ID
* @param replyId 回复ID
* @param userId 发布问题用户ID
* @return default
*/
@ApiOperation
(
"采纳回复"
)
@PutMapping
(
"/question/reply/{replyId}/adoption"
)
public
Response
adoptReply
(
String
questionId
,
@PathVariable
(
"replyId"
)
String
replyId
,
String
userId
)
{
try
{
questionReplyService
.
adoptReply
(
questionId
,
replyId
,
userId
);
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 @
bebce5f3
...
@@ -7,7 +7,14 @@ import cn.meteor.beyondclouds.core.IErrorCode;
...
@@ -7,7 +7,14 @@ import cn.meteor.beyondclouds.core.IErrorCode;
* @since 2020/2/1
* @since 2020/2/1
*/
*/
public
enum
QuestionReplyErrorCode
implements
IErrorCode
{
public
enum
QuestionReplyErrorCode
implements
IErrorCode
{
;
/**
* 回复不存在
*/
REPLY_NOT_FOUND
(
4001
,
"回复不存在"
),
/**
* 回复已被采纳
*/
REPLY_ADOPTED
(
4002
,
"回复已被采纳"
);
private
long
code
;
private
long
code
;
private
String
msg
;
private
String
msg
;
...
@@ -19,11 +26,11 @@ public enum QuestionReplyErrorCode implements IErrorCode {
...
@@ -19,11 +26,11 @@ public enum QuestionReplyErrorCode 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/service/IQuestionReplyService.java
View file @
bebce5f3
...
@@ -19,6 +19,16 @@ public interface IQuestionReplyService extends IService<QuestionReply> {
...
@@ -19,6 +19,16 @@ public interface IQuestionReplyService extends IService<QuestionReply> {
* @param questionId 问题ID
* @param questionId 问题ID
* @param reply 回复内容
* @param reply 回复内容
* @param userId 用户ID
* @param userId 用户ID
* @throws QuestionReplyServiceException 问题回复业务异常
*/
*/
void
replyQuestion
(
String
questionId
,
String
reply
,
String
userId
)
throws
QuestionReplyServiceException
;
void
replyQuestion
(
String
questionId
,
String
reply
,
String
userId
)
throws
QuestionReplyServiceException
;
/**
* 采纳回复
* @param questionId 问题ID
* @param replyId 回复ID
* @param userId 用户ID
* @throws QuestionReplyServiceException 问题回复业务异常
*/
void
adoptReply
(
String
questionId
,
String
replyId
,
String
userId
)
throws
QuestionReplyServiceException
;
}
}
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyServiceImpl.java
View file @
bebce5f3
...
@@ -3,10 +3,13 @@ package cn.meteor.beyondclouds.modules.question.service.impl;
...
@@ -3,10 +3,13 @@ package cn.meteor.beyondclouds.modules.question.service.impl;
import
cn.meteor.beyondclouds.modules.question.entity.Question
;
import
cn.meteor.beyondclouds.modules.question.entity.Question
;
import
cn.meteor.beyondclouds.modules.question.entity.QuestionReply
;
import
cn.meteor.beyondclouds.modules.question.entity.QuestionReply
;
import
cn.meteor.beyondclouds.modules.question.enums.QuestionErrorCode
;
import
cn.meteor.beyondclouds.modules.question.enums.QuestionErrorCode
;
import
cn.meteor.beyondclouds.modules.question.enums.QuestionReplyErrorCode
;
import
cn.meteor.beyondclouds.modules.question.exception.QuestionReplyServiceException
;
import
cn.meteor.beyondclouds.modules.question.exception.QuestionReplyServiceException
;
import
cn.meteor.beyondclouds.modules.question.mapper.QuestionReplyMapper
;
import
cn.meteor.beyondclouds.modules.question.mapper.QuestionReplyMapper
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionReplyService
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionReplyService
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionService
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
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
;
...
@@ -22,6 +25,8 @@ import org.springframework.stereotype.Service;
...
@@ -22,6 +25,8 @@ import org.springframework.stereotype.Service;
@Service
@Service
public
class
QuestionReplyServiceImpl
extends
ServiceImpl
<
QuestionReplyMapper
,
QuestionReply
>
implements
IQuestionReplyService
{
public
class
QuestionReplyServiceImpl
extends
ServiceImpl
<
QuestionReplyMapper
,
QuestionReply
>
implements
IQuestionReplyService
{
private
int
ADOPTED_REPLY_STATUS
=
1
;
private
IQuestionService
questionService
;
private
IQuestionService
questionService
;
@Autowired
@Autowired
...
@@ -48,4 +53,38 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
...
@@ -48,4 +53,38 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
questionReply
.
setReplyStatus
(
0
);
questionReply
.
setReplyStatus
(
0
);
save
(
questionReply
);
save
(
questionReply
);
}
}
@Override
public
void
adoptReply
(
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
(
1
==
questionReply
.
getReplyStatus
())
{
throw
new
QuestionReplyServiceException
(
QuestionReplyErrorCode
.
REPLY_ADOPTED
);
}
//4.采纳回复
UpdateWrapper
<
QuestionReply
>
updateWrapper
=
new
UpdateWrapper
<>();
updateWrapper
.
set
(
"reply_status"
,
ADOPTED_REPLY_STATUS
).
eq
(
"reply_id"
,
replyId
);
update
(
updateWrapper
);
}
}
}
src/main/resources/application.yml
View file @
bebce5f3
...
@@ -3,7 +3,7 @@ spring:
...
@@ -3,7 +3,7 @@ spring:
driver-class-name
:
com.mysql.cj.jdbc.Driver
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
url
:
jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username
:
root
username
:
root
password
:
1
00Centa30821%mysql
password
:
1
97442
swagger
:
swagger
:
enable
:
true
enable
:
true
...
...
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