This commit is contained in:
Leo
2026-01-06 15:56:27 +08:00
parent 9935c6c07e
commit 46d2a209c0

View File

@@ -1189,6 +1189,8 @@ public class TencentDocController extends BaseController {
int filledCount = 0; int filledCount = 0;
int skippedCount = 0; int skippedCount = 0;
int errorCount = 0; int errorCount = 0;
int successUpdates = 0; // 实际成功写入的数量
int maxSuccessRow = 0; // 记录实际成功写入的最大行号
// 收集同步成功的详细日志(用于微信推送) // 收集同步成功的详细日志(用于微信推送)
List<Map<String, Object>> successLogs = new java.util.ArrayList<>(); List<Map<String, Object>> successLogs = new java.util.ArrayList<>();
@@ -1329,7 +1331,9 @@ public class TencentDocController extends BaseController {
// 批量写入(每行单独写入,同时更新多个字段) // 批量写入(每行单独写入,同时更新多个字段)
// 在写入前,重新读取该行验证单号匹配和物流链接列为空 // 在写入前,重新读取该行验证单号匹配和物流链接列为空
int successUpdates = 0; // 重置成功计数(在循环外已定义)
int currentBatchSuccessUpdates = 0;
int currentBatchMaxSuccessRow = 0;
for (Map.Entry<Integer, JSONObject> entry : rowUpdates.entrySet()) { for (Map.Entry<Integer, JSONObject> entry : rowUpdates.entrySet()) {
try { try {
int row = entry.getKey(); int row = entry.getKey();
@@ -1415,7 +1419,11 @@ public class TencentDocController extends BaseController {
// 调用 batchUpdate API // 调用 batchUpdate API
tencentDocService.batchUpdate(accessToken, fileId, batchUpdateBody); tencentDocService.batchUpdate(accessToken, fileId, batchUpdateBody);
successUpdates++; currentBatchSuccessUpdates++;
// 更新实际成功写入的最大行号
if (row > currentBatchMaxSuccessRow) {
currentBatchMaxSuccessRow = row;
}
String logMsg = String.format("✓ 写入成功 - 行: %d, 单号: %s, 物流链接: %s", row, expectedOrderNo, logisticsLink); String logMsg = String.format("✓ 写入成功 - 行: %d, 单号: %s, 物流链接: %s", row, expectedOrderNo, logisticsLink);
if (phone != null) { if (phone != null) {
@@ -1475,45 +1483,57 @@ public class TencentDocController extends BaseController {
} }
} }
log.info("批量填充物流链接完成 - 成功: {}, 跳过: {}, 错误: {}", successUpdates, skippedCount, errorCount); // 更新全局成功计数
successUpdates = currentBatchSuccessUpdates;
maxSuccessRow = currentBatchMaxSuccessRow;
log.info("批量填充物流链接完成 - 成功: {}, 跳过: {}, 错误: {}, 最大成功行号: {}",
successUpdates, skippedCount, errorCount, maxSuccessRow > 0 ? maxSuccessRow : "");
} }
// 根据填充结果决定下次的起始位置 // 根据填充结果决定下次的起始位置
int currentMaxRow = endRow; // 使用实际成功写入的最大行号,如果没有成功写入,则使用 endRow
int currentMaxRow = (maxSuccessRow > 0) ? maxSuccessRow : endRow;
int nextStartRow; int nextStartRow;
String nextSyncHint; String nextSyncHint;
if (filledCount > 0) { // 使用 successUpdates实际成功写入数量而不是 filledCount准备写入数量
// 有数据填充成功,说明当前范围有有效数据,继续往前推进 if (successUpdates > 0) {
// 下次从 endRow - 100 开始回溯100行防止遗漏 // 有数据实际写入成功,说明当前范围有有效数据,继续往前推进
// 下次从 currentMaxRow - 100 开始回溯100行防止遗漏
nextStartRow = Math.max(effectiveStartRow, currentMaxRow - 100); nextStartRow = Math.max(effectiveStartRow, currentMaxRow - 100);
nextSyncHint = String.format("下次将从第 %d 行开始(本次填充 %d 条回溯100行防止遗漏", nextSyncHint = String.format("下次将从第 %d 行开始(本次实际写入成功 %d 条,最大行号: %d回溯100行防止遗漏",
nextStartRow, filledCount); nextStartRow, successUpdates, currentMaxRow);
// 记录进度到 endRow,持续往前 // 记录进度到实际成功写入的最大行号,持续往前
redisCache.setCacheObject(redisKey, currentMaxRow, 30, TimeUnit.DAYS); redisCache.setCacheObject(redisKey, currentMaxRow, 30, TimeUnit.DAYS);
log.info("本次填充成功 {} 条,更新进度到第 {} 行,下次从第 {} 行开始", log.info("========== 更新Redis进度 ==========");
filledCount, currentMaxRow, nextStartRow); log.info("本次实际写入成功 {} 条,最大成功行号: {},更新进度到第 {} 行,下次从第 {} 行开始",
successUpdates, maxSuccessRow, currentMaxRow, nextStartRow);
log.info("Redis Key: {}", redisKey);
} else { } else {
// 没有数据填充,说明这个范围都是空行或已处理的数据 // 没有数据实际写入成功,说明这个范围都是空行或已处理的数据
if (lastMaxRow != null && currentMaxRow > (lastMaxRow + 300)) { if (lastMaxRow != null && currentMaxRow > (lastMaxRow + 300)) {
// 如果跳跃太大(>300行可能已经超出数据区域回到配置起始行重新扫描 // 如果跳跃太大(>300行可能已经超出数据区域回到配置起始行重新扫描
nextStartRow = effectiveStartRow; nextStartRow = effectiveStartRow;
nextSyncHint = String.format("下次将从第 %d 行重新开始(本次范围 %d-%d 无新数据,重新扫描)", nextSyncHint = String.format("下次将从第 %d 行重新开始(本次范围 %d-%d 无实际写入,重新扫描)",
nextStartRow, startRow, endRow); nextStartRow, startRow, endRow);
// 不更新 Redis 进度,保持原有进度 // 不更新 Redis 进度,保持原有进度
log.info("本次无数据填充,且跳跃过大,下次将从配置起始行 {} 重新开始", effectiveStartRow); log.info("本次无实际写入,且跳跃过大{} > {} + 300,下次将从配置起始行 {} 重新开始",
currentMaxRow, lastMaxRow, effectiveStartRow);
} else { } else {
// 跳跃不大,继续往前推进,跳过更多行(+200行 // 跳跃不大,继续往前推进
nextStartRow = Math.max(effectiveStartRow, currentMaxRow - 100); nextStartRow = Math.max(effectiveStartRow, currentMaxRow - 100);
nextSyncHint = String.format("下次将从第 %d 行开始(本次范围 %d-%d 无新数据,继续往前)", nextSyncHint = String.format("下次将从第 %d 行开始(本次范围 %d-%d 无实际写入,继续往前)",
nextStartRow, startRow, endRow); nextStartRow, startRow, endRow);
// 记录进度到 endRow // 记录进度到 endRow(即使没有写入,也要记录扫描进度)
redisCache.setCacheObject(redisKey, currentMaxRow, 30, TimeUnit.DAYS); redisCache.setCacheObject(redisKey, currentMaxRow, 30, TimeUnit.DAYS);
log.info("本次无数据填充,更新进度到第 {} 行,下次从第 {} 行继续", log.info("========== 更新Redis进度 ==========");
log.info("本次无实际写入,更新扫描进度到第 {} 行,下次从第 {} 行继续",
currentMaxRow, nextStartRow); currentMaxRow, nextStartRow);
log.info("Redis Key: {}", redisKey);
} }
} }