1.迁移product search 代码
2.先注释掉提示错误的代码,后续相关人员开发功能时自行解开 3.修改es连接方式为 rest,增加spring data jest
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package cn.iocoder.mall.search.rest.controller.user;
|
||||
|
||||
import cn.iocoder.common.framework.constant.MallConstants;
|
||||
import cn.iocoder.common.framework.util.StringUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.SortingField;
|
||||
import cn.iocoder.mall.search.biz.service.ProductSearchService;
|
||||
import cn.iocoder.mall.search.rest.response.user.ProductPageResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import cn.iocoder.mall.search.rest.request.user.ProductConditionRequest;
|
||||
import cn.iocoder.mall.search.rest.request.user.ProductSearchPageRequest;
|
||||
import cn.iocoder.mall.search.rest.response.user.ProductConditionResponse;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* Created with IDEA
|
||||
*
|
||||
* @author : lhl
|
||||
* @version : 1.0
|
||||
* @Time : 19:26
|
||||
* @date : 2020/5/14
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(MallConstants.ROOT_PATH_ADMIN + "users/product")
|
||||
@Api(tags = "商品查询 API")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class UsersProductSearchController {
|
||||
|
||||
|
||||
private final ProductSearchService productSearchService;
|
||||
|
||||
@GetMapping("/page") // TODO 芋艿,后面把 BO 改成 VO
|
||||
public CommonResult<ProductPageResponse> page(@RequestParam(value = "cid", required = false) Integer cid,
|
||||
@RequestParam(value = "keyword", required = false) String keyword,
|
||||
@RequestParam(value = "pageNo", required = false) Integer pageNo,
|
||||
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
||||
@RequestParam(value = "sortField", required = false) String sortField,
|
||||
@RequestParam(value = "sortOrder", required = false) String sortOrder) {
|
||||
// 创建 ProductSearchPageDTO 对象
|
||||
ProductSearchPageRequest productSearchPageDTO = new ProductSearchPageRequest().setCid(cid).setKeyword(keyword)
|
||||
.setPageNo(pageNo).setPageSize(pageSize);
|
||||
if (StringUtil.hasText(sortField) && StringUtil.hasText(sortOrder)) {
|
||||
productSearchPageDTO.setSorts(Collections.singletonList(new SortingField(sortField, sortOrder)));
|
||||
}
|
||||
// 执行搜索
|
||||
// return success(productSearchService.getSearchPage(productSearchPageDTO));
|
||||
return success(null);
|
||||
}
|
||||
|
||||
@GetMapping("/condition") // TODO 芋艿,后面把 BO 改成 VO
|
||||
public CommonResult<ProductConditionResponse> condition(@RequestParam(value = "keyword", required = false) String keyword) {
|
||||
// 创建 ProductConditionDTO 对象
|
||||
ProductConditionRequest productConditionDTO = new ProductConditionRequest().setKeyword(keyword)
|
||||
.setFields(Collections.singleton(ProductConditionRequest.FIELD_CATEGORY));
|
||||
// 执行搜索
|
||||
// return success(productSearchService.getSearchCondition(productConditionDTO));
|
||||
return success(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.search.rest.convert.user;
|
||||
|
||||
import cn.iocoder.mall.search.biz.bo.ProductBO;
|
||||
import cn.iocoder.mall.search.biz.dataobject.ESProductDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UsersProductSearchConvert {
|
||||
|
||||
cn.iocoder.mall.search.biz.convert.ProductSearchConvert INSTANCE = Mappers.getMapper(cn.iocoder.mall.search.biz.convert.ProductSearchConvert.class);
|
||||
|
||||
// @Mappings({})
|
||||
// ESProductDO convert(ProductSpuDetailBO spu);
|
||||
|
||||
// @Mappings({})
|
||||
// default ESProductDO convert(ProductSpuDetailBO spu, CalcSkuPriceBO calcSkuPrice) {
|
||||
// // Spu 的基础数据
|
||||
// ESProductDO product = this.convert(spu);
|
||||
// product.setOriginalPrice(calcSkuPrice.getOriginalPrice()).setBuyPrice(calcSkuPrice.getBuyPrice());
|
||||
// // 设置促销活动相关字段
|
||||
// if (calcSkuPrice.getTimeLimitedDiscount() != null) {
|
||||
// PromotionActivityBO activity = calcSkuPrice.getTimeLimitedDiscount();
|
||||
// product.setPromotionActivityId(activity.getId()).setPromotionActivityTitle(activity.getTitle())
|
||||
// .setPromotionActivityType(activity.getActivityType());
|
||||
// }
|
||||
// // 返回
|
||||
// return product;
|
||||
// }
|
||||
|
||||
List<ProductBO> convert(List<ESProductDO> list);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.iocoder.mall.search.rest.request.user;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 获得商品检索条件 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UsersProductConditionRequest{
|
||||
|
||||
/**
|
||||
* Field - 商品分类
|
||||
*/
|
||||
public static final String FIELD_CATEGORY = "category";
|
||||
|
||||
/**
|
||||
* 关键字
|
||||
*/
|
||||
private String keyword;
|
||||
/**
|
||||
* 需要返回的搜索条件的 fields 名
|
||||
*/
|
||||
private Collection<String> fields;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.iocoder.mall.search.rest.request.user;
|
||||
|
||||
import cn.iocoder.common.framework.util.CollectionUtil;
|
||||
import cn.iocoder.common.framework.vo.SortingField;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created with IDEA
|
||||
*
|
||||
* @author : lhl
|
||||
* @version : 1.0
|
||||
* @Time : 19:09
|
||||
* @date : 2020/5/14
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UsersProductSearchPageRequest {
|
||||
|
||||
public static final Set<String> SORT_FIELDS = CollectionUtil.asSet("buyPrice");
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 关键字
|
||||
*/
|
||||
private String keyword;
|
||||
|
||||
/**
|
||||
* 页码
|
||||
*/
|
||||
private Integer pageNo;
|
||||
/**
|
||||
* 分页大小
|
||||
*/
|
||||
private Integer pageSize;
|
||||
|
||||
/**
|
||||
* 排序字段数组
|
||||
*/
|
||||
private List<SortingField> sorts;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.search.rest.response.user;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品搜索条件返回 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UsersProductConditionResponse {
|
||||
|
||||
/**
|
||||
* 商品分类数组
|
||||
*/
|
||||
private List<Category> categories;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Category {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.iocoder.mall.search.rest.response.user;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UsersProductPageResponse implements Serializable {
|
||||
|
||||
/**
|
||||
* 管理员数组
|
||||
*/
|
||||
private List<ProductResponse> list;
|
||||
/**
|
||||
* 总量
|
||||
*/
|
||||
private Integer total;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package cn.iocoder.mall.search.rest.response.user;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 ES BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UsersProductResponse implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
// ========== 基本信息 =========
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 卖点
|
||||
*/
|
||||
private String sellPoint;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 分类名
|
||||
*/
|
||||
private String categoryName;
|
||||
/**
|
||||
* 商品主图地数组
|
||||
*/
|
||||
private List<String> picUrls;
|
||||
|
||||
// ========== 其他信息 =========
|
||||
/**
|
||||
* 是否上架商品(是否可见)。
|
||||
*
|
||||
* true 为已上架
|
||||
* false 为已下架
|
||||
*/
|
||||
private Boolean visible;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
// ========== Sku 相关字段 =========
|
||||
/**
|
||||
* 原价格,单位:分
|
||||
*/
|
||||
private Integer originalPrice;
|
||||
/**
|
||||
* 购买价格,单位:分。
|
||||
*/
|
||||
private Integer buyPrice;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
// ========== 促销活动相关字段 =========
|
||||
// 目前只促销单体商品促销,目前仅限制折扣。
|
||||
/**
|
||||
* 促销活动编号
|
||||
*/
|
||||
private Integer promotionActivityId;
|
||||
/**
|
||||
* 促销活动标题
|
||||
*/
|
||||
private String promotionActivityTitle;
|
||||
/**
|
||||
* 促销活动类型
|
||||
*/
|
||||
private Integer promotionActivityType;
|
||||
|
||||
}
|
||||
12
search/search-rest/src/main/resources/rest.yaml
Normal file
12
search/search-rest/src/main/resources/rest.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
# 服务器的配置项
|
||||
server:
|
||||
port: 18099
|
||||
servlet:
|
||||
context-path: /search-api/
|
||||
|
||||
# Swagger 配置项
|
||||
swagger:
|
||||
title: 商品查询子系统
|
||||
description: 商品查询子系统
|
||||
version: 1.0.0
|
||||
base-package: cn.iocoder.mall.search.rest.controller
|
||||
Reference in New Issue
Block a user