Authored by wujiexiang

求购最高价添加缓存

... ... @@ -266,7 +266,7 @@ public class BuyerOrderDetailService extends AbsOrderDetailService implements IO
return;
}
GoodsInfo goodsInfo = orderDetailInfo.getGoodsInfo();
refreshGoodsInfo(goodsInfo, bidProductProxyService.getStatisticalPrice(Sets.newHashSet(goodsInfo.getStorageId())));
refreshGoodsInfo(goodsInfo, bidProductProxyService.getStatisticalPrice(goodsInfo.getProductId(), Sets.newHashSet(goodsInfo.getStorageId())));
}
@Override
... ...
... ... @@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderListType;
... ... @@ -34,6 +35,8 @@ import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
... ... @@ -184,10 +187,15 @@ public class BuyerOrderListServiceImpl extends AbsOrderListService implements IO
if (CollectionUtils.isEmpty(refreshList)) {
return;
}
Set<Integer> storageIds = refreshList.stream().map(item -> item.getGoodsInfo().getStorageId()).collect(Collectors.toSet());
Map<Integer, BidStoragePriceResp> statisticalPriceMap = bidProductProxyService.getStatisticalPrice(storageIds);
//按key = productId,value= StorageId集合进行分组
Map<Integer, Set<Integer>> productGroup = refreshList.stream().map(item -> item.getGoodsInfo())
.collect(Collectors.groupingBy(GoodsInfo::getProductId, Collectors.mapping(GoodsInfo::getStorageId, Collectors.toSet())));
Map<Integer, BidStoragePriceResp> allPriceMap = new LinkedHashMap<>();
productGroup.forEach((productId, storageIds) -> {
allPriceMap.putAll(bidProductProxyService.getStatisticalPrice(productId, storageIds));
});
refreshList.forEach(item -> {
refreshGoodsInfo(item.getGoodsInfo(), statisticalPriceMap);
refreshGoodsInfo(item.getGoodsInfo(), allPriceMap);
});
}
... ...
... ... @@ -110,19 +110,19 @@ public class BidProductProxyService extends AbsProxyService {
}
}
public Map<Integer, BidStoragePriceResp> getStatisticalPrice(Set<Integer> storageIds) {
logger.info("getStatisticalPrice,storageIds:{}", storageIds);
if (CollectionUtils.isEmpty(storageIds)) {
public Map<Integer, BidStoragePriceResp> getStatisticalPrice(Integer productId, Set<Integer> storageIds) {
logger.info("getStatisticalPrice,productId:{},storageIds:{}", productId, storageIds);
if (productId == null || CollectionUtils.isEmpty(storageIds)) {
return Collections.EMPTY_MAP;
}
try {
BidStoragePriceResp[] resps = getResultFromApiResponse(ufoServiceCaller.call(GET_STATISTICAL_PRICE_API, storageIds), BidStoragePriceResp[].class);
BidStoragePriceResp[] resps = getResultFromApiResponse(ufoServiceCaller.call(GET_STATISTICAL_PRICE_API, productId, storageIds), BidStoragePriceResp[].class);
if (ArrayUtils.isEmpty(resps)) {
return Collections.EMPTY_MAP;
}
return Arrays.stream(resps).collect(Collectors.toMap(BidStoragePriceResp::getStorageId, Function.identity(), (key1, key2) -> key2));
} catch (Exception ex) {
logger.warn("exception happened when getStatisticalPrice,storageIds:{}", storageIds);
logger.warn("exception happened when getStatisticalPrice,productId:{},storageIds:{}", productId, storageIds);
return Collections.EMPTY_MAP;
}
}
... ...
... ... @@ -185,13 +185,14 @@ public class BidProductController {
@ApiOperation(name = "ufo.product.bid.getStatisticalPrice", desc = "统计各种价格")
@RequestMapping(params = "method=ufo.product.bid.getStatisticalPrice")
public ApiResponse getStatisticalPrice(@RequestParam(value = "storageIds") Set<Integer> storageIds) {
if (CollectionUtils.isEmpty(storageIds)) {
logger.info("in method=ufo.product.bid.getStatisticalPrice storageIds is null");
public ApiResponse getStatisticalPrice(@RequestParam(value = "productId") Integer productId,
@RequestParam(value = "storageIds") Set<Integer> storageIds) {
if (productId == null || CollectionUtils.isEmpty(storageIds)) {
logger.info("in method=ufo.product.bid.getStatisticalPrice productId is null or storageIds is empty");
return new ApiResponse(200, "ok", Lists.newArrayList());
}
logger.info("in method=ufo.product.bid.getStatisticalPrice storageIds={}", storageIds);
List<BidStoragePriceResp> statisticalPrices = bidProductService.getStatisticalPrice(storageIds);
logger.info("in method=ufo.product.bid.getStatisticalPrice,productId={}, storageIds={}", productId, storageIds);
List<BidStoragePriceResp> statisticalPrices = bidProductService.getStatisticalPrice(productId, storageIds);
return new ApiResponse(200, "ok", statisticalPrices);
}
}
... ...
... ... @@ -10,11 +10,8 @@ import com.yohobuy.ufo.model.order.common.BidSkupStatus;
import com.yohobuy.ufo.model.response.BidStoragePriceResp;
import com.yohoufo.dal.product.BidStoragePriceMapper;
import com.yohoufo.dal.product.ProductMapper;
import com.yohoufo.dal.product.StorageMapper;
import com.yohoufo.dal.product.StoragePriceMapper;
import com.yohoufo.dal.product.model.BidStoragePrice;
import com.yohoufo.dal.product.model.Product;
import com.yohoufo.dal.product.model.Storage;
import com.yohoufo.dal.product.model.StoragePrice;
import com.yohoufo.product.cache.UfoProductCacheKeyEnum;
import com.yohoufo.product.cache.UfoProductCacheService;
... ... @@ -47,12 +44,8 @@ public class BidProductService {
@Autowired
private BidStoragePriceMapper bidStoragePriceMapper;
@Autowired
private StorageMapper storageMapper;
@Autowired
private StoragePriceMapper storagePriceMapper;
private StoragePriceService storagePriceService;
/**
... ... @@ -221,32 +214,32 @@ public class BidProductService {
/**
* 获取统计价格
* 现货最低价,现货最高求购价
*
* @param storageIds
* @return
*/
public List<BidStoragePriceResp> getStatisticalPrice(Set<Integer> storageIds) {
if (CollectionUtils.isEmpty(storageIds)) {
return Lists.newArrayList();
}
List<Storage> storageList = storageMapper.selectByIds(storageIds);
if (CollectionUtils.isEmpty(storageList)) {
public List<BidStoragePriceResp> getStatisticalPrice(int productId, Set<Integer> storageIds) {
if (productId < 0 || CollectionUtils.isEmpty(storageIds)) {
return Lists.newArrayList();
}
List<StoragePrice> storagePrices = storagePriceMapper.selectBatchLeastPrice(storageIds);
List<BidStoragePrice> bidStoragePrices = bidStoragePriceMapper.selectHighestPrices(storageIds);
Map<Integer, BigDecimal> priceMap = storagePrices.stream().collect(Collectors.toMap(StoragePrice::getStorageId, StoragePrice::getPrice));
Map<Integer, BigDecimal> bidPriceMap = bidStoragePrices.stream().collect(Collectors.toMap(BidStoragePrice::getStorageId, BidStoragePrice::getPrice));
//现货最低价
Map<Integer, StoragePrice> storagePriceMap = storagePriceService.selectInStockLeastP(productId);
//现货最高求购价
Map<Integer, BidStoragePrice> bidStoragePriceMap = this.selectInStockLeastP(productId);
List<BidStoragePriceResp> resp = Lists.newArrayList();
storageList.stream().forEach(item -> {
storageIds.stream().forEach(storageId -> {
BidStoragePriceResp bidStoragePriceResp = new BidStoragePriceResp();
bidStoragePriceResp.setStorageId(item.getId());
bidStoragePriceResp.setLeastPrice(priceMap.get(item.getId()));
bidStoragePriceResp.setBidHighestPrice(bidPriceMap.get(item.getId()));
bidStoragePriceResp.setStorageId(storageId);
StoragePrice storagePrice = storagePriceMap.get(storageId);
if (storagePrice != null) {
bidStoragePriceResp.setLeastPrice(storagePrice.getPrice());
}
BidStoragePrice bidStoragePrice = bidStoragePriceMap.get(storageId);
if (bidStoragePrice != null) {
bidStoragePriceResp.setBidHighestPrice(bidStoragePrice.getPrice());
}
resp.add(bidStoragePriceResp);
});
return resp;
... ...
... ... @@ -66,7 +66,7 @@ public class StoragePriceService {
* @param productId
* @return
*/
private Map<Integer, StoragePrice> selectInStockLeastP(@Param("productId") Integer productId) {
public Map<Integer, StoragePrice> selectInStockLeastP(@Param("productId") Integer productId) {
return selectInStockLeastPCache(productId).stream().collect(Collectors.toMap(StoragePrice::getStorageId, Function.identity()));
}
... ...