商品规格接口

This commit is contained in:
q2118cs 2020-05-11 15:41:54 +08:00
parent a00c4eb054
commit a4ca27d68c
36 changed files with 622 additions and 375 deletions

View File

@ -12,6 +12,7 @@
<artifactId>product</artifactId>
<name>product</name>
<packaging>pom</packaging>
<modules>
<module>product-application</module>
<module>product-rpc-api</module>

View File

@ -3,7 +3,7 @@
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>system</artifactId>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -3,7 +3,7 @@
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>system</artifactId>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -3,12 +3,12 @@ package cn.iocoder.mall.product.biz.bo.attr;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
@Accessors(chain = true)
public class ProductAttrBO {
public class ProductAttrBO implements Serializable {
/**
* 规格编号
@ -26,8 +26,5 @@ public class ProductAttrBO {
* 创建时间
*/
private Date createTime;
/**
* 规格值数组
*/
private List<ProductAttrValueBO> values;
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.mall.product.biz.bo.attr;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 商品规格精简 VO
*/
@Data
@Accessors(chain = true)
public class ProductAttrSimpleBO implements Serializable {
/**
* 规格编号
*/
private Integer id;
/**
* 规格名
*/
private String name;
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.mall.product.biz.bo.attr;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class ProductAttrSimpleWithValueBO extends ProductAttrSimpleBO {
/**
* 规格值数组
*/
private List<ProductAttrValueSimpleBO> values;
}

View File

@ -17,6 +17,10 @@ public class ProductAttrValueBO implements Serializable {
* 规格值编号
*/
private Integer id;
/**
* 规格编号
*/
private Integer attrId;
/**
* 规格值名
*/

View File

@ -0,0 +1,24 @@
package cn.iocoder.mall.product.biz.bo.attr;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 商品规格值 VO
*/
@Data
@Accessors(chain = true)
public class ProductAttrValueSimpleBO implements Serializable {
/**
* 规格值编号
*/
private Integer id;
/**
* 规格值名
*/
private String name;
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.mall.product.biz.bo.attr;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class ProductAttrWithValueBO extends ProductAttrBO {
/**
* 规格值数组
*/
private List<ProductAttrValueBO> values;
}

View File

@ -1,10 +1,12 @@
package cn.iocoder.mall.product.biz.convert.attr;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.bo.attr.*;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrDO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrValueDO;
import cn.iocoder.mall.product.biz.dto.attr.ProductAttrUpdateDTO;
import cn.iocoder.mall.product.biz.dto.attr.ProductAttrValueAddDTO;
import cn.iocoder.mall.product.biz.dto.attr.ProductAttrValueUpdateDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@ -19,8 +21,29 @@ public interface ProductAttrConvert {
ProductAttrConvert INSTANCE = Mappers.getMapper(ProductAttrConvert.class);
@Mapping(source = "records", target = "list")
PageResult<ProductAttrBO> convertPage(IPage<ProductAttrDO> bean);
PageResult<ProductAttrWithValueBO> convertPage(IPage<ProductAttrDO> bean);
@Mappings({})
List<ProductAttrValueBO> convertAttrValue(List<ProductAttrValueDO> values);
ProductAttrBO convertAttr(ProductAttrDO values);
@Mappings({})
ProductAttrValueBO convertAttrValue(ProductAttrValueDO productAttrValueDO);
@Mappings({})
List<ProductAttrValueBO> convertAttrValues(List<ProductAttrValueDO> values);
@Mappings({})
List<ProductAttrSimpleWithValueBO> convertAttrSimple(List<ProductAttrDO> attrs);
@Mappings({})
List<ProductAttrValueSimpleBO> convertAttrValueSimple(List<ProductAttrValueDO> values);
@Mappings({})
ProductAttrDO convertUpdate(ProductAttrUpdateDTO productAttrUpdateDTO);
@Mappings({})
ProductAttrValueDO convertValueAdd(ProductAttrValueAddDTO productAttrValueAddDTO);
@Mappings({})
ProductAttrValueDO convertValueUpdate(ProductAttrValueUpdateDTO productAttrValueUpdateDTO);
}

View File

@ -1,58 +0,0 @@
package cn.iocoder.mall.product.biz.convert.product;
import cn.iocoder.mall.product.biz.bo.product.*;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrDO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrValueDO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrUpdateDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueUpdateDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface ProductAttrConvert2 {
ProductAttrConvert2 INSTANCE = Mappers.getMapper(ProductAttrConvert2.class);
@Mappings({})
List<ProductAttrDetailBO> convert(List<ProductAttrDO> attrs);
@Mappings({})
ProductAttrValueDetailBO convert(ProductAttrValueDO value);
@Mappings({})
List<ProductAttrValueDetailBO> convert2(List<ProductAttrValueDO> values);
@Mappings({})
List<ProductAttrSimpleBO> convert3(List<ProductAttrDO> attrs);
@Mappings({})
ProductAttrValueSimpleBO convert3(ProductAttrValueDO value); // 保证 convert4 能够映射到这个方法
@Mappings({})
List<ProductAttrValueSimpleBO> convert4(List<ProductAttrValueDO> values);
@Mappings({})
ProductAttrDO convert(ProductAttrAddDTO productAttrAddDTO);
@Mappings({})
ProductAttrDO convert(ProductAttrUpdateDTO productAttrUpdateDTO);
@Mappings({})
ProductAttrValueDO convert(ProductAttrValueAddDTO productAttrValueAddDTO);
@Mappings({})
ProductAttrValueDO convert(ProductAttrValueUpdateDTO productAttrValueUpdateDTO);
@Mappings({})
ProductAttrBO2 convert(ProductAttrDO productAttrDO);
@Mappings({})
ProductAttrValueBO convert2(ProductAttrValueDO productAttrValueDO);
}

View File

@ -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 ProductAttrValueDO extends DeletableDO {
@ -25,7 +27,7 @@ public class ProductAttrValueDO extends DeletableDO {
private String name;
/**
* 状态
*
* <p>
* 1-正常
* 2-禁用
*/

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.attr;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.attr;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.attr;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.product.biz.dto.product;
package cn.iocoder.mall.product.biz.dto.attr;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,22 +0,0 @@
package cn.iocoder.mall.product.biz.dto.product;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
/**
* 商品规格分页 DTO
*/
@Data
@Accessors(chain = true)
public class ProductAttrPageDTO {
private String name;
@NotNull(message = "页码不能为空")
private Integer pageNo;
@NotNull(message = "每页条数不能为空")
private Integer pageSize;
}

View File

@ -4,14 +4,10 @@ import cn.iocoder.common.framework.constant.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrBO2;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrSimpleBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.dto.attr.AdminProductAttrPageDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrUpdateDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueUpdateDTO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrSimpleWithValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrWithValueBO;
import cn.iocoder.mall.product.biz.dto.attr.*;
import java.util.List;
@ -22,7 +18,7 @@ public interface ProductAttrService {
* @param productAttrPageDTO 查询参数
* @return 规格分页信息
*/
PageResult<ProductAttrBO> getProductAttrPage(AdminProductAttrPageDTO productAttrPageDTO);
PageResult<ProductAttrWithValueBO> getProductAttrPage(AdminProductAttrPageDTO productAttrPageDTO);
/**
* 获得规格属性数组
@ -31,14 +27,35 @@ public interface ProductAttrService {
*
* @return 规格属性数组
*/
List<ProductAttrSimpleBO> getProductAttrList();
List<ProductAttrSimpleWithValueBO> getProductAttrList();
ProductAttrBO2 addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO);
/**
* 添加商品规格
*
* @param adminId 操作人ID
* @param productAttrAddDTO 添加参数
* @return 添加的规格
*/
ProductAttrBO addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO);
/**
* 更新规格
*
* @param adminId 操作人
* @param productAttrUpdateDTO 更新规格
* @return 成功标识
*/
Boolean updateProductAttr(Integer adminId, ProductAttrUpdateDTO productAttrUpdateDTO);
Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId,
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
/**
* 更新规格状态
*
* @param adminId 操作人
* @param productAttrId 规格ID
* @param status 状态
* @return 成功标识
*/
Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId, Integer status);
ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO);

View File

@ -5,21 +5,16 @@ 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.attr.ProductAttrBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrSimpleWithValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrWithValueBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrAndValuePairBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrBO2;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrSimpleBO;
import cn.iocoder.mall.product.biz.bo.product.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.convert.attr.ProductAttrConvert;
import cn.iocoder.mall.product.biz.convert.product.ProductAttrConvert2;
import cn.iocoder.mall.product.biz.dao.product.ProductAttrMapper;
import cn.iocoder.mall.product.biz.dao.product.ProductAttrValueMapper;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrDO;
import cn.iocoder.mall.product.biz.dataobject.product.ProductAttrValueDO;
import cn.iocoder.mall.product.biz.dto.attr.AdminProductAttrPageDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrUpdateDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueAddDTO;
import cn.iocoder.mall.product.biz.dto.product.ProductAttrValueUpdateDTO;
import cn.iocoder.mall.product.biz.dto.attr.*;
import cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum;
import cn.iocoder.mall.product.biz.enums.product.ProductAttrConstants;
import cn.iocoder.mall.product.biz.service.product.ProductAttrService;
@ -27,8 +22,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Multimaps;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -51,14 +44,14 @@ public class ProductAttrServiceImpl implements ProductAttrService {
private ProductAttrValueMapper productAttrValueMapper;
@Override
public PageResult<ProductAttrBO> getProductAttrPage(AdminProductAttrPageDTO productAttrPageDTO) {
public PageResult<ProductAttrWithValueBO> getProductAttrPage(AdminProductAttrPageDTO productAttrPageDTO) {
//查询分页
Page<ProductAttrDO> page = new Page<>(productAttrPageDTO.getPageNo(), productAttrPageDTO.getPageSize());
LambdaQueryWrapper<ProductAttrDO> queryWrapper = Wrappers.<ProductAttrDO>query().lambda()
.like(StringUtils.isNotBlank(productAttrPageDTO.getName()), ProductAttrDO::getName, productAttrPageDTO.getName())
.eq(ProductAttrDO::getDeleted, false);
IPage<ProductAttrDO> attrPage = productAttrMapper.selectPage(page, queryWrapper);
PageResult<ProductAttrBO> productAttrPage = ProductAttrConvert.INSTANCE.convertPage(attrPage);
PageResult<ProductAttrWithValueBO> productAttrPage = ProductAttrConvert.INSTANCE.convertPage(attrPage);
// 将规格值拼接上去
if (!CollectionUtil.isEmpty(productAttrPage.getList())) {
Set<Integer> attrIds = productAttrPage.getList().stream().map(ProductAttrBO::getId).collect(Collectors.toSet());
@ -66,14 +59,151 @@ public class ProductAttrServiceImpl implements ProductAttrService {
.in(ProductAttrValueDO::getAttrId, attrIds)
.eq(ProductAttrValueDO::getDeleted, false));
Map<Integer, List<ProductAttrValueDO>> attrValueMap = attrValues.stream().collect(Collectors.groupingBy(ProductAttrValueDO::getAttrId));
for (ProductAttrBO productAttrBO : productAttrPage.getList()) {
productAttrBO.setValues(ProductAttrConvert.INSTANCE.convertAttrValue(attrValueMap.get(productAttrBO.getId())));
for (ProductAttrWithValueBO item : productAttrPage.getList()) {
item.setValues(ProductAttrConvert.INSTANCE.convertAttrValues(attrValueMap.get(item.getId())));
}
}
// 返回结果
return productAttrPage;
}
@Override
public List<ProductAttrSimpleWithValueBO> getProductAttrList() {
// 查询所有开启的规格数组
List<ProductAttrDO> attrDos = productAttrMapper.selectList(Wrappers.<ProductAttrDO>query().lambda()
.in(ProductAttrDO::getStatus, ProductAttrConstants.ATTR_STATUS_ENABLE)
.eq(ProductAttrDO::getDeleted, false));
// 如果为空则返回空
if (attrDos.isEmpty()) {
return Collections.emptyList();
}
List<ProductAttrSimpleWithValueBO> attrs = ProductAttrConvert.INSTANCE.convertAttrSimple(attrDos);
// 将规格值拼接上去
List<ProductAttrValueDO> attrValues = productAttrValueMapper.selectList(Wrappers.<ProductAttrValueDO>query().lambda()
.in(ProductAttrValueDO::getStatus, ProductAttrConstants.ATTR_STATUS_ENABLE)
.eq(ProductAttrValueDO::getDeleted, false));
Map<Integer, List<ProductAttrValueDO>> attrValueMap = attrValues.stream().collect(Collectors.groupingBy(ProductAttrValueDO::getAttrId));
for (ProductAttrSimpleWithValueBO item : attrs) {
item.setValues(ProductAttrConvert.INSTANCE.convertAttrValueSimple(attrValueMap.get(item.getId())));
}
return attrs;
}
@Override
public ProductAttrBO addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO) {
// 校验规格名不重复
int count = productAttrMapper.selectCount(Wrappers.<ProductAttrDO>query().lambda()
.eq(ProductAttrDO::getName, productAttrAddDTO.getName())
.eq(ProductAttrDO::getDeleted, false));
if (count > 0) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
}
// 插入到数据库
ProductAttrDO productAttrDO = new ProductAttrDO().setName(productAttrAddDTO.getName())
.setStatus(ProductAttrConstants.ATTR_STATUS_ENABLE);
productAttrDO.setCreateTime(new Date());
productAttrDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
productAttrMapper.insert(productAttrDO);
// 返回成功
return ProductAttrConvert.INSTANCE.convertAttr(productAttrDO);
}
@Override
public Boolean updateProductAttr(Integer adminId, ProductAttrUpdateDTO productAttrUpdateDTO) {
// 校验存在
if (productAttrMapper.selectById(productAttrUpdateDTO.getId()) == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode());
}
// 校验规格名不重复
ProductAttrDO existsAttrDO = productAttrMapper.selectOne(Wrappers.<ProductAttrDO>query().lambda()
.eq(ProductAttrDO::getName, productAttrUpdateDTO.getName())
.eq(ProductAttrDO::getDeleted, false));
if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrUpdateDTO.getId())) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
}
// 更新到数据库
ProductAttrDO updateProductAttr = ProductAttrConvert.INSTANCE.convertUpdate(productAttrUpdateDTO);
updateProductAttr.setUpdateTime(new Date());
int i = productAttrMapper.updateById(updateProductAttr);
// 返回成功
return i > 0;
}
@Override
public Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId, Integer status) {
// 校验存在
ProductAttrDO productAttrDO = productAttrMapper.selectById(productAttrId);
if (productAttrDO == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode());
}
// 校验状态
if (productAttrDO.getStatus().equals(status)) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_STATUS_EQUALS.getCode());
}
// 更新到数据库
ProductAttrDO updateProductAttr = new ProductAttrDO().setId(productAttrId).setStatus(status);
int i = productAttrMapper.updateById(updateProductAttr);
return i > 0;
}
@Override
public ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO) {
// 校验规格名不重复
int count = productAttrValueMapper.selectCount(Wrappers.<ProductAttrValueDO>query().lambda()
.eq(ProductAttrValueDO::getName, productAttrValueAddDTO.getName())
.eq(ProductAttrValueDO::getAttrId, productAttrValueAddDTO.getAttrId())
.eq(ProductAttrValueDO::getDeleted, false));
if (count > 0) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_EXISTS.getCode());
}
// 插入到数据库
ProductAttrValueDO productAttrValueDO = ProductAttrConvert.INSTANCE.convertValueAdd(productAttrValueAddDTO)
.setStatus(ProductAttrConstants.ATTR_VALUE_STATUS_ENABLE);
productAttrValueDO.setCreateTime(new Date());
productAttrValueDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
productAttrValueMapper.insert(productAttrValueDO);
return ProductAttrConvert.INSTANCE.convertAttrValue(productAttrValueDO);
}
@Override
public Boolean updateProductAttrValue(Integer adminId, ProductAttrValueUpdateDTO productAttrValueUpdateDTO) {
// 校验存在
ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueUpdateDTO.getId());
if (productAttrValueDO == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode());
}
// 校验规格名不重复
ProductAttrValueDO existsAttrDO = productAttrValueMapper.selectOne(Wrappers.<ProductAttrValueDO>query().lambda()
.eq(ProductAttrValueDO::getName, productAttrValueDO.getName())
.eq(ProductAttrValueDO::getAttrId, productAttrValueDO.getAttrId())
.eq(ProductAttrValueDO::getDeleted, false));
if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrValueUpdateDTO.getId())) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_EXISTS.getCode());
}
// 更新到数据库
ProductAttrValueDO updateProductValue = ProductAttrConvert.INSTANCE.convertValueUpdate(productAttrValueUpdateDTO);
updateProductValue.setUpdateTime(new Date());
int i = productAttrValueMapper.updateById(updateProductValue);
return i > 0;
}
@Override
public Boolean updateProductAttrValueStatus(Integer adminId, Integer productAttrValueId, Integer status) {
// 校验存在
ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueId);
if (productAttrValueDO == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode());
}
// 校验状态
if (productAttrValueDO.getStatus().equals(status)) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_STATUS_EQUALS.getCode());
}
// 更新到数据库
ProductAttrValueDO updateProductAttrValue = new ProductAttrValueDO().setId(productAttrValueId).setStatus(status);
int i = productAttrValueMapper.updateById(updateProductAttrValue);
return i > 0;
}
public List<ProductAttrAndValuePairBO> validProductAttrAndValue(Set<Integer> productAttrValueIds, boolean validStatus) {
// 首先校验规格值
List<ProductAttrValueDO> attrValues = productAttrValueMapper.selectBatchIds(productAttrValueIds);
@ -110,146 +240,4 @@ public class ProductAttrServiceImpl implements ProductAttrService {
.setAttrValueId(productAttrValueDO.getId()).setAttrValueName(productAttrValueDO.getName())).collect(Collectors.toList());
}
@Override
public List<ProductAttrSimpleBO> getProductAttrList() {
// 查询所有开启的规格数组
List<ProductAttrDO> attrDos = productAttrMapper.selectList(Wrappers.<ProductAttrDO>query().lambda()
.in(ProductAttrDO::getStatus, ProductAttrConstants.ATTR_STATUS_ENABLE)
.eq(ProductAttrDO::getDeleted, false));
List<ProductAttrSimpleBO> attrs = ProductAttrConvert2.INSTANCE.convert3(attrDos);
// 如果为空则返回空
if (attrs.isEmpty()) {
return Collections.emptyList();
}
// 将规格值拼接上去
List<ProductAttrValueDO> attrValues = productAttrValueMapper.selectList(Wrappers.<ProductAttrValueDO>query().lambda()
.in(ProductAttrValueDO::getStatus, ProductAttrConstants.ATTR_STATUS_ENABLE)
.eq(ProductAttrValueDO::getDeleted, false));
// KEY attrId VALUE ProductAttrValueDO 数组
ImmutableListMultimap<Integer, ProductAttrValueDO> attrValueMap = Multimaps.index(attrValues, ProductAttrValueDO::getAttrId);
for (ProductAttrSimpleBO productAttrSimpleBO : attrs) {
productAttrSimpleBO.setValues(ProductAttrConvert2.INSTANCE.convert4(((attrValueMap).get(productAttrSimpleBO.getId()))));
}
return attrs;
}
@Override
public ProductAttrBO2 addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO) {
// 校验规格名不重复
int count = productAttrMapper.selectCount(Wrappers.<ProductAttrDO>query().lambda()
.eq(ProductAttrDO::getName, productAttrAddDTO.getName())
.eq(ProductAttrDO::getDeleted, false));
if (count > 0) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
}
// 插入到数据库
ProductAttrDO productAttrDO = ProductAttrConvert2.INSTANCE.convert(productAttrAddDTO)
.setStatus(ProductAttrConstants.ATTR_STATUS_ENABLE);
productAttrDO.setCreateTime(new Date());
productAttrDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
productAttrMapper.insert(productAttrDO);
// 返回成功
return ProductAttrConvert2.INSTANCE.convert(productAttrDO);
}
@Override
public Boolean updateProductAttr(Integer adminId, ProductAttrUpdateDTO productAttrUpdateDTO) {
// 校验存在
if (productAttrMapper.selectById(productAttrUpdateDTO.getId()) == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode());
}
// 校验规格名不重复
ProductAttrDO existsAttrDO = productAttrMapper.selectOne(Wrappers.<ProductAttrDO>query().lambda()
.eq(ProductAttrDO::getName, productAttrUpdateDTO.getName())
.eq(ProductAttrDO::getDeleted, false));
if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrUpdateDTO.getId())) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
}
// 更新到数据库
ProductAttrDO updateProductAttr = ProductAttrConvert2.INSTANCE.convert(productAttrUpdateDTO);
productAttrMapper.updateById(updateProductAttr);
// 返回成功
return true;
}
@Override
public Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId, Integer status) {
// 校验存在
ProductAttrDO productAttrDO = productAttrMapper.selectById(productAttrId);
if (productAttrDO == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode());
}
// 校验状态
if (productAttrDO.getStatus().equals(status)) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_STATUS_EQUALS.getCode());
}
// 更新到数据库
ProductAttrDO updateProductAttr = new ProductAttrDO().setId(productAttrId).setStatus(status);
productAttrMapper.updateById(updateProductAttr);
// 返回成功
return true;
}
@Override
public ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO) {
// 校验规格名不重复
int count = productAttrValueMapper.selectCount(Wrappers.<ProductAttrValueDO>query().lambda()
.eq(ProductAttrValueDO::getName, productAttrValueAddDTO.getName())
.eq(ProductAttrValueDO::getAttrId, productAttrValueAddDTO.getAttrId())
.eq(ProductAttrValueDO::getDeleted, false));
if (count > 0) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_EXISTS.getCode());
}
// 插入到数据库
ProductAttrValueDO productAttrValueDO = ProductAttrConvert2.INSTANCE.convert(productAttrValueAddDTO)
.setStatus(ProductAttrConstants.ATTR_VALUE_STATUS_ENABLE);
productAttrValueDO.setCreateTime(new Date());
productAttrValueDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
productAttrValueMapper.insert(productAttrValueDO);
// 返回成功
return ProductAttrConvert2.INSTANCE.convert2(productAttrValueDO);
}
@Override
public Boolean updateProductAttrValue(Integer adminId, ProductAttrValueUpdateDTO productAttrValueUpdateDTO) {
// 校验存在
ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueUpdateDTO.getId());
if (productAttrValueDO == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode());
}
// 校验规格名不重复
ProductAttrValueDO existsAttrDO = productAttrValueMapper.selectOne(Wrappers.<ProductAttrValueDO>query().lambda()
.eq(ProductAttrValueDO::getName, productAttrValueDO.getName())
.eq(ProductAttrValueDO::getAttrId, productAttrValueDO.getAttrId())
.eq(ProductAttrValueDO::getDeleted, false));
if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrValueUpdateDTO.getId())) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_EXISTS.getCode());
}
// 更新到数据库
ProductAttrValueDO updateProductValue = ProductAttrConvert2.INSTANCE.convert(productAttrValueUpdateDTO);
productAttrValueMapper.updateById(updateProductValue);
// 返回成功
return true;
}
@Override
public Boolean updateProductAttrValueStatus(Integer adminId, Integer productAttrValueId, Integer status) {
// 校验存在
ProductAttrValueDO productAttrValueDO = productAttrValueMapper.selectById(productAttrValueId);
if (productAttrValueDO == null) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_NOT_EXIST.getCode());
}
// 校验状态
if (productAttrValueDO.getStatus().equals(status)) {
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_VALUE_STATUS_EQUALS.getCode());
}
// 更新到数据库
ProductAttrValueDO updateProductAttrValue = new ProductAttrValueDO().setId(productAttrValueId).setStatus(status);
productAttrValueMapper.updateById(updateProductAttrValue);
// 返回成功
return true;
}
}

