Commit 98ca807d4b9ad660f5cb813c19504b9a5ba7d7bb

Authored by YunaiV
1 parent 0b5aa560

product:优化商品属性项的代码

Showing 19 changed files with 150 additions and 152 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java
@@ -25,6 +25,7 @@ public interface ErrorCodeConstants { @@ -25,6 +25,7 @@ public interface ErrorCodeConstants {
25 // ========== 商品属性项 1008003000 ========== 25 // ========== 商品属性项 1008003000 ==========
26 ErrorCode PROPERTY_NOT_EXISTS = new ErrorCode(1008003000, "属性项不存在"); 26 ErrorCode PROPERTY_NOT_EXISTS = new ErrorCode(1008003000, "属性项不存在");
27 ErrorCode PROPERTY_EXISTS = new ErrorCode(1008003001, "属性项的名称已存在"); 27 ErrorCode PROPERTY_EXISTS = new ErrorCode(1008003001, "属性项的名称已存在");
  28 + ErrorCode PROPERTY_DELETE_FAIL_VALUE_EXISTS = new ErrorCode(1008003002, "属性项下存在属性值,无法删除");
28 29
29 // ========== 商品属性值 1008004000 ========== 30 // ========== 商品属性值 1008004000 ==========
30 ErrorCode PROPERTY_VALUE_NOT_EXISTS = new ErrorCode(1008004000, "属性值不存在"); 31 ErrorCode PROPERTY_VALUE_NOT_EXISTS = new ErrorCode(1008004000, "属性值不存在");
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java
1 package cn.iocoder.yudao.module.product.controller.admin.property; 1 package cn.iocoder.yudao.module.product.controller.admin.property;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.*; 6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.*;
  7 +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert;
  8 +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
  9 +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
6 import cn.iocoder.yudao.module.product.service.property.ProductPropertyService; 10 import cn.iocoder.yudao.module.product.service.property.ProductPropertyService;
  11 +import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
7 import io.swagger.annotations.Api; 12 import io.swagger.annotations.Api;
8 import io.swagger.annotations.ApiImplicitParam; 13 import io.swagger.annotations.ApiImplicitParam;
9 import io.swagger.annotations.ApiOperation; 14 import io.swagger.annotations.ApiOperation;
@@ -13,10 +18,11 @@ import org.springframework.web.bind.annotation.*; @@ -13,10 +18,11 @@ import org.springframework.web.bind.annotation.*;
13 18
14 import javax.annotation.Resource; 19 import javax.annotation.Resource;
15 import javax.validation.Valid; 20 import javax.validation.Valid;
16 - 21 +import java.util.Collections;
17 import java.util.List; 22 import java.util.List;
18 23
19 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  25 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
20 26
21 @Api(tags = "管理后台 - 商品属性项") 27 @Api(tags = "管理后台 - 商品属性项")
22 @RestController 28 @RestController
@@ -26,6 +32,8 @@ public class ProductPropertyController { @@ -26,6 +32,8 @@ public class ProductPropertyController {
26 32
27 @Resource 33 @Resource
28 private ProductPropertyService productPropertyService; 34 private ProductPropertyService productPropertyService;
  35 + @Resource
  36 + private ProductPropertyValueService productPropertyValueService;
29 37
30 @PostMapping("/create") 38 @PostMapping("/create")
31 @ApiOperation("创建属性项") 39 @ApiOperation("创建属性项")
@@ -56,28 +64,36 @@ public class ProductPropertyController { @@ -56,28 +64,36 @@ public class ProductPropertyController {
56 @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) 64 @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
57 @PreAuthorize("@ss.hasPermission('product:property:query')") 65 @PreAuthorize("@ss.hasPermission('product:property:query')")
58 public CommonResult<ProductPropertyRespVO> getProperty(@RequestParam("id") Long id) { 66 public CommonResult<ProductPropertyRespVO> getProperty(@RequestParam("id") Long id) {
59 - return success(productPropertyService.getProperty(id)); 67 + return success(ProductPropertyConvert.INSTANCE.convert(productPropertyService.getProperty(id)));
60 } 68 }
61 69
62 @GetMapping("/list") 70 @GetMapping("/list")
63 @ApiOperation("获得属性项列表") 71 @ApiOperation("获得属性项列表")
64 @PreAuthorize("@ss.hasPermission('product:property:query')") 72 @PreAuthorize("@ss.hasPermission('product:property:query')")
65 public CommonResult<List<ProductPropertyRespVO>> getPropertyList(@Valid ProductPropertyListReqVO listReqVO) { 73 public CommonResult<List<ProductPropertyRespVO>> getPropertyList(@Valid ProductPropertyListReqVO listReqVO) {
66 - return success(productPropertyService.getPropertyVOList(listReqVO)); 74 + return success(ProductPropertyConvert.INSTANCE.convertList(productPropertyService.getPropertyList(listReqVO)));
67 } 75 }
68 76
69 @GetMapping("/page") 77 @GetMapping("/page")
70 @ApiOperation("获得属性项分页") 78 @ApiOperation("获得属性项分页")
71 @PreAuthorize("@ss.hasPermission('product:property:query')") 79 @PreAuthorize("@ss.hasPermission('product:property:query')")
72 public CommonResult<PageResult<ProductPropertyRespVO>> getPropertyPage(@Valid ProductPropertyPageReqVO pageVO) { 80 public CommonResult<PageResult<ProductPropertyRespVO>> getPropertyPage(@Valid ProductPropertyPageReqVO pageVO) {
73 - return success(productPropertyService.getPropertyPage(pageVO)); 81 + return success(ProductPropertyConvert.INSTANCE.convertPage(productPropertyService.getPropertyPage(pageVO)));
74 } 82 }
75 83
76 - @GetMapping("/listAndValue") 84 + @GetMapping("/get-value-list")
77 @ApiOperation("获得属性项列表") 85 @ApiOperation("获得属性项列表")
78 @PreAuthorize("@ss.hasPermission('product:property:query')") 86 @PreAuthorize("@ss.hasPermission('product:property:query')")
79 public CommonResult<List<ProductPropertyAndValueRespVO>> getPropertyAndValueList(@Valid ProductPropertyListReqVO listReqVO) { 87 public CommonResult<List<ProductPropertyAndValueRespVO>> getPropertyAndValueList(@Valid ProductPropertyListReqVO listReqVO) {
80 - return success(productPropertyService.getPropertyAndValueList(listReqVO)); 88 + // 查询属性项
  89 + List<ProductPropertyDO> keys = productPropertyService.getPropertyList(listReqVO);
  90 + if (CollUtil.isEmpty(keys)) {
  91 + return success(Collections.emptyList());
  92 + }
  93 + // 查询属性值
  94 + List<ProductPropertyValueDO> values = productPropertyValueService.getPropertyValueListByPropertyId(
  95 + convertSet(keys, ProductPropertyDO::getId));
  96 + return success(ProductPropertyConvert.INSTANCE.convertList(keys, values));
81 } 97 }
82 98
83 } 99 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyAndValueRespVO.java
1 package cn.iocoder.yudao.module.product.controller.admin.property.vo.property; 1 package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
2 2
3 -import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;  
4 import io.swagger.annotations.ApiModel; 3 import io.swagger.annotations.ApiModel;
5 import io.swagger.annotations.ApiModelProperty; 4 import io.swagger.annotations.ApiModelProperty;
6 import lombok.Data; 5 import lombok.Data;
7 import lombok.EqualsAndHashCode; 6 import lombok.EqualsAndHashCode;
8 import lombok.ToString; 7 import lombok.ToString;
9 8
10 -import java.time.LocalDateTime;  
11 import java.util.List; 9 import java.util.List;
12 10
13 @ApiModel("管理后台 - 商品属性项 + 属性值 Response VO") 11 @ApiModel("管理后台 - 商品属性项 + 属性值 Response VO")
@@ -19,12 +17,24 @@ public class ProductPropertyAndValueRespVO extends ProductPropertyBaseVO { @@ -19,12 +17,24 @@ public class ProductPropertyAndValueRespVO extends ProductPropertyBaseVO {
19 @ApiModelProperty(value = "属性项的编号", required = true, example = "1024") 17 @ApiModelProperty(value = "属性项的编号", required = true, example = "1024")
20 private Long id; 18 private Long id;
21 19
22 - @ApiModelProperty(value = "创建时间", required = true)  
23 - private LocalDateTime createTime; 20 + @ApiModelProperty(value = "属性项的名称", required = true, example = "颜色")
  21 + private String name;
24 22
25 /** 23 /**
26 * 属性值的集合 24 * 属性值的集合
27 */ 25 */
28 - private List<ProductPropertyValueRespVO> values; 26 + private List<Value> values;
  27 +
  28 + @ApiModel("管理后台 - 属性值的简单 Response VO")
  29 + @Data
  30 + public static class Value {
  31 +
  32 + @ApiModelProperty(value = "属性值的编号", required = true, example = "2048")
  33 + private Long id;
  34 +
  35 + @ApiModelProperty(value = "属性值的名称", required = true, example = "红色")
  36 + private String name;
  37 +
  38 + }
29 39
30 } 40 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyBaseVO.java
@@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModelProperty; @@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModelProperty;
4 import lombok.Data; 4 import lombok.Data;
5 5
6 import javax.validation.constraints.NotBlank; 6 import javax.validation.constraints.NotBlank;
7 -import javax.validation.constraints.NotNull;  
8 7
9 /** 8 /**
10 * 商品属性项 Base VO,提供给添加、修改、详细的子 VO 使用 9 * 商品属性项 Base VO,提供给添加、修改、详细的子 VO 使用
@@ -20,8 +19,4 @@ public class ProductPropertyBaseVO { @@ -20,8 +19,4 @@ public class ProductPropertyBaseVO {
20 @ApiModelProperty(value = "备注", example = "颜色") 19 @ApiModelProperty(value = "备注", example = "颜色")
21 private String remark; 20 private String remark;
22 21
23 - @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举")  
24 - @NotNull(message = "状态不能为空")  
25 - private Integer status;  
26 -  
27 } 22 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyListReqVO.java
@@ -13,7 +13,4 @@ public class ProductPropertyListReqVO { @@ -13,7 +13,4 @@ public class ProductPropertyListReqVO {
13 @ApiModelProperty(value = "名称", example = "颜色") 13 @ApiModelProperty(value = "名称", example = "颜色")
14 private String name; 14 private String name;
15 15
16 - @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举")  
17 - private Integer status;  
18 -  
19 } 16 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/value/ProductPropertyValueBaseVO.java
@@ -21,10 +21,6 @@ public class ProductPropertyValueBaseVO { @@ -21,10 +21,6 @@ public class ProductPropertyValueBaseVO {
21 @NotEmpty(message = "名称名字不能为空") 21 @NotEmpty(message = "名称名字不能为空")
22 private String name; 22 private String name;
23 23
24 - @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举")  
25 - @NotNull(message = "状态不能为空")  
26 - private Integer status;  
27 -  
28 @ApiModelProperty(value = "备注", example = "颜色") 24 @ApiModelProperty(value = "备注", example = "颜色")
29 private String remark; 25 private String remark;
30 26
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyConvert.java
1 package cn.iocoder.yudao.module.product.convert.property; 1 package cn.iocoder.yudao.module.product.convert.property;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
4 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyAndValueRespVO; 5 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyAndValueRespVO;
5 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO; 6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO;
6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO; 7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO;
7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyUpdateReqVO; 8 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyUpdateReqVO;
8 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; 9 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
  10 +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
9 import org.mapstruct.Mapper; 11 import org.mapstruct.Mapper;
10 import org.mapstruct.factory.Mappers; 12 import org.mapstruct.factory.Mappers;
11 13
12 import java.util.List; 14 import java.util.List;
  15 +import java.util.Map;
13 16
14 /** 17 /**
15 * 属性项 Convert 18 * 属性项 Convert
@@ -25,12 +28,21 @@ public interface ProductPropertyConvert { @@ -25,12 +28,21 @@ public interface ProductPropertyConvert {
25 28
26 ProductPropertyDO convert(ProductPropertyUpdateReqVO bean); 29 ProductPropertyDO convert(ProductPropertyUpdateReqVO bean);
27 30
28 - ProductPropertyAndValueRespVO convert(ProductPropertyRespVO bean);  
29 -  
30 ProductPropertyRespVO convert(ProductPropertyDO bean); 31 ProductPropertyRespVO convert(ProductPropertyDO bean);
31 32
32 List<ProductPropertyRespVO> convertList(List<ProductPropertyDO> list); 33 List<ProductPropertyRespVO> convertList(List<ProductPropertyDO> list);
33 34
34 PageResult<ProductPropertyRespVO> convertPage(PageResult<ProductPropertyDO> page); 35 PageResult<ProductPropertyRespVO> convertPage(PageResult<ProductPropertyDO> page);
35 36
  37 + default List<ProductPropertyAndValueRespVO> convertList(List<ProductPropertyDO> keys, List<ProductPropertyValueDO> values) {
  38 + Map<Long, List<ProductPropertyValueDO>> valueMap = CollectionUtils.convertMultiMap(values, ProductPropertyValueDO::getPropertyId);
  39 + return CollectionUtils.convertList(keys, key -> {
  40 + ProductPropertyAndValueRespVO respVO = convert02(key);
  41 + respVO.setValues(convertList02(valueMap.get(key.getId())));
  42 + return respVO;
  43 + });
  44 + }
  45 + ProductPropertyAndValueRespVO convert02(ProductPropertyDO bean);
  46 + List<ProductPropertyAndValueRespVO.Value> convertList02(List<ProductPropertyValueDO> list);
  47 +
36 } 48 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyDO.java
1 package cn.iocoder.yudao.module.product.dal.dataobject.property; 1 package cn.iocoder.yudao.module.product.dal.dataobject.property;
2 2
3 -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;  
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;
@@ -32,16 +31,8 @@ public class ProductPropertyDO extends BaseDO { @@ -32,16 +31,8 @@ public class ProductPropertyDO extends BaseDO {
32 */ 31 */
33 private String name; 32 private String name;
34 /** 33 /**
35 - * 状态  
36 - *  
37 - * 枚举 {@link CommonStatusEnum}  
38 - */  
39 - private Integer status;  
40 - /**  
41 * 备注 34 * 备注
42 */ 35 */
43 private String remark; 36 private String remark;
44 37
45 - // TODO 芋艿:rule;规格属性 (发布商品时,和 SKU 关联);规格参数(搜索商品时,与 Category 关联搜索)  
46 -  
47 } 38 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyValueDO.java
1 package cn.iocoder.yudao.module.product.dal.dataobject.property; 1 package cn.iocoder.yudao.module.product.dal.dataobject.property;
2 2
3 -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;  
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;
@@ -39,12 +38,6 @@ public class ProductPropertyValueDO extends BaseDO { @@ -39,12 +38,6 @@ public class ProductPropertyValueDO extends BaseDO {
39 */ 38 */
40 private String name; 39 private String name;
41 /** 40 /**
42 - * 状态  
43 - *  
44 - * 枚举 {@link CommonStatusEnum}  
45 - */  
46 - private Integer status;  
47 - /**  
48 * 备注 41 * 备注
49 * 42 *
50 */ 43 */
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyMapper.java
@@ -3,17 +3,19 @@ package cn.iocoder.yudao.module.product.dal.mysql.property; @@ -3,17 +3,19 @@ package cn.iocoder.yudao.module.product.dal.mysql.property;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyListReqVO;
6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyPageReqVO; 7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyPageReqVO;
7 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; 8 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
8 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
9 10
  11 +import java.util.List;
  12 +
10 @Mapper 13 @Mapper
11 public interface ProductPropertyMapper extends BaseMapperX<ProductPropertyDO> { 14 public interface ProductPropertyMapper extends BaseMapperX<ProductPropertyDO> {
12 15
13 default PageResult<ProductPropertyDO> selectPage(ProductPropertyPageReqVO reqVO) { 16 default PageResult<ProductPropertyDO> selectPage(ProductPropertyPageReqVO reqVO) {
14 return selectPage(reqVO, new LambdaQueryWrapperX<ProductPropertyDO>() 17 return selectPage(reqVO, new LambdaQueryWrapperX<ProductPropertyDO>()
15 .likeIfPresent(ProductPropertyDO::getName, reqVO.getName()) 18 .likeIfPresent(ProductPropertyDO::getName, reqVO.getName())
16 - .eqIfPresent(ProductPropertyDO::getStatus, reqVO.getStatus())  
17 .betweenIfPresent(ProductPropertyDO::getCreateTime, reqVO.getCreateTime()) 19 .betweenIfPresent(ProductPropertyDO::getCreateTime, reqVO.getCreateTime())
18 .orderByDesc(ProductPropertyDO::getId)); 20 .orderByDesc(ProductPropertyDO::getId));
19 } 21 }
@@ -23,4 +25,9 @@ public interface ProductPropertyMapper extends BaseMapperX&lt;ProductPropertyDO&gt; { @@ -23,4 +25,9 @@ public interface ProductPropertyMapper extends BaseMapperX&lt;ProductPropertyDO&gt; {
23 .eqIfPresent(ProductPropertyDO::getName, name)); 25 .eqIfPresent(ProductPropertyDO::getName, name));
24 } 26 }
25 27
  28 + default List<ProductPropertyDO> selectList(ProductPropertyListReqVO listReqVO) {
  29 + return selectList(new LambdaQueryWrapperX<ProductPropertyDO>()
  30 + .eqIfPresent(ProductPropertyDO::getName, listReqVO.getName()));
  31 + }
  32 +
26 } 33 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyValueMapper.java
@@ -7,12 +7,13 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc @@ -7,12 +7,13 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc
7 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; 7 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
8 import org.apache.ibatis.annotations.Mapper; 8 import org.apache.ibatis.annotations.Mapper;
9 9
  10 +import java.util.Collection;
10 import java.util.List; 11 import java.util.List;
11 12
12 @Mapper 13 @Mapper
13 public interface ProductPropertyValueMapper extends BaseMapperX<ProductPropertyValueDO> { 14 public interface ProductPropertyValueMapper extends BaseMapperX<ProductPropertyValueDO> {
14 15
15 - default List<ProductPropertyValueDO> selectListByPropertyId(List<Long> propertyIds) { 16 + default List<ProductPropertyValueDO> selectListByPropertyId(Collection<Long> propertyIds) {
16 return selectList(new LambdaQueryWrapperX<ProductPropertyValueDO>() 17 return selectList(new LambdaQueryWrapperX<ProductPropertyValueDO>()
17 .inIfPresent(ProductPropertyValueDO::getPropertyId, propertyIds)); 18 .inIfPresent(ProductPropertyValueDO::getPropertyId, propertyIds));
18 } 19 }
@@ -23,17 +24,20 @@ public interface ProductPropertyValueMapper extends BaseMapperX&lt;ProductPropertyV @@ -23,17 +24,20 @@ public interface ProductPropertyValueMapper extends BaseMapperX&lt;ProductPropertyV
23 .eq(ProductPropertyValueDO::getName, name)); 24 .eq(ProductPropertyValueDO::getName, name));
24 } 25 }
25 26
26 - default void deletePropertyValueByPropertyId(Long propertyId) {  
27 - delete(new LambdaQueryWrapperX<ProductPropertyValueDO>().eq(ProductPropertyValueDO::getPropertyId, propertyId)  
28 - .eq(ProductPropertyValueDO::getDeleted, false)); 27 + default void deleteByPropertyId(Long propertyId) {
  28 + delete(new LambdaQueryWrapperX<ProductPropertyValueDO>()
  29 + .eq(ProductPropertyValueDO::getPropertyId, propertyId));
29 } 30 }
30 31
31 default PageResult<ProductPropertyValueDO> selectPage(ProductPropertyValuePageReqVO reqVO) { 32 default PageResult<ProductPropertyValueDO> selectPage(ProductPropertyValuePageReqVO reqVO) {
32 return selectPage(reqVO, new LambdaQueryWrapperX<ProductPropertyValueDO>() 33 return selectPage(reqVO, new LambdaQueryWrapperX<ProductPropertyValueDO>()
33 .eqIfPresent(ProductPropertyValueDO::getPropertyId, reqVO.getPropertyId()) 34 .eqIfPresent(ProductPropertyValueDO::getPropertyId, reqVO.getPropertyId())
34 .likeIfPresent(ProductPropertyValueDO::getName, reqVO.getName()) 35 .likeIfPresent(ProductPropertyValueDO::getName, reqVO.getName())
35 - .eqIfPresent(ProductPropertyValueDO::getStatus, reqVO.getStatus())  
36 .orderByDesc(ProductPropertyValueDO::getId)); 36 .orderByDesc(ProductPropertyValueDO::getId));
37 } 37 }
38 38
  39 + default Integer selectCountByPropertyId(Long propertyId) {
  40 + return selectCount(ProductPropertyValueDO::getPropertyId, propertyId).intValue();
  41 + }
  42 +
39 } 43 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java
@@ -42,7 +42,7 @@ public interface ProductPropertyService { @@ -42,7 +42,7 @@ public interface ProductPropertyService {
42 * @param listReqVO 集合查询 42 * @param listReqVO 集合查询
43 * @return 属性项集合 43 * @return 属性项集合
44 */ 44 */
45 - List<ProductPropertyRespVO> getPropertyVOList(ProductPropertyListReqVO listReqVO); 45 + List<ProductPropertyDO> getPropertyList(ProductPropertyListReqVO listReqVO);
46 46
47 /** 47 /**
48 * 获取属性名称分页 48 * 获取属性名称分页
@@ -50,7 +50,7 @@ public interface ProductPropertyService { @@ -50,7 +50,7 @@ public interface ProductPropertyService {
50 * @param pageReqVO 分页条件 50 * @param pageReqVO 分页条件
51 * @return 属性项分页 51 * @return 属性项分页
52 */ 52 */
53 - PageResult<ProductPropertyRespVO> getPropertyPage(ProductPropertyPageReqVO pageReqVO); 53 + PageResult<ProductPropertyDO> getPropertyPage(ProductPropertyPageReqVO pageReqVO);
54 54
55 /** 55 /**
56 * 获得指定编号的属性项 56 * 获得指定编号的属性项
@@ -58,7 +58,7 @@ public interface ProductPropertyService { @@ -58,7 +58,7 @@ public interface ProductPropertyService {
58 * @param id 编号 58 * @param id 编号
59 * @return 属性项 59 * @return 属性项
60 */ 60 */
61 - ProductPropertyRespVO getProperty(Long id); 61 + ProductPropertyDO getProperty(Long id);
62 62
63 /** 63 /**
64 * 根据属性项的编号的集合,获得对应的属性项数组 64 * 根据属性项的编号的集合,获得对应的属性项数组
@@ -68,20 +68,4 @@ public interface ProductPropertyService { @@ -68,20 +68,4 @@ public interface ProductPropertyService {
68 */ 68 */
69 List<ProductPropertyDO> getPropertyList(Collection<Long> ids); 69 List<ProductPropertyDO> getPropertyList(Collection<Long> ids);
70 70
71 - /**  
72 - * 根据属性项的编号的集合,获得对应的属性项数组  
73 - *  
74 - * @param ids 属性项的编号的集合  
75 - * @return 属性项数组  
76 - */  
77 - List<ProductPropertyRespVO> getPropertyVOList(Collection<Long> ids);  
78 -  
79 - /**  
80 - * 获得属性项 + 值的列表  
81 - *  
82 - * @param listReqVO 列表查询  
83 - * @return 属性项 + 值的列表  
84 - */  
85 - List<ProductPropertyAndValueRespVO> getPropertyAndValueList(ProductPropertyListReqVO listReqVO);  
86 -  
87 } 71 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java
1 package cn.iocoder.yudao.module.product.service.property; 1 package cn.iocoder.yudao.module.product.service.property;
2 2
  3 +import cn.hutool.core.util.ObjUtil;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;  
5 -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;  
6 -import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.*; 5 +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO;
  6 +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyListReqVO;
  7 +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyPageReqVO;
  8 +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyUpdateReqVO;
7 import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert; 9 import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert;
8 -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert;  
9 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; 10 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
10 -import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;  
11 import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper; 11 import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper;
12 -import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper; 12 +import org.springframework.context.annotation.Lazy;
13 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
14 import org.springframework.transaction.annotation.Transactional; 14 import org.springframework.transaction.annotation.Transactional;
15 import org.springframework.validation.annotation.Validated; 15 import org.springframework.validation.annotation.Validated;
@@ -17,11 +17,9 @@ import org.springframework.validation.annotation.Validated; @@ -17,11 +17,9 @@ import org.springframework.validation.annotation.Validated;
17 import javax.annotation.Resource; 17 import javax.annotation.Resource;
18 import java.util.Collection; 18 import java.util.Collection;
19 import java.util.List; 19 import java.util.List;
20 -import java.util.Map;  
21 20
22 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 21 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
23 -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_EXISTS;  
24 -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_NOT_EXISTS; 22 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
25 23
26 /** 24 /**
27 * 商品属性项 Service 实现类 25 * 商品属性项 Service 实现类
@@ -36,15 +34,17 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { @@ -36,15 +34,17 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
36 private ProductPropertyMapper productPropertyMapper; 34 private ProductPropertyMapper productPropertyMapper;
37 35
38 @Resource 36 @Resource
39 - private ProductPropertyValueMapper productPropertyValueMapper; 37 + @Lazy // 延迟加载,解决循环依赖问题
  38 + private ProductPropertyValueService productPropertyValueService;
40 39
41 @Override 40 @Override
42 @Transactional(rollbackFor = Exception.class) 41 @Transactional(rollbackFor = Exception.class)
43 public Long createProperty(ProductPropertyCreateReqVO createReqVO) { 42 public Long createProperty(ProductPropertyCreateReqVO createReqVO) {
44 - // 校验存在 43 + // 校验名字重复
45 if (productPropertyMapper.selectByName(createReqVO.getName()) != null) { 44 if (productPropertyMapper.selectByName(createReqVO.getName()) != null) {
46 throw exception(PROPERTY_EXISTS); 45 throw exception(PROPERTY_EXISTS);
47 } 46 }
  47 +
48 // 插入 48 // 插入
49 ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO); 49 ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO);
50 productPropertyMapper.insert(property); 50 productPropertyMapper.insert(property);
@@ -55,12 +55,14 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { @@ -55,12 +55,14 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
55 @Override 55 @Override
56 @Transactional(rollbackFor = Exception.class) 56 @Transactional(rollbackFor = Exception.class)
57 public void updateProperty(ProductPropertyUpdateReqVO updateReqVO) { 57 public void updateProperty(ProductPropertyUpdateReqVO updateReqVO) {
58 - // 校验存在  
59 validatePropertyExists(updateReqVO.getId()); 58 validatePropertyExists(updateReqVO.getId());
  59 + // 校验名字重复
60 ProductPropertyDO productPropertyDO = productPropertyMapper.selectByName(updateReqVO.getName()); 60 ProductPropertyDO productPropertyDO = productPropertyMapper.selectByName(updateReqVO.getName());
61 - if (productPropertyDO != null && !productPropertyDO.getId().equals(updateReqVO.getId())) { 61 + if (productPropertyDO != null &&
  62 + ObjUtil.notEqual(productPropertyDO.getId(), updateReqVO.getId())) {
62 throw exception(PROPERTY_EXISTS); 63 throw exception(PROPERTY_EXISTS);
63 } 64 }
  65 +
64 // 更新 66 // 更新
65 ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO); 67 ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO);
66 productPropertyMapper.updateById(updateObj); 68 productPropertyMapper.updateById(updateObj);
@@ -70,10 +72,15 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { @@ -70,10 +72,15 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
70 public void deleteProperty(Long id) { 72 public void deleteProperty(Long id) {
71 // 校验存在 73 // 校验存在
72 validatePropertyExists(id); 74 validatePropertyExists(id);
  75 + // 校验其下是否有规格值
  76 + if (productPropertyValueService.getPropertyValueCountByPropertyId(id) > 0) {
  77 + throw exception(PROPERTY_DELETE_FAIL_VALUE_EXISTS);
  78 + }
  79 +
73 // 删除 80 // 删除
74 productPropertyMapper.deleteById(id); 81 productPropertyMapper.deleteById(id);
75 // 同步删除属性值 82 // 同步删除属性值
76 - productPropertyValueMapper.deletePropertyValueByPropertyId(id); 83 + productPropertyValueService.deletePropertyValueByPropertyId(id);
77 } 84 }
78 85
79 private void validatePropertyExists(Long id) { 86 private void validatePropertyExists(Long id) {
@@ -83,22 +90,18 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { @@ -83,22 +90,18 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
83 } 90 }
84 91
85 @Override 92 @Override
86 - public List<ProductPropertyRespVO> getPropertyVOList(ProductPropertyListReqVO listReqVO) {  
87 - return ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectList(new LambdaQueryWrapperX<ProductPropertyDO>()  
88 - .likeIfPresent(ProductPropertyDO::getName, listReqVO.getName())  
89 - .eqIfPresent(ProductPropertyDO::getStatus, listReqVO.getStatus()))); 93 + public List<ProductPropertyDO> getPropertyList(ProductPropertyListReqVO listReqVO) {
  94 + return productPropertyMapper.selectList(listReqVO);
90 } 95 }
91 96
92 @Override 97 @Override
93 - public PageResult<ProductPropertyRespVO> getPropertyPage(ProductPropertyPageReqVO pageReqVO) {  
94 - PageResult<ProductPropertyDO> pageResult = productPropertyMapper.selectPage(pageReqVO);  
95 - return ProductPropertyConvert.INSTANCE.convertPage(pageResult); 98 + public PageResult<ProductPropertyDO> getPropertyPage(ProductPropertyPageReqVO pageReqVO) {
  99 + return productPropertyMapper.selectPage(pageReqVO);
96 } 100 }
97 101
98 @Override 102 @Override
99 - public ProductPropertyRespVO getProperty(Long id) {  
100 - ProductPropertyDO property = productPropertyMapper.selectById(id);  
101 - return ProductPropertyConvert.INSTANCE.convert(property); 103 + public ProductPropertyDO getProperty(Long id) {
  104 + return productPropertyMapper.selectById(id);
102 } 105 }
103 106
104 @Override 107 @Override
@@ -106,24 +109,4 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { @@ -106,24 +109,4 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
106 return productPropertyMapper.selectBatchIds(ids); 109 return productPropertyMapper.selectBatchIds(ids);
107 } 110 }
108 111
109 - // TODO @芋艿:丢到 Controller  
110 - @Override  
111 - public List<ProductPropertyRespVO> getPropertyVOList(Collection<Long> ids) {  
112 - return ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectBatchIds(ids));  
113 - }  
114 -  
115 - // TODO @芋艿:丢到 Controller  
116 - @Override  
117 - public List<ProductPropertyAndValueRespVO> getPropertyAndValueList(ProductPropertyListReqVO listReqVO) {  
118 - List<ProductPropertyRespVO> propertyList = getPropertyVOList(listReqVO);  
119 -  
120 - // 查询属性值  
121 - List<ProductPropertyValueDO> valueDOList = productPropertyValueMapper.selectListByPropertyId(CollectionUtils.convertList(propertyList, ProductPropertyRespVO::getId));  
122 - Map<Long, List<ProductPropertyValueDO>> valueDOMap = CollectionUtils.convertMultiMap(valueDOList, ProductPropertyValueDO::getPropertyId);  
123 - return CollectionUtils.convertList(propertyList, m -> {  
124 - ProductPropertyAndValueRespVO productPropertyAndValueRespVO = ProductPropertyConvert.INSTANCE.convert(m);  
125 - productPropertyAndValueRespVO.setValues(ProductPropertyValueConvert.INSTANCE.convertList(valueDOMap.get(m.getId())));  
126 - return productPropertyAndValueRespVO;  
127 - });  
128 - }  
129 } 112 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueService.java
@@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc
5 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO; 5 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; 6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;
7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; 7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
  8 +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
8 import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; 9 import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
9 10
10 import java.util.Collection; 11 import java.util.Collection;
@@ -48,6 +49,14 @@ public interface ProductPropertyValueService { @@ -48,6 +49,14 @@ public interface ProductPropertyValueService {
48 ProductPropertyValueRespVO getPropertyValue(Long id); 49 ProductPropertyValueRespVO getPropertyValue(Long id);
49 50
50 /** 51 /**
  52 + * 根据属性项编号数组,获得属性值列表
  53 + *
  54 + * @param propertyIds 属性项目编号数组
  55 + * @return 属性值列表
  56 + */
  57 + List<ProductPropertyValueDO> getPropertyValueListByPropertyId(Collection<Long> propertyIds);
  58 +
  59 + /**
51 * 根据编号数组,获得属性值列表 60 * 根据编号数组,获得属性值列表
52 * 61 *
53 * @param ids 编号数组 62 * @param ids 编号数组
@@ -56,12 +65,20 @@ public interface ProductPropertyValueService { @@ -56,12 +65,20 @@ public interface ProductPropertyValueService {
56 List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids); 65 List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids);
57 66
58 /** 67 /**
59 - * 获得属性值 68 + * 根据属性项编号,获得属性值数组
60 * 69 *
61 - * @param id 编号 70 + * @param propertyIds 属性项编号数组
62 * @return 属性值 71 * @return 属性值
63 */ 72 */
64 - List<ProductPropertyValueRespVO> getPropertyValueListByPropertyId(List<Long> id); 73 + List<ProductPropertyValueRespVO> getPropertyValueListByPropertyId(List<Long> propertyIds);
  74 +
  75 + /**
  76 + * 根据属性项编号,活的属性值数量
  77 + *
  78 + * @param propertyId 属性项编号数
  79 + * @return 属性值数量
  80 + */
  81 + Integer getPropertyValueCountByPropertyId(Long propertyId);
65 82
66 /** 83 /**
67 * 获取属性值的分页 84 * 获取属性值的分页
@@ -70,4 +87,12 @@ public interface ProductPropertyValueService { @@ -70,4 +87,12 @@ public interface ProductPropertyValueService {
70 * @return 属性值的分页 87 * @return 属性值的分页
71 */ 88 */
72 PageResult<ProductPropertyValueRespVO> getPropertyValueListPage(ProductPropertyValuePageReqVO pageReqVO); 89 PageResult<ProductPropertyValueRespVO> getPropertyValueListPage(ProductPropertyValuePageReqVO pageReqVO);
  90 +
  91 + /**
  92 + * 删除指定属性项编号下的属性值们
  93 + *
  94 + * @param propertyId 属性项的编号
  95 + */
  96 + void deletePropertyValueByPropertyId(Long propertyId);
  97 +
73 } 98 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java
@@ -74,6 +74,11 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ @@ -74,6 +74,11 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
74 } 74 }
75 75
76 @Override 76 @Override
  77 + public List<ProductPropertyValueDO> getPropertyValueListByPropertyId(Collection<Long> propertyIds) {
  78 + return productPropertyValueMapper.selectListByPropertyId(propertyIds);
  79 + }
  80 +
  81 + @Override
