mall: 商品的代码 review

pull/2/head
zhijiantianya@gmail.com 2022-09-30 08:30:04 +00:00
parent 034de50999
commit c25791047f
16 changed files with 46 additions and 34 deletions

View File

@ -20,5 +20,4 @@ public class ProductPropertyRespVO extends ProductPropertyBaseVO {
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
}

View File

@ -27,4 +27,5 @@ public class ProductPropertyValueBaseVO {
@ApiModelProperty(value = "备注", example = "颜色")
private String remark;
}

View File

@ -14,7 +14,7 @@ import java.util.List;
@ToString(callSuper = true)
public class ProductSkuCreateOrUpdateReqVO extends ProductSkuBaseVO {
@ApiModelProperty(value = "商品 id", example = "1")
@ApiModelProperty(value = "商品 SKU 编号", example = "1")
private Long id;
/**

View File

@ -55,7 +55,8 @@ public class ProductSpuDetailRespVO extends ProductSpuBaseVO {
}
@ApiModelProperty(value = "分类id数组一直递归到一级父节点", example = "[1,2,4]")
// TODO @luowenfeng: 只返回 categoryId 可以么? 如果是为了前端修改时使用, 会拿到下拉列表, 自动选中合适的. 可以微信讨论下, 我也不完全确定哈;
@ApiModelProperty(value = "分类 id 数组,一直递归到一级父节点", example = "[1,2,4]")
private List<Long> categoryIds;
@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\"}]}]")

View File

@ -14,19 +14,19 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ToString(callSuper = true)
public class ProductSpuPageReqVO extends PageParam {
@ApiModelProperty(value = "商品名称")
@ApiModelProperty(value = "商品名称", example = "yutou")
private String name;
@ApiModelProperty(value = "商品编码", example = "yudaoyuanma")
private String code;
@ApiModelProperty(value = "分类id")
@ApiModelProperty(value = "分类id", example = "1")
private Long categoryId;
@ApiModelProperty(value = "商品品牌编号", example = "1")
private Long brandId;
@ApiModelProperty(value = "上下架状态 0 上架(开启) 1 下架(禁用)")
@ApiModelProperty(value = "上下架状态", example = "1", notes = "参见 CommonStatusEnum 枚举值")
private Integer status;
@ApiModelProperty(value = "销量最小值", example = "1")
@ -41,6 +41,7 @@ public class ProductSpuPageReqVO extends PageParam {
@ApiModelProperty(value = "市场价最大值", example = "1024")
private Integer marketPriceMax;
// TODO @luowenfeng: 这个可以改成前端基于 tab, 传递不同的条件么?
@ApiModelProperty(value = "tab 状态 null 全部, 0销售中上架 1仓库中下架 2预警中", example = "1")
private Integer tabStatus;

View File

@ -17,7 +17,7 @@ import java.util.List;
@Mapper
public interface ProductPropertyValueMapper extends BaseMapperX<ProductPropertyValueDO> {
// TODO @franky方法名selectListByXXX。mapper 的操作都是 crud
// TODO @luowenfeng方法名selectListByXXX。mapper 的操作都是 crud
default List<ProductPropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds) {
// TODO @franky调用父类的 selectList
return selectList(new LambdaQueryWrapperX<ProductPropertyValueDO>()
@ -25,7 +25,7 @@ public interface ProductPropertyValueMapper extends BaseMapperX<ProductPropertyV
}
default void deletePropertyValueByPropertyId(Long propertyId) {
// TODO @frankydelete(new ) 即可
// TODO @luowenfengdelete(new ) 即可
LambdaQueryWrapperX<ProductPropertyValueDO> queryWrapperX = new LambdaQueryWrapperX<>();
queryWrapperX.eq(ProductPropertyValueDO::getPropertyId, propertyId)
.eq(ProductPropertyValueDO::getDeleted, false);
@ -39,4 +39,5 @@ public interface ProductPropertyValueMapper extends BaseMapperX<ProductPropertyV
.eqIfPresent(ProductPropertyValueDO::getStatus, reqVO.getStatus())
.orderByDesc(ProductPropertyValueDO::getId));
}
}

View File

@ -39,7 +39,7 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
.leIfPresent(ProductSpuDO::getMarketPrice, reqVO.getMarketPriceMax())
.geIfPresent(ProductSpuDO::getMarketPrice, reqVO.getMarketPriceMin())
.orderByDesc(ProductSpuDO::getSort);
// TODO @芋艿: 需要优化下这里的代码
if(reqVO.getTabStatus()!= null && reqVO.getTabStatus() == 2){
productSpuDOLambdaQueryWrapperX.inIfPresent(ProductSpuDO::getId, spuIds);
}else{

View File

@ -93,12 +93,13 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
@Override
public void validateCategoryLevel(Long id) {
Long parentId = id;
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) { // TODO @luowenfeng: 建议还是先获得 level; 然后判断 level 是不是满足; 这样逻辑会更清晰一些;
if (Objects.equals(parentId, ProductCategoryDO.PARENT_ID_NULL)) {
throw exception(CATEGORY_LEVEL_ERROR);
}
ProductCategoryDO category = productCategoryMapper.selectById(parentId);
if (category == null) {
// TODO @luowenfeng: 应该抛出 CATEGORY_LEVEL_ERROR
throw exception(CATEGORY_NOT_EXISTS);
}
parentId = category.getParentId();

View File

@ -54,13 +54,14 @@ public interface ProductPropertyService {
List<ProductPropertyRespVO> getPropertyList(ProductPropertyListReqVO listReqVO);
/**
*
* @param pageReqVO
* @return
*
*
* @param pageReqVO
* @return
*/
PageResult<ProductPropertyRespVO> getPropertyPage(ProductPropertyPageReqVO pageReqVO);
// TODO luowenfeng: getProperty 就可以拉, 不用到 Resp
ProductPropertyRespVO getPropertyResp(Long id);
/**
@ -71,11 +72,11 @@ public interface ProductPropertyService {
*/
List<ProductPropertyRespVO> getPropertyList(Collection<Long> ids);
/**
*
* @param listReqVO
* @return
* +
*
* @param listReqVO
* @return +
*/
List<ProductPropertyAndValueRespVO> getPropertyAndValueList(ProductPropertyListReqVO listReqVO);

View File

@ -46,6 +46,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
@Override
@Transactional(rollbackFor = Exception.class)
public Long createProperty(ProductPropertyCreateReqVO createReqVO) {
// TODO @luowenfeng: 插入和更新的时候, 要校验 name 的唯一性;
// 插入
ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO);
productPropertyMapper.insert(property);
@ -96,6 +97,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
//获取属性列表
PageResult<ProductPropertyDO> pageResult = productPropertyMapper.selectPage(pageReqVO);
PageResult<ProductPropertyRespVO> propertyRespVOPageResult = ProductPropertyConvert.INSTANCE.convertPage(pageResult);
// TODO @luofengwen: 下面的代码, 如果不要,可以删除哈; git 可以拿到记录的
// List<Long> propertyIds = propertyRespVOPageResult.getList().stream().map(ProductPropertyAndValueRespVO::getId).collect(Collectors.toList());
//
// //获取属性值列表
@ -116,7 +118,6 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
@Override
public ProductPropertyRespVO getPropertyResp(Long id) {
//查询规格
ProductPropertyDO property = getProperty(id);
return ProductPropertyConvert.INSTANCE.convert(property);
}
@ -130,13 +131,15 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
public List<ProductPropertyAndValueRespVO> getPropertyAndValueList(ProductPropertyListReqVO listReqVO) {
List<ProductPropertyRespVO> propertyList = getPropertyList(listReqVO);
//查询属性值
// 查询属性值
List<ProductPropertyValueDO> valueDOList = productPropertyValueMapper.getPropertyValueListByPropertyId(CollectionUtils.convertList(propertyList, ProductPropertyRespVO::getId));
// CollectionUtils.convertMultiMap() // TODO @luofengwen: 可以使用这个方法哈
Map<Long, List<ProductPropertyValueRespVO>> valueDOMap = valueDOList.stream()
.map(ProductPropertyValueConvert.INSTANCE::convert)
.collect(Collectors.groupingBy(ProductPropertyValueRespVO::getPropertyId));
//组装
// 组装 TODO @luowenfeng: CollectionUtils 转换哈;
return propertyList.stream().map(m -> {
// TODO @luowenfeng: 使用 mapstruct convert 哈
ProductPropertyAndValueRespVO productPropertyAndValueRespVO = BeanUtil.copyProperties(m, ProductPropertyAndValueRespVO.class);
productPropertyAndValueRespVO.setValues(valueDOMap.get(m.getId()));
return productPropertyAndValueRespVO;

View File

@ -16,7 +16,7 @@ import javax.annotation.Resource;
import java.util.List;
/**
* <p>
* <p> TODO @luowenfeng:
*
* </p>
*
@ -31,6 +31,7 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
@Override
public Long createPropertyValue(ProductPropertyValueCreateReqVO createReqVO) {
// TODO @luowenfeng: 需要校验下在这个 propertyId, 新增和更新, name 都要唯一
ProductPropertyValueDO convert = ProductPropertyValueConvert.INSTANCE.convert(createReqVO);
productPropertyValueMapper.insert(convert);
return convert.getId();

View File

@ -83,8 +83,9 @@ public interface ProductSkuService {
*/
void deleteSkuBySpuId(Long spuId);
// TODO @luowenfeng: 可以改成返回 ProductSkuDO 列表; 然后, 上层业务在做处理;
/**
* spu
* SPU
*
* @return spuId
*/

View File

@ -135,6 +135,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
@Override
public List<Long> getRemindSpuIds() {
// TODO @luowenfeng: mybatis plus 不能出现在 Service 哈; 把这个查询, 下沉一个方法到 mapper 里
List<ProductSkuDO> productSkuDOS = productSkuMapper.selectList(new QueryWrapper<ProductSkuDO>().apply("stock <= warn_stock"));
return productSkuDOS.stream().map(ProductSkuDO::getSpuId).distinct().collect(Collectors.toList());
}

View File

@ -33,38 +33,38 @@ public interface ProductSpuService {
void updateSpu(@Valid ProductSpuUpdateReqVO updateReqVO);
/**
* spu
* SPU
*
* @param id
*/
void deleteSpu(Long id);
/**
* spu
* SPU
*
* @param id
* @return spu
* @return SPU
*/
ProductSpuDetailRespVO getSpuDetail(Long id);
/**
* spu
* SPU
*
* @param id
* @return spu
* @return SPU
*/
ProductSpuRespVO getSpu(Long id);
/**
* spu
* SPU
*
* @param ids
* @return spu
* @param ids
* @return SPU
*/
List<ProductSpuDO> getSpuList(Collection<Long> ids);
/**
* spu
* SPU
*
* @param pageReqVO
* @return spu
@ -72,12 +72,11 @@ public interface ProductSpuService {
PageResult<ProductSpuRespVO> getSpuPage(ProductSpuPageReqVO pageReqVO);
/**
* spu
* SPU // TODO @luowenfeng: 中文和英文之间, 要有一个空格; 这样, 阅读起来会更清晰; 我已经都改啦
*
* @param pageReqVO
* @return spu
*/
PageResult<AppSpuPageRespVO> getSpuPage(AppSpuPageReqVO pageReqVO);
}

View File

@ -192,6 +192,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
public PageResult<ProductSpuRespVO> getSpuPage(ProductSpuPageReqVO pageReqVO) {
List<Long> remindSpuIds= null;
// todo @yunai 预警类型的判断应该可以优化,看下怎么处理
// TODO @luowenfeng: 先这么简单处理; 性能应该影响不大的;
if(pageReqVO.getTabStatus() != null && pageReqVO.getTabStatus() == 2){
remindSpuIds= productSkuService.getRemindSpuIds();
if(remindSpuIds.isEmpty()){

View File

@ -39,6 +39,7 @@
<el-tab-pane label="价格库存" name="rates" class="rates">
<el-form ref="rates" :model="ratesForm" :rules="rules">
<el-form-item label="启用多规格">
<!-- TODO @luowenfeng: 1) activeSwitch 可以考虑改成; specSwitch, 更清晰一点, activeSwitch 太通用了; changeRadio 改成 changeSpecSwitch -->
<el-switch v-model="activeSwitch" @change="changeRadio"></el-switch>
</el-form-item>