Authored by Lixiaodi

清除缓存

@@ -4,6 +4,8 @@ import java.lang.reflect.InvocationTargetException; @@ -4,6 +4,8 @@ import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method; 4 import java.lang.reflect.Method;
5 import java.util.HashMap; 5 import java.util.HashMap;
6 import java.util.Map; 6 import java.util.Map;
  7 +import java.util.concurrent.ExecutorService;
  8 +import java.util.concurrent.Executors;
7 9
8 import org.apache.commons.collections.MapUtils; 10 import org.apache.commons.collections.MapUtils;
9 import org.apache.commons.lang3.StringUtils; 11 import org.apache.commons.lang3.StringUtils;
@@ -23,6 +25,8 @@ public class UfoServiceCaller implements ApplicationListener<ContextRefreshedEve @@ -23,6 +25,8 @@ public class UfoServiceCaller implements ApplicationListener<ContextRefreshedEve
23 25
24 private final static Logger logger = LoggerFactory.getLogger(UfoServiceCaller.class); 26 private final static Logger logger = LoggerFactory.getLogger(UfoServiceCaller.class);
25 27
  28 + private ExecutorService executors = Executors.newFixedThreadPool(1);
  29 +
26 private static class ServiceMethod { 30 private static class ServiceMethod {
27 31
28 Object bean; 32 Object bean;
@@ -63,6 +67,21 @@ public class UfoServiceCaller implements ApplicationListener<ContextRefreshedEve @@ -63,6 +67,21 @@ public class UfoServiceCaller implements ApplicationListener<ContextRefreshedEve
63 } 67 }
64 } 68 }
65 69
  70 + public <T> void asyncCall(String serviceMethod, Class<T> responseType, Object... param) {
  71 + logger.info("asyncCall ufo service : {}", serviceMethod);
  72 + ServiceMethod sm = serviceMap.get(serviceMethod);
  73 + if (sm == null) {
  74 + throw new ServiceNotFoundException("Not found service " + serviceMethod, serviceMethod);
  75 + }
  76 + executors.execute(() -> {
  77 + try {
  78 + sm.call(param);
  79 + } catch (Exception e) {
  80 + logger.error("service error : " + serviceMethod, e);
  81 + }
  82 + });
  83 + }
  84 +
66 @SuppressWarnings("unchecked") 85 @SuppressWarnings("unchecked")
67 public <T> T call(String serviceMethod, Object... param) { 86 public <T> T call(String serviceMethod, Object... param) {
68 logger.info("call ufo service : {}", serviceMethod); 87 logger.info("call ufo service : {}", serviceMethod);
@@ -132,6 +132,14 @@ public class DepositController { @@ -132,6 +132,14 @@ public class DepositController {
132 return new ApiResponse(200, "缓存清除成功!", Boolean.TRUE); 132 return new ApiResponse(200, "缓存清除成功!", Boolean.TRUE);
133 } 133 }
134 134
  135 + @RequestMapping(params = "method=ufo.deposit.innerClearUserDeposit")
  136 + @IgnoreSignature
  137 + @IgnoreSession
  138 + public ApiResponse innerClearUserDeposit(Integer uid, Integer productId, Integer storageId) {
  139 + depositService.clearCache(uid, productId, storageId);
  140 + return new ApiResponse(200, "缓存清除成功!", Boolean.TRUE);
  141 + }
  142 +
135 @RequestMapping(params = "method=ufo.deposit.clearUserDeposit") 143 @RequestMapping(params = "method=ufo.deposit.clearUserDeposit")
136 @IgnoreSignature 144 @IgnoreSignature
137 @IgnoreSession 145 @IgnoreSession
@@ -19,6 +19,7 @@ import com.yohoufo.common.annotation.IgnoreSession; @@ -19,6 +19,7 @@ import com.yohoufo.common.annotation.IgnoreSession;
19 import com.yohoufo.common.annotation.IgnoreSignature; 19 import com.yohoufo.common.annotation.IgnoreSignature;
20 import com.yohoufo.common.cache.Cachable; 20 import com.yohoufo.common.cache.Cachable;
21 import com.yohoufo.common.cache.ControllerCacheAop; 21 import com.yohoufo.common.cache.ControllerCacheAop;
  22 +import com.yohoufo.common.caller.UfoServiceCaller;
22 import com.yohoufo.dal.product.model.StoragePrice; 23 import com.yohoufo.dal.product.model.StoragePrice;
23 import com.yohoufo.product.model.SkupInfo; 24 import com.yohoufo.product.model.SkupInfo;
24 import com.yohoufo.product.response.*; 25 import com.yohoufo.product.response.*;
@@ -38,6 +39,7 @@ import org.springframework.web.servlet.ModelAndView; @@ -38,6 +39,7 @@ import org.springframework.web.servlet.ModelAndView;
38 import java.lang.reflect.Method; 39 import java.lang.reflect.Method;
39 import java.math.BigDecimal; 40 import java.math.BigDecimal;
40 import java.util.Collection; 41 import java.util.Collection;
  42 +import java.util.HashMap;
41 import java.util.List; 43 import java.util.List;
42 import java.util.Map; 44 import java.util.Map;
43 import java.util.concurrent.ExecutorService; 45 import java.util.concurrent.ExecutorService;
@@ -58,6 +60,9 @@ public class ProductController { @@ -58,6 +60,9 @@ public class ProductController {
58 private ProductBatchService productBatchService; 60 private ProductBatchService productBatchService;
59 61
60 @Autowired 62 @Autowired
  63 + private UfoServiceCaller ufoServiceCaller;
  64 +
  65 + @Autowired
61 private ConfigReader configReader; 66 private ConfigReader configReader;
62 67
63 private static final String LIMIT_PRODUCT_TIP = "很抱歉通知您,您现在还不具备销售此商品的资质。我们需要您提供完整的商品来源凭证,诸如购买单据、发票等,确保您的货源稳定可靠,请将以上资料、联系手机等相关信息通过邮箱发送至luyan.qian@yoho.cn,我们的工作人员审核通过后会联系您并为您添加出售资质权限,谢谢!"; 68 private static final String LIMIT_PRODUCT_TIP = "很抱歉通知您,您现在还不具备销售此商品的资质。我们需要您提供完整的商品来源凭证,诸如购买单据、发票等,确保您的货源稳定可靠,请将以上资料、联系手机等相关信息通过邮箱发送至luyan.qian@yoho.cn,我们的工作人员审核通过后会联系您并为您添加出售资质权限,谢谢!";
@@ -534,8 +539,8 @@ public class ProductController { @@ -534,8 +539,8 @@ public class ProductController {
534 try { 539 try {
535 LOG.info("in clearBatchProductCache skupList = {}", skupList); 540 LOG.info("in clearBatchProductCache skupList = {}", skupList);
536 List<StoragePrice> spList = productService.getStoragePriceBySkupList(skupList); 541 List<StoragePrice> spList = productService.getStoragePriceBySkupList(skupList);
537 - List<Integer> productIdList = spList.stream().map(StoragePrice::getProductId).collect(Collectors.toList());  
538 - List<Integer> storageIdList = spList.stream().map(StoragePrice::getStorageId).collect(Collectors.toList()); 542 + List<Integer> productIdList = spList.stream().map(StoragePrice::getProductId).distinct().collect(Collectors.toList());
  543 + List<Integer> storageIdList = spList.stream().map(StoragePrice::getStorageId).distinct().collect(Collectors.toList());
539 if (CollectionUtils.isNotEmpty(productIdList)) { 544 if (CollectionUtils.isNotEmpty(productIdList)) {
540 for (Integer productId : productIdList) { 545 for (Integer productId : productIdList) {
541 LOG.info("Batch clearCache queryProductDetailById productId = {}, ", productId); 546 LOG.info("Batch clearCache queryProductDetailById productId = {}, ", productId);
@@ -574,8 +579,16 @@ public class ProductController { @@ -574,8 +579,16 @@ public class ProductController {
574 cacheAop.clearCache( 579 cacheAop.clearCache(
575 ProductController.class.getMethod("queryStorageSuggestPrice", new Class[]{Collection.class}), 580 ProductController.class.getMethod("queryStorageSuggestPrice", new Class[]{Collection.class}),
576 new Object[]{storageId}); 581 new Object[]{storageId});
  582 + cacheAop.clearCache(
  583 + ProductController.class.getMethod("querySecondHandProductListCount", new Class[]{Integer.class}),
  584 + new Object[]{storageId});
  585 + LOG.info("clearCache querySecondHandProductListFilter skup = {}, ", storageId);
  586 + cacheAop.clearCache(
  587 + ProductController.class.getMethod("querySecondHandProductListFilter", new Class[]{Integer.class}),
  588 + new Object[]{storageId});
577 } 589 }
578 } 590 }
  591 + Map<String, StoragePrice> distinctStorage = new HashMap<>();
579 for(StoragePrice sp : spList) { 592 for(StoragePrice sp : spList) {
580 Integer skup = sp.getSkup(); 593 Integer skup = sp.getSkup();
581 Integer storageId = sp.getStorageId(); 594 Integer storageId = sp.getStorageId();
@@ -584,15 +597,13 @@ public class ProductController { @@ -584,15 +597,13 @@ public class ProductController {
584 cacheAop.clearCache( 597 cacheAop.clearCache(
585 ProductController.class.getMethod("querySecondHandProductData", new Class[]{Integer.class}), 598 ProductController.class.getMethod("querySecondHandProductData", new Class[]{Integer.class}),
586 new Object[]{skup}); 599 new Object[]{skup});
587 - LOG.info("clearCache querySecondHandProductListCount skup = {}, ", skup);  
588 - cacheAop.clearCache(  
589 - ProductController.class.getMethod("querySecondHandProductListCount", new Class[]{Integer.class}),  
590 - new Object[]{storageId});  
591 - LOG.info("clearCache querySecondHandProductListFilter skup = {}, ", skup);  
592 - cacheAop.clearCache(  
593 - ProductController.class.getMethod("querySecondHandProductListFilter", new Class[]{Integer.class}),  
594 - new Object[]{storageId});  
595 } 600 }
  601 + if (sp.getPreSaleFlag() != null && (sp.getPreSaleFlag() == 3)) {
  602 + distinctStorage.put(sp.getSellerUid() + "_" + sp.getProductId() + "_" + sp.getStorageId(), sp);
  603 + }
  604 + }
  605 + for (StoragePrice sp : distinctStorage.values()) {
  606 + ufoServiceCaller.asyncCall("ufo.deposit.innerClearUserDeposit", ApiResponse.class, sp.getSellerUid(), sp.getProductId(), sp.getStorageId());
596 } 607 }
597 } catch (Exception e) { 608 } catch (Exception e) {
598 LOG.error("删除商品缓存失败!", e); 609 LOG.error("删除商品缓存失败!", e);