Commit ce0e0874 by 田超

Merge branch 'feature/1005780' into 'master'

feat: [1005780] book error

See merge request rays/pcloud-book!1440
parents f90e1cad 381be837
......@@ -4,10 +4,14 @@
package com.pcloud.book.consumer.resource;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.channelcenter.base.exceptions.ChannelBizException;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.utils.BeanUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.ResponseHandleUtil;
import com.pcloud.common.utils.ThreadUtil;
import com.pcloud.resourcecenter.product.dto.ProDto;
import com.pcloud.resourcecenter.product.dto.Product4BookDTO;
import com.pcloud.resourcecenter.product.dto.ProductDto;
......@@ -25,9 +29,12 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
/**
......@@ -94,18 +101,44 @@ public class ProductConsr {
if (productIds == null || productIds.isEmpty()) {
return null;
}
try {
return ResponseHandleUtil.parseMapResponse(productService.getProBasesByIds(productIds), Long.class,
Map<Long, ProductDto> productDtoMap = new HashMap<>();
productIds = productIds.stream().distinct().collect(Collectors.toList());
Integer size = productIds.size();
if (productIds.size() > 1000) {
Integer[] queryCountArray = {0, 1, 2, 3};
Integer queryCount = 4;
//并发查询
List<Long> finalProductIds = productIds;
Map<Long, ProductDto> finalProductDtoMap = productDtoMap;
CompletableFuture[] completableFutures = Arrays.stream(queryCountArray).
map(x -> CompletableFuture.supplyAsync(() -> {
Integer startIndex = size / queryCount * x;
Integer endIndex = size / queryCount * (x + 1);
List<Long> queryList = finalProductIds.subList(startIndex, endIndex);
Map<Long, ProductDto> productMap = ResponseHandleUtil.parseMapResponse(productService.getProBasesByIds(queryList), Long.class,
ProductDto.class);
return productMap;
}, ThreadPoolUtils.EXPORT_THREAD_POOL).whenComplete(((productMap, throwable) -> {
finalProductDtoMap.putAll(productMap);
}))).toArray(CompletableFuture[]::new);
try {
CompletableFuture.allOf(completableFutures).get();
} catch (InterruptedException | ExecutionException e) {
LOGGER.warn("[getProBasesByIds] 填充信息失败,err:{}", e.getMessage(), e);
}
return finalProductDtoMap;
} else {
try {
productDtoMap = ResponseHandleUtil.parseMapResponse(productService.getProBasesByIds(productIds), Long.class, ProductDto.class);
} catch (BizException e) {
LOGGER.warn("【资源中心(消)】获取商品基本信息失败:" + e.getMessage(), e);
throw new BizException(e.getCode(), e.getMessage());
} catch (Exception e) {
LOGGER.error("【资源中心(消)】获取商品基本信息.[getProBasesByIds]:" + e.getMessage(), e);
throw new BookBizException(BookBizException.INVOKE_RES_ERROR, "服务内部错误,请稍后重试");
LOGGER.warn("调用:productService.getProBasesByIds报错", e.getMessage(), e);
}
return productDtoMap;
}
}
/**
* 资源中心拉取商品基本信息
*/
......
......@@ -1120,7 +1120,7 @@ public class ResourcePageBizImpl implements ResourcePageBiz {
try {
productDtoMap = productMapSubmit.get(ThreadPoolUtils.REMOTE_TIME_OUT, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("调用资源中心获取商品信息错误:"+e.getMessage(), e);
log.warn("调用资源中心获取商品信息错误:"+e.getMessage(), e);
}
try {
appPriceMap = appPriceMapSubmit.get(ThreadPoolUtils.REMOTE_TIME_OUT, TimeUnit.SECONDS);
......
......@@ -12,7 +12,7 @@ public class ThreadPoolUtils {
/**
* 远程调用超时时间(单位:秒)
*/
public static final int REMOTE_TIME_OUT = 5;
public static final int REMOTE_TIME_OUT = 10;
/**
* 远程调用超时时间(单位:秒)
......@@ -90,5 +90,12 @@ public class ThreadPoolUtils {
public static final ThreadPoolExecutor UPDATE_SUPER_SEARCH_POOL = new ThreadPoolExecutor(8, 8, 0, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("update_super_search-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy());
/**
* 超级搜索更新线程
*/
public static final ThreadPoolExecutor FILL_SERVICE_POOL = new ThreadPoolExecutor(8, 8, 0, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("fill-service-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment