提交 0c328605 authored 作者: jiangweifan's avatar jiangweifan

商品分类review修改

上级 a3cbccec
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;
}
}
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;
}
......@@ -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 {
/**
* 分类编号
......
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<ProductCategoryAllListBO> convertToAllListBO(List<ProductCategoryDO> category);
List<ProductCategoryBO> convertToAllListBO(List<ProductCategoryDO> 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
......
......@@ -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;
}
......@@ -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;
}
......@@ -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;
}
......@@ -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;
}
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<ProductCategoryAllListBO> getAllProductCategory();
List<ProductCategoryBO> getAllProductCategory();
/**
* 新增商品分类
* @param productCategoryAddDTO
* @return
*/
ProductCategoryAddBO addProductCategory(ProductCategoryAddDTO productCategoryAddDTO);
ProductCategoryBO addProductCategory(ProductCategoryAddDTO productCategoryAddDTO);
/**
* 更新商品分类
......
......@@ -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<List<AdminsProductCategoryTreeNodeResponse>> tree() {
List<ProductCategoryAllListBO> productCategories = productCategoryService.getAllProductCategory();
List<ProductCategoryBO> productCategories = productCategoryService.getAllProductCategory();
// 创建 ProductCategoryTreeNodeVO Map
Map<Integer, AdminsProductCategoryTreeNodeResponse> treeNodeMap = productCategories.stream().collect(Collectors.toMap(ProductCategoryAllListBO::getId, ProductCategoryConvert.INSTANCE::convertToTreeNodeResponse));
Map<Integer, AdminsProductCategoryTreeNodeResponse> 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));
}
......
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
......
......@@ -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;
}
......@@ -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;
}
......@@ -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;
}
......@@ -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;
......
......@@ -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<AdminsProductCategoryTreeNodeResponse> children;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论