Authored by mali

Merge branch 'test6.9.8' into gray

... ... @@ -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;
... ... @@ -22,6 +24,8 @@ import com.yoho.core.rest.exception.ServiceNotFoundException;
public class UfoServiceCaller implements ApplicationListener<ContextRefreshedEvent> {
private final static Logger logger = LoggerFactory.getLogger(UfoServiceCaller.class);
private ExecutorService executors = Executors.newFixedThreadPool(1);
private static class ServiceMethod {
... ... @@ -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;
... ... @@ -56,6 +58,9 @@ public class ProductController {
@Autowired
private ProductBatchService productBatchService;
@Autowired
private UfoServiceCaller ufoServiceCaller;
@Autowired
private ConfigReader configReader;
... ... @@ -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);
... ...