从接口拿行数
This commit is contained in:
@@ -99,12 +99,13 @@ public interface ITencentDocService {
|
||||
JSONObject getSheetList(String accessToken, String fileId);
|
||||
|
||||
/**
|
||||
* 获取指定工作表的 rowTotal(文档信息接口返回,直接用于 range 上限)
|
||||
* 获取指定工作表的行数(优先返回 rowCount-实际有数据的行数,其次 rowTotal)
|
||||
* 用于替代 Redis 上次记录的行数,决定批量填充的操作范围
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
* @param fileId 文件ID
|
||||
* @param sheetId 工作表ID
|
||||
* @return rowTotal,未找到或解析失败返回 0
|
||||
* @return rowCount/rowTotal,未找到或解析失败返回 0
|
||||
*/
|
||||
int getSheetRowTotal(String accessToken, String fileId, String sheetId);
|
||||
|
||||
|
||||
@@ -349,42 +349,7 @@ public class TencentDocDelayedPushServiceImpl implements ITencentDocDelayedPushS
|
||||
Object result = method.invoke(controller, params);
|
||||
|
||||
log.info("✓ 批量同步执行完成,结果: {}", result);
|
||||
|
||||
// 将接口返回的 nextStartRow 写回 Redis,下次定时执行从新起始行开始(否则会一直从配置的 99 开始)
|
||||
if (result instanceof java.util.Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
java.util.Map<String, Object> resultMap = (java.util.Map<String, Object>) result;
|
||||
Object data = resultMap.get("data");
|
||||
if (data instanceof java.util.Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
java.util.Map<String, Object> dataMap = (java.util.Map<String, Object>) data;
|
||||
Object nextStartRowObj = dataMap.get("nextStartRow");
|
||||
if (nextStartRowObj != null) {
|
||||
int nextStartRow;
|
||||
if (nextStartRowObj instanceof Number) {
|
||||
nextStartRow = ((Number) nextStartRowObj).intValue();
|
||||
} else {
|
||||
try {
|
||||
nextStartRow = Integer.parseInt(nextStartRowObj.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
nextStartRow = -1;
|
||||
}
|
||||
}
|
||||
if (nextStartRow >= 1) {
|
||||
// 若 nextStartRow 超出 rowTotal, capped 避免下次仍超出表尾
|
||||
Object rowTotalObj = dataMap.get("rowTotal");
|
||||
int rowTotal = rowTotalObj instanceof Number ? ((Number) rowTotalObj).intValue() : 0;
|
||||
int toWrite = nextStartRow;
|
||||
if (rowTotal > 0 && nextStartRow > rowTotal) {
|
||||
toWrite = Math.max(MIN_START_ROW_WHEN_USE_ROW_TOTAL, rowTotal - READ_ROWS_WHEN_USE_ROW_TOTAL);
|
||||
log.info("nextStartRow={} 超出 rowTotal={},capped 为 {}", nextStartRow, rowTotal, toWrite);
|
||||
}
|
||||
redisCache.setCacheObject(CONFIG_KEY_PREFIX + "startRow", toWrite, 180, TimeUnit.DAYS);
|
||||
log.info("✓ 已更新下次起始行到 Redis: startRow={}(下次定时同步从第 {} 行开始)", toWrite, toWrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 不再将 nextStartRow 写入 Redis,下次定时执行时从接口获取 rowCount 决定范围
|
||||
|
||||
} catch (Exception ex) {
|
||||
log.error("批量同步调用失败", ex);
|
||||
|
||||
@@ -603,17 +603,17 @@ public class TencentDocServiceImpl implements ITencentDocService {
|
||||
if (sid == null || !sheetId.equals(sid)) {
|
||||
continue;
|
||||
}
|
||||
// rowTotal 可能为 rowTotal、row_total 或 rowCount(腾讯文档 API 多种返回格式)
|
||||
// 优先使用 rowCount(表格实际有数据的行数,用于操作范围),其次 rowTotal(表格容量上限)
|
||||
if (props.containsKey("rowCount")) {
|
||||
return Math.max(0, props.getIntValue("rowCount"));
|
||||
}
|
||||
if (props.containsKey("rowTotal")) {
|
||||
return Math.max(0, props.getIntValue("rowTotal"));
|
||||
}
|
||||
if (props.containsKey("row_total")) {
|
||||
return Math.max(0, props.getIntValue("row_total"));
|
||||
}
|
||||
if (props.containsKey("rowCount")) {
|
||||
return Math.max(0, props.getIntValue("rowCount"));
|
||||
}
|
||||
log.debug("getSheetRowTotal 找到 sheetId 但无 rowTotal/rowCount - fileId: {}, sheetId: {}, propsKeys: {}",
|
||||
log.debug("getSheetRowTotal 找到 sheetId 但无 rowCount/rowTotal - fileId: {}, sheetId: {}, propsKeys: {}",
|
||||
fileId, sheetId, props.keySet());
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user