1
This commit is contained in:
@@ -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);
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user