1
This commit is contained in:
@@ -1006,32 +1006,57 @@ private String cleanForbiddenPhrases(String text) {
|
|||||||
throw new RuntimeException("任务不存在: " + taskId);
|
throw new RuntimeException("任务不存在: " + taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仅重试 待发布(0)/发布失败(3) 的明细
|
|
||||||
List<BatchPublishItem> allItems = itemMapper.selectBatchPublishItemByTaskId(taskId);
|
List<BatchPublishItem> allItems = itemMapper.selectBatchPublishItemByTaskId(taskId);
|
||||||
List<BatchPublishItem> itemsToRetry = new ArrayList<>();
|
|
||||||
|
// 分类处理:需要重新发布的 和 需要重新上架的
|
||||||
|
List<BatchPublishItem> itemsToRepublish = new ArrayList<>(); // 待发布(0)/发布失败(3)
|
||||||
|
List<BatchPublishItem> itemsToRelist = new ArrayList<>(); // 发布成功(2)/上架失败(6)
|
||||||
|
|
||||||
for (BatchPublishItem it : allItems) {
|
for (BatchPublishItem it : allItems) {
|
||||||
if (it.getStatus() != null && (it.getStatus() == 0 || it.getStatus() == 3)) {
|
if (it.getStatus() != null) {
|
||||||
itemsToRetry.add(it);
|
if (it.getStatus() == 0 || it.getStatus() == 3) {
|
||||||
|
// 待发布或发布失败,需要重新发布
|
||||||
|
itemsToRepublish.add(it);
|
||||||
|
} else if (it.getStatus() == 2 || it.getStatus() == 6) {
|
||||||
|
// 发布成功但未上架,或上架失败,需要重新上架
|
||||||
|
itemsToRelist.add(it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemsToRetry.isEmpty()) {
|
if (itemsToRepublish.isEmpty() && itemsToRelist.isEmpty()) {
|
||||||
log.info("任务{} 无需重试,未发现待发布/失败的明细", taskId);
|
log.info("任务{} 无需重试,未发现待处理的明细", taskId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造最小请求对象,仅提供通用参数用于发布
|
// 处理需要重新发布的商品
|
||||||
BatchPublishRequest req = new BatchPublishRequest();
|
if (!itemsToRepublish.isEmpty()) {
|
||||||
try {
|
BatchPublishRequest req = new BatchPublishRequest();
|
||||||
BatchPublishRequest.CommonParams commonParams = JSON.parseObject(
|
try {
|
||||||
task.getCommonParams(), BatchPublishRequest.CommonParams.class);
|
BatchPublishRequest.CommonParams commonParams = JSON.parseObject(
|
||||||
req.setCommonParams(commonParams);
|
task.getCommonParams(), BatchPublishRequest.CommonParams.class);
|
||||||
} catch (Exception e) {
|
req.setCommonParams(commonParams);
|
||||||
log.warn("解析任务通用参数失败,将使用默认参数: {}", task.getCommonParams(), e);
|
} catch (Exception e) {
|
||||||
|
log.warn("解析任务通用参数失败,将使用默认参数: {}", task.getCommonParams(), e);
|
||||||
|
}
|
||||||
|
log.info("开始重新发布任务{} 的 {} 条明细", taskId, itemsToRepublish.size());
|
||||||
|
self.asyncBatchPublish(taskId, itemsToRepublish, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("开始重试任务{} 的 {} 条明细", taskId, itemsToRetry.size());
|
// 处理需要重新上架的商品(直接上架,不需要重新发布)
|
||||||
self.asyncBatchPublish(taskId, itemsToRetry, req);
|
if (!itemsToRelist.isEmpty()) {
|
||||||
|
log.info("开始重新上架任务{} 的 {} 条明细", taskId, itemsToRelist.size());
|
||||||
|
for (BatchPublishItem item : itemsToRelist) {
|
||||||
|
// 重置状态为发布成功,准备上架
|
||||||
|
item.setStatus(2);
|
||||||
|
item.setErrorMessage(null);
|
||||||
|
itemMapper.updateBatchPublishItem(item);
|
||||||
|
appendItemLogSafe(item.getId(), "【重试】准备重新上架");
|
||||||
|
|
||||||
|
// 立即调度上架(延迟1秒,避免过快)
|
||||||
|
schedulePublish(item.getId(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user