This commit is contained in:
van
2026-04-03 17:48:33 +08:00
parent fa7e26cf6e
commit 3e37587074
5 changed files with 19 additions and 4 deletions

View File

@@ -21,6 +21,7 @@ public interface WeComShareLinkLogisticsJobMapper {
/**
* 待自动扫描但可能未在 Redis 队列中的任务(如纯 SQL 补录的 IMPORTED、入队失败后的 PENDING 等)。
* 含曾 {@code ABANDONED} 的任务(对账时会先归零扫描次数并改回 {@code WAITING} 再入队)。
* 仅 {@code create_time} 在最近一个月内的记录,避免扫到过旧历史。
*/
List<WeComShareLinkLogisticsJob> selectJobsNeedingQueueReconcile(@Param("limit") int limit);

View File

@@ -35,7 +35,7 @@ public interface ILogisticsService {
void pushShareLinkJobToRedis(WeComShareLinkLogisticsJob job);
/**
* 扫描落库表中仍待处理的任务({@code create_time} 一个月内),在限频下补入 Redis(覆盖纯 SQL 补录、Redis 曾丢失等),避免仅靠企微回调入队
* 扫描落库表中仍待处理的任务(含 {@code ABANDONED},对账时会重置计数后再入队;仅 {@code create_time} 一个月内),在限频下补入 Redis。
*
* @return 本次获得限频锁并成功推入队列的条数
*/

View File

@@ -497,7 +497,21 @@ public class LogisticsServiceImpl implements ILogisticsService {
continue;
}
try {
pushShareLinkJobToRedis(job);
WeComShareLinkLogisticsJob toEnqueue = job;
if ("ABANDONED".equalsIgnoreCase(job.getStatus())) {
String prev = StringUtils.hasText(job.getLastNote()) ? job.getLastNote() : "";
if (prev.length() > 400) {
prev = prev.substring(0, 400) + "";
}
String note = "requeue_after_abandon|" + prev;
weComShareLinkLogisticsJobMapper.updateByJobKey(job.getJobKey().trim(), "WAITING", note, 0, null);
toEnqueue = weComShareLinkLogisticsJobMapper.selectByJobKey(job.getJobKey().trim());
if (toEnqueue == null) {
stringRedisTemplate.delete(lockKey);
continue;
}
}
pushShareLinkJobToRedis(toEnqueue);
pushed++;
} catch (Exception e) {
try {

View File

@@ -85,7 +85,7 @@ public class LogisticsScanTask {
logger.error("订单扫描阶段异常", e);
} finally {
try {
logger.info("---------- 企微分享链 adhoc落库对账入队IMPORTED/PENDING/WAITING 等) ----------");
logger.info("---------- 企微分享链 adhoc落库对账入队含 ABANDONED 复位入队,一月内 PENDING/WAITING/IMPORTED 等) ----------");
adhocReconciled = logisticsService.reconcileShareLinkJobsIntoPendingQueue();
logger.info("企微分享链 adhoc对账入队 {} 条(余者可能尚在限频窗口内)", adhocReconciled);
} catch (Exception e) {

View File

@@ -72,7 +72,7 @@
<select id="selectJobsNeedingQueueReconcile" resultMap="WeComShareLinkLogisticsJobResult">
<include refid="selectVo"/>
where status in ('PENDING', 'WAITING', 'IMPORTED')
where status in ('PENDING', 'WAITING', 'IMPORTED', 'ABANDONED')
and tracking_url is not null and trim(tracking_url) != ''
and create_time >= date_sub(now(), interval 1 month)
order by id asc