mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	code review:商品 spu、sku 的逻辑
This commit is contained in:
		| @@ -1,31 +1,31 @@ | |||||||
| package cn.iocoder.yudao.module.product.controller.admin.sku; | package cn.iocoder.yudao.module.product.controller.admin.sku; | ||||||
|  |  | ||||||
| import org.springframework.web.bind.annotation.*; |  | ||||||
| import javax.annotation.Resource; |  | ||||||
| import org.springframework.validation.annotation.Validated; |  | ||||||
| import org.springframework.security.access.prepost.PreAuthorize; |  | ||||||
| import io.swagger.annotations.*; |  | ||||||
|  |  | ||||||
| import javax.validation.constraints.*; |  | ||||||
| import javax.validation.*; |  | ||||||
| import javax.servlet.http.*; |  | ||||||
| import java.util.*; |  | ||||||
| import java.io.IOException; |  | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; |  | ||||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||||||
| import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; |  | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; | ||||||
| import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |  | ||||||
| import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | ||||||
|  | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | ||||||
| import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; | ||||||
|  | import io.swagger.annotations.Api; | ||||||
|  | import io.swagger.annotations.ApiImplicitParam; | ||||||
|  | import io.swagger.annotations.ApiOperation; | ||||||
|  | import org.springframework.security.access.prepost.PreAuthorize; | ||||||
|  | import org.springframework.validation.annotation.Validated; | ||||||
|  | import org.springframework.web.bind.annotation.*; | ||||||
|  |  | ||||||
|  | import javax.annotation.Resource; | ||||||
|  | import javax.servlet.http.HttpServletResponse; | ||||||
|  | import javax.validation.Valid; | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.util.Collection; | ||||||
|  | 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 | @RestController | ||||||
| @RequestMapping("/product/sku") | @RequestMapping("/product/sku") | ||||||
|   | |||||||
| @@ -1,9 +1,10 @@ | |||||||
| package cn.iocoder.yudao.module.product.controller.admin.sku.vo; | package cn.iocoder.yudao.module.product.controller.admin.sku.vo; | ||||||
|  |  | ||||||
| import lombok.*; | import io.swagger.annotations.ApiModelProperty; | ||||||
| import java.util.*; | import lombok.Data; | ||||||
| import io.swagger.annotations.*; |  | ||||||
| import javax.validation.constraints.*; | import javax.validation.constraints.NotNull; | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| * 商品sku Base VO,提供给添加、修改、详细的子 VO 使用 | * 商品sku Base VO,提供给添加、修改、详细的子 VO 使用 | ||||||
| @@ -12,10 +13,14 @@ import javax.validation.constraints.*; | |||||||
| @Data | @Data | ||||||
| public class ProductSkuBaseVO { | public class ProductSkuBaseVO { | ||||||
|  |  | ||||||
|  |     // TODO @franky:example 要写哈; | ||||||
|  |  | ||||||
|     @ApiModelProperty(value = "spu编号", required = true) |     @ApiModelProperty(value = "spu编号", required = true) | ||||||
|     @NotNull(message = "spu编号不能为空") |     @NotNull(message = "spu编号不能为空") | ||||||
|     private Long spuId; |     private Long spuId; | ||||||
|  |  | ||||||
|  |     // TODO @franky:类似这种字段,有额外说明的。可以写成;    @ApiModelProperty(value = "规格值数组", required = true, notes = "json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]") | ||||||
|  |  | ||||||
|     @ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true) |     @ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true) | ||||||
|     @NotNull(message = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]不能为空") |     @NotNull(message = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]不能为空") | ||||||
|     private List<Property> properties; |     private List<Property> properties; | ||||||
| @@ -43,12 +48,15 @@ public class ProductSkuBaseVO { | |||||||
|     @ApiModelProperty(value = "状态: 0-正常 1-禁用") |     @ApiModelProperty(value = "状态: 0-正常 1-禁用") | ||||||
|     private Integer status; |     private Integer status; | ||||||
|  |  | ||||||
|  |     // TODO @franky 要有 swagger 注解 | ||||||
|     @Data |     @Data | ||||||
|     public static class Property { |     public static class Property { | ||||||
|  |  | ||||||
|         @NotNull(message = "规格属性名id不能为空") |         @NotNull(message = "规格属性名id不能为空") | ||||||
|         private Integer propertyId; |         private Integer propertyId; | ||||||
|         @NotNull(message = "规格属性值id不能为空") |         @NotNull(message = "规格属性值id不能为空") | ||||||
|         private Integer valueId; |         private Integer valueId; | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,31 +1,29 @@ | |||||||
| package cn.iocoder.yudao.module.product.controller.admin.spu; | package cn.iocoder.yudao.module.product.controller.admin.spu; | ||||||
|  |  | ||||||
| import nonapi.io.github.classgraph.utils.LogNode; |  | ||||||
| import org.springframework.web.bind.annotation.*; |  | ||||||
| import javax.annotation.Resource; |  | ||||||
| import org.springframework.validation.annotation.Validated; |  | ||||||
| import org.springframework.security.access.prepost.PreAuthorize; |  | ||||||
| import io.swagger.annotations.*; |  | ||||||
|  |  | ||||||
| import javax.validation.constraints.*; |  | ||||||
| import javax.validation.*; |  | ||||||
| import javax.servlet.http.*; |  | ||||||
| import java.util.*; |  | ||||||
| import java.io.IOException; |  | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; |  | ||||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||||||
| import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; |  | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; | ||||||
| import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |  | ||||||
| import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; | ||||||
|  | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | ||||||
| import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; | import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; | ||||||
|  | import io.swagger.annotations.Api; | ||||||
|  | import io.swagger.annotations.ApiImplicitParam; | ||||||
|  | import io.swagger.annotations.ApiOperation; | ||||||
|  | import org.springframework.security.access.prepost.PreAuthorize; | ||||||
|  | import org.springframework.validation.annotation.Validated; | ||||||
|  | import org.springframework.web.bind.annotation.*; | ||||||
|  |  | ||||||
|  | import javax.annotation.Resource; | ||||||
|  | import javax.servlet.http.HttpServletResponse; | ||||||
|  | import javax.validation.Valid; | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.util.Collection; | ||||||
|  | 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; | ||||||
|  |  | ||||||
| @Api(tags = "管理后台 - 商品spu") | @Api(tags = "管理后台 - 商品spu") | ||||||
| @RestController | @RestController | ||||||
| @@ -43,6 +41,7 @@ public class ProductSpuController { | |||||||
|         return success(spuService.createSpu(createReqVO)); |         return success(spuService.createSpu(createReqVO)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // TODO @franky:SpuUpdateReqVO 缺少前缀 | ||||||
|     @PutMapping("/update") |     @PutMapping("/update") | ||||||
|     @ApiOperation("更新商品spu") |     @ApiOperation("更新商品spu") | ||||||
|     @PreAuthorize("@ss.hasPermission('product:spu:update')") |     @PreAuthorize("@ss.hasPermission('product:spu:update')") | ||||||
|   | |||||||
| @@ -1,12 +1,14 @@ | |||||||
| package cn.iocoder.yudao.module.product.controller.admin.spu.vo; | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; | ||||||
| import lombok.*; | import io.swagger.annotations.ApiModel; | ||||||
| import java.util.*; | import io.swagger.annotations.ApiModelProperty; | ||||||
| import io.swagger.annotations.*; | import lombok.Data; | ||||||
|  | import lombok.EqualsAndHashCode; | ||||||
|  | import lombok.ToString; | ||||||
|  |  | ||||||
| import javax.validation.Valid; | import javax.validation.Valid; | ||||||
| import javax.validation.constraints.*; | import java.util.List; | ||||||
|  |  | ||||||
| @ApiModel("管理后台 - 商品spu创建 Request VO") | @ApiModel("管理后台 - 商品spu创建 Request VO") | ||||||
| @Data | @Data | ||||||
| @@ -14,6 +16,7 @@ import javax.validation.constraints.*; | |||||||
| @ToString(callSuper = true) | @ToString(callSuper = true) | ||||||
| public class ProductSpuCreateReqVO extends ProductSpuBaseVO { | public class ProductSpuCreateReqVO extends ProductSpuBaseVO { | ||||||
|  |  | ||||||
|  |     // TODO @franky:这种可以缩写下,skus | ||||||
|     @ApiModelProperty(value = "sku组合") |     @ApiModelProperty(value = "sku组合") | ||||||
|     @Valid |     @Valid | ||||||
|     List<ProductSkuCreateReqVO> productSkuCreateReqVOS; |     List<ProductSkuCreateReqVO> productSkuCreateReqVOS; | ||||||
|   | |||||||
| @@ -1,14 +1,11 @@ | |||||||
| package cn.iocoder.yudao.module.product.dal.dataobject.spu; | package cn.iocoder.yudao.module.product.dal.dataobject.spu; | ||||||
|  |  | ||||||
| import cn.hutool.log.Log; |  | ||||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||||
| import com.baomidou.mybatisplus.annotation.KeySequence; | import com.baomidou.mybatisplus.annotation.KeySequence; | ||||||
| import com.baomidou.mybatisplus.annotation.TableId; | import com.baomidou.mybatisplus.annotation.TableId; | ||||||
| import com.baomidou.mybatisplus.annotation.TableName; | import com.baomidou.mybatisplus.annotation.TableName; | ||||||
| import lombok.*; | import lombok.*; | ||||||
|  |  | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 商品spu DO |  * 商品spu DO | ||||||
|  * |  * | ||||||
| @@ -48,7 +45,7 @@ public class ProductSpuDO extends BaseDO { | |||||||
|     /** |     /** | ||||||
|      * 商品主图地址,* 数组,以逗号分隔,最多上传15张 |      * 商品主图地址,* 数组,以逗号分隔,最多上传15张 | ||||||
|      */ |      */ | ||||||
|     // TODO franky:List<String> |     // TODO franky:List<String>。可以参考别的模块,怎么处理这种类型的哈 | ||||||
|     private String picUrls; |     private String picUrls; | ||||||
|     /** |     /** | ||||||
|      * 排序字段 |      * 排序字段 | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import javax.validation.Valid; | |||||||
| import java.util.Collection; | import java.util.Collection; | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
|  | // TODO @JeromeSoar:需要 Product 前缀 | ||||||
| /** | /** | ||||||
|  * 商品分类 Service 接口 |  * 商品分类 Service 接口 | ||||||
|  * |  * | ||||||
|   | |||||||
| @@ -65,6 +65,7 @@ public class CategoryServiceImpl implements CategoryService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private CategoryDO validateCategoryExists(Long id, ErrorCode errorCode) { |     private CategoryDO validateCategoryExists(Long id, ErrorCode errorCode) { | ||||||
|  |         // TODO franky:0 要枚举哈 | ||||||
|         if (id == 0) { |         if (id == 0) { | ||||||
|             return new CategoryDO().setId(id); |             return new CategoryDO().setId(id); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -1,10 +1,15 @@ | |||||||
| package cn.iocoder.yudao.module.product.service.sku; | package cn.iocoder.yudao.module.product.service.sku; | ||||||
|  |  | ||||||
| import java.util.*; |  | ||||||
| import javax.validation.*; |  | ||||||
| import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; |  | ||||||
| import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |  | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
|  | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; | ||||||
|  | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuExportReqVO; | ||||||
|  | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO; | ||||||
|  | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO; | ||||||
|  | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | ||||||
|  |  | ||||||
|  | import javax.validation.Valid; | ||||||
|  | import java.util.Collection; | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 商品sku Service 接口 |  * 商品sku Service 接口 | ||||||
| @@ -67,8 +72,10 @@ public interface ProductSkuService { | |||||||
|      */ |      */ | ||||||
|     List<ProductSkuDO> getSkuList(ProductSkuExportReqVO exportReqVO); |     List<ProductSkuDO> getSkuList(ProductSkuExportReqVO exportReqVO); | ||||||
|  |  | ||||||
|  |     // TODO @franky:validateSkus;skuCreateReqList => list | ||||||
|     /** |     /** | ||||||
|      *对sku的组合的属性等进行合法性校验 |      * 对 sku 的组合的属性等进行合法性校验 | ||||||
|  |      * | ||||||
|      * @param skuCreateReqList sku组合的集合 |      * @param skuCreateReqList sku组合的集合 | ||||||
|      */ |      */ | ||||||
|     void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList); |     void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList); | ||||||
| @@ -76,7 +83,7 @@ public interface ProductSkuService { | |||||||
|     /** |     /** | ||||||
|      * 批量保存sku |      * 批量保存sku | ||||||
|      * @param skuDOList sku对象集合 |      * @param skuDOList sku对象集合 | ||||||
|      * @return |      * @return // TODO @franky:这里的 return 可以去掉;方法名可以改成 createSkus(list) | ||||||
|      */ |      */ | ||||||
|     void batchSave(List<ProductSkuDO> skuDOList); |     void batchSave(List<ProductSkuDO> skuDOList); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -88,6 +88,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | |||||||
|         return productSkuMapper.selectList(exportReqVO); |         return productSkuMapper.selectList(exportReqVO); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // TODO @franky:这个方法,貌似实现的还是有点问题哈。例如说,throw 异常,后面还执行逻辑~ | ||||||
|     @Override |     @Override | ||||||
|     public void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList) { |     public void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList) { | ||||||
|         List<ProductSkuBaseVO.Property> skuPropertyList = skuCreateReqList.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); |         List<ProductSkuBaseVO.Property> skuPropertyList = skuCreateReqList.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV