Authored by Lixiaodi

清除缓存

... ... @@ -4,6 +4,8 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -23,6 +25,8 @@ public class UfoServiceCaller implements ApplicationListener<ContextRefreshedEve
private final static Logger logger = LoggerFactory.getLogger(UfoServiceCaller.class);
private ExecutorService executors = Executors.newFixedThreadPool(1);
private static class ServiceMethod {
Object bean;
... ... @@ -63,6 +67,21 @@ public class UfoServiceCaller implements ApplicationListener<ContextRefreshedEve
}
}
public <T> void asyncCall(String serviceMethod, Class<T> responseType, Object... param) {
logger.info("asyncCall ufo service : {}", serviceMethod);
ServiceMethod sm = serviceMap.get(serviceMethod);
if (sm == null) {
throw new ServiceNotFoundException("Not found service " + serviceMethod, serviceMethod);
}
executors.execute(() -> {
try {
sm.call(param);
} catch (Exception e) {
logger.error("service error : " + serviceMethod, e);
}
});
}
@SuppressWarnings("unchecked")
public <T> T call(String serviceMethod, Object... param) {
logger.info("call ufo service : {}", serviceMethod);
... ...
... ... @@ -132,6 +132,14 @@ public class DepositController {
return new ApiResponse(200, "缓存清除成功!", Boolean.TRUE);
}
@RequestMapping(params = "method=ufo.deposit.innerClearUserDeposit")
@IgnoreSignature
@IgnoreSession
public ApiResponse innerClearUserDeposit(Integer uid, Integer productId, Integer storageId) {
depositService.clearCache(uid, productId, storageId);
return new ApiResponse(200, "缓存清除成功!", Boolean.TRUE);
}
@RequestMapping(params = "method=ufo.deposit.clearUserDeposit")
@IgnoreSignature
@IgnoreSession
... ...
... ... @@ -19,6 +19,7 @@ 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.dal.product.model.StoragePrice;
import com.yohoufo.product.model.SkupInfo;
import com.yohoufo.product.response.*;
... ... @@ -38,6 +39,7 @@ import org.springframework.web.servlet.ModelAndView;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
... ... @@ -58,6 +60,9 @@ public class ProductController {
private ProductBatchService productBatchService;
@Autowired
private UfoServiceCaller ufoServiceCaller;
@Autowired
private ConfigReader configReader;
private static final String LIMIT_PRODUCT_TIP = "很抱歉通知您,您现在还不具备销售此商品的资质。我们需要您提供完整的商品来源凭证,诸如购买单据、发票等,确保您的货源稳定可靠,请将以上资料、联系手机等相关信息通过邮箱发送至luyan.qian@yoho.cn,我们的工作人员审核通过后会联系您并为您添加出售资质权限,谢谢!";
... ... @@ -534,8 +539,8 @@ public class ProductController {
try {
LOG.info("in clearBatchProductCache skupList = {}", skupList);
List<StoragePrice> spList = productService.getStoragePriceBySkupList(skupList);
List<Integer> productIdList = spList.stream().map(StoragePrice::getProductId).collect(Collectors.toList());
List<Integer> storageIdList = spList.stream().map(StoragePrice::getStorageId).collect(Collectors.toList());
List<Integer> productIdList = spList.stream().map(StoragePrice::getProductId).distinct().collect(Collectors.toList());
List<Integer> storageIdList = spList.stream().map(StoragePrice::getStorageId).distinct().collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(productIdList)) {
for (Integer productId : productIdList) {
LOG.info("Batch clearCache queryProductDetailById productId = {}, ", productId);
... ... @@ -574,8 +579,16 @@ public class ProductController {
cacheAop.clearCache(
ProductController.class.getMethod("queryStorageSuggestPrice", new Class[]{Collection.class}),
new Object[]{storageId});
cacheAop.clearCache(
ProductController.class.getMethod("querySecondHandProductListCount", new Class[]{Integer.class}),
new Object[]{storageId});
LOG.info("clearCache querySecondHandProductListFilter skup = {}, ", storageId);
cacheAop.clearCache(
ProductController.class.getMethod("querySecondHandProductListFilter", new Class[]{Integer.class}),
new Object[]{storageId});
}
}
Map<String, StoragePrice> distinctStorage = new HashMap<>();
for(StoragePrice sp : spList) {
Integer skup = sp.getSkup();
Integer storageId = sp.getStorageId();
... ... @@ -584,15 +597,13 @@ public class ProductController {
cacheAop.clearCache(
ProductController.class.getMethod("querySecondHandProductData", new Class[]{Integer.class}),
new Object[]{skup});
LOG.info("clearCache querySecondHandProductListCount skup = {}, ", skup);
cacheAop.clearCache(
ProductController.class.getMethod("querySecondHandProductListCount", new Class[]{Integer.class}),
new Object[]{storageId});
LOG.info("clearCache querySecondHandProductListFilter skup = {}, ", skup);
cacheAop.clearCache(
ProductController.class.getMethod("querySecondHandProductListFilter", new Class[]{Integer.class}),
new Object[]{storageId});
}
if (sp.getPreSaleFlag() != null && (sp.getPreSaleFlag() == 3)) {
distinctStorage.put(sp.getSellerUid() + "_" + sp.getProductId() + "_" + sp.getStorageId(), sp);
}
}
for (StoragePrice sp : distinctStorage.values()) {
ufoServiceCaller.asyncCall("ufo.deposit.innerClearUserDeposit", ApiResponse.class, sp.getSellerUid(), sp.getProductId(), sp.getStorageId());
}
} catch (Exception e) {
LOG.error("删除商品缓存失败!", e);
... ...