mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
fix(order-import): 修复订单导入时下单时间为空的更新策略
- CreateOrderDTO 新增 orderTimeEmptyInInput 字段,用于标识导入输入的下单时间是否为空 - ImportRuntimeContext.PendingOrderInsert 新增 orderTimeEmptyInInput 追踪,解决重复平台订单号合并时的状态传递 - OrderImportProcessor 优化更新跳过逻辑:当导入行下单时间为空且 order_time 已配置映射时,跳过本次更新操作,避免误覆盖其他字段 - 解析失败时保持「创建时用当前时间兜底」的一致性行为
This commit is contained in:
+12
-2
@@ -83,24 +83,34 @@ public class ImportRuntimeContext {
|
||||
public int rowNumber;
|
||||
public String platformOrderNo;
|
||||
public OrderPO order;
|
||||
/**
|
||||
* 该导入行输入的 order_time 是否为空(仅用于更新跳过策略)。
|
||||
* <p>
|
||||
* 创建阶段不受此字段影响:创建时仍会用当前时间兜底。
|
||||
*/
|
||||
public boolean orderTimeEmptyInInput;
|
||||
public Long existingOrderId; // 不为空表示是更新操作
|
||||
public StringBuilder updateMessages;
|
||||
|
||||
public PendingOrderInsert(int rowNumber, String platformOrderNo, OrderPO order,
|
||||
Long existingOrderId, StringBuilder updateMessages) {
|
||||
Long existingOrderId, StringBuilder updateMessages,
|
||||
boolean orderTimeEmptyInInput) {
|
||||
this.rowNumber = rowNumber;
|
||||
this.platformOrderNo = platformOrderNo;
|
||||
this.order = order;
|
||||
this.orderTimeEmptyInInput = orderTimeEmptyInInput;
|
||||
this.existingOrderId = existingOrderId;
|
||||
this.updateMessages = updateMessages;
|
||||
}
|
||||
|
||||
public void updateData(OrderPO newOrder, Long newExistingOrderId,
|
||||
StringBuilder newUpdateMsg, int newRowNumber) {
|
||||
StringBuilder newUpdateMsg, int newRowNumber,
|
||||
boolean newOrderTimeEmptyInInput) {
|
||||
this.order = newOrder;
|
||||
this.rowNumber = newRowNumber;
|
||||
if (newExistingOrderId != null) this.existingOrderId = newExistingOrderId;
|
||||
if (newUpdateMsg != null && newUpdateMsg.length() > 0) this.updateMessages = newUpdateMsg;
|
||||
this.orderTimeEmptyInInput = newOrderTimeEmptyInInput;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+32
-6
@@ -805,18 +805,24 @@ public class OrderImportProcessor {
|
||||
|
||||
if (orderDateField != null) {
|
||||
String dateStr = getValue(rowData, orderDateField);
|
||||
if (dateStr != null && !dateStr.trim().isEmpty()) {
|
||||
boolean emptyInInput = (dateStr == null || dateStr.trim().isEmpty());
|
||||
dto.setOrderTimeEmptyInInput(emptyInInput);
|
||||
if (!emptyInInput) {
|
||||
LocalDateTime dateTime = parseDateTime(dateStr, context);
|
||||
if (dateTime != null) {
|
||||
dto.setOrderTime(dateTime);
|
||||
} else {
|
||||
// 输入非空但解析失败:保持「创建逻辑不变」的兜底行为,填充当前时间
|
||||
dto.setOrderTime(LocalDateTime.now());
|
||||
}
|
||||
} else {
|
||||
// 输入为空:保持「创建逻辑不变」的兜底行为,填充当前时间
|
||||
dto.setOrderTime(LocalDateTime.now());
|
||||
}
|
||||
} else {
|
||||
dto.setOrderTime(LocalDateTime.now());
|
||||
// 未配置映射:不参与「更新跳过」判定
|
||||
dto.setOrderTimeEmptyInInput(false);
|
||||
}
|
||||
|
||||
return dto;
|
||||
@@ -1073,7 +1079,8 @@ public class OrderImportProcessor {
|
||||
r.order,
|
||||
r.rowNumber,
|
||||
r.order != null ? r.order.getId() : null,
|
||||
updateMsg)) {
|
||||
updateMsg,
|
||||
r.dto != null && Boolean.TRUE.equals(r.dto.getOrderTimeEmptyInInput()))) {
|
||||
context.mergedDuplicatePlatformNoCount.incrementAndGet();
|
||||
continue;
|
||||
}
|
||||
@@ -1081,7 +1088,8 @@ public class OrderImportProcessor {
|
||||
ImportRuntimeContext.PendingOrderInsert pending =
|
||||
new ImportRuntimeContext.PendingOrderInsert(
|
||||
r.rowNumber, r.platformOrderNo, r.order,
|
||||
r.order.getId(), updateMsg);
|
||||
r.order.getId(), updateMsg,
|
||||
r.dto != null && Boolean.TRUE.equals(r.dto.getOrderTimeEmptyInInput()));
|
||||
context.pendingOrders.add(pending);
|
||||
if (r.platformOrderNo != null && !r.platformOrderNo.trim().isEmpty()) {
|
||||
synchronized (context.pendingOrderByPlatformNo) {
|
||||
@@ -1146,6 +1154,16 @@ public class OrderImportProcessor {
|
||||
|
||||
for (ImportRuntimeContext.PendingOrderInsert p : updates) {
|
||||
String normalized = p.platformOrderNo != null ? p.platformOrderNo.trim() : null;
|
||||
// 更新策略:当导入行输入的下单时间为空时,直接跳过本次 UPDATE(不改其它字段)
|
||||
if (p.orderTimeEmptyInInput
|
||||
&& context.getOrderImportFieldMapping().containsKey("order_time")) {
|
||||
updateSkippedUnchanged++;
|
||||
if (p.platformOrderNo != null && !p.platformOrderNo.trim().isEmpty()) {
|
||||
context.pendingPlatformOrderNos.remove(normalized);
|
||||
context.existingPlatformOrderNos.add(normalized);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
OrderPO dbSnap = normalized != null ? context.existingOrderSnapshotByPlatformNo.get(normalized) : null;
|
||||
boolean unchanged = dbSnap != null && isOrderImportContentUnchanged(dbSnap, p.order, context.getOrderImportFieldMapping());
|
||||
if (unchanged) {
|
||||
@@ -1533,18 +1551,24 @@ public class OrderImportProcessor {
|
||||
// 订单日期
|
||||
if (orderDateField != null) {
|
||||
String dateStr = getValue(record, orderDateField);
|
||||
if (dateStr != null && !dateStr.trim().isEmpty()) {
|
||||
boolean emptyInInput = (dateStr == null || dateStr.trim().isEmpty());
|
||||
dto.setOrderTimeEmptyInInput(emptyInInput);
|
||||
if (!emptyInInput) {
|
||||
LocalDateTime dateTime = parseDateTime(dateStr, context);
|
||||
if (dateTime != null) {
|
||||
dto.setOrderTime(dateTime);
|
||||
} else {
|
||||
// 输入非空但解析失败:保持「创建逻辑不变」的兜底行为,填充当前时间
|
||||
dto.setOrderTime(LocalDateTime.now());
|
||||
}
|
||||
} else {
|
||||
// 输入为空:保持「创建逻辑不变」的兜底行为,填充当前时间
|
||||
dto.setOrderTime(LocalDateTime.now());
|
||||
}
|
||||
} else {
|
||||
dto.setOrderTime(LocalDateTime.now());
|
||||
// 未配置映射:不参与「更新跳过」判定
|
||||
dto.setOrderTimeEmptyInInput(false);
|
||||
}
|
||||
|
||||
return dto;
|
||||
@@ -1592,7 +1616,8 @@ public class OrderImportProcessor {
|
||||
*/
|
||||
private boolean validatePlatformOrderNo(String platformOrderNo, ImportRuntimeContext context,
|
||||
OrderPO newOrderPO, int newRowNumber,
|
||||
Long newExistingOrderId, StringBuilder newUpdateMsg) {
|
||||
Long newExistingOrderId, StringBuilder newUpdateMsg,
|
||||
boolean newOrderTimeEmptyInInput) {
|
||||
if (platformOrderNo == null || platformOrderNo.trim().isEmpty()) return false;
|
||||
String normalized = platformOrderNo.trim();
|
||||
|
||||
@@ -1606,7 +1631,8 @@ public class OrderImportProcessor {
|
||||
ImportRuntimeContext.PendingOrderInsert existing =
|
||||
context.pendingOrderByPlatformNo.get(normalized);
|
||||
if (existing != null) {
|
||||
existing.updateData(newOrderPO, existingId, newUpdateMsg, newRowNumber);
|
||||
existing.updateData(newOrderPO, existingId, newUpdateMsg, newRowNumber,
|
||||
newOrderTimeEmptyInInput);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
+9
@@ -49,6 +49,15 @@ public class CreateOrderDTO {
|
||||
@NotNull(message = "下单时间不能为空")
|
||||
private LocalDateTime orderTime;
|
||||
|
||||
/**
|
||||
* 导入时输入的下单时间是否为空(仅用于「更新时跳过」的业务决策)。
|
||||
* <p>
|
||||
* 注意:即便输入为空,orderTime 在创建/解析阶段仍会被填充为当前时间;
|
||||
* 该字段用于区分「输入是否为空」而不是区分 orderTime 是否为空。
|
||||
*/
|
||||
@Schema(description = "导入时下单时间是否为空(仅用于更新跳过逻辑)")
|
||||
private Boolean orderTimeEmptyInInput;
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user