This commit is contained in:
van
2026-04-01 16:59:29 +08:00
parent 9ae74c999e
commit 75d7c8e6de
6 changed files with 108 additions and 49 deletions

View File

@@ -17,6 +17,16 @@ public interface ILogisticsService {
* 分享类京东物流短链:查运单并通过 wxts 推送到指定 touser不依赖订单表
*/
boolean fetchLogisticsByShareLinkAndPush(String trackingUrl, String remark, String touser);
/**
* 企微备注提交后仅入队,由 {@link com.ruoyi.jarvis.task.LogisticsScanTask} 与订单扫描一并拉取物流,避免阻塞 HTTP 回调。
*/
void enqueueShareLinkForScan(String trackingUrl, String remark, String touser);
/**
* 定时任务内:依次弹出队列并调用 {@link #fetchLogisticsByShareLinkAndPush}。
*/
void drainPendingShareLinkQueue();
/**
* 检查订单是否已处理过Redis中是否有运单号

View File

@@ -35,6 +35,8 @@ public class LogisticsServiceImpl implements ILogisticsService {
private static final String REDIS_LOCK_KEY_PREFIX = "logistics:lock:order:";
private static final String REDIS_HEALTH_CHECK_ALERT_KEY = "logistics:health:alert:";
private static final String REDIS_ADHOC_WAYBILL_PREFIX = "logistics:adhoc:waybill:";
/** 企微分享链+备注入队FIFORPUSH 入队、LPOP 出队 */
private static final String REDIS_ADHOC_PENDING_QUEUE = "logistics:adhoc:pending:queue";
private static final String PUSH_URL = "https://wxts.van333.cn/wx/send/pdd";
private static final String PUSH_TOKEN = "super_token_b62190c26";
private static final String CONFIG_KEY_PREFIX = "logistics.push.touser.";
@@ -49,6 +51,9 @@ public class LogisticsServiceImpl implements ILogisticsService {
@Value("${jarvis.server.logistics.health-path:/health}")
private String logisticsHealthPath;
@Value("${jarvis.server.logistics.adhoc-pending-batch-size:50}")
private int adhocPendingBatchSize;
private String externalApiUrlTemplate;
private String healthCheckUrl;
@@ -423,6 +428,43 @@ public class LogisticsServiceImpl implements ILogisticsService {
}
}
@Override
public void enqueueShareLinkForScan(String trackingUrl, String remark, String touser) {
if (!StringUtils.hasText(trackingUrl)) {
logger.warn("adhoc 入队跳过:分享链接为空");
return;
}
JSONObject o = new JSONObject();
o.put("trackingUrl", trackingUrl.trim());
o.put("remark", remark != null ? remark : "");
o.put("touser", touser != null ? touser : "");
stringRedisTemplate.opsForList().rightPush(REDIS_ADHOC_PENDING_QUEUE, o.toJSONString());
logger.info("adhoc 分享链接已入队待定时扫描(与订单物流任务一致) trackingUrl={} queueKey={}", trackingUrl.trim(), REDIS_ADHOC_PENDING_QUEUE);
}
@Override
public void drainPendingShareLinkQueue() {
int n = Math.max(1, adhocPendingBatchSize);
for (int i = 0; i < n; i++) {
String json = stringRedisTemplate.opsForList().leftPop(REDIS_ADHOC_PENDING_QUEUE);
if (json == null || !StringUtils.hasText(json)) {
break;
}
try {
JSONObject o = JSON.parseObject(json);
if (o == null) {
continue;
}
String url = o.getString("trackingUrl");
String remark = o.getString("remark");
String touser = o.getString("touser");
fetchLogisticsByShareLinkAndPush(url, remark, touser);
} catch (Exception e) {
logger.error("adhoc 队列项处理失败 raw={}", json.length() > 200 ? json.substring(0, 200) + "..." : json, e);
}
}
}
@Override
public boolean fetchLogisticsByShareLinkAndPush(String trackingUrl, String remark, String touser) {
if (!StringUtils.hasText(trackingUrl)) {

View File

@@ -82,8 +82,8 @@ public class WeComInboundServiceImpl implements IWeComInboundService {
weComChatSessionService.delete(from);
String touser = resolveTouser(row, isSuper);
log.info("企微物流会话提交备注 user={} url={} remarkLen={}", from, url, t.length());
boolean ok = logisticsService.fetchLogisticsByShareLinkAndPush(url, content.trim(), touser);
return ok ? "已查询并推送运单(接收人见超级管理员 touser" : "物流查询或推送失败,请稍后重试";
logisticsService.enqueueShareLinkForScan(url, content.trim(), touser);
return "已登记备注物流将随定时任务查询并推送与订单物流扫描一致约每10分钟";
}
}