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; @@ -8,8 +8,6 @@ import com.yoho.tools.docs.ApiOperation;
8 import com.yoho.tools.docs.ApiParam; 8 import com.yoho.tools.docs.ApiParam;
9 import com.yoho.tools.docs.ApiResp; 9 import com.yoho.tools.docs.ApiResp;
10 import com.yoho.tools.docs.ApiRespCode; 10 import com.yoho.tools.docs.ApiRespCode;
11 -import com.yohobuy.ufo.model.GoodsBO;  
12 -import com.yohobuy.ufo.model.GoodsSize;  
13 import com.yohobuy.ufo.model.ProductInfo; 11 import com.yohobuy.ufo.model.ProductInfo;
14 import com.yohobuy.ufo.model.request.SeekToBuyStorageBo; 12 import com.yohobuy.ufo.model.request.SeekToBuyStorageBo;
15 import com.yohobuy.ufo.model.request.StoragePriceBo; 13 import com.yohobuy.ufo.model.request.StoragePriceBo;
@@ -21,16 +19,12 @@ import com.yohobuy.ufo.model.response.StorageInfoResp; @@ -21,16 +19,12 @@ import com.yohobuy.ufo.model.response.StorageInfoResp;
21 import com.yohobuy.ufo.model.response.StorageCheckResp; 19 import com.yohobuy.ufo.model.response.StorageCheckResp;
22 20
23 import com.yohoufo.common.ApiResponse; 21 import com.yohoufo.common.ApiResponse;
24 -import com.yohoufo.common.alarm.EventBusPublisher;  
25 import com.yohoufo.common.annotation.IgnoreSession; 22 import com.yohoufo.common.annotation.IgnoreSession;
26 import com.yohoufo.common.annotation.IgnoreSignature; 23 import com.yohoufo.common.annotation.IgnoreSignature;
27 import com.yohoufo.common.cache.Cachable; 24 import com.yohoufo.common.cache.Cachable;
28 import com.yohoufo.common.cache.ControllerCacheAop; 25 import com.yohoufo.common.cache.ControllerCacheAop;
29 import com.yohoufo.common.caller.UfoServiceCaller; 26 import com.yohoufo.common.caller.UfoServiceCaller;
30 -import com.yohoufo.common.utils.StringUtil;  
31 -import com.yohoufo.dal.product.model.Goods;  
32 import com.yohoufo.dal.product.model.StoragePrice; 27 import com.yohoufo.dal.product.model.StoragePrice;
33 -import com.yohoufo.product.event.StoragePriceUpdateEvent;  
34 import com.yohoufo.product.model.SkupInfo; 28 import com.yohoufo.product.model.SkupInfo;
35 import com.yohoufo.product.response.*; 29 import com.yohoufo.product.response.*;
36 import com.yohoufo.product.service.ProductService; 30 import com.yohoufo.product.service.ProductService;
@@ -38,12 +32,10 @@ import com.yohoufo.product.service.impl.ProductBatchService; @@ -38,12 +32,10 @@ import com.yohoufo.product.service.impl.ProductBatchService;
38 import com.yohoufo.product.service.impl.ProductPoolService; 32 import com.yohoufo.product.service.impl.ProductPoolService;
39 import com.yohoufo.product.service.impl.SeekToBuyStorageService; 33 import com.yohoufo.product.service.impl.SeekToBuyStorageService;
40 import com.yohoufo.product.service.impl.StoragePriceService; 34 import com.yohoufo.product.service.impl.StoragePriceService;
41 -import com.yohoufo.product.util.ThreadPoolFactory;  
42 import org.apache.commons.collections.CollectionUtils; 35 import org.apache.commons.collections.CollectionUtils;
43 import org.apache.commons.lang3.StringUtils; 36 import org.apache.commons.lang3.StringUtils;
44 import org.slf4j.Logger; 37 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory; 38 import org.slf4j.LoggerFactory;
46 -import org.springframework.beans.BeanUtils;  
47 import org.springframework.beans.factory.annotation.Autowired; 39 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.web.bind.annotation.RequestBody; 40 import org.springframework.web.bind.annotation.RequestBody;
49 import org.springframework.web.bind.annotation.RequestMapping; 41 import org.springframework.web.bind.annotation.RequestMapping;
@@ -54,9 +46,6 @@ import org.springframework.web.servlet.ModelAndView; @@ -54,9 +46,6 @@ import org.springframework.web.servlet.ModelAndView;
54 import java.lang.reflect.Method; 46 import java.lang.reflect.Method;
55 import java.math.BigDecimal; 47 import java.math.BigDecimal;
56 import java.util.*; 48 import java.util.*;
57 -import java.util.concurrent.ExecutorService;  
58 -import java.util.concurrent.Executors;  
59 -import java.util.function.Predicate;  
60 import java.util.stream.Collectors; 49 import java.util.stream.Collectors;
61 50
62 @RestController 51 @RestController
@@ -392,7 +381,7 @@ public class ProductController { @@ -392,7 +381,7 @@ public class ProductController {
392 productService.sellerBatchUpdateStatus(skupList, dbStatus); 381 productService.sellerBatchUpdateStatus(skupList, dbStatus);
393 //清缓存 382 //清缓存
394 LOG.info("sellerUpdateStatus success and async clearProductCache skupList = {}", skupList); 383 LOG.info("sellerUpdateStatus success and async clearProductCache skupList = {}", skupList);
395 - ThreadPoolFactory.cacheCleanExecutorService().submit(()->clearBatchProductCache(skupList)); 384 + clearBatchProductCache(skupList);
396 return new ApiResponse(200, "更新成功!", Boolean.TRUE); 385 return new ApiResponse(200, "更新成功!", Boolean.TRUE);
397 } catch (Exception e) { 386 } catch (Exception e) {
398 LOG.error("sellerBatchUpdateStatus失败!", e); 387 LOG.error("sellerBatchUpdateStatus失败!", e);
@@ -608,27 +597,27 @@ public class ProductController { @@ -608,27 +597,27 @@ public class ProductController {
608 if (CollectionUtils.isNotEmpty(productIdList)) { 597 if (CollectionUtils.isNotEmpty(productIdList)) {
609 for (Integer productId : productIdList) { 598 for (Integer productId : productIdList) {
610 LOG.info("Batch clearCache queryProductDetailById productId = {}, ", productId); 599 LOG.info("Batch clearCache queryProductDetailById productId = {}, ", productId);
611 -  
612 - storagePriceService.publishPriceUpdateEventIf(productId, oldSkupList -> {  
613 - // 缓存不存在,需要更新  
614 - if (CollectionUtils.isEmpty(oldSkupList)) {  
615 - return true;  
616 - }  
617 - // 比最低价要低,需要更新  
618 - Predicate<StoragePrice> pricePredicate = newPrice -> oldSkupList.stream()  
619 - .filter(oldPrice -> Objects.equals(newPrice.getStorageId(), oldPrice.getStorageId()))  
620 - .anyMatch(oldPrice -> newPrice.getPrice().compareTo(oldPrice.getPrice()) < 0);  
621 - if(storagePriceList.stream().anyMatch(pricePredicate)){  
622 - return true;  
623 - }  
624 - // 如果当前skup为缓存中商品,需要更新  
625 - Predicate<StoragePrice> sameSkupPredicate = newSkup -> oldSkupList.stream()  
626 - .anyMatch(oldSkup -> Objects.equals(newSkup.getSkup(), oldSkup.getSkup()));  
627 - if(storagePriceList.stream().anyMatch(sameSkupPredicate)){  
628 - return true;  
629 - }  
630 - return false;  
631 - }); 600 + storagePriceService.publishPriceUpdateEventWithDeleteCache(productId);
  601 +// storagePriceService.publishPriceUpdateEventIf(productId, oldSkupList -> {
  602 +// // 缓存不存在,需要更新
  603 +// if (CollectionUtils.isEmpty(oldSkupList)) {
  604 +// return true;
  605 +// }
  606 +// // 比最低价要低,需要更新
  607 +// Predicate<StoragePrice> pricePredicate = newPrice -> oldSkupList.stream()
  608 +// .filter(oldPrice -> Objects.equals(newPrice.getStorageId(), oldPrice.getStorageId()))
  609 +// .anyMatch(oldPrice -> newPrice.getPrice().compareTo(oldPrice.getPrice()) < 0);
  610 +// if(storagePriceList.stream().anyMatch(pricePredicate)){
  611 +// return true;
  612 +// }
  613 +// // 如果当前skup为缓存中商品,需要更新
  614 +// Predicate<StoragePrice> sameSkupPredicate = newSkup -> oldSkupList.stream()
  615 +// .anyMatch(oldSkup -> Objects.equals(newSkup.getSkup(), oldSkup.getSkup()));
  616 +// if(storagePriceList.stream().anyMatch(sameSkupPredicate)){
  617 +// return true;
  618 +// }
  619 +// return false;
  620 +// });
632 621
633 //商品详情 622 //商品详情
634 cacheAop.clearCache( 623 cacheAop.clearCache(
@@ -115,4 +115,14 @@ public class StoragePriceService { @@ -115,4 +115,14 @@ public class StoragePriceService {
115 public List<StoragePrice> selectLeastPricesByProductId(Integer productId) { 115 public List<StoragePrice> selectLeastPricesByProductId(Integer productId) {
116 return storagePriceMapper.selectLeastPricesByProductId(productId); 116 return storagePriceMapper.selectLeastPricesByProductId(productId);
117 } 117 }
  118 +
  119 + public void publishPriceUpdateEventWithDeleteCache(Integer productId) {
  120 + LOGGER.info("method com.yohoufo.product.service.impl.StoragePriceService.publishPriceUpdateEvent in productId is 【{}】", productId);
  121 + StoragePriceUpdateEvent storagePriceUpdateEvent = new StoragePriceUpdateEvent(event->{
  122 + productCacheService.deleteCacheByString(UfoProductCacheKeyEnum.STORAGE_PRICE_IN_STOCK_INFO_KEY, productId.toString());
  123 + return true;
  124 + });
  125 + storagePriceUpdateEvent.setProductId(productId);
  126 + EventBusPublisher.publishEvent(storagePriceUpdateEvent);
  127 + }
118 } 128 }