Skip to content

Commit 113bc6f

Browse files
author
hps
committed
添加分页查询单个商品的评价接口
1 parent 61d8ff9 commit 113bc6f

10 files changed

Lines changed: 134 additions & 1747 deletions

File tree

PRD/gpmall商品评价设计.docx

1.59 KB
Binary file not shown.

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.gpmall.comment;
22

3-
import com.gpmall.comment.dto.AddCommentRequest;
4-
import com.gpmall.comment.dto.AddCommentResponse;
5-
import com.gpmall.comment.dto.CommentRequest;
6-
import com.gpmall.comment.dto.CommentResponse;
3+
import com.gpmall.comment.dto.*;
74

85
/**
96
* @author heps
@@ -26,4 +23,11 @@ public interface ICommentService {
2623
* @return
2724
*/
2825
CommentResponse comment(CommentRequest request);
26+
27+
/**
28+
* 分页查询某个商品的评价
29+
* @param request
30+
* @return
31+
*/
32+
CommentListResponse commentList(CommentListRequest request);
2933
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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/15 23:01
12+
* 分页查询单个商品的商品评价参数
13+
*/
14+
@Data
15+
public class CommentListRequest extends AbstractRequest {
16+
17+
private String itemId;
18+
19+
/**
20+
* 评价类型 1、好评 2、中评 3、差评
21+
*/
22+
private Integer type;
23+
24+
private int page;
25+
26+
private int size;
27+
28+
@Override
29+
public void requestCheck() {
30+
if (StringUtils.isEmpty(itemId)) {
31+
throw new ValidateException(CommentRetCode.REQUISITE_PARAMETER_NOT_EXIST.getCode(),CommentRetCode.REQUISITE_PARAMETER_NOT_EXIST.getMessage());
32+
}
33+
if (page < 1) {
34+
setPage(1);
35+
}
36+
if (size < 1) {
37+
size = 10;
38+
}
39+
}
40+
}
Lines changed: 23 additions & 0 deletions
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/15 23:09
11+
* 分页查询单个商品的商品评价返回类型
12+
*/
13+
@Data
14+
public class CommentListResponse extends AbstractResponse {
15+
16+
private List<CommentDto> commentDtoList;
17+
18+
private int page;
19+
20+
private int size;
21+
22+
private long total;
23+
}

comment-service/comment-api/src/main/java/com/gpmall/comment/dto/CommentResponse.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.gpmall.commons.result.AbstractResponse;
44
import lombok.Data;
55

6+
import java.util.List;
7+
68
/**
79
* @author heps
810
* @date 2019/8/14 23:24
@@ -11,5 +13,5 @@
1113
@Data
1214
public class CommentResponse extends AbstractResponse {
1315

14-
private CommentDto commentDto;
16+
private List<CommentDto> commentDtoList;
1517
}

comment-service/comment-provider/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@
9595
<groupId>com.gpmall.order</groupId>
9696
<version>1.0-SNAPSHOT</version>
9797
</dependency>
98+
99+
<dependency>
100+
<groupId>com.github.pagehelper</groupId>
101+
<artifactId>pagehelper</artifactId>
102+
</dependency>
103+
<dependency>
104+
<groupId>com.github.pagehelper</groupId>
105+
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
106+
</dependency>
107+
<dependency>
108+
<groupId>com.github.pagehelper</groupId>
109+
<artifactId>pagehelper-spring-boot-starter</artifactId>
110+
</dependency>
98111
</dependencies>
99112

100113
<build>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.mapstruct.Mapper;
66
import org.mapstruct.Mappings;
77

8+
import java.util.List;
9+
810
/**
911
* @author heps
1012
* @date 2019/8/14 23:54
@@ -14,4 +16,6 @@ public interface CommentConverter {
1416

1517
@Mappings({})
1618
CommentDto comment2Dto(Comment comment);
19+
20+
List<CommentDto> comment2Dto(List<Comment> commentList);
1721
}

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

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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.ICommentService;
57
import com.gpmall.comment.constant.CommentRetCode;
@@ -9,10 +11,7 @@
911
import com.gpmall.comment.dal.entitys.CommentPicture;
1012
import com.gpmall.comment.dal.persistence.CommentMapper;
1113
import com.gpmall.comment.dal.persistence.CommentPictureMapper;
12-
import com.gpmall.comment.dto.AddCommentRequest;
13-
import com.gpmall.comment.dto.AddCommentResponse;
14-
import com.gpmall.comment.dto.CommentRequest;
15-
import com.gpmall.comment.dto.CommentResponse;
14+
import com.gpmall.comment.dto.*;
1615
import com.gpmall.comment.utils.ExceptionProcessorUtil;
1716
import com.gpmall.comment.utils.GlobalIdGeneratorUtil;
1817
import com.gpmall.comment.utils.SensitiveWordsUtil;
@@ -98,7 +97,41 @@ public CommentResponse comment(CommentRequest request) {
9897
} else {
9998
response.setCode(CommentRetCode.SUCCESS.getCode());
10099
response.setMsg(CommentRetCode.SUCCESS.getMessage());
101-
response.setCommentDto(commentConverter.comment2Dto(comments.get(0)));
100+
response.setCommentDtoList(commentConverter.comment2Dto(comments));
101+
}
102+
} catch (Exception e) {
103+
ExceptionProcessorUtil.handleException(response, e);
104+
}
105+
return response;
106+
}
107+
108+
@Override
109+
public CommentListResponse commentList(CommentListRequest request) {
110+
CommentListResponse response = new CommentListResponse();
111+
try {
112+
request.requestCheck();
113+
String itemId = request.getItemId();
114+
Integer type = request.getType();
115+
CommentExample example = new CommentExample();
116+
117+
CommentExample.Criteria criteria = example.createCriteria();
118+
criteria.andItemIdEqualTo(itemId);
119+
if (type != null) {
120+
criteria.andTypeEqualTo(type.byteValue());
121+
}
122+
PageHelper.startPage(request.getPage(), request.getSize());
123+
List<Comment> comments = commentMapper.selectByExample(example);
124+
if (CollectionUtils.isEmpty(comments)) {
125+
response.setCode(CommentRetCode.COMMENT_NOT_EXIST.getCode());
126+
response.setMsg(CommentRetCode.COMMENT_NOT_EXIST.getMessage());
127+
} else {
128+
response.setCode(CommentRetCode.SUCCESS.getCode());
129+
response.setMsg(CommentRetCode.SUCCESS.getMessage());
130+
response.setPage(request.getPage());
131+
response.setSize(request.getSize());
132+
PageInfo<Comment> commentPageInfo = new PageInfo<>();
133+
response.setTotal(commentPageInfo.getTotal());
134+
response.setCommentDtoList(commentConverter.comment2Dto(comments));
102135
}
103136
} catch (Exception e) {
104137
ExceptionProcessorUtil.handleException(response, e);

comment-service/comment-provider/src/main/resources/application.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ spring:
44
mybatis:
55
mapper-locations: classpath*:com/gpmall/comment/dal/persistence/*Mapper.xml"
66
type-aliases-package: com.gpmall.comment.dal.entitys
7+
pagehelper:
8+
helper-dialect: mysql
9+
reasonable: true
10+
support-methods-arguments: true
11+
params: count=countSql
712

search-service/logs/spring.application.name_IS_UNDEFINED.log

Lines changed: 0 additions & 1737 deletions
This file was deleted.

0 commit comments

Comments
 (0)