Authored by mali

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

1 package com.yohoufo.dal.product; 1 package com.yohoufo.dal.product;
2 2
3 import com.yohoufo.dal.product.model.Goods; 3 import com.yohoufo.dal.product.model.Goods;
  4 +import org.apache.ibatis.annotations.Param;
  5 +
4 import java.util.List; 6 import java.util.List;
5 7
6 public interface GoodsMapper { 8 public interface GoodsMapper {
@@ -16,4 +18,6 @@ public interface GoodsMapper { @@ -16,4 +18,6 @@ public interface GoodsMapper {
16 List<Goods> selectByProductId(Integer productId); 18 List<Goods> selectByProductId(Integer productId);
17 19
18 List<Goods> selectByProductIds(List<Integer> productIds); 20 List<Goods> selectByProductIds(List<Integer> productIds);
  21 +
  22 + List<Goods> selectByIds(@Param("goodsIdList")List<Integer> goodsIdList);
19 } 23 }
@@ -50,4 +50,13 @@ @@ -50,4 +50,13 @@
50 #{item} 50 #{item}
51 </foreach> 51 </foreach>
52 </select> 52 </select>
  53 +
  54 + <select id="selectByIds">
  55 + select id, product_id, color_id, color_name, goods_name, color_image, is_default
  56 + from goods where id IN
  57 + <foreach item="item" index="index" collection="goodsIdList"
  58 + open="(" separator="," close=")">
  59 + #{item}
  60 + </foreach>
  61 + </select>
53 </mapper> 62 </mapper>
@@ -1934,38 +1934,40 @@ public class ProductServiceImpl implements ProductService { @@ -1934,38 +1934,40 @@ public class ProductServiceImpl implements ProductService {
1934 return null; 1934 return null;
1935 } 1935 }
1936 1936
1937 - /*List<Integer> sizeIdList = storageList.stream().map(Storage::getSizeId).collect(Collectors.toList()); 1937 + List<Integer> sizeIdList = storageList.stream().map(Storage::getSizeId).collect(Collectors.toList());
1938 List<Size> sizes = sizeMapper.selectByIds(sizeIdList); 1938 List<Size> sizes = sizeMapper.selectByIds(sizeIdList);
1939 1939
  1940 + Map<Integer, String> sizeMap = sizes.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
  1941 +
1940 List<Integer> goodsIdList = storageList.stream().map(Storage::getGoodsId).collect(Collectors.toList()); 1942 List<Integer> goodsIdList = storageList.stream().map(Storage::getGoodsId).collect(Collectors.toList());
1941 List<Goods> goodsList = goodsMapper.selectByIds(goodsIdList); 1943 List<Goods> goodsList = goodsMapper.selectByIds(goodsIdList);
  1944 + Map<Integer, Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods::getId, a -> a));
1942 1945
1943 List<Integer> productIdList = storageList.stream().map(Storage::getProductId).collect(Collectors.toList()); 1946 List<Integer> productIdList = storageList.stream().map(Storage::getProductId).collect(Collectors.toList());
1944 List<Product> products = productMapper.selectByIds(productIdList); 1947 List<Product> products = productMapper.selectByIds(productIdList);
  1948 + Map<Integer, Product> productMap = products.stream().collect(Collectors.toMap(Product::getId, a -> a));
1945 1949
1946 StorageDataResp resp = new StorageDataResp(); 1950 StorageDataResp resp = new StorageDataResp();
1947 storageList.forEach(item -> { 1951 storageList.forEach(item -> {
1948 -  
1949 GoodsSize goodsSize = new GoodsSize(); 1952 GoodsSize goodsSize = new GoodsSize();
1950 - goodsSize.setSizeId(storage.getSizeId());  
1951 - if (size != null) {  
1952 - goodsSize.setSizeName(size.getSizeName());  
1953 - } 1953 + goodsSize.setSizeId(item.getSizeId());
  1954 + goodsSize.setSizeName(sizeMap.get(item.getSizeId()));
1954 resp.setSize(goodsSize); 1955 resp.setSize(goodsSize);
1955 1956
  1957 + Goods goods = goodsMap.get(item.getGoodsId());
  1958 + if (null != goods) {
  1959 + resp.setColorId(goods.getColorId().toString());
  1960 + resp.setColorName(StringUtils.isEmpty(goods.getGoodsName()) ? goods.getColorName() : goods.getGoodsName());
  1961 + resp.setImageUrl(goods.getColorImage());
  1962 + }
1956 1963
1957 -  
1958 - resp.setColorId(goods.getColorId().toString());  
1959 - resp.setColorName(StringUtils.isEmpty(goods.getGoodsName()) ? goods.getColorName() : goods.getGoodsName());  
1960 - resp.setImageUrl(goods.getColorImage());  
1961 -  
1962 - 1964 + Product product = productMap.get(item.getProductId());
1963 if (product != null) { 1965 if (product != null) {
1964 resp.setProductId(product.getId()); 1966 resp.setProductId(product.getId());
1965 resp.setProductName(product.getProductName()); 1967 resp.setProductName(product.getProductName());
1966 resp.setStatus(product.getShelveStatus()); 1968 resp.setStatus(product.getShelveStatus());
1967 } 1969 }
1968 - });*/ 1970 + });
1969 1971
1970 return respList; 1972 return respList;
1971 } 1973 }