1
This commit is contained in:
@@ -88,6 +88,10 @@ public class WeComShareLinkLogisticsJobController extends BaseController {
|
|||||||
StringUtils.hasText(wb) ? wb : null);
|
StringUtils.hasText(wb) ? wb : null);
|
||||||
} else {
|
} else {
|
||||||
weComShareLinkLogisticsJobMapper.updateByJobKey(jobKey, "WAITING", note, nextAttempts, null);
|
weComShareLinkLogisticsJobMapper.updateByJobKey(jobKey, "WAITING", note, nextAttempts, null);
|
||||||
|
WeComShareLinkLogisticsJob refreshed = weComShareLinkLogisticsJobService.selectByJobKey(jobKey);
|
||||||
|
if (refreshed != null) {
|
||||||
|
logisticsService.pushShareLinkJobToRedis(refreshed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return AjaxResult.success(data);
|
return AjaxResult.success(data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.jarvis.service;
|
package com.ruoyi.jarvis.service;
|
||||||
|
|
||||||
import com.ruoyi.jarvis.domain.JDOrder;
|
import com.ruoyi.jarvis.domain.JDOrder;
|
||||||
|
import com.ruoyi.jarvis.domain.WeComShareLinkLogisticsJob;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -27,6 +28,12 @@ public interface ILogisticsService {
|
|||||||
*/
|
*/
|
||||||
void enqueueShareLinkForScan(String trackingUrl, String remark, String touser, String fromWecomUserId);
|
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}。
|
* 定时任务内:依次弹出队列并调用 {@link #fetchLogisticsByShareLinkAndPush}。
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -445,13 +445,6 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String jobKey = UUID.randomUUID().toString().replace("-", "");
|
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 {
|
try {
|
||||||
WeComShareLinkLogisticsJob row = new WeComShareLinkLogisticsJob();
|
WeComShareLinkLogisticsJob row = new WeComShareLinkLogisticsJob();
|
||||||
row.setJobKey(jobKey);
|
row.setJobKey(jobKey);
|
||||||
@@ -465,8 +458,32 @@ public class LogisticsServiceImpl implements ILogisticsService {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("adhoc 分享链任务落库失败仍将入队 jobKey={} err={}", jobKey, e.toString());
|
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());
|
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
|
@Override
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.ruoyi.jarvis.domain.WeComInboundTrace;
|
|||||||
import com.ruoyi.jarvis.domain.WeComShareLinkLogisticsJob;
|
import com.ruoyi.jarvis.domain.WeComShareLinkLogisticsJob;
|
||||||
import com.ruoyi.jarvis.mapper.WeComInboundTraceMapper;
|
import com.ruoyi.jarvis.mapper.WeComInboundTraceMapper;
|
||||||
import com.ruoyi.jarvis.mapper.WeComShareLinkLogisticsJobMapper;
|
import com.ruoyi.jarvis.mapper.WeComShareLinkLogisticsJobMapper;
|
||||||
|
import com.ruoyi.jarvis.service.ILogisticsService;
|
||||||
import com.ruoyi.jarvis.service.IWeComShareLinkLogisticsJobService;
|
import com.ruoyi.jarvis.service.IWeComShareLinkLogisticsJobService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -33,6 +34,9 @@ public class WeComShareLinkLogisticsJobServiceImpl implements IWeComShareLinkLog
|
|||||||
@Resource
|
@Resource
|
||||||
private WeComInboundTraceMapper weComInboundTraceMapper;
|
private WeComInboundTraceMapper weComInboundTraceMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ILogisticsService logisticsService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WeComShareLinkLogisticsJob selectByJobKey(String jobKey) {
|
public WeComShareLinkLogisticsJob selectByJobKey(String jobKey) {
|
||||||
return weComShareLinkLogisticsJobMapper.selectByJobKey(jobKey);
|
return weComShareLinkLogisticsJobMapper.selectByJobKey(jobKey);
|
||||||
@@ -94,6 +98,11 @@ public class WeComShareLinkLogisticsJobServiceImpl implements IWeComShareLinkLog
|
|||||||
try {
|
try {
|
||||||
weComShareLinkLogisticsJobMapper.insertWeComShareLinkLogisticsJob(row);
|
weComShareLinkLogisticsJobMapper.insertWeComShareLinkLogisticsJob(row);
|
||||||
imported++;
|
imported++;
|
||||||
|
try {
|
||||||
|
logisticsService.pushShareLinkJobToRedis(row);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("补录入队 Redis 失败 jobKey={} err={}", row.getJobKey(), e.toString());
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("补录插入失败 traceId={} err={}", t.getId(), e.toString());
|
log.warn("补录插入失败 traceId={} err={}", t.getId(), e.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user