From 4f50845b66d00eaf304e683da66f7afcd65233ed Mon Sep 17 00:00:00 2001 From: zhuyang <1qazxsw2> Date: Thu, 7 Oct 2021 16:50:40 +0800 Subject: [PATCH] =?UTF-8?q?1.=20ProductSPU=20=E8=BF=81=E7=A7=BBspringcloud?= =?UTF-8?q?.=202.=20=E8=B0=83=E7=94=A8=E6=96=B9manager=E9=80=9A=E8=BF=87fe?= =?UTF-8?q?ign=E8=B0=83=E7=94=A8spu=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ManagementWebApplication.java | 2 +- .../product/ProductSpuController.http | 22 +++-- .../managementweb/feign/ProductSpuFeign.java | 20 ---- .../manager/product/ProductSpuManager.java | 14 +-- .../recommend/ProductRecommendManager.java | 10 +- .../rpc/spu/ProductSpuFeign.java | 77 ++++++++++++++++ .../productservice/rpc/spu/ProductSpuRpc.java | 65 ------------- .../controller/ProductSpuController.http | 9 ++ .../controller/ProductSpuController.java | 91 +++++++++++++++++++ .../controller/SpuController.java | 31 ------- .../rpc/spu/ProductSpuRpcImpl.java | 60 ------------ .../promotion-service-app/pom.xml | 4 + .../PromotionServiceApplication.java | 4 + .../manager/price/PriceManager.java | 12 ++- .../recommend/ProductRecommendManager.java | 9 +- .../search-service-app/pom.xml | 4 + .../SearchServiceApplication.java | 4 + .../manager/product/SearchProductManager.java | 11 ++- shop-web-app/pom.xml | 5 +- .../mall/shopweb/ShopWebApplication.java | 4 + .../product/ProductSpuController.http | 6 +- .../service/product/ProductSpuManager.java | 9 +- .../promotion/ProductRecommendManager.java | 9 +- 23 files changed, 256 insertions(+), 226 deletions(-) delete mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/feign/ProductSpuFeign.java create mode 100644 product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuFeign.java delete mode 100644 product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpc.java create mode 100644 product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/ProductSpuController.java delete mode 100644 product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/SpuController.java delete mode 100644 product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/ManagementWebApplication.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/ManagementWebApplication.java index 6812bb727..0c15ca0e9 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/ManagementWebApplication.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/ManagementWebApplication.java @@ -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) { diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductSpuController.http b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductSpuController.http index 6ffb59c67..301e8f1aa 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductSpuController.http +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/product/ProductSpuController.http @@ -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 + +### diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/feign/ProductSpuFeign.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/feign/ProductSpuFeign.java deleted file mode 100644 index 2597badf5..000000000 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/feign/ProductSpuFeign.java +++ /dev/null @@ -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 getProductSpu(@RequestParam("productSpuId") Integer productSpuId); - -} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/product/ProductSpuManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/product/ProductSpuManager.java index ef2c4d734..c61d7c87b 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/product/ProductSpuManager.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/product/ProductSpuManager.java @@ -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 createProductSpuResult = productSpuRpc.createProductSpu(ProductSpuConvert.INSTANCE.convert(createVO)); + CommonResult 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 updateProductSpuResult = productSpuRpc.updateProductSpu(ProductSpuConvert.INSTANCE.convert(updateVO)); + CommonResult updateProductSpuResult = productSpuFeign.updateProductSpu(ProductSpuConvert.INSTANCE.convert(updateVO)); updateProductSpuResult.checkError(); } @@ -69,7 +65,7 @@ public class ProductSpuManager { * @return 商品 SPU列表 */ public List listProductSpus(List productSpuIds) { - CommonResult> listProductSpuResult = productSpuRpc.listProductSpus(productSpuIds); + CommonResult> listProductSpuResult = productSpuFeign.listProductSpus(productSpuIds); listProductSpuResult.checkError(); return ProductSpuConvert.INSTANCE.convertList(listProductSpuResult.getData()); } @@ -81,7 +77,7 @@ public class ProductSpuManager { * @return 商品 SPU分页结果 */ public PageResult pageProductSpu(ProductSpuPageReqVO pageVO) { - CommonResult> pageProductSpuResult = productSpuRpc.pageProductSpu(ProductSpuConvert.INSTANCE.convert(pageVO)); + CommonResult> pageProductSpuResult = productSpuFeign.pageProductSpu(ProductSpuConvert.INSTANCE.convert(pageVO)); pageProductSpuResult.checkError(); return ProductSpuConvert.INSTANCE.convertPage(pageProductSpuResult.getData()); } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/recommend/ProductRecommendManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/recommend/ProductRecommendManager.java index 0a3c686b6..6bd4b7a99 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/recommend/ProductRecommendManager.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/recommend/ProductRecommendManager.java @@ -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 pageResult = ProductRecommendConvert.INSTANCE.convertPage(pageProductRecommendResult.getData()); if (!CollectionUtils.isEmpty(pageResult.getList())) { // 获取商品信息,并进行拼接 - CommonResult> listProductSpusResult = productSpuRpc.listProductSpus( + CommonResult> listProductSpusResult = productSpuFeign.listProductSpus( CollectionUtils.convertSet(pageResult.getList(), ProductRecommendDetailVO::getProductSpuId)); listProductSpusResult.checkError(); Map productSpuMap = CollectionUtils.convertMap(listProductSpusResult.getData(), ProductSpuRespDTO::getId); diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuFeign.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuFeign.java new file mode 100644 index 000000000..413cd2891 --- /dev/null +++ b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuFeign.java @@ -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 getProductSpu(@RequestParam("productSpuId") Integer productSpuId); + + + + /** + * 创建商品 SPU + * + * @param createDTO 创建商品 SPU DTO + * @return 商品 SPU编号 + */ + @PostMapping(value = "/product/spu/create") + CommonResult createProductSpu(@RequestBody ProductSpuAndSkuCreateReqDTO createDTO); + + /** + * 更新商品 SPU + * + * @param updateDTO 更新商品 SPU DTO + */ + @PostMapping(value = "/product/spu/update") + CommonResult updateProductSpu(@RequestBody ProductSpuAndSkuUpdateReqDTO updateDTO); + + + /** + * 获得商品 SPU列表 + * + * @param productSpuIds 商品 SPU 编号列表 + * @return 商品 SPU 列表 + */ + @GetMapping(value = "/product/spu/list") + CommonResult> listProductSpus(@RequestParam("productSpuIds") Collection productSpuIds); + + /** + * 获得商品 SPU 分页 + * + * @param pageDTO 商品 SPU 分页查询 + * @return 商品 SPU 分页结果 + */ + @PostMapping(value = "/product/spu/page") + CommonResult> pageProductSpu(@RequestBody ProductSpuPageReqDTO pageDTO); + + /** + * 顺序获得商品 SPU 编号数组 + * + * @param lastSpuId 最后一个商品 SPU 编号 + * @param limit 数量 + * @return 商品 SPU 编号数组 + */ + @GetMapping(value = "/product/spu/lislistProductSpuIdst") + CommonResult> listProductSpuIds(@RequestParam("lastSpuId")Integer lastSpuId, @RequestParam("limit")Integer limit); + + @GetMapping(value = "/product/spu/getProductSpuDetail") + CommonResult getProductSpuDetail(@RequestParam("productSpuId") Integer productSpuId,@RequestParam("fields") Collection fields); + +} diff --git a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpc.java b/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpc.java deleted file mode 100644 index 792e16a89..000000000 --- a/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpc.java +++ /dev/null @@ -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 createProductSpu(ProductSpuAndSkuCreateReqDTO createDTO); - - /** - * 更新商品 SPU - * - * @param updateDTO 更新商品 SPU DTO - */ - CommonResult updateProductSpu(ProductSpuAndSkuUpdateReqDTO updateDTO); - - /** - * 获得商品 SPU - * - * @param productSpuId 商品 SPU 编号 - * @return 商品 SPU - */ - CommonResult getProductSpu(Integer productSpuId); - - /** - * 获得商品 SPU列表 - * - * @param productSpuIds 商品 SPU 编号列表 - * @return 商品 SPU 列表 - */ - CommonResult> listProductSpus(Collection productSpuIds); - - /** - * 获得商品 SPU 分页 - * - * @param pageDTO 商品 SPU 分页查询 - * @return 商品 SPU 分页结果 - */ - CommonResult> pageProductSpu(ProductSpuPageReqDTO pageDTO); - - /** - * 顺序获得商品 SPU 编号数组 - * - * @param lastSpuId 最后一个商品 SPU 编号 - * @param limit 数量 - * @return 商品 SPU 编号数组 - */ - CommonResult> listProductSpuIds(Integer lastSpuId, Integer limit); - - CommonResult getProductSpuDetail(Integer productSpuId, Collection fields); - -} diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/ProductSpuController.http b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/ProductSpuController.http index 48ef87dd1..97e2ed394 100644 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/ProductSpuController.http +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/ProductSpuController.http @@ -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 +### + diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/ProductSpuController.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/ProductSpuController.java new file mode 100644 index 000000000..eb58b972f --- /dev/null +++ b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/ProductSpuController.java @@ -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 getProductSpu(@RequestParam(value="productSpuId") Integer productSpuId) { + return success(productSpuManager.getProductSpu(productSpuId)); + } + + /** + * 更新商品 SPU + * + * @param updateDTO 更新商品 SPU DTO + */ + @PostMapping("/update") + @ApiOperation("更新商品 SPU") + public CommonResult updateProductSpu(@Valid @RequestBody ProductSpuAndSkuUpdateReqDTO updateDTO) { + productSpuManager.updateProductSpu(updateDTO); + return success(true); + } + + @PostMapping("/create") + @ApiOperation("创建商品 SPU") + public CommonResult createProductSpu(@Valid @RequestBody ProductSpuAndSkuCreateReqDTO createDTO) { + return success(productSpuManager.createProductSpu(createDTO)); + } + + @GetMapping("/list") + @ApiOperation("获得商品 SPU 列表") + @ApiImplicitParam(name = "productSpuIds", value = "商品 SPU 编号列表", required = true) + public CommonResult> listProductSpus(@RequestParam("productSpuIds") List productSpuIds) { + return success(productSpuManager.listProductSpus(productSpuIds)); + } + + @PostMapping("/page") + @ApiOperation("获得商品 SPU 分页") + public CommonResult> 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> 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 getProductSpuDetail(@RequestParam("productSpuId") Integer productSpuId,@RequestParam("fields") Collection fields) { + return success(productSpuManager.getProductSpuDetail(productSpuId,fields)); + } +} diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/SpuController.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/SpuController.java deleted file mode 100644 index 6f7fd7903..000000000 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/SpuController.java +++ /dev/null @@ -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 getProductSpu(@RequestParam(value="productSpuId") Integer productSpuId) { - return success(productSpuManager.getProductSpu(productSpuId)); - } - -} diff --git a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java b/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java deleted file mode 100644 index a00d969ae..000000000 --- a/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/rpc/spu/ProductSpuRpcImpl.java +++ /dev/null @@ -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 createProductSpu(ProductSpuAndSkuCreateReqDTO createDTO) { - return success(productSpuManager.createProductSpu(createDTO)); - } - - @Override - public CommonResult updateProductSpu(ProductSpuAndSkuUpdateReqDTO updateDTO) { - productSpuManager.updateProductSpu(updateDTO); - return success(true); - } - - @Override - public CommonResult getProductSpu(Integer productSpuId) { - return success(productSpuManager.getProductSpu(productSpuId)); - } - - @Override - public CommonResult> listProductSpus(Collection productSpuIds) { - return success(productSpuManager.listProductSpus(productSpuIds)); - } - - @Override - public CommonResult> pageProductSpu(ProductSpuPageReqDTO pageDTO) { - return success(productSpuManager.pageProductSpu(pageDTO)); - } - - @Override - public CommonResult> listProductSpuIds(Integer lastSpuId, Integer limit) { - return success(productSpuManager.listProductSpuIds(lastSpuId, limit)); - } - - @Override - public CommonResult getProductSpuDetail(Integer productSpuId, Collection fields) { - return success(productSpuManager.getProductSpuDetail(productSpuId, fields)); - } - -} diff --git a/promotion-service-project/promotion-service-app/pom.xml b/promotion-service-project/promotion-service-app/pom.xml index 6e7818b88..2542b5202 100644 --- a/promotion-service-project/promotion-service-app/pom.xml +++ b/promotion-service-project/promotion-service-app/pom.xml @@ -104,6 +104,10 @@ aspectjweaver 1.9.6 + + org.springframework.cloud + spring-cloud-starter-openfeign + diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/PromotionServiceApplication.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/PromotionServiceApplication.java index fc6422543..06143b6c9 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/PromotionServiceApplication.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/PromotionServiceApplication.java @@ -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) { diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/price/PriceManager.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/price/PriceManager.java index c63aab764..142851957 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/price/PriceManager.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/price/PriceManager.java @@ -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 initCalcOrderPriceItems(List skus, Map calcProductItemDTOMap) { // 获得商品分类 Map - CommonResult> listProductSpusResult = productSpuRpc.listProductSpus(CollectionUtils.convertSet(skus, ProductSkuRespDTO::getSpuId)); + CommonResult> listProductSpusResult = productSpuFeign.listProductSpus(CollectionUtils.convertSet(skus, ProductSkuRespDTO::getSpuId)); listProductSpusResult.checkError(); Map spuIdCategoryIdMap = CollectionUtils.convertMap(listProductSpusResult.getData(), // SPU 编号与 Category 编号的映射 ProductSpuRespDTO::getId, ProductSpuRespDTO::getCid); diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/recommend/ProductRecommendManager.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/recommend/ProductRecommendManager.java index 9ca04e34b..4467dcc4a 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/recommend/ProductRecommendManager.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/recommend/ProductRecommendManager.java @@ -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 getProductSpuResult = productSpuRpc.getProductSpu(productSpuId); + CommonResult getProductSpuResult = productSpuFeign.getProductSpu(productSpuId); getProductSpuResult.checkError(); if (getProductSpuResult.getData() == null) { throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS); diff --git a/search-service-project/search-service-app/pom.xml b/search-service-project/search-service-app/pom.xml index c813f761d..45b0bbb42 100644 --- a/search-service-project/search-service-app/pom.xml +++ b/search-service-project/search-service-app/pom.xml @@ -101,6 +101,10 @@ aspectjweaver 1.9.6 + + org.springframework.cloud + spring-cloud-starter-openfeign + diff --git a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/SearchServiceApplication.java b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/SearchServiceApplication.java index 96016368b..a0a162ac1 100644 --- a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/SearchServiceApplication.java +++ b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/SearchServiceApplication.java @@ -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) { diff --git a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManager.java b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManager.java index 19546f116..92d8e7935 100644 --- a/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManager.java +++ b/search-service-project/search-service-app/src/main/java/cn/iocoder/mall/searchservice/manager/product/SearchProductManager.java @@ -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> listProductSpuIdsResult = productSpuRpc.listProductSpuIds(lastId, REBUILD_FETCH_PER_SIZE); + CommonResult> listProductSpuIdsResult = productSpuFeign.listProductSpuIds(lastId, REBUILD_FETCH_PER_SIZE); listProductSpuIdsResult.checkError(); List spuIds = listProductSpuIdsResult.getData(); // 逐个重建索引到 ES 中 @@ -93,7 +94,7 @@ public class SearchProductManager { */ public Boolean saveProduct(Integer id) { // 获得商品 SPU - CommonResult productSpuResult = productSpuRpc.getProductSpu(id); + CommonResult productSpuResult = productSpuFeign.getProductSpu(id); productSpuResult.checkError(); if (productSpuResult.getData() == null) { log.error("[saveProduct][商品 SPU({}) 不存在]", id); diff --git a/shop-web-app/pom.xml b/shop-web-app/pom.xml index b634fbf48..d649bfd9e 100644 --- a/shop-web-app/pom.xml +++ b/shop-web-app/pom.xml @@ -117,7 +117,10 @@ org.mapstruct mapstruct-jdk8 - + + org.springframework.cloud + spring-cloud-starter-openfeign + diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java index 8b0f5a02a..ca0a38146 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/ShopWebApplication.java @@ -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) { diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSpuController.http b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSpuController.http index 5ab67814f..c18e02753 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSpuController.http +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSpuController.http @@ -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 ### diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/product/ProductSpuManager.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/product/ProductSpuManager.java index 02d0523da..13f16cb4b 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/product/ProductSpuManager.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/product/ProductSpuManager.java @@ -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 pageProductSpu(ProductSpuPageReqVO pageReqVO) { CommonResult> pageResult = @@ -69,7 +70,7 @@ public class ProductSpuManager { } public ProductSpuDetailRespVO getProductSpuDetail(Integer id) { - CommonResult getProductSpuDetailResult = productSpuRpc.getProductSpuDetail(id, + CommonResult getProductSpuDetailResult = productSpuFeign.getProductSpuDetail(id, Arrays.asList(ProductSpuDetailFieldEnum.SKU.getField(), ProductSpuDetailFieldEnum.ATTR.getField())); getProductSpuDetailResult.checkError(); return ProductSpuConvert.INSTANCE.convert(getProductSpuDetailResult.getData()); diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/promotion/ProductRecommendManager.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/promotion/ProductRecommendManager.java index 091693fd8..43d62a8d4 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/promotion/ProductRecommendManager.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/service/promotion/ProductRecommendManager.java @@ -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> listProductRecommends() { // 查询商品推荐列表 @@ -49,7 +50,7 @@ public class ProductRecommendManager { } private Map getProductSkuMap(List productRecommends) { - CommonResult> listProductSpusResult = productSpuRpc.listProductSpus( + CommonResult> listProductSpusResult = productSpuFeign.listProductSpus( CollectionUtils.convertSet(productRecommends, ProductRecommendRespDTO::getProductSpuId)); listProductSpusResult.checkError(); return CollectionUtils.convertMap(listProductSpusResult.getData(), ProductSpuRespDTO::getId);