This commit is contained in:
van
2026-04-10 01:00:10 +08:00
parent 52d0adfc85
commit 042068ccf1
5 changed files with 53 additions and 6 deletions

View File

@@ -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")

View File

@@ -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<ErpGoofishOrderEventLog> listEventLogsByOrderId(Long orderId);

View File

@@ -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) {

View File

@@ -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<ErpGoofishOrder> 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<ErpGoofishOrderEventLog> listEventLogsByOrderId(Long orderId) {
if (orderId == null) {

View File

@@ -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) {