Commit 766afbacbf1cf824138b7e2167ed9f92be73dc64
1 parent
f07bf8b0
code review:商品 spu、sku 的逻辑
Showing
9 changed files
with
74 additions
and
57 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.sku; | 1 | package cn.iocoder.yudao.module.product.controller.admin.sku; |
| 2 | 2 | ||
| 3 | -import org.springframework.web.bind.annotation.*; | ||
| 4 | -import javax.annotation.Resource; | ||
| 5 | -import org.springframework.validation.annotation.Validated; | ||
| 6 | -import org.springframework.security.access.prepost.PreAuthorize; | ||
| 7 | -import io.swagger.annotations.*; | ||
| 8 | - | ||
| 9 | -import javax.validation.constraints.*; | ||
| 10 | -import javax.validation.*; | ||
| 11 | -import javax.servlet.http.*; | ||
| 12 | -import java.util.*; | ||
| 13 | -import java.io.IOException; | ||
| 14 | - | ||
| 15 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 16 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 17 | -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 18 | - | 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 19 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 20 | - | ||
| 21 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 6 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 22 | -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | ||
| 23 | - | ||
| 24 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; | 7 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; |
| 25 | -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | ||
| 26 | import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | 8 | import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; |
| 9 | +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | ||
| 27 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; | 10 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 11 | +import io.swagger.annotations.Api; | ||
| 12 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 13 | +import io.swagger.annotations.ApiOperation; | ||
| 14 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 15 | +import org.springframework.validation.annotation.Validated; | ||
| 16 | +import org.springframework.web.bind.annotation.*; | ||
| 17 | + | ||
| 18 | +import javax.annotation.Resource; | ||
| 19 | +import javax.servlet.http.HttpServletResponse; | ||
| 20 | +import javax.validation.Valid; | ||
| 21 | +import java.io.IOException; | ||
| 22 | +import java.util.Collection; | ||
| 23 | +import java.util.List; | ||
| 24 | + | ||
| 25 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | ||
| 28 | 27 | ||
| 28 | +// TODO @franky:中英文之间要有空格哈。商品 sku | ||
| 29 | @Api(tags = "管理后台 - 商品sku") | 29 | @Api(tags = "管理后台 - 商品sku") |
| 30 | @RestController | 30 | @RestController |
| 31 | @RequestMapping("/product/sku") | 31 | @RequestMapping("/product/sku") |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.sku.vo; | 1 | package cn.iocoder.yudao.module.product.controller.admin.sku.vo; |
| 2 | 2 | ||
| 3 | -import lombok.*; | ||
| 4 | -import java.util.*; | ||
| 5 | -import io.swagger.annotations.*; | ||
| 6 | -import javax.validation.constraints.*; | 3 | +import io.swagger.annotations.ApiModelProperty; |
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +import javax.validation.constraints.NotNull; | ||
| 7 | +import java.util.List; | ||
| 7 | 8 | ||
| 8 | /** | 9 | /** |
| 9 | * 商品sku Base VO,提供给添加、修改、详细的子 VO 使用 | 10 | * 商品sku Base VO,提供给添加、修改、详细的子 VO 使用 |
| @@ -12,10 +13,14 @@ import javax.validation.constraints.*; | @@ -12,10 +13,14 @@ import javax.validation.constraints.*; | ||
| 12 | @Data | 13 | @Data |
| 13 | public class ProductSkuBaseVO { | 14 | public class ProductSkuBaseVO { |
| 14 | 15 | ||
| 16 | + // TODO @franky:example 要写哈; | ||
| 17 | + | ||
| 15 | @ApiModelProperty(value = "spu编号", required = true) | 18 | @ApiModelProperty(value = "spu编号", required = true) |
| 16 | @NotNull(message = "spu编号不能为空") | 19 | @NotNull(message = "spu编号不能为空") |
| 17 | private Long spuId; | 20 | private Long spuId; |
| 18 | 21 | ||
| 22 | + // TODO @franky:类似这种字段,有额外说明的。可以写成; @ApiModelProperty(value = "规格值数组", required = true, notes = "json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]") | ||
| 23 | + | ||
| 19 | @ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true) | 24 | @ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true) |
| 20 | @NotNull(message = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]不能为空") | 25 | @NotNull(message = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]不能为空") |
| 21 | private List<Property> properties; | 26 | private List<Property> properties; |
| @@ -43,12 +48,15 @@ public class ProductSkuBaseVO { | @@ -43,12 +48,15 @@ public class ProductSkuBaseVO { | ||
| 43 | @ApiModelProperty(value = "状态: 0-正常 1-禁用") | 48 | @ApiModelProperty(value = "状态: 0-正常 1-禁用") |
| 44 | private Integer status; | 49 | private Integer status; |
| 45 | 50 | ||
| 51 | + // TODO @franky 要有 swagger 注解 | ||
| 46 | @Data | 52 | @Data |
| 47 | public static class Property { | 53 | public static class Property { |
| 54 | + | ||
| 48 | @NotNull(message = "规格属性名id不能为空") | 55 | @NotNull(message = "规格属性名id不能为空") |
| 49 | private Integer propertyId; | 56 | private Integer propertyId; |
| 50 | @NotNull(message = "规格属性值id不能为空") | 57 | @NotNull(message = "规格属性值id不能为空") |
| 51 | private Integer valueId; | 58 | private Integer valueId; |
| 59 | + | ||
| 52 | } | 60 | } |
| 53 | 61 | ||
| 54 | } | 62 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.spu; | 1 | package cn.iocoder.yudao.module.product.controller.admin.spu; |
| 2 | 2 | ||
| 3 | -import nonapi.io.github.classgraph.utils.LogNode; | ||
| 4 | -import org.springframework.web.bind.annotation.*; | ||
| 5 | -import javax.annotation.Resource; | ||
| 6 | -import org.springframework.validation.annotation.Validated; | ||
| 7 | -import org.springframework.security.access.prepost.PreAuthorize; | ||
| 8 | -import io.swagger.annotations.*; | ||
| 9 | - | ||
| 10 | -import javax.validation.constraints.*; | ||
| 11 | -import javax.validation.*; | ||
| 12 | -import javax.servlet.http.*; | ||
| 13 | -import java.util.*; | ||
| 14 | -import java.io.IOException; | ||
| 15 | - | ||
| 16 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 17 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 18 | -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 19 | - | 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 20 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 21 | - | ||
| 22 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 6 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 23 | -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | ||
| 24 | - | ||
| 25 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; | 7 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; |
| 26 | -import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | ||
| 27 | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; | 8 | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; |
| 9 | +import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | ||
| 28 | import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; | 10 | import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; |
| 11 | +import io.swagger.annotations.Api; | ||
| 12 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 13 | +import io.swagger.annotations.ApiOperation; | ||
| 14 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 15 | +import org.springframework.validation.annotation.Validated; | ||
| 16 | +import org.springframework.web.bind.annotation.*; | ||
| 17 | + | ||
| 18 | +import javax.annotation.Resource; | ||
| 19 | +import javax.servlet.http.HttpServletResponse; | ||
| 20 | +import javax.validation.Valid; | ||
| 21 | +import java.io.IOException; | ||
| 22 | +import java.util.Collection; | ||
| 23 | +import java.util.List; | ||
| 24 | + | ||
| 25 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | ||
| 29 | 27 | ||
| 30 | @Api(tags = "管理后台 - 商品spu") | 28 | @Api(tags = "管理后台 - 商品spu") |
| 31 | @RestController | 29 | @RestController |
| @@ -43,6 +41,7 @@ public class ProductSpuController { | @@ -43,6 +41,7 @@ public class ProductSpuController { | ||
| 43 | return success(spuService.createSpu(createReqVO)); | 41 | return success(spuService.createSpu(createReqVO)); |
| 44 | } | 42 | } |
| 45 | 43 | ||
| 44 | + // TODO @franky:SpuUpdateReqVO 缺少前缀 | ||
| 46 | @PutMapping("/update") | 45 | @PutMapping("/update") |
| 47 | @ApiOperation("更新商品spu") | 46 | @ApiOperation("更新商品spu") |
| 48 | @PreAuthorize("@ss.hasPermission('product:spu:update')") | 47 | @PreAuthorize("@ss.hasPermission('product:spu:update')") |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuCreateReqVO.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; | 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; | 3 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; |
| 4 | -import lombok.*; | ||
| 5 | -import java.util.*; | ||
| 6 | -import io.swagger.annotations.*; | 4 | +import io.swagger.annotations.ApiModel; |
| 5 | +import io.swagger.annotations.ApiModelProperty; | ||
| 6 | +import lombok.Data; | ||
| 7 | +import lombok.EqualsAndHashCode; | ||
| 8 | +import lombok.ToString; | ||
| 7 | 9 | ||
| 8 | import javax.validation.Valid; | 10 | import javax.validation.Valid; |
| 9 | -import javax.validation.constraints.*; | 11 | +import java.util.List; |
| 10 | 12 | ||
| 11 | @ApiModel("管理后台 - 商品spu创建 Request VO") | 13 | @ApiModel("管理后台 - 商品spu创建 Request VO") |
| 12 | @Data | 14 | @Data |
| @@ -14,6 +16,7 @@ import javax.validation.constraints.*; | @@ -14,6 +16,7 @@ import javax.validation.constraints.*; | ||
| 14 | @ToString(callSuper = true) | 16 | @ToString(callSuper = true) |
| 15 | public class ProductSpuCreateReqVO extends ProductSpuBaseVO { | 17 | public class ProductSpuCreateReqVO extends ProductSpuBaseVO { |
| 16 | 18 | ||
| 19 | + // TODO @franky:这种可以缩写下,skus | ||
| 17 | @ApiModelProperty(value = "sku组合") | 20 | @ApiModelProperty(value = "sku组合") |
| 18 | @Valid | 21 | @Valid |
| 19 | List<ProductSkuCreateReqVO> productSkuCreateReqVOS; | 22 | List<ProductSkuCreateReqVO> productSkuCreateReqVOS; |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java
| 1 | package cn.iocoder.yudao.module.product.dal.dataobject.spu; | 1 | package cn.iocoder.yudao.module.product.dal.dataobject.spu; |
| 2 | 2 | ||
| 3 | -import cn.hutool.log.Log; | ||
| 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | import com.baomidou.mybatisplus.annotation.KeySequence; | 4 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 6 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 7 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| 8 | import lombok.*; | 7 | import lombok.*; |
| 9 | 8 | ||
| 10 | -import java.util.List; | ||
| 11 | - | ||
| 12 | /** | 9 | /** |
| 13 | * 商品spu DO | 10 | * 商品spu DO |
| 14 | * | 11 | * |
| @@ -48,7 +45,7 @@ public class ProductSpuDO extends BaseDO { | @@ -48,7 +45,7 @@ public class ProductSpuDO extends BaseDO { | ||
| 48 | /** | 45 | /** |
| 49 | * 商品主图地址,* 数组,以逗号分隔,最多上传15张 | 46 | * 商品主图地址,* 数组,以逗号分隔,最多上传15张 |
| 50 | */ | 47 | */ |
| 51 | - // TODO franky:List<String> | 48 | + // TODO franky:List<String>。可以参考别的模块,怎么处理这种类型的哈 |
| 52 | private String picUrls; | 49 | private String picUrls; |
| 53 | /** | 50 | /** |
| 54 | * 排序字段 | 51 | * 排序字段 |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java
| @@ -8,6 +8,7 @@ import javax.validation.Valid; | @@ -8,6 +8,7 @@ import javax.validation.Valid; | ||
| 8 | import java.util.Collection; | 8 | import java.util.Collection; |
| 9 | import java.util.List; | 9 | import java.util.List; |
| 10 | 10 | ||
| 11 | +// TODO @JeromeSoar:需要 Product 前缀 | ||
| 11 | /** | 12 | /** |
| 12 | * 商品分类 Service 接口 | 13 | * 商品分类 Service 接口 |
| 13 | * | 14 | * |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java
| @@ -65,6 +65,7 @@ public class CategoryServiceImpl implements CategoryService { | @@ -65,6 +65,7 @@ public class CategoryServiceImpl implements CategoryService { | ||
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | private CategoryDO validateCategoryExists(Long id, ErrorCode errorCode) { | 67 | private CategoryDO validateCategoryExists(Long id, ErrorCode errorCode) { |
| 68 | + // TODO franky:0 要枚举哈 | ||
| 68 | if (id == 0) { | 69 | if (id == 0) { |
| 69 | return new CategoryDO().setId(id); | 70 | return new CategoryDO().setId(id); |
| 70 | } | 71 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java
| 1 | package cn.iocoder.yudao.module.product.service.sku; | 1 | package cn.iocoder.yudao.module.product.service.sku; |
| 2 | 2 | ||
| 3 | -import java.util.*; | ||
| 4 | -import javax.validation.*; | ||
| 5 | -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; | ||
| 6 | -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | ||
| 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuExportReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO; | ||
| 8 | +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | ||
| 9 | + | ||
| 10 | +import javax.validation.Valid; | ||
| 11 | +import java.util.Collection; | ||
| 12 | +import java.util.List; | ||
| 8 | 13 | ||
| 9 | /** | 14 | /** |
| 10 | * 商品sku Service 接口 | 15 | * 商品sku Service 接口 |
| @@ -67,8 +72,10 @@ public interface ProductSkuService { | @@ -67,8 +72,10 @@ public interface ProductSkuService { | ||
| 67 | */ | 72 | */ |
| 68 | List<ProductSkuDO> getSkuList(ProductSkuExportReqVO exportReqVO); | 73 | List<ProductSkuDO> getSkuList(ProductSkuExportReqVO exportReqVO); |
| 69 | 74 | ||
| 75 | + // TODO @franky:validateSkus;skuCreateReqList => list | ||
| 70 | /** | 76 | /** |
| 71 | - *对sku的组合的属性等进行合法性校验 | 77 | + * 对 sku 的组合的属性等进行合法性校验 |
| 78 | + * | ||
| 72 | * @param skuCreateReqList sku组合的集合 | 79 | * @param skuCreateReqList sku组合的集合 |
| 73 | */ | 80 | */ |
| 74 | void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList); | 81 | void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList); |
| @@ -76,7 +83,7 @@ public interface ProductSkuService { | @@ -76,7 +83,7 @@ public interface ProductSkuService { | ||
| 76 | /** | 83 | /** |
| 77 | * 批量保存sku | 84 | * 批量保存sku |
| 78 | * @param skuDOList sku对象集合 | 85 | * @param skuDOList sku对象集合 |
| 79 | - * @return | 86 | + * @return // TODO @franky:这里的 return 可以去掉;方法名可以改成 createSkus(list) |
| 80 | */ | 87 | */ |
| 81 | void batchSave(List<ProductSkuDO> skuDOList); | 88 | void batchSave(List<ProductSkuDO> skuDOList); |
| 82 | } | 89 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
| @@ -88,6 +88,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | @@ -88,6 +88,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | ||
| 88 | return productSkuMapper.selectList(exportReqVO); | 88 | return productSkuMapper.selectList(exportReqVO); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | + // TODO @franky:这个方法,貌似实现的还是有点问题哈。例如说,throw 异常,后面还执行逻辑~ | ||
| 91 | @Override | 92 | @Override |
| 92 | public void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList) { | 93 | public void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList) { |
| 93 | List<ProductSkuBaseVO.Property> skuPropertyList = skuCreateReqList.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); | 94 | List<ProductSkuBaseVO.Property> skuPropertyList = skuCreateReqList.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); |