From 0c328605b72f53ebe921134efc77bea86a49d3f0 Mon Sep 17 00:00:00 2001 From: jiangweifan <1553713823@qq.com> Date: Fri, 8 May 2020 12:07:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BBreview?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/enums/ProductErrorCodeEnum.java | 12 ++-- .../bo/category/ProductCategoryAllListBO.java | 56 ------------------- ...egoryAddBO.java => ProductCategoryBO.java} | 6 +- .../category/ProductCategoryConvert.java | 19 ++----- .../dto/category/ProductCategoryAddDTO.java | 9 ++- .../category/ProductCategoryDeleteDTO.java | 4 ++ .../category/ProductCategoryUpdateDTO.java | 8 +++ .../ProductCategoryUpdateStatusDTO.java | 5 ++ .../product/ProductCategoryService.java | 8 +-- .../impl/ProductCategoryServiceImpl.java | 55 +++++++++--------- .../AdminsProductCategoryController.java | 9 ++- .../category/ProductCategoryConvert.java | 8 +-- .../AdminsProductCategoryAddRequest.java | 25 ++------- .../AdminsProductCategoryUpdateRequest.java | 29 ++-------- ...insProductCategoryUpdateStatusRequest.java | 10 +--- .../AdminsProductCategoryAddResponse.java | 7 +++ ...AdminsProductCategoryTreeNodeResponse.java | 8 +++ 17 files changed, 106 insertions(+), 172 deletions(-) delete mode 100644 product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/category/ProductCategoryAllListBO.java rename product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/category/{ProductCategoryAddBO.java => ProductCategoryBO.java} (88%) diff --git a/product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/ProductErrorCodeEnum.java b/product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/ProductErrorCodeEnum.java index e5ad307c8..f2e7c10ae 100644 --- a/product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/ProductErrorCodeEnum.java +++ b/product/product-biz-api/src/main/java/cn/iocoder/mall/product/biz/enums/ProductErrorCodeEnum.java @@ -1,11 +1,13 @@ package cn.iocoder.mall.product.biz.enums; +import cn.iocoder.common.framework.util.ServiceExceptionUtil; + /** * 错误码枚举类 * * 商品系统,使用 1-003-000-000 段 */ -public enum ProductErrorCodeEnum { +public enum ProductErrorCodeEnum implements ServiceExceptionUtil.Enumerable { // ========== PRODUCT CATEGORY 模块 ========== PRODUCT_CATEGORY_PARENT_NOT_EXISTS(1003001000, "父分类不存在"), @@ -45,12 +47,12 @@ public enum ProductErrorCodeEnum { this.message = message; } - public int getCode() { - return code; - } - public String getMessage() { return message; } + @Override + public int getCode() { + return code; + } } diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/category/ProductCategoryAllListBO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/category/ProductCategoryAllListBO.java deleted file mode 100644 index 9d6666e5e..000000000 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/category/ProductCategoryAllListBO.java +++ /dev/null @@ -1,56 +0,0 @@ -package cn.iocoder.mall.product.biz.bo.category; - -import lombok.Data; -import lombok.experimental.Accessors; -import java.io.Serializable; -import java.util.Date; - -/** - * @Author: jiangweifan - * @Date: 2020/5/6 - * @Description: 商品分类 - 商品分类列表BO - */ -@Data -@Accessors(chain = true) -// TODO FROM 芋艿 to 伟帆, -public class ProductCategoryAllListBO 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/bo/category/ProductCategoryAddBO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/category/ProductCategoryBO.java similarity index 88% rename from product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/category/ProductCategoryAddBO.java rename to product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/category/ProductCategoryBO.java index 569d72d24..1b918d4ab 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/category/ProductCategoryAddBO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/category/ProductCategoryBO.java @@ -8,12 +8,12 @@ import java.util.Date; /** * @Author: jiangweifan * @Date: 2020/5/6 - * @Description: 商品分类 - 创建商品分类BO + * @Description: 商品分类 - 商品分类统一BO */ @Data @Accessors(chain = true) -// TODO FROM 芋艿 to 伟帆,BO 可以不加 Serializable 接口,因为没序列化的诉求哈。一般 BO 可以创建一个统一的 ProductCategory,可以把 ProductCategoryAllListBO 合并过来 -public class ProductCategoryAddBO implements Serializable { +// TODO FROM 芋艿 to 伟帆,BO 可以不加 Serializable 接口,因为没序列化的诉求哈。一般 BO 可以创建一个统一的 ProductCategory,可以把 ProductCategoryAllListBO 合并过来 [DONE] +public class ProductCategoryBO { /** * 分类编号 diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/convert/category/ProductCategoryConvert.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/convert/category/ProductCategoryConvert.java index e19de6c07..8bcdba78d 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/convert/category/ProductCategoryConvert.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/convert/category/ProductCategoryConvert.java @@ -1,12 +1,10 @@ package cn.iocoder.mall.product.biz.convert.category; -import cn.iocoder.mall.product.biz.bo.category.ProductCategoryAddBO; -import cn.iocoder.mall.product.biz.bo.category.ProductCategoryAllListBO; +import cn.iocoder.mall.product.biz.bo.category.ProductCategoryBO; import cn.iocoder.mall.product.biz.dataobject.product.ProductCategoryDO; import cn.iocoder.mall.product.biz.dto.category.ProductCategoryAddDTO; import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateDTO; import org.mapstruct.Mapper; -import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; import java.util.List; @@ -21,19 +19,19 @@ public interface ProductCategoryConvert { ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class); /** - * 商品分类列表 - DO转换BO 单实体 + * 商品分类统一DO转BO * @param category * @return */ - ProductCategoryAllListBO convertToAllListBO(ProductCategoryDO category); + ProductCategoryBO convertToBO(ProductCategoryDO category); /** - * 商品分类列表 - DO转换BO {@link #convertToAllListBO(ProductCategoryDO)} + * 商品分类列表 - DO转换BO {@link #convertToBO(ProductCategoryDO)} * @param category * @return */ - List convertToAllListBO(List category); + List convertToAllListBO(List category); /** * 新增商品分类 - DTO转换DO @@ -42,13 +40,6 @@ public interface ProductCategoryConvert { */ ProductCategoryDO convertToDO(ProductCategoryAddDTO productCategoryAddDTO); - /** - * 新增商品分类 - DO转换BO - * @param category - * @return - */ - ProductCategoryAddBO convertToAddBO(ProductCategoryDO category); - /** * 更新商品分类 - DTO转换DO * @param productCategoryUpdateDTO diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryAddDTO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryAddDTO.java index 2a78ceac3..8d0a8f389 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryAddDTO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryAddDTO.java @@ -3,6 +3,8 @@ package cn.iocoder.mall.product.biz.dto.category; import lombok.Data; import lombok.experimental.Accessors; +import javax.validation.constraints.NotNull; + /** * @Author: jiangweifan * @Date: 2020/5/6 @@ -15,20 +17,24 @@ public class ProductCategoryAddDTO { /** * 管理员id */ - // TODO FROM 芋艿 to 伟帆:传入 Service 的,要加下 Validation 的注解,虽然 Controller 那也添加了 Validation,但是相比来说,Service 更应该被保护,嘿嘿。因为一些时候,Service 也会被别人所调用,所以要保护好自己。 + // TODO FROM 芋艿 to 伟帆:传入 Service 的,要加下 Validation 的注解,虽然 Controller 那也添加了 Validation,但是相比来说,Service 更应该被保护,嘿嘿。因为一些时候,Service 也会被别人所调用,所以要保护好自己。[DONE] + @NotNull(message = "管理员id不能为空") private Integer adminId; /** * 父分类编号 */ + @NotNull(message = "父分类编号不能为空") private Integer pid; /** * 名称 */ + @NotNull(message = "名称不能为空") private String name; /** * 描述 */ + @NotNull(message = "描述不能为空") private String description; /** * 分类图片 @@ -37,6 +43,7 @@ public class ProductCategoryAddDTO { /** * 排序值 */ + @NotNull(message = "排序值不能为空") private Integer sort; } diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryDeleteDTO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryDeleteDTO.java index d594f0afc..0f48ee4ca 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryDeleteDTO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryDeleteDTO.java @@ -3,6 +3,8 @@ package cn.iocoder.mall.product.biz.dto.category; import lombok.Data; import lombok.experimental.Accessors; +import javax.validation.constraints.NotNull; + /** * @Author: jiangweifan * @Date: 2020/5/6 @@ -15,10 +17,12 @@ public class ProductCategoryDeleteDTO { /** * 管理员id */ + @NotNull(message = "管理员id不能为空") private Integer adminId; /** * 商品分类编号 */ + @NotNull(message = "编号不能为空") private Integer id; } diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryUpdateDTO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryUpdateDTO.java index 66310170d..e007878b0 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryUpdateDTO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryUpdateDTO.java @@ -3,6 +3,8 @@ package cn.iocoder.mall.product.biz.dto.category; import lombok.Data; import lombok.experimental.Accessors; +import javax.validation.constraints.NotNull; + /** * @Author: jiangweifan * @Date: 2020/5/6 @@ -15,22 +17,27 @@ public class ProductCategoryUpdateDTO { /** * 管理员id */ + @NotNull(message = "管理员id不能为空") private Integer adminId; /** * 编号 */ + @NotNull(message = "编号不能为空") private Integer id; /** * 父分类编号 */ + @NotNull(message = "父分类编号不能为空") private Integer pid; /** * 名称 */ + @NotNull(message = "名称不能为空") private String name; /** * 描述 */ + @NotNull(message = "描述不能为空") private String description; /** * 分类图片 @@ -39,6 +46,7 @@ public class ProductCategoryUpdateDTO { /** * 排序值 */ + @NotNull(message = "描述不能为空") private Integer sort; } diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryUpdateStatusDTO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryUpdateStatusDTO.java index 1f7a68bac..9bd7f57e7 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryUpdateStatusDTO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/category/ProductCategoryUpdateStatusDTO.java @@ -3,6 +3,8 @@ package cn.iocoder.mall.product.biz.dto.category; import lombok.Data; import lombok.experimental.Accessors; +import javax.validation.constraints.NotNull; + /** * @Author: jiangweifan * @Date: 2020/5/6 @@ -15,14 +17,17 @@ public class ProductCategoryUpdateStatusDTO { /** * 管理员id */ + @NotNull(message = "管理员id不能为空") private Integer adminId; /** * 商品分类编号 */ + @NotNull(message = "编号不能为空") private Integer id; /** * 状态 */ + @NotNull(message = "状态不能为空") private Integer status; } diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductCategoryService.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductCategoryService.java index e08b680e5..624ae9689 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductCategoryService.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductCategoryService.java @@ -1,12 +1,10 @@ package cn.iocoder.mall.product.biz.service.product; -import cn.iocoder.mall.product.biz.bo.category.ProductCategoryAddBO; -import cn.iocoder.mall.product.biz.bo.category.ProductCategoryAllListBO; +import cn.iocoder.mall.product.biz.bo.category.ProductCategoryBO; 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 java.util.List; @@ -21,14 +19,14 @@ public interface ProductCategoryService { * 获取所有商品分类 * @return */ - List getAllProductCategory(); + List getAllProductCategory(); /** * 新增商品分类 * @param productCategoryAddDTO * @return */ - ProductCategoryAddBO addProductCategory(ProductCategoryAddDTO productCategoryAddDTO); + ProductCategoryBO addProductCategory(ProductCategoryAddDTO productCategoryAddDTO); /** * 更新商品分类 diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductCategoryServiceImpl.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductCategoryServiceImpl.java index 7f2148fa1..180bbbe82 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductCategoryServiceImpl.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductCategoryServiceImpl.java @@ -2,8 +2,7 @@ package cn.iocoder.mall.product.biz.service.product.impl; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum; -import cn.iocoder.mall.product.biz.bo.category.ProductCategoryAddBO; -import cn.iocoder.mall.product.biz.bo.category.ProductCategoryAllListBO; +import cn.iocoder.mall.product.biz.bo.category.ProductCategoryBO; import cn.iocoder.mall.product.biz.convert.category.ProductCategoryConvert; import cn.iocoder.mall.product.biz.dao.product.ProductCategoryMapper; import cn.iocoder.mall.product.biz.dataobject.product.ProductCategoryDO; @@ -11,13 +10,14 @@ 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.ProductErrorCodeEnum; import cn.iocoder.mall.product.biz.enums.product.ProductCategoryConstants; import cn.iocoder.mall.product.biz.service.product.ProductCategoryService; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; - +import org.springframework.validation.annotation.Validated; +import static cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum.*; +import javax.validation.Valid; import java.util.Date; import java.util.List; @@ -27,6 +27,7 @@ import java.util.List; * @Description: 商品分类 - 服务实现层 */ @Service +@Validated public class ProductCategoryServiceImpl implements ProductCategoryService { @Autowired @@ -37,7 +38,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { * @return */ @Override - public List getAllProductCategory() { + public List getAllProductCategory() { List categoryList = productCategoryMapper.selectList(null); return ProductCategoryConvert.INSTANCE.convertToAllListBO(categoryList); } @@ -48,7 +49,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { * @return */ @Override - public ProductCategoryAddBO addProductCategory(ProductCategoryAddDTO productCategoryAddDTO) { + public ProductCategoryBO addProductCategory(@Valid ProductCategoryAddDTO productCategoryAddDTO) { // 校验父分类 validParent(productCategoryAddDTO.getPid()); // 保存到数据库 @@ -57,9 +58,9 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { productCategory.setCreateTime(new Date()); productCategory.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); productCategoryMapper.insert(productCategory); - // TODO jiangweifan 操作日志 + // TODO 伟帆 操作日志 // 返回成功 - return ProductCategoryConvert.INSTANCE.convertToAddBO(productCategory); + return ProductCategoryConvert.INSTANCE.convertToBO(productCategory); } /** @@ -68,26 +69,26 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { * @return */ @Override - public Boolean updateProductCategory(ProductCategoryUpdateDTO productCategoryUpdateDTO) { + public Boolean updateProductCategory(@Valid ProductCategoryUpdateDTO productCategoryUpdateDTO) { // 校验当前分类是否存在 if (productCategoryMapper.selectById(productCategoryUpdateDTO.getId()) == null) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS); } // 校验父分类 validParent(productCategoryUpdateDTO.getPid()); // 校验不能设置自己为父分类 if (productCategoryUpdateDTO.getId().equals(productCategoryUpdateDTO.getPid())) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_SELF.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_SELF); } // 校验父分类是否存在 if (!ProductCategoryConstants.PID_ROOT.equals(productCategoryUpdateDTO.getPid()) && productCategoryMapper.selectById(productCategoryUpdateDTO.getPid()) == null) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS); } // 更新到数据库 ProductCategoryDO productCategoryDO = ProductCategoryConvert.INSTANCE.convertToDO(productCategoryUpdateDTO); productCategoryMapper.updateById(productCategoryDO); - // TODO jiangweifan 操作日志 + // TODO 伟帆 操作日志 return true; } @@ -97,27 +98,27 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { * @return */ @Override - public Boolean updateProductCategoryStatus(ProductCategoryUpdateStatusDTO productCategoryUpdateStatusDTO) { + public Boolean updateProductCategoryStatus(@Valid ProductCategoryUpdateStatusDTO productCategoryUpdateStatusDTO) { Integer productCategoryId = productCategoryUpdateStatusDTO.getId(); Integer status = productCategoryUpdateStatusDTO.getStatus(); // 校验商品分类是否存在 ProductCategoryDO productCategoryDO = productCategoryMapper.selectById(productCategoryId); if (productCategoryDO == null) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS); } // 判断更新状态是否存在 if (!ProductCategoryConstants.STATUS_ENABLE.equals(status) && !ProductCategoryConstants.STATUS_DISABLE.equals(status)) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_STATUS_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_STATUS_NOT_EXISTS); } // 如果状态相同,则返回错误 if (productCategoryDO.getStatus().equals(status)) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_STATUS_EQUALS.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_STATUS_EQUALS); } // 更新商品分类 productCategoryDO.setId(productCategoryId).setStatus(status); productCategoryMapper.updateById(productCategoryDO); - // TODO jiangweifan 操作日志 + // TODO 伟帆 操作日志 return true; } @@ -127,31 +128,31 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { * @return */ @Override - public Boolean deleteProductCategory(ProductCategoryDeleteDTO productCategoryDeleteDTO) { + public Boolean deleteProductCategory(@Valid ProductCategoryDeleteDTO productCategoryDeleteDTO) { Integer productCategoryId = productCategoryDeleteDTO.getId(); // 校验分类是否存在 ProductCategoryDO productCategory = productCategoryMapper.selectById(productCategoryId); if (productCategory == null) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS); } // 只有禁用的商品分类才可以删除 if (ProductCategoryConstants.STATUS_ENABLE.equals(productCategory.getStatus())) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_DELETE_ONLY_DISABLE.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_DELETE_ONLY_DISABLE); } // 只有不存在子分类才可以删除 Integer childCount = productCategoryMapper.selectCount( Wrappers.lambdaQuery().eq(ProductCategoryDO::getPid, productCategoryId) ); if (childCount > 0) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_DELETE_ONLY_NO_CHILD.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_DELETE_ONLY_NO_CHILD); } - // TODO jiangweifan 补充只有不存在商品才可以删除 + // TODO 伟帆 补充只有不存在商品才可以删除 // 标记删除商品分类 ProductCategoryDO updateProductCategory = new ProductCategoryDO() .setId(productCategoryId); updateProductCategory.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); productCategoryMapper.updateById(updateProductCategory); - // TODO jiangweifan 操作日志 + // TODO 伟帆 操作日志 return true; } @@ -164,12 +165,12 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { ProductCategoryDO parentCategory = productCategoryMapper.selectById(pid); // 校验父分类是否存在 if (parentCategory == null) { - throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS); } // 父分类必须是一级分类 if (!ProductCategoryConstants.PID_ROOT.equals(parentCategory.getPid())) { - // TODO FROM 芋艿 to 伟帆,ProductErrorCodeEnum 去实现下 ServiceExceptionUtil.Enumerable 接口,酱紫就不用 .getCode() 方法,代码会更简洁。同时,可以把 ProductErrorCodeEnum static import 下, - throw ServiceExceptionUtil.exception((ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2.getCode())); + // TODO FROM 芋艿 to 伟帆,ProductErrorCodeEnum 去实现下 ServiceExceptionUtil.Enumerable 接口,酱紫就不用 .getCode() 方法,代码会更简洁。同时,可以把 ProductErrorCodeEnum static import 下,[DONE] + throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2); } } } diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductCategoryController.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductCategoryController.java index 658b5a0ac..3ce92f8de 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductCategoryController.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductCategoryController.java @@ -2,8 +2,7 @@ package cn.iocoder.mall.product.rest.controller.admins; import cn.iocoder.common.framework.constant.MallConstants; import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.product.biz.bo.category.ProductCategoryAddBO; -import cn.iocoder.mall.product.biz.bo.category.ProductCategoryAllListBO; +import cn.iocoder.mall.product.biz.bo.category.ProductCategoryBO; 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; @@ -45,9 +44,9 @@ public class AdminsProductCategoryController { @GetMapping("/tree") @ApiOperation("获取分类树结构") public CommonResult> tree() { - List productCategories = productCategoryService.getAllProductCategory(); + List productCategories = productCategoryService.getAllProductCategory(); // 创建 ProductCategoryTreeNodeVO Map - Map treeNodeMap = productCategories.stream().collect(Collectors.toMap(ProductCategoryAllListBO::getId, ProductCategoryConvert.INSTANCE::convertToTreeNodeResponse)); + Map treeNodeMap = productCategories.stream().collect(Collectors.toMap(ProductCategoryBO::getId, ProductCategoryConvert.INSTANCE::convertToTreeNodeResponse)); // 处理父子关系 treeNodeMap.values().stream() .filter(node -> !node.getPid().equals(ProductCategoryConstants.PID_ROOT)) @@ -74,7 +73,7 @@ public class AdminsProductCategoryController { // 转换 ProductCategoryAddDTO 对象 ProductCategoryAddDTO productCategoryAddDTO = ProductCategoryConvert.INSTANCE.convertToAddDTO(AdminSecurityContextHolder.getContext().getAdminId(), adminsProductCategoryAddRequest); // 创建商品分类 - ProductCategoryAddBO addProductCategoryBO = productCategoryService.addProductCategory(productCategoryAddDTO); + ProductCategoryBO addProductCategoryBO = productCategoryService.addProductCategory(productCategoryAddDTO); // 返回结果 return success(ProductCategoryConvert.INSTANCE.convertToAddResponse(addProductCategoryBO)); } diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/category/ProductCategoryConvert.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/category/ProductCategoryConvert.java index a300108bf..50cddef0b 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/category/ProductCategoryConvert.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/category/ProductCategoryConvert.java @@ -1,7 +1,6 @@ package cn.iocoder.mall.product.rest.convert.category; -import cn.iocoder.mall.product.biz.bo.category.ProductCategoryAddBO; -import cn.iocoder.mall.product.biz.bo.category.ProductCategoryAllListBO; +import cn.iocoder.mall.product.biz.bo.category.ProductCategoryBO; 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; @@ -12,7 +11,6 @@ import cn.iocoder.mall.product.rest.request.category.AdminsProductCategoryUpdate import cn.iocoder.mall.product.rest.response.category.AdminsProductCategoryAddResponse; import cn.iocoder.mall.product.rest.response.category.AdminsProductCategoryTreeNodeResponse; import org.mapstruct.Mapper; -import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; /** @@ -30,7 +28,7 @@ public interface ProductCategoryConvert { * @param productCategoryAllListBO * @return */ - AdminsProductCategoryTreeNodeResponse convertToTreeNodeResponse(ProductCategoryAllListBO productCategoryAllListBO); + AdminsProductCategoryTreeNodeResponse convertToTreeNodeResponse(ProductCategoryBO productCategoryAllListBO); /** @@ -45,7 +43,7 @@ public interface ProductCategoryConvert { * @param productCategoryAddBO * @return */ - AdminsProductCategoryAddResponse convertToAddResponse(ProductCategoryAddBO productCategoryAddBO); + AdminsProductCategoryAddResponse convertToAddResponse(ProductCategoryBO productCategoryAddBO); /** * 更新商品分类 - Request转DTO diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryAddRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryAddRequest.java index 3e6c8920d..565be064d 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryAddRequest.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryAddRequest.java @@ -17,34 +17,19 @@ import javax.validation.constraints.NotNull; @Accessors(chain = true) public class AdminsProductCategoryAddRequest { - // TODO FROM 芋艿 to 伟帆:写了 swagger 注解,我们可以少写一份 Java 注释。 - /** - * 父分类编号 - */ + // TODO FROM 芋艿 to 伟帆:写了 swagger 注解,我们可以少写一份 Java 注释。[DONE] @ApiModelProperty(name = "pid", value = "父级分类编号", required = true, example = "1") - @NotNull(message = "父分类编号不能为空") private Integer pid; - /** - * 名称 - */ + @ApiModelProperty(name = "name", value = "分类名字(标识)", required = true, example = "admin/info") - @NotNull(message = "名称不能为空") private String name; - /** - * 描述 - */ + @ApiModelProperty(name = "description", value = "描述", required = true, example = "1") - @NotNull(message = "描述不能为空") private String description; - /** - * 分类图片 - */ + @ApiModelProperty(name = "picUrl", value = "分类图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg/") private String picUrl; - /** - * 排序值 - */ + @ApiModelProperty(name = "sort", value = "排序", required = true, example = "1") - @NotNull(message = "排序值不能为空") private Integer sort; } diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryUpdateRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryUpdateRequest.java index e96799935..db28ab019 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryUpdateRequest.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryUpdateRequest.java @@ -16,39 +16,22 @@ import javax.validation.constraints.NotNull; @Data @Accessors(chain = true) public class AdminsProductCategoryUpdateRequest { - /** - * 编号 - */ + @ApiModelProperty(name = "id", value = "分类编号", required = true, example = "1") - @NotNull(message = "编号不能为空") private Integer id; - /** - * 父分类编号 - */ + @ApiModelProperty(name = "pid", value = "父级分类编号", required = true, example = "1") - @NotNull(message = "父分类编号不能为空") private Integer pid; - /** - * 名称 - */ + @ApiModelProperty(name = "name", value = "分类名字(标识)", required = true, example = "admin/info") - @NotNull(message = "名称不能为空") private String name; - /** - * 描述 - */ + @ApiModelProperty(name = "description", value = "描述", required = true, example = "1") - @NotNull(message = "描述不能为空") private String description; - /** - * 分类图片 - */ + @ApiModelProperty(name = "picUrl", value = "分类图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg/") private String picUrl; - /** - * 排序值 - */ + @ApiModelProperty(name = "sort", value = "排序", required = true, example = "1") - @NotNull(message = "排序值不能为空") private Integer sort; } diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryUpdateStatusRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryUpdateStatusRequest.java index 8777902a1..01b2d773f 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryUpdateStatusRequest.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/category/AdminsProductCategoryUpdateStatusRequest.java @@ -16,16 +16,10 @@ import javax.validation.constraints.NotNull; @Data @Accessors(chain = true) public class AdminsProductCategoryUpdateStatusRequest { - /** - * 商品分类编号 - */ + @ApiModelProperty(name = "id", value = "分类编号", required = true, example = "1") - @NotNull(message = "编号不能为空") private Integer id; - /** - * 更新状态 - */ + @ApiModelProperty(name = "status", value = "状态。1 - 开启;2 - 禁用", required = true, example = "1") - @NotNull(message = "状态不能为空") private Integer status; } diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/category/AdminsProductCategoryAddResponse.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/category/AdminsProductCategoryAddResponse.java index b4ebff33a..b86b6e2aa 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/category/AdminsProductCategoryAddResponse.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/category/AdminsProductCategoryAddResponse.java @@ -18,18 +18,25 @@ public class AdminsProductCategoryAddResponse { @ApiModelProperty(value = "分类编号", required = true, example = "1") private Integer id; + @ApiModelProperty(value = "父分类编号", required = true, example = "0") private Integer pid; + @ApiModelProperty(value = "分类名", required = true, example = "手机") private String name; + @ApiModelProperty(value = "描述", required = true, example = "这个商品很吊") private String description; + @ApiModelProperty(value = "分类图片", notes = "一般情况下,只有根分类才有图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") private String picUrl; + @ApiModelProperty(value = "排序值", required = true, example = "10") private Integer sort; + @ApiModelProperty(value = "状态", required = true, notes = "1-开启;2-关闭", example = "1") private Integer status; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳") private Date createTime; diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/category/AdminsProductCategoryTreeNodeResponse.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/category/AdminsProductCategoryTreeNodeResponse.java index 2fec71cd7..24ed628ad 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/category/AdminsProductCategoryTreeNodeResponse.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/category/AdminsProductCategoryTreeNodeResponse.java @@ -20,20 +20,28 @@ public class AdminsProductCategoryTreeNodeResponse { @ApiModelProperty(value = "分类编号", required = true, example = "1") private Integer id; + @ApiModelProperty(value = "父分类编号", required = true, example = "0") private Integer pid; + @ApiModelProperty(value = "分类名", required = true, example = "手机") private String name; + @ApiModelProperty(value = "描述", required = true, example = "这个商品很吊") private String description; + @ApiModelProperty(value = "分类图片", notes = "一般情况下,只有根分类才有图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") private String picUrl; + @ApiModelProperty(value = "排序值", required = true, example = "10") private Integer sort; + @ApiModelProperty(value = "状态", required = true, notes = "1-开启;2-关闭", example = "1") private Integer status; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳") private Date createTime; + @ApiModelProperty(value = "子节点数组") private List children;