Authored by mali

根据sku列表 查询商品的信息

package com.yohoufo.dal.product;
import com.yohoufo.dal.product.model.Goods;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface GoodsMapper {
... ... @@ -16,4 +18,6 @@ public interface GoodsMapper {
List<Goods> selectByProductId(Integer productId);
List<Goods> selectByProductIds(List<Integer> productIds);
List<Goods> selectByIds(@Param("goodsIdList")List<Integer> goodsIdList);
}
\ No newline at end of file
... ...
... ... @@ -50,4 +50,13 @@
#{item}
</foreach>
</select>
<select id="selectByIds">
select id, product_id, color_id, color_name, goods_name, color_image, is_default
from goods where id IN
<foreach item="item" index="index" collection="goodsIdList"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -1934,38 +1934,40 @@ public class ProductServiceImpl implements ProductService {
return null;
}
/*List<Integer> sizeIdList = storageList.stream().map(Storage::getSizeId).collect(Collectors.toList());
List<Integer> sizeIdList = storageList.stream().map(Storage::getSizeId).collect(Collectors.toList());
List<Size> sizes = sizeMapper.selectByIds(sizeIdList);
Map<Integer, String> sizeMap = sizes.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
List<Integer> goodsIdList = storageList.stream().map(Storage::getGoodsId).collect(Collectors.toList());
List<Goods> goodsList = goodsMapper.selectByIds(goodsIdList);
Map<Integer, Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods::getId, a -> a));
List<Integer> productIdList = storageList.stream().map(Storage::getProductId).collect(Collectors.toList());
List<Product> products = productMapper.selectByIds(productIdList);
Map<Integer, Product> productMap = products.stream().collect(Collectors.toMap(Product::getId, a -> a));
StorageDataResp resp = new StorageDataResp();
storageList.forEach(item -> {
GoodsSize goodsSize = new GoodsSize();
goodsSize.setSizeId(storage.getSizeId());
if (size != null) {
goodsSize.setSizeName(size.getSizeName());
}
goodsSize.setSizeId(item.getSizeId());
goodsSize.setSizeName(sizeMap.get(item.getSizeId()));
resp.setSize(goodsSize);
Goods goods = goodsMap.get(item.getGoodsId());
if (null != goods) {
resp.setColorId(goods.getColorId().toString());
resp.setColorName(StringUtils.isEmpty(goods.getGoodsName()) ? goods.getColorName() : goods.getGoodsName());
resp.setImageUrl(goods.getColorImage());
}
resp.setColorId(goods.getColorId().toString());
resp.setColorName(StringUtils.isEmpty(goods.getGoodsName()) ? goods.getColorName() : goods.getGoodsName());
resp.setImageUrl(goods.getColorImage());
Product product = productMap.get(item.getProductId());
if (product != null) {
resp.setProductId(product.getId());
resp.setProductName(product.getProductName());
resp.setStatus(product.getShelveStatus());
}
});*/
});
return respList;
}
... ...