diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java index f2b97aee7..90387f90a 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java @@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import java.util.Date; +import java.util.LinkedList; import java.util.List; @ApiModel("管理后台 - 商品spu Response VO") @@ -29,4 +30,7 @@ public class SpuRespVO extends ProductSpuBaseVO { */ List skus; + @ApiModelProperty(value = "分类id数组,一直递归到一级父节点", example = "[1,2,4]") + LinkedList categoryIds; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index fbcd32031..4420b0af8 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; @@ -16,9 +17,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -105,6 +104,19 @@ public class ProductSpuServiceImpl implements ProductSpuService { if (null != spuVO) { List skuReqs = ProductSkuConvert.INSTANCE.convertList(productSkuService.getSkusBySpuId(id)); spuVO.setSkus(skuReqs); + // 组合分类 + if (null != spuVO.getCategoryId()) { + LinkedList categoryArray = new LinkedList<>(); + Long parentId = spuVO.getCategoryId(); + categoryArray.addFirst(parentId); + while (parentId != 0) { + parentId = categoryService.getCategory(parentId).getParentId(); + if (parentId > 0) { + categoryArray.addFirst(parentId); + } + } + spuVO.setCategoryIds(categoryArray); + } } return spuVO; }