初始化商品分页接口

This commit is contained in:
YunaiV 2020-08-04 08:12:08 +08:00
parent 5acf1ae3d4
commit f3316d14c7
24 changed files with 371 additions and 93 deletions

View File

@ -5,6 +5,7 @@
"accessToken": "yudaoyuanma",
"user-api-base-url": "http://127.0.0.1:18082/user-api/",
"shop-api-base-url": "http://127.0.0.1:18084/shop-api/",
"user-access-token": "yunai",
"dubboTag": "${HOSTNAME}"

View File

@ -70,19 +70,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
return ProductSpuConvert.INSTANCE.convert2(spu, skus, attrAndValuePairList, category);
}
@Override
public List<ProductSpuDetailBO> getProductSpuDetailListForSync(Integer lastId, Integer limit) {
// TODO 芋艿这里目前是一个一个进行计算后续需要优化下
// 查询下一批商品编号集合
List<Integer> spuIds = productSpuMapper.selectIdListByIdGt(lastId, limit);
if (spuIds.isEmpty()) {
return Collections.emptyList();
}
// 查询每个商品明细
List<ProductSpuDetailBO> spus = spuIds.stream().map(id -> getProductSpuDetail(id)).collect(Collectors.toList()); // TODO 芋艿此处相当于是 N 个查询后续要优化
return spus;
}
@Override
public Boolean updateProductSpuSort(Integer adminId, Integer spuId, Integer sort) {
// 校验 Spu 是否存在

View File

@ -1,20 +0,0 @@
package cn.iocoder.mall.product.application.vo.users;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@ApiModel("商品 SPU 分页 VO")
@Data
@Accessors(chain = true)
public class UsersProductSpuPageVO {
@ApiModelProperty(value = "spu 数组", required = true)
private List<UsersProductSpuVO> spus;
@ApiModelProperty(value = "总数", required = true)
private Integer count;
}

View File

@ -1,7 +1,15 @@
package cn.iocoder.mall.searchservice.rpc.product;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductPageReqDTO;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO;
/**
* 商品搜索 RPC 接口
*/
public interface SearchProductRpc {
CommonResult<PageResult<SearchProductRespDTO>> pageSearchProduct(SearchProductPageReqDTO pageQueryReqDTO);
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.mall.searchservice.rpc.product.dto;
import cn.iocoder.common.framework.vo.PageParam;
import cn.iocoder.common.framework.vo.SortingField;
import cn.iocoder.mall.searchservice.enums.product.SearchProductPageQuerySortFieldEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.List;
/**
* 商品检索分页查询 Request DTO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class SearchProductPageReqDTO extends PageParam {
/**
* 分类编号
*/
private Integer cid;
/**
* 关键字
*/
private String keyword;
/**
* 排序字段数组
*
* 可支持排序的字段 {@link SearchProductPageQuerySortFieldEnum}
*/
private List<SortingField> sorts;
}

View File

@ -0,0 +1,85 @@
package cn.iocoder.mall.searchservice.rpc.product.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
/**
* 搜索商品 Response DTO
*/
@Data
@Accessors(chain = true)
public class SearchProductRespDTO {
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;
}

View File

@ -4,7 +4,10 @@ import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
import cn.iocoder.mall.searchservice.dal.es.dataobject.ESProductDO;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductPageReqDTO;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductBO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductPageQueryBO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductSaveBO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@ -39,4 +42,8 @@ public interface SearchProductConvert {
.setTotal(searchPage.getTotalElements());
}
SearchProductPageQueryBO convert(SearchProductPageReqDTO bean);
PageResult<SearchProductRespDTO> convertPage(PageResult<SearchProductBO> pageResult);
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.mall.searchservice.manager.product;
import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.productservice.rpc.category.ProductCategoryRpc;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuRpc;
@ -10,7 +11,10 @@ import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
import cn.iocoder.mall.searchservice.convert.product.SearchProductConvert;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductPageReqDTO;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO;
import cn.iocoder.mall.searchservice.service.product.SearchProductService;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductBO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductSaveBO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
@ -39,6 +43,11 @@ public class SearchProductManager {
@Autowired
private SearchProductService searchProductService;
public PageResult<SearchProductRespDTO> pageSearchProduct(SearchProductPageReqDTO pageReqDTO) {
PageResult<SearchProductBO> pageResult = searchProductService.pageSearchProduct(SearchProductConvert.INSTANCE.convert(pageReqDTO));
return SearchProductConvert.INSTANCE.convertPage(pageResult);
}
/**
* 重建所有商品的 ES 索引
*

View File

@ -1,7 +1,24 @@
package cn.iocoder.mall.searchservice.rpc.product;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.searchservice.manager.product.SearchProductManager;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductPageReqDTO;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@DubboService
public class SearchProductRpcImpl implements SearchProductRpc {
@Autowired
private SearchProductManager searchProductManager;
@Override
public CommonResult<PageResult<SearchProductRespDTO>> pageSearchProduct(SearchProductPageReqDTO pageQueryReqDTO) {
return success(searchProductManager.pageSearchProduct(pageQueryReqDTO));
}
}

View File

@ -42,7 +42,7 @@ public class SearchProductService {
* @param pageQueryBO 分页查询条件
* @return 商品信息
*/
public PageResult<SearchProductBO> getSearchPage(SearchProductPageQueryBO pageQueryBO) {
public PageResult<SearchProductBO> pageSearchProduct(SearchProductPageQueryBO pageQueryBO) {
checkSortFieldInvalid(pageQueryBO.getSorts());
// 执行查询
Page<ESProductDO> searchPage = productRepository.search(pageQueryBO.getCid(), pageQueryBO.getKeyword(),

View File

@ -2,7 +2,9 @@ package cn.iocoder.mall.searchservice.service.product.bo;
import cn.iocoder.common.framework.vo.PageParam;
import cn.iocoder.common.framework.vo.SortingField;
import cn.iocoder.mall.searchservice.enums.product.SearchProductPageQuerySortFieldEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.List;
@ -11,6 +13,7 @@ import java.util.List;
* 商品检索分查询 BO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class SearchProductPageQueryBO extends PageParam {
@ -25,7 +28,7 @@ public class SearchProductPageQueryBO extends PageParam {
/**
* 排序字段数组
*
*
* 可支持排序的字段 {@link SearchProductPageQuerySortFieldEnum}
*/
private List<SortingField> sorts;

View File

@ -1,21 +0,0 @@
package cn.iocoder.mall.search.biz.api.user;
import cn.iocoder.common.framework.vo.CommonResult;
public interface ProductSearchRPC {
CommonResult<Integer> rebuild();
/**
* 构建商品的搜索索引
*
* @param id 商品编号
* @return 构建结果
*/
CommonResult<Boolean> save(Integer id);
// ProductPageBO getSearchPage(ProductSearchPageDTO searchPageDTO);
//
// ProductConditionBO getSearchCondition(ProductConditionDTO conditionDTO);
}

View File

@ -1,22 +0,0 @@
package cn.iocoder.mall.search.biz.response.user;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
@Data
@Accessors(chain = true)
public class ProductPageResponse implements Serializable {
/**
* 管理员数组
*/
private List<ProductResponse> list;
/**
* 总量
*/
private Integer total;
}

View File

@ -60,6 +60,12 @@
<artifactId>product-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<!-- 搜索服务 -->
<groupId>cn.iocoder.mall</groupId>
<artifactId>search-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<!-- 系统服务 -->
<groupId>cn.iocoder.mall</groupId>

View File

@ -1,4 +1,4 @@
### /user-address/get-default 成功
GET {{user-api-base-url}}/product-category/list?pid=0
GET {{shop-api-base-url}}/product-category/list?pid=0
###

View File

@ -17,14 +17,10 @@ import java.util.List;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* 商品分类 Controller
*/
@Api(tags = "商品分类 API")
@RestController
@RequestMapping("/product-category")
@Api(tags = "商品分类")
@Validated
// TODO 芋艿稍后迁移到 shop-web-app 服务下
public class ProductCategoryController {
@Autowired

View File

@ -0,0 +1,33 @@
package cn.iocoder.mall.shopweb.controller.product;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuPageReqVO;
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO;
import cn.iocoder.mall.shopweb.manager.product.ProductSpuManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@Api(tags = "商品 SPU API")
@RestController
@RequestMapping("/product-spu")
@Validated
public class ProductSpuController {
@Autowired
private ProductSpuManager productSpuManager;
@GetMapping("/page")
@ApiOperation("获得商品 SPU 的分页")
public CommonResult<PageResult<ProductSpuRespVO>> pageProductSpu(ProductSpuPageReqVO pageReqVO) {
return success(productSpuManager.pageProductSpu(pageReqVO));
}
}

View File

@ -1 +0,0 @@
package cn.iocoder.mall.shopweb.controller.product.vo;

View File

@ -0,0 +1,24 @@
package cn.iocoder.mall.shopweb.controller.product.vo.product;
import cn.iocoder.common.framework.vo.PageParam;
import cn.iocoder.common.framework.vo.SortingField;
import java.util.List;
public class ProductSpuPageReqVO extends PageParam {
/**
* 分类编号
*/
private Integer cid;
/**
* 关键字
*/
private String keyword;
/**
* 排序字段数组
*/
private List<SortingField> sorts;
}

View File

@ -0,0 +1,84 @@
package cn.iocoder.mall.shopweb.controller.product.vo.product;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@ApiModel("商品 SPU Response VO")
@Data
@Accessors(chain = true)
public class ProductSpuRespVO {
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;
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.mall.shopweb.convert.product;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductPageReqDTO;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO;
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuPageReqVO;
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface ProductSpuConvert {
ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class);
SearchProductPageReqDTO convert(ProductSpuPageReqVO bean);
PageResult<ProductSpuRespVO> convertPage(PageResult<SearchProductRespDTO> page);
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.mall.shopweb.manager.product;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.searchservice.rpc.product.SearchProductRpc;
import cn.iocoder.mall.searchservice.rpc.product.dto.SearchProductRespDTO;
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuPageReqVO;
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO;
import cn.iocoder.mall.shopweb.convert.product.ProductSpuConvert;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
/**
* Product SPU Manager
*/
@Service
@Validated
public class ProductSpuManager {
@DubboReference(version = "${dubbo.consumer.SearchProductRpc.version}")
private SearchProductRpc searchProductRpc;
public PageResult<ProductSpuRespVO> pageProductSpu(ProductSpuPageReqVO pageReqVO) {
CommonResult<PageResult<SearchProductRespDTO>> pageResult =
searchProductRpc.pageSearchProduct(ProductSpuConvert.INSTANCE.convert(pageReqVO));
pageResult.checkError();
return ProductSpuConvert.INSTANCE.convertPage(pageResult.getData());
}
}

View File

@ -1,8 +1,8 @@
# 服务器的配置项
server:
port: 18083
port: 18084
servlet:
context-path: /user-api/
context-path: /shop-api/
spring:
# Application 的配置项
@ -25,8 +25,6 @@ dubbo:
consumer:
timeout: 10000
validation: true # 开启 Consumer 的参数校验
UserSmsCodeRpc:
version: 1.0.0
UserRpc:
version: 1.0.0
OAuth2Rpc:
@ -35,10 +33,10 @@ dubbo:
version: 1.0.0
SystemExceptionLogRpc:
version: 1.0.0
UserAddressRpc:
version: 1.0.0
ProductCategoryRpc:
version: 1.0.0
SearchProductRpc:
version: 1.0.0
# Swagger 配置项
swagger:

View File

@ -37,8 +37,6 @@ dubbo:
version: 1.0.0
UserAddressRpc:
version: 1.0.0
ProductCategoryRpc:
version: 1.0.0
# Swagger 配置项
swagger: