fix(sheet):修复行数计算逻辑并优化数据写入
- 修复行数不足时的计算逻辑,使用 Math.abs 确保正数 -优化数据写入时的行映射逻辑,避免重复键冲突 - 调整表格选项设置中的行数范围,防止越界错误 - 增加对现有行数的读取逻辑,确保操作不会超出限制
This commit is contained in:
parent
f191e57c9a
commit
3b0b8712a8
@ -260,7 +260,12 @@ public class FsHelper {
|
||||
FeishuClient client = FsClient.getInstance().getClient();
|
||||
Sheet sheet = FsApiUtil.getSheetMetadata(sheetId, client, spreadsheetToken);
|
||||
List<FsTableData> fsTableDataList = FsTableUtil.getFsTableData(sheet, spreadsheetToken, tableConf, fieldsMap);
|
||||
Map<String, Integer> currTableRowMap = fsTableDataList.stream().collect(Collectors.toMap(FsTableData::getUniqueId, FsTableData::getRow));
|
||||
|
||||
Map<String, Integer> currTableRowMap = fsTableDataList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
FsTableData::getUniqueId,
|
||||
FsTableData::getRow,
|
||||
(existing, replacement) -> existing));
|
||||
|
||||
final Integer[] row = {tableConf.headLine()};
|
||||
fsTableDataList.forEach(fsTableData -> {
|
||||
@ -345,7 +350,7 @@ public class FsHelper {
|
||||
int rowTotal = sheet.getGridProperties().getRowCount();
|
||||
int rowNum = rowCount.get();
|
||||
if (rowNum >= rowTotal) {
|
||||
FsApiUtil.addRowColumns(sheetId, spreadsheetToken, "ROWS", rowTotal - rowNum, client);
|
||||
FsApiUtil.addRowColumns(sheetId, spreadsheetToken, "ROWS", Math.abs(rowTotal - rowNum), client);
|
||||
}
|
||||
|
||||
Object resp = FsApiUtil.batchPutValues(sheetId, spreadsheetToken, resultValuesBuilder.build(), client);
|
||||
|
||||
@ -345,7 +345,7 @@ public class MapWriteBuilder {
|
||||
private void ensureSufficientRows(Sheet sheet, int requiredRows, FeishuClient client) {
|
||||
int rowTotal = sheet.getGridProperties().getRowCount();
|
||||
if (requiredRows >= rowTotal) {
|
||||
FsApiUtil.addRowColumns(sheetId, spreadsheetToken, "ROWS", requiredRows - rowTotal, client);
|
||||
FsApiUtil.addRowColumns(sheetId, spreadsheetToken, "ROWS", Math.abs(requiredRows - rowTotal), client);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -163,7 +163,10 @@ public class WriteBuilder<T> {
|
||||
|
||||
Map<String, Integer> currTableRowMap = fsTableDataList.stream()
|
||||
.filter(fsTableData -> fsTableData.getRow() >= tableConf.headLine())
|
||||
.collect(Collectors.toMap(FsTableData::getUniqueId, FsTableData::getRow));
|
||||
.collect(Collectors.toMap(
|
||||
FsTableData::getUniqueId,
|
||||
FsTableData::getRow,
|
||||
(existing, replacement) -> existing));
|
||||
|
||||
final Integer[] row = {tableConf.headLine()};
|
||||
fsTableDataList.forEach(fsTableData -> {
|
||||
@ -246,7 +249,7 @@ public class WriteBuilder<T> {
|
||||
int rowTotal = sheet.getGridProperties().getRowCount();
|
||||
int rowNum = rowCount.get();
|
||||
if (rowNum >= rowTotal) {
|
||||
FsApiUtil.addRowColumns(sheetId, spreadsheetToken, "ROWS", rowTotal - rowNum, client);
|
||||
FsApiUtil.addRowColumns(sheetId, spreadsheetToken, "ROWS", Math.abs(rowTotal - rowNum), client);
|
||||
}
|
||||
|
||||
fileDataList.forEach(fileData -> {
|
||||
|
||||
@ -186,7 +186,7 @@ public class FsTableUtil {
|
||||
List<List<Object>> values = new LinkedList<>();
|
||||
for (int i = 0; i < batchCount; i++) {
|
||||
int startRowIndex = startOffset + i * rowCount;
|
||||
int endRowIndex = Math.max(startRowIndex + rowCount - 1, totalRow - 1);
|
||||
int endRowIndex = Math.min(startRowIndex + rowCount - 1, totalRow - 1);
|
||||
|
||||
// 3. 获取工作表数据
|
||||
ValuesBatch valuesBatch = FsApiUtil.getSheetData(sheet.getSheetId(), spreadsheetToken,
|
||||
@ -498,6 +498,9 @@ public class FsTableUtil {
|
||||
|
||||
public static void setTableOptions(String spreadsheetToken, List<String> headers, Map<String, FieldProperty> fieldsMap,
|
||||
String sheetId, boolean enableDesc, Map<String, Object> customProperties) {
|
||||
// 读取sheet数据,查询有现有行数(超出会报错)
|
||||
Sheet sheet = FsApiUtil.getSheetMetadata(sheetId, FsClient.getInstance().getClient(), spreadsheetToken);
|
||||
int rowCount = sheet.getGridProperties().getRowCount();
|
||||
|
||||
List<Object> list = Arrays.asList(headers.toArray());
|
||||
int line = getMaxLevel(fieldsMap) + (enableDesc ? 2 : 1);
|
||||
@ -534,8 +537,9 @@ public class FsTableUtil {
|
||||
}
|
||||
|
||||
if (result != null && !result.isEmpty()) {
|
||||
FsApiUtil.setOptions(sheetId, FsClient.getInstance().getClient(), spreadsheetToken, tableProperty.type() == TypeEnum.MULTI_SELECT, position + line, position + 200,
|
||||
result);
|
||||
FsApiUtil.setOptions(sheetId, FsClient.getInstance().getClient(), spreadsheetToken,
|
||||
tableProperty.type() == TypeEnum.MULTI_SELECT,
|
||||
position + line, position + rowCount, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user