商品分类的迁移,继续未完成,继续先提交下~

This commit is contained in:
YunaiV
2020-07-25 00:10:10 +08:00
parent b209505f99
commit a99afdc833
44 changed files with 731 additions and 674 deletions

View File

@@ -0,0 +1,61 @@
package cn.iocoder.mall.productservice.rpc.category;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryCreateReqDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryUpdateReqDTO;
import java.util.List;
/**
* 商品分类 Rpc 接口
*/
public interface ProductCategoryRpc {
/**
* 创建商品分类
*
* @param createDTO 创建商品分类 DTO
* @return 商品分类编号
*/
CommonResult<Integer> createProductCategory(ProductCategoryCreateReqDTO createDTO);
/**
* 更新商品分类
*
* @param updateDTO 更新商品分类 DTO
*/
CommonResult<Boolean> updateProductCategory(ProductCategoryUpdateReqDTO updateDTO);
/**
* 删除商品分类
*
* @param productCategoryId 商品分类编号
*/
CommonResult<Boolean> deleteProductCategory(Integer productCategoryId);
/**
* 获得商品分类
*
* @param productCategoryId 商品分类编号
* @return 商品分类
*/
CommonResult<ProductCategoryRespDTO> getProductCategory(Integer productCategoryId);
/**
* 获得商品分类列表
*
* @param productCategoryIds 商品分类编号列表
* @return 商品分类列表
*/
CommonResult<List<ProductCategoryRespDTO>> listProductCategories(List<Integer> productCategoryIds);
/**
* 获得符合条件的商品分类列表
*
* @return 商品分类列表
*/
CommonResult<List<ProductCategoryRespDTO>> listProductCategories(ProductCategoryListQueryReqDTO listQueryReqDTO);
}

View File

@@ -0,0 +1,49 @@
package cn.iocoder.mall.productservice.rpc.category.dto;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 商品分类创建 Request DTO
*/
@Data
@Accessors(chain = true)
public class ProductCategoryCreateReqDTO implements Serializable {
/**
* 父分类编号
*/
@NotNull(message = "父分类编号不能为空")
private Integer pid;
/**
* 分类名称
*/
@NotEmpty(message = "分类名称不能为空")
private String name;
/**
* 分类描述
*/
private String description;
/**
* 分类图片
*/
private String picUrl;
/**
* 分类排序
*/
@NotNull(message = "分类排序不能为空")
private Integer sort;
/**
* 状态
*/
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
private Integer status;
}

View File

@@ -0,0 +1,18 @@
package cn.iocoder.mall.productservice.rpc.category.dto;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 商品分类列表查询 DTO
*/
@Data
@Accessors(chain = true)
public class ProductCategoryListQueryReqDTO {
/**
* 父编号
*/
private Integer pid;
}

View File

@@ -0,0 +1,49 @@
package cn.iocoder.mall.productservice.rpc.category.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* 商品分类 Response DTO
*/
@Data
@Accessors(chain = true)
public class ProductCategoryRespDTO implements Serializable {
/**
* 分类编号
*/
private Integer id;
/**
* 父分类编号
*/
private Integer pid;
/**
* 分类名称
*/
private String name;
/**
* 分类描述
*/
private String description;
/**
* 分类图片
*/
private String picUrl;
/**
* 分类排序
*/
private Integer sort;
/**
* 状态
*/
private Integer status;
/**
* 创建时间
*/
private Date createTime;
}

View File

@@ -0,0 +1,54 @@
package cn.iocoder.mall.productservice.rpc.category.dto;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 商品分类更新 Request DTO
*/
@Data
@Accessors(chain = true)
public class ProductCategoryUpdateReqDTO implements Serializable {
/**
* 分类编号
*/
@NotNull(message = "分类编号不能为空")
private Integer id;
/**
* 父分类编号
*/
@NotNull(message = "父分类编号不能为空")
private Integer pid;
/**
* 分类名称
*/
@NotEmpty(message = "分类名称不能为空")
private String name;
/**
* 分类描述
*/
private String description;
/**
* 分类图片
*/
private String picUrl;
/**
* 分类排序
*/
@NotNull(message = "分类排序不能为空")
private Integer sort;
/**
* 状态
*/
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}")
private Integer status;
}

View File

@@ -1,8 +1,13 @@
package cn.iocoder.mall.productservice.convert.category;
import cn.iocoder.mall.productservice.dal.mysql.dataobject.category.ProductCategoryDO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryCreateReqDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryUpdateReqDTO;
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryBO;
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryCreateBO;
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryListQueryBO;
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryUpdateBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@@ -22,4 +27,14 @@ public interface ProductCategoryConvert {
ProductCategoryDO convert(ProductCategoryUpdateBO bean);
ProductCategoryCreateBO convert(ProductCategoryCreateReqDTO bean);
ProductCategoryUpdateBO convert(ProductCategoryUpdateReqDTO bean);
ProductCategoryRespDTO convert(ProductCategoryBO bean);
List<ProductCategoryRespDTO> convertList02(List<ProductCategoryBO> list);
ProductCategoryListQueryBO convert(ProductCategoryListQueryReqDTO bean);
}

