1. ProductSPU 迁移springcloud.
2. 调用方manager通过feign调用spu api
This commit is contained in:
parent
c50f99e7b3
commit
4f50845b66
|
@ -7,7 +7,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc.spu"})
|
||||
public class ManagementWebApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
### /product-spu/page 成功(全部)
|
||||
GET {{baseUrl}}/product-spu/page?pageNo=1&pageSize=10
|
||||
GET http://127.0.0.1:18083/management-api/product-spu/page?pageNo=1&pageSize=100
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
Authorization: Bearer yudaoyuanma
|
||||
|
||||
### /product-spu/page 成功(有库存 + 上架)
|
||||
GET {{baseUrl}}/product-spu/page?pageNo=1&pageSize=10&hasQuantity=true&visible=true
|
||||
|
@ -14,11 +14,11 @@ Content-Type: application/x-www-form-urlencoded
|
|||
Authorization: Bearer {{accessToken}}
|
||||
|
||||
### /product-spu/create 成功
|
||||
POST {{baseUrl}}/product-spu/create
|
||||
POST http://127.0.0.1:18083/management-api/product-spu/create
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
Authorization: Bearer yudaoyuanma
|
||||
|
||||
name=测试商品标题&description=测试商品描述&cid=637&sellPoint=丑&picUrls=1,2,3&visible=true
|
||||
name=新商品&description=新商品描述&cid=637&sellPoint=丑&picUrls=1,2,3&visible=true
|
||||
&skus[0].price=1&skus[0].quantity=100&skus[0].attrValueIds=1,3
|
||||
&skus[1].price=2&skus[1].quantity=50&skus[1].attrValueIds=2,4
|
||||
|
||||
|
@ -40,11 +40,11 @@ name=测试商品标题&description=测试商品描述&cid=637&sellPoint=丑&pic
|
|||
&skus[1].price=2&skus[1].quantity=50&skus[1].attrValueIds=1,2,4
|
||||
|
||||
### /product-spu/update 成功
|
||||
POST {{baseUrl}}/product-spu/update
|
||||
POST http://127.0.0.1:18083/management-api/product-spu/update
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
Authorization: Bearer yudaoyuanma
|
||||
|
||||
id=59&name=测试商品标题&description=测试商品描述&cid=637&sellPoint=丑&picUrls=1,2,3&visible=true
|
||||
id=64&name=新商品测试&description=新商品测试&cid=637&sellPoint=丑&picUrls=1,2,3&visible=true
|
||||
&skus[0].price=1&skus[0].quantity=100&skus[0].attrValueIds=1,3
|
||||
&skus[1].price=2&skus[1].quantity=50&skus[1].attrValueIds=2,4
|
||||
|
||||
|
@ -57,3 +57,9 @@ Authorization:Bearer yudaoyuanma
|
|||
|
||||
###
|
||||
|
||||
### /product-spu/get
|
||||
GET http://127.0.0.1:18083/management-api/product-spu/list?productSpuIds=32,33,34
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization:Bearer yudaoyuanma
|
||||
|
||||
###
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package cn.iocoder.mall.managementweb.feign;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@FeignClient(value = "product-service")
|
||||
public interface ProductSpuFeign {
|
||||
/**
|
||||
* 获得商品 SPU
|
||||
*
|
||||
* @param productSpuId 商品 SPU 编号
|
||||
* @return 商品 SPU
|
||||
*/
|
||||
@GetMapping(value = "/product/spu/get")
|
||||
CommonResult<ProductSpuRespDTO> getProductSpu(@RequestParam("productSpuId") Integer productSpuId);
|
||||
|
||||
}
|
|
@ -7,10 +7,8 @@ import cn.iocoder.mall.managementweb.controller.product.vo.spu.ProductSpuPageReq
|
|||
import cn.iocoder.mall.managementweb.controller.product.vo.spu.ProductSpuRespVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.spu.ProductSpuUpdateReqVO;
|
||||
import cn.iocoder.mall.managementweb.convert.product.ProductSpuConvert;
|
||||
import cn.iocoder.mall.managementweb.feign.ProductSpuFeign;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -22,8 +20,6 @@ import java.util.List;
|
|||
@Service
|
||||
public class ProductSpuManager {
|
||||
|
||||
@DubboReference(version = "${dubbo.consumer.ProductSpuRpc.version}")
|
||||
private ProductSpuRpc productSpuRpc;
|
||||
|
||||
@Autowired
|
||||
private ProductSpuFeign productSpuFeign;
|
||||
|
@ -35,7 +31,7 @@ public class ProductSpuManager {
|
|||
* @return 商品 SPU
|
||||
*/
|
||||
public Integer createProductSpu(ProductSpuCreateReqVO createVO) {
|
||||
CommonResult<Integer> createProductSpuResult = productSpuRpc.createProductSpu(ProductSpuConvert.INSTANCE.convert(createVO));
|
||||
CommonResult<Integer> createProductSpuResult = productSpuFeign.createProductSpu(ProductSpuConvert.INSTANCE.convert(createVO));
|
||||
createProductSpuResult.checkError();
|
||||
return createProductSpuResult.getData();
|
||||
}
|
||||
|
@ -46,7 +42,7 @@ public class ProductSpuManager {
|
|||
* @param updateVO 更新商品 SPU VO
|
||||
*/
|
||||
public void updateProductSpu(ProductSpuUpdateReqVO updateVO) {
|
||||
CommonResult<Boolean> updateProductSpuResult = productSpuRpc.updateProductSpu(ProductSpuConvert.INSTANCE.convert(updateVO));
|
||||
CommonResult<Boolean> updateProductSpuResult = productSpuFeign.updateProductSpu(ProductSpuConvert.INSTANCE.convert(updateVO));
|
||||
updateProductSpuResult.checkError();
|
||||
}
|
||||
|
||||
|
@ -69,7 +65,7 @@ public class ProductSpuManager {
|
|||
* @return 商品 SPU列表
|
||||
*/
|
||||
public List<ProductSpuRespVO> listProductSpus(List<Integer> productSpuIds) {
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpuResult = productSpuRpc.listProductSpus(productSpuIds);
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpuResult = productSpuFeign.listProductSpus(productSpuIds);
|
||||
listProductSpuResult.checkError();
|
||||
return ProductSpuConvert.INSTANCE.convertList(listProductSpuResult.getData());
|
||||
}
|
||||
|
@ -81,7 +77,7 @@ public class ProductSpuManager {
|
|||
* @return 商品 SPU分页结果
|
||||
*/
|
||||
public PageResult<ProductSpuRespVO> pageProductSpu(ProductSpuPageReqVO pageVO) {
|
||||
CommonResult<PageResult<ProductSpuRespDTO>> pageProductSpuResult = productSpuRpc.pageProductSpu(ProductSpuConvert.INSTANCE.convert(pageVO));
|
||||
CommonResult<PageResult<ProductSpuRespDTO>> pageProductSpuResult = productSpuFeign.pageProductSpu(ProductSpuConvert.INSTANCE.convert(pageVO));
|
||||
pageProductSpuResult.checkError();
|
||||
return ProductSpuConvert.INSTANCE.convertPage(pageProductSpuResult.getData());
|
||||
}
|
||||
|
|
|
@ -8,11 +8,12 @@ import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRe
|
|||
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendPageReqVO;
|
||||
import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendUpdateReqVO;
|
||||
import cn.iocoder.mall.managementweb.convert.promotion.ProductRecommendConvert;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.ProductRecommendRpc;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendRespDTO;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
|
@ -28,9 +29,8 @@ public class ProductRecommendManager {
|
|||
|
||||
@DubboReference(version = "${dubbo.consumer.ProductRecommendRpc.version}")
|
||||
private ProductRecommendRpc productRecommendRpc;
|
||||
@DubboReference(version = "${dubbo.consumer.ProductSpuRpc.version}")
|
||||
private ProductSpuRpc productSpuRpc;
|
||||
|
||||
@Autowired
|
||||
private ProductSpuFeign productSpuFeign;
|
||||
/**
|
||||
* 创建商品推荐
|
||||
*
|
||||
|
@ -78,7 +78,7 @@ public class ProductRecommendManager {
|
|||
PageResult<ProductRecommendDetailVO> pageResult = ProductRecommendConvert.INSTANCE.convertPage(pageProductRecommendResult.getData());
|
||||
if (!CollectionUtils.isEmpty(pageResult.getList())) {
|
||||
// 获取商品信息,并进行拼接
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpusResult = productSpuRpc.listProductSpus(
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpusResult = productSpuFeign.listProductSpus(
|
||||
CollectionUtils.convertSet(pageResult.getList(), ProductRecommendDetailVO::getProductSpuId));
|
||||
listProductSpusResult.checkError();
|
||||
Map<Integer, ProductSpuRespDTO> productSpuMap = CollectionUtils.convertMap(listProductSpusResult.getData(), ProductSpuRespDTO::getId);
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package cn.iocoder.mall.productservice.rpc.spu;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(value = "product-service")
|
||||
public interface ProductSpuFeign {
|
||||
/**
|
||||
* 获得商品 SPU
|
||||
*
|
||||
* @param productSpuId 商品 SPU 编号
|
||||
* @return 商品 SPU
|
||||
*/
|
||||
@GetMapping(value = "/product/spu/get")
|
||||
CommonResult<ProductSpuRespDTO> getProductSpu(@RequestParam("productSpuId") Integer productSpuId);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建商品 SPU
|
||||
*
|
||||
* @param createDTO 创建商品 SPU DTO
|
||||
* @return 商品 SPU编号
|
||||
*/
|
||||
@PostMapping(value = "/product/spu/create")
|
||||
CommonResult<Integer> createProductSpu(@RequestBody ProductSpuAndSkuCreateReqDTO createDTO);
|
||||
|
||||
/**
|
||||
* 更新商品 SPU
|
||||
*
|
||||
* @param updateDTO 更新商品 SPU DTO
|
||||
*/
|
||||
@PostMapping(value = "/product/spu/update")
|
||||
CommonResult<Boolean> updateProductSpu(@RequestBody ProductSpuAndSkuUpdateReqDTO updateDTO);
|
||||
|
||||
|
||||
/**
|
||||
* 获得商品 SPU列表
|
||||
*
|
||||
* @param productSpuIds 商品 SPU 编号列表
|
||||
* @return 商品 SPU 列表
|
||||
*/
|
||||
@GetMapping(value = "/product/spu/list")
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpus(@RequestParam("productSpuIds") Collection<Integer> productSpuIds);
|
||||
|
||||
/**
|
||||
* 获得商品 SPU 分页
|
||||
*
|
||||
* @param pageDTO 商品 SPU 分页查询
|
||||
* @return 商品 SPU 分页结果
|
||||
*/
|
||||
@PostMapping(value = "/product/spu/page")
|
||||
CommonResult<PageResult<ProductSpuRespDTO>> pageProductSpu(@RequestBody ProductSpuPageReqDTO pageDTO);
|
||||
|
||||
/**
|
||||
* 顺序获得商品 SPU 编号数组
|
||||
*
|
||||
* @param lastSpuId 最后一个商品 SPU 编号
|
||||
* @param limit 数量
|
||||
* @return 商品 SPU 编号数组
|
||||
*/
|
||||
@GetMapping(value = "/product/spu/lislistProductSpuIdst")
|
||||
CommonResult<List<Integer>> listProductSpuIds(@RequestParam("lastSpuId")Integer lastSpuId, @RequestParam("limit")Integer limit);
|
||||
|
||||
@GetMapping(value = "/product/spu/getProductSpuDetail")
|
||||
CommonResult<ProductSpuDetailRespDTO> getProductSpuDetail(@RequestParam("productSpuId") Integer productSpuId,@RequestParam("fields") Collection<String> fields);
|
||||
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package cn.iocoder.mall.productservice.rpc.spu;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 SPU Rpc 接口
|
||||
*/
|
||||
public interface ProductSpuRpc {
|
||||
|
||||
/**
|
||||
* 创建商品 SPU
|
||||
*
|
||||
* @param createDTO 创建商品 SPU DTO
|
||||
* @return 商品 SPU编号
|
||||
*/
|
||||
CommonResult<Integer> createProductSpu(ProductSpuAndSkuCreateReqDTO createDTO);
|
||||
|
||||
/**
|
||||
* 更新商品 SPU
|
||||
*
|
||||
* @param updateDTO 更新商品 SPU DTO
|
||||
*/
|
||||
CommonResult<Boolean> updateProductSpu(ProductSpuAndSkuUpdateReqDTO updateDTO);
|
||||
|
||||
/**
|
||||
* 获得商品 SPU
|
||||
*
|
||||
* @param productSpuId 商品 SPU 编号
|
||||
* @return 商品 SPU
|
||||
*/
|
||||
CommonResult<ProductSpuRespDTO> getProductSpu(Integer productSpuId);
|
||||
|
||||
/**
|
||||
* 获得商品 SPU列表
|
||||
*
|
||||
* @param productSpuIds 商品 SPU 编号列表
|
||||
* @return 商品 SPU 列表
|
||||
*/
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpus(Collection<Integer> productSpuIds);
|
||||
|
||||
/**
|
||||
* 获得商品 SPU 分页
|
||||
*
|
||||
* @param pageDTO 商品 SPU 分页查询
|
||||
* @return 商品 SPU 分页结果
|
||||
*/
|
||||
CommonResult<PageResult<ProductSpuRespDTO>> pageProductSpu(ProductSpuPageReqDTO pageDTO);
|
||||
|
||||
/**
|
||||
* 顺序获得商品 SPU 编号数组
|
||||
*
|
||||
* @param lastSpuId 最后一个商品 SPU 编号
|
||||
* @param limit 数量
|
||||
* @return 商品 SPU 编号数组
|
||||
*/
|
||||
CommonResult<List<Integer>> listProductSpuIds(Integer lastSpuId, Integer limit);
|
||||
|
||||
CommonResult<ProductSpuDetailRespDTO> getProductSpuDetail(Integer productSpuId, Collection<String> fields);
|
||||
|
||||
}
|
|
@ -2,3 +2,12 @@
|
|||
GET http://localhost:38082/product/spu/get?productSpuId=32
|
||||
###
|
||||
|
||||
### /product/spu/get 获得商品 SPU
|
||||
GET http://localhost:38082/product/spu/lislistProductSpuIdst?lastSpuId=30&limit=10
|
||||
###
|
||||
|
||||
|
||||
### /product/spu/get 获得商品 SPU
|
||||
GET http://localhost:38082/product/spu/getProductSpuDetail?productSpuId=32&fields=attr,sku
|
||||
###
|
||||
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package cn.iocoder.mall.productservice.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.manager.spu.ProductSpuManager;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/product/spu")
|
||||
@Api("商品spu")
|
||||
public class ProductSpuController {
|
||||
@Autowired
|
||||
private ProductSpuManager productSpuManager;
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得商品 SPU")
|
||||
@ApiImplicitParam(name = "productSpuId", value = "商品 SPU 编号", required = true)
|
||||
public CommonResult<ProductSpuRespDTO> getProductSpu(@RequestParam(value="productSpuId") Integer productSpuId) {
|
||||
return success(productSpuManager.getProductSpu(productSpuId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品 SPU
|
||||
*
|
||||
* @param updateDTO 更新商品 SPU DTO
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("更新商品 SPU")
|
||||
public CommonResult<Boolean> updateProductSpu(@Valid @RequestBody ProductSpuAndSkuUpdateReqDTO updateDTO) {
|
||||
productSpuManager.updateProductSpu(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建商品 SPU")
|
||||
public CommonResult<Integer> createProductSpu(@Valid @RequestBody ProductSpuAndSkuCreateReqDTO createDTO) {
|
||||
return success(productSpuManager.createProductSpu(createDTO));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得商品 SPU 列表")
|
||||
@ApiImplicitParam(name = "productSpuIds", value = "商品 SPU 编号列表", required = true)
|
||||
public CommonResult<List<ProductSpuRespDTO>> listProductSpus(@RequestParam("productSpuIds") List<Integer> productSpuIds) {
|
||||
return success(productSpuManager.listProductSpus(productSpuIds));
|
||||
}
|
||||
|
||||
@PostMapping("/page")
|
||||
@ApiOperation("获得商品 SPU 分页")
|
||||
public CommonResult<PageResult<ProductSpuRespDTO>> pageProductSpu(@RequestBody ProductSpuPageReqDTO pageVO) {
|
||||
// 全部:无搜索条件
|
||||
// 在售中:visible = true && hasQuantity = true
|
||||
// 已售罄:visible = true && hasQuantity = false
|
||||
// 仓库中:visible = false
|
||||
return success(productSpuManager.pageProductSpu(pageVO));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 顺序获得商品 SPU 编号数组
|
||||
*
|
||||
* @param lastSpuId 最后一个商品 SPU 编号
|
||||
* @param limit 数量
|
||||
* @return 商品 SPU 编号数组
|
||||
*/
|
||||
@GetMapping("/lislistProductSpuIdst")
|
||||
public CommonResult<List<Integer>> lislistProductSpuIdst(@RequestParam("lastSpuId")Integer lastSpuId, @RequestParam("limit")Integer limit) {
|
||||
// 全部:无搜索条件
|
||||
// 在售中:visible = true && hasQuantity = true
|
||||
// 已售罄:visible = true && hasQuantity = false
|
||||
// 仓库中:visible = false
|
||||
return success(productSpuManager.listProductSpuIds(lastSpuId, limit));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/getProductSpuDetail")
|
||||
public CommonResult<ProductSpuDetailRespDTO> getProductSpuDetail(@RequestParam("productSpuId") Integer productSpuId,@RequestParam("fields") Collection<String> fields) {
|
||||
return success(productSpuManager.getProductSpuDetail(productSpuId,fields));
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package cn.iocoder.mall.productservice.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.productservice.manager.spu.ProductSpuManager;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
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 static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/product/spu")
|
||||
@Api("商品spu")
|
||||
public class SpuController {
|
||||
@Autowired
|
||||
private ProductSpuManager productSpuManager;
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得商品 SPU")
|
||||
@ApiImplicitParam(name = "productSpuId", value = "商品 SPU 编号", required = true)
|
||||
public CommonResult<ProductSpuRespDTO> getProductSpu(@RequestParam(value="productSpuId") Integer productSpuId) {
|
||||
return success(productSpuManager.getProductSpu(productSpuId));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package cn.iocoder.mall.productservice.rpc.spu;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.manager.spu.ProductSpuManager;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 商品 SPU Rpc 实现类
|
||||
*/
|
||||
@DubboService
|
||||
public class ProductSpuRpcImpl implements ProductSpuRpc {
|
||||
|
||||
@Autowired
|
||||
private ProductSpuManager productSpuManager;
|
||||
|
||||
@Override
|
||||
public CommonResult<Integer> createProductSpu(ProductSpuAndSkuCreateReqDTO createDTO) {
|
||||
return success(productSpuManager.createProductSpu(createDTO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateProductSpu(ProductSpuAndSkuUpdateReqDTO updateDTO) {
|
||||
productSpuManager.updateProductSpu(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<ProductSpuRespDTO> getProductSpu(Integer productSpuId) {
|
||||
return success(productSpuManager.getProductSpu(productSpuId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<ProductSpuRespDTO>> listProductSpus(Collection<Integer> productSpuIds) {
|
||||
return success(productSpuManager.listProductSpus(productSpuIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<PageResult<ProductSpuRespDTO>> pageProductSpu(ProductSpuPageReqDTO pageDTO) {
|
||||
return success(productSpuManager.pageProductSpu(pageDTO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<Integer>> listProductSpuIds(Integer lastSpuId, Integer limit) {
|
||||
return success(productSpuManager.listProductSpuIds(lastSpuId, limit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<ProductSpuDetailRespDTO> getProductSpuDetail(Integer productSpuId, Collection<String> fields) {
|
||||
return success(productSpuManager.getProductSpuDetail(productSpuId, fields));
|
||||
}
|
||||
|
||||
}
|
|
@ -104,6 +104,10 @@
|
|||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.9.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -3,8 +3,12 @@ package cn.iocoder.mall.promotionservice;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc.spu"})
|
||||
public class PromotionServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -6,9 +6,11 @@ import cn.iocoder.common.framework.vo.CommonResult;
|
|||
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.promotion.api.enums.*;
|
||||
import cn.iocoder.mall.promotion.api.enums.MeetTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.enums.PreferentialTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityStatusEnum;
|
||||
import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
|
||||
|
@ -36,8 +38,8 @@ public class PriceManager {
|
|||
|
||||
@DubboReference(version = "${dubbo.consumer.ProductSkuRpc.version}")
|
||||
private ProductSkuRpc productSkuRpc;
|
||||
@DubboReference(version = "${dubbo.consumer.ProductSpuRpc.version}")
|
||||
private ProductSpuRpc productSpuRpc;
|
||||
@Autowired
|
||||
private ProductSpuFeign productSpuFeign;
|
||||
|
||||
@Autowired
|
||||
private PromotionActivityService promotionActivityService;
|
||||
|
@ -95,7 +97,7 @@ public class PriceManager {
|
|||
private List<PriceProductCalcRespDTO.Item> initCalcOrderPriceItems(List<ProductSkuRespDTO> skus,
|
||||
Map<Integer, PriceProductCalcReqDTO.Item> calcProductItemDTOMap) {
|
||||
// 获得商品分类 Map
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpusResult = productSpuRpc.listProductSpus(CollectionUtils.convertSet(skus, ProductSkuRespDTO::getSpuId));
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpusResult = productSpuFeign.listProductSpus(CollectionUtils.convertSet(skus, ProductSkuRespDTO::getSpuId));
|
||||
listProductSpusResult.checkError();
|
||||
Map<Integer, Integer> spuIdCategoryIdMap = CollectionUtils.convertMap(listProductSpusResult.getData(), // SPU 编号与 Category 编号的映射
|
||||
ProductSpuRespDTO::getId, ProductSpuRespDTO::getCid);
|
||||
|
|
|
@ -3,11 +3,10 @@ package cn.iocoder.mall.promotionservice.manager.recommend;
|
|||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.*;
|
||||
import cn.iocoder.mall.promotionservice.service.recommend.ProductRecommendService;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -23,8 +22,8 @@ import static cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants.PR
|
|||
@Validated
|
||||
public class ProductRecommendManager {
|
||||
|
||||
@DubboReference(validation = "true", version = "${dubbo.consumer.ProductSpuRpc.version}")
|
||||
private ProductSpuRpc productSpuRpc;
|
||||
@Autowired
|
||||
private ProductSpuFeign productSpuFeign;
|
||||
|
||||
@Autowired
|
||||
private ProductRecommendService productRecommendService;
|
||||
|
@ -56,7 +55,7 @@ public class ProductRecommendManager {
|
|||
}
|
||||
|
||||
private void checkProductSpu(Integer productSpuId) {
|
||||
CommonResult<ProductSpuRespDTO> getProductSpuResult = productSpuRpc.getProductSpu(productSpuId);
|
||||
CommonResult<ProductSpuRespDTO> getProductSpuResult = productSpuFeign.getProductSpu(productSpuId);
|
||||
getProductSpuResult.checkError();
|
||||
if (getProductSpuResult.getData() == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS);
|
||||
|
|
|
@ -101,6 +101,10 @@
|
|||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.9.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -2,8 +2,12 @@ package cn.iocoder.mall.searchservice;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc.spu"})
|
||||
public class SearchServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
|
|||
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
|
||||
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.SearchProductConditionReqDTO;
|
||||
|
@ -33,13 +33,14 @@ public class SearchProductManager {
|
|||
|
||||
private static final Integer REBUILD_FETCH_PER_SIZE = 100;
|
||||
|
||||
@DubboReference(version = "${dubbo.consumer.ProductSpuRpc.version}")
|
||||
private ProductSpuRpc productSpuRpc;
|
||||
@DubboReference(version = "${dubbo.consumer.ProductSkuRpc.version}")
|
||||
private ProductSkuRpc productSkuRpc;
|
||||
@DubboReference(version = "${dubbo.consumer.ProductCategoryRpc.version}")
|
||||
private ProductCategoryRpc productCategoryRpc;
|
||||
|
||||
@Autowired
|
||||
private ProductSpuFeign productSpuFeign;
|
||||
|
||||
// @DubboReference( version = "${dubbo.consumer.CartService.version}")
|
||||
// private CartService cartService;
|
||||
|
||||
|
@ -68,7 +69,7 @@ public class SearchProductManager {
|
|||
int rebuildCounts = 0;
|
||||
while (true) {
|
||||
// 从商品服务,增量获取商品列表编号
|
||||
CommonResult<List<Integer>> listProductSpuIdsResult = productSpuRpc.listProductSpuIds(lastId, REBUILD_FETCH_PER_SIZE);
|
||||
CommonResult<List<Integer>> listProductSpuIdsResult = productSpuFeign.listProductSpuIds(lastId, REBUILD_FETCH_PER_SIZE);
|
||||
listProductSpuIdsResult.checkError();
|
||||
List<Integer> spuIds = listProductSpuIdsResult.getData();
|
||||
// 逐个重建索引到 ES 中
|
||||
|
@ -93,7 +94,7 @@ public class SearchProductManager {
|
|||
*/
|
||||
public Boolean saveProduct(Integer id) {
|
||||
// 获得商品 SPU
|
||||
CommonResult<ProductSpuRespDTO> productSpuResult = productSpuRpc.getProductSpu(id);
|
||||
CommonResult<ProductSpuRespDTO> productSpuResult = productSpuFeign.getProductSpu(id);
|
||||
productSpuResult.checkError();
|
||||
if (productSpuResult.getData() == null) {
|
||||
log.error("[saveProduct][商品 SPU({}) 不存在]", id);
|
||||
|
|
|
@ -117,7 +117,10 @@
|
|||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-jdk8</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -2,8 +2,12 @@ package cn.iocoder.mall.shopweb;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc.spu"})
|
||||
public class ShopWebApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
### /product-spu/page 成功(全部)
|
||||
GET {{shop-api-base-url}}/product-spu/page?pageNo=1&pageSize=10&keyword=骚气
|
||||
GET http://127.0.0.1:18084/shop-api/product-spu/page?pageNo=1&pageSize=10&keyword=骚气
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
### /product-spu/search-condition 成功
|
||||
GET {{shop-api-base-url}}/product-spu/search-condition?keyword=骚气
|
||||
GET http://127.0.0.1:18084/shop-api/product-spu/search-condition?keyword=骚气
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
### /product-spu/get-detail 成功
|
||||
GET {{shop-api-base-url}}/product-spu/get-detail?id=63
|
||||
GET http://127.0.0.1:18084/shop-api/product-spu/get-detail?id=63
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
###
|
||||
|
|
|
@ -6,7 +6,7 @@ import cn.iocoder.common.framework.vo.PageResult;
|
|||
import cn.iocoder.mall.productservice.enums.spu.ProductSpuDetailFieldEnum;
|
||||
import cn.iocoder.mall.productservice.rpc.category.ProductCategoryRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuDetailRespDTO;
|
||||
import cn.iocoder.mall.searchservice.enums.product.SearchProductConditionFieldEnum;
|
||||
import cn.iocoder.mall.searchservice.rpc.product.SearchProductRpc;
|
||||
|
@ -19,6 +19,7 @@ import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO;
|
|||
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuSearchConditionRespVO;
|
||||
import cn.iocoder.mall.shopweb.convert.product.ProductSpuConvert;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
|
@ -39,8 +40,8 @@ public class ProductSpuManager {
|
|||
@DubboReference(version = "${dubbo.consumer.ProductCategoryRpc.version}")
|
||||
private ProductCategoryRpc productCategoryRpc;
|
||||
|
||||
@DubboReference(version = "${dubbo.consumer.ProductSpuRpc.version}")
|
||||
private ProductSpuRpc productSpuRpc;
|
||||
@Autowired
|
||||
private ProductSpuFeign productSpuFeign;
|
||||
|
||||
public PageResult<ProductSpuRespVO> pageProductSpu(ProductSpuPageReqVO pageReqVO) {
|
||||
CommonResult<PageResult<SearchProductRespDTO>> pageResult =
|
||||
|
@ -69,7 +70,7 @@ public class ProductSpuManager {
|
|||
}
|
||||
|
||||
public ProductSpuDetailRespVO getProductSpuDetail(Integer id) {
|
||||
CommonResult<ProductSpuDetailRespDTO> getProductSpuDetailResult = productSpuRpc.getProductSpuDetail(id,
|
||||
CommonResult<ProductSpuDetailRespDTO> getProductSpuDetailResult = productSpuFeign.getProductSpuDetail(id,
|
||||
Arrays.asList(ProductSpuDetailFieldEnum.SKU.getField(), ProductSpuDetailFieldEnum.ATTR.getField()));
|
||||
getProductSpuDetailResult.checkError();
|
||||
return ProductSpuConvert.INSTANCE.convert(getProductSpuDetailResult.getData());
|
||||
|
|
|
@ -3,7 +3,7 @@ package cn.iocoder.mall.shopweb.service.promotion;
|
|||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.ProductRecommendRpc;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendListReqDTO;
|
||||
|
@ -13,6 +13,7 @@ import cn.iocoder.mall.shopweb.convert.promotion.ProductRecommendConvert;
|
|||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
|
@ -30,8 +31,8 @@ public class ProductRecommendManager {
|
|||
|
||||
@DubboReference(version = "${dubbo.consumer.ProductRecommendRpc.version}")
|
||||
private ProductRecommendRpc productRecommendRpc;
|
||||
@DubboReference(version = "${dubbo.consumer.ProductSpuRpc.version}")
|
||||
private ProductSpuRpc productSpuRpc;
|
||||
@Autowired
|
||||
private ProductSpuFeign productSpuFeign;
|
||||
|
||||
public Map<Integer, Collection<ProductSpuRespVO>> listProductRecommends() {
|
||||
// 查询商品推荐列表
|
||||
|
@ -49,7 +50,7 @@ public class ProductRecommendManager {
|
|||
}
|
||||
|
||||
private Map<Integer, ProductSpuRespDTO> getProductSkuMap(List<ProductRecommendRespDTO> productRecommends) {
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpusResult = productSpuRpc.listProductSpus(
|
||||
CommonResult<List<ProductSpuRespDTO>> listProductSpusResult = productSpuFeign.listProductSpus(
|
||||
CollectionUtils.convertSet(productRecommends, ProductRecommendRespDTO::getProductSpuId));
|
||||
listProductSpusResult.checkError();
|
||||
return CollectionUtils.convertMap(listProductSpusResult.getData(), ProductSpuRespDTO::getId);
|
||||
|
|
Loading…
Reference in New Issue