From 2382ddfb372c2ac94d086396c3d294c4c527ce37 Mon Sep 17 00:00:00 2001 From: franky-mgmg-pc Date: Tue, 7 Jun 2022 18:04:21 +0800 Subject: [PATCH] =?UTF-8?q?spu=20sku=20review=E8=B0=83=E6=95=B4=E4=B8=80?= =?UTF-8?q?=E6=B3=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/sku/ProductSkuController.java | 3 +-- .../controller/admin/spu/vo/ProductSpuCreateReqVO.java | 3 +-- .../propertyvalue/ProductPropertyValueConvert.java | 2 +- .../ProductPropertyValueDO.java | 5 ++--- .../product/dal/dataobject/sku/ProductSkuDO.java | 1 - .../propertyvalue/ProductPropertyValueMapper.java | 2 +- .../service/property/ProductPropertyServiceImpl.java | 2 +- .../module/product/service/sku/ProductSkuService.java | 10 ++++------ .../product/service/sku/ProductSkuServiceImpl.java | 8 ++++---- .../product/service/spu/ProductSpuServiceImpl.java | 6 +++--- 10 files changed, 18 insertions(+), 24 deletions(-) rename yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/{propertyvalue => property}/ProductPropertyValueDO.java (84%) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java index 23593388d..a8974243e 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java @@ -25,8 +25,7 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; -// TODO @franky:中英文之间要有空格哈。商品 sku -@Api(tags = "管理后台 - 商品sku") +@Api(tags = "管理后台-商品 sku") @RestController @RequestMapping("/product/sku") @Validated diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuCreateReqVO.java index c4dd972cf..6281e20d5 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuCreateReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuCreateReqVO.java @@ -16,9 +16,8 @@ import java.util.List; @ToString(callSuper = true) public class ProductSpuCreateReqVO extends ProductSpuBaseVO { - // TODO @franky:这种可以缩写下,skus @ApiModelProperty(value = "sku组合") @Valid - List productSkuCreateReqVOS; + List skus; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java index 730ce1cf4..447b9a5ea 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java @@ -4,7 +4,7 @@ import java.util.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO; +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/propertyvalue/ProductPropertyValueDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyValueDO.java similarity index 84% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/propertyvalue/ProductPropertyValueDO.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyValueDO.java index 80e68ac4c..0203939cc 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/propertyvalue/ProductPropertyValueDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyValueDO.java @@ -1,13 +1,12 @@ -package cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue; +package cn.iocoder.yudao.module.product.dal.dataobject.property; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; -// TODO @franky:包放到 property 中 + /** * 规格值 DO * diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java index e9f4d20dc..34a115565 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java @@ -35,7 +35,6 @@ public class ProductSkuDO extends BaseDO { /** * 规格值数组-json格式, [{propertId: , valueId: }, {propertId: , valueId: }] */ - // TODO franky:可以定义一个内部的 Property 类,然后 List private String properties; /** * 销售价格,单位:分 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/propertyvalue/ProductPropertyValueMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/propertyvalue/ProductPropertyValueMapper.java index 760d22481..768875c3e 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/propertyvalue/ProductPropertyValueMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/propertyvalue/ProductPropertyValueMapper.java @@ -4,7 +4,7 @@ import java.util.*; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO; +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import org.apache.ibatis.annotations.Mapper; /** diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java index 55a725d44..9cb1a0da3 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.Product import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert; import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; -import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO; +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper; import cn.iocoder.yudao.module.product.dal.mysql.propertyvalue.ProductPropertyValueMapper; import org.springframework.stereotype.Service; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java index 3888d0ef8..d93da5986 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java @@ -72,20 +72,18 @@ public interface ProductSkuService { */ List getSkuList(ProductSkuExportReqVO exportReqVO); - // TODO @franky:validateSkus;skuCreateReqList => list /** * 对 sku 的组合的属性等进行合法性校验 * - * @param skuCreateReqList sku组合的集合 + * @param list sku组合的集合 */ - void validatedSkuReq(List skuCreateReqList); + void validateSkus(List list); /** * 批量保存sku - * @param skuDOList sku对象集合 - * @return // TODO @franky:这里的 return 可以去掉;方法名可以改成 createSkus(list) + * @param list sku对象集合 */ - void batchSave(List skuDOList); + void createSkus(List list); /** * 获得商品sku 集合 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index d892b19da..92e84f211 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java @@ -90,8 +90,8 @@ public class ProductSkuServiceImpl implements ProductSkuService { // TODO @franky:这个方法,貌似实现的还是有点问题哈。例如说,throw 异常,后面还执行逻辑~ @Override - public void validatedSkuReq(List skuCreateReqList) { - List skuPropertyList = skuCreateReqList.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); + public void validateSkus(List list) { + List skuPropertyList = list.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); // 校验规格属性以及规格值是否存在 List propertyIds = skuPropertyList.stream().map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList()); List propertyAndValueList = productPropertyService.selectByIds(propertyIds); @@ -109,7 +109,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { } }); // 校验是否有重复的sku组合 - List> skuProperties = skuCreateReqList.stream().map(ProductSkuBaseVO::getProperties).collect(Collectors.toList()); + List> skuProperties = list.stream().map(ProductSkuBaseVO::getProperties).collect(Collectors.toList()); Set skuPropertiesConvertSet = new HashSet<>(); skuProperties.forEach(p -> { // 组合属性值id为 1~2~3.... 形式的字符串,通过set的特性判断是否有重复的组合 @@ -120,7 +120,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { } @Override - public void batchSave(List skuDOList) { + public void createSkus(List skuDOList) { productSkuMapper.insertBatch(skuDOList); } 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 caa79fe5a..820fc901f 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 @@ -50,8 +50,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { // 校验分类 categoryService.validatedCategoryById(createReqVO.getCategoryId()); // 校验SKU - List skuCreateReqList = createReqVO.getProductSkuCreateReqVOS(); - productSkuService.validatedSkuReq(skuCreateReqList); + List skuCreateReqList = createReqVO.getSkus(); + productSkuService.validateSkus(skuCreateReqList); // 插入SPU ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); ProductSpuMapper.insert(spu); @@ -61,7 +61,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { }); List skuDOList = ProductSkuConvert.INSTANCE.convertSkuDOList(skuCreateReqList); // 批量插入sku - productSkuService.batchSave(skuDOList); + productSkuService.createSkus(skuDOList); // 返回 return spu.getId(); }