商品分类的迁移,继续未完成,继续先提交下~
This commit is contained in:
parent
b209505f99
commit
a99afdc833
|
@ -60,6 +60,12 @@
|
|||
<artifactId>system-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- 商品服务 -->
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>product-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Registry 和 Config 相关 -->
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package cn.iocoder.mall.managementweb.controller.product;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.category.ProductCategoryCreateReqVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.category.ProductCategoryUpdateReqVO;
|
||||
import cn.iocoder.mall.managementweb.manager.product.ProductCategoryManager;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 商品分类 Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/product_category")
|
||||
@Api(tags = "商品分类")
|
||||
@Validated
|
||||
public class ProductCategoryController {
|
||||
|
||||
@Autowired
|
||||
private ProductCategoryManager productCategoryManager;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建商品分类")
|
||||
public CommonResult<Integer> createProductCategory(@Valid ProductCategoryCreateReqVO createVO) {
|
||||
return success(productCategoryManager.createProductCategory(createVO));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("更新商品分类")
|
||||
public CommonResult<Boolean> updateProductCategory(@Valid ProductCategoryUpdateReqVO updateVO) {
|
||||
productCategoryManager.updateProductCategory(updateVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除商品分类")
|
||||
@ApiImplicitParam(name = "productCategoryId", value = "商品分类编号", required = true)
|
||||
public CommonResult<Boolean> deleteProductCategory(@RequestParam("productCategoryId") Integer productCategoryId) {
|
||||
productCategoryManager.deleteProductCategory(productCategoryId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package cn.iocoder.mall.managementweb.controller.product.vo.category;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("商品分类创建 Request VO")
|
||||
@Data
|
||||
public class ProductCategoryCreateReqVO {
|
||||
|
||||
@ApiModelProperty(value = "父分类编号", required = true, example = "0")
|
||||
@NotNull(message = "父分类编号不能为空")
|
||||
private Integer pid;
|
||||
@ApiModelProperty(value = "分类名称", required = true, example = "手机")
|
||||
@NotEmpty(message = "分类名称不能为空")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "分类描述", required = true, example = "这个商品很吊")
|
||||
private String description;
|
||||
@ApiModelProperty(value = "分类图片", notes = "一般情况下,只有根分类才有图片", example = "http://www.iocoder.cn/xx.jpg")
|
||||
private String picUrl;
|
||||
@ApiModelProperty(value = "分类排序", required = true, example = "10")
|
||||
@NotNull(message = "分类排序不能为空")
|
||||
private Integer sort;
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package cn.iocoder.mall.managementweb.controller.product.vo.category;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel("商品分类 Response VO")
|
||||
@Data
|
||||
public class ProductCategoryRespVO {
|
||||
|
||||
@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/xx.jpg")
|
||||
private String picUrl;
|
||||
@ApiModelProperty(value = "分类排序", required = true, example = "10")
|
||||
private Integer sort;
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||
private Integer status;
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package cn.iocoder.mall.managementweb.controller.product.vo.category;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel("商品分类 Response VO")
|
||||
@Data
|
||||
public class ProductCategoryTreeNodeRespVO {
|
||||
|
||||
@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/xx.jpg")
|
||||
private String picUrl;
|
||||
@ApiModelProperty(value = "分类排序", required = true, example = "10")
|
||||
private Integer sort;
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 子节点
|
||||
*/
|
||||
private List<ProductCategoryTreeNodeRespVO> children;
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package cn.iocoder.mall.managementweb.controller.product.vo.category;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("商品分类更新 Request VO")
|
||||
@Data
|
||||
public class ProductCategoryUpdateReqVO {
|
||||
|
||||
@ApiModelProperty(value = "分类编号", required = true, example = "1")
|
||||
@NotNull(message = "分类编号不能为空")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "父分类编号", required = true, example = "0")
|
||||
@NotNull(message = "父分类编号不能为空")
|
||||
private Integer pid;
|
||||
@ApiModelProperty(value = "分类名称", required = true, example = "手机")
|
||||
@NotEmpty(message = "分类名称不能为空")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "分类描述", required = true, example = "这个商品很吊")
|
||||
private String description;
|
||||
@ApiModelProperty(value = "分类图片", notes = "一般情况下,只有根分类才有图片", example = "http://www.iocoder.cn/xx.jpg")
|
||||
private String picUrl;
|
||||
@ApiModelProperty(value = "分类排序", required = true, example = "10")
|
||||
@NotNull(message = "分类排序不能为空")
|
||||
private Integer sort;
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package cn.iocoder.mall.managementweb.convert.product;
|
||||
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.category.ProductCategoryCreateReqVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.category.ProductCategoryRespVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.category.ProductCategoryTreeNodeRespVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.category.ProductCategoryUpdateReqVO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryUpdateReqDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface ProductCategoryConvert {
|
||||
|
||||
ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
|
||||
|
||||
ProductCategoryCreateReqDTO convert(ProductCategoryCreateReqVO bean);
|
||||
|
||||
ProductCategoryUpdateReqDTO convert(ProductCategoryUpdateReqVO bean);
|
||||
|
||||
ProductCategoryRespVO convert(ProductCategoryRespDTO bean);
|
||||
|
||||
ProductCategoryTreeNodeRespVO convertTreeNode(ProductCategoryRespDTO bean);
|
||||
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package cn.iocoder.mall.managementweb.manager.product;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.category.ProductCategoryCreateReqVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.category.ProductCategoryTreeNodeRespVO;
|
||||
import cn.iocoder.mall.managementweb.controller.product.vo.category.ProductCategoryUpdateReqVO;
|
||||
import cn.iocoder.mall.managementweb.convert.product.ProductCategoryConvert;
|
||||
import cn.iocoder.mall.productservice.enums.category.ProductCategoryIdEnum;
|
||||
import cn.iocoder.mall.productservice.rpc.category.ProductCategoryRpc;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryListQueryReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 商品分类表 Manager
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ProductCategoryManager {
|
||||
|
||||
@Reference(version = "${dubbo.consumer.ProductCategoryRpc.version}")
|
||||
private ProductCategoryRpc productCategoryRpc;
|
||||
|
||||
/**
|
||||
* 创建商品分类表
|
||||
*
|
||||
* @param createVO 创建商品分类表 VO
|
||||
* @return 商品分类表
|
||||
*/
|
||||
public Integer createProductCategory(ProductCategoryCreateReqVO createVO) {
|
||||
CommonResult<Integer> createProductCategoryResult = productCategoryRpc.createProductCategory(ProductCategoryConvert.INSTANCE.convert(createVO));
|
||||
createProductCategoryResult.checkError();
|
||||
return createProductCategoryResult.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品分类表
|
||||
*
|
||||
* @param updateVO 更新商品分类表 VO
|
||||
*/
|
||||
public void updateProductCategory(ProductCategoryUpdateReqVO updateVO) {
|
||||
CommonResult<Boolean> updateProductCategoryResult = productCategoryRpc.updateProductCategory(ProductCategoryConvert.INSTANCE.convert(updateVO));
|
||||
updateProductCategoryResult.checkError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品分类表
|
||||
*
|
||||
* @param productCategoryId 商品分类表编号
|
||||
*/
|
||||
public void deleteProductCategory(Integer productCategoryId) {
|
||||
CommonResult<Boolean> deleteProductCategoryResult = productCategoryRpc.deleteProductCategory(productCategoryId);
|
||||
deleteProductCategoryResult.checkError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品分类树结构
|
||||
*
|
||||
* @return 商品分类树结构
|
||||
*/
|
||||
public List<ProductCategoryTreeNodeRespVO> treeProductCategory() {
|
||||
// 获得商品分类全列表
|
||||
CommonResult<List<ProductCategoryRespDTO>> listProductCategories = productCategoryRpc.listProductCategories(new ProductCategoryListQueryReqDTO());
|
||||
listProductCategories.checkError();
|
||||
// 构建菜单树
|
||||
return buildProductCategoryTree(listProductCategories.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建商品分类树
|
||||
*
|
||||
* @param productCategories 商品分类列表
|
||||
* @return 商品分类树
|
||||
*/
|
||||
private static List<ProductCategoryTreeNodeRespVO> buildProductCategoryTree(List<ProductCategoryRespDTO> productCategories) {
|
||||
// 排序,保证菜单的有序性
|
||||
productCategories.sort(Comparator.comparing(ProductCategoryRespDTO::getSort));
|
||||
// 构建菜单树
|
||||
// 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。
|
||||
Map<Integer, ProductCategoryTreeNodeRespVO> treeNodeMap = new LinkedHashMap<>();
|
||||
productCategories.forEach(category -> treeNodeMap.put(category.getId(), ProductCategoryConvert.INSTANCE.convertTreeNode(category)));
|
||||
// 处理父子关系
|
||||
treeNodeMap.values().stream().filter(node -> !node.getPid().equals(ProductCategoryIdEnum.ROOT.getId())).forEach((childNode) -> {
|
||||
// 获得父节点
|
||||
ProductCategoryTreeNodeRespVO parentNode = treeNodeMap.get(childNode.getPid());
|
||||
if (parentNode == null) {
|
||||
log.error("[buildProductCategoryTree][category({}) 找不到父商品分类({})]", childNode.getId(), childNode.getPid());
|
||||
return;
|
||||
}
|
||||
// 将自己添加到父节点中
|
||||
if (parentNode.getChildren() == null) {
|
||||
parentNode.setChildren(new ArrayList<>());
|
||||
}
|
||||
parentNode.getChildren().add(childNode);
|
||||
});
|
||||
// 获得到所有的根节点
|
||||
return treeNodeMap.values().stream().filter(node -> node.getPid().equals(ProductCategoryIdEnum.ROOT.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
|
@ -49,6 +49,8 @@ dubbo:
|
|||
version: 1.0.0
|
||||
ErrorCodeRpc:
|
||||
version: 1.0.0
|
||||
ProductCategoryRpc:
|
||||
version: 1.0.0
|
||||
|
||||
# Swagger 配置项
|
||||
swagger:
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -1,18 +1,17 @@
|
|||
package cn.iocoder.mall.product.biz.bo.category;
|
||||
package cn.iocoder.mall.productservice.rpc.category.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 商品分类 - 商品分类统一BO
|
||||
*/
|
||||
* 商品分类 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryBO {
|
||||
public class ProductCategoryRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
|
@ -20,16 +19,14 @@ public class ProductCategoryBO {
|
|||
private Integer id;
|
||||
/**
|
||||
* 父分类编号
|
||||
*
|
||||
* 如果不存在父级,则 pid = 0 。
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 名称
|
||||
* 分类名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 描述
|
||||
* 分类描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
|
@ -37,14 +34,11 @@ public class ProductCategoryBO {
|
|||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 排序值
|
||||
* 分类排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 1-开启
|
||||
* 2-关闭
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import lombok.EqualsAndHashCode;
|
|||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品分类表
|
||||
* 商品分类 DO
|
||||
*/
|
||||
@TableName("product_category")
|
||||
@Data
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import lombok.experimental.Accessors;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品分类表 BO
|
||||
* 商品分类 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
|
|
|
@ -7,7 +7,7 @@ import javax.validation.constraints.NotEmpty;
|
|||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品分类表创建 BO
|
||||
* 商品分类创建 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ import javax.validation.constraints.NotEmpty;
|
|||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品分类表更新 BO
|
||||
* 商品分类更新 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:31 下午
|
||||
*/
|
||||
package cn.iocoder.mall.product.biz.bo;
|
|
@ -1,26 +0,0 @@
|
|||
package cn.iocoder.mall.product.biz.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@MapperScan("cn.iocoder.mall.product.biz.dao") // 扫描对应的 Mapper 接口
|
||||
@EnableTransactionManagement(proxyTargetClass = true)
|
||||
// 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600
|
||||
public class DatabaseConfiguration {
|
||||
@Bean
|
||||
public ISqlInjector sqlInjector() {
|
||||
return new DefaultSqlInjector(); // MyBatis Plus 逻辑删除
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor(); // MyBatis Plus 分页插件
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package cn.iocoder.mall.product.biz.convert.category;
|
||||
|
||||
import cn.iocoder.mall.product.biz.bo.category.ProductCategoryBO;
|
||||
import cn.iocoder.mall.product.biz.dataobject.category.ProductCategoryDO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryAddDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.category.ProductCategoryUpdateStatusDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
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
|
||||
*/
|
||||
ProductCategoryBO convertToBO(ProductCategoryDO category);
|
||||
|
||||
|
||||
/**
|
||||
* 商品分类列表 - DO转换BO {@link #convertToBO(ProductCategoryDO)}
|
||||
* @param category
|
||||
* @return
|
||||
*/
|
||||
List<ProductCategoryBO> convertToAllListBO(List<ProductCategoryDO> category);
|
||||
|
||||
/**
|
||||
* 新增商品分类 - DTO转换DO
|
||||
* @param productCategoryAddDTO
|
||||
* @return
|
||||
*/
|
||||
ProductCategoryDO convertToDO(ProductCategoryAddDTO productCategoryAddDTO);
|
||||
|
||||
/**
|
||||
* 更新商品分类 - DTO转换DO
|
||||
* @param productCategoryUpdateDTO
|
||||
* @return
|
||||
*/
|
||||
ProductCategoryDO convertToDO(ProductCategoryUpdateDTO productCategoryUpdateDTO);
|
||||
|
||||
/**
|
||||
* 更新商品分类状态 - DTO转换DO
|
||||
* @param productCategoryUpdateStatusDTO
|
||||
* @return
|
||||
*/
|
||||
ProductCategoryDO convertToDO(ProductCategoryUpdateStatusDTO productCategoryUpdateStatusDTO);
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:31 下午
|
||||
*/
|
||||
package cn.iocoder.mall.product.biz.convert;
|
|
@ -1,25 +0,0 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 商品分类数据持久层
|
||||
*/
|
||||
@Repository
|
||||
public interface ProductCategoryMapper extends BaseMapper<ProductCategoryDO> {
|
||||
/**
|
||||
* 查询商品分类的下一级子分类数量
|
||||
* @param productCategoryId
|
||||
* @return
|
||||
*/
|
||||
default Integer selectChildCategoryCount(Integer productCategoryId) {
|
||||
return this.selectCount(
|
||||
Wrappers.<ProductCategoryDO>lambdaQuery().eq(ProductCategoryDO::getPid, productCategoryId)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:28 下午
|
||||
*/
|
||||
package cn.iocoder.mall.product.biz.dao;
|
|
@ -1,50 +0,0 @@
|
|||
package cn.iocoder.mall.product.biz.dataobject.category;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品分类
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName("product_category")
|
||||
public class ProductCategoryDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:27 下午
|
||||
*/
|
||||
package cn.iocoder.mall.product.biz.dataobject;
|
|
@ -1,48 +0,0 @@
|
|||
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
|
||||
* @Description: 商品分类 - 创建商品分类DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryAddDTO {
|
||||
|
||||
/**
|
||||
* 管理员id
|
||||
*/
|
||||
@NotNull(message = "管理员id不能为空")
|
||||
private Integer adminId;
|
||||
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
@NotNull(message = "父分类编号不能为空")
|
||||
private Integer pid;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@NotNull(message = "名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@NotNull(message = "描述不能为空")
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
@NotNull(message = "排序值不能为空")
|
||||
private Integer sort;
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
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
|
||||
* @Description: 商品分类 - 删除商品分类DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryDeleteDTO {
|
||||
|
||||
/**
|
||||
* 管理员id
|
||||
*/
|
||||
@NotNull(message = "管理员id不能为空")
|
||||
private Integer adminId;
|
||||
/**
|
||||
* 商品分类编号
|
||||
*/
|
||||
@NotNull(message = "编号不能为空")
|
||||
private Integer id;
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
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
|
||||
* @Description: 商品分类 - 更新商品分类DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
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;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
@NotNull(message = "描述不能为空")
|
||||
private Integer sort;
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
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
|
||||
* @Description: 商品分类 - 更新商品分类状态DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryUpdateStatusDTO {
|
||||
|
||||
/**
|
||||
* 管理员id
|
||||
*/
|
||||
@NotNull(message = "管理员id不能为空")
|
||||
private Integer adminId;
|
||||
/**
|
||||
* 商品分类编号
|
||||
*/
|
||||
@NotNull(message = "编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package cn.iocoder.mall.product.biz.service.category;
|
||||
|
||||
import cn.iocoder.mall.product.biz.bo.category.ProductCategoryBO;
|
||||
import cn.iocoder.mall.product.biz.dataobject.category.ProductCategoryDO;
|
||||
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 org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 商品分类 - 服务层
|
||||
*/
|
||||
@Validated
|
||||
public interface ProductCategoryService {
|
||||
|
||||
/**
|
||||
* 获取所有商品分类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<ProductCategoryBO> getAllProductCategory();
|
||||
|
||||
/**
|
||||
* 新增商品分类
|
||||
*
|
||||
* @param productCategoryAddDTO
|
||||
* @return
|
||||
*/
|
||||
ProductCategoryBO addProductCategory(@Valid ProductCategoryAddDTO productCategoryAddDTO);
|
||||
|
||||
/**
|
||||
* 更新商品分类
|
||||
*
|
||||
* @param productCategoryUpdateDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean updateProductCategory(@Valid ProductCategoryUpdateDTO productCategoryUpdateDTO);
|
||||
|
||||
/**
|
||||
* 更新商品分类状态
|
||||
*
|
||||
* @param productCategoryUpdateStatusDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean updateProductCategoryStatus(@Valid ProductCategoryUpdateStatusDTO productCategoryUpdateStatusDTO);
|
||||
|
||||
/**
|
||||
* 删除商品分类
|
||||
*
|
||||
* @param productCategoryDeleteDTO
|
||||
* @return
|
||||
*/
|
||||
Boolean deleteProductCategory(@Valid ProductCategoryDeleteDTO productCategoryDeleteDTO);
|
||||
|
||||
/**
|
||||
* 校验分类是否可用
|
||||
*
|
||||
* @param productCategoryId 分类ID
|
||||
* @return 商品分类
|
||||
*/
|
||||
ProductCategoryDO validProductCategory(Integer productCategoryId);
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package cn.iocoder.mall.product.biz.service.category;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum;
|
||||
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.category.ProductCategoryMapper;
|
||||
import cn.iocoder.mall.product.biz.dataobject.category.ProductCategoryDO;
|
||||
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.category.ProductCategoryNodeEnum;
|
||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryStatusEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum.*;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 商品分类 - 服务实现层
|
||||
*/
|
||||
@Service
|
||||
public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
|
||||
@Autowired
|
||||
private ProductCategoryMapper productCategoryMapper;
|
||||
|
||||
@Override
|
||||
public List<ProductCategoryBO> getAllProductCategory() {
|
||||
List<ProductCategoryDO> categoryList = productCategoryMapper.selectList(null);
|
||||
return ProductCategoryConvert.INSTANCE.convertToAllListBO(categoryList);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:31 下午
|
||||
*/
|
||||
package cn.iocoder.mall.product.biz.service;
|
|
@ -1,69 +0,0 @@
|
|||
package cn.iocoder.mall.product.rest.convert.category;
|
||||
|
||||
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 cn.iocoder.mall.product.rest.request.category.AdminsProductCategoryAddRequest;
|
||||
import cn.iocoder.mall.product.rest.request.category.AdminsProductCategoryUpdateRequest;
|
||||
import cn.iocoder.mall.product.rest.request.category.AdminsProductCategoryUpdateStatusRequest;
|
||||
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.factory.Mappers;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 管理员 - 商品分类 - API层数据转换
|
||||
*/
|
||||
@Mapper
|
||||
public interface AdminsProductCategoryConvert {
|
||||
|
||||
AdminsProductCategoryConvert INSTANCE = Mappers.getMapper(AdminsProductCategoryConvert.class);
|
||||
|
||||
/**
|
||||
* 商品分类列表 - BO转换Response
|
||||
* @param productCategoryAllListBO
|
||||
* @return
|
||||
*/
|
||||
AdminsProductCategoryTreeNodeResponse convertToTreeNodeResponse(ProductCategoryBO productCategoryAllListBO);
|
||||
|
||||
|
||||
/**
|
||||
* 新增商品分类 - Request转DTO
|
||||
* @param adminsProductCategoryAddRequest
|
||||
* @return
|
||||
*/
|
||||
ProductCategoryAddDTO convertToAddDTO(Integer adminId, AdminsProductCategoryAddRequest adminsProductCategoryAddRequest);
|
||||
|
||||
/**
|
||||
* 新增商品分类 - BO转Response
|
||||
* @param productCategoryAddBO
|
||||
* @return
|
||||
*/
|
||||
AdminsProductCategoryAddResponse convertToAddResponse(ProductCategoryBO productCategoryAddBO);
|
||||
|
||||
/**
|
||||
* 更新商品分类 - Request转DTO
|
||||
* @param adminsProductCategoryUpdateRequest
|
||||
* @return
|
||||
*/
|
||||
ProductCategoryUpdateDTO convertToUpdateDTO(Integer adminId, AdminsProductCategoryUpdateRequest adminsProductCategoryUpdateRequest);
|
||||
|
||||
/**
|
||||
* 更新商品分类状态 - Request转DTO
|
||||
* @param adminsProductCategoryUpdateStatusRequest
|
||||
* @return
|
||||
*/
|
||||
ProductCategoryUpdateStatusDTO convertToUpdateStatusDTO(Integer adminId, AdminsProductCategoryUpdateStatusRequest adminsProductCategoryUpdateStatusRequest);
|
||||
|
||||
/**
|
||||
* 删除商品分类 - Request转DTO
|
||||
* @param adminId 管理员id
|
||||
* @param id 商品分类id
|
||||
* @return
|
||||
*/
|
||||
ProductCategoryDeleteDTO convertToDeleteDTO(Integer adminId, Integer id);
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package cn.iocoder.mall.product.rest.request.category;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 管理员 - 商品分类 - 创建商品分类Request
|
||||
*/
|
||||
@ApiModel("创建商品分类Request")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class AdminsProductCategoryAddRequest {
|
||||
|
||||
@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;
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package cn.iocoder.mall.product.rest.request.category;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 管理员 - 商品分类 - 更新商品分类Request
|
||||
*/
|
||||
@ApiModel("更新商品分类Request")
|
||||
@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;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package cn.iocoder.mall.product.rest.request.category;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @Author: jiangweifan
|
||||
* @Date: 2020/5/6
|
||||
* @Description: 管理员 - 商品分类 - 更新商品分类状态Request
|
||||
*/
|
||||
@ApiModel("更新商品分类状态Request")
|
||||
@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;
|
||||
}
|
|
@ -122,9 +122,9 @@ public class ResourceService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获得资源树结构
|
||||
* 获得资源全列表
|
||||
*
|
||||
* @return 资源树结构
|
||||
* @return 资源全列表
|
||||
*/
|
||||
public List<ResourceBO> listResources() {
|
||||
List<ResourceDO> resourceDOs = resourceMapper.selectList(null);
|
||||
|
|
Loading…
Reference in New Issue