Skip to content

Commit d33868d

Browse files
author
hps
committed
1.新增删除商品评价回复意见接口 2.新增分页查询商品评价回复意见接口
1 parent 706333f commit d33868d

File tree

9 files changed

+194
-5
lines changed

9 files changed

+194
-5
lines changed

PRD/gpmall商品评价设计.docx

689 Bytes
Binary file not shown.

comment-service/comment-api/src/main/java/com/gpmall/comment/ICommentReplyService.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.gpmall.comment;
22

3-
import com.gpmall.comment.dto.AddCommentReplyRequest;
4-
import com.gpmall.comment.dto.AddCommentReplyResponse;
3+
import com.gpmall.comment.dto.*;
54

65
/**
76
* @author hepengshuai
@@ -16,4 +15,18 @@ public interface ICommentReplyService {
1615
* @return
1716
*/
1817
AddCommentReplyResponse addCommentReply(AddCommentReplyRequest request);
18+
19+
/**
20+
* 删除商品评价回复
21+
* @param request
22+
* @return
23+
*/
24+
DeleteCommentReplyResponse deleteCommentReply(DeleteCommentReplyRequest request);
25+
26+
/**
27+
* 分页查询商品评价回复意见
28+
* @param request
29+
* @return
30+
*/
31+
CommentReplyListResponse commentReplyList(CommentReplyListRequest request);
1932
}

