商品分类review 修改
This commit is contained in:
parent
c34c501fb8
commit
e47029cff2
@ -1,20 +0,0 @@
|
||||
package cn.iocoder.mall.product.biz.enums.category;
|
||||
|
||||
// TODO FROM 芋艿 to sunderui:改到枚举类,我之前没弄对,哈哈哈
|
||||
public interface ProductCategoryConstants {
|
||||
|
||||
/**
|
||||
* 状态 - 开启
|
||||
*/
|
||||
Integer STATUS_ENABLE = 1;
|
||||
/**
|
||||
* 状态 - 关闭
|
||||
*/
|
||||
Integer STATUS_DISABLE = 2;
|
||||
|
||||
/**
|
||||
* 父分类编号 - 根节点
|
||||
*/
|
||||
Integer PID_ROOT = 0;
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.mall.product.biz.enums.category;
|
||||
|
||||
import cn.iocoder.common.framework.core.IntArrayValuable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/12
|
||||
* @Description: 商品分类节点枚举
|
||||
*/
|
||||
public enum ProductCategoryNodeEnum{
|
||||
|
||||
/**
|
||||
* 根节点
|
||||
*/
|
||||
ROOT(0);
|
||||
|
||||
private final Integer id;
|
||||
|
||||
ProductCategoryNodeEnum(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package cn.iocoder.mall.product.biz.bo.product;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品分类 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Deprecated // TODO jiangweifan 后面确认无使用后删除
|
||||
public class ProductCategoryBO implements Serializable {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 父分类编号
|
||||
*
|
||||
* 如果不存在父级,则 pid = 0 。
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 1-开启
|
||||
* 2-关闭
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package cn.iocoder.mall.product.biz.dao.category;
|
||||
|
||||
import cn.iocoder.mall.product.biz.dataobject.category.ProductCategoryDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
@ -11,5 +12,14 @@ import org.springframework.stereotype.Repository;
|
||||
*/
|
||||
@Repository
|
||||
public interface ProductCategoryMapper extends BaseMapper<ProductCategoryDO> {
|
||||
|
||||
/**
|
||||
* 查询商品分类的下一级子分类数量
|
||||
* @param productCategoryId
|
||||
* @return
|
||||
*/
|
||||
default Integer selectChildCategoryCount(Integer productCategoryId) {
|
||||
return this.selectCount(
|
||||
Wrappers.<ProductCategoryDO>lambdaQuery().eq(ProductCategoryDO::getPid, productCategoryId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,8 @@ import cn.iocoder.mall.product.biz.dto.category.ProductCategoryDeleteDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateStatusDTO;
|
||||
import cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryConstants;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryNodeEnum;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryStatusEnum;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -68,7 +67,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_SELF);
|
||||
}
|
||||
// 校验父分类是否存在
|
||||
if (!ProductCategoryConstants.PID_ROOT.equals(productCategoryUpdateDTO.getPid())
|
||||
if (!ProductCategoryNodeEnum.ROOT.getId().equals(productCategoryUpdateDTO.getPid())
|
||||
&& productCategoryMapper.selectById(productCategoryUpdateDTO.getPid()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS);
|
||||
}
|
||||
@ -114,10 +113,8 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_DELETE_ONLY_DISABLE);
|
||||
}
|
||||
// 只有不存在子分类才可以删除
|
||||
// TODO FROM 芋艿 to jiangweifan:Wrappers 只用在 Mapper 层
|
||||
Integer childCount = productCategoryMapper.selectCount(
|
||||
Wrappers.<ProductCategoryDO>lambdaQuery().eq(ProductCategoryDO::getPid, productCategoryId)
|
||||
);
|
||||
// TODO FROM 芋艿 to jiangweifan:Wrappers 只用在 Mapper 层 [DONE]
|
||||
Integer childCount = productCategoryMapper.selectChildCategoryCount(productCategoryId);
|
||||
if (childCount > 0) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_DELETE_ONLY_NO_CHILD);
|
||||
}
|
||||
@ -129,14 +126,14 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
}
|
||||
|
||||
private void validParent(Integer pid) {
|
||||
if (!ProductCategoryConstants.PID_ROOT.equals(pid)) {
|
||||
if (!ProductCategoryNodeEnum.ROOT.getId().equals(pid)) {
|
||||
ProductCategoryDO parentCategory = productCategoryMapper.selectById(pid);
|
||||
// 校验父分类是否存在
|
||||
if (parentCategory == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS);
|
||||
}
|
||||
// 父分类必须是一级分类
|
||||
if (!ProductCategoryConstants.PID_ROOT.equals(parentCategory.getPid())) {
|
||||
if (!ProductCategoryNodeEnum.ROOT.getId().equals(parentCategory.getPid())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2);
|
||||
}
|
||||
}
|
||||
@ -150,7 +147,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode());
|
||||
}
|
||||
// 只有禁用的商品分类才可以删除
|
||||
if (ProductCategoryConstants.STATUS_DISABLE.equals(productCategory.getStatus())) {
|
||||
if (ProductCategoryStatusEnum.DISABLED.getStatus().equals(productCategory.getStatus())) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_MUST_ENABLE.getCode());
|
||||
}
|
||||
// 返回结果
|
||||
|
@ -15,7 +15,7 @@ import cn.iocoder.mall.product.biz.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.mall.product.biz.dto.sku.ProductSkuAddOrUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.sku.ProductSpuAddDTO;
|
||||
import cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryConstants;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryNodeEnum;
|
||||
import cn.iocoder.mall.product.biz.enums.spu.ProductSpuConstants;
|
||||
import cn.iocoder.mall.product.biz.service.attr.ProductAttrService;
|
||||
import cn.iocoder.mall.product.biz.service.category.ProductCategoryService;
|
||||
@ -76,7 +76,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||
public ProductSpuDetailBO addProductSpu0(Integer adminId, ProductSpuAddDTO productSpuAddDTO) {
|
||||
// 校验商品分类分类存在
|
||||
ProductCategoryDO category = productCategoryService.validProductCategory(productSpuAddDTO.getCid());
|
||||
if (ProductCategoryConstants.PID_ROOT.equals(category.getPid())) {
|
||||
if (ProductCategoryNodeEnum.ROOT.getId().equals(category.getPid())) {
|
||||
// 商品只能添加到二级分类下
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_SPU_CATEGORY_MUST_BE_LEVEL2.getCode());
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import cn.iocoder.mall.product.biz.dto.category.ProductCategoryAddDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryDeleteDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateStatusDTO;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryConstants;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryNodeEnum;
|
||||
import cn.iocoder.mall.product.biz.service.category.ProductCategoryService;
|
||||
import cn.iocoder.mall.product.rest.convert.category.AdminsProductCategoryConvert;
|
||||
import cn.iocoder.mall.product.rest.request.category.AdminsProductCategoryAddRequest;
|
||||
@ -49,7 +49,7 @@ public class AdminsProductCategoryController {
|
||||
Map<Integer, AdminsProductCategoryTreeNodeResponse> treeNodeMap = productCategories.stream().collect(Collectors.toMap(ProductCategoryBO::getId, AdminsProductCategoryConvert.INSTANCE::convertToTreeNodeResponse));
|
||||
// 处理父子关系
|
||||
treeNodeMap.values().stream()
|
||||
.filter(node -> !node.getPid().equals(ProductCategoryConstants.PID_ROOT))
|
||||
.filter(node -> !node.getPid().equals(ProductCategoryNodeEnum.ROOT.getId()))
|
||||
.forEach((childNode) -> {
|
||||
// 获得父节点
|
||||
AdminsProductCategoryTreeNodeResponse parentNode = treeNodeMap.get(childNode.getPid());
|
||||
@ -61,7 +61,7 @@ public class AdminsProductCategoryController {
|
||||
});
|
||||
// 获得到所有的根节点
|
||||
List<AdminsProductCategoryTreeNodeResponse> rootNodes = treeNodeMap.values().stream()
|
||||
.filter(node -> node.getPid().equals(ProductCategoryConstants.PID_ROOT))
|
||||
.filter(node -> node.getPid().equals(ProductCategoryNodeEnum.ROOT.getId()))
|
||||
.sorted(Comparator.comparing(AdminsProductCategoryTreeNodeResponse::getSort))
|
||||
.collect(Collectors.toList());
|
||||
return success(rootNodes);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.mall.system.biz.dao.user;
|
||||
|
||||
import cn.iocoder.mall.mybatis.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.system.biz.dataobject.authorization.RoleDO;
|
||||
import cn.iocoder.mall.system.biz.dataobject.user.UserDO;
|
||||
import cn.iocoder.mall.system.biz.dto.user.UserPageDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@ -25,12 +27,11 @@ public interface UserMapper extends BaseMapper<UserDO> {
|
||||
* @return
|
||||
*/
|
||||
default IPage<UserDO> selectUserPage(UserPageDTO userPageDTO) {
|
||||
// TODO FROM 芋艿 to jwf1173:看下 QueryWrapperX 噢,已经提供判空啦
|
||||
// TODO FROM 伟帆 to 芋艿: 这里是使用MP原生的判空,支持lambda好,还是使用QueryWrapperX,使用字段名字符串的好呢;reply:没特别想好,现在建议还是 QueryWrapperX
|
||||
// TODO FROM 芋艿 to jwf1173:看下 QueryWrapperX 噢,已经提供判空啦 [DONE]
|
||||
return this.selectPage(new Page<>(userPageDTO.getPageNo(), userPageDTO.getPageSize()),
|
||||
Wrappers.<UserDO>query().lambda()
|
||||
.eq(StringUtils.isNotBlank(userPageDTO.getNickname()), UserDO::getNickname, userPageDTO.getNickname())
|
||||
.eq(null != userPageDTO.getStatus(), UserDO::getStatus, userPageDTO.getStatus())
|
||||
new QueryWrapperX<UserDO>()
|
||||
.eq(StringUtils.isNotBlank(userPageDTO.getNickname()), "nickname", userPageDTO.getNickname())
|
||||
.eq(null != userPageDTO.getStatus(), "status", userPageDTO.getStatus())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -137,6 +137,6 @@ public class ErrorCodeServiceImpl implements ErrorCodeService {
|
||||
list = list.subList(currentPage, currentPage + rows);
|
||||
}
|
||||
// TODO FROM 芋艿 to 鱿鱼丝:泛型噢
|
||||
return new PageResult().setList(list).setTotal(sum);
|
||||
return new PageResult().setList(list).setTotal(new Long(sum));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user