1
This commit is contained in:
@@ -1189,6 +1189,8 @@ public class TencentDocController extends BaseController {
|
||||
int filledCount = 0;
|
||||
int skippedCount = 0;
|
||||
int errorCount = 0;
|
||||
int successUpdates = 0; // 实际成功写入的数量
|
||||
int maxSuccessRow = 0; // 记录实际成功写入的最大行号
|
||||
|
||||
// 收集同步成功的详细日志(用于微信推送)
|
||||
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()) {
|
||||
try {
|
||||
int row = entry.getKey();
|
||||
@@ -1415,7 +1419,11 @@ public class TencentDocController extends BaseController {
|
||||
|
||||
// 调用 batchUpdate API
|
||||
tencentDocService.batchUpdate(accessToken, fileId, batchUpdateBody);
|
||||
successUpdates++;
|
||||
currentBatchSuccessUpdates++;
|
||||
// 更新实际成功写入的最大行号
|
||||
if (row > currentBatchMaxSuccessRow) {
|
||||
currentBatchMaxSuccessRow = row;
|
||||
}
|
||||
|
||||
String logMsg = String.format("✓ 写入成功 - 行: %d, 单号: %s, 物流链接: %s", row, expectedOrderNo, logisticsLink);
|
||||
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;
|
||||
String nextSyncHint;
|
||||
|
||||
if (filledCount > 0) {
|
||||
// 有数据填充成功,说明当前范围有有效数据,继续往前推进
|
||||
// 下次从 endRow - 100 开始(回溯100行,防止遗漏)
|
||||
// 使用 successUpdates(实际成功写入数量)而不是 filledCount(准备写入数量)
|
||||
if (successUpdates > 0) {
|
||||
// 有数据实际写入成功,说明当前范围有有效数据,继续往前推进
|
||||
// 下次从 currentMaxRow - 100 开始(回溯100行,防止遗漏)
|
||||
nextStartRow = Math.max(effectiveStartRow, currentMaxRow - 100);
|
||||
nextSyncHint = String.format("下次将从第 %d 行开始(本次填充 %d 条,回溯100行防止遗漏)",
|
||||
nextStartRow, filledCount);
|
||||
nextSyncHint = String.format("下次将从第 %d 行开始(本次实际写入成功 %d 条,最大行号: %d,回溯100行防止遗漏)",
|
||||
nextStartRow, successUpdates, currentMaxRow);
|
||||
|
||||
// 记录进度到 endRow,持续往前
|
||||
// 记录进度到实际成功写入的最大行号,持续往前
|
||||
redisCache.setCacheObject(redisKey, currentMaxRow, 30, TimeUnit.DAYS);
|
||||
log.info("本次填充成功 {} 条,更新进度到第 {} 行,下次从第 {} 行开始",
|
||||
filledCount, currentMaxRow, nextStartRow);
|
||||
log.info("========== 更新Redis进度 ==========");
|
||||
log.info("本次实际写入成功 {} 条,最大成功行号: {},更新进度到第 {} 行,下次从第 {} 行开始",
|
||||
successUpdates, maxSuccessRow, currentMaxRow, nextStartRow);
|
||||
log.info("Redis Key: {}", redisKey);
|
||||
} else {
|
||||
// 没有数据填充,说明这个范围都是空行或已处理的数据
|
||||
// 没有数据实际写入成功,说明这个范围都是空行或已处理的数据
|
||||
if (lastMaxRow != null && currentMaxRow > (lastMaxRow + 300)) {
|
||||
// 如果跳跃太大(>300行),可能已经超出数据区域,回到配置起始行重新扫描
|
||||
nextStartRow = effectiveStartRow;
|
||||
nextSyncHint = String.format("下次将从第 %d 行重新开始(本次范围 %d-%d 无新数据,重新扫描)",
|
||||
nextSyncHint = String.format("下次将从第 %d 行重新开始(本次范围 %d-%d 无实际写入,重新扫描)",
|
||||
nextStartRow, startRow, endRow);
|
||||
|
||||
// 不更新 Redis 进度,保持原有进度
|
||||
log.info("本次无数据填充,且跳跃过大,下次将从配置起始行 {} 重新开始", effectiveStartRow);
|
||||
log.info("本次无实际写入,且跳跃过大({} > {} + 300),下次将从配置起始行 {} 重新开始",
|
||||
currentMaxRow, lastMaxRow, effectiveStartRow);
|
||||
} else {
|
||||
// 跳跃不大,继续往前推进,跳过更多行(+200行)
|
||||
// 跳跃不大,继续往前推进
|
||||
nextStartRow = Math.max(effectiveStartRow, currentMaxRow - 100);
|
||||
nextSyncHint = String.format("下次将从第 %d 行开始(本次范围 %d-%d 无新数据,继续往前)",
|
||||
nextSyncHint = String.format("下次将从第 %d 行开始(本次范围 %d-%d 无实际写入,继续往前)",
|
||||
nextStartRow, startRow, endRow);
|
||||
|
||||
// 记录进度到 endRow
|
||||
// 记录进度到 endRow(即使没有写入,也要记录扫描进度)
|
||||
redisCache.setCacheObject(redisKey, currentMaxRow, 30, TimeUnit.DAYS);
|
||||
log.info("本次无数据填充,更新进度到第 {} 行,下次从第 {} 行继续",
|
||||
log.info("========== 更新Redis进度 ==========");
|
||||
log.info("本次无实际写入,更新扫描进度到第 {} 行,下次从第 {} 行继续",
|
||||
currentMaxRow, nextStartRow);
|
||||
log.info("Redis Key: {}", redisKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user