parent
7697c8b0c0
commit
11b2f67ed1
@ -1,57 +0,0 @@
|
|||||||
package cn.iocoder.mall.product.biz.service.spu;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
|
||||||
import cn.iocoder.common.framework.util.StringUtil;
|
|
||||||
import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum;
|
|
||||||
import cn.iocoder.mall.product.biz.bo.product.ProductAttrAndValuePairBO;
|
|
||||||
import cn.iocoder.mall.product.biz.bo.product.ProductSpuDetailBO;
|
|
||||||
import cn.iocoder.mall.product.biz.convert.sku.ProductSpuConvert;
|
|
||||||
import cn.iocoder.mall.product.biz.dao.category.ProductCategoryMapper;
|
|
||||||
import cn.iocoder.mall.product.biz.dao.sku.ProductSkuMapper;
|
|
||||||
import cn.iocoder.mall.product.biz.dao.sku.ProductSpuMapper;
|
|
||||||
import cn.iocoder.mall.product.biz.dataobject.category.ProductCategoryDO;
|
|
||||||
import cn.iocoder.mall.product.biz.dataobject.spu.ProductSkuDO;
|
|
||||||
import cn.iocoder.mall.product.biz.dataobject.spu.ProductSpuDO;
|
|
||||||
import cn.iocoder.mall.product.biz.dto.sku.ProductSkuAddOrUpdateDTO;
|
|
||||||
import cn.iocoder.mall.product.biz.dto.sku.ProductSpuAddDTO;
|
|
||||||
import cn.iocoder.mall.product.biz.enums.ProductErrorCodeEnum;
|
|
||||||
import cn.iocoder.mall.product.biz.enums.category.ProductCategoryNodeEnum;
|
|
||||||
import cn.iocoder.mall.product.biz.enums.spu.ProductSpuConstants;
|
|
||||||
import cn.iocoder.mall.product.biz.service.attr.ProductAttrService;
|
|
||||||
import cn.iocoder.mall.product.biz.service.category.ProductCategoryService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class ProductSpuServiceImpl implements ProductSpuService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ProductAttrService productAttrService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProductSpuDetailBO getProductSpuDetail(Integer spuId) {
|
|
||||||
// 校验商品 spu 存在
|
|
||||||
ProductSpuDO spu = productSpuMapper.selectById(spuId);
|
|
||||||
if (spu == null) {
|
|
||||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_SPU_NOT_EXISTS.getCode());
|
|
||||||
}
|
|
||||||
// 获得商品分类分类
|
|
||||||
ProductCategoryDO category = productCategoryMapper.selectById(spu.getCid());
|
|
||||||
Assert.notNull(category, String.format("分类编号(%d) 对应", spu.getCid()));
|
|
||||||
// 获得商品 sku 数组
|
|
||||||
List<ProductSkuDO> skus = productSkuMapper.selectListBySpuIdAndStatus(spuId, ProductSpuConstants.SKU_STATUS_ENABLE);
|
|
||||||
// 获得规格
|
|
||||||
Set<Integer> productAttrValueIds = new HashSet<>();
|
|
||||||
skus.forEach(sku -> productAttrValueIds.addAll(StringUtil.splitToInt(sku.getAttrs(), ",")));
|
|
||||||
// 读取规格时,不考虑规格是否被禁用
|
|
||||||
List<ProductAttrAndValuePairBO> attrAndValuePairList = productAttrService.validProductAttrAndValue(productAttrValueIds, false);
|
|
||||||
// 返回成功
|
|
||||||
return ProductSpuConvert.INSTANCE.convert2(spu, skus, attrAndValuePairList, category);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
package cn.iocoder.mall.product.api.dto;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package cn.iocoder.mall.productservice.enums.spu;
|
||||||
|
|
||||||
|
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuDetailRespDTO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品 SPU 明细的字段枚举
|
||||||
|
*
|
||||||
|
* @see ProductSpuDetailRespDTO
|
||||||
|
*/
|
||||||
|
public enum ProductSpuDetailFieldEnum {
|
||||||
|
|
||||||
|
SKU("sku"),
|
||||||
|
ATTR("attr");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段
|
||||||
|
*/
|
||||||
|
private final String field;
|
||||||
|
|
||||||
|
ProductSpuDetailFieldEnum(String field) {
|
||||||
|
this.field = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getField() {
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package cn.iocoder.mall.productservice.rpc.attr.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品规格 KEY + VALUE 对的 Response DTO
|
||||||
|
*/
|
||||||
|
public class ProductAttrKeyValueRespDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规格 KEY 编号
|
||||||
|
*/
|
||||||
|
private Integer attrKeyId;
|
||||||
|
/**
|
||||||
|
* 规格 KEY 名
|
||||||
|
*/
|
||||||
|
private String attrKeyName;
|
||||||
|
/**
|
||||||
|
* 规格 VALUE 编号
|
||||||
|
*/
|
||||||
|
private Integer attrValueId;
|
||||||
|
/**
|
||||||
|
* 规格 VALUE 名
|
||||||
|
*/
|
||||||
|
private String attrValueName;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue