迁移商品分类树节点及创建商品分类
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
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)
|
||||
public class ProductCategoryAddBO 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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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)
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import java.util.Date;
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Deprecated // TODO jiangweifan 后面确认无使用后删除
|
||||
public class ProductCategoryBO implements Serializable {
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
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.dataobject.product.ProductCategoryDO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryAddDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 商品分类 - 服务层数据转换
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProductCategoryConvert {
|
||||
|
||||
ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
|
||||
|
||||
/**
|
||||
* 商品分类列表 - DO转换BO 单实体
|
||||
* @param category
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
ProductCategoryAllListBO convertToAllListBO(ProductCategoryDO category);
|
||||
|
||||
|
||||
/**
|
||||
* 商品分类列表 - DO转换BO {@link #convertToAllListBO(ProductCategoryDO)}
|
||||
* @param category
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
List<ProductCategoryAllListBO> convertToAllListBO(List<ProductCategoryDO> category);
|
||||
|
||||
/**
|
||||
* 商品分类新增 - DTO转换DO
|
||||
* @param productCategoryAddDTO
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
ProductCategoryDO convertToDO(ProductCategoryAddDTO productCategoryAddDTO);
|
||||
|
||||
/**
|
||||
* 商品分类新增 - DO转换BO
|
||||
* @param category
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
ProductCategoryAddBO convertToAddBO(ProductCategoryDO category);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package cn.iocoder.mall.product.biz.convert.product;
|
||||
|
||||
import cn.iocoder.mall.product.biz.bo.product.ProductCategoryBO;
|
||||
import cn.iocoder.mall.product.biz.dataobject.product.ProductCategoryDO;
|
||||
import cn.iocoder.mall.product.biz.dto.product.ProductCategoryAddDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.product.ProductCategoryUpdateDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductCategoryConvert {
|
||||
|
||||
ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
ProductCategoryBO convertToBO(ProductCategoryDO category);
|
||||
|
||||
@Mappings({})
|
||||
List<ProductCategoryBO> convertToBO(List<ProductCategoryDO> categoryList);
|
||||
|
||||
@Mappings({})
|
||||
ProductCategoryDO convert(ProductCategoryAddDTO productCategoryAddDTO);
|
||||
|
||||
@Mappings({})
|
||||
ProductCategoryDO convert(ProductCategoryUpdateDTO productCategoryUpdateDTO);
|
||||
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
package cn.iocoder.mall.product.biz.dao.product;
|
||||
|
||||
import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO;
|
||||
import cn.iocoder.mall.product.biz.dataobject.product.ProductCategoryDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 商品分类数据持久层
|
||||
*/
|
||||
@Repository
|
||||
public interface ProductCategoryMapper extends BaseMapper<ProductBrandDO> {
|
||||
public interface ProductCategoryMapper extends BaseMapper<ProductCategoryDO> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
package cn.iocoder.mall.product.biz.dto.product;
|
||||
package cn.iocoder.mall.product.biz.dto.category;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品分类添加 DTO
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 商品分类 - 创建商品分类DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryAddDTO {
|
||||
|
||||
/**
|
||||
* 管理员id
|
||||
*/
|
||||
private Integer adminId;
|
||||
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
@NotNull(message = "父分类编号不能为空")
|
||||
private Integer pid;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@NotNull(message = "名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@NotNull(message = "描述不能为空")
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
// @NotNull(message = "分类图片不能为空")
|
||||
private String picUrl;
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
@NotNull(message = "排序值不能为空")
|
||||
private Integer sort;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
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.dto.category.ProductCategoryAddDTO;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 商品分类 - 服务层
|
||||
*/
|
||||
public interface ProductCategoryService {
|
||||
|
||||
/**
|
||||
* 获取所有商品分类
|
||||
* @return
|
||||
*/
|
||||
List<ProductCategoryAllListBO> getAllProductCategory();
|
||||
|
||||
/**
|
||||
* 新增商品分类
|
||||
* @param productCategoryAddDTO
|
||||
* @return
|
||||
*/
|
||||
ProductCategoryAddBO addProductCategory(ProductCategoryAddDTO productCategoryAddDTO);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
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.convert.category.ProductCategoryConvert;
|
||||
import cn.iocoder.mall.product.biz.dao.product.ProductCategoryMapper;
|
||||
import cn.iocoder.mall.product.biz.dataobject.product.ProductCategoryDO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryAddDTO;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 商品分类 - 服务实现层
|
||||
*/
|
||||
@Service
|
||||
public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
|
||||
@Autowired
|
||||
private ProductCategoryMapper productCategoryMapper;
|
||||
|
||||
/**
|
||||
* 获取所有商品分类
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ProductCategoryAllListBO> getAllProductCategory() {
|
||||
List<ProductCategoryDO> categoryList = productCategoryMapper.selectList(null);
|
||||
return ProductCategoryConvert.INSTANCE.convertToAllListBO(categoryList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增商品分类
|
||||
* @param productCategoryAddDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ProductCategoryAddBO addProductCategory(ProductCategoryAddDTO productCategoryAddDTO) {
|
||||
// 校验父分类
|
||||
validParent(productCategoryAddDTO.getPid());
|
||||
// 保存到数据库
|
||||
ProductCategoryDO productCategory = ProductCategoryConvert.INSTANCE.convertToDO(productCategoryAddDTO)
|
||||
.setStatus(ProductCategoryConstants.STATUS_ENABLE);
|
||||
productCategory.setCreateTime(new Date());
|
||||
productCategory.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
||||
productCategoryMapper.insert(productCategory);
|
||||
// TODO jiangweifan 操作日志
|
||||
// 返回成功
|
||||
return ProductCategoryConvert.INSTANCE.convertToAddBO(productCategory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验商品分类的父分类
|
||||
* @param pid
|
||||
*/
|
||||
private void validParent(Integer pid) {
|
||||
if (!ProductCategoryConstants.PID_ROOT.equals(pid)) {
|
||||
ProductCategoryDO parentCategory = productCategoryMapper.selectById(pid);
|
||||
// 校验父分类是否存在
|
||||
if (parentCategory == null) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_EXISTS.getCode());
|
||||
}
|
||||
// 父分类必须是一级分类
|
||||
if (!ProductCategoryConstants.PID_ROOT.equals(parentCategory.getPid())) {
|
||||
throw ServiceExceptionUtil.exception((ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2.getCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user