Skip to content

Commit 17ad625

Browse files
authored
Merge pull request 2227324689#89 from lizhaowh/stu_dev_0809
Stu dev 0809
2 parents aa58b1a + b266e8b commit 17ad625

23 files changed

Lines changed: 290 additions & 138 deletions

File tree

db_scrpit/gpmall.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ CREATE TABLE `tb_order` (
314314
`buyer_message` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '买家留言',
315315
`buyer_nick` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '买家昵称',
316316
`buyer_comment` tinyint(1) DEFAULT NULL COMMENT '买家是否已经评价',
317+
`unique_key` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '唯一键',
317318
PRIMARY KEY (`order_id`),
318319
KEY `create_time` (`create_time`),
319320
KEY `buyer_nick` (`buyer_nick`),

gpmall-parent/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<dubbo-spring-boot.version>2.7.1</dubbo-spring-boot.version>
2121
<curator.famework.version>4.2.0</curator.famework.version>
2222
<mybatis.version>2.1.0</mybatis.version>
23+
<tkmybatis.version>3.4.2</tkmybatis.version>
24+
<tkmybatis.springboot.version>1.1.7</tkmybatis.springboot.version>
2325
<druid.version>1.1.19</druid.version>
2426
<gpmall.commons>1.0-SNAPSHOT</gpmall.commons>
2527
<mapstruct.version>1.3.0.Final</mapstruct.version>
@@ -133,6 +135,17 @@
133135
</exclusion>
134136
</exclusions>
135137
</dependency>
138+
<dependency>
139+
<groupId>tk.mybatis</groupId>
140+
<artifactId>mapper</artifactId>
141+
<version>${tkmybatis.version}</version>
142+
</dependency>
143+
<!--mapper-->
144+
<dependency>
145+
<groupId>tk.mybatis</groupId>
146+
<artifactId>mapper-spring-boot-starter</artifactId>
147+
<version>${tkmybatis.springboot.version}</version>
148+
</dependency>
136149
<dependency>
137150
<groupId>com.alibaba</groupId>
138151
<artifactId>druid</artifactId>

gpmall-shopping/src/main/java/com/gpmall/shopping/controller/SearchController.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import com.gpmall.search.ProductSearchService;
66
import com.gpmall.search.dto.SearchRequest;
77
import com.gpmall.search.dto.SearchResponse;
8+
import com.gpmall.shopping.constants.ShoppingRetCode;
9+
import com.gpmall.shopping.form.SearchPageInfo;
10+
import com.gpmall.user.annotation.Anoymous;
811
import org.apache.dubbo.config.annotation.Reference;
912
import org.springframework.web.bind.annotation.GetMapping;
1013
import org.springframework.web.bind.annotation.PathVariable;
@@ -20,14 +23,25 @@
2023
* @Date 2019年8月11日
2124
*/
2225
@RestController
23-
@RequestMapping("/search")
26+
@RequestMapping("/shopping")
2427
public class SearchController {
2528
@Reference(timeout = 30000)
2629
private ProductSearchService productSearchService;
2730

28-
@GetMapping("/product/{keyword}")
29-
public ResponseData<SearchResponse> searchProduct(@PathVariable("keyword") String keyword) {
30-
SearchResponse searchResponse = productSearchService.search(SearchRequest.of(keyword));
31-
return new ResponseUtil().setData(searchResponse.getData());
31+
@Anoymous
32+
@GetMapping("/search")
33+
public ResponseData<SearchResponse> searchProduct(SearchPageInfo pageInfo) {
34+
SearchRequest request = new SearchRequest();
35+
request.setKeyword(pageInfo.getKey());
36+
request.setCurrentPage(pageInfo.getPage());
37+
request.setPageSize(pageInfo.getSize());
38+
request.setPriceGt(pageInfo.getPriceGt());
39+
request.setPriceLte(pageInfo.getPriceLte());
40+
request.setSort(pageInfo.getSort());
41+
SearchResponse response = productSearchService.search(request);
42+
if(response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
43+
return new ResponseUtil().setData(response.getData());
44+
}
45+
return new ResponseUtil().setErrorMsg(response.getMsg());
3246
}
3347
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.gpmall.shopping.form;
2+
3+
import lombok.Data;
4+
5+
/**
6+
* @author lanwp
7+
* @Date 2019/8/14 11:36
8+
*/
9+
@Data
10+
public class SearchPageInfo {
11+
private String key;
12+
private Integer page;
13+
private Integer size;
14+
private String sort;
15+
private Integer priceGt;
16+
private Integer priceLte;
17+
}

search-service/search-api/src/main/java/com/gpmall/search/consts/SearchEnum.java renamed to search-service/search-api/src/main/java/com/gpmall/search/consts/SearchRetCode.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,31 @@
77
* @author jin
88
* @version v1.0.0
99
* @Date 2019年8月10日
10+
* search-service统一错误码为 007
1011
*/
11-
public enum SearchEnum {
12-
/**
13-
* 成功响应码
14-
*/
15-
SUCCESS("Z0000", "成功"),
12+
public enum SearchRetCode {
13+
// 系统公用
14+
SUCCESS("000000", "成功"),
1615
/**
1716
* 失败响应码
1817
*/
19-
FAILED("Z0001", "失败,详情见附属信息"),
18+
FAILED("007001", "失败,详情见附属信息"),
2019
/**
2120
* 参数为空
2221
*/
23-
STRING_EMPTY("Z0002", "入参字符串为空,%s");
22+
STRING_EMPTY("007002", "入参字符串为空,%s"),
23+
24+
REQUEST_CHECK_FAILURE ("007003", "请求数据校验失败"),
25+
REQUISITE_PARAMETER_NOT_EXIST ("007004", "必要的参数不能为空"),
26+
27+
SYSTEM_TIMEOUT("007098", "系统超时"),
28+
SYSTEM_ERROR("007099", "系统错误");
29+
2430
private String code;
2531

2632
private String msg;
2733

28-
private SearchEnum(String code, String msg) {
34+
private SearchRetCode(String code, String msg) {
2935
this.code = code;
3036
this.msg = msg;
3137
}
@@ -48,7 +54,7 @@ public String getMsg(String code) {
4854

4955
@Override
5056
public String toString() {
51-
return "SearchEnum{" +
57+
return "SearchRetCode{" +
5258
"code=" + code +
5359
", msg='" + msg + '\'' +
5460
'}';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.gpmall.search.dto;
2+
3+
import lombok.Data;
4+
5+
import java.io.Serializable;
6+
import java.math.BigDecimal;
7+
8+
/**
9+
* 腾讯课堂搜索【咕泡学院】
10+
* 官网:www.gupaoedu.com
11+
* 风骚的Mic 老师
12+
* create-date: 2019/7/24-19:08
13+
*/
14+
@Data
15+
public class ProductDto implements Serializable {
16+
17+
private static final long serialVersionUID = 2763986506997467400L;
18+
private Long productId;
19+
20+
private BigDecimal salePrice;
21+
22+
private String productName;
23+
24+
private String subTitle;
25+
26+
private String picUrl;
27+
}
Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.gpmall.search.dto;
22

33
import com.gpmall.commons.result.AbstractRequest;
4+
import com.gpmall.commons.tool.exception.ValidateException;
45
import com.gpmall.search.SearchException;
5-
import com.gpmall.search.consts.SearchEnum;
6+
import com.gpmall.search.consts.SearchRetCode;
7+
import lombok.Data;
68
import org.apache.commons.lang3.StringUtils;
79

810
/**
@@ -12,45 +14,25 @@
1214
* @version v1.0.0
1315
* @Date 2019年8月10日
1416
*/
17+
@Data
1518
public class SearchRequest extends AbstractRequest {
1619

1720
private String keyword;
1821
private Integer currentPage;
1922
private Integer pageSize;
23+
private String sort;
24+
private Integer priceGt;
25+
private Integer priceLte;
2026

21-
public SearchRequest() {
22-
}
23-
24-
public SearchRequest(String keyword) {
25-
this.keyword = keyword;
26-
}
27-
28-
public static SearchRequest of(String keyword) {
29-
return new SearchRequest(keyword);
30-
}
31-
public String getKeyword() {
32-
return keyword;
33-
}
34-
35-
public void setKeyword(String keyword) {
36-
this.keyword = keyword;
37-
}
38-
39-
public Integer getCurrentPage() {
40-
return currentPage;
41-
}
42-
43-
public void setCurrentPage(Integer currentPage) {
44-
this.currentPage = currentPage;
45-
}
46-
47-
public Integer getPageSize() {
48-
return pageSize;
27+
@Override
28+
public void requestCheck() {
29+
if(StringUtils.isBlank(keyword)){
30+
throw new ValidateException(
31+
SearchRetCode.REQUEST_CHECK_FAILURE.getCode(),
32+
SearchRetCode.REQUEST_CHECK_FAILURE.getMsg());
33+
}
4934
}
5035

51-
public void setPageSize(Integer pageSize) {
52-
this.pageSize = pageSize;
53-
}
5436

5537
@Override
5638
public String toString() {
@@ -60,12 +42,4 @@ public String toString() {
6042
", pageSize=" + pageSize +
6143
'}';
6244
}
63-
64-
@Override
65-
public void requestCheck() {
66-
if (StringUtils.isAllBlank(keyword)) {
67-
throw SearchException.create(SearchEnum.STRING_EMPTY.getCode(),
68-
SearchEnum.STRING_EMPTY.param(keyword));
69-
}
70-
}
7145
}
Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.gpmall.search.dto;
22

33

4-
import com.gpmall.search.consts.SearchEnum;
4+
import com.gpmall.commons.result.AbstractResponse;
5+
import com.gpmall.search.consts.SearchRetCode;
6+
import lombok.Data;
57

6-
import java.io.Serializable;
8+
import java.util.List;
79

810
/**
911
* 通用响应类
@@ -12,64 +14,24 @@
1214
* @version v1.0.0
1315
* @Date 2019年8月10日
1416
*/
15-
public class SearchResponse implements Serializable {
16-
private String code;
17-
private String msg;
18-
private Object data;
17+
@Data
18+
public class SearchResponse<T> extends AbstractResponse {
1919

20-
public static SearchResponse ok() {
21-
SearchResponse response = new SearchResponse();
22-
response.setCode(SearchEnum.SUCCESS.getCode());
23-
return response;
24-
}
20+
private List<T> data;
2521

26-
public static SearchResponse err() {
27-
SearchResponse response = new SearchResponse();
28-
response.setCode(SearchEnum.FAILED.getCode());
29-
return response;
22+
public List<T> getData() {
23+
return data;
3024
}
3125

32-
public SearchResponse msg(String msg) {
33-
this.setMsg(msg);
26+
public SearchResponse setData(List<T> data) {
27+
this.data = data;
3428
return this;
3529
}
3630

37-
public SearchResponse data(Object data) {
31+
public SearchResponse ok(List<T> data) {
32+
this.setCode(SearchRetCode.SUCCESS.getCode());
33+
this.setMsg(SearchRetCode.SUCCESS.getMsg());
3834
this.setData(data);
3935
return this;
4036
}
41-
42-
public String getCode() {
43-
return code;
44-
}
45-
46-
public void setCode(String code) {
47-
this.code = code;
48-
}
49-
50-
public String getMsg() {
51-
return msg;
52-
}
53-
54-
public void setMsg(String msg) {
55-
this.msg = msg;
56-
}
57-
58-
public Object getData() {
59-
return data;
60-
}
61-
62-
public void setData(Object data) {
63-
this.data = data;
64-
}
65-
66-
@Override
67-
public String toString() {
68-
return "SearchResponse{" +
69-
"code=" + code +
70-
", msg='" + msg + '\'' +
71-
", data=" + data +
72-
'}';
73-
}
74-
7537
}

search-service/search-provider/src/main/java/com/gpmall/search/bootstrap/SearchProviderApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.gpmall.search.bootstrap;
22

33

4+
//import org.mybatis.spring.annotation.MapperScan;
45
import org.mybatis.spring.annotation.MapperScan;
56
import org.springframework.boot.SpringApplication;
67
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -14,7 +15,7 @@
1415
*/
1516

1617
@SpringBootApplication
17-
@ComponentScan(basePackages = "com.gpmall.search.repository")
18+
@ComponentScan(basePackages = "com.gpmall.search")
1819
@MapperScan(basePackages = "com.gpmall.search.mapper")
1920
@EnableElasticsearchRepositories(basePackages = "com.gpmall.search.repository")
2021
public class SearchProviderApplication {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.gpmall.search.converter;
2+
3+
import com.gpmall.search.dto.ProductDto;
4+
import com.gpmall.search.entity.ItemDocument;
5+
import org.mapstruct.Mapper;
6+
import org.mapstruct.Mapping;
7+
import org.mapstruct.Mappings;
8+
9+
import java.util.List;
10+
11+
/**
12+
* 腾讯课堂搜索【咕泡学院】
13+
* 官网:www.gupaoedu.com
14+
* 风骚的Mic 老师
15+
* create-date: 2019/7/24-19:15
16+
*/
17+
@Mapper(componentModel = "spring")
18+
public interface ProductConverter {
19+
20+
@Mappings({
21+
@Mapping(source = "id",target = "productId"),
22+
@Mapping(source = "title",target = "productName"),
23+
@Mapping(source = "price",target = "salePrice"),
24+
@Mapping(source = "sell_point",target = "subTitle"),
25+
@Mapping(source = "image",target = "picUrl")
26+
})
27+
ProductDto item2Dto(ItemDocument item);
28+
29+
List<ProductDto> items2Dto(List<ItemDocument> items);
30+
}

0 commit comments

Comments
 (0)