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

This commit is contained in:
YunaiV
2020-07-24 18:55:51 +08:00
parent 4198c154aa
commit b209505f99
43 changed files with 721 additions and 806 deletions

View File

@@ -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>

View File

@@ -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);
}
}

View File

@@ -1,6 +0,0 @@
swagger:
enable: true
title: 商品子系统
description: 商品子系统
version: 1.0.0
base-package: cn.iocoder.mall.product.application.controller

View File

@@ -1,9 +0,0 @@
spring:
# Application 的配置项
application:
name: product-application
# Profile 的配置项
profiles:
active: local

View File

@@ -1,23 +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-biz-api</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>common-framework</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -1,6 +0,0 @@
/**
* 该项目,主要用于暴露一些共享的枚举类等。
*
* 例如说RPC 接口提供错误码给调用方
*/
package cn.iocoder.mall.product.biz;

View File

@@ -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 jiangweifanWrappers 只用在 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;
}
}

View File

@@ -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>

View File

@@ -1 +0,0 @@
package cn.iocoder.mall.demo.mq;

View File

@@ -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()));
}
}
}
}