77 public List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids) { 82 public List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids) {
78 // 获得属性值列表 83 // 获得属性值列表
79 if (CollUtil.isEmpty(ids)) { 84 if (CollUtil.isEmpty(ids)) {
@@ -91,12 +96,23 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ @@ -91,12 +96,23 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
91 } 96 }
92 97
93 @Override 98 @Override
94 - public List<ProductPropertyValueRespVO> getPropertyValueListByPropertyId(List<Long> id) {  
95 - return ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueMapper.selectList("property_id", id)); 99 + public List<ProductPropertyValueRespVO> getPropertyValueListByPropertyId(List<Long> propertyIds) {
  100 + return ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueMapper.selectList("property_id", propertyIds));
  101 + }
  102 +
  103 + @Override
  104 + public Integer getPropertyValueCountByPropertyId(Long propertyId) {
  105 + return productPropertyValueMapper.selectCountByPropertyId(propertyId);
96 } 106 }
97 107
98 @Override 108 @Override
99 public PageResult<ProductPropertyValueRespVO> getPropertyValueListPage(ProductPropertyValuePageReqVO pageReqVO) { 109 public PageResult<ProductPropertyValueRespVO> getPropertyValueListPage(ProductPropertyValuePageReqVO pageReqVO) {
100 return ProductPropertyValueConvert.INSTANCE.convertPage(productPropertyValueMapper.selectPage(pageReqVO)); 110 return ProductPropertyValueConvert.INSTANCE.convertPage(productPropertyValueMapper.selectPage(pageReqVO));
101 } 111 }
  112 +
  113 + @Override
  114 + public void deletePropertyValueByPropertyId(Long propertyId) {
  115 + productPropertyValueMapper.deleteByPropertyId(propertyId);
  116 + }
  117 +