View File

@ -3,7 +3,7 @@
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>system</artifactId>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -3,17 +3,30 @@ package cn.iocoder.mall.product.rest.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrBO;
import cn.iocoder.mall.product.biz.dto.attr.AdminProductAttrPageDTO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrSimpleWithValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrWithValueBO;
import cn.iocoder.mall.product.biz.dto.attr.*;
import cn.iocoder.mall.product.biz.service.product.ProductAttrService;
import cn.iocoder.mall.product.rest.convert.attr.ProductAttrConvert;
import cn.iocoder.mall.product.rest.request.attr.AdminProductAttrPageRequest;
import cn.iocoder.mall.product.rest.request.attr.ProductAttrAddRequest;
import cn.iocoder.mall.product.rest.request.attr.ProductAttrUpdateRequest;
import cn.iocoder.mall.product.rest.request.attr.ProductAttrValueAddRequest;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrPageResponse;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrSimpleResponse;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrVO;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrValueResponse;
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 商品规格
@ -34,100 +47,88 @@ public class AdminsProductAttrController {
@ApiOperation("获得规格分页")
public CommonResult<PageResult<AdminsProductAttrPageResponse>> attrPage(AdminProductAttrPageRequest request) {
AdminProductAttrPageDTO pageDTO = ProductAttrConvert.INSTANCE.convert(request);
PageResult<ProductAttrBO> productAttrPage = productAttrService.getProductAttrPage(pageDTO);
PageResult<ProductAttrWithValueBO> productAttrPage = productAttrService.getProductAttrPage(pageDTO);
PageResult<AdminsProductAttrPageResponse> adminPageResponse = ProductAttrConvert.INSTANCE.convertPage(productAttrPage);
return CommonResult.success(adminPageResponse);
}
// @GetMapping("/attr/tree")
// @ApiOperation(value = "获得规格树结构", notes = "该接口返回的信息更为精简。一般用于前端缓存数据字典到本地。")
// public CommonResult<List<AdminsProductAttrSimpleVO>> tree() {
// // 查询全列表
// List<ProductAttrSimpleBO> result = productAttrService.getProductAttrList();
// // 返回结果
// return success(ProductAttrConvert.INSTANCE.convert(result));
// }
//
// @PostMapping("/attr/add")
// @ApiOperation(value = "创建商品规格")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "name", value = "规格名", required = true, example = "颜色")
// })
// public CommonResult<AdminsProductAttrVO> addAttr(@RequestParam("name") String name) {
// // 创建 ProductAttrAddDTO 对象
// ProductAttrAddDTO productAttrAddDTO = new ProductAttrAddDTO().setName(name);
// // 添加
// ProductAttrBO result = productAttrService.addProductAttr(AdminSecurityContextHolder.getContext().getAdminId(), productAttrAddDTO);
// // 返回结果
// return success(ProductAttrConvert.INSTANCE.convert3(result));
// }
//
// @PostMapping("/attr/update")
// @ApiOperation(value = "修改商品规格")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "1"),
// @ApiImplicitParam(name = "name", value = "规格名", required = true, example = "颜色")
// })
// public CommonResult<Boolean> updateAttr(@RequestParam("id") Integer id,
// @RequestParam("name") String name) {
// // 创建 ProductAttrUpdateDTO 对象
// ProductAttrUpdateDTO productAttrUpdateDTO = new ProductAttrUpdateDTO().setId(id).setName(name);
// // 更新
// return success(productAttrService.updateProductAttr(AdminSecurityContextHolder.getContext().getAdminId(), productAttrUpdateDTO));
// }
//
// @PostMapping("/attr/update_status")
// @ApiOperation(value = "修改商品规格状态")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "100"),
// @ApiImplicitParam(name = "status", value = "状态", required = true, example = "1")
// })
// public CommonResult<Boolean> updateAttrStatus(@RequestParam("id") Integer id,
// @RequestParam("status") Integer status) {
// return success(productAttrService.updateProductAttrStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
// }
//
// // TODO 芋艿 暂时不考虑 delete Attr 因为关联逻辑比较多
//
// @PostMapping("/attr_value/add")
// @ApiOperation(value = "创建商品规格值")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "attrId", value = "规格编号", required = true, example = "100"),
// @ApiImplicitParam(name = "name", value = "规格值", required = true, example = "蓝色")
// })
// public CommonResult<AdminsProductAttrValueVO> addAttrValue(@RequestParam("attrId") Integer attrId,
// @RequestParam("name") String name) {
// // 创建 ProductAttrValueAddDTO 对象
// ProductAttrValueAddDTO productAttrValueAddDTO = new ProductAttrValueAddDTO().setAttrId(attrId).setName(name);
// // 添加
// ProductAttrValueBO result = productAttrService.addProductAttrValue(AdminSecurityContextHolder.getContext().getAdminId(), productAttrValueAddDTO);
// // 返回结果
// return success(ProductAttrConvert.INSTANCE.convert4(result));
// }
//
// @PostMapping("/attr_value/update")
// @ApiOperation(value = "修改商品规格值")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "id", value = "规格值编号", required = true, example = "100"),
// @ApiImplicitParam(name = "name", value = "规格值", required = true, example = "蓝色")
// })
// public CommonResult<Boolean> updateAttrValue(@RequestParam("id") Integer id,
// @RequestParam("name") String name) {
// // 创建 ProductAttrValueUpdateDTO 对象
// ProductAttrValueUpdateDTO productAttrValueUpdateDTO = new ProductAttrValueUpdateDTO().setId(id).setName(name);
// // 更新
// return success(productAttrService.updateProductAttrValue(AdminSecurityContextHolder.getContext().getAdminId(), productAttrValueUpdateDTO));
// }
//
// @PostMapping("/attr_value/update_status")
// @ApiImplicitParams({
// @ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "100"),
// @ApiImplicitParam(name = "status", value = "状态", required = true, example = "1")
// })
// public CommonResult<Boolean> updateAttrValueStatus(@RequestParam("id") Integer id,
// @RequestParam("status") Integer status) {
// return success(productAttrService.updateProductAttrValueStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
// }
@GetMapping("/attr/tree")
@ApiOperation(value = "获得规格树结构", notes = "该接口返回的信息更为精简。一般用于前端缓存数据字典到本地。")
public CommonResult<List<AdminsProductAttrSimpleResponse>> tree() {
// 查询全列表
List<ProductAttrSimpleWithValueBO> result = productAttrService.getProductAttrList();
return CommonResult.success(ProductAttrConvert.INSTANCE.convertSimple(result));
}
@PostMapping("/attr/add")
@ApiOperation(value = "创建商品规格")
public CommonResult<AdminsProductAttrVO> addAttr(@Validated ProductAttrAddRequest addRequest) {
// 创建 ProductAttrAddDTO 对象
ProductAttrAddDTO productAttrAddDTO = new ProductAttrAddDTO().setName(addRequest.getName());
// 添加
ProductAttrBO result = productAttrService.addProductAttr(AdminSecurityContextHolder.getContext().getAdminId(), productAttrAddDTO);
return CommonResult.success(ProductAttrConvert.INSTANCE.convertAttr(result));
}
@PostMapping("/attr/update")
@ApiOperation(value = "修改商品规格")
public CommonResult<Boolean> updateAttr(@Validated ProductAttrUpdateRequest updateRequest) {
ProductAttrUpdateDTO productAttrUpdateDTO = ProductAttrConvert.INSTANCE.convertUpdate(updateRequest);
// 更新
return CommonResult.success(productAttrService.updateProductAttr(AdminSecurityContextHolder.getContext().getAdminId(), productAttrUpdateDTO));
}
@PostMapping("/attr/update_status")
@ApiOperation(value = "修改商品规格状态")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "100"),
@ApiImplicitParam(name = "status", value = "状态", required = true, example = "1")
})
public CommonResult<Boolean> updateAttrStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return CommonResult.success(productAttrService.updateProductAttrStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
}
// TODO 芋艿 暂时不考虑 delete Attr 因为关联逻辑比较多
@PostMapping("/attr_value/add")
@ApiOperation(value = "创建商品规格值")
@ApiImplicitParams({
@ApiImplicitParam(name = "attrId", value = "规格编号", required = true, example = "100"),
@ApiImplicitParam(name = "name", value = "规格值", required = true, example = "蓝色")
})
public CommonResult<AdminsProductAttrValueResponse> addAttrValue(@Validated ProductAttrValueAddRequest addRequest) {
// 创建 ProductAttrValueAddDTO 对象
ProductAttrValueAddDTO productAttrValueAddDTO = new ProductAttrValueAddDTO().setAttrId(addRequest.getAttrId()).setName(addRequest.getName());
// 添加
ProductAttrValueBO result = productAttrService.addProductAttrValue(AdminSecurityContextHolder.getContext().getAdminId(), productAttrValueAddDTO);
// 返回结果
return CommonResult.success(ProductAttrConvert.INSTANCE.convertAddResponse(result));
}
@PostMapping("/attr_value/update")
@ApiOperation(value = "修改商品规格值")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "规格值编号", required = true, example = "100"),
@ApiImplicitParam(name = "name", value = "规格值", required = true, example = "蓝色")
})
public CommonResult<Boolean> updateAttrValue(@RequestParam("id") Integer id,
@RequestParam("name") String name) {
// 创建 ProductAttrValueUpdateDTO 对象
ProductAttrValueUpdateDTO productAttrValueUpdateDTO = new ProductAttrValueUpdateDTO().setId(id).setName(name);
// 更新
return CommonResult.success(productAttrService.updateProductAttrValue(AdminSecurityContextHolder.getContext().getAdminId(), productAttrValueUpdateDTO));
}
@PostMapping("/attr_value/update_status")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "规格编号", required = true, example = "100"),
@ApiImplicitParam(name = "status", value = "状态", required = true, example = "1")
})
public CommonResult<Boolean> updateAttrValueStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return CommonResult.success(productAttrService.updateProductAttrValueStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
}
// TODO 芋艿 暂时不考虑 delete Attr Value 因为关联逻辑比较多