comment-service/comment-api/src/main/java/com/gpmall/comment/constant/CommentRetCode.java

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum CommentRetCode {
1414
CURRENT_COMMENT_NOT_EXIST("006005", "该评价不存在"),
1515
REQUEST_PARAMETER_ERROR("006006", "请求参数错误"),
1616
ORIGIN_COMMENT_NOT_EXIST("006007", "原评价不存在"),
17+
CURRENT_COMMENT_REPLY_NOT_EXIST("006008", "该回复意见不存在"),
1718
SYSTEM_ERROR("006500", "系统错误");
1819

1920
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.gpmall.comment.dto;
2+
3+
import com.gpmall.comment.constant.CommentRetCode;
4+
import com.gpmall.commons.result.AbstractRequest;
5+
import com.gpmall.commons.tool.exception.ValidateException;
6+
import lombok.Data;
7+
import org.apache.commons.lang3.StringUtils;
8+
9+
/**
10+
* @author heps
11+
* @date 2019/8/22 23:32
12+
* 商品评价回复意见分页查询请求参数
13+
*/
14+
@Data
15+
public class CommentReplyListRequest extends AbstractRequest {
16+
17+
/**
18+
* 商品评价id或者回复意见id
19+
*/
20+
private String commentId;
21+
22+
private int page;
23+
24+
private int size;
25+
26+
@Override
27+
public void requestCheck() {
28+
if (StringUtils.isEmpty(commentId)) {
29+
throw new ValidateException(CommentRetCode.REQUISITE_PARAMETER_NOT_EXIST.getCode(),CommentRetCode.REQUISITE_PARAMETER_NOT_EXIST.getMessage());
30+
}
31+
if (page < 1) {
32+
setPage(1);
33+
}
34+
if (size < 1) {
35+
size = 10;
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.gpmall.comment.dto;
2+
3+
import com.gpmall.commons.result.AbstractResponse;
4+
import lombok.Data;
5+
6+
import java.util.List;
7+
8+
/**
9+
* @author heps
10+
* @date 2019/8/22 23:36
11+
* 商品评价回复意见分页查询返回结果
12+
*/
13+
@Data
14+
public class CommentReplyListResponse extends AbstractResponse {
15+
16+
private long total;
17+
18+
private List<CommentReplyDto> commentReplyDtoList;
19+
20+
private int page;
21+
22+
private int size;
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.gpmall.comment.dto;
2+
3+
import com.gpmall.comment.constant.CommentRetCode;
4+
import com.gpmall.commons.result.AbstractRequest;
5+
import com.gpmall.commons.tool.exception.ValidateException;
6+
import lombok.Data;
7+
import org.apache.commons.lang3.StringUtils;
8+
9+
/**
10+
* @author heps
11+
* @date 2019/8/22 23:03
12+
* 删除商品评价回复意见请求参数
13+
*/
14+
@Data
15+
public class DeleteCommentReplyRequest extends AbstractRequest {
16+
17+
/**
18+
* 回复意见id
19+
*/
20+
private String commentReplyId;
21+
22+
/**
23+
* 删除人id
24+
*/
25+
private Long userId;
26+
27+
@Override
28+
public void requestCheck() {
29+
if (StringUtils.isEmpty(commentReplyId) || null == userId) {
30+
throw new ValidateException(CommentRetCode.REQUISITE_PARAMETER_NOT_EXIST.getCode(), CommentRetCode.REQUISITE_PARAMETER_NOT_EXIST.getMessage());
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.gpmall.comment.dto;
2+
3+
import com.gpmall.commons.result.AbstractResponse;
4+
import lombok.Data;
5+
6+
/**
7+
* @author heps
8+
* @date 2019/8/22 23:11
9+
* 删除商品评价回复意见返回结果
10+
*/
11+
@Data
12+
public class DeleteCommentReplyResponse extends AbstractResponse {
13+
}

comment-service/comment-provider/src/main/java/com/gpmall/comment/convert/CommentConverter.java

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.gpmall.comment.convert;
22

33
import com.gpmall.comment.dal.entitys.Comment;
4+
import com.gpmall.comment.dal.entitys.CommentReply;
45
import com.gpmall.comment.dto.CommentDto;
6+
import com.gpmall.comment.dto.CommentReplyDto;
57
import org.mapstruct.Mapper;
68
import org.mapstruct.Mappings;
79

@@ -18,4 +20,8 @@ public interface CommentConverter {
1820
CommentDto comment2Dto(Comment comment);
1921

2022
List<CommentDto> comment2Dto(List<Comment> commentList);
23+
24+
CommentReplyDto commentReply2Dto(CommentReply commentReply);
25+
26+
List<CommentReplyDto> commentReply2Dto(List<CommentReply> commentReplyList);
2127
}

comment-service/comment-provider/src/main/java/com/gpmall/comment/service/CommentReplyServiceImpl.java

+65-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
package com.gpmall.comment.service;
22

3+
import com.github.pagehelper.PageHelper;
4+
import com.github.pagehelper.PageInfo;
35
import com.gpmall.comment.CommentException;
46
import com.gpmall.comment.ICommentReplyService;
57
import com.gpmall.comment.constant.CommentRetCode;
8+
import com.gpmall.comment.convert.CommentConverter;
69
import com.gpmall.comment.dal.entitys.Comment;
710
import com.gpmall.comment.dal.entitys.CommentReply;
811
import com.gpmall.comment.dal.persistence.CommentMapper;
912
import com.gpmall.comment.dal.persistence.CommentReplyMapper;
10-
import com.gpmall.comment.dto.AddCommentReplyRequest;
11-
import com.gpmall.comment.dto.AddCommentReplyResponse;
13+
import com.gpmall.comment.dto.*;
1214
import com.gpmall.comment.utils.ExceptionProcessorUtil;
1315
import com.gpmall.comment.utils.GlobalIdGeneratorUtil;
1416
import org.apache.dubbo.config.annotation.Service;
17+
import org.springframework.util.CollectionUtils;
18+
import tk.mybatis.mapper.entity.Example;
1519

20+
import java.util.ArrayList;
1621
import java.util.Date;
22+
import java.util.List;
1723

1824
/**
1925
* @author heps
@@ -27,13 +33,16 @@ public class CommentReplyServiceImpl implements ICommentReplyService {
2733

2834
private final CommentMapper commentMapper;
2935

36+
private final CommentConverter commentConverter;
37+
3038
private final GlobalIdGeneratorUtil globalIdGeneratorUtil;
3139

3240
private static final String COMMENT_GLOBAL_ID_CACHE_KEY = "COMMENT_REPLY_ID";
3341

34-
public CommentReplyServiceImpl(CommentReplyMapper commentReplyMapper, CommentMapper commentMapper, GlobalIdGeneratorUtil globalIdGeneratorUtil) {
42+
public CommentReplyServiceImpl(CommentReplyMapper commentReplyMapper, CommentMapper commentMapper, CommentConverter commentConverter, GlobalIdGeneratorUtil globalIdGeneratorUtil) {
3543
this.commentReplyMapper = commentReplyMapper;
3644
this.commentMapper = commentMapper;
45+
this.commentConverter = commentConverter;
3746
this.globalIdGeneratorUtil = globalIdGeneratorUtil;
3847
}
3948

@@ -70,4 +79,57 @@ public AddCommentReplyResponse addCommentReply(AddCommentReplyRequest request) {
7079
}
7180
return response;
7281
}
82+
83+
@Override
84+
public DeleteCommentReplyResponse deleteCommentReply(DeleteCommentReplyRequest request) {
85+
DeleteCommentReplyResponse response = new DeleteCommentReplyResponse();
86+
try {
87+
request.requestCheck();
88+
CommentReply commentReply = commentReplyMapper.selectByPrimaryKey(request.getCommentReplyId());
89+
if (commentReply == null || (commentReply.getIsDeleted() != null && commentReply.getIsDeleted())) {
90+
throw new CommentException(CommentRetCode.CURRENT_COMMENT_REPLY_NOT_EXIST.getCode(), CommentRetCode.CURRENT_COMMENT_REPLY_NOT_EXIST.getMessage());
91+
}
92+
commentReply.setIsDeleted(true);
93+
commentReply.setDeletionUserId(request.getUserId());
94+
commentReply.setDeletionTime(new Date());
95+
commentReplyMapper.updateByPrimaryKey(commentReply);
96+
97+
response.setCode(CommentRetCode.SUCCESS.getCode());
98+
response.setMsg(CommentRetCode.SUCCESS.getMessage());
99+
} catch (Exception e) {
100+
ExceptionProcessorUtil.handleException(response, e);
101+
}
102+
return response;
103+
}
104+
105+
@Override
106+
public CommentReplyListResponse commentReplyList(CommentReplyListRequest request) {
107+
CommentReplyListResponse response = new CommentReplyListResponse();
108+
try {
109+
request.requestCheck();
110+
111+
Example example = new Example(CommentReply.class);
112+
Example.Criteria criteria = example.createCriteria();
113+
CommentReply commentReply = commentReplyMapper.selectByPrimaryKey(request.getCommentId());
114+
if (commentReply != null) {
115+
criteria.andEqualTo("parentId", request.getCommentId());
116+
} else {
117+
criteria.andEqualTo("commentId", request.getCommentId());
118+
}
119+
PageHelper.startPage(request.getPage(), request.getSize());
120+
List<CommentReply> commentReplyList = commentReplyMapper.selectByExample(example);
121+
PageInfo<CommentReply> pageInfo = new PageInfo<>(commentReplyList);
122+
if (CollectionUtils.isEmpty(commentReplyList)) {
123+
response.setCommentReplyDtoList(new ArrayList<>());
124+
} else {
125+
response.setCommentReplyDtoList(commentConverter.commentReply2Dto(commentReplyList));
126+
}
127+
response.setTotal(pageInfo.getTotal());
128+
response.setPage(request.getPage());
129+
response.setSize(request.getSize());
130+
} catch (Exception e) {
131+
ExceptionProcessorUtil.handleException(response, e);
132+
}
133+
return response;
134+
}
73135
}

0 commit comments

Comments
 (0)