View File

@@ -9,7 +9,7 @@ import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* 商品分类
* 商品分类 DO
*/
@TableName("product_category")
@Data

View File

@@ -1,10 +1,14 @@
package cn.iocoder.mall.productservice.dal.mysql.mapper.category;
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
import cn.iocoder.mall.productservice.dal.mysql.dataobject.category.ProductCategoryDO;
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryListQueryBO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ProductCategoryMapper extends BaseMapper<ProductCategoryDO> {
@@ -12,4 +16,8 @@ public interface ProductCategoryMapper extends BaseMapper<ProductCategoryDO> {
return selectCount(new QueryWrapper<ProductCategoryDO>().eq("pid", pid));
}
default List<ProductCategoryDO> selectList(ProductCategoryListQueryBO listQueryBO) {
return selectList(new QueryWrapperX<ProductCategoryDO>().eqIfPresent("pid", listQueryBO.getPid()));
}
}

View File

@@ -0,0 +1,86 @@
package cn.iocoder.mall.productservice.manager.category;
import cn.iocoder.mall.productservice.convert.category.ProductCategoryConvert;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryCreateReqDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryUpdateReqDTO;
import cn.iocoder.mall.productservice.service.category.ProductCategoryService;
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 商品分类 Manager
*/
@Service
public class ProductCategoryManager {
@Autowired
private ProductCategoryService productCategoryService;
/**
* 创建商品分类
*
* @param createDTO 创建商品分类 DTO
* @return 商品分类
*/
public Integer createProductCategory(ProductCategoryCreateReqDTO createDTO) {
ProductCategoryBO productCategoryBO = productCategoryService.createProductCategory(ProductCategoryConvert.INSTANCE.convert(createDTO));
return productCategoryBO.getId();
}
/**
* 更新商品分类
*
* @param updateDTO 更新商品分类 DTO
*/
public void updateProductCategory(ProductCategoryUpdateReqDTO updateDTO) {
productCategoryService.updateProductCategory(ProductCategoryConvert.INSTANCE.convert(updateDTO));
}
/**
* 删除商品分类
*
* @param productCategoryId 商品分类编号
*/
public void deleteProductCategory(Integer productCategoryId) {
productCategoryService.deleteProductCategory(productCategoryId);
}
/**
* 获得商品分类
*
* @param productCategoryId 商品分类编号
* @return 商品分类
*/
public ProductCategoryRespDTO getProductCategory(Integer productCategoryId) {
ProductCategoryBO productCategoryBO = productCategoryService.getProductCategory(productCategoryId);
return ProductCategoryConvert.INSTANCE.convert(productCategoryBO);
}
/**
* 获得商品分类列表
*
* @param productCategoryIds 商品分类编号列表
* @return 商品分类列表
*/
public List<ProductCategoryRespDTO> listProductCategories(List<Integer> productCategoryIds) {
List<ProductCategoryBO> productCategoryBOs = productCategoryService.listProductCategories(productCategoryIds);
return ProductCategoryConvert.INSTANCE.convertList02(productCategoryBOs);
}
/**
* 获得商品分类全列表
*
* @return 商品分类全列表
*/
public List<ProductCategoryRespDTO> listProductCategories(ProductCategoryListQueryReqDTO listQueryReqDTO) {
List<ProductCategoryBO> productCategoryBOs = productCategoryService.listProductCategories(
ProductCategoryConvert.INSTANCE.convert(listQueryReqDTO));
return ProductCategoryConvert.INSTANCE.convertList02(productCategoryBOs);
}
}

View File

@@ -0,0 +1,57 @@
package cn.iocoder.mall.productservice.rpc.category;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.productservice.manager.category.ProductCategoryManager;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryCreateReqDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryUpdateReqDTO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* 商品分类 Rpc 实现类
*/
@DubboService(version = "${dubbo.provider.ProductCategoryRpc.version}")
public class ProductCategoryRpcImpl implements ProductCategoryRpc {
@Autowired
private ProductCategoryManager productCategoryManager;
@Override
public CommonResult<Integer> createProductCategory(ProductCategoryCreateReqDTO createDTO) {
return success(productCategoryManager.createProductCategory(createDTO));
}
@Override
public CommonResult<Boolean> updateProductCategory(ProductCategoryUpdateReqDTO updateDTO) {
productCategoryManager.updateProductCategory(updateDTO);
return success(true);
}
@Override
public CommonResult<Boolean> deleteProductCategory(Integer productCategoryId) {
productCategoryManager.deleteProductCategory(productCategoryId);
return success(true);
}
@Override
public CommonResult<ProductCategoryRespDTO> getProductCategory(Integer productCategoryId) {
return success(productCategoryManager.getProductCategory(productCategoryId));
}
@Override
public CommonResult<List<ProductCategoryRespDTO>> listProductCategories(List<Integer> productCategoryIds) {
return success(productCategoryManager.listProductCategories(productCategoryIds));
}
@Override
public CommonResult<List<ProductCategoryRespDTO>> listProductCategories(ProductCategoryListQueryReqDTO listQueryReqDTO) {
return success(productCategoryManager.listProductCategories(listQueryReqDTO));
}
}