102 } 118 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
@@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.product.service.sku; @@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.product.service.sku;
3 import cn.hutool.core.util.ObjectUtil; 3 import cn.hutool.core.util.ObjectUtil;
4 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 4 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
5 import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; 5 import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
6 -import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO;  
7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; 6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;
8 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; 7 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
9 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; 8 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
10 import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; 9 import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
  10 +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
11 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; 11 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
12 import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper; 12 import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper;
13 import cn.iocoder.yudao.module.product.enums.ErrorCodeConstants; 13 import cn.iocoder.yudao.module.product.enums.ErrorCodeConstants;
@@ -89,7 +89,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { @@ -89,7 +89,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
89 .flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性 89 .flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性
90 .map(ProductSkuBaseVO.Property::getPropertyId) // 将每个 Property 转换成对应的 propertyId,最后形成集合 90 .map(ProductSkuBaseVO.Property::getPropertyId) // 将每个 Property 转换成对应的 propertyId,最后形成集合
91 .collect(Collectors.toSet()); 91 .collect(Collectors.toSet());
92 - List<ProductPropertyRespVO> propertyList = productPropertyService.getPropertyVOList(propertyIds); 92 + List<ProductPropertyDO> propertyList = productPropertyService.getPropertyList(propertyIds);
93 if (propertyList.size() != propertyIds.size()) { 93 if (propertyList.size() != propertyIds.size()) {
94 throw exception(PROPERTY_NOT_EXISTS); 94 throw exception(PROPERTY_NOT_EXISTS);
95 } 95 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
@@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollUtil; @@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollUtil;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 6 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyViewRespVO; 7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyViewRespVO;
8 -import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO;  
9 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; 8 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;
10 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; 9 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
11 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; 10 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
@@ -15,6 +14,7 @@ import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO; @@ -15,6 +14,7 @@ import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
15 import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO; 14 import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
16 import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; 15 import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
17 import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; 16 import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
  17 +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
18 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; 18 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
19 import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; 19 import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
20 import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; 20 import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
@@ -142,7 +142,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { @@ -142,7 +142,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
142 Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId)); 142 Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId));
143 143
144 List<ProductPropertyValueRespVO> propertyValueList = productPropertyValueService.getPropertyValueListByPropertyId(new ArrayList<>(propertyMaps.keySet())); 144 List<ProductPropertyValueRespVO> propertyValueList = productPropertyValueService.getPropertyValueListByPropertyId(new ArrayList<>(propertyMaps.keySet()));
145 - List<ProductPropertyRespVO> propertyList = productPropertyService.getPropertyVOList(new ArrayList<>(propertyMaps.keySet())); 145 + List<ProductPropertyDO> propertyList = productPropertyService.getPropertyList(propertyMaps.keySet());
146 // 装载组装过后的属性 146 // 装载组装过后的属性
147 List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>(); 147 List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>();
148 propertyList.forEach(p -> { 148 propertyList.forEach(p -> {
yudao-ui-admin/src/api/mall/product/property.js
@@ -57,7 +57,7 @@ export function getPropertyList(query) { @@ -57,7 +57,7 @@ export function getPropertyList(query) {
57 // 获得属性项列表 57 // 获得属性项列表
58 export function getPropertyListAndValue(query) { 58 export function getPropertyListAndValue(query) {
59 return request({ 59 return request({
60 - url: '/product/property/listAndValue', 60 + url: '/product/property/get-value-list',
61 method: 'get', 61 method: 'get',
62 params: query 62 params: query
63 }) 63 })
yudao-ui-admin/src/views/mall/product/property/index.vue
@@ -41,11 +41,6 @@ @@ -41,11 +41,6 @@
41 </router-link> 41 </router-link>
42 </template> 42 </template>
43 </el-table-column> 43 </el-table-column>
44 - <el-table-column label="开启状态" align="center" prop="status">  
45 - <template slot-scope="scope">  
46 - <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>  
47 - </template>  
48 - </el-table-column>  
49 <el-table-column label="创建时间" align="center" prop="createTime" width="180"> 44 <el-table-column label="创建时间" align="center" prop="createTime" width="180">
50 <template slot-scope="scope"> 45 <template slot-scope="scope">
51 <span>{{ parseTime(scope.row.createTime) }}</span> 46 <span>{{ parseTime(scope.row.createTime) }}</span>
@@ -74,13 +69,6 @@ @@ -74,13 +69,6 @@
74 <el-form-item label="名称" prop="name"> 69 <el-form-item label="名称" prop="name">
75 <el-input v-model="form.name" placeholder="请输入名称" /> 70 <el-input v-model="form.name" placeholder="请输入名称" />
76 </el-form-item> 71 </el-form-item>
77 - <el-form-item label="状态" prop="status">  
78 - <el-radio-group v-model="form.status">  
79 - <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"  
80 - :key="dict.value" :label="parseInt(dict.value)">{{ dict.label }}  
81 - </el-radio>  
82 - </el-radio-group>  
83 - </el-form-item>  
84 <el-form-item label="备注" prop="remark"> 72 <el-form-item label="备注" prop="remark">
85 <el-input v-model="form.remark" placeholder="备注" /> 73 <el-input v-model="form.remark" placeholder="备注" />
86 </el-form-item> 74 </el-form-item>
@@ -121,7 +109,6 @@ export default { @@ -121,7 +109,6 @@ export default {
121 pageNo: 1, 109 pageNo: 1,
122 pageSize: 10, 110 pageSize: 10,
123 name: null, 111 name: null,
124 - status: null,  
125 createTime: [] 112 createTime: []
126 }, 113 },
127 // 表单参数 114 // 表单参数
@@ -135,9 +122,6 @@ export default { @@ -135,9 +122,6 @@ export default {
135 rules: { 122 rules: {
136 name: [ 123 name: [
137 { required: true, message: "名称不能为空", trigger: "blur" } 124 { required: true, message: "名称不能为空", trigger: "blur" }
138 - ],  
139 - status: [  
140 - { required: true, message: "状态不能为空", trigger: "blur" }  
141 ] 125 ]
142 } 126 }
143 }; 127 };
@@ -165,7 +149,6 @@ export default { @@ -165,7 +149,6 @@ export default {
165 reset() { 149 reset() {
166 this.form = { 150 this.form = {
167 name:'', 151 name:'',
168 - status:'',  
169 remark:"", 152 remark:"",
170 id: null, 153 id: null,
171 }; 154 };
@@ -230,21 +213,6 @@ export default { @@ -230,21 +213,6 @@ export default {
230 this.$modal.msgSuccess("删除成功"); 213 this.$modal.msgSuccess("删除成功");
231 }).catch(() => {}); 214 }).catch(() => {});
232 }, 215 },
233 - /** 导出按钮操作 */  
234 - handleExport() {  
235 - // 处理查询参数  
236 - let params = {...this.queryParams};  
237 - params.pageNo = undefined;  
238 - params.pageSize = undefined;  
239 - // 执行导出  
240 - this.$modal.confirm('是否确认导出所有名称数据项?').then(() => {  
241 - this.exportLoading = true;  
242 - return exportPropertyExcel(params);  
243 - }).then(response => {  
244 - this.$download.excel(response, '名称.xls');  
245 - this.exportLoading = false;  
246 - }).catch(() => {});  
247 - },  
248 } 216 }
249 }; 217 };
250 </script> 218 </script>