product brand
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.mall.product.biz.bo.product;
|
||||
package cn.iocoder.mall.product.biz.bo.brand;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.mall.product.biz.bo.product;
|
||||
|
||||
import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package cn.iocoder.mall.product.biz.convert.product;
|
||||
package cn.iocoder.mall.product.biz.convert.brand;
|
||||
|
||||
import cn.iocoder.mall.product.biz.bo.product.ProductBrandBO;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO;
|
||||
import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO;
|
||||
import cn.iocoder.mall.product.biz.dto.product.ProductBrandAddDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.product.ProductBrandUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandAddDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandUpdateDTO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@@ -15,6 +18,9 @@ public interface ProductBrandConvert {
|
||||
|
||||
ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class);
|
||||
|
||||
@Mapping(source = "records", target = "list")
|
||||
PageResult<ProductBrandBO> convertPage(IPage<ProductBrandDO> bean);
|
||||
|
||||
@Mappings({})
|
||||
List<ProductBrandBO> convert(List<ProductBrandDO> brands);
|
||||
|
||||
@@ -26,5 +32,4 @@ public interface ProductBrandConvert {
|
||||
|
||||
@Mappings({})
|
||||
ProductBrandDO convert(ProductBrandAddDTO brand);
|
||||
|
||||
}
|
||||
@@ -1,11 +1,25 @@
|
||||
package cn.iocoder.mall.product.biz.dao.product;
|
||||
|
||||
import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandPageDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProductBrandMapper extends BaseMapper<ProductBrandDO> {
|
||||
|
||||
|
||||
default IPage<ProductBrandDO> selectListByParams(ProductBrandPageDTO productBrandPageDTO) {
|
||||
Page<ProductBrandDO> page = new Page<>(productBrandPageDTO.getPageNo(), productBrandPageDTO.getPageSize());
|
||||
LambdaQueryWrapper<ProductBrandDO> queryWrapper = Wrappers.<ProductBrandDO>query().lambda()
|
||||
.like(StringUtils.isNotBlank(productBrandPageDTO.getName()), ProductBrandDO::getName, productBrandPageDTO.getName())
|
||||
.like(StringUtils.isNotBlank(productBrandPageDTO.getDescription()), ProductBrandDO::getName, productBrandPageDTO.getDescription())
|
||||
.eq(null != productBrandPageDTO.getStatus(), ProductBrandDO::getName, productBrandPageDTO.getStatus())
|
||||
.eq(ProductBrandDO::getDeleted, false);
|
||||
return selectPage(page, queryWrapper);
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,14 @@ package cn.iocoder.mall.product.biz.dataobject.product;
|
||||
|
||||
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* Product 品牌
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandDO extends DeletableDO {
|
||||
|
||||
@@ -32,7 +34,7 @@ public class ProductBrandDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* <p>
|
||||
* 1-开启
|
||||
* 2-禁用
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@ import lombok.experimental.Accessors;
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AdminProductAttrPageDTO extends PageParam {
|
||||
public class ProductAttrPageDTO extends PageParam {
|
||||
/**
|
||||
* 商品规格名字
|
||||
*/
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.mall.product.biz.dto.product;
|
||||
package cn.iocoder.mall.product.biz.dto.brand;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -1,16 +1,17 @@
|
||||
package cn.iocoder.mall.product.biz.dto.product;
|
||||
package cn.iocoder.mall.product.biz.dto.brand;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 商品品牌分页 DTO
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class ProductBrandPageDTO {
|
||||
public class ProductBrandPageDTO extends PageParam {
|
||||
|
||||
/**
|
||||
* 名称
|
||||
@@ -27,10 +28,4 @@ public class ProductBrandPageDTO {
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
@NotNull(message = "页码不能为空")
|
||||
private Integer pageNo;
|
||||
|
||||
@NotNull(message = "每页条数不能为空")
|
||||
private Integer pageSize;
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.mall.product.biz.dto.product;
|
||||
package cn.iocoder.mall.product.biz.dto.brand;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -20,7 +20,7 @@ public interface ProductAttrService {
|
||||
* @param productAttrPageDTO 查询参数
|
||||
* @return 规格分页信息
|
||||
*/
|
||||
PageResult<ProductAttrWithValueBO> getProductAttrPage(AdminProductAttrPageDTO productAttrPageDTO);
|
||||
PageResult<ProductAttrWithValueBO> getProductAttrPage(ProductAttrPageDTO productAttrPageDTO);
|
||||
|
||||
/**
|
||||
* 获得规格属性数组
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package cn.iocoder.mall.product.biz.service.product;
|
||||
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandAddDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandPageDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandUpdateDTO;
|
||||
|
||||
public interface ProductBrandService {
|
||||
|
||||
/**
|
||||
* 获取品牌分页数据
|
||||
*
|
||||
* @param productBrandPageDTO 翻页参数
|
||||
* @return
|
||||
*/
|
||||
PageResult<ProductBrandBO> getProductBrandPage(ProductBrandPageDTO productBrandPageDTO);
|
||||
|
||||
/**
|
||||
* 获取品牌明细
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
ProductBrandBO getProductBrand(Integer id);
|
||||
|
||||
/**
|
||||
* 添加品牌
|
||||
*
|
||||
* @param productBrandAddDTO 添加参数
|
||||
* @return
|
||||
*/
|
||||
ProductBrandBO addProductBrand(Integer adminId, ProductBrandAddDTO productBrandAddDTO);
|
||||
|
||||
/**
|
||||
* 更新品牌
|
||||
*
|
||||
* @param productBrandUpdateDTO 更新参数
|
||||
* @return
|
||||
*/
|
||||
Boolean updateProductBrand(Integer adminId, ProductBrandUpdateDTO productBrandUpdateDTO);
|
||||
|
||||
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class ProductAttrServiceImpl implements ProductAttrService {
|
||||
private ProductAttrValueMapper productAttrValueMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<ProductAttrWithValueBO> getProductAttrPage(AdminProductAttrPageDTO productAttrPageDTO) {
|
||||
public PageResult<ProductAttrWithValueBO> getProductAttrPage(ProductAttrPageDTO productAttrPageDTO) {
|
||||
//查询分页
|
||||
Page<ProductAttrDO> page = new Page<>(productAttrPageDTO.getPageNo(), productAttrPageDTO.getPageSize());
|
||||
LambdaQueryWrapper<ProductAttrDO> queryWrapper = Wrappers.<ProductAttrDO>query().lambda()
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.iocoder.mall.product.biz.service.product.impl;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
|
||||
import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO;
|
||||
import cn.iocoder.mall.product.biz.convert.brand.ProductBrandConvert;
|
||||
import cn.iocoder.mall.product.biz.dao.product.ProductBrandMapper;
|
||||
import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandAddDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandPageDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum;
|
||||
import cn.iocoder.mall.product.biz.service.product.ProductBrandService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品规格 Service 实现类
|
||||
*
|
||||
* @see ProductBrandDO
|
||||
*/
|
||||
@Service
|
||||
public class ProductBrandServiceImpl implements ProductBrandService {
|
||||
|
||||
@Autowired
|
||||
private ProductBrandMapper productBrandMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<ProductBrandBO> getProductBrandPage(ProductBrandPageDTO productBrandPageDTO) {
|
||||
IPage<ProductBrandDO> brandPage = productBrandMapper.selectListByParams(productBrandPageDTO);
|
||||
return ProductBrandConvert.INSTANCE.convertPage(brandPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductBrandBO getProductBrand(Integer brandId) {
|
||||
return ProductBrandConvert.INSTANCE.convert(productBrandMapper.selectById(brandId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductBrandBO addProductBrand(Integer adminId, ProductBrandAddDTO productBrandAddDTO) {
|
||||
// 校验品牌名不重复
|
||||
int count = productBrandMapper.selectCount(Wrappers.<ProductBrandDO>query().lambda()
|
||||
.eq(ProductBrandDO::getName, productBrandAddDTO.getName())
|
||||
.eq(ProductBrandDO::getDeleted, false));
|
||||
if (count > 0) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_BRAND_EXIST.getCode());
|
||||
}
|
||||
ProductBrandDO productBrandDO = ProductBrandConvert.INSTANCE.convert(productBrandAddDTO);
|
||||
productBrandDO.setCreateTime(new Date());
|
||||
productBrandDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
||||
productBrandMapper.insert(productBrandDO);
|
||||
return ProductBrandConvert.INSTANCE.convert(productBrandDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateProductBrand(Integer adminId, ProductBrandUpdateDTO productBrandUpdateDTO) {
|
||||
ProductBrandDO productBrandDO = ProductBrandConvert.INSTANCE.convert(productBrandUpdateDTO);
|
||||
productBrandDO.setUpdateTime(new Date());
|
||||
productBrandMapper.updateById(productBrandDO);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user