1
This commit is contained in:
@@ -897,12 +897,11 @@ public class TencentDocController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合并同一行的腾讯文档填充任务(物流更新与京东下单订单号补充可能分两条加入队列)
|
* 合并同一行的腾讯文档填充任务(同一行多条更新时合并为一次写入)
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
@@ -925,9 +924,6 @@ 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1323,8 +1319,6 @@ public class TencentDocController extends BaseController {
|
|||||||
log.debug("读取京东下单订单号列异常 行 {}: {}", excelRow, ex.getMessage());
|
log.debug("读取京东下单订单号列异常 行 {}: {}", excelRow, ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean needJdOrderIdUpdate = jdPlaceOrderNoColumn != null && !dbJdOrderId.isEmpty()
|
|
||||||
&& (docJdOrderId.isEmpty() || !docJdOrderId.equals(dbJdOrderId));
|
|
||||||
|
|
||||||
// 比对物流链接,如果不一致则需要更新
|
// 比对物流链接,如果不一致则需要更新
|
||||||
if (!trimmedDbLink.isEmpty() && !trimmedExistingLink.equals(trimmedDbLink)) {
|
if (!trimmedDbLink.isEmpty() && !trimmedExistingLink.equals(trimmedDbLink)) {
|
||||||
@@ -1341,7 +1335,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()) {
|
// 仅物流变更时顺带写京东单号,且文档该列为空时才写入
|
||||||
|
if (jdPlaceOrderNoColumn != null && !dbJdOrderId.isEmpty() && docJdOrderId.isEmpty()) {
|
||||||
update.put("jdOrderId", dbJdOrderId);
|
update.put("jdOrderId", dbJdOrderId);
|
||||||
update.put("jdOrderIdColumn", jdPlaceOrderNoColumn);
|
update.put("jdOrderIdColumn", jdPlaceOrderNoColumn);
|
||||||
}
|
}
|
||||||
@@ -1359,17 +1354,6 @@ public class TencentDocController extends BaseController {
|
|||||||
|
|
||||||
log.info("========== 物流链接不一致,已加入更新队列 - 单号: {}, 行号: {}, 旧链接: {}, 新链接: {} ==========",
|
log.info("========== 物流链接不一致,已加入更新队列 - 单号: {}, 行号: {}, 旧链接: {}, 新链接: {} ==========",
|
||||||
orderNo, excelRow, trimmedExistingLink, trimmedDbLink);
|
orderNo, excelRow, trimmedExistingLink, trimmedDbLink);
|
||||||
} else if (needJdOrderIdUpdate) {
|
|
||||||
JSONObject update = new JSONObject();
|
|
||||||
update.put("row", excelRow);
|
|
||||||
update.put("orderNo", orderNo);
|
|
||||||
update.put("isJdOrderIdOnlyUpdate", true);
|
|
||||||
update.put("jdOrderId", dbJdOrderId);
|
|
||||||
update.put("jdOrderIdColumn", jdPlaceOrderNoColumn);
|
|
||||||
updates.add(update);
|
|
||||||
filledCount++;
|
|
||||||
log.info("========== 需补充/更新京东下单订单号 - 第三方单号: {}, 行: {}, 文档: [{}], 系统: [{}] ==========",
|
|
||||||
orderNo, excelRow, docJdOrderId, dbJdOrderId);
|
|
||||||
} else {
|
} else {
|
||||||
// 物流链接一致或数据库中没有链接,只需同步订单状态
|
// 物流链接一致或数据库中没有链接,只需同步订单状态
|
||||||
if (existingOrder.getTencentDocPushed() == null || existingOrder.getTencentDocPushed() == 0) {
|
if (existingOrder.getTencentDocPushed() == null || existingOrder.getTencentDocPushed() == 0) {
|
||||||
@@ -1459,11 +1443,6 @@ 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);
|
||||||
|
|
||||||
@@ -1526,83 +1505,6 @@ 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++;
|
|
||||||
Map<String, Object> errorLog = new java.util.HashMap<>();
|
|
||||||
errorLog.put("orderNo", expectedOrderNo);
|
|
||||||
errorLog.put("row", row);
|
|
||||||
errorLog.put("errorType", "验证失败");
|
|
||||||
errorLog.put("errorMessage", "无法读取行数据(京东单号)");
|
|
||||||
errorLogs.add(errorLog);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
JSONArray jdVerifyRows = jdVerifyData.getJSONArray("values");
|
|
||||||
if (jdVerifyRows == null || jdVerifyRows.isEmpty()) {
|
|
||||||
errorCount++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
JSONArray jdVerifyRow = jdVerifyRows.getJSONArray(0);
|
|
||||||
int jdNeedIdx = Math.max(orderNoColumn, jdCol);
|
|
||||||
if (jdVerifyRow == null || jdVerifyRow.size() <= jdNeedIdx) {
|
|
||||||
errorCount++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String jdCurOrderNo = jdVerifyRow.getString(orderNoColumn);
|
|
||||||
if (jdCurOrderNo == null || !jdCurOrderNo.trim().equals(expectedOrderNo)) {
|
|
||||||
errorCount++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String docJd = "";
|
|
||||||
if (jdVerifyRow.size() > jdCol) {
|
|
||||||
try {
|
|
||||||
String sj = jdVerifyRow.getString(jdCol);
|
|
||||||
docJd = sj != null ? sj.trim() : "";
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (docJd.equals(jdId)) {
|
|
||||||
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);
|
||||||
@@ -1741,9 +1643,12 @@ public class TencentDocController extends BaseController {
|
|||||||
log.info("✓ 物流链接更新,保留原标记日期 - 单号: {}, 行: {}", expectedOrderNo, row);
|
log.info("✓ 物流链接更新,保留原标记日期 - 单号: {}, 行: {}", expectedOrderNo, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 仅物流变更时顺带写京东单号;文档该列已有内容则不写入
|
||||||
|
boolean wroteJdOrderIdCell = false;
|
||||||
|
String jdIdUpdForLog = null;
|
||||||
Integer jdColUpd = update.getInteger("jdOrderIdColumn");
|
Integer jdColUpd = update.getInteger("jdOrderIdColumn");
|
||||||
String jdIdUpd = update.getString("jdOrderId");
|
String jdIdUpd = update.getString("jdOrderId");
|
||||||
if (jdColUpd != null && jdIdUpd != null && !jdIdUpd.trim().isEmpty()) {
|
if (Boolean.TRUE.equals(isLinkUpdated) && 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) {
|
||||||
@@ -1754,10 +1659,13 @@ public class TencentDocController extends BaseController {
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean syncJd = Boolean.TRUE.equals(isLinkUpdated) || docJdVal.isEmpty() || !docJdVal.equals(jdIdUpd);
|
if (docJdVal.isEmpty()) {
|
||||||
if (syncJd) {
|
|
||||||
requests.add(buildUpdateCellRequest(sheetId, row - 1, jdColUpd, jdIdUpd, false));
|
requests.add(buildUpdateCellRequest(sheetId, row - 1, jdColUpd, jdIdUpd, false));
|
||||||
log.info("✓ 准备写入京东下单订单号 - 第三方单号: {}, 行: {}, 值: {}", expectedOrderNo, row, jdIdUpd);
|
wroteJdOrderIdCell = true;
|
||||||
|
jdIdUpdForLog = jdIdUpd;
|
||||||
|
log.info("✓ 准备写入京东下单订单号(随物流变更) - 第三方单号: {}, 行: {}, 值: {}", expectedOrderNo, row, jdIdUpd);
|
||||||
|
} else {
|
||||||
|
log.info("✓ 文档已有京东下单订单号,跳过写入 - 第三方单号: {}, 行: {}, 现有: [{}]", expectedOrderNo, row, docJdVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1816,8 +1724,8 @@ public class TencentDocController extends BaseController {
|
|||||||
if (orderToUpdate != null && orderToUpdate.getModelNumber() != null) {
|
if (orderToUpdate != null && orderToUpdate.getModelNumber() != null) {
|
||||||
successLog.put("modelNumber", orderToUpdate.getModelNumber());
|
successLog.put("modelNumber", orderToUpdate.getModelNumber());
|
||||||
}
|
}
|
||||||
if (jdIdUpd != null && !jdIdUpd.trim().isEmpty()) {
|
if (wroteJdOrderIdCell && jdIdUpdForLog != null) {
|
||||||
successLog.put("jdOrderId", jdIdUpd.trim());
|
successLog.put("jdOrderId", jdIdUpdForLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否为物流链接更新(复用之前的变量)
|
// 检查是否为物流链接更新(复用之前的变量)
|
||||||
|
|||||||
@@ -204,7 +204,6 @@ 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;
|
||||||
@@ -219,13 +218,10 @@ 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 (TencentDocDataParser.isJdPlaceOrderNoHeader(cellText)) {
|
if (cellText.contains("日期")) dateColumn = i;
|
||||||
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("物流")) orderNoColumn = i;
|
else if (cellText.contains("单号") && !cellText.contains("物流")
|
||||||
|
&& !TencentDocDataParser.isJdPlaceOrderNoHeader(cellText)) orderNoColumn = i;
|
||||||
else if (cellText.contains("型号")) modelColumn = i;
|
else if (cellText.contains("型号")) modelColumn = i;
|
||||||
else if (cellText.contains("数量")) quantityColumn = i;
|
else if (cellText.contains("数量")) quantityColumn = i;
|
||||||
else if (cellText.contains("姓名")) nameColumn = i;
|
else if (cellText.contains("姓名")) nameColumn = i;
|
||||||
@@ -242,7 +238,7 @@ public class TencentDocServiceImpl implements ITencentDocService {
|
|||||||
throw new RuntimeException("未找到'单号'列,请检查表头配置");
|
throw new RuntimeException("未找到'单号'列,请检查表头配置");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("表头识别完成 - 单号列: {}, 京东下单订单号列: {}, 物流列: {}", orderNoColumn, jdPlaceOrderNoColumn, logisticsColumn);
|
log.info("表头识别完成 - 单号列: {}, 物流列: {}", orderNoColumn, 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);
|
||||||
@@ -298,9 +294,6 @@ 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