This commit is contained in:
van
2026-05-06 17:38:58 +08:00
parent 9d03cca517
commit 7582868b2c
4 changed files with 303 additions and 62 deletions

View File

@@ -33,6 +33,11 @@ public class GoofishOrderChangeLogger {
*/
public static final String SOURCE_JD_LOGISTICS_PUSH = "JD_LOGISTICS_PUSH";
/**
* Redis 写入本地运单:与后续详情运单合并、发货成功通知重复度高,仅落库便于对账,不推企微。
*/
public static final String SOURCE_REDIS_WAYBILL = "REDIS_WAYBILL";
@Resource
private ErpGoofishOrderEventLogMapper erpGoofishOrderEventLogMapper;
@@ -40,6 +45,14 @@ public class GoofishOrderChangeLogger {
private WxSendGoofishNotifyClient wxSendGoofishNotifyClient;
public void append(Long orderId, String appKey, String orderNo, String eventType, String source, String message) {
append(orderId, appKey, orderNo, eventType, source, message, true);
}
/**
* @param notifyWecom 为 false 时仅写事件日志,不推企微(用于过滤纯对齐类状态)。
*/
public void append(Long orderId, String appKey, String orderNo, String eventType, String source, String message,
boolean notifyWecom) {
if (orderId == null || StringUtils.isEmpty(message)) {
return;
}
@@ -59,7 +72,10 @@ public class GoofishOrderChangeLogger {
return;
}
log.info("[goofish-order-event] orderId={} orderNo={} type={} source={} {}", orderId, orderNo, eventType, source, msg);
if (SOURCE_JD_LOGISTICS_PUSH.equals(source)) {
if (SOURCE_JD_LOGISTICS_PUSH.equals(source) || SOURCE_REDIS_WAYBILL.equals(source)) {
return;
}
if (!notifyWecom) {
return;
}
try {
@@ -82,16 +98,21 @@ public class GoofishOrderChangeLogger {
RowSnap b = RowSnap.from(beforeSnap);
RowSnap a = RowSnap.from(afterRow);
boolean refundDiff = !Objects.equals(b.refundStatus, a.refundStatus);
boolean orderDiff = !Objects.equals(b.orderStatus, a.orderStatus);
List<String> orderParts = new ArrayList<>();
if (!Objects.equals(b.orderStatus, a.orderStatus)) {
orderParts.add("订单状态 " + GoofishStatusLabels.orderStatusChange(b.orderStatus, a.orderStatus));
if (orderDiff) {
orderParts.add("订单状态 " + GoofishStatusLabels.orderStatusChangeForNotify(b.orderStatus, a.orderStatus));
}
if (!Objects.equals(b.refundStatus, a.refundStatus)) {
if (refundDiff) {
orderParts.add("退款状态 " + GoofishStatusLabels.refundStatusChange(b.refundStatus, a.refundStatus));
}
if (!orderParts.isEmpty()) {
boolean notifyWecom = refundDiff || (orderDiff
&& GoofishStatusLabels.isWxNotifiableOrderStatusChange(b.orderStatus, a.orderStatus));
append(afterRow.getId(), afterRow.getAppKey(), afterRow.getOrderNo(), TYPE_ORDER, source,
String.join("", orderParts));
String.join("", orderParts), notifyWecom);
}
List<String> logParts = new ArrayList<>();

View File

@@ -143,17 +143,27 @@ public class GoofishOrderPipeline {
if (existingBeforeUpdate == null) {
goofishOrderChangeLogger.append(loaded.getId(), loaded.getAppKey(), loaded.getOrderNo(),
GoofishOrderChangeLogger.TYPE_ORDER, upsertSource,
"新订单入库,订单状态 " + GoofishStatusLabels.orderStatusHuman(loaded.getOrderStatus())
"新订单入库,订单状态 " + GoofishStatusLabels.orderStatusHumanForNotify(loaded.getOrderStatus())
+ ",退款状态 " + GoofishStatusLabels.refundStatusHuman(loaded.getRefundStatus()));
return;
}
if (!Objects.equals(existingBeforeUpdate.getOrderStatus(), upsertPayload.getOrderStatus())
|| !Objects.equals(existingBeforeUpdate.getRefundStatus(), upsertPayload.getRefundStatus())) {
boolean refundDiff = !Objects.equals(existingBeforeUpdate.getRefundStatus(), upsertPayload.getRefundStatus());
boolean orderDiff = !Objects.equals(existingBeforeUpdate.getOrderStatus(), upsertPayload.getOrderStatus());
if (orderDiff || refundDiff) {
List<String> parts = new ArrayList<>(2);
if (orderDiff) {
parts.add("订单状态 " + GoofishStatusLabels.orderStatusChangeForNotify(
existingBeforeUpdate.getOrderStatus(), upsertPayload.getOrderStatus()));
}
if (refundDiff) {
parts.add("退款状态 " + GoofishStatusLabels.refundStatusChange(
existingBeforeUpdate.getRefundStatus(), upsertPayload.getRefundStatus()));
}
boolean notifyWecom = refundDiff || (orderDiff && GoofishStatusLabels.isWxNotifiableOrderStatusChange(
existingBeforeUpdate.getOrderStatus(), upsertPayload.getOrderStatus()));
goofishOrderChangeLogger.append(loaded.getId(), loaded.getAppKey(), loaded.getOrderNo(),
GoofishOrderChangeLogger.TYPE_ORDER, upsertSource,
"订单状态 " + GoofishStatusLabels.orderStatusChange(existingBeforeUpdate.getOrderStatus(), upsertPayload.getOrderStatus())
+ ";退款状态 " + GoofishStatusLabels.refundStatusChange(
existingBeforeUpdate.getRefundStatus(), upsertPayload.getRefundStatus()));
String.join("", parts), notifyWecom);
}
}
@@ -425,7 +435,7 @@ public class GoofishOrderPipeline {
row.setLocalWaybillNo(wb.trim());
if (goofishOrderChangeLogger != null) {
goofishOrderChangeLogger.append(row.getId(), row.getAppKey(), row.getOrderNo(),
GoofishOrderChangeLogger.TYPE_LOGISTICS, "REDIS_WAYBILL",
GoofishOrderChangeLogger.TYPE_LOGISTICS, GoofishOrderChangeLogger.SOURCE_REDIS_WAYBILL,
"本地运单 " + (prev == null || prev.isEmpty() ? "" : prev) + "" + wb.trim());
}
}
@@ -532,7 +542,9 @@ public class GoofishOrderPipeline {
if (goofishOrderChangeLogger != null) {
goofishOrderChangeLogger.append(row.getId(), row.getAppKey(), row.getOrderNo(),
GoofishOrderChangeLogger.TYPE_SHIP, "AUTO_SHIP",
"发货成功,运单 " + waybill.trim() + ",快递编码 " + expressCode);
"发货成功,运单 " + waybill.trim()
+ ",订单状态 " + GoofishStatusLabels.orderStatusHuman(row.getOrderStatus())
+ ",退款状态 " + GoofishStatusLabels.refundStatusHuman(row.getRefundStatus()));
}
} else {
String msg = r != null ? r.getString("msg") : "unknown";

View File

@@ -2,6 +2,7 @@ package com.ruoyi.jarvis.service.goofish;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* 闲管家开放平台:订单状态、退款状态中文说明(与 Apifox 订单列表 schema 一致)
@@ -79,6 +80,45 @@ public final class GoofishStatusLabels {
return orderStatusHuman(from) + "" + orderStatusHuman(to);
}
/**
* 快照/首行展示:待发阶段注明已付款语义(开放平台码 12 即待发货)。
*/
public static String orderStatusHumanForNotify(Integer s) {
if (Objects.equals(s, 12)) {
return "待发货(已付款)";
}
return orderStatusHuman(s);
}
/**
* 企微通知用变化文案:付款完成单独写「已付款(待发货)」。
*/
public static String orderStatusChangeForNotify(Integer from, Integer to) {
if (Objects.equals(from, 11) && Objects.equals(to, 12)) {
return orderStatusHuman(11) + " → 已付款(待发货)";
}
return orderStatusHuman(from) + "" + orderStatusHumanForNotify(to);
}
/**
* 是否与「付款、待发、在途、终态退款/完成/关闭」相关,从而值得推企微(排除已由 SHIP 覆盖的待发→已发)。
*/
public static boolean isWxNotifiableOrderStatusChange(Integer from, Integer to) {
if (Objects.equals(from, to)) {
return false;
}
if (Objects.equals(from, 12) && Objects.equals(to, 21)) {
return false;
}
int[] anchors = {11, 12, 21, 22, 23, 24};
for (int code : anchors) {
if (Objects.equals(from, code) || Objects.equals(to, code)) {
return true;
}
}
return false;
}
public static String refundStatusChange(Integer from, Integer to) {
return refundStatusHuman(from) + "" + refundStatusHuman(to);
}