From d4fdf076e98024f89dc1d7a9779343f8a31277a3 Mon Sep 17 00:00:00 2001 From: van Date: Fri, 3 Apr 2026 01:18:33 +0800 Subject: [PATCH] 1 --- .../WeComShareLinkLogisticsJobController.java | 4 +++ .../jarvis/service/ILogisticsService.java | 7 ++++ .../service/impl/LogisticsServiceImpl.java | 33 ++++++++++++++----- ...WeComShareLinkLogisticsJobServiceImpl.java | 9 +++++ 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/WeComShareLinkLogisticsJobController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/WeComShareLinkLogisticsJobController.java index 5c9b639..b1c4fe7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/WeComShareLinkLogisticsJobController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/WeComShareLinkLogisticsJobController.java @@ -88,6 +88,10 @@ public class WeComShareLinkLogisticsJobController extends BaseController { StringUtils.hasText(wb) ? wb : null); } else { weComShareLinkLogisticsJobMapper.updateByJobKey(jobKey, "WAITING", note, nextAttempts, null); + WeComShareLinkLogisticsJob refreshed = weComShareLinkLogisticsJobService.selectByJobKey(jobKey); + if (refreshed != null) { + logisticsService.pushShareLinkJobToRedis(refreshed); + } } return AjaxResult.success(data); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/ILogisticsService.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/ILogisticsService.java index 733e936..55ddd9c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/ILogisticsService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/ILogisticsService.java @@ -1,6 +1,7 @@ package com.ruoyi.jarvis.service; import com.ruoyi.jarvis.domain.JDOrder; +import com.ruoyi.jarvis.domain.WeComShareLinkLogisticsJob; import java.util.Map; @@ -27,6 +28,12 @@ public interface ILogisticsService { */ void enqueueShareLinkForScan(String trackingUrl, String remark, String touser, String fromWecomUserId); + /** + * 将已落库任务按与 {@link #enqueueShareLinkForScan} 相同的 JSON 格式推入 Redis(补录、手动失败后重入队等)。 + * {@code attempts} 取自 {@link WeComShareLinkLogisticsJob#getScanAttempts()},与 drain 重试计数对齐。 + */ + void pushShareLinkJobToRedis(WeComShareLinkLogisticsJob job); + /** * 定时任务内:依次弹出队列并调用 {@link #fetchLogisticsByShareLinkAndPush}。 * 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 0a06094..c936966 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 @@ -445,13 +445,6 @@ public class LogisticsServiceImpl implements ILogisticsService { return; } String jobKey = UUID.randomUUID().toString().replace("-", ""); - JSONObject o = new JSONObject(); - o.put("jobKey", jobKey); - o.put("attempts", 0); - o.put("trackingUrl", trackingUrl.trim()); - o.put("remark", remark != null ? remark : ""); - o.put("touser", touser != null ? touser : ""); - o.put("fromWecom", fromWecomUserId != null ? fromWecomUserId : ""); try { WeComShareLinkLogisticsJob row = new WeComShareLinkLogisticsJob(); row.setJobKey(jobKey); @@ -465,8 +458,32 @@ public class LogisticsServiceImpl implements ILogisticsService { } catch (Exception e) { logger.warn("adhoc 分享链任务落库失败仍将入队 jobKey={} err={}", jobKey, e.toString()); } + rightPushAdhocQueueJson(jobKey, 0, trackingUrl.trim(), remark, touser, fromWecomUserId); + } + + @Override + public void pushShareLinkJobToRedis(WeComShareLinkLogisticsJob job) { + if (job == null || !StringUtils.hasText(job.getJobKey()) || !StringUtils.hasText(job.getTrackingUrl())) { + logger.warn("adhoc 入队跳过:jobKey 或 trackingUrl 为空"); + return; + } + int attempts = job.getScanAttempts() != null ? job.getScanAttempts() : 0; + rightPushAdhocQueueJson(job.getJobKey().trim(), attempts, job.getTrackingUrl().trim(), + job.getUserRemark(), job.getTouserPush(), job.getFromUserName()); + } + + /** 与 drain 解析字段一致:jobKey、attempts、trackingUrl、remark、touser、fromWecom */ + private void rightPushAdhocQueueJson(String jobKey, int attempts, String trackingUrl, String remark, + String touser, String fromWecom) { + JSONObject o = new JSONObject(); + o.put("jobKey", jobKey); + o.put("attempts", attempts); + o.put("trackingUrl", trackingUrl); + o.put("remark", remark != null ? remark : ""); + o.put("touser", touser != null ? touser : ""); + o.put("fromWecom", fromWecom != null ? fromWecom : ""); stringRedisTemplate.opsForList().rightPush(REDIS_ADHOC_PENDING_QUEUE, o.toJSONString()); - logger.info("adhoc 分享链接已入队 jobKey={} trackingUrl={} queueKey={}", jobKey, trackingUrl.trim(), REDIS_ADHOC_PENDING_QUEUE); + logger.info("adhoc 分享链接已入队 jobKey={} trackingUrl={} queueKey={}", jobKey, trackingUrl, REDIS_ADHOC_PENDING_QUEUE); } @Override diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/WeComShareLinkLogisticsJobServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/WeComShareLinkLogisticsJobServiceImpl.java index 4e82a72..f85fe94 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/WeComShareLinkLogisticsJobServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/WeComShareLinkLogisticsJobServiceImpl.java @@ -4,6 +4,7 @@ import com.ruoyi.jarvis.domain.WeComInboundTrace; import com.ruoyi.jarvis.domain.WeComShareLinkLogisticsJob; import com.ruoyi.jarvis.mapper.WeComInboundTraceMapper; import com.ruoyi.jarvis.mapper.WeComShareLinkLogisticsJobMapper; +import com.ruoyi.jarvis.service.ILogisticsService; import com.ruoyi.jarvis.service.IWeComShareLinkLogisticsJobService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,6 +34,9 @@ public class WeComShareLinkLogisticsJobServiceImpl implements IWeComShareLinkLog @Resource private WeComInboundTraceMapper weComInboundTraceMapper; + @Resource + private ILogisticsService logisticsService; + @Override public WeComShareLinkLogisticsJob selectByJobKey(String jobKey) { return weComShareLinkLogisticsJobMapper.selectByJobKey(jobKey); @@ -94,6 +98,11 @@ public class WeComShareLinkLogisticsJobServiceImpl implements IWeComShareLinkLog try { weComShareLinkLogisticsJobMapper.insertWeComShareLinkLogisticsJob(row); imported++; + try { + logisticsService.pushShareLinkJobToRedis(row); + } catch (Exception e) { + log.warn("补录入队 Redis 失败 jobKey={} err={}", row.getJobKey(), e.toString()); + } } catch (Exception e) { log.warn("补录插入失败 traceId={} err={}", t.getId(), e.toString()); }