Commit 664abe70626acf5a0e23439f6e900c1803427784

Authored by YunaiV
1 parent 6e67120b

【功能优化】添加商品属性时允许选择已有的属性值

yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java
... ... @@ -17,7 +17,10 @@ import org.springframework.security.access.prepost.PreAuthorize;
17 17 import org.springframework.validation.annotation.Validated;
18 18 import org.springframework.web.bind.annotation.*;
19 19  
  20 +import java.util.List;
  21 +
20 22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  23 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
21 24  
22 25 @Tag(name = "管理后台 - 商品属性项")
23 26 @RestController
... ... @@ -69,4 +72,12 @@ public class ProductPropertyController {
69 72 return success(BeanUtils.toBean(pageResult, ProductPropertyRespVO.class));
70 73 }
71 74  
  75 + @GetMapping("/simple-list")
  76 + @Operation(summary = "获得属性项精简列表")
  77 + public CommonResult<List<ProductPropertyRespVO>> getPropertySimpleList() {
  78 + List<ProductPropertyDO> list = productPropertyService.getPropertyList();
  79 + return success(convertList(list, property -> new ProductPropertyRespVO() // 只返回 id、name 属性
  80 + .setId(property.getId()).setName(property.getName())));
  81 + }
  82 +
72 83 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java
... ... @@ -17,7 +17,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
17 17 import org.springframework.validation.annotation.Validated;
18 18 import org.springframework.web.bind.annotation.*;
19 19  
  20 +import java.util.List;
  21 +
20 22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  23 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
  24 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.singleton;
21 25  
22 26 @Tag(name = "管理后台 - 商品属性值")
23 27 @RestController
... ... @@ -69,4 +73,13 @@ public class ProductPropertyValueController {
69 73 return success(BeanUtils.toBean(pageResult, ProductPropertyValueRespVO.class));
70 74 }
71 75  
  76 + @GetMapping("/simple-list")
  77 + @Operation(summary = "获得属性值精简列表")
  78 + @Parameter(name = "propertyId", description = "属性项编号", required = true, example = "1024")
  79 + public CommonResult<List<ProductPropertyValueRespVO>> getPropertyValueSimpleList(@RequestParam("propertyId") Long propertyId) {
  80 + List<ProductPropertyValueDO> list = productPropertyValueService.getPropertyValueListByPropertyId(singleton(propertyId));
  81 + return success(convertList(list, value -> new ProductPropertyValueRespVO() // 只返回 id、name 属性
  82 + .setId(value.getId()).setName(value.getName())));
  83 + }
  84 +
72 85 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/property/ProductPropertyDO.java
... ... @@ -40,10 +40,6 @@ public class ProductPropertyDO extends BaseDO {
40 40 */
41 41 private String name;
42 42 /**
43   - * 状态
44   - */
45   - private Integer status;
46   - /**
47 43 * 备注
48 44 */
49 45 private String remark;
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java
... ... @@ -62,4 +62,11 @@ public interface ProductPropertyService {
62 62 */
63 63 List<ProductPropertyDO> getPropertyList(Collection<Long> ids);
64 64  
  65 + /**
  66 + * 获得指定状态的属性项列表
  67 + *
  68 + * @return 属性项列表
  69 + */
  70 + List<ProductPropertyDO> getPropertyList();
  71 +
65 72 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java
... ... @@ -109,4 +109,9 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
109 109 return productPropertyMapper.selectBatchIds(ids);
110 110 }
111 111  
  112 + @Override
  113 + public List<ProductPropertyDO> getPropertyList() {
  114 + return productPropertyMapper.selectList();
  115 + }
  116 +
112 117 }
... ...