商品分类的迁移,未完成,先提交下~
parent
4198c154aa
commit
b209505f99
|
@ -31,6 +31,7 @@ import org.springframework.web.servlet.NoHandlerFoundException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.ValidationException;
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.common.framework.exception.enums.GlobalErrorCodeConstants.*;
|
||||
|
@ -162,7 +163,6 @@ public class GlobalExceptionHandler {
|
|||
public CommonResult globalExceptionHandler(HttpServletRequest req, GlobalException ex) {
|
||||
// 系统异常时,才打印异常日志
|
||||
if (INTERNAL_SERVER_ERROR.getCode().equals(ex.getCode())) {
|
||||
logger.error("[globalExceptionHandler]", ex);
|
||||
// 插入异常日志
|
||||
this.createExceptionLog(req, ex);
|
||||
// 普通全局异常,打印 info 日志即可
|
||||
|
@ -173,6 +173,16 @@ public class GlobalExceptionHandler {
|
|||
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(), "请求参数不正确");
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理系统异常,兜底处理所有的一切
|
||||
*/
|
||||
|
|
3
pom.xml
3
pom.xml
|
@ -16,7 +16,6 @@
|
|||
<modules>
|
||||
<!-- <module>product</module>-->
|
||||
<!-- <module>order</module>-->
|
||||
<module>user</module>
|
||||
<module>common</module>
|
||||
<!-- <module>system</module>-->
|
||||
<!-- <module>ops</module>-->
|
||||
|
@ -24,13 +23,13 @@
|
|||
<!-- <module>promotion</module>-->
|
||||
<!-- <module>search</module>-->
|
||||
<module>mall-dependencies</module>
|
||||
<!-- <module>mall-spring-boot-starter-cache</module>-->
|
||||
<module>user-service-project</module>
|
||||
<module>user-web-app</module>
|
||||
<module>system-service-project</module>
|
||||
<module>pay-service-project</module>
|
||||
<module>management-web-app</module>
|
||||
<module>shop-web-app</module>
|
||||
<module>product-service-project</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
|
|
@ -9,18 +9,16 @@
|
|||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>user</artifactId>
|
||||
<artifactId>product-service-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<!-- <module>user-application</module>-->
|
||||
<!-- <module>user-service-api</module>-->
|
||||
<!-- <module>user-service-impl</module>-->
|
||||
<module>user-rest</module>
|
||||
<module>user-biz</module>
|
||||
<module>product-service-api</module>
|
||||
<module>product-service-app</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- onemall 基础 bom 文件 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>mall-dependencies</artifactId>
|
||||
|
@ -28,6 +26,13 @@
|
|||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 自身项目 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>product-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
|
@ -3,20 +3,28 @@
|
|||
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>
|
||||
<artifactId>product-service-project</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>product-biz-api</artifactId>
|
||||
<artifactId>product-service-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- Mall 相关 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<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>
|
||||
</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,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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package cn.iocoder.mall.productservice.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@MapperScan("cn.iocoder.mall.productservice.dal.mysql.mapper") // 扫描对应的 Mapper 接口
|
||||
@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
// 数据库连接池 Druid
|
||||
|
||||
@Bean
|
||||
public ISqlInjector sqlInjector() {
|
||||
return new DefaultSqlInjector(); // MyBatis Plus 逻辑删除
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PaginationInterceptor paginationInterceptor() {
|
||||
return new PaginationInterceptor(); // MyBatis Plus 分页插件
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package cn.iocoder.mall.productservice.convert.category;
|
||||
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.category.ProductCategoryDO;
|
||||
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.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);
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package cn.iocoder.mall.productservice.dal.mysql.dataobject.category;
|
||||
|
||||
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 lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品分类表
|
||||
*/
|
||||
@TableName("product_category")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
private Integer pid;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 分类描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 分类排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package cn.iocoder.mall.productservice.dal.mysql.mapper.category;
|
||||
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.category.ProductCategoryDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProductCategoryMapper extends BaseMapper<ProductCategoryDO> {
|
||||
|
||||
default Integer selectCountByPid(Integer pid) {
|
||||
return selectCount(new QueryWrapper<ProductCategoryDO>().eq("pid", pid));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
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.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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<ProductCategoryBO> getListByPid(Integer pid) {
|
||||
// List<ProductCategoryDO> categoryList = productCategoryMapper.selectListByPidAndStatusOrderBySort(pid, ProductCategoryConstants.STATUS_ENABLE);
|
||||
// return ProductCategoryConvert.INSTANCE.convertToBO(categoryList);
|
||||
// }
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package cn.iocoder.mall.productservice.service.category.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品分类表 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryBO {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
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,45 @@
|
|||
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 ProductCategoryCreateBO {
|
||||
|
||||
/**
|
||||
* 父分类编号
|
||||
*/
|
||||
@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,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;
|
|
@ -39,118 +39,4 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
|
|||
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,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,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>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
### /user-address/get-default 成功
|
||||
GET {{user-api-base-url}}/user-address/get-default
|
||||
Authorization: Bearer {{user-access-token}}
|
||||
|
||||
###
|
|
@ -63,6 +63,13 @@ public class UserAddressController {
|
|||
return success(userAddressManager.getUserAddress(UserSecurityContextHolder.getUserId(), userAddressId));
|
||||
}
|
||||
|
||||
@GetMapping("/get-default")
|
||||
@ApiOperation("获得默认的用户收件地址")
|
||||
@RequiresPermissions
|
||||
public CommonResult<UserAddressRespVO> getDefaultUserAddress() {
|
||||
return success(userAddressManager.getDefaultUserAddress(UserSecurityContextHolder.getUserId()));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得用户收件地址列表")
|
||||
@RequiresPermissions
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package cn.iocoder.mall.userweb.manager.address;
|
||||
|
||||
import cn.iocoder.common.framework.exception.GlobalException;
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
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.dto.UserAddressRespDTO;
|
||||
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressCreateReqVO;
|
||||
|
@ -48,7 +50,8 @@ public class UserAddressManager {
|
|||
// 校验是否能够操作
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -93,6 +96,19 @@ public class UserAddressManager {
|
|||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验用户收件地址是不是属于该用户
|
||||
*
|
||||
|
|
|
@ -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