This commit is contained in:
van
2026-04-03 01:18:33 +08:00
parent 9c503464c1
commit d4fdf076e9
4 changed files with 45 additions and 8 deletions

View File

@@ -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);
}

View File

@@ -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}。
*

View File

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

View File

@@ -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());
}