This commit is contained in:
Leo
2026-02-08 11:35:38 +08:00
parent 549224a83f
commit 4c07dda3d7
2 changed files with 55 additions and 13 deletions

View File

@@ -1061,22 +1061,25 @@ public class TencentDocController extends BaseController {
}
if (rowTotal > 0) {
if (startRow > rowTotal) {
startRow = Math.max(MIN_START_ROW_WHEN_USE_ROW_TOTAL,
Math.max(effectiveStartRow, rowTotal - READ_ROWS_WHEN_USE_ROW_TOTAL));
// 配置/缓存的起始行超出表尾时,必须忽略 effectiveStartRow按 rowTotal 回溯
startRow = Math.max(MIN_START_ROW_WHEN_USE_ROW_TOTAL, rowTotal - READ_ROWS_WHEN_USE_ROW_TOTAL);
endRow = Math.min(rowTotal, startRow + READ_ROWS_WHEN_USE_ROW_TOTAL - 1);
log.info("按 rowTotal={} 修正范围,避免超出表尾: 第 {} ~ {} 行", rowTotal, startRow, endRow);
log.info("按 rowTotal={} 修正范围(忽略超出表尾的配置起始行),避免超出: 第 {} ~ {} 行", rowTotal, startRow, endRow);
// 将修正后的起始行写回配置,避免下次仍使用过大的值
redisCache.setCacheObject(CONFIG_KEY_PREFIX + "startRow", startRow, 180, TimeUnit.DAYS);
log.info("已自动修正 Redis 配置 startRow 为 {}", startRow);
} else if (endRow > rowTotal) {
endRow = rowTotal;
log.info("按 rowTotal={} 截断结束行: endRow={}", rowTotal, endRow);
}
} else {
// 未取到 rowTotal 时:若 startRow 过高(如 348 超出实际 324 行)可能是 Redis 缓存过时,保守回溯
// 未取到 rowTotal 时:若 startRow 过高(如 350 超出实际 324 行)可能是配置/Redis 过时,回溯至配置最小值
final int START_ROW_SAFE_THRESHOLD = 350;
if (startRow > START_ROW_SAFE_THRESHOLD) {
int oldStart = startRow;
startRow = Math.max(MIN_START_ROW_WHEN_USE_ROW_TOTAL, effectiveStartRow);
startRow = Math.max(MIN_START_ROW_WHEN_USE_ROW_TOTAL, headerRow != null ? headerRow + 1 : 3);
endRow = startRow + READ_ROWS_WHEN_USE_ROW_TOTAL - 1;
log.warn("rowTotal 未获取且 startRow={} 过高,保守回溯至 effectiveStartRow={},范围: {} ~ {}", oldStart, startRow, startRow, endRow);
log.warn("rowTotal 未获取且 startRow={} 过高,保守回溯至表头下一行 {},范围: {} ~ {}", oldStart, startRow, startRow, endRow);
}
}
@@ -1287,6 +1290,7 @@ public class TencentDocController extends BaseController {
result.put("endRow", effectiveEndRow);
result.put("lastMaxRow", lastMaxRow);
result.put("nextStartRow", emptyNextStart);
result.put("rowTotal", rowTotal > 0 ? rowTotal : null);
result.put("currentMaxRow", emptyCurrentMax);
result.put("filledCount", 0);
result.put("skippedCount", 0);
@@ -1796,6 +1800,7 @@ public class TencentDocController extends BaseController {
result.put("currentMaxRow", currentMaxRow);
result.put("lastMaxRow", lastMaxRow);
result.put("nextStartRow", nextStartRow);
result.put("rowTotal", rowTotal > 0 ? rowTotal : null);
result.put("filledCount", filledCount);
result.put("skippedCount", skippedCount);
result.put("errorCount", errorCount);