mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-27 01:32:03 +08:00
feat:mall product 新增通过 spuIds 获取相关 spu 详情列表的接口
This commit is contained in:
parent
409ec555e8
commit
c563051841
@ -21,6 +21,7 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -100,6 +101,15 @@ public class ProductSpuController {
|
||||
return success(ProductSpuConvert.INSTANCE.convertList02(list));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得商品 SPU 详情列表")
|
||||
@Parameter(name = "spuIds", description = "spu 编号列表", required = true, example = "[1,2,3]")
|
||||
@PreAuthorize("@ss.hasPermission('product:spu:query')")
|
||||
public CommonResult<List<ProductSpuDetailRespVO>> getSpuList(@RequestParam("spuIds") Collection<Long> spuIds) {
|
||||
return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespListVO(
|
||||
productSpuService.getSpuList(spuIds), productSkuService.getSkuListBySpuId(spuIds)));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得商品 SPU 分页")
|
||||
@PreAuthorize("@ss.hasPermission('product:spu:query')")
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.product.convert.spu;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
|
||||
@ -18,6 +19,7 @@ import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
|
||||
|
||||
@ -107,4 +109,15 @@ public interface ProductSpuConvert {
|
||||
return detailRespVO;
|
||||
}
|
||||
|
||||
default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) {
|
||||
ArrayList<ProductSpuDetailRespVO> vos = new ArrayList<>();
|
||||
Map<Long, List<ProductSkuDO>> skuMultiMap = CollectionUtils.convertMultiMap(skus, ProductSkuDO::getSpuId);
|
||||
spus.forEach(spu -> {
|
||||
ProductSpuDetailRespVO detailRespVO = convert03(spu);
|
||||
detailRespVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skuMultiMap.get(spu.getId())));
|
||||
vos.add(detailRespVO);
|
||||
});
|
||||
return vos;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public interface ProductSkuService {
|
||||
* @param spuIds spu 编码集合
|
||||
* @return 商品 sku 集合
|
||||
*/
|
||||
List<ProductSkuDO> getSkuListBySpuId(List<Long> spuIds);
|
||||
List<ProductSkuDO> getSkuListBySpuId(Collection<Long> spuIds);
|
||||
|
||||
/**
|
||||
* 通过 spuId 删除 sku 信息
|
||||
|
@ -148,7 +148,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductSkuDO> getSkuListBySpuId(List<Long> spuIds) {
|
||||
public List<ProductSkuDO> getSkuListBySpuId(Collection<Long> spuIds) {
|
||||
return productSkuMapper.selectListBySpuId(spuIds);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user