1
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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}。
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user