优化订单列表,多单号查询,支持几万单号查询

This commit is contained in:
luojiaquan
2026-10-16 09:22:13 +08:00
parent 0a7f639138
commit 02481b102c
10 changed files with 655 additions and 32 deletions
@@ -73,8 +73,16 @@ public class TabOrderSyncAsyncRunner
ExecutorService pool = newWorkerPool(threads, "order-source-sync");
try
{
long totalLong = tabOrderMonitorService.count(query);
int total = totalLong > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) totalLong;
// 大批量单号:先一次性分批收集全部匹配主键,之后按切片拉明细,避免每页重复全量扫描
List<com.bms.price.oracle.MatchedOrderKey> matchedKeys = null;
if (query != null && query.getOrderIdentifiers() != null && !query.getOrderIdentifiers().isEmpty())
{
matchedKeys = tabOrderMonitorService.collectMatchedOrderKeys(query);
}
final List<com.bms.price.oracle.MatchedOrderKey> keys = matchedKeys;
int total = keys != null
? keys.size()
: toIntExact(tabOrderMonitorService.count(query));
put(asyncTaskId, PrcBillingTaskRetryTask.STATUS_RUNNING, 0, "starting", total, 0, 0, 0, null);
if (total <= 0)
{
@@ -89,7 +97,21 @@ public class TabOrderSyncAsyncRunner
int pageNum = 1;
while (true)
{
List<TabOrderMonitorVo> rows = tabOrderMonitorService.selectPage(query, pageNum, batch);
List<TabOrderMonitorVo> rows;
if (keys != null)
{
int from = (pageNum - 1) * batch;
if (from >= keys.size())
{
break;
}
rows = tabOrderMonitorService.selectPageByKeys(
keys.subList(from, Math.min(from + batch, keys.size())));
}
else
{
rows = tabOrderMonitorService.selectPage(query, pageNum, batch);
}
if (rows == null || rows.isEmpty())
{
break;
@@ -403,6 +425,11 @@ public class TabOrderSyncAsyncRunner
return redisCache.getCacheObject(CACHE_KEY_PREFIX + taskId);
}
private static int toIntExact(long value)
{
return value > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) value;
}
public static int clampBatch(Integer batchSize)
{
int n = batchSize == null ? DEFAULT_BATCH : batchSize.intValue();