Commit c25791047f54ec2426b17434bb2d1df364f5f7de

Authored by zhijiantianya@gmail.com
1 parent 034de509

mall: 商品的代码 review

Showing 16 changed files with 46 additions and 34 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/property/ProductPropertyRespVO.java
... ... @@ -20,5 +20,4 @@ public class ProductPropertyRespVO extends ProductPropertyBaseVO {
20 20 @ApiModelProperty(value = "创建时间", required = true)
21 21 private Date createTime;
22 22  
23   -
24 23 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/vo/value/ProductPropertyValueBaseVO.java
... ... @@ -27,4 +27,5 @@ public class ProductPropertyValueBaseVO {
27 27  
28 28 @ApiModelProperty(value = "备注", example = "颜色")
29 29 private String remark;
  30 +
30 31 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuCreateOrUpdateReqVO.java
... ... @@ -14,7 +14,7 @@ import java.util.List;
14 14 @ToString(callSuper = true)
15 15 public class ProductSkuCreateOrUpdateReqVO extends ProductSkuBaseVO {
16 16  
17   - @ApiModelProperty(value = "商品 id", example = "1")
  17 + @ApiModelProperty(value = "商品 SKU 编号", example = "1")
18 18 private Long id;
19 19  
20 20 /**
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java
... ... @@ -55,7 +55,8 @@ public class ProductSpuDetailRespVO extends ProductSpuBaseVO {
55 55  
56 56 }
57 57  
58   - @ApiModelProperty(value = "分类id数组,一直递归到一级父节点", example = "[1,2,4]")
  58 + // TODO @luowenfeng: 只返回 categoryId 可以么? 如果是为了前端修改时使用, 会拿到下拉列表, 自动选中合适的. 可以微信讨论下, 我也不完全确定哈;
  59 + @ApiModelProperty(value = "分类 id 数组,一直递归到一级父节点", example = "[1,2,4]")
59 60 private List<Long> categoryIds;
60 61  
61 62 @ApiModelProperty(value = "规格属性修改和详情展示组合", example = "[{\"propertyId\":2,\"name\":\"内存\",\"propertyValues\":[{\"v1\":11,\"v2\":\"64G\"},{\"v1\":10,\"v2\":\"32G\"}]},{\"propertyId\":3,\"name\":\"尺寸\",\"propertyValues\":[{\"v1\":16,\"v2\":\"6.1\"},{\"v1\":15,\"v2\":\"5.7\"}]}]")
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java
... ... @@ -14,19 +14,19 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
14 14 @ToString(callSuper = true)
15 15 public class ProductSpuPageReqVO extends PageParam {
16 16  
17   - @ApiModelProperty(value = "商品名称")
  17 + @ApiModelProperty(value = "商品名称", example = "yutou")
18 18 private String name;
19 19  
20 20 @ApiModelProperty(value = "商品编码", example = "yudaoyuanma")
21 21 private String code;
22 22  
23   - @ApiModelProperty(value = "分类id")
  23 + @ApiModelProperty(value = "分类id", example = "1")
24 24 private Long categoryId;
25 25  
26 26 @ApiModelProperty(value = "商品品牌编号", example = "1")
27 27 private Long brandId;
28 28  
29   - @ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)")
  29 + @ApiModelProperty(value = "上下架状态", example = "1", notes = "参见 CommonStatusEnum 枚举值")
30 30 private Integer status;
31 31  
32 32 @ApiModelProperty(value = "销量最小值", example = "1")
... ... @@ -41,6 +41,7 @@ public class ProductSpuPageReqVO extends PageParam {
41 41 @ApiModelProperty(value = "市场价最大值", example = "1024")
42 42 private Integer marketPriceMax;
43 43  
  44 + // TODO @luowenfeng: 这个可以改成前端基于 tab, 传递不同的条件么?
44 45 @ApiModelProperty(value = "tab 状态 null 全部, 0:销售中(上架) 1:仓库中(下架) 2:预警中", example = "1")
45 46 private Integer tabStatus;
46 47  
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyValueMapper.java
... ... @@ -17,7 +17,7 @@ import java.util.List;
17 17 @Mapper
18 18 public interface ProductPropertyValueMapper extends BaseMapperX<ProductPropertyValueDO> {
19 19  
20   - // TODO @franky:方法名,selectListByXXX。mapper 的操作都是 crud
  20 + // TODO @luowenfeng:方法名,selectListByXXX。mapper 的操作都是 crud
21 21 default List<ProductPropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds) {
22 22 // TODO @franky:调用父类的 selectList
23 23 return selectList(new LambdaQueryWrapperX<ProductPropertyValueDO>()
... ... @@ -25,7 +25,7 @@ public interface ProductPropertyValueMapper extends BaseMapperX&lt;ProductPropertyV
25 25 }
26 26  
27 27 default void deletePropertyValueByPropertyId(Long propertyId) {
28   - // TODO @franky:delete(new ) 即可
  28 + // TODO @luowenfeng:delete(new ) 即可
29 29 LambdaQueryWrapperX<ProductPropertyValueDO> queryWrapperX = new LambdaQueryWrapperX<>();
30 30 queryWrapperX.eq(ProductPropertyValueDO::getPropertyId, propertyId)
31 31 .eq(ProductPropertyValueDO::getDeleted, false);
... ... @@ -39,4 +39,5 @@ public interface ProductPropertyValueMapper extends BaseMapperX&lt;ProductPropertyV
39 39 .eqIfPresent(ProductPropertyValueDO::getStatus, reqVO.getStatus())
40 40 .orderByDesc(ProductPropertyValueDO::getId));
41 41 }
  42 +
42 43 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java
... ... @@ -39,7 +39,7 @@ public interface ProductSpuMapper extends BaseMapperX&lt;ProductSpuDO&gt; {
39 39 .leIfPresent(ProductSpuDO::getMarketPrice, reqVO.getMarketPriceMax())
40 40 .geIfPresent(ProductSpuDO::getMarketPrice, reqVO.getMarketPriceMin())
41 41 .orderByDesc(ProductSpuDO::getSort);
42   -
  42 + // TODO @芋艿: 需要优化下这里的代码
43 43 if(reqVO.getTabStatus()!= null && reqVO.getTabStatus() == 2){
44 44 productSpuDOLambdaQueryWrapperX.inIfPresent(ProductSpuDO::getId, spuIds);
45 45 }else{
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java
... ... @@ -93,12 +93,13 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
93 93 @Override
94 94 public void validateCategoryLevel(Long id) {
95 95 Long parentId = id;
96   - for (int i = 0; i < 3; i++) {
  96 + for (int i = 0; i < 3; i++) { // TODO @luowenfeng: 建议还是先获得 level; 然后判断 level 是不是满足; 这样逻辑会更清晰一些;
97 97 if (Objects.equals(parentId, ProductCategoryDO.PARENT_ID_NULL)) {
98 98 throw exception(CATEGORY_LEVEL_ERROR);
99 99 }
100 100 ProductCategoryDO category = productCategoryMapper.selectById(parentId);
101 101 if (category == null) {
  102 + // TODO @luowenfeng: 应该抛出 CATEGORY_LEVEL_ERROR
102 103 throw exception(CATEGORY_NOT_EXISTS);
103 104 }
104 105 parentId = category.getParentId();
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java
... ... @@ -54,13 +54,14 @@ public interface ProductPropertyService {
54 54 List<ProductPropertyRespVO> getPropertyList(ProductPropertyListReqVO listReqVO);
55 55  
56 56 /**
57   - * 获取属性及属性值列表 分页
58   - * @param pageReqVO
59   - * @return
  57 + * 获取属性名称分页
  58 + *
  59 + * @param pageReqVO 分页条件
  60 + * @return 规格名称分页
60 61 */
61 62 PageResult<ProductPropertyRespVO> getPropertyPage(ProductPropertyPageReqVO pageReqVO);
62 63  
63   -
  64 + // TODO luowenfeng: getProperty 就可以拉, 不用到 Resp
64 65 ProductPropertyRespVO getPropertyResp(Long id);
65 66  
66 67 /**
... ... @@ -71,11 +72,11 @@ public interface ProductPropertyService {
71 72 */
72 73 List<ProductPropertyRespVO> getPropertyList(Collection<Long> ids);
73 74  
74   -
75 75 /**
76   - * 获得规格名称列表
77   - * @param listReqVO 集合查询
78   - * @return 规格名称集合
  76 + * 获得规格名称 + 值的列表
  77 + *
  78 + * @param listReqVO 列表查询
  79 + * @return 规格名称 + 值的列表
79 80 */
80 81 List<ProductPropertyAndValueRespVO> getPropertyAndValueList(ProductPropertyListReqVO listReqVO);
81 82  
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java
... ... @@ -46,6 +46,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
46 46 @Override
47 47 @Transactional(rollbackFor = Exception.class)
48 48 public Long createProperty(ProductPropertyCreateReqVO createReqVO) {
  49 + // TODO @luowenfeng: 插入和更新的时候, 要校验 name 的唯一性;
49 50 // 插入
50 51 ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO);
51 52 productPropertyMapper.insert(property);
... ... @@ -96,6 +97,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
96 97 //获取属性列表
97 98 PageResult<ProductPropertyDO> pageResult = productPropertyMapper.selectPage(pageReqVO);
98 99 PageResult<ProductPropertyRespVO> propertyRespVOPageResult = ProductPropertyConvert.INSTANCE.convertPage(pageResult);
  100 + // TODO @luofengwen: 下面的代码, 如果不要,可以删除哈; git 可以拿到记录的
99 101 // List<Long> propertyIds = propertyRespVOPageResult.getList().stream().map(ProductPropertyAndValueRespVO::getId).collect(Collectors.toList());
100 102 //
101 103 // //获取属性值列表
... ... @@ -116,7 +118,6 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
116 118  
117 119 @Override
118 120 public ProductPropertyRespVO getPropertyResp(Long id) {
119   - //查询规格
120 121 ProductPropertyDO property = getProperty(id);
121 122 return ProductPropertyConvert.INSTANCE.convert(property);
122 123 }
... ... @@ -130,13 +131,15 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
130 131 public List<ProductPropertyAndValueRespVO> getPropertyAndValueList(ProductPropertyListReqVO listReqVO) {
131 132 List<ProductPropertyRespVO> propertyList = getPropertyList(listReqVO);
132 133  
133   - //查询属性值
  134 + // 查询属性值
134 135 List<ProductPropertyValueDO> valueDOList = productPropertyValueMapper.getPropertyValueListByPropertyId(CollectionUtils.convertList(propertyList, ProductPropertyRespVO::getId));
  136 +// CollectionUtils.convertMultiMap() // TODO @luofengwen: 可以使用这个方法哈
135 137 Map<Long, List<ProductPropertyValueRespVO>> valueDOMap = valueDOList.stream()
136 138 .map(ProductPropertyValueConvert.INSTANCE::convert)
137 139 .collect(Collectors.groupingBy(ProductPropertyValueRespVO::getPropertyId));
138   - //组装
  140 + // 组装 TODO @luowenfeng: CollectionUtils 转换哈;
139 141 return propertyList.stream().map(m -> {
  142 + // TODO @luowenfeng: 使用 mapstruct convert 哈
140 143 ProductPropertyAndValueRespVO productPropertyAndValueRespVO = BeanUtil.copyProperties(m, ProductPropertyAndValueRespVO.class);
141 144 productPropertyAndValueRespVO.setValues(valueDOMap.get(m.getId()));
142 145 return productPropertyAndValueRespVO;
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java
... ... @@ -16,7 +16,7 @@ import javax.annotation.Resource;
16 16 import java.util.List;
17 17  
18 18 /**
19   - * <p>
  19 + * <p> TODO @luowenfeng: 类注释
20 20 *
21 21 * </p>
22 22 *
... ... @@ -31,6 +31,7 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
31 31  
32 32 @Override
33 33 public Long createPropertyValue(ProductPropertyValueCreateReqVO createReqVO) {
  34 + // TODO @luowenfeng: 需要校验下在这个 propertyId, 新增和更新, name 都要唯一
34 35 ProductPropertyValueDO convert = ProductPropertyValueConvert.INSTANCE.convert(createReqVO);
35 36 productPropertyValueMapper.insert(convert);
36 37 return convert.getId();
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java
... ... @@ -83,8 +83,9 @@ public interface ProductSkuService {
83 83 */
84 84 void deleteSkuBySpuId(Long spuId);
85 85  
  86 + // TODO @luowenfeng: 可以改成返回 ProductSkuDO 列表; 然后, 上层业务在做处理;
86 87 /**
87   - * 获得商品预警中的spu集合
  88 + * 获得商品预警中的 SPU 集合
88 89 *
89 90 * @return 商品spuId集合
90 91 */
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
... ... @@ -135,6 +135,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
135 135  
136 136 @Override
137 137 public List<Long> getRemindSpuIds() {
  138 + // TODO @luowenfeng: mybatis plus 不能出现在 Service 哈; 把这个查询, 下沉一个方法到 mapper 里
138 139 List<ProductSkuDO> productSkuDOS = productSkuMapper.selectList(new QueryWrapper<ProductSkuDO>().apply("stock <= warn_stock"));
139 140 return productSkuDOS.stream().map(ProductSkuDO::getSpuId).distinct().collect(Collectors.toList());
140 141 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java
... ... @@ -33,38 +33,38 @@ public interface ProductSpuService {
33 33 void updateSpu(@Valid ProductSpuUpdateReqVO updateReqVO);
34 34  
35 35 /**
36   - * 删除商品spu
  36 + * 删除商品 SPU
37 37 *
38 38 * @param id 编号
39 39 */
40 40 void deleteSpu(Long id);
41 41  
42 42 /**
43   - * 获得商品spu详情
  43 + * 获得商品 SPU 详情
44 44 *
45 45 * @param id 编号
46   - * @return 商品spu
  46 + * @return 商品 SPU
47 47 */
48 48 ProductSpuDetailRespVO getSpuDetail(Long id);
49 49  
50 50 /**
51   - * 获得商品spu
  51 + * 获得商品 SPU
52 52 *
53 53 * @param id 编号
54   - * @return 商品spu
  54 + * @return 商品 SPU
55 55 */
56 56 ProductSpuRespVO getSpu(Long id);
57 57  
58 58 /**
59   - * 获得商品spu列表
  59 + * 获得商品 SPU 列表
60 60 *
61   - * @param ids 编号
62   - * @return 商品spu列表
  61 + * @param ids 编号数组
  62 + * @return 商品 SPU 列表
63 63 */
64 64 List<ProductSpuDO> getSpuList(Collection<Long> ids);
65 65  
66 66 /**
67   - * 获得商品spu分页
  67 + * 获得商品 SPU 分页
68 68 *
69 69 * @param pageReqVO 分页查询
70 70 * @return 商品spu分页
... ... @@ -72,12 +72,11 @@ public interface ProductSpuService {
72 72 PageResult<ProductSpuRespVO> getSpuPage(ProductSpuPageReqVO pageReqVO);
73 73  
74 74 /**
75   - * 获得商品spu分页
  75 + * 获得商品 SPU 分页 // TODO @luowenfeng: 中文和英文之间, 要有一个空格; 这样, 阅读起来会更清晰; 我已经都改啦
76 76 *
77 77 * @param pageReqVO 分页查询
78 78 * @return 商品spu分页
79 79 */
80 80 PageResult<AppSpuPageRespVO> getSpuPage(AppSpuPageReqVO pageReqVO);
81 81  
82   -
83 82 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
... ... @@ -192,6 +192,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
192 192 public PageResult<ProductSpuRespVO> getSpuPage(ProductSpuPageReqVO pageReqVO) {
193 193 List<Long> remindSpuIds= null;
194 194 // todo @yunai 预警类型的判断应该可以优化,看下怎么处理
  195 + // TODO @luowenfeng: 先这么简单处理; 性能应该影响不大的;
195 196 if(pageReqVO.getTabStatus() != null && pageReqVO.getTabStatus() == 2){
196 197 remindSpuIds= productSkuService.getRemindSpuIds();
197 198 if(remindSpuIds.isEmpty()){
... ...
yudao-ui-admin/src/views/mall/product/spu/save.vue
... ... @@ -39,6 +39,7 @@
39 39 <el-tab-pane label="价格库存" name="rates" class="rates">
40 40 <el-form ref="rates" :model="ratesForm" :rules="rules">
41 41 <el-form-item label="启用多规格">
  42 + <!-- TODO @luowenfeng: 1) activeSwitch 可以考虑改成; specSwitch, 更清晰一点, activeSwitch 太通用了; changeRadio 改成 changeSpecSwitch -->
42 43 <el-switch v-model="activeSwitch" @change="changeRadio"></el-switch>
43 44 </el-form-item>
44 45  
... ...