Commit 4a2cb33cd7d295b6d98bcb3ab0335793a70ef4fd

Authored by YunaiV
1 parent 98ca807d

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

yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc
6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO; 6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; 7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;
8 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; 8 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
  9 +import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert;
9 import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; 10 import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
10 import io.swagger.annotations.Api; 11 import io.swagger.annotations.Api;
11 import io.swagger.annotations.ApiImplicitParam; 12 import io.swagger.annotations.ApiImplicitParam;
@@ -57,13 +58,13 @@ public class ProductPropertyValueController { @@ -57,13 +58,13 @@ public class ProductPropertyValueController {
57 @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) 58 @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
58 @PreAuthorize("@ss.hasPermission('product:property:query')") 59 @PreAuthorize("@ss.hasPermission('product:property:query')")
59 public CommonResult<ProductPropertyValueRespVO> getProperty(@RequestParam("id") Long id) { 60 public CommonResult<ProductPropertyValueRespVO> getProperty(@RequestParam("id") Long id) {
60 - return success(productPropertyValueService.getPropertyValue(id)); 61 + return success(ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueService.getPropertyValue(id)));
61 } 62 }
62 63
63 @GetMapping("/page") 64 @GetMapping("/page")
64 @ApiOperation("获得属性值分页") 65 @ApiOperation("获得属性值分页")
65 @PreAuthorize("@ss.hasPermission('product:property:query')") 66 @PreAuthorize("@ss.hasPermission('product:property:query')")
66 public CommonResult<PageResult<ProductPropertyValueRespVO>> getPropertyValuePage(@Valid ProductPropertyValuePageReqVO pageVO) { 67 public CommonResult<PageResult<ProductPropertyValueRespVO>> getPropertyValuePage(@Valid ProductPropertyValuePageReqVO pageVO) {
67 - return success(productPropertyValueService.getPropertyValueListPage(pageVO)); 68 + return success(ProductPropertyValueConvert.INSTANCE.convertPage(productPropertyValueService.getPropertyValuePage(pageVO)));
68 } 69 }
69 } 70 }
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyAndValueRespVO.java
@@ -3,16 +3,12 @@ package cn.iocoder.yudao.module.product.controller.admin.property.vo.property; @@ -3,16 +3,12 @@ package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
3 import io.swagger.annotations.ApiModel; 3 import io.swagger.annotations.ApiModel;
4 import io.swagger.annotations.ApiModelProperty; 4 import io.swagger.annotations.ApiModelProperty;
5 import lombok.Data; 5 import lombok.Data;
6 -import lombok.EqualsAndHashCode;  
7 -import lombok.ToString;  
8 6
9 import java.util.List; 7 import java.util.List;
10 8
11 @ApiModel("管理后台 - 商品属性项 + 属性值 Response VO") 9 @ApiModel("管理后台 - 商品属性项 + 属性值 Response VO")
12 @Data 10 @Data
13 -@EqualsAndHashCode(callSuper = true)  
14 -@ToString(callSuper = true)  
15 -public class ProductPropertyAndValueRespVO extends ProductPropertyBaseVO { 11 +public class ProductPropertyAndValueRespVO {
16 12
17 @ApiModelProperty(value = "属性项的编号", required = true, example = "1024") 13 @ApiModelProperty(value = "属性项的编号", required = true, example = "1024")
18 private Long id; 14 private Long id;
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueService.java
@@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.product.service.property; @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.product.service.property;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO; 4 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
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;  
7 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; 6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
8 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; 7 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
9 import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; 8 import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
@@ -46,7 +45,7 @@ public interface ProductPropertyValueService { @@ -46,7 +45,7 @@ public interface ProductPropertyValueService {
46 * @param id 编号 45 * @param id 编号
47 * @return 属性值 46 * @return 属性值
48 */ 47 */
49 - ProductPropertyValueRespVO getPropertyValue(Long id); 48 + ProductPropertyValueDO getPropertyValue(Long id);
50 49
51 /** 50 /**
52 * 根据属性项编号数组,获得属性值列表 51 * 根据属性项编号数组,获得属性值列表
@@ -65,14 +64,6 @@ public interface ProductPropertyValueService { @@ -65,14 +64,6 @@ public interface ProductPropertyValueService {
65 List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids); 64 List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids);
66 65
67 /** 66 /**
68 - * 根据属性项编号,获得属性值数组  
69 - *  
70 - * @param propertyIds 属性项编号数组  
71 - * @return 属性值  
72 - */  
73 - List<ProductPropertyValueRespVO> getPropertyValueListByPropertyId(List<Long> propertyIds);  
74 -  
75 - /**  
76 * 根据属性项编号,活的属性值数量 67 * 根据属性项编号,活的属性值数量
77 * 68 *
78 * @param propertyId 属性项编号数 69 * @param propertyId 属性项编号数
@@ -86,7 +77,7 @@ public interface ProductPropertyValueService { @@ -86,7 +77,7 @@ public interface ProductPropertyValueService {
86 * @param pageReqVO 查询条件 77 * @param pageReqVO 查询条件
87 * @return 属性值的分页 78 * @return 属性值的分页
88 */ 79 */
89 - PageResult<ProductPropertyValueRespVO> getPropertyValueListPage(ProductPropertyValuePageReqVO pageReqVO); 80 + PageResult<ProductPropertyValueDO> getPropertyValuePage(ProductPropertyValuePageReqVO pageReqVO);
90 81
91 /** 82 /**
92 * 删除指定属性项编号下的属性值们 83 * 删除指定属性项编号下的属性值们
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java
@@ -4,14 +4,12 @@ import cn.hutool.core.collection.CollUtil; @@ -4,14 +4,12 @@ import cn.hutool.core.collection.CollUtil;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO; 5 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO; 6 import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
7 -import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;  
8 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;
9 import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; 8 import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert;
10 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; 9 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
11 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; 10 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
12 import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper; 11 import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper;
13 import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO; 12 import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
14 -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;  
15 import org.springframework.context.annotation.Lazy; 13 import org.springframework.context.annotation.Lazy;
16 import org.springframework.stereotype.Service; 14 import org.springframework.stereotype.Service;
17 import org.springframework.validation.annotation.Validated; 15 import org.springframework.validation.annotation.Validated;
@@ -24,6 +22,7 @@ import java.util.List; @@ -24,6 +22,7 @@ import java.util.List;
24 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 22 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
25 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; 23 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
26 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_EXISTS; 24 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_EXISTS;
  25 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_NOT_EXISTS;
27 26
28 /** 27 /**
29 * 商品属性值 Service 实现类 28 * 商品属性值 Service 实现类
@@ -43,34 +42,47 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ @@ -43,34 +42,47 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
43 42
44 @Override 43 @Override
45 public Long createPropertyValue(ProductPropertyValueCreateReqVO createReqVO) { 44 public Long createPropertyValue(ProductPropertyValueCreateReqVO createReqVO) {
  45 + // 校验名字唯一
46 if (productPropertyValueMapper.selectByName(createReqVO.getPropertyId(), createReqVO.getName()) != null) { 46 if (productPropertyValueMapper.selectByName(createReqVO.getPropertyId(), createReqVO.getName()) != null) {
47 throw exception(PROPERTY_VALUE_EXISTS); 47 throw exception(PROPERTY_VALUE_EXISTS);
48 } 48 }
49 - ProductPropertyValueDO convert = ProductPropertyValueConvert.INSTANCE.convert(createReqVO);  
50 - productPropertyValueMapper.insert(convert);  
51 - return convert.getId(); 49 +
  50 + // 新增
  51 + ProductPropertyValueDO value = ProductPropertyValueConvert.INSTANCE.convert(createReqVO);
  52 + productPropertyValueMapper.insert(value);
  53 + return value.getId();
52 } 54 }
53 55
54 @Override 56 @Override
55 public void updatePropertyValue(ProductPropertyValueUpdateReqVO updateReqVO) { 57 public void updatePropertyValue(ProductPropertyValueUpdateReqVO updateReqVO) {
56 - ProductPropertyValueDO productPropertyValueDO = productPropertyValueMapper.selectByName(updateReqVO.getPropertyId(), updateReqVO.getName()); 58 + validatePropertyValueExists(updateReqVO.getId());
  59 + // 校验名字唯一
  60 + ProductPropertyValueDO productPropertyValueDO = productPropertyValueMapper.selectByName
  61 + (updateReqVO.getPropertyId(), updateReqVO.getName());
57 if (productPropertyValueDO != null && !productPropertyValueDO.getId().equals(updateReqVO.getId())) { 62 if (productPropertyValueDO != null && !productPropertyValueDO.getId().equals(updateReqVO.getId())) {
58 throw exception(PROPERTY_VALUE_EXISTS); 63 throw exception(PROPERTY_VALUE_EXISTS);
59 } 64 }
60 - ProductPropertyValueDO convert = ProductPropertyValueConvert.INSTANCE.convert(updateReqVO);  
61 - productPropertyValueMapper.updateById(convert); 65 +
  66 + // 更新
  67 + ProductPropertyValueDO updateObj = ProductPropertyValueConvert.INSTANCE.convert(updateReqVO);
  68 + productPropertyValueMapper.updateById(updateObj);
62 } 69 }
63 70
64 @Override 71 @Override
65 public void deletePropertyValue(Long id) { 72 public void deletePropertyValue(Long id) {
  73 + validatePropertyValueExists(id);
66 productPropertyValueMapper.deleteById(id); 74 productPropertyValueMapper.deleteById(id);
67 } 75 }
68 76
  77 + private void validatePropertyValueExists(Long id) {
  78 + if (productPropertyValueMapper.selectById(id) == null) {
  79 + throw exception(PROPERTY_VALUE_NOT_EXISTS);
  80 + }
  81 + }
  82 +
69 @Override 83 @Override
70 - public ProductPropertyValueRespVO getPropertyValue(Long id) {  
71 - ProductPropertyValueDO productPropertyValueDO = productPropertyValueMapper.selectOne(new LambdaQueryWrapper<ProductPropertyValueDO>()  
72 - .eq(ProductPropertyValueDO::getId, id));  
73 - return ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueDO); 84 + public ProductPropertyValueDO getPropertyValue(Long id) {
  85 + return productPropertyValueMapper.selectById(id);
74 } 86 }
75 87
76 @Override 88 @Override
@@ -96,18 +108,13 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ @@ -96,18 +108,13 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
96 } 108 }
97 109
98 @Override 110 @Override
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) { 111 public Integer getPropertyValueCountByPropertyId(Long propertyId) {
105 return productPropertyValueMapper.selectCountByPropertyId(propertyId); 112 return productPropertyValueMapper.selectCountByPropertyId(propertyId);
106 } 113 }
107 114
108 @Override 115 @Override
109 - public PageResult<ProductPropertyValueRespVO> getPropertyValueListPage(ProductPropertyValuePageReqVO pageReqVO) {  
110 - return ProductPropertyValueConvert.INSTANCE.convertPage(productPropertyValueMapper.selectPage(pageReqVO)); 116 + public PageResult<ProductPropertyValueDO> getPropertyValuePage(ProductPropertyValuePageReqVO pageReqVO) {
  117 + return productPropertyValueMapper.selectPage(pageReqVO);
111 } 118 }
112 119
113 @Override 120 @Override
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
1 package cn.iocoder.yudao.module.product.service.sku; 1 package cn.iocoder.yudao.module.product.service.sku;
2 2
3 import cn.hutool.core.util.ObjectUtil; 3 import cn.hutool.core.util.ObjectUtil;
4 -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;  
5 import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; 4 import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
6 -import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;  
7 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; 5 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
8 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; 6 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
9 import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; 7 import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
10 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; 8 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
  9 +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
11 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; 10 import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
12 import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper; 11 import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper;
13 import cn.iocoder.yudao.module.product.enums.ErrorCodeConstants; 12 import cn.iocoder.yudao.module.product.enums.ErrorCodeConstants;
@@ -25,6 +24,7 @@ import java.util.*; @@ -25,6 +24,7 @@ import java.util.*;
25 import java.util.stream.Collectors; 24 import java.util.stream.Collectors;
26 25
27 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 26 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  27 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
28 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; 28 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
29 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; 29 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
30 30
@@ -95,7 +95,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { @@ -95,7 +95,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
95 } 95 }
96 96
97 // 2. 校验,一个 SKU 下,没有重复的属性。校验方式是,遍历每个 SKU ,看看是否有重复的属性 propertyId 97 // 2. 校验,一个 SKU 下,没有重复的属性。校验方式是,遍历每个 SKU ,看看是否有重复的属性 propertyId
98 - Map<Long, ProductPropertyValueRespVO> propertyValueMap = CollectionUtils.convertMap(productPropertyValueService.getPropertyValueListByPropertyId(new ArrayList<>(propertyIds)), ProductPropertyValueRespVO::getId); 98 + Map<Long, ProductPropertyValueDO> propertyValueMap = convertMap(productPropertyValueService.getPropertyValueListByPropertyId(propertyIds), ProductPropertyValueDO::getId);
99 skus.forEach(sku -> { 99 skus.forEach(sku -> {
100 Set<Long> skuPropertyIds = convertSet(sku.getProperties(), propertyItem -> propertyValueMap.get(propertyItem.getValueId()).getPropertyId()); 100 Set<Long> skuPropertyIds = convertSet(sku.getProperties(), propertyItem -> propertyValueMap.get(propertyItem.getValueId()).getPropertyId());
101 if (skuPropertyIds.size() != sku.getProperties().size()) { 101 if (skuPropertyIds.size() != sku.getProperties().size()) {
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.value.ProductPropertyValueRespVO;  
9 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; 8 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
10 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; 9 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
11 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; 10 import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
@@ -15,6 +14,7 @@ import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO; @@ -15,6 +14,7 @@ import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
15 import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; 14 import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
16 import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; 15 import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
17 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; 16 import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
  17 +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
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;
@@ -34,6 +34,7 @@ import java.util.*; @@ -34,6 +34,7 @@ import java.util.*;
34 import java.util.stream.Collectors; 34 import java.util.stream.Collectors;
35 35
36 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 36 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  37 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
37 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; 38 import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS;
38 39
39 /** 40 /**
@@ -141,7 +142,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { @@ -141,7 +142,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
141 } 142 }
142 Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId)); 143 Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId));
143 144
144 - List<ProductPropertyValueRespVO> propertyValueList = productPropertyValueService.getPropertyValueListByPropertyId(new ArrayList<>(propertyMaps.keySet())); 145 + List<ProductPropertyValueDO> propertyValueList = productPropertyValueService.getPropertyValueListByPropertyId(propertyMaps.keySet());
145 List<ProductPropertyDO> propertyList = productPropertyService.getPropertyList(propertyMaps.keySet()); 146 List<ProductPropertyDO> propertyList = productPropertyService.getPropertyList(propertyMaps.keySet());
146 // 装载组装过后的属性 147 // 装载组装过后的属性
147 List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>(); 148 List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>();
@@ -151,7 +152,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { @@ -151,7 +152,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
151 productPropertyViewRespVO.setName(p.getName()); 152 productPropertyViewRespVO.setName(p.getName());
152 List<ProductPropertyViewRespVO.Tuple2> propertyValues = new ArrayList<>(); 153 List<ProductPropertyViewRespVO.Tuple2> propertyValues = new ArrayList<>();
153 // 转换成map是为了能快速获取 154 // 转换成map是为了能快速获取
154 - Map<Long, ProductPropertyValueRespVO> propertyValueMaps = CollectionUtils.convertMap(propertyValueList, ProductPropertyValueRespVO::getId); 155 + Map<Long, ProductPropertyValueDO> propertyValueMaps = convertMap(propertyValueList, ProductPropertyValueDO::getId);
155 propertyMaps.get(p.getId()).forEach(pv -> { 156 propertyMaps.get(p.getId()).forEach(pv -> {
156 ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName()); 157 ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName());
157 propertyValues.add(tuple2); 158 propertyValues.add(tuple2);
yudao-ui-admin/src/api/mall/product/property.js
@@ -63,17 +63,6 @@ export function getPropertyListAndValue(query) { @@ -63,17 +63,6 @@ export function getPropertyListAndValue(query) {
63 }) 63 })
64 } 64 }
65 65
66 -  
67 -// 导出属性项 Excel  
68 -export function exportPropertyExcel(query) {  
69 - return request({  
70 - url: '/product/property/export-excel',  
71 - method: 'get',  
72 - params: query,  
73 - responseType: 'blob'  
74 - })  
75 -}  
76 -  
77 // ------------------------ 属性值 ------------------- 66 // ------------------------ 属性值 -------------------
78 67
79 // 获得属性值分页 68 // 获得属性值分页
@@ -119,3 +108,6 @@ export function deletePropertyValue(id) { @@ -119,3 +108,6 @@ export function deletePropertyValue(id) {
119 method: 'delete' 108 method: 'delete'
120 }) 109 })
121 } 110 }
  111 +
  112 +export class exportPropertyExcel {
  113 +}
yudao-ui-admin/src/views/mall/product/property/index.vue
@@ -6,12 +6,6 @@ @@ -6,12 +6,6 @@
6 <el-form-item label="名称" prop="name"> 6 <el-form-item label="名称" prop="name">
7 <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery"/> 7 <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery"/>
8 </el-form-item> 8 </el-form-item>
9 - <el-form-item label="状态" prop="status">  
10 - <el-select v-model="queryParams.status" placeholder="请选择开启状态" clearable size="small">  
11 - <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"  
12 - :key="dict.value" :label="dict.label" :value="dict.value"/>  
13 - </el-select>  
14 - </el-form-item>  
15 <el-form-item label="创建时间" prop="createTime"> 9 <el-form-item label="创建时间" prop="createTime">
16 <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" 10 <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
17 range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" /> 11 range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
@@ -41,12 +35,12 @@ @@ -41,12 +35,12 @@
41 </router-link> 35 </router-link>
42 </template> 36 </template>
43 </el-table-column> 37 </el-table-column>
  38 + <el-table-column label="备注" align="center" prop="remark" />
44 <el-table-column label="创建时间" align="center" prop="createTime" width="180"> 39 <el-table-column label="创建时间" align="center" prop="createTime" width="180">
45 <template slot-scope="scope"> 40 <template slot-scope="scope">
46 <span>{{ parseTime(scope.row.createTime) }}</span> 41 <span>{{ parseTime(scope.row.createTime) }}</span>
47 </template> 42 </template>
48 </el-table-column> 43 </el-table-column>
49 - <el-table-column label="备注" align="center" prop="left" />  
50 <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> 44 <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
51 <template slot-scope="scope"> 45 <template slot-scope="scope">
52 <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" 46 <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
@@ -63,9 +57,6 @@ @@ -63,9 +57,6 @@
63 <!-- 对话框(添加 / 修改) --> 57 <!-- 对话框(添加 / 修改) -->
64 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> 58 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
65 <el-form ref="form" :model="form" :rules="rules" label-width="80px"> 59 <el-form ref="form" :model="form" :rules="rules" label-width="80px">
66 - <el-form-item label="编号" prop="id" v-if="form.id != null">  
67 - <el-input v-model="form.id" disabled />  
68 - </el-form-item>  
69 <el-form-item label="名称" prop="name"> 60 <el-form-item label="名称" prop="name">
70 <el-input v-model="form.name" placeholder="请输入名称" /> 61 <el-input v-model="form.name" placeholder="请输入名称" />
71 </el-form-item> 62 </el-form-item>
@@ -82,7 +73,7 @@ @@ -82,7 +73,7 @@
82 </template> 73 </template>
83 74
84 <script> 75 <script>
85 -import { createProperty, updateProperty, deleteProperty, getProperty, getPropertyPage, exportPropertyExcel } from "@/api/mall/product/property"; 76 +import { createProperty, updateProperty, deleteProperty, getProperty, getPropertyPage } from "@/api/mall/product/property";
86 77
87 export default { 78 export default {
88 name: "Property", 79 name: "Property",
@@ -92,8 +83,6 @@ export default { @@ -92,8 +83,6 @@ export default {
92 return { 83 return {
93 // 遮罩层 84 // 遮罩层
94 loading: true, 85 loading: true,
95 - // 导出遮罩层  
96 - exportLoading: false,  
97 // 显示搜索条件 86 // 显示搜索条件
98 showSearch: true, 87 showSearch: true,
99 // 总条数 88 // 总条数
@@ -114,7 +103,6 @@ export default { @@ -114,7 +103,6 @@ export default {
114 // 表单参数 103 // 表单参数
115 form: { 104 form: {
116 name:'', 105 name:'',
117 - status:'',  
118 remark:"", 106 remark:"",
119 id: null, 107 id: null,
120 }, 108 },
yudao-ui-admin/src/views/mall/product/property/value.vue
@@ -3,18 +3,12 @@ @@ -3,18 +3,12 @@
3 <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> 3 <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
4 <el-form-item label="属性项" prop="propertyId"> 4 <el-form-item label="属性项" prop="propertyId">
5 <el-select v-model="queryParams.propertyId"> 5 <el-select v-model="queryParams.propertyId">
6 - <el-option v-for="item in propertyOptions" :key="item.id" :label="item.id +'-'+ item.name" :value="item.id"/> 6 + <el-option v-for="item in propertyOptions" :key="item.id" :label="item.name" :value="item.id"/>
7 </el-select> 7 </el-select>
8 </el-form-item> 8 </el-form-item>
9 <el-form-item label="名称" prop="name"> 9 <el-form-item label="名称" prop="name">
10 <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery"/> 10 <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery"/>
11 </el-form-item> 11 </el-form-item>
12 - <el-form-item label="状态" prop="status">  
13 - <el-select v-model="queryParams.status" placeholder="状态" clearable size="small">  
14 - <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"  
15 - :key="dict.value" :label="dict.label" :value="dict.value"/>  
16 - </el-select>  
17 - </el-form-item>  
18 <el-form-item> 12 <el-form-item>
19 <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> 13 <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
20 <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> 14 <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
@@ -27,21 +21,12 @@ @@ -27,21 +21,12 @@
27 v-hasPermi="['system:dict:create']">新增 21 v-hasPermi="['system:dict:create']">新增
28 </el-button> 22 </el-button>
29 </el-col> 23 </el-col>
30 - <!-- <el-col :span="1.5">  
31 - <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"  
32 - v-hasPermi="['system:dict:export']">导出</el-button>  
33 - </el-col> -->  
34 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> 24 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
35 </el-row> 25 </el-row>
36 26
37 <el-table v-loading="loading" :data="dataList"> 27 <el-table v-loading="loading" :data="dataList">
38 <el-table-column label="编号" align="center" prop="id"/> 28 <el-table-column label="编号" align="center" prop="id"/>
39 <el-table-column label="名称" align="center" prop="name"/> 29 <el-table-column label="名称" align="center" prop="name"/>
40 - <el-table-column label="状态" align="center" prop="status">  
41 - <template slot-scope="scope">  
42 - <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>  
43 - </template>  
44 - </el-table-column>  
45 <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true"/> 30 <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true"/>
46 <el-table-column label="创建时间" align="center" prop="createTime" width="180"> 31 <el-table-column label="创建时间" align="center" prop="createTime" width="180">
47 <template slot-scope="scope"> 32 <template slot-scope="scope">
@@ -72,13 +57,6 @@ @@ -72,13 +57,6 @@
72 <el-form-item label="名称" prop="name"> 57 <el-form-item label="名称" prop="name">
73 <el-input v-model="form.name" placeholder="请输入名称"/> 58 <el-input v-model="form.name" placeholder="请输入名称"/>
74 </el-form-item> 59 </el-form-item>
75 - <el-form-item label="状态" prop="status">  
76 - <el-radio-group v-model="form.status">  
77 - <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"  
78 - :key="dict.value" :label="parseInt(dict.value)">{{ dict.label }}  
79 - </el-radio>  
80 - </el-radio-group>  
81 - </el-form-item>  
82 <el-form-item label="备注" prop="remark"> 60 <el-form-item label="备注" prop="remark">
83 <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input> 61 <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
84 </el-form-item> 62 </el-form-item>
@@ -108,8 +86,6 @@ export default { @@ -108,8 +86,6 @@ export default {
108 return { 86 return {
109 // 遮罩层 87 // 遮罩层
110 loading: true, 88 loading: true,
111 - // 导出遮罩层  
112 - exportLoading: false,  
113 // 显示搜索条件 89 // 显示搜索条件
114 showSearch: true, 90 showSearch: true,
115 // 总条数 91 // 总条数
@@ -130,7 +106,6 @@ export default { @@ -130,7 +106,6 @@ export default {
130 pageSize: 10, 106 pageSize: 10,
131 propertyId: undefined, 107 propertyId: undefined,
132 name: undefined, 108 name: undefined,
133 - status: undefined  
134 }, 109 },
135 // 表单参数 110 // 表单参数
136 form: {}, 111 form: {},
@@ -138,9 +113,6 @@ export default { @@ -138,9 +113,6 @@ export default {
138 rules: { 113 rules: {
139 name: [ 114 name: [
140 {required: true, message: "名称不能为空", trigger: "blur"} 115 {required: true, message: "名称不能为空", trigger: "blur"}
141 - ],  
142 - status: [  
143 - {required: true, message: "状态不能为空", trigger: "blur"}  
144 ] 116 ]
145 }, 117 },
146 118
@@ -186,7 +158,6 @@ export default { @@ -186,7 +158,6 @@ export default {
186 id: undefined, 158 id: undefined,
187 propertyId: undefined, 159 propertyId: undefined,
188 name: undefined, 160 name: undefined,
189 - status: undefined,  
190 remark: undefined 161 remark: undefined
191 }; 162 };
192 this.resetForm("form"); 163 this.resetForm("form");
@@ -212,7 +183,7 @@ export default { @@ -212,7 +183,7 @@ export default {
212 /** 修改按钮操作 */ 183 /** 修改按钮操作 */
213 handleUpdate(row) { 184 handleUpdate(row) {
214 this.reset(); 185 this.reset();
215 - const id = row.id || this.ids 186 + const id = row.id;
216 getPropertyValue(id).then(response => { 187 getPropertyValue(id).then(response => {
217 this.form = response.data; 188 this.form = response.data;
218 this.open = true; 189 this.open = true;