Description or Example
# 代码
## 思路
> 首先, 先构造SKU和SPU的映射信息, 具体的做法是通过查询语句, 从表里面把这两个字段查出来, 最后返回对应的集合, 然后通过stream流映射成一个Map集合, 最终形成映射关系, 然后, 批量收集这些SPUID, 通过SPUID批量查询对应的信息, 具体的映射思路如上, 然后联立两个Map, 最终生成一个SkuID和SPu详情信息的映射
```java
@RequestMapping("/all/spuInfo")
public Map<Long, OrderItemSpuInfoTO> getAllSpuInfoBySkuIds(@RequestParam List<Long> skuIds) {
if (skuIds != null && !skuIds.isEmpty()) {
// SKUId 与 SPUId的映射信息
Map<Long, Long> SkuIdMapSpuId = skuInfoService.getSpuIdBySkuId(skuIds);
ArrayList<Long> spuIds = new ArrayList<>(SkuIdMapSpuId.values());
// 获取到的SPU信息
List<OrderItemSpuInfoTO> orderItemSpuInfoTOS = spuInfoService.getAllSpuInfo(spuIds);
// 封装sku和spu信息的映射信息
HashMap<Long, OrderItemSpuInfoTO> skuMapSpuInfo = new HashMap<>();
if (orderItemSpuInfoTOS != null && !orderItemSpuInfoTOS.isEmpty()) {
Map<Long, OrderItemSpuInfoTO> spuIdMapSpuInfo = orderItemSpuInfoTOS.stream().collect(Collectors.toMap(OrderItemSpuInfoTO::getSpuId, orderItemSpuInfoTO -> orderItemSpuInfoTO));
for (Map.Entry<Long, Long> entry : SkuIdMapSpuId.entrySet()) {
Long skuId = entry.getKey();
Long spuId = entry.getValue();
skuMapSpuInfo.put(skuId, spuIdMapSpuInfo.getOrDefault(spuId, null));
}
return skuMapSpuInfo;
}
}
return null;
}
```
```xml
<select id="getAllSpuInfo" resultType="com.junjie.bitmall.common.to.OrderItemSpuInfoTO">
SELECT psi.id AS spuId, psi.spu_name AS spuName, psim.img_url AS spuPic,
psi.catalog_id AS catalogId, psi.brand_id AS brandId
FROM pms_spu_info psi JOIN pms_spu_images psim ON psi.id = psim.spu_id
WHERE psim.default_img = 1 AND psi.id IN
<foreach collection="spuIds" separator="," open="(" close=")" item="spuId">
#{spuId}
</foreach>
</select>
```