商品品牌的迁移,准备和前端管理后台对接
This commit is contained in:
@@ -12,10 +12,7 @@ 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, "父分类必须是一级分类");
|
||||
@@ -36,6 +33,7 @@ public interface ProductErrorCodeConstants {
|
||||
ErrorCode PRODUCT_ATTR_VALUE_STATUS_EQUALS = new ErrorCode(1003003005, "商品规格值已经是该状态");
|
||||
|
||||
// ========== PRODUCT BRAND模块 ==========
|
||||
ErrorCode PRODUCT_BRAND_EXIST = new ErrorCode(1003004000,"品牌值已经存在");
|
||||
ErrorCode PRODUCT_BRAND_NAME_EXIST = new ErrorCode(1003004000,"商品品牌的名字已经存在");
|
||||
ErrorCode PRODUCT_BRAND_NOT_FOUND = new ErrorCode(1003004001, "商品品牌不粗糙你在");
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandUpdateReqDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品品牌 Rpc 接口
|
||||
*/
|
||||
public interface ProductBrandRpc {
|
||||
|
||||
/**
|
||||
* 创建商品品牌
|
||||
*
|
||||
* @param createDTO 创建商品品牌 DTO
|
||||
* @return 商品品牌编号
|
||||
*/
|
||||
CommonResult<Integer> createProductBrand(ProductBrandCreateReqDTO createDTO);
|
||||
|
||||
/**
|
||||
* 更新商品品牌
|
||||
*
|
||||
* @param updateDTO 更新商品品牌 DTO
|
||||
*/
|
||||
CommonResult<Boolean> updateProductBrand(ProductBrandUpdateReqDTO updateDTO);
|
||||
|
||||
/**
|
||||
* 删除商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
*/
|
||||
CommonResult<Boolean> deleteProductBrand(Integer productBrandId);
|
||||
|
||||
/**
|
||||
* 获得商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
* @return 商品品牌
|
||||
*/
|
||||
CommonResult<ProductBrandRespDTO> getProductBrand(Integer productBrandId);
|
||||
|
||||
/**
|
||||
* 获得商品品牌列表
|
||||
*
|
||||
* @param productBrandIds 商品品牌编号列表
|
||||
* @return 商品品牌列表
|
||||
*/
|
||||
CommonResult<List<ProductBrandRespDTO>> listProductBrands(List<Integer> productBrandIds);
|
||||
|
||||
/**
|
||||
* 获得商品品牌分页
|
||||
*
|
||||
* @param pageDTO 商品品牌分页查询
|
||||
* @return 商品品牌分页结果
|
||||
*/
|
||||
CommonResult<PageResult<ProductBrandRespDTO>> pageProductBrand(ProductBrandPageReqDTO pageDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand.dto;
|
||||
|
||||
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 ProductBrandCreateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
@NotEmpty(message = "品牌名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand.dto;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品品牌分页 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandPageReqDTO extends PageParam {
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品品牌 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 品牌编号(主键)
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand.dto;
|
||||
|
||||
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 ProductBrandUpdateReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 品牌编号
|
||||
*/
|
||||
@NotNull(message = "品牌编号不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
@NotEmpty(message = "品牌名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package cn.iocoder.mall.productservice.convert.brand;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.brand.ProductBrandDO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandPageBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandUpdateBO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductBrandConvert {
|
||||
|
||||
ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class);
|
||||
|
||||
ProductBrandDO convert(ProductBrandCreateBO bean);
|
||||
|
||||
ProductBrandBO convert(ProductBrandDO bean);
|
||||
|
||||
ProductBrandDO convert(ProductBrandUpdateBO bean);
|
||||
|
||||
List<ProductBrandBO> convertList(List<ProductBrandDO> list);
|
||||
|
||||
PageResult<ProductBrandBO> convertPage(IPage<ProductBrandDO> page);
|
||||
|
||||
ProductBrandCreateBO convert(ProductBrandCreateReqDTO bean);
|
||||
|
||||
ProductBrandUpdateBO convert(ProductBrandUpdateReqDTO bean);
|
||||
|
||||
ProductBrandRespDTO convert(ProductBrandBO bean);
|
||||
|
||||
List<ProductBrandRespDTO> convertList02(List<ProductBrandBO> list);
|
||||
|
||||
ProductBrandPageBO convert(ProductBrandPageReqDTO bean);
|
||||
|
||||
PageResult<ProductBrandRespDTO> convertPage(PageResult<ProductBrandBO> page);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.dataobject.brand;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品品牌
|
||||
*/
|
||||
@TableName("product_brand")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 品牌编号(主键)
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
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 cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
@@ -15,7 +15,7 @@ import lombok.experimental.Accessors;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductCategoryDO extends BaseDO {
|
||||
public class ProductCategoryDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 分类编号
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.productservice.dal.mysql.mapper.brand;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.brand.ProductBrandDO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandPageBO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProductBrandMapper extends BaseMapper<ProductBrandDO> {
|
||||
|
||||
default IPage<ProductBrandDO> selectPage(ProductBrandPageBO pageBO) {
|
||||
return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
|
||||
new QueryWrapperX<ProductBrandDO>().likeIfPresent("name", pageBO.getName())
|
||||
.eqIfPresent("status", pageBO.getStatus()));
|
||||
}
|
||||
|
||||
default ProductBrandDO selectByName(String name) {
|
||||
return selectOne(new QueryWrapper<ProductBrandDO>().eq("name", name));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package cn.iocoder.mall.productservice.manager.brand;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.brand.ProductBrandConvert;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.service.brand.ProductBrandService;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品品牌 Manager
|
||||
*/
|
||||
@Service
|
||||
public class ProductBrandManager {
|
||||
|
||||
@Autowired
|
||||
private ProductBrandService productBrandService;
|
||||
|
||||
/**
|
||||
* 创建商品品牌
|
||||
*
|
||||
* @param createDTO 创建商品品牌 DTO
|
||||
* @return 商品品牌
|
||||
*/
|
||||
public Integer createProductBrand(ProductBrandCreateReqDTO createDTO) {
|
||||
ProductBrandBO productBrandBO = productBrandService.createProductBrand(ProductBrandConvert.INSTANCE.convert(createDTO));
|
||||
return productBrandBO.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品品牌
|
||||
*
|
||||
* @param updateDTO 更新商品品牌 DTO
|
||||
*/
|
||||
public void updateProductBrand(ProductBrandUpdateReqDTO updateDTO) {
|
||||
productBrandService.updateProductBrand(ProductBrandConvert.INSTANCE.convert(updateDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
*/
|
||||
public void deleteProductBrand(Integer productBrandId) {
|
||||
productBrandService.deleteProductBrand(productBrandId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
* @return 商品品牌
|
||||
*/
|
||||
public ProductBrandRespDTO getProductBrand(Integer productBrandId) {
|
||||
ProductBrandBO productBrandBO = productBrandService.getProductBrand(productBrandId);
|
||||
return ProductBrandConvert.INSTANCE.convert(productBrandBO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌列表
|
||||
*
|
||||
* @param productBrandIds 商品品牌编号列表
|
||||
* @return 商品品牌列表
|
||||
*/
|
||||
public List<ProductBrandRespDTO> listProductBrands(List<Integer> productBrandIds) {
|
||||
List<ProductBrandBO> productBrandBOs = productBrandService.listProductBrands(productBrandIds);
|
||||
return ProductBrandConvert.INSTANCE.convertList02(productBrandBOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌分页
|
||||
*
|
||||
* @param pageDTO 商品品牌分页查询
|
||||
* @return 商品品牌分页结果
|
||||
*/
|
||||
public PageResult<ProductBrandRespDTO> pageProductBrand(ProductBrandPageReqDTO pageDTO) {
|
||||
PageResult<ProductBrandBO> pageResultBO = productBrandService.pageProductBrand(ProductBrandConvert.INSTANCE.convert(pageDTO));
|
||||
return ProductBrandConvert.INSTANCE.convertPage(pageResultBO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package cn.iocoder.mall.productservice.rpc.brand;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.manager.brand.ProductBrandManager;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.brand.dto.ProductBrandUpdateReqDTO;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 商品品牌 Rpc 实现类
|
||||
*/
|
||||
@Service(version = "${dubbo.provider.ProductBrandRpc.version}")
|
||||
public class ProductBrandRpcImpl implements ProductBrandRpc {
|
||||
|
||||
@Autowired
|
||||
private ProductBrandManager productBrandManager;
|
||||
|
||||
@Override
|
||||
public CommonResult<Integer> createProductBrand(ProductBrandCreateReqDTO createDTO) {
|
||||
return success(productBrandManager.createProductBrand(createDTO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateProductBrand(ProductBrandUpdateReqDTO updateDTO) {
|
||||
productBrandManager.updateProductBrand(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> deleteProductBrand(Integer productBrandId) {
|
||||
productBrandManager.deleteProductBrand(productBrandId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<ProductBrandRespDTO> getProductBrand(Integer productBrandId) {
|
||||
return success(productBrandManager.getProductBrand(productBrandId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<ProductBrandRespDTO>> listProductBrands(List<Integer> productBrandIds) {
|
||||
return success(productBrandManager.listProductBrands(productBrandIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<PageResult<ProductBrandRespDTO>> pageProductBrand(ProductBrandPageReqDTO pageDTO) {
|
||||
return success(productBrandManager.pageProductBrand(pageDTO));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package cn.iocoder.mall.productservice.service.brand;
|
||||
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.brand.ProductBrandConvert;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.brand.ProductBrandDO;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.mapper.brand.ProductBrandMapper;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandPageBO;
|
||||
import cn.iocoder.mall.productservice.service.brand.bo.ProductBrandUpdateBO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
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.PRODUCT_BRAND_NAME_EXIST;
|
||||
import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.PRODUCT_BRAND_NOT_FOUND;
|
||||
|
||||
/**
|
||||
* 商品品牌 Service
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductBrandService {
|
||||
|
||||
@Autowired
|
||||
private ProductBrandMapper productBrandMapper;
|
||||
|
||||
/**
|
||||
* 创建商品品牌
|
||||
*
|
||||
* @param createBO 创建商品品牌 BO
|
||||
* @return 商品品牌
|
||||
*/
|
||||
public ProductBrandBO createProductBrand(@Valid ProductBrandCreateBO createBO) {
|
||||
// 校验商品品牌的名字是否已经使用
|
||||
if (productBrandMapper.selectByName(createBO.getName()) != null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_BRAND_NAME_EXIST);
|
||||
}
|
||||
// 插入到数据库
|
||||
ProductBrandDO productBrandDO = ProductBrandConvert.INSTANCE.convert(createBO);
|
||||
productBrandMapper.insert(productBrandDO);
|
||||
// 返回
|
||||
return ProductBrandConvert.INSTANCE.convert(productBrandDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品品牌
|
||||
*
|
||||
* @param updateBO 更新商品品牌 BO
|
||||
*/
|
||||
public void updateProductBrand(@Valid ProductBrandUpdateBO updateBO) {
|
||||
// 校验更新的商品品牌是否存在
|
||||
if (productBrandMapper.selectById(updateBO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_BRAND_NOT_FOUND);
|
||||
}
|
||||
// 校验商品品牌的名字是否已经使用
|
||||
ProductBrandDO productBrandDOByName = productBrandMapper.selectByName(updateBO.getName());
|
||||
if (productBrandDOByName != null && !updateBO.getId().equals(productBrandDOByName.getId())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_BRAND_NAME_EXIST);
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductBrandDO updateObject = ProductBrandConvert.INSTANCE.convert(updateBO);
|
||||
productBrandMapper.updateById(updateObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
*/
|
||||
public void deleteProductBrand(Integer productBrandId) {
|
||||
// 校验删除的商品品牌是否存在
|
||||
if (productBrandMapper.selectById(productBrandId) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_BRAND_NOT_FOUND);
|
||||
}
|
||||
// TODO 功能点:需要品牌下没有分类
|
||||
// 标记删除
|
||||
productBrandMapper.deleteById(productBrandId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌
|
||||
*
|
||||
* @param productBrandId 商品品牌编号
|
||||
* @return 商品品牌
|
||||
*/
|
||||
public ProductBrandBO getProductBrand(Integer productBrandId) {
|
||||
ProductBrandDO productBrandDO = productBrandMapper.selectById(productBrandId);
|
||||
return ProductBrandConvert.INSTANCE.convert(productBrandDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌列表
|
||||
*
|
||||
* @param productBrandIds 商品品牌编号列表
|
||||
* @return 商品品牌列表
|
||||
*/
|
||||
public List<ProductBrandBO> listProductBrands(List<Integer> productBrandIds) {
|
||||
List<ProductBrandDO> productBrandDOs = productBrandMapper.selectBatchIds(productBrandIds);
|
||||
return ProductBrandConvert.INSTANCE.convertList(productBrandDOs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品品牌分页
|
||||
*
|
||||
* @param pageBO 商品品牌分页查询
|
||||
* @return 商品品牌分页结果
|
||||
*/
|
||||
public PageResult<ProductBrandBO> pageProductBrand(ProductBrandPageBO pageBO) {
|
||||
IPage<ProductBrandDO> productBrandDOPage = productBrandMapper.selectPage(pageBO);
|
||||
return ProductBrandConvert.INSTANCE.convertPage(productBrandDOPage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package cn.iocoder.mall.productservice.service.brand.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品品牌 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandBO {
|
||||
|
||||
/**
|
||||
* 品牌编号(主键)
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.iocoder.mall.productservice.service.brand.bo;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 商品品牌创建 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandCreateBO {
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
@NotEmpty(message = "品牌名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.iocoder.mall.productservice.service.brand.bo;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品品牌分页 BO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandPageBO extends PageParam {
|
||||
|
||||
/**
|
||||
* 品牌名称
|
||||
*
|
||||
* 模糊匹配
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package cn.iocoder.mall.productservice.service.brand.bo;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 商品品牌更新 BO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandUpdateBO {
|
||||
|
||||
/**
|
||||
* 品牌编号(主键)
|
||||
*/
|
||||
@NotNull(message = "品牌编号(主键)不能为空")
|
||||
private Integer id;
|
||||
/**
|
||||
* 品牌名称
|
||||
*/
|
||||
@NotEmpty(message = "品牌名称不能为空")
|
||||
private String name;
|
||||
/**
|
||||
* 品牌描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 品牌名图片
|
||||
*/
|
||||
private String picUrl;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.iocoder.mall.productservice.service.category.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -40,6 +42,7 @@ public class ProductCategoryCreateBO {
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.iocoder.mall.productservice.service.category.bo;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -45,6 +47,7 @@ public class ProductCategoryUpdateBO {
|
||||
* 状态
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ dubbo:
|
||||
validation: true # 开启 Provider 参数校验
|
||||
ProductCategoryRpc:
|
||||
version: 1.0.0
|
||||
ProductBrandRpc:
|
||||
verion: 1.0.0
|
||||
# Dubbo 服务消费者的配置
|
||||
consumer:
|
||||
ErrorCodeRpc:
|
||||
|
||||
Reference in New Issue
Block a user