增加商品详情 RPC 接口
This commit is contained in:
parent
7697c8b0c0
commit
11b2f67ed1
|
@ -34,6 +34,6 @@ public interface ProductAttrConvert {
|
|||
|
||||
List<ProductAttrValueRespVO> convertList02(List<ProductAttrValueRespDTO> list);
|
||||
|
||||
ProductAttrValueListQueryRequestDTO convert(ProductAttrValueListQueryReqVO bean);
|
||||
ProductAttrValueListQueryReqDTO convert(ProductAttrValueListQueryReqVO bean);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,6 @@ import java.util.List;
|
|||
|
||||
public interface ProductAttrService {
|
||||
|
||||
ProductAttrPageBO getProductAttrPage(ProductAttrPageDTO productAttrPageDTO);
|
||||
|
||||
/**
|
||||
* 获得规格属性数组
|
||||
|
|
|
@ -13,15 +13,6 @@ public interface ProductSpuService {
|
|||
|
||||
ProductSpuDetailBO getProductSpuDetail(Integer id);
|
||||
|
||||
/**
|
||||
* 增量获得商品列表,按照 lastId 递增获得
|
||||
*
|
||||
* @param lastId 最后查询的编号
|
||||
* @param limit 大小
|
||||
* @return 商品列表
|
||||
*/
|
||||
List<ProductSpuDetailBO> getProductSpuDetailListForSync(Integer lastId, Integer limit);
|
||||
|
||||
List<ProductSpuBO> getProductSpuSearchList(ProductSpuSearchListDTO productSpuSearchListDTO);
|
||||
|
||||
List<ProductSpuBO> getProductSpuList(Collection<Integer> ids);
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.List;
|
|||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Deprecated
|
||||
public class ProductSpuDetailBO implements Serializable {
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -81,30 +81,7 @@ public interface ProductSpuConvert {
|
|||
})
|
||||
ProductSkuBO convert4(ProductSkuDO sku);
|
||||
|
||||
@Mappings({}) // TODO 芋艿,后续细看下 mapstruct 的 API ,优化这块
|
||||
default ProductSpuDetailBO convert2(ProductSpuDO spu, List<ProductSkuDO> skus, List<ProductAttrAndValuePairBO> productAttrDetailBOs,
|
||||
ProductCategoryDO category) {
|
||||
// 创建并转换 ProductSpuDetailBO 对象
|
||||
ProductSpuDetailBO spuDetail = this.convert2(spu).setPicUrls(StringUtil.split(spu.getPicUrls(), ","));
|
||||
// 创建 ProductAttrDetailBO 的映射。其中,KEY 为 ProductAttrDetailBO.attrValueId ,即规格值的编号
|
||||
Map<Integer, ProductAttrAndValuePairBO> productAttrDetailBOMap = productAttrDetailBOs.stream().collect(
|
||||
Collectors.toMap(ProductAttrAndValuePairBO::getAttrValueId, productAttrDetailBO -> productAttrDetailBO));
|
||||
// 创建并转换 ProductSpuDetailBO 数组
|
||||
spuDetail.setSkus(new ArrayList<>());
|
||||
skus.forEach(sku -> {
|
||||
// 创建 ProductSpuDetailBO 对象
|
||||
ProductSpuDetailBO.Sku skuDetail = ProductSpuConvert.this.convert2(sku)
|
||||
.setAttrs(new ArrayList<>());
|
||||
spuDetail.getSkus().add(skuDetail);
|
||||
// 设置 ProductSpuDetailBO 的 attrs 规格属性
|
||||
List<String> attrs = StringUtil.split(sku.getAttrs(), ",");
|
||||
attrs.forEach(attr -> skuDetail.getAttrs().add(productAttrDetailBOMap.get(Integer.valueOf(attr))));
|
||||
});
|
||||
// 设置分类名
|
||||
spuDetail.setCategoryName(category.getName());
|
||||
// 返回
|
||||
return spuDetail;
|
||||
}
|
||||
|
||||
|
||||
@Mappings({}) // TODO 芋艿,后续细看下 mapstruct 的 API ,优化这块
|
||||
default List<ProductSkuDetailBO> convert3(List<ProductSkuDO> skus, List<ProductSpuDO> spus, List<ProductAttrAndValuePairBO> productAttrDetailBOs) {
|
||||
|
|
|
@ -34,24 +34,4 @@ public class UsersProductSpuController {
|
|||
return success(ProductSpuConvert.INSTANCE.convert4(productSpuService.getProductSpuDetail(id)));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("商品 SPU 分页列表")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "cid", value = "分类编号", example = "1"),
|
||||
@ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"),
|
||||
})
|
||||
@Deprecated // 使用商品搜索接口
|
||||
public CommonResult<UsersProductSpuPageVO> page(@RequestParam(value = "cid", required = false) Integer cid,
|
||||
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
// 创建 ProductSpuPageDTO 对象
|
||||
ProductSpuPageDTO productSpuPageDTO = new ProductSpuPageDTO().setCid(cid).setVisible(true)
|
||||
.setPageNo(pageNo).setPageSize(pageSize);
|
||||
// 查询分页
|
||||
ProductSpuPageBO result = productSpuService.getProductSpuPage(productSpuPageDTO);
|
||||
// 返回结果
|
||||
return success(ProductSpuConvert.INSTANCE.convert3(result));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package cn.iocoder.mall.product.application.vo.users;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel(value = "商品 SPU VO", description = "不包括 SKU 信息 VO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UsersProductSpuVO {
|
||||
|
||||
@ApiModelProperty(value = "SPU 编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
|
||||
// ========== 基本信息 =========
|
||||
@ApiModelProperty(value = "SPU 名字", required = true, example = "厮大牛逼")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "卖点", required = true, example = "各种 MQ 骚操作")
|
||||
private String sellPoint;
|
||||
@ApiModelProperty(value = "分类编号", required = true, example = "反正我是信了")
|
||||
private Integer cid;
|
||||
@ApiModelProperty(value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn")
|
||||
private List<String> picUrls;
|
||||
|
||||
// ========== Sku 相关字段 =========
|
||||
/**
|
||||
* 价格
|
||||
*
|
||||
* 目前的计算方式是,以 Sku 最小价格为准
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*
|
||||
* 目前的计算方式是,以 Sku 库存累加为准
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -79,6 +79,6 @@ public interface ProductAttrRpc {
|
|||
* @param queryDTO 商品规格值的列表查询条件 DTO
|
||||
* @return 商品规格值列表
|
||||
*/
|
||||
CommonResult<List<ProductAttrValueRespDTO>> listProductAttrValues(ProductAttrValueListQueryRequestDTO queryDTO);
|
||||
CommonResult<List<ProductAttrValueRespDTO>> listProductAttrValues(ProductAttrValueListQueryReqDTO queryDTO);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -11,7 +11,7 @@ import java.util.List;
|
|||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductAttrValueListQueryRequestDTO implements Serializable {
|
||||
public class ProductAttrValueListQueryReqDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 商品规格值编号列表
|
|
@ -2,11 +2,9 @@ package cn.iocoder.mall.productservice.rpc.spu;
|
|||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -62,4 +60,6 @@ public interface ProductSpuRpc {
|
|||
*/
|
||||
CommonResult<List<Integer>> listProductSpuIds(Integer lastSpuId, Integer limit);
|
||||
|
||||
CommonResult<ProductSpuDetailRespDTO> getProductSpuDetail(Integer productSpuId, Collection<String> fields);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
package cn.iocoder.mall.productservice.rpc.spu.dto;
|
||||
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyValueRespDTO;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品 SPU 明细 Response DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSpuDetailRespDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* SPU 编号
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
// ========== 基本信息 =========
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 卖点
|
||||
*/
|
||||
private String sellPoint;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 分类名
|
||||
*/
|
||||
private String categoryName;
|
||||
/**
|
||||
* 商品主图地址
|
||||
*
|
||||
* 数组,以逗号分隔
|
||||
*
|
||||
* 建议尺寸:800*800像素,你可以拖拽图片调整顺序,最多上传15张
|
||||
*/
|
||||
private List<String> picUrls;
|
||||
|
||||
// ========== 其他信息 =========
|
||||
/**
|
||||
* 是否上架商品(是否可见)。
|
||||
*
|
||||
* true 为已上架
|
||||
* false 为已下架
|
||||
*/
|
||||
private Boolean visible;
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
// ========== SKU =========
|
||||
|
||||
/**
|
||||
* SKU 数组
|
||||
*/
|
||||
private List<Sku> skus;
|
||||
|
||||
/**
|
||||
* 商品 Sku 明细
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Sku implements Serializable {
|
||||
|
||||
/**
|
||||
* sku 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 商品编号
|
||||
*/
|
||||
private Integer spuId;
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
private String picURL;
|
||||
/**
|
||||
* 规格值数组
|
||||
*/
|
||||
private List<ProductAttrKeyValueRespDTO> attrs;
|
||||
/**
|
||||
* 价格,单位:分
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -56,6 +56,6 @@ public interface ProductAttrConvert {
|
|||
|
||||
List<ProductAttrValueRespDTO> convertList04(List<ProductAttrValueBO> list);
|
||||
|
||||
ProductAttrValueListQueryBO convert(ProductAttrValueListQueryRequestDTO bean);
|
||||
ProductAttrValueListQueryBO convert(ProductAttrValueListQueryReqDTO bean);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,10 +3,11 @@ package cn.iocoder.mall.productservice.convert.spu;
|
|||
import cn.iocoder.common.framework.util.StringUtils;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.dal.mysql.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.attr.dto.ProductAttrKeyValueRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyValueBO;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuCreateOrUpdateBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuCreateBO;
|
||||
|
@ -18,7 +19,10 @@ import org.mapstruct.Mapping;
|
|||
import org.mapstruct.Named;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Mapper
|
||||
public interface ProductSpuConvert {
|
||||
|
@ -44,6 +48,7 @@ public interface ProductSpuConvert {
|
|||
ProductSpuUpdateBO convert(ProductSpuAndSkuUpdateReqDTO bean);
|
||||
|
||||
ProductSpuRespDTO convert(ProductSpuBO bean);
|
||||
ProductSpuDetailRespDTO convert2(ProductSpuBO bean);
|
||||
|
||||
List<ProductSpuRespDTO> convertList02(List<ProductSpuBO> list);
|
||||
|
||||
|
@ -54,6 +59,32 @@ public interface ProductSpuConvert {
|
|||
List<ProductSkuCreateOrUpdateBO> convert(List<ProductSpuAndSkuCreateReqDTO.Sku> list);
|
||||
List<ProductSkuCreateOrUpdateBO> convert02(List<ProductSpuAndSkuUpdateReqDTO.Sku> list);
|
||||
|
||||
ProductSpuDetailRespDTO.Sku convert(ProductSkuBO bean);
|
||||
|
||||
ProductAttrKeyValueRespDTO convert(ProductAttrKeyValueBO bean);
|
||||
|
||||
default ProductSpuDetailRespDTO convert(ProductSpuBO spuBO, List<ProductSkuBO> skuBOs, List<ProductAttrKeyValueBO> attrBOs,
|
||||
ProductCategoryBO categoryBO) {
|
||||
// 创建并转换 ProductSpuDetailBO 对象
|
||||
ProductSpuDetailRespDTO spuDetailDTO = this.convert2(spuBO);
|
||||
// 创建 ProductAttrDetailBO 的映射。其中,KEY 为 ProductAttrDetailBO.attrValueId ,即规格值的编号
|
||||
Map<Integer, ProductAttrKeyValueBO> productAttrDetailBOMap = attrBOs.stream().collect(
|
||||
Collectors.toMap(ProductAttrKeyValueBO::getAttrValueId, attrBO -> attrBO));
|
||||
// 创建并转换 ProductSpuDetailBO 数组
|
||||
spuDetailDTO.setSkus(new ArrayList<>());
|
||||
skuBOs.forEach(sku -> {
|
||||
// 创建 ProductSpuDetailBO 对象
|
||||
ProductSpuDetailRespDTO.Sku skuDetail = convert(sku).setAttrs(new ArrayList<>());
|
||||
spuDetailDTO.getSkus().add(skuDetail);
|
||||
// 设置 ProductSpuDetailBO 的 attrs 规格属性
|
||||
sku.getAttrValueIds().forEach(attrValueId -> skuDetail.getAttrs().add(convert(productAttrDetailBOMap.get(attrValueId))));
|
||||
});
|
||||
// 设置分类名
|
||||
spuDetailDTO.setCategoryName(categoryBO.getName());
|
||||
// 返回
|
||||
return spuDetailDTO;
|
||||
}
|
||||
|
||||
@Named("translatePicUrlsFromString")
|
||||
default List<String> translatePicUrlsFromList(String picUrls) {
|
||||
return StringUtils.split(picUrls, ",");
|
||||
|
|
|
@ -21,7 +21,8 @@ public interface ProductSkuMapper extends BaseMapper<ProductSkuDO> {
|
|||
|
||||
default List<ProductSkuDO> selectList(ProductSkuListQueryBO queryBO) {
|
||||
return selectList(new QueryWrapperX<ProductSkuDO>().eqIfPresent("id", queryBO.getProductSkuId())
|
||||
.eqIfPresent("spu_id", queryBO.getProductSpuId()));
|
||||
.eqIfPresent("spu_id", queryBO.getProductSpuId())
|
||||
.eqIfPresent("status", queryBO.getProductSkuStatus()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public class ProductAttrManager {
|
|||
* @param queryDTO 商品规格值的列表查询条件 DTO
|
||||
* @return 商品规格值列表
|
||||
*/
|
||||
public List<ProductAttrValueRespDTO> listProductAttrValues(ProductAttrValueListQueryRequestDTO queryDTO) {
|
||||
public List<ProductAttrValueRespDTO> listProductAttrValues(ProductAttrValueListQueryReqDTO queryDTO) {
|
||||
List<ProductAttrValueBO> productAttrValueBOs = productAttrService.listProductAttrValues(ProductAttrConvert.INSTANCE.convert(queryDTO));
|
||||
return ProductAttrConvert.INSTANCE.convertList04(productAttrValueBOs);
|
||||
}
|
||||
|
|
|
@ -1,24 +1,27 @@
|
|||
package cn.iocoder.mall.productservice.manager.spu;
|
||||
|
||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.util.CollectionUtils;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.convert.spu.ProductSpuConvert;
|
||||
import cn.iocoder.mall.productservice.enums.category.ProductCategoryIdEnum;
|
||||
import cn.iocoder.mall.productservice.enums.spu.ProductSpuDetailFieldEnum;
|
||||
import cn.iocoder.mall.productservice.mq.producer.ProductMQProducer;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
import cn.iocoder.mall.productservice.service.attr.ProductAttrService;
|
||||
import cn.iocoder.mall.productservice.service.attr.bo.ProductAttrKeyValueBO;
|
||||
import cn.iocoder.mall.productservice.service.category.ProductCategoryService;
|
||||
import cn.iocoder.mall.productservice.service.category.bo.ProductCategoryBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.ProductSkuService;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuCreateOrUpdateBO;
|
||||
import cn.iocoder.mall.productservice.service.sku.bo.ProductSkuListQueryBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.ProductSpuService;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuCreateBO;
|
||||
import cn.iocoder.mall.productservice.service.spu.bo.ProductSpuUpdateBO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.aop.framework.AopContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -33,6 +36,7 @@ import static cn.iocoder.mall.productservice.enums.ProductErrorCodeConstants.*;
|
|||
* 商品 SPU Manager
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ProductSpuManager {
|
||||
|
||||
@Autowired
|
||||
|
@ -207,4 +211,32 @@ public class ProductSpuManager {
|
|||
return attrKeyValueBOs;
|
||||
}
|
||||
|
||||
public ProductSpuDetailRespDTO getProductSpuDetail(Integer productSpuId, Collection<String> fields) {
|
||||
// 获得商品 SPU 信息
|
||||
ProductSpuBO spuBO = productSpuService.getProductSpu(productSpuId);
|
||||
if (spuBO == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_SPU_NOT_EXISTS);
|
||||
}
|
||||
// 获取商品分类
|
||||
ProductCategoryBO categoryBO = productCategoryService.getProductCategory(spuBO.getCid());
|
||||
if (categoryBO == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
||||
}
|
||||
// 获得商品 SKU 数组
|
||||
List<ProductSkuBO> skuBOs = Collections.emptyList();
|
||||
if (fields.contains(ProductSpuDetailFieldEnum.SKU.getField())) {
|
||||
skuBOs = productSkuService.listProductSkus(new ProductSkuListQueryBO().setProductSpuId(productSpuId)
|
||||
.setProductSkuStatus(CommonStatusEnum.ENABLE.getValue()));
|
||||
}
|
||||
// 获取商品 SKU 的规格数组
|
||||
List<ProductAttrKeyValueBO> attrBOs = Collections.emptyList();
|
||||
if (fields.contains(ProductSpuDetailFieldEnum.ATTR.getField()) && !CollectionUtils.isEmpty(skuBOs)) {
|
||||
Set<Integer> productAttrValueIds = new HashSet<>();
|
||||
skuBOs.forEach(sku -> productAttrValueIds.addAll(sku.getAttrValueIds()));
|
||||
attrBOs = productAttrService.validProductAttr(productAttrValueIds, false); // 读取规格时,不考虑规格是否被禁用
|
||||
}
|
||||
// 拼接最终返回
|
||||
return ProductSpuConvert.INSTANCE.convert(spuBO, skuBOs, attrBOs, categoryBO);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public class ProductAttrRpcImpl implements ProductAttrRpc {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<ProductAttrValueRespDTO>> listProductAttrValues(ProductAttrValueListQueryRequestDTO queryDTO) {
|
||||
public CommonResult<List<ProductAttrValueRespDTO>> listProductAttrValues(ProductAttrValueListQueryReqDTO queryDTO) {
|
||||
return success(productAttrManager.listProductAttrValues(queryDTO));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,11 @@ package cn.iocoder.mall.productservice.rpc.spu;
|
|||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.manager.spu.ProductSpuManager;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuCreateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuAndSkuUpdateReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuPageReqDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.*;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
@ -54,4 +52,9 @@ public class ProductSpuRpcImpl implements ProductSpuRpc {
|
|||
return success(productSpuManager.listProductSpuIds(lastSpuId, limit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<ProductSpuDetailRespDTO> getProductSpuDetail(Integer productSpuId, Collection<String> fields) {
|
||||
return success(productSpuManager.getProductSpuDetail(productSpuId, fields));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,5 +18,9 @@ public class ProductSkuListQueryBO {
|
|||
* 商品 SPU 编号
|
||||
*/
|
||||
private Integer productSpuId;
|
||||
/**
|
||||
* 商品 SKU 状态
|
||||
*/
|
||||
private Integer productSkuStatus;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue