From e47029cff26910b70e13e5da143306d1eb83131c Mon Sep 17 00:00:00 2001 From: jwf1173 <1553713823@qq.com> Date: Sat, 16 May 2020 16:43:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BBreview=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/ProductCategoryConstants.java | 20 ------- .../category/ProductCategoryNodeEnum.java | 28 ++++++++++ .../biz/bo/product/ProductCategoryBO.java | 55 ------------------- .../dao/category/ProductCategoryMapper.java | 12 +++- .../category/ProductCategoryServiceImpl.java | 17 +++--- .../service/spu/ProductSpuServiceImpl.java | 4 +- .../AdminsProductCategoryController.java | 6 +- .../mall/system/biz/dao/user/UserMapper.java | 11 ++-- .../errorcode/ErrorCodeServiceImpl.java | 2 +- 9 files changed, 58 insertions(+), 97 deletions(-) delete mode 100644 product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/category/ProductCategoryConstants.java create mode 100644 product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/category/ProductCategoryNodeEnum.java delete mode 100644 product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductCategoryBO.java diff --git a/product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/category/ProductCategoryConstants.java b/product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/category/ProductCategoryConstants.java deleted file mode 100644 index 396864266..000000000 --- a/product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/category/ProductCategoryConstants.java +++ /dev/null @@ -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; - -} diff --git a/product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/category/ProductCategoryNodeEnum.java b/product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/category/ProductCategoryNodeEnum.java new file mode 100644 index 000000000..9f32d1df7 --- /dev/null +++ b/product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/category/ProductCategoryNodeEnum.java @@ -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; + } +} diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductCategoryBO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductCategoryBO.java deleted file mode 100644 index 75e9e17c7..000000000 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductCategoryBO.java +++ /dev/null @@ -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; - -} diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dao/category/ProductCategoryMapper.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dao/category/ProductCategoryMapper.java index 792a19e81..1dd557202 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dao/category/ProductCategoryMapper.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dao/category/ProductCategoryMapper.java @@ -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 { - + /** + * 查询商品分类的下一级子分类数量 + * @param productCategoryId + * @return + */ + default Integer selectChildCategoryCount(Integer productCategoryId) { + return this.selectCount( + Wrappers.lambdaQuery().eq(ProductCategoryDO::getPid, productCategoryId) + ); + } } diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/category/ProductCategoryServiceImpl.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/category/ProductCategoryServiceImpl.java index 2d81f99fc..2a43d3abc 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/category/ProductCategoryServiceImpl.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/category/ProductCategoryServiceImpl.java @@ -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.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()); } // 返回结果 diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/spu/ProductSpuServiceImpl.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/spu/ProductSpuServiceImpl.java index a03d39452..5f3a6f601 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/spu/ProductSpuServiceImpl.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/spu/ProductSpuServiceImpl.java @@ -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()); } diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/category/AdminsProductCategoryController.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/category/AdminsProductCategoryController.java index daf7b64d9..77cb69d27 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/category/AdminsProductCategoryController.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/category/AdminsProductCategoryController.java @@ -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 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 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); diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java index bf45488df..fc636771f 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserMapper.java @@ -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 { * @return */ default IPage 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.query().lambda() - .eq(StringUtils.isNotBlank(userPageDTO.getNickname()), UserDO::getNickname, userPageDTO.getNickname()) - .eq(null != userPageDTO.getStatus(), UserDO::getStatus, userPageDTO.getStatus()) + new QueryWrapperX() + .eq(StringUtils.isNotBlank(userPageDTO.getNickname()), "nickname", userPageDTO.getNickname()) + .eq(null != userPageDTO.getStatus(), "status", userPageDTO.getStatus()) ); } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeServiceImpl.java index 192ea11ff..94db19942 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/errorcode/ErrorCodeServiceImpl.java @@ -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)); } }