|
|
package com.yohoufo.product.service.impl;
|
|
|
|
|
|
import com.yohobuy.ufo.model.GoodsSize;
|
|
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
|
|
import com.yohoufo.dal.product.StoragePriceMapper;
|
|
|
import com.yohoufo.dal.product.model.StoragePrice;
|
|
|
import com.yohoufo.product.cache.UfoProductCacheKeyEnum;
|
|
|
import com.yohoufo.product.cache.UfoProductCacheService;
|
|
|
import com.yohoufo.product.event.StoragePriceUpdateEvent;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
...
|
...
|
@@ -20,6 +25,8 @@ import java.util.stream.Collectors; |
|
|
*/
|
|
|
@Service
|
|
|
public class StoragePriceService {
|
|
|
private final static Logger LOGGER = LoggerFactory.getLogger(StoragePriceService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private StoragePriceMapper storagePriceMapper;
|
|
|
|
...
|
...
|
@@ -31,13 +38,36 @@ public class StoragePriceService { |
|
|
}
|
|
|
|
|
|
|
|
|
private List<StoragePrice> selectInStockLeastPCache(Integer productId) {
|
|
|
List<StoragePrice> sizePriceCacheList = productCacheService.getListCacheByString(UfoProductCacheKeyEnum.STORAGE_PRICE_IN_STOCK_INFO_KEY, StoragePrice.class, productId);
|
|
|
if (CollectionUtils.isNotEmpty(sizePriceCacheList)) {
|
|
|
LOGGER.info("sizePriceCacheList is cache hit, productId is {}", productId);
|
|
|
return sizePriceCacheList;
|
|
|
}
|
|
|
|
|
|
sizePriceCacheList = setStoragePriceCache(productId);
|
|
|
|
|
|
return sizePriceCacheList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 重新设置缓存
|
|
|
* @param productId
|
|
|
* @return
|
|
|
*/
|
|
|
public List<StoragePrice> setStoragePriceCache(Integer productId) {
|
|
|
List<StoragePrice> sizePriceCacheList = storagePriceMapper.selectInStockLeastPByProductId(productId);
|
|
|
productCacheService.setCacheByString(UfoProductCacheKeyEnum.STORAGE_PRICE_IN_STOCK_INFO_KEY, sizePriceCacheList, productId);
|
|
|
return sizePriceCacheList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询现货各尺码的最低价
|
|
|
* @param productId
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<Integer, StoragePrice> selectInStockLeastPByProductId(@Param("productId") Integer productId) {
|
|
|
return storagePriceMapper.selectInStockLeastPByProductId(productId).stream().collect(Collectors.toMap(StoragePrice::getStorageId, Function.identity()));
|
|
|
private Map<Integer, StoragePrice> selectInStockLeastP(@Param("productId") Integer productId) {
|
|
|
return selectInStockLeastPCache(productId).stream().collect(Collectors.toMap(StoragePrice::getStorageId, Function.identity()));
|
|
|
}
|
|
|
|
|
|
public void setStoragePrice(List<GoodsSize> goodsSizes, Integer productId) {
|
...
|
...
|
@@ -45,8 +75,7 @@ public class StoragePriceService { |
|
|
return;
|
|
|
}
|
|
|
|
|
|
Map<Integer, StoragePrice> storagePriceMap = selectInStockLeastPByProductId(productId);
|
|
|
|
|
|
Map<Integer, StoragePrice> storagePriceMap = selectInStockLeastP(productId);
|
|
|
goodsSizes.stream().forEach(item -> {
|
|
|
StoragePrice storagePrice = storagePriceMap.get(item.getId());//大陆现货
|
|
|
if (null != storagePrice && null != item.getSuggestHighPrice()
|
...
|
...
|
@@ -61,4 +90,18 @@ public class StoragePriceService { |
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
public boolean reSetStoragePriceCache(StoragePriceUpdateEvent storagePriceUpdateEvent) {
|
|
|
Integer productId = storagePriceUpdateEvent.getProductId();
|
|
|
setStoragePriceCache(productId);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public void publishPriceUpdateEvent(Integer productId) {
|
|
|
LOGGER.info("method com.yohoufo.product.service.impl.StoragePriceService.publishPriceUpdateEvent in productId is 【{}】", productId);
|
|
|
|
|
|
StoragePriceUpdateEvent storagePriceUpdateEvent = new StoragePriceUpdateEvent(this::reSetStoragePriceCache);
|
|
|
storagePriceUpdateEvent.setProductId(productId);
|
|
|
EventBusPublisher.publishEvent(storagePriceUpdateEvent);
|
|
|
}
|
|
|
} |
...
|
...
|
|