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
f6eeb5d6
Commit
f6eeb5d6
authored
Feb 02, 2020
by
胡学良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
发表评论
parent
b7efbf09
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
196 additions
and
2 deletions
+196
-2
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReplyCommentApi.java
+50
-0
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionReplyCommentErrorCode.java
+29
-0
src/main/java/cn/meteor/beyondclouds/modules/question/exception/QuestionReplyCommentServiceException.java
+18
-0
src/main/java/cn/meteor/beyondclouds/modules/question/form/QuestionReplyCommentForm.java
+22
-0
src/main/java/cn/meteor/beyondclouds/modules/question/service/IQuestionReplyCommentService.java
+10
-0
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyCommentServiceImpl.java
+61
-0
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionServiceImpl.java
+6
-2
No files found.
src/main/java/cn/meteor/beyondclouds/modules/question/api/QuestionReplyCommentApi.java
0 → 100644
View file @
f6eeb5d6
package
cn
.
meteor
.
beyondclouds
.
modules
.
question
.
api
;
import
cn.meteor.beyondclouds.core.annotation.CurrentSubject
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.bean.Subject
;
import
cn.meteor.beyondclouds.modules.question.exception.QuestionReplyCommentServiceException
;
import
cn.meteor.beyondclouds.modules.question.form.QuestionReplyCommentForm
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionReplyCommentService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.Valid
;
/**
* @author 胡学良
* @since 2020/2/2
*/
@Api
(
tags
=
"问题回复的评论Api"
)
@RestController
@RequestMapping
(
"/api"
)
public
class
QuestionReplyCommentApi
{
private
IQuestionReplyCommentService
questionReplyCommentService
;
@Autowired
public
QuestionReplyCommentApi
(
IQuestionReplyCommentService
questionReplyCommentService
)
{
this
.
questionReplyCommentService
=
questionReplyCommentService
;
}
@ApiOperation
(
"发表评论"
)
@PostMapping
(
"/question/reply/{replyId}/comment"
)
public
Response
publishReplyComment
(
@RequestBody
@Valid
QuestionReplyCommentForm
questionReplyCommentForm
,
BindingResult
bindingResult
,
@PathVariable
(
"replyId"
)
String
replyId
,
@CurrentSubject
Subject
subject
){
if
(
bindingResult
.
hasErrors
())
{
return
Response
.
fieldError
(
bindingResult
.
getFieldError
());
}
try
{
questionReplyCommentService
.
publishReplyComment
((
String
)
subject
.
getId
(),
replyId
,
questionReplyCommentForm
.
getParentId
(),
questionReplyCommentForm
.
getComment
());
return
Response
.
success
();
}
catch
(
QuestionReplyCommentServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
}
src/main/java/cn/meteor/beyondclouds/modules/question/enums/QuestionReplyCommentErrorCode.java
0 → 100644
View file @
f6eeb5d6
package
cn
.
meteor
.
beyondclouds
.
modules
.
question
.
enums
;
import
cn.meteor.beyondclouds.core.IErrorCode
;
/**
* @author 胡学良
* @since 2020/2/2
*/
public
enum
QuestionReplyCommentErrorCode
implements
IErrorCode
{
COMMENT_NOT_FOUND
(
5001
,
"父评论不存在"
);
private
long
code
;
private
String
msg
;
QuestionReplyCommentErrorCode
(
long
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
msg
=
msg
;
}
@Override
public
long
code
()
{
return
code
;
}
@Override
public
String
msg
()
{
return
msg
;
}
}
src/main/java/cn/meteor/beyondclouds/modules/question/exception/QuestionReplyCommentServiceException.java
0 → 100644
View file @
f6eeb5d6
package
cn
.
meteor
.
beyondclouds
.
modules
.
question
.
exception
;
import
cn.meteor.beyondclouds.core.IErrorCode
;
import
cn.meteor.beyondclouds.core.exception.ServiceException
;
/**
* @author 胡学良
* @since 2020/2/2
*/
public
class
QuestionReplyCommentServiceException
extends
ServiceException
{
public
QuestionReplyCommentServiceException
(
long
errorCode
,
String
errorMsg
)
{
super
(
errorCode
,
errorMsg
);
}
public
QuestionReplyCommentServiceException
(
IErrorCode
errorCode
)
{
super
(
errorCode
);
}
}
src/main/java/cn/meteor/beyondclouds/modules/question/form/QuestionReplyCommentForm.java
0 → 100644
View file @
f6eeb5d6
package
cn
.
meteor
.
beyondclouds
.
modules
.
question
.
form
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotEmpty
;
/**
* 回复评论表单
* @author 胡学良
* @since 2020/2/2
*/
@Data
public
class
QuestionReplyCommentForm
{
@ApiModelProperty
(
"父评论ID"
)
private
String
parentId
;
@ApiModelProperty
(
"评论内容"
)
@NotEmpty
(
message
=
"评论内容不能为空"
)
private
String
comment
;
}
src/main/java/cn/meteor/beyondclouds/modules/question/service/IQuestionReplyCommentService.java
View file @
f6eeb5d6
package
cn
.
meteor
.
beyondclouds
.
modules
.
question
.
service
;
import
cn.meteor.beyondclouds.modules.question.entity.QuestionReplyComment
;
import
cn.meteor.beyondclouds.modules.question.exception.QuestionReplyCommentServiceException
;
import
com.baomidou.mybatisplus.extension.service.IService
;
/**
...
...
@@ -13,4 +14,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public
interface
IQuestionReplyCommentService
extends
IService
<
QuestionReplyComment
>
{
/**
* 发表评论
* @param userId 用户ID
* @param replyId 回复ID
* @param parentId 父评论ID
* @param comment 评论内容
* @throws QuestionReplyCommentServiceException 问题回复评论业务异常
*/
void
publishReplyComment
(
String
userId
,
String
replyId
,
String
parentId
,
String
comment
)
throws
QuestionReplyCommentServiceException
;
}
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionReplyCommentServiceImpl.java
View file @
f6eeb5d6
package
cn
.
meteor
.
beyondclouds
.
modules
.
question
.
service
.
impl
;
import
cn.meteor.beyondclouds.modules.question.entity.QuestionReply
;
import
cn.meteor.beyondclouds.modules.question.entity.QuestionReplyComment
;
import
cn.meteor.beyondclouds.modules.question.enums.QuestionReplyCommentErrorCode
;
import
cn.meteor.beyondclouds.modules.question.enums.QuestionReplyErrorCode
;
import
cn.meteor.beyondclouds.modules.question.exception.QuestionReplyCommentServiceException
;
import
cn.meteor.beyondclouds.modules.question.mapper.QuestionReplyCommentMapper
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionReplyCommentService
;
import
cn.meteor.beyondclouds.modules.question.service.IQuestionReplyService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
/**
* <p>
...
...
@@ -17,4 +26,56 @@ import org.springframework.stereotype.Service;
@Service
public
class
QuestionReplyCommentServiceImpl
extends
ServiceImpl
<
QuestionReplyCommentMapper
,
QuestionReplyComment
>
implements
IQuestionReplyCommentService
{
private
IQuestionReplyService
questionReplyService
;
@Autowired
public
void
setQuestionReplyService
(
IQuestionReplyService
questionReplyService
)
{
this
.
questionReplyService
=
questionReplyService
;
}
@Override
public
void
publishReplyComment
(
String
userId
,
String
replyId
,
String
parentId
,
String
comment
)
throws
QuestionReplyCommentServiceException
{
Assert
.
hasText
(
replyId
,
"replyId must not be empty"
);
//1.判断是否存在该回复
QuestionReply
questionReply
=
questionReplyService
.
getById
(
replyId
);
//若回复为空,则抛出回复不存在异常
if
(
questionReply
==
null
)
{
throw
new
QuestionReplyCommentServiceException
(
QuestionReplyErrorCode
.
REPLY_NOT_FOUND
);
}
QuestionReplyComment
parentQuestionReplyComment
=
null
;
//2.判断夫评论是否存在
if
(!
StringUtils
.
isEmpty
(
parentId
))
{
QueryWrapper
<
QuestionReplyComment
>
questionReplyCommentQueryWrapper
=
new
QueryWrapper
<>();
questionReplyCommentQueryWrapper
.
eq
(
"reply_id"
,
replyId
)
.
eq
(
"comment_id"
,
parentId
);
parentQuestionReplyComment
=
getOne
(
questionReplyCommentQueryWrapper
);
//若父评论为空,则抛出父评论不存在异常
if
(
null
==
parentQuestionReplyComment
)
{
throw
new
QuestionReplyCommentServiceException
(
QuestionReplyCommentErrorCode
.
COMMENT_NOT_FOUND
);
}
}
//3.保存评论信息
QuestionReplyComment
questionReplyComment
=
new
QuestionReplyComment
();
questionReplyComment
.
setUserId
(
userId
);
questionReplyComment
.
setReplyId
(
replyId
);
questionReplyComment
.
setParentId
(
parentId
);
questionReplyComment
.
setComment
(
comment
);
save
(
questionReplyComment
);
//4.更新评论层级和评论路径
if
(
null
!=
parentQuestionReplyComment
)
{
//子级评论
questionReplyComment
.
setDepth
(
parentQuestionReplyComment
.
getDepth
()+
1
);
questionReplyComment
.
setThread
(
parentQuestionReplyComment
.
getThread
()+
"/"
+
questionReplyComment
.
getCommentId
());
}
else
{
//1级评论
questionReplyComment
.
setDepth
(
0
);
questionReplyComment
.
setThread
(
"/"
+
questionReplyComment
.
getCommentId
());
}
updateById
(
questionReplyComment
);
}
}
src/main/java/cn/meteor/beyondclouds/modules/question/service/impl/QuestionServiceImpl.java
View file @
f6eeb5d6
...
...
@@ -52,9 +52,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
private
IQuestionCategoryService
questionCategoryService
;
@Autowired
public
QuestionServiceImpl
(
IQuestionExtService
questionExtService
,
IQuestion
ReplyCommentService
questionReplyCommentService
,
IQuestion
CategoryService
questionCategoryService
)
{
public
QuestionServiceImpl
(
IQuestionExtService
questionExtService
,
IQuestionCategoryService
questionCategoryService
)
{
this
.
questionExtService
=
questionExtService
;
this
.
questionReplyCommentService
=
questionReplyCommentService
;
this
.
questionCategoryService
=
questionCategoryService
;
}
...
...
@@ -68,6 +67,11 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
this
.
questionTagService
=
questionTagService
;
}
@Autowired
public
void
setQuestionReplyCommentService
(
IQuestionReplyCommentService
questionReplyCommentService
)
{
this
.
questionReplyCommentService
=
questionReplyCommentService
;
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
void
postQuestion
(
Question
question
,
String
questionDetail
,
HashSet
<
String
>
tags
)
throws
QuestionServiceException
{
...
...
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