Commit cd86620b74eeff4c507aa9678c7969e1b806c224
1 parent
7345d80b
REVIEW 商品管理的逻辑
Showing
23 changed files
with
62 additions
and
82 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/spu/ProductSpuTabTypeEnum.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.product.enums.spu; |
| 3 | 3 | import lombok.AllArgsConstructor; |
| 4 | 4 | import lombok.Getter; |
| 5 | 5 | |
| 6 | +// TODO @puhui999:中英文之间要有空格; 商品 spu Tab 标签枚举;这个类可以改成 ProductSpuPageTabEnum 会更好一点哈;分页 Tab 的意思; | |
| 6 | 7 | /** |
| 7 | 8 | * 商品spu标签枚举类型 |
| 8 | 9 | * |
| ... | ... | @@ -11,11 +12,13 @@ import lombok.Getter; |
| 11 | 12 | @Getter |
| 12 | 13 | @AllArgsConstructor |
| 13 | 14 | public enum ProductSpuTabTypeEnum { |
| 15 | + | |
| 14 | 16 | FOR_SALE(0,"出售中商品"), |
| 15 | 17 | IN_WAREHOUSE(1,"仓库中商品"), |
| 16 | 18 | SOLD_OUT(2,"已售空商品"), |
| 17 | 19 | ALERT_STOCK(3,"警戒库存"), |
| 18 | 20 | RECYCLE_BIN(4,"商品回收站"); |
| 21 | + | |
| 19 | 22 | /** |
| 20 | 23 | * 状态 |
| 21 | 24 | */ |
| ... | ... | @@ -24,4 +27,5 @@ public enum ProductSpuTabTypeEnum { |
| 24 | 27 | * 状态名 |
| 25 | 28 | */ |
| 26 | 29 | private final String name; |
| 30 | + | |
| 27 | 31 | } | ... | ... |
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/spu/ProductUnitEnum.java
| ... | ... | @@ -6,6 +6,7 @@ import lombok.Getter; |
| 6 | 6 | |
| 7 | 7 | import java.util.Arrays; |
| 8 | 8 | |
| 9 | +// TODO @puhui999:是不是放到数据字典里? | |
| 9 | 10 | /** |
| 10 | 11 | * 产品单位枚举 |
| 11 | 12 | * |
| ... | ... | @@ -14,6 +15,7 @@ import java.util.Arrays; |
| 14 | 15 | @Getter |
| 15 | 16 | @AllArgsConstructor |
| 16 | 17 | public enum ProductUnitEnum implements IntArrayValuable { |
| 18 | + | |
| 17 | 19 | PIECE(1, "个"), |
| 18 | 20 | DOZEN(2, "打"), |
| 19 | 21 | BOX(3, "盒"), | ... | ... |
yudao-module-mall/yudao-module-product-biz/pom.xml
| ... | ... | @@ -35,6 +35,7 @@ |
| 35 | 35 | <groupId>cn.iocoder.boot</groupId> |
| 36 | 36 | <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId> |
| 37 | 37 | </dependency> |
| 38 | + <!-- TODO 芋艿:是不是可以去掉这个依赖呀? --> | |
| 38 | 39 | <dependency> |
| 39 | 40 | <groupId>cn.iocoder.boot</groupId> |
| 40 | 41 | <artifactId>yudao-spring-boot-starter-biz-tenant</artifactId> | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java
| ... | ... | @@ -12,7 +12,6 @@ import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueServ |
| 12 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | 13 | import io.swagger.v3.oas.annotations.Parameter; |
| 14 | 14 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 15 | -import oracle.jdbc.proxy.annotation.Post; | |
| 16 | 15 | import org.springframework.security.access.prepost.PreAuthorize; |
| 17 | 16 | import org.springframework.validation.annotation.Validated; |
| 18 | 17 | import org.springframework.web.bind.annotation.*; |
| ... | ... | @@ -85,7 +84,8 @@ public class ProductPropertyController { |
| 85 | 84 | @PostMapping("/get-value-list") |
| 86 | 85 | @Operation(summary = "获得属性项列表") |
| 87 | 86 | @PreAuthorize("@ss.hasPermission('product:property:query')") |
| 88 | - public CommonResult<List<ProductPropertyAndValueRespVO>> getPropertyAndValueList(@Valid @RequestBody ProductPropertyListReqVO listReqVO) { | |
| 87 | + public CommonResult<List<ProductPropertyAndValueRespVO>> getPropertyAndValueList( | |
| 88 | + @Valid @RequestBody ProductPropertyListReqVO listReqVO) { | |
| 89 | 89 | // 查询属性项 |
| 90 | 90 | List<ProductPropertyDO> keys = productPropertyService.getPropertyList(listReqVO); |
| 91 | 91 | if (CollUtil.isEmpty(keys)) { | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyListReqVO.java
| ... | ... | @@ -4,7 +4,6 @@ import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | import lombok.ToString; |
| 6 | 6 | |
| 7 | -import javax.validation.constraints.NotEmpty; | |
| 8 | 7 | import java.util.List; |
| 9 | 8 | |
| 10 | 9 | @Schema(description = "管理后台 - 属性项 List Request VO") |
| ... | ... | @@ -15,6 +14,8 @@ public class ProductPropertyListReqVO { |
| 15 | 14 | @Schema(description = "属性名称", example = "颜色") |
| 16 | 15 | private String name; |
| 17 | 16 | |
| 18 | - @Schema(description = "属性ids", example = "1,2") | |
| 17 | + // TODO @puhui999:这个查询条件的作用是啥呀? | |
| 18 | + @Schema(description = "属性编号的数组", example = "1,2") | |
| 19 | 19 | private List<Long> propertyIds; |
| 20 | + | |
| 20 | 21 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java
| 1 | 1 | package cn.iocoder.yudao.module.product.controller.admin.sku.vo; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | -import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | -import lombok.AllArgsConstructor; | |
| 7 | 4 | import lombok.Data; |
| 8 | -import lombok.NoArgsConstructor; | |
| 9 | 5 | |
| 10 | 6 | import javax.validation.constraints.NotEmpty; |
| 11 | 7 | import javax.validation.constraints.NotNull; |
| ... | ... | @@ -50,6 +46,7 @@ public class ProductSkuBaseVO { |
| 50 | 46 | |
| 51 | 47 | @Schema(description = "商品体积", example = "1024") // 单位:m^3 平米 |
| 52 | 48 | private Double volume; |
| 49 | + // TODO @pitui999:注释可以去掉,VO 使用 @Schema 作为注释 | |
| 53 | 50 | /** |
| 54 | 51 | * 一级分销的佣金,单位:分 |
| 55 | 52 | */ | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuCreateOrUpdateReqVO.java
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuRespVO.java
| ... | ... | @@ -4,12 +4,8 @@ import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.*; |
| 5 | 5 | |
| 6 | 6 | import javax.validation.constraints.NotNull; |
| 7 | -import java.time.LocalDateTime; | |
| 8 | 7 | import java.util.List; |
| 9 | 8 | |
| 10 | -/** | |
| 11 | - * @author HUIHUI | |
| 12 | - */ | |
| 13 | 9 | @Schema(description = "管理后台 - 商品 SKU Response VO") |
| 14 | 10 | @Data |
| 15 | 11 | @EqualsAndHashCode(callSuper = true) |
| ... | ... | @@ -29,13 +25,17 @@ public class ProductSkuRespVO extends ProductSkuBaseVO { |
| 29 | 25 | @NotNull(message = "属性编号不能为空") |
| 30 | 26 | private Long propertyId; |
| 31 | 27 | |
| 28 | + // TODO @puhui999:propertyName 是不是也返回下 | |
| 29 | + | |
| 32 | 30 | @Schema(description = "属性值编号", required = true, example = "1024") |
| 33 | 31 | @NotNull(message = "属性值编号不能为空") |
| 34 | 32 | private Long valueId; |
| 35 | 33 | |
| 36 | 34 | @Schema(description = "属性值", example = "1024") |
| 37 | 35 | private String valueName; |
| 36 | + | |
| 38 | 37 | } |
| 38 | + | |
| 39 | 39 | /** |
| 40 | 40 | * 属性数组 |
| 41 | 41 | */ | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java
| ... | ... | @@ -3,12 +3,9 @@ package cn.iocoder.yudao.module.product.controller.admin.spu; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; |
| 6 | -import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | |
| 7 | 6 | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; |
| 8 | -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | |
| 9 | 7 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 10 | 8 | import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; |
| 11 | -import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; | |
| 12 | 9 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 13 | 10 | import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; |
| 14 | 11 | import io.swagger.v3.oas.annotations.Operation; |
| ... | ... | @@ -23,9 +20,7 @@ import javax.validation.Valid; |
| 23 | 20 | import java.util.List; |
| 24 | 21 | import java.util.Map; |
| 25 | 22 | |
| 26 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 27 | 23 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 28 | -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; | |
| 29 | 24 | |
| 30 | 25 | @Tag(name = "管理后台 - 商品 SPU") |
| 31 | 26 | @RestController |
| ... | ... | @@ -94,6 +89,8 @@ public class ProductSpuController { |
| 94 | 89 | public CommonResult<PageResult<ProductSpuPageRespVO>> getSpuPage(@Valid ProductSpuPageReqVO pageVO) { |
| 95 | 90 | return success(ProductSpuConvert.INSTANCE.convertPage(productSpuService.getSpuPage(pageVO))); |
| 96 | 91 | } |
| 92 | + | |
| 93 | + // TODO @tuihui999:get-count;另外,url 使用 - 拆分 | |
| 97 | 94 | @GetMapping("/tabsCount") |
| 98 | 95 | @Operation(summary = "获得商品 SPU tabsCount") |
| 99 | 96 | @PreAuthorize("@ss.hasPermission('product:spu:query')") | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java
| 1 | 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 4 | -import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; | |
| 5 | -import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; | |
| 6 | -import cn.iocoder.yudao.module.product.dal.dataobject.delivery.DeliveryTemplateDO; | |
| 7 | -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | |
| 8 | -import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; | |
| 9 | -import com.baomidou.mybatisplus.annotation.TableField; | |
| 10 | -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | |
| 11 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 12 | 4 | import lombok.Data; |
| 13 | 5 | |
| ... | ... | @@ -116,5 +108,4 @@ public class ProductSpuBaseVO { |
| 116 | 108 | @Schema(description = "虚拟销量", required = true, example = "芋道") |
| 117 | 109 | private Integer virtualSalesCount; |
| 118 | 110 | |
| 119 | - | |
| 120 | 111 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueDetailRespVO; | |
| 4 | -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; | |
| 5 | 3 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; |
| 6 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 7 | 5 | import lombok.Data; |
| 8 | 6 | import lombok.EqualsAndHashCode; |
| 9 | 7 | import lombok.ToString; |
| 10 | 8 | |
| 11 | -import javax.validation.constraints.NotNull; | |
| 12 | 9 | import java.util.List; |
| 13 | 10 | |
| 14 | 11 | @Schema(description = "管理后台 - 商品 SPU 详细 Response VO") // 包括关联的 SKU 等信息 |
| ... | ... | @@ -19,6 +16,7 @@ public class ProductSpuDetailRespVO extends ProductSpuBaseVO { |
| 19 | 16 | |
| 20 | 17 | @Schema(description = "商品编号", example = "1") |
| 21 | 18 | private Long id; |
| 19 | + | |
| 22 | 20 | // ========== SKU 相关字段 ========= |
| 23 | 21 | |
| 24 | 22 | @Schema(description = "SKU 数组", example = "1") | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java
| ... | ... | @@ -20,6 +20,7 @@ public class ProductSpuPageReqVO extends PageParam { |
| 20 | 20 | @Schema(description = "商品名称", example = "yutou") |
| 21 | 21 | private String name; |
| 22 | 22 | |
| 23 | + // TODO @puhui999:加下 @InEnum 校验 | |
| 23 | 24 | @Schema(description = "前端请求的tab类型", example = "1") |
| 24 | 25 | private Integer tabType; |
| 25 | 26 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; |
| 2 | 2 | |
| 3 | -import com.baomidou.mybatisplus.annotation.FieldFill; | |
| 4 | -import com.baomidou.mybatisplus.annotation.TableField; | |
| 5 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | 4 | import lombok.Data; |
| 7 | 5 | |
| 8 | 6 | import java.time.LocalDateTime; |
| 9 | 7 | |
| 8 | +// TODO @puhui999:可以直接继承 ProductSpuRespVO 么?一般情况下,多返回一些字段问题不大的;另外,是不是使用 ProductSpuRespVO 替代 | |
| 10 | 9 | @Schema(description = "管理后台 - 商品 SPU 分页 response VO") |
| 11 | 10 | @Data |
| 12 | 11 | public class ProductSpuPageRespVO { |
| 12 | + | |
| 13 | 13 | @Schema(description = "spuId", example = "1") |
| 14 | 14 | private Long id; |
| 15 | 15 | @Schema(description = "商品封面图", example = "1") |
| ... | ... | @@ -28,4 +28,5 @@ public class ProductSpuPageRespVO { |
| 28 | 28 | private LocalDateTime createTime; |
| 29 | 29 | @Schema(description = "商品状态", example = "1") |
| 30 | 30 | private Integer status; |
| 31 | + | |
| 31 | 32 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java
| ... | ... | @@ -47,7 +47,7 @@ public interface ProductSpuConvert { |
| 47 | 47 | |
| 48 | 48 | List<ProductSpuSimpleRespVO> convertList02(List<ProductSpuDO> list); |
| 49 | 49 | |
| 50 | - | |
| 50 | + // TODO @puhui999:是不是可以删除啦 | |
| 51 | 51 | default ProductSpuDetailRespVO convert03(ProductSpuDO spu, List<ProductSkuDO> skus, |
| 52 | 52 | List<ProductPropertyValueDetailRespBO> propertyValues) { |
| 53 | 53 | ProductSpuDetailRespVO spuVO = convert03(spu); | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyDO.java
| 1 | 1 | package cn.iocoder.yudao.module.product.dal.dataobject.property; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | 3 | import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; |
| 5 | 4 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 6 | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| ... | ... | @@ -20,7 +19,7 @@ import lombok.*; |
| 20 | 19 | @Builder |
| 21 | 20 | @NoArgsConstructor |
| 22 | 21 | @AllArgsConstructor |
| 23 | -public class ProductPropertyDO extends TenantBaseDO { | |
| 22 | +public class ProductPropertyDO extends TenantBaseDO { // TODO @puhui999:这里是不是用 BaseDO 就可以了? | |
| 24 | 23 | |
| 25 | 24 | /** |
| 26 | 25 | * 主键 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyValueDO.java
| 1 | 1 | package cn.iocoder.yudao.module.product.dal.dataobject.property; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | 3 | import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; |
| 5 | 4 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 6 | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| ... | ... | @@ -21,7 +20,7 @@ import lombok.*; |
| 21 | 20 | @Builder |
| 22 | 21 | @NoArgsConstructor |
| 23 | 22 | @AllArgsConstructor |
| 24 | -public class ProductPropertyValueDO extends TenantBaseDO { | |
| 23 | +public class ProductPropertyValueDO extends TenantBaseDO { // TODO @puhui999:这里是不是用 BaseDO 就可以了? | |
| 25 | 24 | |
| 26 | 25 | /** |
| 27 | 26 | * 主键 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java
| 1 | 1 | package cn.iocoder.yudao.module.product.dal.dataobject.sku; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 5 | 4 | import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; |
| 6 | 5 | import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; |
| 7 | 6 | import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; |
| ... | ... | @@ -28,7 +27,7 @@ import java.util.List; |
| 28 | 27 | @Builder |
| 29 | 28 | @NoArgsConstructor |
| 30 | 29 | @AllArgsConstructor |
| 31 | -public class ProductSkuDO extends TenantBaseDO { | |
| 30 | +public class ProductSkuDO extends TenantBaseDO { // TODO @puhui999:这里是不是用 BaseDO 就可以了? | |
| 32 | 31 | |
| 33 | 32 | /** |
| 34 | 33 | * 商品 SKU 编号,自增 |
| ... | ... | @@ -116,7 +115,7 @@ public class ProductSkuDO extends TenantBaseDO { |
| 116 | 115 | // * 冗余 {@link ProductPropertyDO#getName()} |
| 117 | 116 | // * |
| 118 | 117 | // * 注意:每次属性名字发生变化时,需要更新该冗余 |
| 119 | - // */ TODO 与已有代码逻辑存在冲突 | |
| 118 | + // */ TODO @puhui999:与已有代码逻辑存在冲突;芋艿:冲突点是啥呀? | |
| 120 | 119 | //private String propertyName; |
| 121 | 120 | |
| 122 | 121 | /** |
| ... | ... | @@ -131,7 +130,7 @@ public class ProductSkuDO extends TenantBaseDO { |
| 131 | 130 | // * 冗余 {@link ProductPropertyValueDO#getName()} |
| 132 | 131 | // * |
| 133 | 132 | // * 注意:每次属性值名字发生变化时,需要更新该冗余 |
| 134 | - // */ TODO 与已有代码逻辑存在冲突 | |
| 133 | + // */ TODO @puhui999:与已有代码逻辑存在冲突;芋艿:冲突点是啥呀? | |
| 135 | 134 | //private String valueName; |
| 136 | 135 | |
| 137 | 136 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.product.dal.mysql.spu; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.ObjUtil; |
| 4 | -import cn.hutool.core.util.StrUtil; | |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 7 | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 8 | -import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; | |
| 9 | 7 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; |
| 10 | 8 | import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; |
| 11 | 9 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| ... | ... | @@ -14,24 +12,14 @@ import cn.iocoder.yudao.module.product.enums.spu.ProductSpuTabTypeEnum; |
| 14 | 12 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 15 | 13 | import org.apache.ibatis.annotations.Mapper; |
| 16 | 14 | |
| 17 | -import java.util.Map; | |
| 18 | 15 | import java.util.Objects; |
| 19 | 16 | import java.util.Set; |
| 20 | 17 | |
| 21 | -/** | |
| 22 | - * 商品spu Mapper | |
| 23 | - * | |
| 24 | - * @author 芋道源码 | |
| 25 | - */ | |
| 26 | 18 | @Mapper |
| 27 | 19 | public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { |
| 28 | 20 | |
| 29 | - //default PageResult<ProductSpuDO> selectPage(ProductSpuPageReqVO reqVO) { | |
| 30 | - // return selectPage(reqVO, new LambdaQueryWrapperX<ProductSpuDO>() | |
| 31 | - // .likeIfPresent(ProductSpuDO::getName, reqVO.getName()) | |
| 32 | - // .orderByDesc(ProductSpuDO::getSort)); | |
| 33 | - //} | |
| 34 | 21 | default PageResult<ProductSpuDO> selectPage(ProductSpuPageReqVO reqVO) { |
| 22 | + // TODO @puhui999:多个 tab,写 if else 去补条件,可阅读性会好点哈 | |
| 35 | 23 | return selectPage(reqVO, new LambdaQueryWrapperX<ProductSpuDO>() |
| 36 | 24 | // 商品名称 |
| 37 | 25 | .likeIfPresent(ProductSpuDO::getName, reqVO.getName()) |
| ... | ... | @@ -42,7 +30,7 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> { |
| 42 | 30 | .eq(ProductSpuTabTypeEnum.IN_WAREHOUSE.getType().equals(reqVO.getTabType()),ProductSpuDO::getStatus,ProductSpuStatusEnum.DISABLE.getStatus()) |
| 43 | 31 | // 已售空商品 |
| 44 | 32 | .eq(ProductSpuTabTypeEnum.SOLD_OUT.getType().equals(reqVO.getTabType()),ProductSpuDO::getStock,0) |
| 45 | - // TODO 警戒库存暂时为 10,后期需要使用常量或者数据库配置替换 | |
| 33 | + // TODO @phuui999:警戒库存暂时为 10,后期需要使用常量或者数据库配置替换 | |
| 46 | 34 | .le(ProductSpuTabTypeEnum.ALERT_STOCK.getType().equals(reqVO.getTabType()),ProductSpuDO::getStock,10) |
| 47 | 35 | // 回收站 |
| 48 | 36 | .eq(ProductSpuTabTypeEnum.RECYCLE_BIN.getType().equals(reqVO.getTabType()),ProductSpuDO::getStatus,ProductSpuStatusEnum.RECYCLE.getStatus()) | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java
| ... | ... | @@ -94,7 +94,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { |
| 94 | 94 | |
| 95 | 95 | @Override |
| 96 | 96 | public List<ProductPropertyDO> getPropertyList(ProductPropertyListReqVO listReqVO) { |
| 97 | - // 增加使用属性id查询 | |
| 97 | + // 增加使用属性 id 查询 | |
| 98 | 98 | if (CollUtil.isNotEmpty(listReqVO.getPropertyIds())){ |
| 99 | 99 | return productPropertyMapper.selectBatchIds(listReqVO.getPropertyIds()); |
| 100 | 100 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.product.service.spu; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.hutool.core.convert.Convert; | |
| 5 | 4 | import cn.hutool.core.util.ObjectUtil; |
| 6 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 8 | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 9 | -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | |
| 10 | 7 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; |
| 11 | 8 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; |
| 12 | 9 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; |
| ... | ... | @@ -23,7 +20,6 @@ import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; |
| 23 | 20 | import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; |
| 24 | 21 | import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; |
| 25 | 22 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 26 | -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
| 27 | 23 | import org.springframework.context.annotation.Lazy; |
| 28 | 24 | import org.springframework.stereotype.Service; |
| 29 | 25 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -34,7 +30,7 @@ import java.util.*; |
| 34 | 30 | import java.util.stream.Collectors; |
| 35 | 31 | |
| 36 | 32 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 37 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | |
| 33 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; | |
| 38 | 34 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; |
| 39 | 35 | import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_SAVE_FAIL_CATEGORY_LEVEL_ERROR; |
| 40 | 36 | |
| ... | ... | @@ -63,17 +59,18 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 63 | 59 | @Override |
| 64 | 60 | @Transactional(rollbackFor = Exception.class) |
| 65 | 61 | public Long createSpu(ProductSpuCreateReqVO createReqVO) { |
| 66 | - // 校验分类 TODO 暂不清楚为什么只能选择第三层的结点 | |
| 62 | + // 校验分类 TODO puhui999:暂不清楚为什么只能选择第三层的结点;芋艿:改成二级分类,因为商品只能放在叶子节点级别; | |
| 67 | 63 | //validateCategory(createReqVO.getCategoryId()); |
| 68 | - // 校验品牌 TODO 暂不校验,前端没有做品牌选择 | |
| 64 | + // 校验品牌 TODO puhui999:暂不校验,前端没有做品牌选择;芋艿:可以加下哈 | |
| 69 | 65 | //brandService.validateProductBrand(createReqVO.getBrandId()); |
| 70 | 66 | |
| 71 | 67 | List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = createReqVO.getSkus(); |
| 72 | - // 校验SKU | |
| 68 | + // 校验 SKU | |
| 73 | 69 | productSkuService.validateSkuList(skuSaveReqList, createReqVO.getSpecType()); |
| 74 | 70 | ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); |
| 75 | - // 初始化SPU中SKU相关属性 | |
| 71 | + // 初始化 SPU 中 SKU 相关属性 | |
| 76 | 72 | initSpuFromSkus(spu, skuSaveReqList); |
| 73 | + | |
| 77 | 74 | // 插入 SPU |
| 78 | 75 | productSpuMapper.insert(spu); |
| 79 | 76 | // 插入 SKU |
| ... | ... | @@ -193,6 +190,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 193 | 190 | stockIncrCounts.forEach((id, incCount) -> productSpuMapper.updateStock(id, incCount)); |
| 194 | 191 | } |
| 195 | 192 | |
| 193 | + // TODO @puhui999:Service 尽量不做一些跟 VO 相关的拼接逻辑,目的是让 Service 更加简洁一点哈。 | |
| 196 | 194 | @Override |
| 197 | 195 | public ProductSpuDetailRespVO getSpuDetail(Long id) { |
| 198 | 196 | // 获得商品 SPU |
| ... | ... | @@ -204,12 +202,17 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 204 | 202 | // 查询商品 SKU |
| 205 | 203 | List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId()); |
| 206 | 204 | if (CollUtil.isNotEmpty(skus)){ |
| 205 | + // TODO @puhui999:skuVOs 更简洁一点。然后大小写要注释哈。RespVOs;因为 VO 是缩写,s 是复数 | |
| 207 | 206 | List<ProductSkuRespVO> skuRespVoS = ProductSkuConvert.INSTANCE.convertList(skus); |
| 208 | 207 | // 非多规格,不需要处理 |
| 208 | + // TODO @puhui999:统一模型,即使是单规格,也查询下,问题不大的 | |
| 209 | 209 | if (ObjectUtil.equal(productSpuDetailRespVO.getSpecType(), true)) { |
| 210 | - // 获取所有的属性值id | |
| 211 | - Set<Long> valueIds = skus.stream().flatMap(p -> p.getProperties().stream()).map(ProductSkuDO.Property::getValueId).collect(Collectors.toSet()); | |
| 210 | + // 获取所有的属性值 id | |
| 211 | + Set<Long> valueIds = skus.stream().flatMap(p -> p.getProperties().stream()) | |
| 212 | + .map(ProductSkuDO.Property::getValueId) | |
| 213 | + .collect(Collectors.toSet()); | |
| 212 | 214 | List<ProductPropertyValueDetailRespBO> valueDetailList = productPropertyValueService.getPropertyValueDetailList(valueIds); |
| 215 | + // TODO @puhui999:拼接的逻辑,最好查询好后,丢到 convert 里面统一处理;这样 Service or Controller 也可以更简洁;原则上,Controller 去组合;Service 写逻辑;Convert 转换 | |
| 213 | 216 | Map<Long, String> stringMap = valueDetailList.stream().collect(Collectors.toMap(ProductPropertyValueDetailRespBO::getValueId, ProductPropertyValueDetailRespBO::getValueName)); |
| 214 | 217 | // 设置属性值名称 |
| 215 | 218 | skuRespVoS.stream().flatMap(p -> p.getProperties().stream()).forEach(item ->item.setValueName(stringMap.get(item.getValueId()))); |
| ... | ... | @@ -232,6 +235,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 232 | 235 | |
| 233 | 236 | @Override |
| 234 | 237 | public Map<Integer, Long> getTabsCount() { |
| 238 | + // TODO @puhui999:map =》counts;尽量避免出现 map 这种命名,无命名含义哈 | |
| 235 | 239 | Map<Integer, Long> map = new HashMap<>(); |
| 236 | 240 | // 查询销售中的商品数量 |
| 237 | 241 | map.put(ProductSpuTabTypeEnum.FOR_SALE.getType(), productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus())); |
| ... | ... | @@ -240,6 +244,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 240 | 244 | // 查询售空的商品数量 |
| 241 | 245 | map.put(ProductSpuTabTypeEnum.SOLD_OUT.getType(),productSpuMapper.selectCount(ProductSpuDO::getStock, 0)); |
| 242 | 246 | // 查询触发警戒库存的商品数量 TODO 警戒库存暂时为 10,后期需要使用常量或者数据库配置替换 |
| 247 | + // TODO @puhui999:要有空格;, productSpuMapper | |
| 248 | + // TODO @puhui999:Service 不要有 Mapper 的逻辑;想想咋抽象一下哈 | |
| 243 | 249 | map.put(ProductSpuTabTypeEnum.ALERT_STOCK.getType(),productSpuMapper.selectCount(new LambdaQueryWrapperX<ProductSpuDO>().le(ProductSpuDO::getStock, 10))); |
| 244 | 250 | // 查询回收站中的商品数量 |
| 245 | 251 | map.put(ProductSpuTabTypeEnum.RECYCLE_BIN.getType(),productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus())); | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImplTest.java
| ... | ... | @@ -5,11 +5,11 @@ import cn.hutool.core.map.MapUtil; |
| 5 | 5 | import cn.hutool.core.util.RandomUtil; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 9 | -import cn.iocoder.yudao.framework.common.util.collection.SetUtils; | |
| 10 | 8 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 11 | -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; | |
| 12 | -import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; | |
| 9 | +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO; | |
| 10 | +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; | |
| 11 | +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageRespVO; | |
| 12 | +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO; | |
| 13 | 13 | import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; |
| 14 | 14 | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; |
| 15 | 15 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| ... | ... | @@ -34,7 +34,6 @@ import java.util.*; |
| 34 | 34 | import java.util.stream.Collectors; |
| 35 | 35 | import java.util.stream.Stream; |
| 36 | 36 | |
| 37 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; | |
| 38 | 37 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 39 | 38 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 40 | 39 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| ... | ... | @@ -79,13 +78,10 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { |
| 79 | 78 | @Test |
| 80 | 79 | public void testCreateSpu_success() { |
| 81 | 80 | // 准备参数 |
| 82 | - ProductSpuCreateReqVO createReqVO = randomPojo(ProductSpuCreateReqVO.class, o -> { | |
| 83 | - o.setSpecType(true); | |
| 84 | - }); | |
| 81 | + ProductSpuCreateReqVO createReqVO = randomPojo(ProductSpuCreateReqVO.class); | |
| 85 | 82 | Long spu = productSpuService.createSpu(createReqVO); |
| 86 | 83 | ProductSpuDO productSpuDO = productSpuMapper.selectById(spu); |
| 87 | 84 | assertPojoEquals(createReqVO, productSpuDO); |
| 88 | - | |
| 89 | 85 | } |
| 90 | 86 | |
| 91 | 87 | @Test |
| ... | ... | @@ -96,7 +92,6 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { |
| 96 | 92 | // 准备参数 |
| 97 | 93 | ProductSpuUpdateReqVO reqVO = randomPojo(ProductSpuUpdateReqVO.class, o -> { |
| 98 | 94 | o.setId(createReqVO.getId()); // 设置更新的 ID |
| 99 | - o.setSpecType(true); | |
| 100 | 95 | }); |
| 101 | 96 | // 调用 |
| 102 | 97 | productSpuService.updateSpu(reqVO); |
| ... | ... | @@ -107,9 +102,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { |
| 107 | 102 | |
| 108 | 103 | @Test |
| 109 | 104 | public void testValidateSpuExists_exception() { |
| 110 | - ProductSpuUpdateReqVO reqVO = randomPojo(ProductSpuUpdateReqVO.class, o -> { | |
| 111 | - o.setSpecType(true); | |
| 112 | - }); | |
| 105 | + ProductSpuUpdateReqVO reqVO = randomPojo(ProductSpuUpdateReqVO.class); | |
| 113 | 106 | // 调用 |
| 114 | 107 | Assertions.assertThrows(ServiceException.class, () -> productSpuService.updateSpu(reqVO)); |
| 115 | 108 | } |
| ... | ... | @@ -174,7 +167,6 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { |
| 174 | 167 | //o.setMinPrice(1); // TODO ProductSpuDO中已没有相关属性 |
| 175 | 168 | //o.setMaxPrice(50); |
| 176 | 169 | o.setMarketPrice(25); |
| 177 | - o.setSpecType(false); | |
| 178 | 170 | o.setBrandId(brandId); |
| 179 | 171 | o.setCategoryId(categoryId); |
| 180 | 172 | //o.setClickCount(100); |
| ... | ... | @@ -222,8 +214,8 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest { |
| 222 | 214 | //o.setMinPrice(1); // TODO ProductSpuDO中已没有相关属性 |
| 223 | 215 | //o.setMaxPrice(1); |
| 224 | 216 | o.setMarketPrice(1); |
| 225 | - o.setSpecType(false); | |
| 226 | 217 | o.setBrandId(brandId); |
| 218 | + o.setSpecType(false); | |
| 227 | 219 | o.setCategoryId(categoryId); |
| 228 | 220 | //o.setClickCount(1); // TODO ProductSpuDO中已没有相关属性 |
| 229 | 221 | //o.setCode(generateNo()); | ... | ... |