From 2113e825d7b085478e8a352e077146f1c4e2581f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 27 Apr 2023 22:43:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20App=20=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=80=BB=E8=BE=91=E7=9A=84=2010%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/spu/AppProductSpuController.http | 2 +- .../app/spu/AppProductSpuController.java | 2 +- .../app/spu/vo/AppProductSpuDetailRespVO.java | 24 +++---- .../spu/vo/AppProductSpuPageItemRespVO.java | 9 +-- .../convert/spu/ProductSpuConvert.java | 64 +++++++++---------- .../service/spu/ProductSpuServiceImpl.java | 7 +- 6 files changed, 50 insertions(+), 58 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.http b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.http index 0de7583ae..c391b5873 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.http +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.http @@ -14,5 +14,5 @@ Authorization: Bearer {{appToken}} tenant-id: {{appTenentId}} ### 获得商品 SPU 明细 -GET {{appApi}}/product/spu/get-detail?id=4 +GET {{appApi}}/product/spu/get-detail?id=102 tenant-id: {{appTenentId}} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java index 783b85780..fe1a8ee87 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java @@ -73,7 +73,7 @@ public class AppProductSpuController { List propertyValues = productPropertyValueService .getPropertyValueDetailList(ProductSkuConvert.INSTANCE.convertPropertyValueIds(skus)); // 拼接 - return success(ProductSpuConvert.INSTANCE.convert(spu, skus, propertyValues)); + return success(ProductSpuConvert.INSTANCE.convertForGetSpuDetail(spu, skus, propertyValues)); } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java index 424843bc7..6992d83b7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java @@ -18,17 +18,17 @@ public class AppProductSpuDetailRespVO { @Schema(description = "商品名称", required = true, example = "芋道") private String name; - @Schema(description = "促销语", example = "好吃!") - private String sellPoint; - @Schema(description = "商品详情", required = true, example = "我是商品描述") private String description; @Schema(description = "商品分类编号", required = true, example = "1") private Long categoryId; - @Schema(description = "商品图片的数组", required = true) - private List picUrls; + @Schema(description = "商品封面图", required = true) + private String picUrl; + + @Schema(description = "商品轮播图", required = true) + private List sliderPicUrls; @Schema(description = "商品视频", required = true) private String videoUrl; @@ -38,14 +38,14 @@ public class AppProductSpuDetailRespVO { @Schema(description = "规格类型", required = true, example = "true") private Boolean specType; - @Schema(description = "是否展示库存", required = true, example = "true") - private Boolean showStock; + @Schema(description = "商品价格,单位使用:分", required = true, example = "1024") + private Integer price; - @Schema(description = " 最小价格,单位使用:分", required = true, example = "1024") - private Integer minPrice; + @Schema(description = "市场价,单位使用:分", required = true, example = "1024") + private Integer marketPrice; - @Schema(description = "最大价格,单位使用:分", required = true, example = "1024") - private Integer maxPrice; + @Schema(description = "库存", required = true, example = "666") + private Integer stock; /** * SKU 数组 @@ -72,7 +72,7 @@ public class AppProductSpuDetailRespVO { @Schema(description = "销售价格,单位:分", required = true, example = "1024") private Integer price; - @Schema(description = "市场价", example = "1024") + @Schema(description = "市场价,单位使用:分", required = true, example = "1024") private Integer marketPrice; @Schema(description = "图片地址", required = true, example = "https://www.iocoder.cn/xx.png") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageItemRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageItemRespVO.java index 27d577976..97513c3bc 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageItemRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageItemRespVO.java @@ -1,11 +1,8 @@ package cn.iocoder.yudao.module.product.controller.app.spu.vo; -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; import java.util.List; @Schema(description = "用户 App - 商品 SPU 分页项 Response VO") @@ -27,17 +24,17 @@ public class AppProductSpuPageItemRespVO { @Schema(description = "商品轮播图", required = true) private List sliderPicUrls; + // ========== SKU 相关字段 ========= + @Schema(description = "商品价格,单位使用:分", required = true, example = "1024") private Integer price; - // ========== SKU 相关字段 ========= - @Schema(description = "库存", required = true, example = "666") private Integer stock; // ========== 统计相关字段 ========= - @Schema(description = "商品销量", example = "1024") + @Schema(description = "商品销量", required = true, example = "1024") private Integer salesCount; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java index cddd742f0..1aa3a4bef 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java @@ -13,7 +13,6 @@ import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; import org.mapstruct.Mapper; -import org.mapstruct.Named; import org.mapstruct.factory.Mappers; import java.util.ArrayList; @@ -33,48 +32,18 @@ public interface ProductSpuConvert { ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class); - ProductSpuDO convert(ProductSpuCreateReqVO bean); + ProductSpuDO convertForGetSpuDetail(ProductSpuCreateReqVO bean); - ProductSpuDO convert(ProductSpuUpdateReqVO bean); + ProductSpuDO convertForGetSpuDetail(ProductSpuUpdateReqVO bean); List convertList(List list); PageResult convertPage(PageResult page); - ProductSpuPageReqVO convert(AppProductSpuPageReqVO bean); - List convertList2(List list); List convertList02(List list); - default AppProductSpuDetailRespVO convert(ProductSpuDO spu, List skus, - List propertyValues) { - AppProductSpuDetailRespVO spuVO = convert02(spu) - .setSalesCount(spu.getSalesCount() + defaultIfNull(spu.getVirtualSalesCount(), 0)); - spuVO.setSkus(convertList03(skus)); - // 处理商品属性 - Map propertyValueMap = convertMap(propertyValues, ProductPropertyValueDetailRespBO::getValueId); - for (int i = 0; i < skus.size(); i++) { - List properties = skus.get(i).getProperties(); - if (CollUtil.isEmpty(properties)) { - continue; - } - AppProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i); - sku.setProperties(new ArrayList<>(properties.size())); - // 遍历每个 properties,设置到 AppSpuDetailRespVO.Sku 中 - properties.forEach(property -> { - ProductPropertyValueDetailRespBO propertyValue = propertyValueMap.get(property.getValueId()); - if (propertyValue == null) { - return; - } - sku.getProperties().add(convert03(propertyValue)); - }); - } - return spuVO; - } - AppProductSpuDetailRespVO convert02(ProductSpuDO spu); - List convertList03(List skus); - AppProductPropertyValueDetailRespVO convert03(ProductPropertyValueDetailRespBO propertyValue); default ProductSpuDetailRespVO convert03(ProductSpuDO spu, List skus, List propertyValues) { @@ -114,4 +83,33 @@ public interface ProductSpuConvert { } PageResult convertPageForGetSpuPage0(PageResult page); + default AppProductSpuDetailRespVO convertForGetSpuDetail(ProductSpuDO spu, List skus, + List propertyValues) { + AppProductSpuDetailRespVO spuVO = convertForGetSpuDetail(spu) + .setSalesCount(spu.getSalesCount() + defaultIfNull(spu.getVirtualSalesCount(), 0)); + spuVO.setSkus(convertListForGetSpuDetail(skus)); + // 处理商品属性 + Map propertyValueMap = convertMap(propertyValues, ProductPropertyValueDetailRespBO::getValueId); + for (int i = 0; i < skus.size(); i++) { + List properties = skus.get(i).getProperties(); + if (CollUtil.isEmpty(properties)) { + continue; + } + AppProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i); + sku.setProperties(new ArrayList<>(properties.size())); + // 遍历每个 properties,设置到 AppSpuDetailRespVO.Sku 中 + properties.forEach(property -> { + ProductPropertyValueDetailRespBO propertyValue = propertyValueMap.get(property.getValueId()); + if (propertyValue == null) { + return; + } + sku.getProperties().add(convertForGetSpuDetail(propertyValue)); + }); + } + return spuVO; + } + AppProductSpuDetailRespVO convertForGetSpuDetail(ProductSpuDO spu); + List convertListForGetSpuDetail(List skus); + AppProductPropertyValueDetailRespVO convertForGetSpuDetail(ProductPropertyValueDetailRespBO propertyValue); + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index 79a6949a5..22b643ef5 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -1,12 +1,9 @@ package cn.iocoder.yudao.module.product.service.spu; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.NumberUtil; -import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO; @@ -66,7 +63,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { productSkuService.validateSkuList(skuSaveReqList, createReqVO.getSpecType()); // 插入 SPU - ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); + ProductSpuDO spu = ProductSpuConvert.INSTANCE.convertForGetSpuDetail(createReqVO); initSpuFromSkus(spu, skuSaveReqList); productSpuMapper.insert(spu); // 插入 SKU @@ -89,7 +86,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType()); // 更新 SPU - ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO); + ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convertForGetSpuDetail(updateReqVO); initSpuFromSkus(updateObj, skuSaveReqList); productSpuMapper.updateById(updateObj); // 批量更新 SKU