This commit is contained in:
Leo
2026-02-05 00:11:59 +08:00
parent 7ed5a76d2f
commit 7367e28133
3 changed files with 101 additions and 31 deletions

View File

@@ -97,6 +97,16 @@ public interface ITencentDocService {
* @return 工作表列表
*/
JSONObject getSheetList(String accessToken, String fileId);
/**
* 获取指定工作表的 rowTotal文档信息接口返回直接用于 range 上限)
*
* @param accessToken 访问令牌
* @param fileId 文件ID
* @param sheetId 工作表ID
* @return rowTotal未找到或解析失败返回 0
*/
int getSheetRowTotal(String accessToken, String fileId, String sheetId);
/**
* 获取用户信息

View File

@@ -562,6 +562,53 @@ public class TencentDocServiceImpl implements ITencentDocService {
}
}
@Override
public int getSheetRowTotal(String accessToken, String fileId, String sheetId) {
if (accessToken == null || fileId == null || sheetId == null) {
return 0;
}
try {
JSONObject result = getFileInfo(accessToken, fileId);
if (result == null) {
return 0;
}
// 兼容多种返回结构data.properties[]、properties[]、sheets[].properties
com.alibaba.fastjson2.JSONArray list = null;
if (result.containsKey("data")) {
com.alibaba.fastjson2.JSONObject data = result.getJSONObject("data");
if (data != null && data.containsKey("properties")) {
list = data.getJSONArray("properties");
} else if (data != null && data.containsKey("sheets")) {
list = data.getJSONArray("sheets");
}
}
if (list == null && result.containsKey("properties")) {
list = result.getJSONArray("properties");
}
if (list == null && result.containsKey("sheets")) {
list = result.getJSONArray("sheets");
}
if (list == null) {
return 0;
}
for (int i = 0; i < list.size(); i++) {
com.alibaba.fastjson2.JSONObject item = list.getJSONObject(i);
com.alibaba.fastjson2.JSONObject props = item.containsKey("properties") ? item.getJSONObject("properties") : item;
if (props == null) {
continue;
}
String sid = props.getString("sheetId");
if (sheetId.equals(sid) && props.containsKey("rowTotal")) {
return Math.max(0, props.getIntValue("rowTotal"));
}
}
return 0;
} catch (Exception e) {
log.warn("获取工作表 rowTotal 失败 - fileId: {}, sheetId: {}", fileId, sheetId, e);
return 0;
}
}
@Override
public JSONObject getUserInfo(String accessToken) {
try {