Merge remote-tracking branch 'origin/master-new' into master-new
This commit is contained in:
commit
a61613aca4
@ -31,6 +31,7 @@ import org.springframework.web.servlet.NoHandlerFoundException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.validation.ConstraintViolation;
|
import javax.validation.ConstraintViolation;
|
||||||
import javax.validation.ConstraintViolationException;
|
import javax.validation.ConstraintViolationException;
|
||||||
|
import javax.validation.ValidationException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static cn.iocoder.common.framework.exception.enums.GlobalErrorCodeConstants.*;
|
import static cn.iocoder.common.framework.exception.enums.GlobalErrorCodeConstants.*;
|
||||||
@ -162,7 +163,6 @@ public class GlobalExceptionHandler {
|
|||||||
public CommonResult globalExceptionHandler(HttpServletRequest req, GlobalException ex) {
|
public CommonResult globalExceptionHandler(HttpServletRequest req, GlobalException ex) {
|
||||||
// 系统异常时,才打印异常日志
|
// 系统异常时,才打印异常日志
|
||||||
if (INTERNAL_SERVER_ERROR.getCode().equals(ex.getCode())) {
|
if (INTERNAL_SERVER_ERROR.getCode().equals(ex.getCode())) {
|
||||||
logger.error("[globalExceptionHandler]", ex);
|
|
||||||
// 插入异常日志
|
// 插入异常日志
|
||||||
this.createExceptionLog(req, ex);
|
this.createExceptionLog(req, ex);
|
||||||
// 普通全局异常,打印 info 日志即可
|
// 普通全局异常,打印 info 日志即可
|
||||||
@ -173,6 +173,16 @@ public class GlobalExceptionHandler {
|
|||||||
return CommonResult.error(ex);
|
return CommonResult.error(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理 Dubbo Consumer 本地参数校验时,抛出的 ValidationException 异常
|
||||||
|
*/
|
||||||
|
@ExceptionHandler(value = ValidationException.class)
|
||||||
|
public CommonResult validationException(ValidationException ex) {
|
||||||
|
logger.warn("[constraintViolationExceptionHandler]", ex);
|
||||||
|
// 无法拼接明细的错误信息,因为 Dubbo Consumer 抛出 ValidationException 异常时,是直接的字符串信息,且人类不可读
|
||||||
|
return CommonResult.error(BAD_REQUEST.getCode(), "请求参数不正确");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理系统异常,兜底处理所有的一切
|
* 处理系统异常,兜底处理所有的一切
|
||||||
*/
|
*/
|
||||||
|
@ -60,6 +60,12 @@
|
|||||||
<artifactId>system-service-api</artifactId>
|
<artifactId>system-service-api</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<!-- 商品服务 -->
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<artifactId>product-service-api</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Registry 和 Config 相关 -->
|
<!-- Registry 和 Config 相关 -->
|
||||||
<dependency>
|
<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
|
version: 1.0.0
|
||||||
ErrorCodeRpc:
|
ErrorCodeRpc:
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
ProductCategoryRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
|
||||||
# Swagger 配置项
|
# Swagger 配置项
|
||||||
swagger:
|
swagger:
|
||||||
|
3
pom.xml
3
pom.xml
@ -16,7 +16,6 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<!-- <module>product</module>-->
|
<!-- <module>product</module>-->
|
||||||
<!-- <module>order</module>-->
|
<!-- <module>order</module>-->
|
||||||
<module>user</module>
|
|
||||||
<module>common</module>
|
<module>common</module>
|
||||||
<!-- <module>system</module>-->
|
<!-- <module>system</module>-->
|
||||||
<!-- <module>ops</module>-->
|
<!-- <module>ops</module>-->
|
||||||
@ -24,13 +23,13 @@
|
|||||||
<!-- <module>promotion</module>-->
|
<!-- <module>promotion</module>-->
|
||||||
<!-- <module>search</module>-->
|
<!-- <module>search</module>-->
|
||||||
<module>mall-dependencies</module>
|
<module>mall-dependencies</module>
|
||||||
<!-- <module>mall-spring-boot-starter-cache</module>-->
|
|
||||||
<module>user-service-project</module>
|
<module>user-service-project</module>
|
||||||
<module>user-web-app</module>
|
<module>user-web-app</module>
|
||||||
<module>system-service-project</module>
|
<module>system-service-project</module>
|
||||||
<module>pay-service-project</module>
|
<module>pay-service-project</module>
|
||||||
<module>management-web-app</module>
|
<module>management-web-app</module>
|
||||||
<module>shop-web-app</module>
|
<module>shop-web-app</module>
|
||||||
|
<module>product-service-project</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
@ -9,18 +9,16 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>user</artifactId>
|
<artifactId>product-service-project</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<!-- <module>user-application</module>-->
|
<module>product-service-api</module>
|
||||||
<!-- <module>user-service-api</module>-->
|
<module>product-service-app</module>
|
||||||
<!-- <module>user-service-impl</module>-->
|
|
||||||
<module>user-rest</module>
|
|
||||||
<module>user-biz</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- onemall 基础 bom 文件 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
<artifactId>mall-dependencies</artifactId>
|
<artifactId>mall-dependencies</artifactId>
|
||||||
@ -28,6 +26,13 @@
|
|||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 自身项目 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<artifactId>product-service-api</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
@ -3,20 +3,28 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>product</artifactId>
|
<artifactId>product-service-project</artifactId>
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>product-biz-api</artifactId>
|
<artifactId>product-service-api</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- Mall 相关 -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
<artifactId>common-framework</artifactId>
|
<artifactId>common-framework</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 工具类相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.validation</groupId>
|
||||||
|
<artifactId>validation-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
@ -0,0 +1,41 @@
|
|||||||
|
package cn.iocoder.mall.productservice.enums;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.exception.ErrorCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误码枚举类
|
||||||
|
*
|
||||||
|
* 商品系统,使用 1-003-000-000 段
|
||||||
|
*/
|
||||||
|
public interface ProductErrorCodeConstants {
|
||||||
|
|
||||||
|
// ========== PRODUCT CATEGORY 模块 ==========
|
||||||
|
ErrorCode PRODUCT_CATEGORY_PARENT_NOT_EXISTS = new ErrorCode(1003001000, "父分类不存在");
|
||||||
|
ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1003001001, "商品分类不存在");
|
||||||
|
ErrorCode PRODUCT_CATEGORY_STATUS_NOT_EXISTS = new ErrorCode(1003001001, "商品分类状态不存在");
|
||||||
|
ErrorCode PRODUCT_CATEGORY_PARENT_NOT_SELF = new ErrorCode(1003001002, "不能设置自己为父分类");
|
||||||
|
ErrorCode PRODUCT_CATEGORY_STATUS_EQUALS = new ErrorCode(1002001003, "商品分类已经是该状态");
|
||||||
|
ErrorCode PRODUCT_CATEGORY_DELETE_ONLY_DISABLE = new ErrorCode(1002001004, "只有关闭的商品分类才可以删除");
|
||||||
|
ErrorCode PRODUCT_CATEGORY_DELETE_ONLY_NO_CHILD = new ErrorCode(1002001004, "只有无子分类的商品分类才可以删除");
|
||||||
|
ErrorCode PRODUCT_CATEGORY_MUST_ENABLE = new ErrorCode(1002001005, "只有开启的商品分类,才可以使用");
|
||||||
|
ErrorCode PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2 = new ErrorCode(1002001005, "父分类必须是一级分类");
|
||||||
|
|
||||||
|
// ========== PRODUCT SPU + SKU 模块 ==========
|
||||||
|
ErrorCode PRODUCT_SKU_ATTR_CANT_NOT_DUPLICATE = new ErrorCode(1003002000, "一个 Sku 下,不能有重复的规格");
|
||||||
|
ErrorCode PRODUCT_SPU_ATTR_NUMBERS_MUST_BE_EQUALS = new ErrorCode(1003002001, "一个 Spu 下的每个 Sku ,其规格数必须一致");
|
||||||
|
ErrorCode PRODUCT_SPU_SKU__NOT_DUPLICATE = new ErrorCode(1003002002, "一个 Spu 下的每个 Sku ,必须不重复");
|
||||||
|
ErrorCode PRODUCT_SPU_NOT_EXISTS = new ErrorCode(1003002003, "Spu 不存在");
|
||||||
|
ErrorCode PRODUCT_SPU_CATEGORY_MUST_BE_LEVEL2 = new ErrorCode(1003002003, "Spu 只能添加在二级分类下");
|
||||||
|
|
||||||
|
// ========== PRODUCT ATTR + ATTR_VALUE 模块 ==========
|
||||||
|
ErrorCode PRODUCT_ATTR_VALUE_NOT_EXIST = new ErrorCode(1003003000, "商品属性值不存在");
|
||||||
|
ErrorCode PRODUCT_ATTR_NOT_EXIST = new ErrorCode(1003003001, "商品属性值不存在");
|
||||||
|
ErrorCode PRODUCT_ATTR_EXISTS = new ErrorCode(1003003002, "商品规格已经存在");
|
||||||
|
ErrorCode PRODUCT_ATTR_STATUS_EQUALS = new ErrorCode(1003003003, "商品规格已经是该状态");
|
||||||
|
ErrorCode PRODUCT_ATTR_VALUE_EXISTS = new ErrorCode(1003003004, "商品规格值已经存在");
|
||||||
|
ErrorCode PRODUCT_ATTR_VALUE_STATUS_EQUALS = new ErrorCode(1003003005, "商品规格值已经是该状态");
|
||||||
|
|
||||||
|
// ========== PRODUCT BRAND模块 ==========
|
||||||
|
ErrorCode PRODUCT_BRAND_EXIST = new ErrorCode(1003004000,"品牌值已经存在");
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package cn.iocoder.mall.productservice.enums.category;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品分类的编号枚举
|
||||||
|
*/
|
||||||
|
public enum ProductCategoryIdEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根节点
|
||||||
|
*/
|
||||||
|
ROOT(0);
|
||||||
|
|
||||||
|
private final Integer id;
|
||||||
|
|
||||||
|
ProductCategoryIdEnum(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
|
||||||
|
}
|
76
product-service-project/product-service-app/pom.xml
Normal file
76
product-service-project/product-service-app/pom.xml
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>product-service-project</artifactId>
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>product-service-app</artifactId>
|
||||||
|
<dependencies>
|
||||||
|
<!-- RPC 相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<artifactId>mall-spring-boot-starter-dubbo</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<!-- 系统服务 -->
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<artifactId>system-service-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<!-- 商品服务 -->
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<artifactId>product-service-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Registry 和 Config 相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- DB 相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<artifactId>mall-spring-boot-starter-mybatis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 工具类相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher -->
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-jdk8</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,13 @@
|
|||||||
|
package cn.iocoder.mall.productservice;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ProductServiceApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ProductServiceApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.mall.product.biz.config;
|
package cn.iocoder.mall.productservice.config;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
||||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
||||||
@ -9,10 +9,12 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@MapperScan("cn.iocoder.mall.product.biz.dao") // 扫描对应的 Mapper 接口
|
@MapperScan("cn.iocoder.mall.productservice.dal.mysql.mapper") // 扫描对应的 Mapper 接口
|
||||||
@EnableTransactionManagement(proxyTargetClass = true)
|
@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。
|
||||||
// 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600
|
|
||||||
public class DatabaseConfiguration {
|
public class DatabaseConfiguration {
|
||||||
|
|
||||||
|
// 数据库连接池 Druid
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ISqlInjector sqlInjector() {
|
public ISqlInjector sqlInjector() {
|
||||||
return new DefaultSqlInjector(); // MyBatis Plus 逻辑删除
|
return new DefaultSqlInjector(); // MyBatis Plus 逻辑删除
|
@ -0,0 +1,40 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ProductCategoryConvert {
|
||||||
|
|
||||||
|
ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
|
||||||
|
|
||||||
|
ProductCategoryDO convert(ProductCategoryCreateBO bean);
|
||||||
|
|
||||||
|
ProductCategoryBO convert(ProductCategoryDO bean);
|
||||||
|
|
||||||
|
List<ProductCategoryBO> convertList(List<ProductCategoryDO> list);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
@ -1,34 +1,37 @@
|
|||||||
package cn.iocoder.mall.product.biz.dataobject.category;
|
package cn.iocoder.mall.productservice.dal.mysql.dataobject.category;
|
||||||
|
|
||||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.mall.mybatis.core.dataobject.BaseDO;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品分类
|
* 商品分类 DO
|
||||||
*/
|
*/
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@TableName("product_category")
|
@TableName("product_category")
|
||||||
public class ProductCategoryDO extends DeletableDO {
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class ProductCategoryDO extends BaseDO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分类编号
|
* 分类编号
|
||||||
*/
|
*/
|
||||||
|
@TableId
|
||||||
private Integer id;
|
private Integer id;
|
||||||
/**
|
/**
|
||||||
* 父分类编号
|
* 父分类编号
|
||||||
*
|
|
||||||
* 如果不存在父级,则 pid = 0 。
|
|
||||||
*/
|
*/
|
||||||
private Integer pid;
|
private Integer pid;
|
||||||
/**
|
/**
|
||||||
* 名称
|
* 分类名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
/**
|
/**
|
||||||
* 描述
|
* 分类描述
|
||||||
*/
|
*/
|
||||||
private String description;
|
private String description;
|
||||||
/**
|
/**
|
||||||
@ -36,14 +39,13 @@ public class ProductCategoryDO extends DeletableDO {
|
|||||||
*/
|
*/
|
||||||
private String picUrl;
|
private String picUrl;
|
||||||
/**
|
/**
|
||||||
* 排序值
|
* 分类排序
|
||||||
*/
|
*/
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
/**
|
/**
|
||||||
* 状态
|
* 状态
|
||||||
*
|
*
|
||||||
* 1-开启
|
* 枚举 {@link CommonStatusEnum}
|
||||||
* 2-关闭
|
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
@ -0,0 +1,23 @@
|
|||||||
|
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> {
|
||||||
|
|
||||||
|
default Integer selectCountByPid(Integer pid) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,134 @@
|
|||||||
|
package cn.iocoder.mall.productservice.service.category;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||||
|
import cn.iocoder.mall.productservice.convert.category.ProductCategoryConvert;
|
||||||
|
import cn.iocoder.mall.productservice.dal.mysql.dataobject.category.ProductCategoryDO;
|
||||||
|
import cn.iocoder.mall.productservice.dal.mysql.mapper.category.ProductCategoryMapper;
|
||||||
|
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;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品分类 Service
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class ProductCategoryService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductCategoryMapper productCategoryMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建商品分类
|
||||||
|
*
|
||||||
|
* @param createBO 创建商品分类 BO
|
||||||
|
* @return 商品分类
|
||||||
|
*/
|
||||||
|
public ProductCategoryBO createProductCategory(@Valid ProductCategoryCreateBO createBO) {
|
||||||
|
// 校验父分类
|
||||||
|
validParent(createBO.getPid());
|
||||||
|
// 插入到数据库
|
||||||
|
ProductCategoryDO productCategoryDO = ProductCategoryConvert.INSTANCE.convert(createBO);
|
||||||
|
productCategoryMapper.insert(productCategoryDO);
|
||||||
|
// 返回
|
||||||
|
return ProductCategoryConvert.INSTANCE.convert(productCategoryDO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新商品分类
|
||||||
|
*
|
||||||
|
* @param updateBO 更新商品分类 BO
|
||||||
|
*/
|
||||||
|
public void updateProductCategory(@Valid ProductCategoryUpdateBO updateBO) {
|
||||||
|
// 校验父分类
|
||||||
|
validParent(updateBO.getPid());
|
||||||
|
// 校验不能设置自己为父分类
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
// 更新到数据库
|
||||||
|
ProductCategoryDO updateObject = ProductCategoryConvert.INSTANCE.convert(updateBO);
|
||||||
|
productCategoryMapper.updateById(updateObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除商品分类
|
||||||
|
*
|
||||||
|
* @param productCategoryId 商品分类编号
|
||||||
|
*/
|
||||||
|
public void deleteProductCategory(Integer productCategoryId) {
|
||||||
|
// 校验删除的商品分类是否存在
|
||||||
|
if (productCategoryMapper.selectById(productCategoryId) == null) {
|
||||||
|
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
// 只有不存在子分类才可以删除
|
||||||
|
Integer childCount = productCategoryMapper.selectCountByPid(productCategoryId);
|
||||||
|
if (childCount > 0) {
|
||||||
|
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_DELETE_ONLY_NO_CHILD);
|
||||||
|
}
|
||||||
|
// TODO 芋艿 补充只有不存在商品才可以删除
|
||||||
|
// 标记删除
|
||||||
|
productCategoryMapper.deleteById(productCategoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得商品分类
|
||||||
|
*
|
||||||
|
* @param productCategoryId 商品分类编号
|
||||||
|
* @return 商品分类
|
||||||
|
*/
|
||||||
|
public ProductCategoryBO getProductCategory(Integer productCategoryId) {
|
||||||
|
ProductCategoryDO productCategoryDO = productCategoryMapper.selectById(productCategoryId);
|
||||||
|
return ProductCategoryConvert.INSTANCE.convert(productCategoryDO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得商品分类列表
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
// 校验父分类是否存在
|
||||||
|
if (parentCategory == null) {
|
||||||
|
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
// 父分类必须是一级分类
|
||||||
|
if (!ProductCategoryIdEnum.ROOT.getId().equals(parentCategory.getPid())) {
|
||||||
|
throw ServiceExceptionUtil.exception((PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.mall.product.biz.bo.category;
|
package cn.iocoder.mall.productservice.service.category.bo;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
@ -6,10 +6,8 @@ import lombok.experimental.Accessors;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: jiangweifan
|
* 商品分类 BO
|
||||||
* @Date: 2020/5/6
|
*/
|
||||||
* @Description: 商品分类 - 商品分类统一BO
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class ProductCategoryBO {
|
public class ProductCategoryBO {
|
||||||
@ -20,16 +18,14 @@ public class ProductCategoryBO {
|
|||||||
private Integer id;
|
private Integer id;
|
||||||
/**
|
/**
|
||||||
* 父分类编号
|
* 父分类编号
|
||||||
*
|
|
||||||
* 如果不存在父级,则 pid = 0 。
|
|
||||||
*/
|
*/
|
||||||
private Integer pid;
|
private Integer pid;
|
||||||
/**
|
/**
|
||||||
* 名称
|
* 分类名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
/**
|
/**
|
||||||
* 描述
|
* 分类描述
|
||||||
*/
|
*/
|
||||||
private String description;
|
private String description;
|
||||||
/**
|
/**
|
||||||
@ -37,14 +33,11 @@ public class ProductCategoryBO {
|
|||||||
*/
|
*/
|
||||||
private String picUrl;
|
private String picUrl;
|
||||||
/**
|
/**
|
||||||
* 排序值
|
* 分类排序
|
||||||
*/
|
*/
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
/**
|
/**
|
||||||
* 状态
|
* 状态
|
||||||
*
|
|
||||||
* 1-开启
|
|
||||||
* 2-关闭
|
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
/**
|
/**
|
@ -1,24 +1,17 @@
|
|||||||
package cn.iocoder.mall.product.biz.dto.category;
|
package cn.iocoder.mall.productservice.service.category.bo;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: jiangweifan
|
* 商品分类创建 BO
|
||||||
* @Date: 2020/5/6
|
*/
|
||||||
* @Description: 商品分类 - 创建商品分类DTO
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class ProductCategoryAddDTO {
|
public class ProductCategoryCreateBO {
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理员id
|
|
||||||
*/
|
|
||||||
@NotNull(message = "管理员id不能为空")
|
|
||||||
private Integer adminId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 父分类编号
|
* 父分类编号
|
||||||
@ -26,23 +19,27 @@ public class ProductCategoryAddDTO {
|
|||||||
@NotNull(message = "父分类编号不能为空")
|
@NotNull(message = "父分类编号不能为空")
|
||||||
private Integer pid;
|
private Integer pid;
|
||||||
/**
|
/**
|
||||||
* 名称
|
* 分类名称
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "名称不能为空")
|
@NotEmpty(message = "分类名称不能为空")
|
||||||
private String name;
|
private String name;
|
||||||
/**
|
/**
|
||||||
* 描述
|
* 分类描述
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "描述不能为空")
|
|
||||||
private String description;
|
private String description;
|
||||||
/**
|
/**
|
||||||
* 分类图片
|
* 分类图片
|
||||||
*/
|
*/
|
||||||
private String picUrl;
|
private String picUrl;
|
||||||
/**
|
/**
|
||||||
* 排序值
|
* 分类排序
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "排序值不能为空")
|
@NotNull(message = "分类排序不能为空")
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
@NotNull(message = "状态不能为空")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
}
|
}
|
@ -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;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package cn.iocoder.mall.productservice.service.category.bo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品分类更新 BO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class ProductCategoryUpdateBO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类编号
|
||||||
|
*/
|
||||||
|
@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 = "状态不能为空")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
spring:
|
||||||
|
# 数据源配置项
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_system?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||||
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
|
username: root
|
||||||
|
password: 3WLiVUBEwTbvAfsh
|
||||||
|
# Spring Cloud 配置项
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
# Spring Cloud Nacos Discovery 配置项
|
||||||
|
discovery:
|
||||||
|
server-addr: 400-infra.server.iocoder.cn:8848 # Nacos 服务器地址
|
||||||
|
namespace: dev # Nacos 命名空间
|
||||||
|
|
||||||
|
# Dubbo 配置项
|
||||||
|
dubbo:
|
||||||
|
# Dubbo 注册中心
|
||||||
|
registry:
|
||||||
|
address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
@ -0,0 +1,24 @@
|
|||||||
|
spring:
|
||||||
|
# 数据源配置项
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_system?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||||
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
|
username: root
|
||||||
|
password: 3WLiVUBEwTbvAfsh
|
||||||
|
# Spring Cloud 配置项
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
# Spring Cloud Nacos Discovery 配置项
|
||||||
|
discovery:
|
||||||
|
server-addr: 400-infra.server.iocoder.cn:8848 # Nacos 服务器地址
|
||||||
|
namespace: dev # Nacos 命名空间
|
||||||
|
|
||||||
|
# Dubbo 配置项
|
||||||
|
dubbo:
|
||||||
|
# Dubbo 注册中心
|
||||||
|
registry:
|
||||||
|
# address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||||
|
address: nacos://400-infra.server.iocoder.cn:8848?namespace=dev # 指定 Dubbo 服务注册中心的地址
|
||||||
|
# Dubbo 服务提供者的配置
|
||||||
|
provider:
|
||||||
|
tag: ${DUBBO_TAG} # Dubbo 路由分组
|
@ -0,0 +1,67 @@
|
|||||||
|
spring:
|
||||||
|
# Application 的配置项
|
||||||
|
application:
|
||||||
|
name: product-service
|
||||||
|
# Profile 的配置项
|
||||||
|
profiles:
|
||||||
|
active: local
|
||||||
|
|
||||||
|
# MyBatis Plus 配置项
|
||||||
|
mybatis-plus:
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
|
||||||
|
global-config:
|
||||||
|
db-config:
|
||||||
|
id-type: auto
|
||||||
|
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
|
||||||
|
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
|
||||||
|
mapper-locations: classpath*:mapper/*.xml
|
||||||
|
type-aliases-package: cn.iocoder.mall.productservice.dal.mysql.dataobject
|
||||||
|
|
||||||
|
# Dubbo 配置项
|
||||||
|
dubbo:
|
||||||
|
# Spring Cloud Alibaba Dubbo 专属配置
|
||||||
|
cloud:
|
||||||
|
subscribed-services: '' # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||||
|
# Dubbo 提供者的协议
|
||||||
|
protocol:
|
||||||
|
name: dubbo
|
||||||
|
port: -1
|
||||||
|
# Dubbo 提供服务的扫描基础包
|
||||||
|
scan:
|
||||||
|
base-packages: cn.iocoder.mall.productservice.rpc
|
||||||
|
# Dubbo 服务提供者的配置
|
||||||
|
provider:
|
||||||
|
filter: -exception
|
||||||
|
validation: true # 开启 Provider 参数校验
|
||||||
|
OAuth2Rpc:
|
||||||
|
version: 1.0.0
|
||||||
|
AdminRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
ResourceRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
RoleRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
PermissionRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
DepartmentRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
DataDictRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
ProductExceptionLogRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
ProductAccessLogRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
ErrorCodeRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
# Dubbo 服务消费者的配置
|
||||||
|
consumer:
|
||||||
|
ErrorCodeRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
|
||||||
|
# Mall 配置项
|
||||||
|
mall:
|
||||||
|
# 错误码配置项对应 ErrorCodeProperties 配置类
|
||||||
|
error-code:
|
||||||
|
group: ${spring.application.name}
|
||||||
|
constants-class: cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants
|
@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>product</artifactId>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>product-application</artifactId>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- Mall 相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>product-rest</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>product-rpc</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,26 +0,0 @@
|
|||||||
package cn.iocoder.mall.product.application;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.context.config.ConfigFileApplicationListener;
|
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
|
||||||
|
|
||||||
@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.product"})
|
|
||||||
@EnableAsync(proxyTargetClass = true)
|
|
||||||
public class ProductApplication {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置需要读取的配置文件的名字。
|
|
||||||
* 基于 {@link org.springframework.boot.context.config.ConfigFileApplicationListener#CONFIG_NAME_PROPERTY} 实现。
|
|
||||||
*/
|
|
||||||
private static final String CONFIG_NAME_VALUE = "biz,rest,rpc,application";
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// 设置环境变量
|
|
||||||
System.setProperty(ConfigFileApplicationListener.CONFIG_NAME_PROPERTY, CONFIG_NAME_VALUE);
|
|
||||||
|
|
||||||
// 启动 Spring Boot 应用
|
|
||||||
SpringApplication.run(ProductApplication.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
swagger:
|
|
||||||
enable: true
|
|
||||||
title: 商品子系统
|
|
||||||
description: 商品子系统
|
|
||||||
version: 1.0.0
|
|
||||||
base-package: cn.iocoder.mall.product.application.controller
|
|
@ -1,9 +0,0 @@
|
|||||||
spring:
|
|
||||||
# Application 的配置项
|
|
||||||
application:
|
|
||||||
name: product-application
|
|
||||||
# Profile 的配置项
|
|
||||||
profiles:
|
|
||||||
active: local
|
|
||||||
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
|||||||
package cn.iocoder.mall.product.biz.enums;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 错误码枚举类
|
|
||||||
*
|
|
||||||
* 商品系统,使用 1-003-000-000 段
|
|
||||||
*/
|
|
||||||
public enum ProductErrorCodeEnum implements ServiceExceptionUtil.Enumerable {
|
|
||||||
|
|
||||||
// ========== PRODUCT CATEGORY 模块 ==========
|
|
||||||
PRODUCT_CATEGORY_PARENT_NOT_EXISTS(1003001000, "父分类不存在"),
|
|
||||||
PRODUCT_CATEGORY_NOT_EXISTS(1003001001, "商品分类不存在"),
|
|
||||||
PRODUCT_CATEGORY_STATUS_NOT_EXISTS(1003001001, "商品分类状态不存在"),
|
|
||||||
PRODUCT_CATEGORY_PARENT_NOT_SELF(1003001002, "不能设置自己为父分类"),
|
|
||||||
PRODUCT_CATEGORY_STATUS_EQUALS(1002001003, "商品分类已经是该状态"),
|
|
||||||
PRODUCT_CATEGORY_DELETE_ONLY_DISABLE(1002001004, "只有关闭的商品分类才可以删除"),
|
|
||||||
PRODUCT_CATEGORY_DELETE_ONLY_NO_CHILD(1002001004, "只有无子分类的商品分类才可以删除"),
|
|
||||||
PRODUCT_CATEGORY_MUST_ENABLE(1002001005, "只有开启的商品分类,才可以使用"),
|
|
||||||
PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2(1002001005, "父分类必须是一级分类"),
|
|
||||||
|
|
||||||
// ========== PRODUCT SPU + SKU 模块 ==========
|
|
||||||
PRODUCT_SKU_ATTR_CANT_NOT_DUPLICATE(1003002000, "一个 Sku 下,不能有重复的规格"),
|
|
||||||
PRODUCT_SPU_ATTR_NUMBERS_MUST_BE_EQUALS(1003002001, "一个 Spu 下的每个 Sku ,其规格数必须一致"),
|
|
||||||
PRODUCT_SPU_SKU__NOT_DUPLICATE(1003002002, "一个 Spu 下的每个 Sku ,必须不重复"),
|
|
||||||
PRODUCT_SPU_NOT_EXISTS(1003002003, "Spu 不存在"),
|
|
||||||
PRODUCT_SPU_CATEGORY_MUST_BE_LEVEL2(1003002003, "Spu 只能添加在二级分类下"),
|
|
||||||
|
|
||||||
// ========== PRODUCT ATTR + ATTR_VALUE 模块 ==========
|
|
||||||
PRODUCT_ATTR_VALUE_NOT_EXIST(1003003000, "商品属性值不存在"),
|
|
||||||
PRODUCT_ATTR_NOT_EXIST(1003003001, "商品属性值不存在"),
|
|
||||||
PRODUCT_ATTR_EXISTS(1003003002, "商品规格已经存在"),
|
|
||||||
PRODUCT_ATTR_STATUS_EQUALS(1003003003, "商品规格已经是该状态"),
|
|
||||||
PRODUCT_ATTR_VALUE_EXISTS(1003003004, "商品规格值已经存在"),
|
|
||||||
PRODUCT_ATTR_VALUE_STATUS_EQUALS(1003003005, "商品规格值已经是该状态"),
|
|
||||||
|
|
||||||
// ========== PRODUCT BRAND模块 ==========
|
|
||||||
PRODUCT_BRAND_EXIST(1003004000, "品牌值已经存在"),
|
|
||||||
;
|
|
||||||
|
|
||||||
private final int code;
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
ProductErrorCodeEnum(int code, String message) {
|
|
||||||
this.code = code;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getGroup() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package cn.iocoder.mall.product.biz.enums.attr;
|
|
||||||
|
|
||||||
public class ProductAttrConstants {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ATTR 状态 - 开启
|
|
||||||
*/
|
|
||||||
public static final Integer ATTR_STATUS_ENABLE = 1;
|
|
||||||
/**
|
|
||||||
* ATTR 状态 - 关闭
|
|
||||||
*/
|
|
||||||
public static final Integer ATTR_STATUS_DISABLE = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ATTR_VALUE 状态 - 开启
|
|
||||||
*/
|
|
||||||
public static final Integer ATTR_VALUE_STATUS_ENABLE = 1;
|
|
||||||
/**
|
|
||||||
* ATTR_VALUE 状态 - 关闭
|
|
||||||
*/
|
|
||||||
public static final Integer ATTR_VALUE_STATUS_DISABLE = 2;
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package cn.iocoder.mall.product.biz.enums.category;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.core.IntArrayValuable;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: jiangweifan
|
|
||||||
* @Date: 2020/5/12
|
|
||||||
* @Description: 商品分类节点枚举
|
|
||||||
*/
|
|
||||||
public enum ProductCategoryNodeEnum{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根节点
|
|
||||||
*/
|
|
||||||
ROOT(0);
|
|
||||||
|
|
||||||
private final Integer id;
|
|
||||||
|
|
||||||
ProductCategoryNodeEnum(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package cn.iocoder.mall.product.biz.enums.category;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.core.IntArrayValuable;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: jiangweifan
|
|
||||||
* @Date: 2020/5/12
|
|
||||||
* @Description: 商品分类状态枚举
|
|
||||||
*/
|
|
||||||
public enum ProductCategoryStatusEnum implements IntArrayValuable {
|
|
||||||
|
|
||||||
ENABLED(1, "启用"),
|
|
||||||
DISABLED(2, "禁用");
|
|
||||||
|
|
||||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductCategoryStatusEnum::getStatus).toArray();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态
|
|
||||||
*/
|
|
||||||
private final Integer status;
|
|
||||||
/**
|
|
||||||
* 描述
|
|
||||||
*/
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
ProductCategoryStatusEnum(Integer status, String name) {
|
|
||||||
this.status = status;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int[] array() {
|
|
||||||
return ARRAYS;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cn.iocoder.mall.product.biz.enums.spu;
|
|
||||||
|
|
||||||
public class ProductSpuConstants {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态 - 开启
|
|
||||||
*/
|
|
||||||
public static final Integer SKU_STATUS_ENABLE = 1;
|
|
||||||
/**
|
|
||||||
* 状态 - 关闭
|
|
||||||
*/
|
|
||||||
public static final Integer SKU_STATUS_DISABLE = 2;
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
/**
|
|
||||||
* 该项目,主要用于暴露一些共享的枚举类等。
|
|
||||||
*
|
|
||||||
* 例如说,RPC 接口提供错误码给调用方
|
|
||||||
*/
|
|
||||||
package cn.iocoder.mall.product.biz;
|
|
@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* author: sin
|
|
||||||
* time: 2020/5/3 8:31 下午
|
|
||||||
*/
|
|
||||||
package cn.iocoder.mall.product.biz.bo;
|
|
@ -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,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* author: sin
|
|
||||||
* time: 2020/5/3 8:27 下午
|
|
||||||
*/
|
|
||||||
package cn.iocoder.mall.product.biz.dataobject;
|
|
@ -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,156 +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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductCategoryBO addProductCategory(ProductCategoryAddDTO productCategoryAddDTO) {
|
|
||||||
// 校验父分类
|
|
||||||
validParent(productCategoryAddDTO.getPid());
|
|
||||||
// 保存到数据库
|
|
||||||
ProductCategoryDO productCategory = ProductCategoryConvert.INSTANCE.convertToDO(productCategoryAddDTO)
|
|
||||||
.setStatus(ProductCategoryStatusEnum.ENABLED.getStatus());
|
|
||||||
productCategory.setCreateTime(new Date());
|
|
||||||
productCategory.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
|
||||||
productCategoryMapper.insert(productCategory);
|
|
||||||
// TODO 伟帆 操作日志
|
|
||||||
// 返回成功
|
|
||||||
return ProductCategoryConvert.INSTANCE.convertToBO(productCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean updateProductCategory(ProductCategoryUpdateDTO productCategoryUpdateDTO) {
|
|
||||||
// 校验当前分类是否存在
|
|
||||||
if (productCategoryMapper.selectById(productCategoryUpdateDTO.getId()) == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
// 校验父分类
|
|
||||||
validParent(productCategoryUpdateDTO.getPid());
|
|
||||||
// 校验不能设置自己为父分类
|
|
||||||
if (productCategoryUpdateDTO.getId().equals(productCategoryUpdateDTO.getPid())) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_SELF);
|
|
||||||
}
|
|
||||||
// 校验父分类是否存在
|
|
||||||
if (!ProductCategoryNodeEnum.ROOT.getId().equals(productCategoryUpdateDTO.getPid())
|
|
||||||
&& productCategoryMapper.selectById(productCategoryUpdateDTO.getPid()) == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
// 更新到数据库
|
|
||||||
ProductCategoryDO updateProductCategory = ProductCategoryConvert.INSTANCE.convertToDO(productCategoryUpdateDTO);
|
|
||||||
productCategoryMapper.updateById(updateProductCategory);
|
|
||||||
// TODO 伟帆 操作日志
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean updateProductCategoryStatus(ProductCategoryUpdateStatusDTO productCategoryUpdateStatusDTO) {
|
|
||||||
// 校验商品分类是否存在
|
|
||||||
ProductCategoryDO productCategoryDO = productCategoryMapper.selectById(productCategoryUpdateStatusDTO.getId());
|
|
||||||
if (productCategoryDO == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
// 判断更新状态是否存在
|
|
||||||
if (Arrays.stream(ProductCategoryStatusEnum.ARRAYS).noneMatch(status -> status == productCategoryUpdateStatusDTO.getStatus())) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_STATUS_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
// 如果状态相同,则返回错误
|
|
||||||
if (productCategoryDO.getStatus().equals(productCategoryUpdateStatusDTO.getStatus())) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_STATUS_EQUALS);
|
|
||||||
}
|
|
||||||
// 更新商品分类状态
|
|
||||||
ProductCategoryDO updateCategoryStatus = ProductCategoryConvert.INSTANCE.convertToDO(productCategoryUpdateStatusDTO);
|
|
||||||
productCategoryMapper.updateById(updateCategoryStatus);
|
|
||||||
// TODO 伟帆 操作日志
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean deleteProductCategory(ProductCategoryDeleteDTO productCategoryDeleteDTO) {
|
|
||||||
Integer productCategoryId = productCategoryDeleteDTO.getId();
|
|
||||||
// 校验分类是否存在
|
|
||||||
ProductCategoryDO productCategory = productCategoryMapper.selectById(productCategoryId);
|
|
||||||
if (productCategory == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
// 只有禁用的商品分类才可以删除
|
|
||||||
if (ProductCategoryStatusEnum.ENABLED.getStatus().equals(productCategory.getStatus())) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_DELETE_ONLY_DISABLE);
|
|
||||||
}
|
|
||||||
// 只有不存在子分类才可以删除
|
|
||||||
// TODO FROM 芋艿 to jiangweifan:Wrappers 只用在 Mapper 层 [DONE]
|
|
||||||
Integer childCount = productCategoryMapper.selectChildCategoryCount(productCategoryId);
|
|
||||||
if (childCount > 0) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_DELETE_ONLY_NO_CHILD);
|
|
||||||
}
|
|
||||||
// TODO 伟帆 补充只有不存在商品才可以删除
|
|
||||||
// 标记删除商品分类
|
|
||||||
productCategoryMapper.deleteById(productCategoryId);
|
|
||||||
// TODO 伟帆 操作日志
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validParent(Integer pid) {
|
|
||||||
if (!ProductCategoryNodeEnum.ROOT.getId().equals(pid)) {
|
|
||||||
ProductCategoryDO parentCategory = productCategoryMapper.selectById(pid);
|
|
||||||
// 校验父分类是否存在
|
|
||||||
if (parentCategory == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
// 父分类必须是一级分类
|
|
||||||
if (!ProductCategoryNodeEnum.ROOT.getId().equals(parentCategory.getPid())) {
|
|
||||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_PARENT_CAN_NOT_BE_LEVEL2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductCategoryDO validProductCategory(Integer productCategoryId) {
|
|
||||||
// 校验分类是否存在
|
|
||||||
ProductCategoryDO productCategory = productCategoryMapper.selectById(productCategoryId);
|
|
||||||
if (productCategory == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode());
|
|
||||||
}
|
|
||||||
// 只有禁用的商品分类才可以删除
|
|
||||||
if (ProductCategoryStatusEnum.DISABLED.getStatus().equals(productCategory.getStatus())) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_MUST_ENABLE.getCode());
|
|
||||||
}
|
|
||||||
// 返回结果
|
|
||||||
return productCategory;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* author: sin
|
|
||||||
* time: 2020/5/3 8:31 下午
|
|
||||||
*/
|
|
||||||
package cn.iocoder.mall.product.biz.service;
|
|
@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>demo</artifactId>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>product-mq</artifactId>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
@ -1 +0,0 @@
|
|||||||
package cn.iocoder.mall.demo.mq;
|
|
@ -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;
|
|
||||||
}
|
|
@ -1,154 +0,0 @@
|
|||||||
package cn.iocoder.mall.product.service;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
|
||||||
import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum;
|
|
||||||
import cn.iocoder.mall.product.api.ProductCategoryService;
|
|
||||||
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
|
|
||||||
import cn.iocoder.mall.product.api.constant.ProductCategoryConstants;
|
|
||||||
import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum;
|
|
||||||
import cn.iocoder.mall.product.api.dto.ProductCategoryAddDTO;
|
|
||||||
import cn.iocoder.mall.product.api.dto.ProductCategoryUpdateDTO;
|
|
||||||
import cn.iocoder.mall.product.convert.ProductCategoryConvert;
|
|
||||||
import cn.iocoder.mall.product.dao.ProductCategoryMapper;
|
|
||||||
import cn.iocoder.mall.product.dataobject.ProductCategoryDO;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
|
|
||||||
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.ProductCategoryService.version}")
|
|
||||||
public class ProductCategoryServiceImpl implements ProductCategoryService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ProductCategoryMapper productCategoryMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ProductCategoryBO> getListByPid(Integer pid) {
|
|
||||||
List<ProductCategoryDO> categoryList = productCategoryMapper.selectListByPidAndStatusOrderBySort(pid, ProductCategoryConstants.STATUS_ENABLE);
|
|
||||||
return ProductCategoryConvert.INSTANCE.convertToBO(categoryList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ProductCategoryBO> getListByIds(Collection<Integer> ids) {
|
|
||||||
List<ProductCategoryDO> categoryList = productCategoryMapper.selectByIds(ids);
|
|
||||||
return ProductCategoryConvert.INSTANCE.convertToBO(categoryList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ProductCategoryBO> getAll() {
|
|
||||||
List<ProductCategoryDO> categoryList = productCategoryMapper.selectList();
|
|
||||||
return ProductCategoryConvert.INSTANCE.convertToBO(categoryList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductCategoryBO addProductCategory(Integer adminId, ProductCategoryAddDTO productCategoryAddDTO) {
|
|
||||||
// 校验父分类
|
|
||||||
validParent(productCategoryAddDTO.getPid());
|
|
||||||
// 保存到数据库
|
|
||||||
ProductCategoryDO productCategory = ProductCategoryConvert.INSTANCE.convert(productCategoryAddDTO)
|
|
||||||
.setStatus(ProductCategoryConstants.STATUS_ENABLE);
|
|
||||||
productCategory.setCreateTime(new Date());
|
|
||||||
productCategory.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
|
||||||
productCategoryMapper.insert(productCategory);
|
|
||||||
// TODO 操作日志
|
|
||||||
// 返回成功
|
|
||||||
return ProductCategoryConvert.INSTANCE.convertToBO(productCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean updateProductCategory(Integer adminId, ProductCategoryUpdateDTO productCategoryUpdateDTO) {
|
|
||||||
// 校验父分类
|
|
||||||
validParent(productCategoryUpdateDTO.getPid());
|
|
||||||
// 校验不能设置自己为父分类
|
|
||||||
if (productCategoryUpdateDTO.getId().equals(productCategoryUpdateDTO.getPid())) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_SELF.getCode());
|
|
||||||
}
|
|
||||||
// 校验父分类是否存在
|
|
||||||
if (!ProductCategoryConstants.PID_ROOT.equals(productCategoryUpdateDTO.getPid())
|
|
||||||
&& productCategoryMapper.selectById(productCategoryUpdateDTO.getPid()) == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_EXISTS.getCode());
|
|
||||||
}
|
|
||||||
// 更新到数据库
|
|
||||||
ProductCategoryDO updateProductCategory = ProductCategoryConvert.INSTANCE.convert(productCategoryUpdateDTO);
|
|
||||||
productCategoryMapper.update(updateProductCategory);
|
|
||||||
// TODO 操作日志
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean updateProductCategoryStatus(Integer adminId, Integer productCategoryId, Integer status) {
|
|
||||||
// 校验分类是否存在
|
|
||||||
ProductCategoryDO productCategory = productCategoryMapper.selectById(productCategoryId);
|
|
||||||
if (productCategory == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode());
|
|
||||||
}
|
|
||||||
// 如果状态相同,则返回错误
|
|
||||||
if (productCategory.getStatus().equals(status)) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_STATUS_EQUALS.getCode());
|
|
||||||
}
|
|
||||||
// 更新商品分类
|
|
||||||
ProductCategoryDO updateProductCategory = new ProductCategoryDO()
|
|
||||||
.setId(productCategoryId).setStatus(status);
|
|
||||||
productCategoryMapper.update(updateProductCategory);
|
|
||||||
// TODO 操作日志
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean deleteProductCategory(Integer admin, Integer productCategoryId) {
|
|
||||||
// 校验分类是否存在
|
|
||||||
ProductCategoryDO productCategory = productCategoryMapper.selectById(productCategoryId);
|
|
||||||
if (productCategory == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode());
|
|
||||||
}
|
|
||||||
// 只有禁用的商品分类才可以删除
|
|
||||||
if (ProductCategoryConstants.STATUS_ENABLE.equals(productCategory.getStatus())) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_DELETE_ONLY_DISABLE.getCode());
|
|
||||||
}
|
|
||||||
// TODO 芋艿:考虑下,是否需要判断下该分类下是否有商品
|
|
||||||
// TODO 芋艿,需要补充下,还有子分类
|
|
||||||
// 标记删除商品分类
|
|
||||||
ProductCategoryDO updateProductCategory = new ProductCategoryDO()
|
|
||||||
.setId(productCategoryId);
|
|
||||||
updateProductCategory.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
|
|
||||||
productCategoryMapper.update(updateProductCategory);
|
|
||||||
// TODO 操作日志
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductCategoryDO getProductCategory(Integer productCategoryId) {
|
|
||||||
return productCategoryMapper.selectById(productCategoryId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductCategoryDO validProductCategory(Integer productCategoryId) {
|
|
||||||
// 校验分类是否存在
|
|
||||||
ProductCategoryDO productCategory = productCategoryMapper.selectById(productCategoryId);
|
|
||||||
if (productCategory == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_NOT_EXISTS.getCode());
|
|
||||||
}
|
|
||||||
// 只有禁用的商品分类才可以删除
|
|
||||||
if (ProductCategoryConstants.STATUS_DISABLE.equals(productCategory.getStatus())) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_CATEGORY_MUST_ENABLE.getCode());
|
|
||||||
}
|
|
||||||
// 返回结果
|
|
||||||
return productCategory;
|
|
||||||
}
|
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -40,14 +40,6 @@
|
|||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-tx</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-jdbc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>druid-spring-boot-starter</artifactId>
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
|
@ -122,9 +122,9 @@ public class ResourceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得资源树结构
|
* 获得资源全列表
|
||||||
*
|
*
|
||||||
* @return 资源树结构
|
* @return 资源全列表
|
||||||
*/
|
*/
|
||||||
public List<ResourceBO> listResources() {
|
public List<ResourceBO> listResources() {
|
||||||
List<ResourceDO> resourceDOs = resourceMapper.selectList(null);
|
List<ResourceDO> resourceDOs = resourceMapper.selectList(null);
|
||||||
|
@ -30,20 +30,10 @@ public class UserAddressCreateReqDTO implements Serializable {
|
|||||||
@NotEmpty(message = "手机号不能为空")
|
@NotEmpty(message = "手机号不能为空")
|
||||||
private String mobile;
|
private String mobile;
|
||||||
/**
|
/**
|
||||||
* 省份编号
|
* 地区编码
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "省份编号不能为空")
|
@NotNull(message = "地区编码不能为空")
|
||||||
private Integer provinceCode;
|
private Integer areaCode;
|
||||||
/**
|
|
||||||
* 城市编号
|
|
||||||
*/
|
|
||||||
@NotNull(message = "城市编号不能为空")
|
|
||||||
private Integer cityCode;
|
|
||||||
/**
|
|
||||||
* 区域编号
|
|
||||||
*/
|
|
||||||
@NotNull(message = "区域编号不能为空")
|
|
||||||
private Integer countyCode;
|
|
||||||
/**
|
/**
|
||||||
* 收件详细地址
|
* 收件详细地址
|
||||||
*/
|
*/
|
||||||
|
@ -30,17 +30,9 @@ public class UserAddressRespDTO implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String mobile;
|
private String mobile;
|
||||||
/**
|
/**
|
||||||
* 省份编号
|
* 地区编码
|
||||||
*/
|
*/
|
||||||
private Integer provinceCode;
|
private Integer areaCode;
|
||||||
/**
|
|
||||||
* 城市编号
|
|
||||||
*/
|
|
||||||
private Integer cityCode;
|
|
||||||
/**
|
|
||||||
* 区域编号
|
|
||||||
*/
|
|
||||||
private Integer countyCode;
|
|
||||||
/**
|
/**
|
||||||
* 收件详细地址
|
* 收件详细地址
|
||||||
*/
|
*/
|
||||||
|
@ -41,20 +41,10 @@ public class UserAddressUpdateReqDTO implements Serializable {
|
|||||||
@Mobile
|
@Mobile
|
||||||
private String mobile;
|
private String mobile;
|
||||||
/**
|
/**
|
||||||
* 省份编号
|
* 地区编码
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "省份编号不能为空")
|
@NotNull(message = "地区编码不能为空")
|
||||||
private Integer provinceCode;
|
private Integer areaCode;
|
||||||
/**
|
|
||||||
* 城市编号
|
|
||||||
*/
|
|
||||||
@NotNull(message = "城市编号不能为空")
|
|
||||||
private Integer cityCode;
|
|
||||||
/**
|
|
||||||
* 区域编号
|
|
||||||
*/
|
|
||||||
@NotNull(message = "区域编号不能为空")
|
|
||||||
private Integer countyCode;
|
|
||||||
/**
|
/**
|
||||||
* 收件详细地址
|
* 收件详细地址
|
||||||
*/
|
*/
|
||||||
|
@ -38,17 +38,9 @@ public class UserAddressDO extends DeletableDO {
|
|||||||
*/
|
*/
|
||||||
private String mobile;
|
private String mobile;
|
||||||
/**
|
/**
|
||||||
* 省份编号
|
* 地区编码
|
||||||
*/
|
*/
|
||||||
private Integer provinceCode;
|
private Integer areaCode;
|
||||||
/**
|
|
||||||
* 城市编号
|
|
||||||
*/
|
|
||||||
private Integer cityCode;
|
|
||||||
/**
|
|
||||||
* 区域编号
|
|
||||||
*/
|
|
||||||
private Integer countyCode;
|
|
||||||
/**
|
/**
|
||||||
* 收件详细地址
|
* 收件详细地址
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||||||
public interface UserAddressMapper extends BaseMapper<UserAddressDO> {
|
public interface UserAddressMapper extends BaseMapper<UserAddressDO> {
|
||||||
|
|
||||||
default List<UserAddressDO> selectListByUserIdAndType(Integer userId, @Nullable Integer type) {
|
default List<UserAddressDO> selectListByUserIdAndType(Integer userId, @Nullable Integer type) {
|
||||||
return selectList(new QueryWrapperX<UserAddressDO>().eq("userId", userId)
|
return selectList(new QueryWrapperX<UserAddressDO>().eq("user_id", userId)
|
||||||
.eqIfPresent("type", type));
|
.eqIfPresent("type", type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,17 +29,9 @@ public class UserAddressBO {
|
|||||||
*/
|
*/
|
||||||
private String mobile;
|
private String mobile;
|
||||||
/**
|
/**
|
||||||
* 省份编号
|
* 地区编码
|
||||||
*/
|
*/
|
||||||
private Integer provinceCode;
|
private Integer areaCode;
|
||||||
/**
|
|
||||||
* 城市编号
|
|
||||||
*/
|
|
||||||
private Integer cityCode;
|
|
||||||
/**
|
|
||||||
* 区域编号
|
|
||||||
*/
|
|
||||||
private Integer countyCode;
|
|
||||||
/**
|
/**
|
||||||
* 收件详细地址
|
* 收件详细地址
|
||||||
*/
|
*/
|
||||||
@ -52,13 +44,5 @@ public class UserAddressBO {
|
|||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
/**
|
|
||||||
* 最后更新时间
|
|
||||||
*/
|
|
||||||
private Date updateTime;
|
|
||||||
/**
|
|
||||||
* 删除状态
|
|
||||||
*/
|
|
||||||
private Integer deleted;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,20 +31,10 @@ public class UserAddressCreateBO {
|
|||||||
@Mobile
|
@Mobile
|
||||||
private String mobile;
|
private String mobile;
|
||||||
/**
|
/**
|
||||||
* 省份编号
|
* 地区编码
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "省份编号不能为空")
|
@NotNull(message = "地区编码不能为空")
|
||||||
private Integer provinceCode;
|
private Integer areaCode;
|
||||||
/**
|
|
||||||
* 城市编号
|
|
||||||
*/
|
|
||||||
@NotNull(message = "城市编号不能为空")
|
|
||||||
private Integer cityCode;
|
|
||||||
/**
|
|
||||||
* 区域编号
|
|
||||||
*/
|
|
||||||
@NotNull(message = "区域编号不能为空")
|
|
||||||
private Integer countyCode;
|
|
||||||
/**
|
/**
|
||||||
* 收件详细地址
|
* 收件详细地址
|
||||||
*/
|
*/
|
||||||
|
@ -34,20 +34,10 @@ public class UserAddressUpdateBO {
|
|||||||
@NotEmpty(message = "手机号不能为空")
|
@NotEmpty(message = "手机号不能为空")
|
||||||
private String mobile;
|
private String mobile;
|
||||||
/**
|
/**
|
||||||
* 省份编号
|
* 地区编码
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "省份编号不能为空")
|
@NotNull(message = "地区编码不能为空")
|
||||||
private Integer provinceCode;
|
private Integer areaCode;
|
||||||
/**
|
|
||||||
* 城市编号
|
|
||||||
*/
|
|
||||||
@NotNull(message = "城市编号不能为空")
|
|
||||||
private Integer cityCode;
|
|
||||||
/**
|
|
||||||
* 区域编号
|
|
||||||
*/
|
|
||||||
@NotNull(message = "区域编号不能为空")
|
|
||||||
private Integer countyCode;
|
|
||||||
/**
|
/**
|
||||||
* 收件详细地址
|
* 收件详细地址
|
||||||
*/
|
*/
|
||||||
|
@ -38,6 +38,8 @@ dubbo:
|
|||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
UserSmsCodeRpc:
|
UserSmsCodeRpc:
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
UserAddressRpc:
|
||||||
|
version: 1.0.0
|
||||||
# Dubbo 服务消费者的配置
|
# Dubbo 服务消费者的配置
|
||||||
consumer:
|
consumer:
|
||||||
OAuth2Rpc:
|
OAuth2Rpc:
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
### /user-address/get-default 成功
|
||||||
|
GET {{user-api-base-url}}/user-address/get-default
|
||||||
|
Authorization: Bearer {{user-access-token}}
|
||||||
|
|
||||||
|
###
|
@ -23,7 +23,7 @@ import static cn.iocoder.common.framework.vo.CommonResult.success;
|
|||||||
* 用户收件地址 Controller
|
* 用户收件地址 Controller
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/user_address")
|
@RequestMapping("/user-address")
|
||||||
@Api(tags = "用户收件地址")
|
@Api(tags = "用户收件地址")
|
||||||
@Validated
|
@Validated
|
||||||
public class UserAddressController {
|
public class UserAddressController {
|
||||||
@ -63,12 +63,18 @@ public class UserAddressController {
|
|||||||
return success(userAddressManager.getUserAddress(UserSecurityContextHolder.getUserId(), userAddressId));
|
return success(userAddressManager.getUserAddress(UserSecurityContextHolder.getUserId(), userAddressId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get-default")
|
||||||
|
@ApiOperation("获得默认的用户收件地址")
|
||||||
|
@RequiresPermissions
|
||||||
|
public CommonResult<UserAddressRespVO> getDefaultUserAddress() {
|
||||||
|
return success(userAddressManager.getDefaultUserAddress(UserSecurityContextHolder.getUserId()));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperation("获得用户收件地址列表")
|
@ApiOperation("获得用户收件地址列表")
|
||||||
@ApiImplicitParam(name = "userAddressIds", value = "用户收件地址编号列表", required = true)
|
|
||||||
@RequiresPermissions
|
@RequiresPermissions
|
||||||
public CommonResult<List<UserAddressRespVO>> listUserAddresses(@RequestParam("userAddressIds") List<Integer> userAddressIds) {
|
public CommonResult<List<UserAddressRespVO>> listUserAddresses() {
|
||||||
return success(userAddressManager.listUserAddresses(UserSecurityContextHolder.getUserId(), userAddressIds));
|
return success(userAddressManager.listUserAddresses(UserSecurityContextHolder.getUserId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,15 +19,9 @@ public class UserAddressCreateReqVO {
|
|||||||
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
|
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
|
||||||
@NotEmpty(message = "手机号不能为空")
|
@NotEmpty(message = "手机号不能为空")
|
||||||
private String mobile;
|
private String mobile;
|
||||||
@ApiModelProperty(value = "省份编号", required = true, example = "230000")
|
|
||||||
@NotNull(message = "省份编号不能为空")
|
|
||||||
private Integer provinceCode;
|
|
||||||
@ApiModelProperty(value = "城市编号", required = true, example = "469031")
|
|
||||||
@NotNull(message = "城市编号不能为空")
|
|
||||||
private Integer cityCode;
|
|
||||||
@ApiModelProperty(value = "区域编号", required = true, example = "610632")
|
@ApiModelProperty(value = "区域编号", required = true, example = "610632")
|
||||||
@NotNull(message = "区域编号不能为空")
|
@NotNull(message = "地区编码不能为空")
|
||||||
private Integer countyCode;
|
private Integer areaCode;
|
||||||
@ApiModelProperty(value = "收件详细地址", required = true, example = "芋道源码 233 号 666 室")
|
@ApiModelProperty(value = "收件详细地址", required = true, example = "芋道源码 233 号 666 室")
|
||||||
@NotEmpty(message = "收件详细地址不能为空")
|
@NotEmpty(message = "收件详细地址不能为空")
|
||||||
private String detailAddress;
|
private String detailAddress;
|
||||||
|
@ -1,35 +1,31 @@
|
|||||||
package cn.iocoder.mall.userweb.controller.address.vo;
|
package cn.iocoder.mall.userweb.controller.address.vo;
|
||||||
|
|
||||||
import lombok.*;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import java.util.*;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@ApiModel("用户收件地址 Response VO")
|
@ApiModel("用户收件地址 Response VO")
|
||||||
@Data
|
@Data
|
||||||
public class UserAddressRespVO {
|
public class UserAddressRespVO {
|
||||||
|
|
||||||
@ApiModelProperty(value = "收件地址编号", required = true)
|
@ApiModelProperty(value = "收件地址编号", required = true, example = "1024")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
@ApiModelProperty(value = "用户编号", required = true)
|
@ApiModelProperty(value = "用户编号", required = true, example = "2048")
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
@ApiModelProperty(value = "收件人名称", required = true)
|
@ApiModelProperty(value = "收件人名称", required = true, example = "帅艿艿")
|
||||||
private String name;
|
private String name;
|
||||||
@ApiModelProperty(value = "手机号", required = true)
|
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
|
||||||
private String mobile;
|
private String mobile;
|
||||||
@ApiModelProperty(value = "省份编号", required = true)
|
@ApiModelProperty(value = "区域编号", required = true, example = "610632")
|
||||||
private Integer provinceCode;
|
private Integer areaCode;
|
||||||
@ApiModelProperty(value = "城市编号", required = true)
|
@ApiModelProperty(value = "收件详细地址", required = true, example = "芋道源码 233 号 666 室")
|
||||||
private Integer cityCode;
|
|
||||||
@ApiModelProperty(value = "区域编号", required = true)
|
|
||||||
private Integer countyCode;
|
|
||||||
@ApiModelProperty(value = "收件详细地址", required = true)
|
|
||||||
private String detailAddress;
|
private String detailAddress;
|
||||||
@ApiModelProperty(value = "地址类型", required = true)
|
@ApiModelProperty(value = "地址类型", required = true, example = "1", notes = "参见 UserAddressType 枚举类")
|
||||||
private Integer type;
|
private Integer type;
|
||||||
@ApiModelProperty(value = "创建时间", required = true)
|
@ApiModelProperty(value = "创建时间", required = true)
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
@ApiModelProperty(value = "最后更新时间", required = true)
|
|
||||||
private Date updateTime;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import javax.validation.constraints.NotNull;
|
|||||||
@Data
|
@Data
|
||||||
public class UserAddressUpdateReqVO {
|
public class UserAddressUpdateReqVO {
|
||||||
|
|
||||||
@ApiModelProperty(value = "收件地址编号", required = true)
|
@ApiModelProperty(value = "收件地址编号", required = true, example = "1024")
|
||||||
@NotNull(message = "收件地址编号不能为空")
|
@NotNull(message = "收件地址编号不能为空")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
@ApiModelProperty(value = "收件人名称", required = true, example = "帅艿艿")
|
@ApiModelProperty(value = "收件人名称", required = true, example = "帅艿艿")
|
||||||
@ -22,15 +22,9 @@ public class UserAddressUpdateReqVO {
|
|||||||
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
|
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
|
||||||
@NotEmpty(message = "手机号不能为空")
|
@NotEmpty(message = "手机号不能为空")
|
||||||
private String mobile;
|
private String mobile;
|
||||||
@ApiModelProperty(value = "省份编号", required = true, example = "230000")
|
|
||||||
@NotNull(message = "省份编号不能为空")
|
|
||||||
private Integer provinceCode;
|
|
||||||
@ApiModelProperty(value = "城市编号", required = true, example = "469031")
|
|
||||||
@NotNull(message = "城市编号不能为空")
|
|
||||||
private Integer cityCode;
|
|
||||||
@ApiModelProperty(value = "区域编号", required = true, example = "610632")
|
@ApiModelProperty(value = "区域编号", required = true, example = "610632")
|
||||||
@NotNull(message = "区域编号不能为空")
|
@NotNull(message = "地区编码不能为空")
|
||||||
private Integer countyCode;
|
private Integer areaCode;
|
||||||
@ApiModelProperty(value = "收件详细地址", required = true, example = "芋道源码 233 号 666 室")
|
@ApiModelProperty(value = "收件详细地址", required = true, example = "芋道源码 233 号 666 室")
|
||||||
@NotEmpty(message = "收件详细地址不能为空")
|
@NotEmpty(message = "收件详细地址不能为空")
|
||||||
private String detailAddress;
|
private String detailAddress;
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package cn.iocoder.mall.userweb.manager.address;
|
package cn.iocoder.mall.userweb.manager.address;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.exception.GlobalException;
|
import cn.iocoder.common.framework.exception.GlobalException;
|
||||||
|
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
|
import cn.iocoder.mall.userservice.enums.address.UserAddressType;
|
||||||
import cn.iocoder.mall.userservice.rpc.address.UserAddressRpc;
|
import cn.iocoder.mall.userservice.rpc.address.UserAddressRpc;
|
||||||
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
|
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
|
||||||
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressCreateReqVO;
|
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressCreateReqVO;
|
||||||
@ -48,7 +50,8 @@ public class UserAddressManager {
|
|||||||
// 校验是否能够操作
|
// 校验是否能够操作
|
||||||
check(userId, updateVO.getId());
|
check(userId, updateVO.getId());
|
||||||
// 执行更新
|
// 执行更新
|
||||||
CommonResult<Boolean> updateUserAddressResult = userAddressRpc.updateUserAddress(UserAddressConvert.INSTANCE.convert(updateVO));
|
CommonResult<Boolean> updateUserAddressResult = userAddressRpc.updateUserAddress(UserAddressConvert.INSTANCE.convert(updateVO)
|
||||||
|
.setUserId(userId));
|
||||||
updateUserAddressResult.checkError();
|
updateUserAddressResult.checkError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,17 +88,27 @@ public class UserAddressManager {
|
|||||||
* 获得用户收件地址列表
|
* 获得用户收件地址列表
|
||||||
*
|
*
|
||||||
* @param userId 用户编号
|
* @param userId 用户编号
|
||||||
* @param userAddressIds 用户收件地址编号列表
|
|
||||||
* @return 用户收件地址列表
|
* @return 用户收件地址列表
|
||||||
*/
|
*/
|
||||||
public List<UserAddressRespVO> listUserAddresses(Integer userId, List<Integer> userAddressIds) {
|
public List<UserAddressRespVO> listUserAddresses(Integer userId) {
|
||||||
CommonResult<List<UserAddressRespDTO>> listUserAddressResult = userAddressRpc.listUserAddresses(userAddressIds);
|
CommonResult<List<UserAddressRespDTO>> listUserAddressResult = userAddressRpc.listUserAddresses(userId, null);
|
||||||
listUserAddressResult.checkError();
|
listUserAddressResult.checkError();
|
||||||
// 校验是否能够操作
|
|
||||||
listUserAddressResult.getData().forEach(userAddressRespDTO -> check(userId, userAddressRespDTO));
|
|
||||||
return UserAddressConvert.INSTANCE.convertList(listUserAddressResult.getData());
|
return UserAddressConvert.INSTANCE.convertList(listUserAddressResult.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户的默认收件地址
|
||||||
|
*
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @return 用户收件地址
|
||||||
|
*/
|
||||||
|
public UserAddressRespVO getDefaultUserAddress(Integer userId) {
|
||||||
|
CommonResult<List<UserAddressRespDTO>> listUserAddressResult = userAddressRpc.listUserAddresses(userId, UserAddressType.DEFAULT.getType());
|
||||||
|
listUserAddressResult.checkError();
|
||||||
|
return !CollectionUtils.isEmpty(listUserAddressResult.getData()) ?
|
||||||
|
UserAddressConvert.INSTANCE.convert(listUserAddressResult.getData().get(0)) : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验用户收件地址是不是属于该用户
|
* 校验用户收件地址是不是属于该用户
|
||||||
*
|
*
|
||||||
|
@ -35,6 +35,8 @@ dubbo:
|
|||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
SystemExceptionLogRpc:
|
SystemExceptionLogRpc:
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
UserAddressRpc:
|
||||||
|
version: 1.0.0
|
||||||
|
|
||||||
# Swagger 配置项
|
# Swagger 配置项
|
||||||
swagger:
|
swagger:
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>user</artifactId>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>user-rest</artifactId>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- Mall 相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>user-biz</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Web 相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>mall-spring-boot-starter-web</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>mall-spring-boot-starter-security</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>mall-spring-boot-starter-swagger</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,81 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.rest.controller.user;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
|
||||||
import cn.iocoder.mall.security.core.context.UserSecurityContextHolder;
|
|
||||||
import cn.iocoder.mall.user.biz.dto.user.UserAddressAddDTO;
|
|
||||||
import cn.iocoder.mall.user.biz.dto.user.UserAddressUpdateDTO;
|
|
||||||
import cn.iocoder.mall.user.biz.service.user.UserAddressService;
|
|
||||||
import cn.iocoder.mall.user.rest.convert.UserAddressConvert;
|
|
||||||
import cn.iocoder.mall.user.rest.request.user.UserAddressAddRequest;
|
|
||||||
import cn.iocoder.mall.user.rest.request.user.UserAddressUpdateRequest;
|
|
||||||
import cn.iocoder.mall.user.rest.response.user.UserAddressResponse;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户地址(user API)
|
|
||||||
*
|
|
||||||
* author: sin
|
|
||||||
* time: 2020/5/8 9:50
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@Api(tags = "用户地址(user API)") // TODO FROM 芋艿 to 小范:"管理员 - 管理员 API" 按照类似酱紫的格式哈。= = 虽然我也没想太好格式。
|
|
||||||
@RequestMapping("/users/user-address")
|
|
||||||
public class UsersUserAddressController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserAddressService userAddressService;
|
|
||||||
|
|
||||||
@GetMapping("list-address")
|
|
||||||
@ApiOperation("获取 - 地址列表(all)")
|
|
||||||
public CommonResult<List<UserAddressResponse>> listAddress() {
|
|
||||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
|
||||||
return CommonResult.success(UserAddressConvert.INSTANCE.convert(userAddressService.listAddress(userId)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("{addressId}")
|
|
||||||
@ApiOperation("获取 - 根据id获取")
|
|
||||||
public CommonResult<UserAddressResponse> getAddress(@PathVariable("addressId") Integer addressId) {
|
|
||||||
return CommonResult.success(UserAddressConvert.INSTANCE.convert(userAddressService.getAddress(addressId)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("default")
|
|
||||||
@ApiOperation("获取 - 获取默认地址")
|
|
||||||
public CommonResult<UserAddressResponse> getDefaultAddress() {
|
|
||||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
|
||||||
return CommonResult.success(UserAddressConvert.INSTANCE.convert(userAddressService.getDefaultAddress(userId)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{addressId}/remove")
|
|
||||||
@ApiOperation("删除 - 根据id删除")
|
|
||||||
public CommonResult getDefaultAddress(@PathVariable("addressId") Integer addressId) {
|
|
||||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
|
||||||
userAddressService.removeAddress(userId, addressId);
|
|
||||||
return CommonResult.success(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/add-address")
|
|
||||||
@ApiOperation("添加地址")
|
|
||||||
public CommonResult addAddress(@RequestBody @Valid UserAddressAddRequest userAddressAddRequest) {
|
|
||||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
|
||||||
UserAddressAddDTO userAddressAddDTO = UserAddressConvert.INSTANCE.convert(userAddressAddRequest);
|
|
||||||
userAddressAddDTO.setUserId(userId);
|
|
||||||
userAddressService.addAddress(userAddressAddDTO);
|
|
||||||
return CommonResult.success(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/update-address")
|
|
||||||
@ApiOperation("更新地址")
|
|
||||||
public CommonResult updateAddress(@RequestBody @Valid UserAddressUpdateRequest userAddressAddRequest) {
|
|
||||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
|
||||||
UserAddressUpdateDTO userAddressAddDTO = UserAddressConvert.INSTANCE.convert(userAddressAddRequest);
|
|
||||||
userAddressAddDTO.setUserId(userId);
|
|
||||||
userAddressService.updateAddress(userAddressAddDTO);
|
|
||||||
return CommonResult.success(null);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.rest.request.user;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户地址 add
|
|
||||||
*
|
|
||||||
* @author Sin
|
|
||||||
* @time 2019-04-06 13:25
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@ApiModel("用户地址(添加)")
|
|
||||||
public class UserAddressAddRequest implements Serializable {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("收件区域编号")
|
|
||||||
private String areaNo;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("收件人名称")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("收件手机号")
|
|
||||||
private String mobile;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("收件详细地址")
|
|
||||||
private String address;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("是否默认 1 不是 2 是")
|
|
||||||
private Integer hasDefault;
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.rest.request.user;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户地址 更新
|
|
||||||
*
|
|
||||||
* @author Sin
|
|
||||||
* @time 2019-04-06 13:28
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@ApiModel("用户地址(更新)")
|
|
||||||
public class UserAddressUpdateRequest implements Serializable {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("编号")
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("收件区域编号")
|
|
||||||
private String areaNo;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("收件人名称")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("收件手机号")
|
|
||||||
private String mobile;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("收件详细地址")
|
|
||||||
private String address;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ApiModelProperty("是否默认地址")
|
|
||||||
private Integer hasDefault;
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.rest.response.user;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户地址
|
|
||||||
*
|
|
||||||
* @author Sin
|
|
||||||
* @time 2019-04-06 13:28
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@ApiModel(value = "用户地址")
|
|
||||||
public class UserAddressResponse implements Serializable {
|
|
||||||
|
|
||||||
@ApiModelProperty("编号")
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
@ApiModelProperty("用户编号")
|
|
||||||
private Integer userId;
|
|
||||||
|
|
||||||
@ApiModelProperty("收件区域编号")
|
|
||||||
private String areaNo;
|
|
||||||
|
|
||||||
@ApiModelProperty("收件人名称")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@ApiModelProperty("收件手机号")
|
|
||||||
private String mobile;
|
|
||||||
|
|
||||||
@ApiModelProperty("收件详细地址")
|
|
||||||
private String address;
|
|
||||||
|
|
||||||
@ApiModelProperty("是否默认")
|
|
||||||
private Integer hasDefault;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user