diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/domain/ErpGoofishOrderEventLog.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/domain/ErpGoofishOrderEventLog.java index 98bb828..3d4d973 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/domain/ErpGoofishOrderEventLog.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/domain/ErpGoofishOrderEventLog.java @@ -18,7 +18,7 @@ public class ErpGoofishOrderEventLog { private String orderNo; /** ORDER_SYNC / LOGISTICS_SYNC / SHIP */ private String eventType; - /** NOTIFY、LIST、DETAIL_REFRESH、UPSERT、REDIS_WAYBILL、AUTO_SHIP 等 */ + /** NOTIFY、LIST、DETAIL_REFRESH、JD_LOGISTICS_PUSH、REDIS_WAYBILL、AUTO_SHIP 等 */ private String source; private String message; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IErpGoofishOrderService.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IErpGoofishOrderService.java index d2e6db4..b7d374d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IErpGoofishOrderService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IErpGoofishOrderService.java @@ -42,6 +42,9 @@ public interface IErpGoofishOrderService { */ void notifyJdWaybillReady(Long jdOrderId); + /** 京东物流服务在写 Redis / 企微货主推送后、触发闲鱼同步前记一笔(source=JD_LOGISTICS_PUSH)。 */ + void traceJdLogisticsPushForGoofish(Long jdOrderId, String waybillNo, String summary); + /** 订单状态 / 物流 / 发货 变更日志(新→旧) */ List listEventLogsByOrderId(Long orderId); diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/goofish/GoofishOrderChangeLogger.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/goofish/GoofishOrderChangeLogger.java index b978dd9..ae4e8d9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/goofish/GoofishOrderChangeLogger.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/goofish/GoofishOrderChangeLogger.java @@ -28,6 +28,9 @@ public class GoofishOrderChangeLogger { public static final String TYPE_LOGISTICS = "LOGISTICS_SYNC"; public static final String TYPE_SHIP = "SHIP"; + /** 京东物流扫描服务:Redis + 企微货主推送链路(见 LogisticsServiceImpl),不再二次走 wxSend 闲鱼应用避免重复打扰 */ + public static final String SOURCE_JD_LOGISTICS_PUSH = "JD_LOGISTICS_PUSH"; + @Resource private ErpGoofishOrderEventLogMapper erpGoofishOrderEventLogMapper; @@ -54,6 +57,9 @@ 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)) { + return; + } try { wxSendGoofishNotifyClient.notifyGoofishEvent(orderNo, eventType, source, msg); } catch (Exception ex) { diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/ErpGoofishOrderServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/ErpGoofishOrderServiceImpl.java index 917978a..55744d1 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/ErpGoofishOrderServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/ErpGoofishOrderServiceImpl.java @@ -13,6 +13,7 @@ import com.ruoyi.jarvis.mapper.ErpGoofishOrderMapper; import com.ruoyi.jarvis.service.IErpGoofishOrderService; import com.ruoyi.jarvis.service.IErpOpenConfigService; import com.ruoyi.jarvis.service.goofish.GoofishNotifyAsyncFacade; +import com.ruoyi.jarvis.service.goofish.GoofishOrderChangeLogger; import com.ruoyi.jarvis.service.goofish.GoofishOrderPipeline; import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.factory.ObjectProvider; @@ -47,6 +48,9 @@ public class ErpGoofishOrderServiceImpl implements IErpGoofishOrderService { @Resource private IErpOpenConfigService erpOpenConfigService; + @Resource + private GoofishOrderChangeLogger goofishOrderChangeLogger; + @Override public void publishOrProcessNotify(String appid, Long timestamp, JSONObject body) { RocketMQTemplate mq = rocketMQTemplate.getIfAvailable(); @@ -167,6 +171,32 @@ public class ErpGoofishOrderServiceImpl implements IErpGoofishOrderService { } } + @Override + public void traceJdLogisticsPushForGoofish(Long jdOrderId, String waybillNo, String summary) { + if (jdOrderId == null || goofishOrderChangeLogger == null) { + return; + } + ErpGoofishOrder query = new ErpGoofishOrder(); + query.setJdOrderId(jdOrderId); + List list = erpGoofishOrderMapper.selectList(query); + if (list == null || list.isEmpty()) { + return; + } + String wb = waybillNo != null ? waybillNo.trim() : ""; + String sum = summary != null ? summary : ""; + String msg = "jdOrderId=" + jdOrderId + " waybill=" + wb + ";" + sum; + if (msg.length() > 1000) { + msg = msg.substring(0, 999) + "…"; + } + for (ErpGoofishOrder row : list) { + if (row.getId() == null) { + continue; + } + goofishOrderChangeLogger.append(row.getId(), row.getAppKey(), row.getOrderNo(), + GoofishOrderChangeLogger.TYPE_LOGISTICS, GoofishOrderChangeLogger.SOURCE_JD_LOGISTICS_PUSH, msg); + } + } + @Override public List listEventLogsByOrderId(Long orderId) { if (orderId == null) { diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/LogisticsServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/LogisticsServiceImpl.java index abf6a55..576c56d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/LogisticsServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/LogisticsServiceImpl.java @@ -219,9 +219,13 @@ public class LogisticsServiceImpl implements ILogisticsService { } } - /** 京东单已写入 Redis 运单后,联动闲鱼单同步并发货(失败不影响物流主流程) */ - private void safeNotifyGoofishShip(Long jdOrderId) { + /** + * 京东单已写入 Redis 运单后,联动闲鱼单同步并发货(失败不影响物流主流程)。 + * 若存在关联闲鱼单,会先写入事件来源 JD_LOGISTICS_PUSH,便于与 REDIS_WAYBILL / AUTO_SHIP 对照。 + */ + private void safeNotifyGoofishShip(Long jdOrderId, String waybillNo, String traceSummary) { try { + erpGoofishOrderService.traceJdLogisticsPushForGoofish(jdOrderId, waybillNo, traceSummary); erpGoofishOrderService.notifyJdWaybillReady(jdOrderId); } catch (Exception e) { logger.warn("闲鱼发货联动异常 jdOrderId={} err={}", jdOrderId, e.toString()); @@ -388,7 +392,8 @@ public class LogisticsServiceImpl implements ILogisticsService { logger.info("订单运单号已存在且一致,说明之前已推送过,跳过重复推送 - 订单ID: {}, waybill_no: {}", orderId, waybillNo); // 更新过期时间,确保记录不会过期 stringRedisTemplate.opsForValue().set(redisKey, waybillNo, 30, TimeUnit.DAYS); - safeNotifyGoofishShip(orderId); + safeNotifyGoofishShip(orderId, waybillNo, + "Redis 运单与本次一致,跳过重复企微推送;已刷新 TTL;随后触发闲鱼同步"); return true; } @@ -406,7 +411,8 @@ public class LogisticsServiceImpl implements ILogisticsService { logger.info("订单创建时间较早({}),且Redis中无记录但已获取到运单号,视为之前已推送过,直接标记为已处理,跳过推送 - 订单ID: {}, waybill_no: {}", order.getCreateTime(), orderId, waybillNo); stringRedisTemplate.opsForValue().set(redisKey, waybillNo, 30, TimeUnit.DAYS); - safeNotifyGoofishShip(orderId); + safeNotifyGoofishShip(orderId, waybillNo, + "老单兜底:直写 Redis,跳过企微;随后触发闲鱼同步"); return true; } } @@ -433,7 +439,9 @@ public class LogisticsServiceImpl implements ILogisticsService { // 更新过期时间,确保记录不会过期 stringRedisTemplate.opsForValue().set(redisKey, waybillNo, 30, TimeUnit.DAYS); } - safeNotifyGoofishShip(orderId); + safeNotifyGoofishShip(orderId, waybillNo, + "企微货主推送成功;" + (logisticsLinkUpdated ? "物流链接已更新;" : "物流链接未变;") + + "Redis 已写入;随后触发闲鱼同步"); // 记录最终处理结果 if (logisticsLinkUpdated) {