This commit is contained in:
Leo
2026-02-04 23:59:36 +08:00
parent f928e778da
commit 7ed5a76d2f
3 changed files with 22 additions and 13 deletions

View File

@@ -57,8 +57,10 @@ public class TencentDocController extends BaseController {
/** Redis key前缀用于存储上次处理的最大行数 */
private static final String LAST_PROCESSED_ROW_KEY_PREFIX = "tendoc:last_row:";
/** 单次请求最大行数(腾讯文档 API range 限制,避免 invalid param range */
private static final int API_MAX_ROWS_PER_REQUEST = 200;
/** 单次请求最大行数(腾讯文档 API行数≤1000一次拉 500 行 */
private static final int API_MAX_ROWS_PER_REQUEST = 500;
/** 数据区 range 列尾30 列 = A 到 ADAPI 列数≤200 */
private static final String DATA_RANGE_COL_END = "AD";
/** 回溯行数:下次起始行 = 本次扫描终点 + 1 - 回溯,用于覆盖物流变更或延后补填 */
private static final int BACKTRACK_ROWS = 80;
/** 整批都跳过0 写入)时使用的回溯行数,减小回溯以尽快扫到后续行(如 308 */
@@ -1168,7 +1170,7 @@ public class TencentDocController extends BaseController {
if (tryEndRow < startRow) {
continue;
}
String range = String.format("A%d:Z%d", startRow, tryEndRow);
String range = String.format("A%d:%s%d", startRow, DATA_RANGE_COL_END, tryEndRow);
log.info("开始读取数据行 - 行号: {} ~ {} (共 {} 行), range: {} (尝试 decrement={})", startRow, tryEndRow, tryRowCount, range, decrement);
try {
sheetData = tencentDocService.readSheetData(accessToken, fileId, sheetId, range);
@@ -1198,7 +1200,7 @@ public class TencentDocController extends BaseController {
for (int decrement : new int[] { 1, 10 }) {
int tryEndRow = Math.max(startRow, effectiveEndRow - decrement);
if (tryEndRow >= startRow) {
String retryRange = String.format("A%d:Z%d", startRow, tryEndRow);
String retryRange = String.format("A%d:%s%d", startRow, DATA_RANGE_COL_END, tryEndRow);
try {
sheetData = tencentDocService.readSheetData(accessToken, fileId, sheetId, retryRange);
if (sheetData != null) {
@@ -1221,7 +1223,7 @@ public class TencentDocController extends BaseController {
}
}
endRow = effectiveEndRow; // 后续统一使用实际读取成功的 endRow
String range = String.format("A%d:Z%d", startRow, endRow);
String range = String.format("A%d:%s%d", startRow, DATA_RANGE_COL_END, endRow);
log.info("解析后的数据行数: {}", values != null ? values.size() : "null");
if (values == null || values.isEmpty()) {
@@ -2122,8 +2124,8 @@ public class TencentDocController extends BaseController {
int skippedCount = 0;
int errorCount = 0;
// 分批读取数据,每批200行避免单次读取过多数据导致API限制
final int BATCH_SIZE = 200;
// 分批读取数据,每批500行API 行数≤1000列数≤200
final int BATCH_SIZE = 500;
int currentStartRow = startRow;
int totalBatches = (int) Math.ceil((double)(endRow - startRow + 1) / BATCH_SIZE);
int currentBatch = 0;
@@ -2421,8 +2423,8 @@ public class TencentDocController extends BaseController {
int errorCount = 0; // 错误数量
java.util.List<String> updatedOrderNos = new java.util.ArrayList<>(); // 更新的单号列表
// 分批读取数据,每批200行避免单次读取过多数据导致API限制
final int BATCH_SIZE = 200;
// 分批读取数据,每批500行API 行数≤1000列数≤200
final int BATCH_SIZE = 500;
int currentStartRow = startRow;
int totalBatches = (int) Math.ceil((double)(endRow - startRow + 1) / BATCH_SIZE);
int currentBatch = 0;