1
This commit is contained in:
@@ -897,11 +897,12 @@ public class TencentDocController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合并同一行的腾讯文档填充任务(同一行多条更新时合并为一次写入)
|
* 合并同一行的腾讯文档填充任务(物流更新与仅补京东单号合并为一次 batchUpdate)
|
||||||
*/
|
*/
|
||||||
private void mergeTencentDocRowFillUpdate(JSONObject target, JSONObject extra) {
|
private void mergeTencentDocRowFillUpdate(JSONObject target, JSONObject extra) {
|
||||||
if (extra.containsKey("logisticsLink")) {
|
if (extra.containsKey("logisticsLink")) {
|
||||||
target.put("logisticsLink", extra.getString("logisticsLink"));
|
target.put("logisticsLink", extra.getString("logisticsLink"));
|
||||||
|
target.remove("isJdOrderIdOnlyUpdate");
|
||||||
}
|
}
|
||||||
if (Boolean.TRUE.equals(extra.getBoolean("isLinkUpdated"))) {
|
if (Boolean.TRUE.equals(extra.getBoolean("isLinkUpdated"))) {
|
||||||
target.put("isLinkUpdated", true);
|
target.put("isLinkUpdated", true);
|
||||||
@@ -924,6 +925,9 @@ public class TencentDocController extends BaseController {
|
|||||||
if (extra.containsKey("jdOrderIdColumn")) {
|
if (extra.containsKey("jdOrderIdColumn")) {
|
||||||
target.put("jdOrderIdColumn", extra.getInteger("jdOrderIdColumn"));
|
target.put("jdOrderIdColumn", extra.getInteger("jdOrderIdColumn"));
|
||||||
}
|
}
|
||||||
|
if (Boolean.TRUE.equals(extra.getBoolean("isJdOrderIdOnlyUpdate")) && !target.containsKey("logisticsLink")) {
|
||||||
|
target.put("isJdOrderIdOnlyUpdate", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1335,8 +1339,8 @@ public class TencentDocController extends BaseController {
|
|||||||
update.put("isLinkUpdated", true); // 标记为物流链接更新
|
update.put("isLinkUpdated", true); // 标记为物流链接更新
|
||||||
update.put("oldLogisticsLink", trimmedExistingLink); // 旧链接
|
update.put("oldLogisticsLink", trimmedExistingLink); // 旧链接
|
||||||
update.put("newLogisticsLink", trimmedDbLink); // 新链接
|
update.put("newLogisticsLink", trimmedDbLink); // 新链接
|
||||||
// 仅物流变更时顺带写京东单号,且文档该列为空时才写入
|
// 物流变更:与京东单号一并同步(单号随物流变,覆盖文档原京东单号)
|
||||||
if (jdPlaceOrderNoColumn != null && !dbJdOrderId.isEmpty() && docJdOrderId.isEmpty()) {
|
if (jdPlaceOrderNoColumn != null && !dbJdOrderId.isEmpty()) {
|
||||||
update.put("jdOrderId", dbJdOrderId);
|
update.put("jdOrderId", dbJdOrderId);
|
||||||
update.put("jdOrderIdColumn", jdPlaceOrderNoColumn);
|
update.put("jdOrderIdColumn", jdPlaceOrderNoColumn);
|
||||||
}
|
}
|
||||||
@@ -1354,6 +1358,17 @@ public class TencentDocController extends BaseController {
|
|||||||
|
|
||||||
log.info("========== 物流链接不一致,已加入更新队列 - 单号: {}, 行号: {}, 旧链接: {}, 新链接: {} ==========",
|
log.info("========== 物流链接不一致,已加入更新队列 - 单号: {}, 行号: {}, 旧链接: {}, 新链接: {} ==========",
|
||||||
orderNo, excelRow, trimmedExistingLink, trimmedDbLink);
|
orderNo, excelRow, trimmedExistingLink, trimmedDbLink);
|
||||||
|
} else if (docJdOrderId.isEmpty() && !dbJdOrderId.isEmpty() && jdPlaceOrderNoColumn != null) {
|
||||||
|
// 文档已有物流、京东单号列为空:仅补写京东单号
|
||||||
|
JSONObject jdUpdate = new JSONObject();
|
||||||
|
jdUpdate.put("row", excelRow);
|
||||||
|
jdUpdate.put("orderNo", orderNo);
|
||||||
|
jdUpdate.put("isJdOrderIdOnlyUpdate", true);
|
||||||
|
jdUpdate.put("jdOrderId", dbJdOrderId);
|
||||||
|
jdUpdate.put("jdOrderIdColumn", jdPlaceOrderNoColumn);
|
||||||
|
updates.add(jdUpdate);
|
||||||
|
filledCount++;
|
||||||
|
log.info("========== 文档有物流无京东单号,补写京东下单订单号 - 第三方单号: {}, 行: {} ==========", orderNo, excelRow);
|
||||||
} else {
|
} else {
|
||||||
// 物流链接一致或数据库中没有链接,只需同步订单状态
|
// 物流链接一致或数据库中没有链接,只需同步订单状态
|
||||||
if (existingOrder.getTencentDocPushed() == null || existingOrder.getTencentDocPushed() == 0) {
|
if (existingOrder.getTencentDocPushed() == null || existingOrder.getTencentDocPushed() == 0) {
|
||||||
@@ -1443,6 +1458,12 @@ public class TencentDocController extends BaseController {
|
|||||||
update.put("phoneColumn", phoneColumn);
|
update.put("phoneColumn", phoneColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 文档无物流:与物流一并写入京东单号(无物流无单号 → 一起写入)
|
||||||
|
if (jdPlaceOrderNoColumn != null && order.getOrderId() != null && !order.getOrderId().trim().isEmpty()) {
|
||||||
|
update.put("jdOrderId", order.getOrderId().trim());
|
||||||
|
update.put("jdOrderIdColumn", jdPlaceOrderNoColumn);
|
||||||
|
}
|
||||||
|
|
||||||
// 注意:不再保存order对象,写入成功后会重新查询以确保数据最新
|
// 注意:不再保存order对象,写入成功后会重新查询以确保数据最新
|
||||||
updates.add(update);
|
updates.add(update);
|
||||||
|
|
||||||
@@ -1505,6 +1526,83 @@ public class TencentDocController extends BaseController {
|
|||||||
JSONObject update = entry.getValue();
|
JSONObject update = entry.getValue();
|
||||||
String expectedOrderNo = update.getString("orderNo");
|
String expectedOrderNo = update.getString("orderNo");
|
||||||
|
|
||||||
|
// 文档已有物流、仅补写京东下单订单号(有物流无京东单号)
|
||||||
|
if (Boolean.TRUE.equals(update.getBoolean("isJdOrderIdOnlyUpdate"))) {
|
||||||
|
Integer jdCol = update.getInteger("jdOrderIdColumn");
|
||||||
|
String jdId = update.getString("jdOrderId");
|
||||||
|
if (jdCol == null || jdId == null || jdId.trim().isEmpty()) {
|
||||||
|
log.warn("仅补京东单号任务参数不全 - 行 {}", row);
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
jdId = jdId.trim();
|
||||||
|
String jdVerifyRange = String.format("A%d:Z%d", row, row);
|
||||||
|
JSONObject jdVerifyData = tencentDocService.readSheetData(accessToken, fileId, sheetId, jdVerifyRange);
|
||||||
|
if (jdVerifyData == null || !jdVerifyData.containsKey("values")) {
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONArray jdVerifyRows = jdVerifyData.getJSONArray("values");
|
||||||
|
if (jdVerifyRows == null || jdVerifyRows.isEmpty()) {
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONArray jdVerifyRow = jdVerifyRows.getJSONArray(0);
|
||||||
|
int jdNeedIdx = Math.max(orderNoColumn, Math.max(logisticsLinkColumn, jdCol));
|
||||||
|
if (jdVerifyRow == null || jdVerifyRow.size() <= jdNeedIdx) {
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String jdCurOrderNo = jdVerifyRow.getString(orderNoColumn);
|
||||||
|
if (jdCurOrderNo == null || !jdCurOrderNo.trim().equals(expectedOrderNo)) {
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String jdDocLogistics = jdVerifyRow.getString(logisticsLinkColumn);
|
||||||
|
if (jdDocLogistics == null || jdDocLogistics.trim().isEmpty()) {
|
||||||
|
log.info("跳过仅补京东单号 - 行 {} 物流列为空", row);
|
||||||
|
skippedCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String docJd = "";
|
||||||
|
if (jdVerifyRow.size() > jdCol) {
|
||||||
|
try {
|
||||||
|
String sj = jdVerifyRow.getString(jdCol);
|
||||||
|
docJd = sj != null ? sj.trim() : "";
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!docJd.isEmpty()) {
|
||||||
|
skippedCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONArray jdRequests = new JSONArray();
|
||||||
|
jdRequests.add(buildUpdateCellRequest(sheetId, row - 1, jdCol, jdId, false));
|
||||||
|
JSONObject jdBatch = new JSONObject();
|
||||||
|
jdBatch.put("requests", jdRequests);
|
||||||
|
tencentDocService.batchUpdate(accessToken, fileId, jdBatch);
|
||||||
|
currentBatchSuccessUpdates++;
|
||||||
|
if (row > currentBatchMaxSuccessRow) {
|
||||||
|
currentBatchMaxSuccessRow = row;
|
||||||
|
}
|
||||||
|
log.info("✓ 已补写京东下单订单号 - 第三方单号: {}, 行: {}, 值: {}", expectedOrderNo, row, jdId);
|
||||||
|
logOperation(batchId, fileId, sheetId, "BATCH_SYNC", expectedOrderNo, row, jdId,
|
||||||
|
"SUCCESS", "补写京东下单订单号");
|
||||||
|
Map<String, Object> jdSuccessLog = new java.util.HashMap<>();
|
||||||
|
jdSuccessLog.put("orderNo", expectedOrderNo);
|
||||||
|
jdSuccessLog.put("row", row);
|
||||||
|
jdSuccessLog.put("jdOrderId", jdId);
|
||||||
|
jdSuccessLog.put("updateType", "JD_ORDER_ID");
|
||||||
|
successLogs.add(jdSuccessLog);
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String logisticsLink = update.getString("logisticsLink");
|
String logisticsLink = update.getString("logisticsLink");
|
||||||
if (logisticsLink == null || logisticsLink.trim().isEmpty()) {
|
if (logisticsLink == null || logisticsLink.trim().isEmpty()) {
|
||||||
log.warn("跳过写入 - 行 {} 缺少物流链接", row);
|
log.warn("跳过写入 - 行 {} 缺少物流链接", row);
|
||||||
@@ -1643,12 +1741,12 @@ public class TencentDocController extends BaseController {
|
|||||||
log.info("✓ 物流链接更新,保留原标记日期 - 单号: {}, 行: {}", expectedOrderNo, row);
|
log.info("✓ 物流链接更新,保留原标记日期 - 单号: {}, 行: {}", expectedOrderNo, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仅物流变更时顺带写京东单号;文档该列已有内容则不写入
|
// 物流变更:与京东单号一并覆盖写入;首次填物流:仅文档京东列为空时写入
|
||||||
boolean wroteJdOrderIdCell = false;
|
boolean wroteJdOrderIdCell = false;
|
||||||
String jdIdUpdForLog = null;
|
String jdIdUpdForLog = null;
|
||||||
Integer jdColUpd = update.getInteger("jdOrderIdColumn");
|
Integer jdColUpd = update.getInteger("jdOrderIdColumn");
|
||||||
String jdIdUpd = update.getString("jdOrderId");
|
String jdIdUpd = update.getString("jdOrderId");
|
||||||
if (Boolean.TRUE.equals(isLinkUpdated) && jdColUpd != null && jdIdUpd != null && !jdIdUpd.trim().isEmpty()) {
|
if (jdColUpd != null && jdIdUpd != null && !jdIdUpd.trim().isEmpty()) {
|
||||||
jdIdUpd = jdIdUpd.trim();
|
jdIdUpd = jdIdUpd.trim();
|
||||||
String docJdVal = "";
|
String docJdVal = "";
|
||||||
if (verifyRow.size() > jdColUpd) {
|
if (verifyRow.size() > jdColUpd) {
|
||||||
@@ -1659,11 +1757,16 @@ public class TencentDocController extends BaseController {
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (docJdVal.isEmpty()) {
|
boolean shouldWriteJd = Boolean.TRUE.equals(isLinkUpdated) || docJdVal.isEmpty();
|
||||||
|
if (shouldWriteJd) {
|
||||||
requests.add(buildUpdateCellRequest(sheetId, row - 1, jdColUpd, jdIdUpd, false));
|
requests.add(buildUpdateCellRequest(sheetId, row - 1, jdColUpd, jdIdUpd, false));
|
||||||
wroteJdOrderIdCell = true;
|
wroteJdOrderIdCell = true;
|
||||||
jdIdUpdForLog = jdIdUpd;
|
jdIdUpdForLog = jdIdUpd;
|
||||||
log.info("✓ 准备写入京东下单订单号(随物流变更) - 第三方单号: {}, 行: {}, 值: {}", expectedOrderNo, row, jdIdUpd);
|
if (Boolean.TRUE.equals(isLinkUpdated)) {
|
||||||
|
log.info("✓ 同步京东下单订单号(随物流变更) - 第三方单号: {}, 行: {}, 值: {}", expectedOrderNo, row, jdIdUpd);
|
||||||
|
} else {
|
||||||
|
log.info("✓ 写入京东下单订单号(与物流一并) - 第三方单号: {}, 行: {}, 值: {}", expectedOrderNo, row, jdIdUpd);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("✓ 文档已有京东下单订单号,跳过写入 - 第三方单号: {}, 行: {}, 现有: [{}]", expectedOrderNo, row, docJdVal);
|
log.info("✓ 文档已有京东下单订单号,跳过写入 - 第三方单号: {}, 行: {}, 现有: [{}]", expectedOrderNo, row, docJdVal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ public class TencentDocServiceImpl implements ITencentDocService {
|
|||||||
// 2. 识别列位置(根据表头)
|
// 2. 识别列位置(根据表头)
|
||||||
Integer dateColumn = null;
|
Integer dateColumn = null;
|
||||||
Integer companyColumn = null;
|
Integer companyColumn = null;
|
||||||
|
Integer jdPlaceOrderNoColumn = null;
|
||||||
Integer orderNoColumn = null;
|
Integer orderNoColumn = null;
|
||||||
Integer modelColumn = null;
|
Integer modelColumn = null;
|
||||||
Integer quantityColumn = null;
|
Integer quantityColumn = null;
|
||||||
@@ -218,7 +219,11 @@ public class TencentDocServiceImpl implements ITencentDocService {
|
|||||||
for (int i = 0; i < headerCells.size(); i++) {
|
for (int i = 0; i < headerCells.size(); i++) {
|
||||||
String cellText = headerCells.getString(i);
|
String cellText = headerCells.getString(i);
|
||||||
if (cellText != null) {
|
if (cellText != null) {
|
||||||
if (cellText.contains("日期")) dateColumn = i;
|
if (TencentDocDataParser.isJdPlaceOrderNoHeader(cellText)) {
|
||||||
|
if (jdPlaceOrderNoColumn == null) {
|
||||||
|
jdPlaceOrderNoColumn = i;
|
||||||
|
}
|
||||||
|
} else if (cellText.contains("日期")) dateColumn = i;
|
||||||
else if (cellText.contains("公司")) companyColumn = i;
|
else if (cellText.contains("公司")) companyColumn = i;
|
||||||
else if (cellText.contains("单号") && !cellText.contains("物流")
|
else if (cellText.contains("单号") && !cellText.contains("物流")
|
||||||
&& !TencentDocDataParser.isJdPlaceOrderNoHeader(cellText)) orderNoColumn = i;
|
&& !TencentDocDataParser.isJdPlaceOrderNoHeader(cellText)) orderNoColumn = i;
|
||||||
@@ -238,7 +243,7 @@ public class TencentDocServiceImpl implements ITencentDocService {
|
|||||||
throw new RuntimeException("未找到'单号'列,请检查表头配置");
|
throw new RuntimeException("未找到'单号'列,请检查表头配置");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("表头识别完成 - 单号列: {}, 物流列: {}", orderNoColumn, logisticsColumn);
|
log.info("表头识别完成 - 单号列: {}, 京东下单订单号列: {}, 物流列: {}", orderNoColumn, jdPlaceOrderNoColumn, logisticsColumn);
|
||||||
|
|
||||||
// 3. 读取数据区域,查找第一个空行(单号列为空)
|
// 3. 读取数据区域,查找第一个空行(单号列为空)
|
||||||
String dataRange = String.format("A%d:Z%d", startRow, startRow + 999);
|
String dataRange = String.format("A%d:Z%d", startRow, startRow + 999);
|
||||||
@@ -294,6 +299,9 @@ public class TencentDocServiceImpl implements ITencentDocService {
|
|||||||
if (orderNoColumn != null && order.getThirdPartyOrderNo() != null) {
|
if (orderNoColumn != null && order.getThirdPartyOrderNo() != null) {
|
||||||
requests.add(buildUpdateRequest(sheetId, rowIndex, orderNoColumn, order.getThirdPartyOrderNo(), false));
|
requests.add(buildUpdateRequest(sheetId, rowIndex, orderNoColumn, order.getThirdPartyOrderNo(), false));
|
||||||
}
|
}
|
||||||
|
if (jdPlaceOrderNoColumn != null && order.getOrderId() != null && !order.getOrderId().trim().isEmpty()) {
|
||||||
|
requests.add(buildUpdateRequest(sheetId, rowIndex, jdPlaceOrderNoColumn, order.getOrderId().trim(), false));
|
||||||
|
}
|
||||||
if (modelColumn != null && order.getModelNumber() != null) {
|
if (modelColumn != null && order.getModelNumber() != null) {
|
||||||
requests.add(buildUpdateRequest(sheetId, rowIndex, modelColumn, order.getModelNumber(), false));
|
requests.add(buildUpdateRequest(sheetId, rowIndex, modelColumn, order.getModelNumber(), false));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user