From 16fd9dc425a49918e89af580596c19fa1f995416 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 25 Aug 2022 08:16:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=B7=B2=E7=BB=8F=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E7=9A=84=E5=95=86=E5=9F=8E=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/product/ProductSpuManager.java | 22 ----- .../productservice/rpc/spu/ProductSpuFeign.java | 20 ---- .../spu/dto/ProductSpuAndSkuCreateReqDTO.java | 90 ----------------- .../spu/dto/ProductSpuAndSkuUpdateReqDTO.java | 96 ------------------- .../controller/ProductSpuController.http | 13 --- .../controller/ProductSpuController.java | 18 ---- .../manager/spu/ProductSpuManager.java | 63 ------------ .../service/sku/ProductSkuService.java | 38 -------- 8 files changed, 360 deletions(-) delete mode 100644 归档/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuAndSkuCreateReqDTO.java delete mode 100644 归档/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuAndSkuUpdateReqDTO.java delete mode 100644 归档/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/ProductSpuController.http 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 c61d7c87b..b178b3fbd 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 @@ -24,28 +24,6 @@ public class ProductSpuManager { @Autowired private ProductSpuFeign productSpuFeign; - /** - * 创建商品 SPU - * - * @param createVO 创建商品 SPU VO - * @return 商品 SPU - */ - public Integer createProductSpu(ProductSpuCreateReqVO createVO) { - CommonResult createProductSpuResult = productSpuFeign.createProductSpu(ProductSpuConvert.INSTANCE.convert(createVO)); - createProductSpuResult.checkError(); - return createProductSpuResult.getData(); - } - - /** - * 更新商品 SPU - * - * @param updateVO 更新商品 SPU VO - */ - public void updateProductSpu(ProductSpuUpdateReqVO updateVO) { - CommonResult updateProductSpuResult = productSpuFeign.updateProductSpu(ProductSpuConvert.INSTANCE.convert(updateVO)); - updateProductSpuResult.checkError(); - } - /** * 获得商品 SPU * 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 index 413cd2891..1a8cde8ea 100644 --- 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 @@ -23,26 +23,6 @@ public interface ProductSpuFeign { @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列表 * diff --git a/归档/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuAndSkuCreateReqDTO.java b/归档/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuAndSkuCreateReqDTO.java deleted file mode 100644 index 625a449e3..000000000 --- a/归档/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuAndSkuCreateReqDTO.java +++ /dev/null @@ -1,90 +0,0 @@ -package cn.iocoder.mall.productservice.rpc.spu.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.Valid; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.io.Serializable; -import java.util.List; - -/** -* 商品 SPU 和 SKU 创建 Request DTO -*/ -@Data -@Accessors(chain = true) -public class ProductSpuAndSkuCreateReqDTO implements Serializable { - - /** - * SKU 信息 - */ - @Data - @Accessors(chain = true) - public static class Sku implements Serializable { - - /** - * 规格值数组 - */ - @NotNull(message = "规格值数组不能为空") - private List attrValueIds; - /** - * 价格,单位:分 - */ - @NotNull(message = "价格不能为空") - @Min(value = 1L, message = "最小价格为 1") - private Integer price; - /** - * 库存数量 - */ - @NotNull(message = "库存数量不能为空") - @Min(value = 1L, message = "最小库存为 1") - private Integer quantity; - - } - - // ========== 基本信息 ========= - /** - * SPU 名字 - */ - @NotEmpty(message = "SPU 名字不能为空") - private String name; - /** - * 卖点 - */ - @NotEmpty(message = "卖点不能为空") - private String sellPoint; - /** - * 描述 - */ - @NotEmpty(message = "描述不能为空") - private String description; - /** - * 分类编号 - */ - @NotNull(message = "分类编号不能为空") - private Integer cid; - /** - * 商品主图地址 - */ - @NotEmpty(message = "商品主图地址不能为空") - private List picUrls; - - // ========== 其他信息 ========= - /** - * 是否上架商品 - */ - @NotNull(message = "是否上架商品不能为空") - private Boolean visible; - - // ========== SKU ========= - - /** - * SKU 数组 - */ - @NotNull(message = "SKU 不能为空") - @Valid - private List skus; - -} diff --git a/归档/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuAndSkuUpdateReqDTO.java b/归档/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuAndSkuUpdateReqDTO.java deleted file mode 100644 index 32b547b1a..000000000 --- a/归档/product-service-project/product-service-api/src/main/java/cn/iocoder/mall/productservice/rpc/spu/dto/ProductSpuAndSkuUpdateReqDTO.java +++ /dev/null @@ -1,96 +0,0 @@ -package cn.iocoder.mall.productservice.rpc.spu.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.Valid; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.io.Serializable; -import java.util.List; - -/** -* 商品 SPU 和 SKU 更新 Request DTO -*/ -@Data -@Accessors(chain = true) -public class ProductSpuAndSkuUpdateReqDTO implements Serializable { - - /** - * SKU 信息 - */ - @Data - @Accessors(chain = true) - public static class Sku implements Serializable { - - /** - * 规格值数组 - */ - @NotNull(message = "规格值数组不能为空") - private List attrValueIds; - /** - * 价格,单位:分 - */ - @NotNull(message = "价格不能为空") - @Min(value = 1L, message = "最小价格为 1") - private Integer price; - /** - * 库存数量 - */ - @NotNull(message = "库存数量不能为空") - @Min(value = 1L, message = "最小库存为 1") - private Integer quantity; - - } - - /** - * Spu 编号 - */ - @NotNull(message = "SPU 编号不能为空") - private Integer id; - - // ========== 基本信息 ========= - /** - * SPU 名字 - */ - @NotEmpty(message = "SPU 名字不能为空") - private String name; - /** - * 卖点 - */ - @NotEmpty(message = "卖点不能为空") - private String sellPoint; - /** - * 描述 - */ - @NotEmpty(message = "描述不能为空") - private String description; - /** - * 分类编号 - */ - @NotNull(message = "分类编号不能为空") - private Integer cid; - /** - * 商品主图地址 - */ - @NotEmpty(message = "商品主图地址不能为空") - private List picUrls; - - // ========== 其他信息 ========= - /** - * 是否上架商品 - */ - @NotNull(message = "是否上架商品不能为空") - private Boolean visible; - - // ========== SKU ========= - - /** - * SKU 数组 - */ - @NotNull(message = "SKU 不能为空") - @Valid - private List skus; - -} 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 deleted file mode 100644 index 97e2ed394..000000000 --- a/归档/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/controller/ProductSpuController.http +++ /dev/null @@ -1,13 +0,0 @@ -### /product/spu/get 获得商品 SPU -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 index eb58b972f..89e1f5979 100644 --- 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 @@ -31,24 +31,6 @@ public class ProductSpuController { 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) diff --git a/归档/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/spu/ProductSpuManager.java b/归档/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/spu/ProductSpuManager.java index 2007f3658..80392c15b 100644 --- a/归档/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/spu/ProductSpuManager.java +++ b/归档/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/manager/spu/ProductSpuManager.java @@ -51,69 +51,6 @@ public class ProductSpuManager { @Autowired private ProductMQProducer productMQProducer; - private static ProductSpuManager self() { - return (ProductSpuManager) AopContext.currentProxy(); - } - - /** - * 创建商品 SPU 和 SKU - * - * @param createDTO 创建商品 SPU 和 SKU DTO - * @return 商品 SPU - */ - public Integer createProductSpu(ProductSpuAndSkuCreateReqDTO createDTO) { - // 创建商品 SPU 和 SKU。注意,这里要调用 self() 方法,因为需要创建事务,否则会失效 - Integer spuId = self().createProductSpu0(createDTO); - // 发送商品创建的 MQ 消息 - productMQProducer.sendProductUpdateMessage(spuId); - return spuId; - } - - @Transactional - public Integer createProductSpu0(ProductSpuAndSkuCreateReqDTO createDTO) { - // 校验商品分类是否合法 - this.checkProductCategory(createDTO.getCid()); - // 创建商品 SKU 对象,并进行校验 - List skuBOs = ProductSpuConvert.INSTANCE.convert(createDTO.getSkus()); - this.checkProductAttr(skuBOs); - // 插入商品 SPU 记录 - ProductSpuCreateBO spuCreateBO = ProductSpuConvert.INSTANCE.convert(createDTO).setSort(0); - spuCreateBO.setPrice(skuBOs.stream().min(Comparator.comparing(ProductSkuCreateOrUpdateBO::getPrice)).get().getPrice()); // 求最小价格 - spuCreateBO.setQuantity(skuBOs.stream().mapToInt(ProductSkuCreateOrUpdateBO::getQuantity).sum()); // 求库存之和 - ProductSpuBO spuBO = productSpuService.createProductSpu(spuCreateBO); - // 插入商品 SKU 记录 - productSkuService.createProductSkus(spuBO.getId(), skuBOs); - return spuBO.getId(); - } - - /** - * 更新商品 SPU - * - * @param updateDTO 更新商品 SPU DTO - */ - public void updateProductSpu(ProductSpuAndSkuUpdateReqDTO updateDTO) { - // 更新商品 SPU 和 SKU。注意,这里要调用 self() 方法,因为需要创建事务,否则会失效 - self().updateProductSpu0(updateDTO); - // 发送商品创建的 MQ 消息 - productMQProducer.sendProductUpdateMessage(updateDTO.getId()); - } - - @Transactional - public void updateProductSpu0(ProductSpuAndSkuUpdateReqDTO updateDTO) { - // 校验商品分类是否合法 - this.checkProductCategory(updateDTO.getCid()); - // 创建商品 SKU 对象,并进行校验 - List skuBOs = ProductSpuConvert.INSTANCE.convert02(updateDTO.getSkus()); - this.checkProductAttr(skuBOs); - // 更新商品 SPU 记录 - ProductSpuUpdateBO spuUpdateBO = ProductSpuConvert.INSTANCE.convert(updateDTO); - spuUpdateBO.setPrice(skuBOs.stream().min(Comparator.comparing(ProductSkuCreateOrUpdateBO::getPrice)).get().getPrice()); // 求最小价格 - spuUpdateBO.setQuantity(skuBOs.stream().mapToInt(ProductSkuCreateOrUpdateBO::getQuantity).sum()); // 求库存之和 - productSpuService.updateProductSpu(spuUpdateBO); - // 更新商品 SKU 记录 - productSkuService.updateProductSkus(updateDTO.getId(), skuBOs); - } - /** * 获得商品 SPU * diff --git a/归档/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/sku/ProductSkuService.java b/归档/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/sku/ProductSkuService.java index a78a35b18..b134dea93 100644 --- a/归档/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/sku/ProductSkuService.java +++ b/归档/product-service-project/product-service-app/src/main/java/cn/iocoder/mall/productservice/service/sku/ProductSkuService.java @@ -31,44 +31,6 @@ public class ProductSkuService { productSkuMapper.insertList(skus); } - @Transactional - public void updateProductSkus(Integer spuId, List skuUpdateBOs) { - List existsSkus = productSkuMapper.selectListBySpuIdAndStatus(spuId, - CommonStatusEnum.ENABLE.getValue()); - List insertSkus = new ArrayList<>(); // 1、找不到,进行插入 - List deleteSkus = new ArrayList<>(); // 2、多余的,删除 - List updateSkus = new ArrayList<>(); // 3、找的到,进行更新。 - for (ProductSkuCreateOrUpdateBO skuUpdateDTO : skuUpdateBOs) { - ProductSkuDO existsSku = findProductSku(skuUpdateDTO.getAttrValueIds(), existsSkus); - // 3、找的到,进行更新。 - if (existsSku != null) { - // 移除 - existsSkus.remove(existsSku); - // 创建 ProductSkuDO - updateSkus.add(ProductSkuConvert.INSTANCE.convert(skuUpdateDTO).setId(existsSku.getId())); - continue; - } - // 1、找不到,进行插入 - ProductSkuDO insertSku = ProductSkuConvert.INSTANCE.convert(skuUpdateDTO) - .setSpuId(spuId).setStatus(CommonStatusEnum.ENABLE.getValue()); - insertSkus.add(insertSku); - } - // 2、多余的,删除 - if (!existsSkus.isEmpty()) { - deleteSkus.addAll(existsSkus.stream().map(ProductSkuDO::getId).collect(Collectors.toList())); - } - // 执行修改 Sku - if (!insertSkus.isEmpty()) { - productSkuMapper.insertList(insertSkus); - } - if (!updateSkus.isEmpty()) { - updateSkus.forEach(productSkuDO -> productSkuMapper.updateById(productSkuDO)); - } - if (!deleteSkus.isEmpty()) { - productSkuMapper.deleteBatchIds(deleteSkus); - } - } - /** * 获得 sku 数组中,指定规格的 sku *