View File

@@ -7,6 +7,7 @@ import cn.iocoder.mall.productservice.dal.mysql.mapper.category.ProductCategoryM
import cn.iocoder.mall.productservice.enums.category.ProductCategoryIdEnum;
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryBO;
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryCreateBO;
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryListQueryBO;
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryUpdateBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -18,7 +19,7 @@ import java.util.List;
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.*;
/**
* 商品分类 Service
* 商品分类 Service
*/
@Service
@Validated
@@ -28,10 +29,10 @@ public class ProductCategoryService {
private ProductCategoryMapper productCategoryMapper;
/**
* 创建商品分类
* 创建商品分类
*
* @param createBO 创建商品分类 BO
* @return 商品分类
* @param createBO 创建商品分类 BO
* @return 商品分类
*/
public ProductCategoryBO createProductCategory(@Valid ProductCategoryCreateBO createBO) {
// 校验父分类
@@ -44,9 +45,9 @@ public class ProductCategoryService {
}
/**
* 更新商品分类
* 更新商品分类
*
* @param updateBO 更新商品分类 BO
* @param updateBO 更新商品分类 BO
*/
public void updateProductCategory(@Valid ProductCategoryUpdateBO updateBO) {
// 校验父分类
@@ -55,7 +56,7 @@ public class ProductCategoryService {
if (updateBO.getId().equals(updateBO.getPid())) {
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_SELF);
}
// 校验更新的商品分类是否存在
// 校验更新的商品分类是否存在
if (productCategoryMapper.selectById(updateBO.getId()) == null) {
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
}
@@ -65,12 +66,12 @@ public class ProductCategoryService {
}
/**
* 删除商品分类
* 删除商品分类
*
* @param productCategoryId 商品分类编号
* @param productCategoryId 商品分类编号
*/
public void deleteProductCategory(Integer productCategoryId) {
// 校验删除的商品分类是否存在
// 校验删除的商品分类是否存在
if (productCategoryMapper.selectById(productCategoryId) == null) {
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
}
@@ -85,10 +86,10 @@ public class ProductCategoryService {
}
/**
* 获得商品分类
* 获得商品分类
*
* @param productCategoryId 商品分类编号
* @return 商品分类
* @param productCategoryId 商品分类编号
* @return 商品分类
*/
public ProductCategoryBO getProductCategory(Integer productCategoryId) {
ProductCategoryDO productCategoryDO = productCategoryMapper.selectById(productCategoryId);
@@ -96,16 +97,26 @@ public class ProductCategoryService {
}
/**
* 获得商品分类列表
* 获得商品分类列表
*
* @param productCategoryIds 商品分类编号列表
* @return 商品分类列表
* @param productCategoryIds 商品分类编号列表
* @return 商品分类列表
*/
public List<ProductCategoryBO> listProductCategories(List<Integer> productCategoryIds) {
List<ProductCategoryDO> productCategoryDOs = productCategoryMapper.selectBatchIds(productCategoryIds);
return ProductCategoryConvert.INSTANCE.convertList(productCategoryDOs);
}
/**
* 获得商品分类全列表
*
* @return 商品分类全列表
*/
public List<ProductCategoryBO> listProductCategories(ProductCategoryListQueryBO listQueryBO) {
List<ProductCategoryDO> resourceDOs = productCategoryMapper.selectList(listQueryBO);
return ProductCategoryConvert.INSTANCE.convertList(resourceDOs);
}
private void validParent(Integer pid) {
if (!ProductCategoryIdEnum.ROOT.getId().equals(pid)) {
ProductCategoryDO parentCategory = productCategoryMapper.selectById(pid);
@@ -120,10 +131,4 @@ public class ProductCategoryService {
}
}
// @Override
// public List<ProductCategoryBO> getListByPid(Integer pid) {
// List<ProductCategoryDO> categoryList = productCategoryMapper.selectListByPidAndStatusOrderBySort(pid, ProductCategoryConstants.STATUS_ENABLE);
// return ProductCategoryConvert.INSTANCE.convertToBO(categoryList);
// }
}

View File

@@ -6,7 +6,7 @@ import lombok.experimental.Accessors;
import java.util.Date;
/**
* 商品分类 BO
* 商品分类 BO
*/
@Data
@Accessors(chain = true)

View File

@@ -7,7 +7,7 @@ import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 商品分类创建 BO
* 商品分类创建 BO
*/
@Data
@Accessors(chain = true)

View File

@@ -0,0 +1,18 @@
package cn.iocoder.mall.productservice.service.category.bo;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 商品分类列表查询 BO
*/
@Data
@Accessors(chain = true)
public class ProductCategoryListQueryBO {
/**
* 父编号
*/
private Integer pid;
}

View File

@@ -7,7 +7,7 @@ import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 商品分类更新 BO
* 商品分类更新 BO
*/
@Data
@Accessors(chain = true)