View File

@ -2,18 +2,44 @@ package cn.iocoder.mall.product.rest.convert.attr;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrSimpleWithValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO;
import cn.iocoder.mall.product.biz.bo.attr.ProductAttrWithValueBO;
import cn.iocoder.mall.product.biz.dto.attr.AdminProductAttrPageDTO;
import cn.iocoder.mall.product.biz.dto.attr.ProductAttrUpdateDTO;
import cn.iocoder.mall.product.rest.request.attr.AdminProductAttrPageRequest;
import cn.iocoder.mall.product.rest.request.attr.ProductAttrUpdateRequest;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrPageResponse;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrSimpleResponse;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrVO;
import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrValueResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface ProductAttrConvert {
ProductAttrConvert INSTANCE = Mappers.getMapper(ProductAttrConvert.class);
@Mappings({})
AdminProductAttrPageDTO convert(AdminProductAttrPageRequest bean);
PageResult<AdminsProductAttrPageResponse> convertPage(PageResult<ProductAttrBO> productAttrPage);
@Mappings({})
PageResult<AdminsProductAttrPageResponse> convertPage(PageResult<ProductAttrWithValueBO> productAttrPage);
@Mappings({})
List<AdminsProductAttrSimpleResponse> convertSimple(List<ProductAttrSimpleWithValueBO> simpleList);
@Mappings({})
AdminsProductAttrVO convertAttr(ProductAttrBO attrBO);
@Mappings({})
ProductAttrUpdateDTO convertUpdate(ProductAttrUpdateRequest updateRequest);
@Mappings({})
AdminsProductAttrValueResponse convertAddResponse(ProductAttrValueBO result);
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.mall.product.rest.request.attr;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
/**
* 规格添加
*/
@Data
@Accessors(chain = true)
public class ProductAttrAddRequest {
@ApiModelProperty(name = "name", value = "规格名", required = true, example = "颜色")
@NotEmpty(message = "规格名不能为空")
private String name;
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.mall.product.rest.request.attr;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 规格修改
*/
@Data
@Accessors(chain = true)
public class ProductAttrUpdateRequest {
@ApiModelProperty(name = "id", value = "规格编号", required = true, example = "1")
@NotNull(message = "规格编号不能为空")
private Integer id;
@ApiModelProperty(name = "name", value = "规格名", required = true, example = "颜色")
@NotEmpty(message = "规格名不能为空")
private String name;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.mall.product.rest.request.attr;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* Product 规格值添加 DTO
*/
@Data
@Accessors(chain = true)
public class ProductAttrValueAddRequest {
@ApiModelProperty(name = "attrId", value = "规格编号", required = true, example = "1")
@NotNull(message = "规格编号不能为空")
private Integer attrId;
/**
* 名称
*/
@ApiModelProperty(name = "name", value = "规格值名", required = true, example = "红色")
@NotEmpty(message = "规格值名不能为空")
private String name;
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.mall.product.rest.request.attr;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* Product 规格值修改 DTO
* <p>
* 注意不允许修改所属规格
*/
@Data
@Accessors(chain = true)
public class ProductAttrValueUpdateRequest {
@ApiModelProperty(name = "id", value = "规格值编号", required = true, example = "1")
@NotNull(message = "规格值编号不能为空")
private Integer id;
@ApiModelProperty(name = "id", value = "规格值编号", required = true, example = "1")
@NotEmpty(message = "规格名不能为空")
private String name;
}

View File

@ -0,0 +1,38 @@
package cn.iocoder.mall.product.rest.response.attr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@ApiModel(value = "商品规格精简 VO", description = "带有规格值数组")
@Data
@Accessors(chain = true)
public class AdminsProductAttrSimpleResponse {
@ApiModelProperty(value = "规格编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "规格名", required = true, example = "颜色")
private String name;
@ApiModelProperty(value = "规格值数组", required = true)
private List<ProductAttrValue> values;
@ApiModel("规格值")
@Data
@Accessors(chain = true)
public static class ProductAttrValue {
/**
* 规格值编号
*/
@ApiModelProperty(value = "规格值编号", required = true, example = "1")
private Integer id;
/**
* 规格值名
*/
@ApiModelProperty(value = "规格值名", required = true, example = "")
private String name;
}
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.mall.product.rest.response.attr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel(value = "商品规格 VO", description = "不带有规格值数组")
@Data
@Accessors(chain = true)
public class AdminsProductAttrVO {
@ApiModelProperty(value = "规格编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "规格名", required = true, example = "颜色")
private String name;
@ApiModelProperty(value = "状态", required = true, example = "1")
private Integer status;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳")
private Date createTime;
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.mall.product.rest.response.attr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel(value = "商品规格值 VO")
@Data
@Accessors(chain = true)
public class AdminsProductAttrValueResponse {
@ApiModelProperty(value = "规格值编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "规格编号", required = true, example = "1")
private Integer attrId;
@ApiModelProperty(value = "规格名", required = true, example = "颜色")
private String name;
@ApiModelProperty(value = "状态", required = true, example = "1")
private Integer status;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳")
private Date createTime;
}

View File

@ -3,7 +3,7 @@
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>system</artifactId>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -3,7 +3,7 @@
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>system</artifactId>
<artifactId>product</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -1,7 +1,6 @@
package cn.iocoder.mall.product.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import cn.iocoder.mall.product.api.ProductAttrService;
import cn.iocoder.mall.product.api.bo.ProductAttrBO;
import cn.iocoder.mall.product.api.bo.ProductAttrPageBO;
@ -13,12 +12,12 @@ import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrPageVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrSimpleVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductAttrValueVO;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import java.util.List;

View File

@ -1,7 +1,6 @@
package cn.iocoder.mall.product.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import cn.iocoder.mall.product.api.ProductBrandService;
import cn.iocoder.mall.product.api.bo.ProductBrandBO;
import cn.iocoder.mall.product.api.bo.ProductBrangPageBO;
@ -11,12 +10,12 @@ import cn.iocoder.mall.product.api.dto.ProductBrandUpdateDTO;
import cn.iocoder.mall.product.application.convert.ProductBrandConvert;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductBrandVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductBrangPageVO;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import static cn.iocoder.common.framework.vo.CommonResult.success;

View File

@ -1,7 +1,6 @@
package cn.iocoder.mall.product.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import cn.iocoder.mall.product.api.ProductCategoryService;
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import cn.iocoder.mall.product.api.constant.ProductCategoryConstants;
@ -10,12 +9,12 @@ import cn.iocoder.mall.product.api.dto.ProductCategoryUpdateDTO;
import cn.iocoder.mall.product.application.convert.ProductCategoryConvert;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryTreeNodeVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryVO;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Comparator;

View File

@ -1,7 +1,6 @@
package cn.iocoder.mall.product.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import cn.iocoder.mall.product.api.ProductSpuService;
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO;
@ -11,13 +10,13 @@ import cn.iocoder.mall.product.application.convert.ProductSpuConvert;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductSpuDetailVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductSpuPageVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductSpuVO;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.List;

View File

@ -10,7 +10,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 用户收藏