Authored by LUOXC

Merge branch 'pt' into test6.9.14

# Conflicts:
#	product/src/main/java/com/yohoufo/product/service/impl/StoragePriceService.java
... ... @@ -8,8 +8,6 @@ import com.yoho.tools.docs.ApiOperation;
import com.yoho.tools.docs.ApiParam;
import com.yoho.tools.docs.ApiResp;
import com.yoho.tools.docs.ApiRespCode;
import com.yohobuy.ufo.model.GoodsBO;
import com.yohobuy.ufo.model.GoodsSize;
import com.yohobuy.ufo.model.ProductInfo;
import com.yohobuy.ufo.model.request.SeekToBuyStorageBo;
import com.yohobuy.ufo.model.request.StoragePriceBo;
... ... @@ -21,16 +19,12 @@ import com.yohobuy.ufo.model.response.StorageInfoResp;
import com.yohobuy.ufo.model.response.StorageCheckResp;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.cache.Cachable;
import com.yohoufo.common.cache.ControllerCacheAop;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.utils.StringUtil;
import com.yohoufo.dal.product.model.Goods;
import com.yohoufo.dal.product.model.StoragePrice;
import com.yohoufo.product.event.StoragePriceUpdateEvent;
import com.yohoufo.product.model.SkupInfo;
import com.yohoufo.product.response.*;
import com.yohoufo.product.service.ProductService;
... ... @@ -38,12 +32,10 @@ import com.yohoufo.product.service.impl.ProductBatchService;
import com.yohoufo.product.service.impl.ProductPoolService;
import com.yohoufo.product.service.impl.SeekToBuyStorageService;
import com.yohoufo.product.service.impl.StoragePriceService;
import com.yohoufo.product.util.ThreadPoolFactory;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
... ... @@ -54,9 +46,6 @@ import org.springframework.web.servlet.ModelAndView;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@RestController
... ... @@ -392,7 +381,7 @@ public class ProductController {
productService.sellerBatchUpdateStatus(skupList, dbStatus);
//清缓存
LOG.info("sellerUpdateStatus success and async clearProductCache skupList = {}", skupList);
ThreadPoolFactory.cacheCleanExecutorService().submit(()->clearBatchProductCache(skupList));
clearBatchProductCache(skupList);
return new ApiResponse(200, "更新成功!", Boolean.TRUE);
} catch (Exception e) {
LOG.error("sellerBatchUpdateStatus失败!", e);
... ... @@ -608,27 +597,27 @@ public class ProductController {
if (CollectionUtils.isNotEmpty(productIdList)) {
for (Integer productId : productIdList) {
LOG.info("Batch clearCache queryProductDetailById productId = {}, ", productId);
storagePriceService.publishPriceUpdateEventIf(productId, oldSkupList -> {
// 缓存不存在,需要更新
if (CollectionUtils.isEmpty(oldSkupList)) {
return true;
}
// 比最低价要低,需要更新
Predicate<StoragePrice> pricePredicate = newPrice -> oldSkupList.stream()
.filter(oldPrice -> Objects.equals(newPrice.getStorageId(), oldPrice.getStorageId()))
.anyMatch(oldPrice -> newPrice.getPrice().compareTo(oldPrice.getPrice()) < 0);
if(storagePriceList.stream().anyMatch(pricePredicate)){
return true;
}
// 如果当前skup为缓存中商品,需要更新
Predicate<StoragePrice> sameSkupPredicate = newSkup -> oldSkupList.stream()
.anyMatch(oldSkup -> Objects.equals(newSkup.getSkup(), oldSkup.getSkup()));
if(storagePriceList.stream().anyMatch(sameSkupPredicate)){
return true;
}
return false;
});
storagePriceService.publishPriceUpdateEventWithDeleteCache(productId);
// storagePriceService.publishPriceUpdateEventIf(productId, oldSkupList -> {
// // 缓存不存在,需要更新
// if (CollectionUtils.isEmpty(oldSkupList)) {
// return true;
// }
// // 比最低价要低,需要更新
// Predicate<StoragePrice> pricePredicate = newPrice -> oldSkupList.stream()
// .filter(oldPrice -> Objects.equals(newPrice.getStorageId(), oldPrice.getStorageId()))
// .anyMatch(oldPrice -> newPrice.getPrice().compareTo(oldPrice.getPrice()) < 0);
// if(storagePriceList.stream().anyMatch(pricePredicate)){
// return true;
// }
// // 如果当前skup为缓存中商品,需要更新
// Predicate<StoragePrice> sameSkupPredicate = newSkup -> oldSkupList.stream()
// .anyMatch(oldSkup -> Objects.equals(newSkup.getSkup(), oldSkup.getSkup()));
// if(storagePriceList.stream().anyMatch(sameSkupPredicate)){
// return true;
// }
// return false;
// });
//商品详情
cacheAop.clearCache(
... ...
... ... @@ -115,4 +115,14 @@ public class StoragePriceService {
public List<StoragePrice> selectLeastPricesByProductId(Integer productId) {
return storagePriceMapper.selectLeastPricesByProductId(productId);
}
public void publishPriceUpdateEventWithDeleteCache(Integer productId) {
LOGGER.info("method com.yohoufo.product.service.impl.StoragePriceService.publishPriceUpdateEvent in productId is 【{}】", productId);
StoragePriceUpdateEvent storagePriceUpdateEvent = new StoragePriceUpdateEvent(event->{
productCacheService.deleteCacheByString(UfoProductCacheKeyEnum.STORAGE_PRICE_IN_STOCK_INFO_KEY, productId.toString());
return true;
});
storagePriceUpdateEvent.setProductId(productId);
EventBusPublisher.publishEvent(storagePriceUpdateEvent);
}
}
... ...