1
This commit is contained in:
@@ -958,14 +958,56 @@ public class TencentDocController extends BaseController {
|
||||
}
|
||||
|
||||
// 批量写入(每行单独写入,同时更新多个字段)
|
||||
// 在写入前,重新读取该行验证单号匹配和物流链接列为空
|
||||
int successUpdates = 0;
|
||||
for (Map.Entry<Integer, JSONObject> entry : rowUpdates.entrySet()) {
|
||||
try {
|
||||
int row = entry.getKey();
|
||||
JSONObject update = entry.getValue();
|
||||
String logisticsLink = update.getString("logisticsLink");
|
||||
String orderNo = update.getString("orderNo");
|
||||
String expectedOrderNo = update.getString("orderNo");
|
||||
|
||||
// 重新读取该行数据,验证单号和物流链接列
|
||||
String verifyRange = String.format("A%d:Z%d", row, row);
|
||||
JSONObject verifyData = tencentDocService.readSheetData(accessToken, fileId, sheetId, verifyRange);
|
||||
|
||||
if (verifyData == null || !verifyData.containsKey("values")) {
|
||||
log.warn("验证失败 - 无法读取行 {}", row);
|
||||
errorCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONArray verifyRows = verifyData.getJSONArray("values");
|
||||
if (verifyRows == null || verifyRows.isEmpty()) {
|
||||
log.warn("验证失败 - 行 {} 数据为空", row);
|
||||
errorCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONArray verifyRow = verifyRows.getJSONArray(0);
|
||||
if (verifyRow == null || verifyRow.size() <= Math.max(orderNoColumn, logisticsLinkColumn)) {
|
||||
log.warn("验证失败 - 行 {} 列数不足", row);
|
||||
errorCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 验证1:单号是否匹配
|
||||
String currentOrderNo = verifyRow.getString(orderNoColumn);
|
||||
if (currentOrderNo == null || !currentOrderNo.trim().equals(expectedOrderNo)) {
|
||||
log.warn("验证失败 - 行 {} 单号不匹配,预期: {}, 实际: {}", row, expectedOrderNo, currentOrderNo);
|
||||
errorCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 验证2:物流链接列是否为空
|
||||
String currentLogisticsLink = verifyRow.getString(logisticsLinkColumn);
|
||||
if (currentLogisticsLink != null && !currentLogisticsLink.trim().isEmpty()) {
|
||||
log.info("跳过写入 - 行 {} 单号 {} 的物流链接列已有值: {}", row, expectedOrderNo, currentLogisticsLink);
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 验证通过,执行写入
|
||||
// 使用 batchUpdate 一次性更新多个字段
|
||||
JSONArray requests = new JSONArray();
|
||||
|
||||
@@ -990,8 +1032,7 @@ public class TencentDocController extends BaseController {
|
||||
tencentDocService.batchUpdate(accessToken, fileId, batchUpdateBody);
|
||||
successUpdates++;
|
||||
|
||||
log.info("成功写入数据 - 行: {}, 单号: {}, 物流链接: {}, 是否安排: 2, 标记: {}",
|
||||
row, orderNo, logisticsLink, today);
|
||||
log.info("✓ 写入成功 - 行: {}, 单号: {}, 物流链接: {}", row, expectedOrderNo, logisticsLink);
|
||||
} catch (Exception e) {
|
||||
log.error("写入数据失败 - 行: {}", entry.getKey(), e);
|
||||
errorCount++;
|
||||
|
||||
Reference in New Issue
Block a user