Authored by caoyan

批量查询价格

... ... @@ -31,6 +31,7 @@ import com.yohoufo.product.response.ProductSimpleResp;
import com.yohoufo.product.response.ProductSortTemplateResp;
import com.yohoufo.product.response.SaleCategoryBo;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageInfoResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import com.yohoufo.product.service.ProductService;
... ... @@ -440,7 +441,7 @@ public class ProductController {
return null;
}
LOG.info("in method=ufo.product.storage.info skuList={}", skuList);
List<StorageDataResp> storageList = productService.queryStorageInfoBySkuList(skuList);
List<StorageInfoResp> storageList = productService.queryStorageInfoBySkuList(skuList);
return new ApiResponse.ApiResponseBuilder().data(storageList).code(200).message("storageInfo data").build();
}
}
\ No newline at end of file
... ...
package com.yohoufo.product.response;
import java.math.BigDecimal;
import lombok.Data;
@Data
public class StorageInfoResp {
private Integer productId;
private BigDecimal suggestLowPrice;
private BigDecimal suggestHighPrice;
private BigDecimal leastPrice;
private Integer storageId;
}
... ...
... ... @@ -4,7 +4,6 @@ import java.util.Collection;
import java.util.List;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohoufo.dal.product.model.Storage;
import com.yohoufo.dal.product.model.StoragePrice;
import com.yohoufo.product.request.StoragePriceBo;
import com.yohoufo.product.response.ProductDetailResp;
... ... @@ -13,6 +12,7 @@ import com.yohoufo.product.response.ProductSimpleResp;
import com.yohoufo.product.response.ProductSortTemplateResp;
import com.yohoufo.product.response.SaleCategoryBo;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageInfoResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
public interface ProductService {
... ... @@ -75,5 +75,5 @@ public interface ProductService {
List<SaleCategoryBo> querySaleCategoryDetail(Integer id);
List<StorageDataResp> queryStorageInfoBySkuList(Collection<Integer> skuList);
List<StorageInfoResp> queryStorageInfoBySkuList(Collection<Integer> skuList);
}
... ...
package com.yohoufo.product.service.impl;
import java.math.BigDecimal;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;
... ... @@ -51,6 +58,7 @@ import com.yohoufo.product.response.ProductSimpleResp;
import com.yohoufo.product.response.ProductSortTemplateResp;
import com.yohoufo.product.response.SaleCategoryBo;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageInfoResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import com.yohoufo.product.service.ProductService;
... ... @@ -195,7 +203,7 @@ public class ProductServiceImpl implements ProductService{
}
@Override
public List<StorageDataResp> queryStorageInfoBySkuList(Collection<Integer> skuList){
public List<StorageInfoResp> queryStorageInfoBySkuList(Collection<Integer> skuList){
if (CollectionUtils.isEmpty(skuList)) {
return Lists.newArrayList();
}
... ... @@ -208,15 +216,15 @@ public class ProductServiceImpl implements ProductService{
List<StoragePrice> storagePrices = storagePriceMapper.selectBatchLeastPrice(skuList);
Map<Integer, BigDecimal> priceMap = storagePrices.stream().collect(Collectors.toMap(StoragePrice::getStorageId, StoragePrice::getPrice));
List<StorageDataResp> resp = Lists.newArrayList();
List<StorageInfoResp> resp = Lists.newArrayList();
storageList.stream().forEach(item -> {
StorageDataResp storageDataResp = new StorageDataResp();
storageDataResp.setProductId(item.getProductId());
storageDataResp.setSuggestHighPrice(item.getSuggestHighPrice());
storageDataResp.setSuggestLowPrice(item.getSuggestLowPrice());
storageDataResp.setStorageId(item.getId());
storageDataResp.setLeastPrice(priceMap.get(item.getId()));
resp.add(storageDataResp);
StorageInfoResp storageInfoResp = new StorageInfoResp();
storageInfoResp.setProductId(item.getProductId());
storageInfoResp.setSuggestHighPrice(item.getSuggestHighPrice());
storageInfoResp.setSuggestLowPrice(item.getSuggestLowPrice());
storageInfoResp.setStorageId(item.getId());
storageInfoResp.setLeastPrice(priceMap.get(item.getId()));
resp.add(storageInfoResp);
});
return resp;
... ...