feat(通知): 品牌/采集数据部分失败改为「已交付」提醒,用户不再只看到成功
BRAND 与 COLLECT_DATA 的结果里没有承载「N 行查询失败」的字段,这类任务此前一律显示成功, 用户要到 Excel 里逐行看才发现缺数据。上架模块不需要这条通道——它的历史详情已经通过 SimilarAsinHistoryAssembler 把 result.notice 透出到前端。 新增 NotificationDispatchService.pushPartialResult:复用既有 SCENE_TASK_FAILED/LEVEL_WARNING 场景与 dedupe_key 机制(task_partial:<taskId>),不新增 scene、不加迁移、不动前端枚举。 品牌侧在 finalizeTask 里 deleteTaskData 之前推送,避免统计数据被清库后读不到。
This commit is contained in:
+23
@@ -33,6 +33,7 @@ import com.nanri.aiimage.modules.brand.model.vo.LegacyBrandTaskDetailVo;
|
||||
import com.nanri.aiimage.modules.brand.model.vo.LegacyBrandTaskItemVo;
|
||||
import com.nanri.aiimage.modules.brand.model.vo.LegacyBrandTaskListVo;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
import com.nanri.aiimage.modules.notification.service.NotificationDispatchService;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
|
||||
import com.nanri.aiimage.modules.task.service.TaskDistributedLockService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskFileJobService;
|
||||
@@ -137,6 +138,7 @@ public class BrandTaskService {
|
||||
private final ObjectMapper objectMapper;
|
||||
private final TaskFileJobService taskFileJobService;
|
||||
private final TaskProgressSnapshotService taskProgressSnapshotService;
|
||||
private final NotificationDispatchService notificationDispatchService;
|
||||
|
||||
public BrandTaskCreateVo createTask(Long userId, BrandTaskCreateRequest request) {
|
||||
if (userId == null || userId <= 0) {
|
||||
@@ -702,6 +704,7 @@ public class BrandTaskService {
|
||||
throw new BusinessException("任务已取消");
|
||||
}
|
||||
saveBrandProgressSnapshot(taskId, STATUS_SUCCESS, totalCount, totalCount, 0, null);
|
||||
notifyQueryFailedBrands(freshTask, aggregates);
|
||||
brandTaskStorageService.deleteTaskData(taskId);
|
||||
brandTaskProgressCacheService.delete(taskId);
|
||||
log.info("[brand-finalize] taskId={} finalized success files={} elapsedMs={}",
|
||||
@@ -774,6 +777,26 @@ public class BrandTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询失败品牌的唯一出口是结果文件里的「查询失败品牌」子表,用户不下载文件就完全看不到;
|
||||
* 而聚合数据在 finalize 的 deleteTaskData 之后就没了,所以通知必须赶在删除之前推。
|
||||
*/
|
||||
private void notifyQueryFailedBrands(BrandCrawlTaskEntity task,
|
||||
Map<String, BrandFileAggregateCacheDto> aggregates) {
|
||||
int failedBrands = 0;
|
||||
for (BrandFileAggregateCacheDto aggregate : aggregates.values()) {
|
||||
if (aggregate != null) {
|
||||
failedBrands += normalizeBrandSet(aggregate.getQueryFailedBrands()).size();
|
||||
}
|
||||
}
|
||||
if (failedBrands == 0) {
|
||||
return;
|
||||
}
|
||||
log.info("[brand-finalize] taskId={} queryFailedBrands={}", task.getId(), failedBrands);
|
||||
notificationDispatchService.pushPartialResult(task.getUserId(), task.getId(), "BRAND",
|
||||
"#" + task.getId(), failedBrands + " 个品牌查询失败(品牌检测服务未返回结果)");
|
||||
}
|
||||
|
||||
/** 未检测品牌 = 源文件品牌 -(保留 ∪ 不符合品牌 ∪ 查询失败品牌);按源文件出现顺序去重。 */
|
||||
private List<String> resolveUndetectedBrands(BrandParsedFileCacheDto cachedFile, BrandFileAggregateCacheDto aggregate) {
|
||||
List<Map<String, Object>> sourceRows = cachedFile.getRows() == null ? List.of() : cachedFile.getRows();
|
||||
|
||||
+10
@@ -45,6 +45,7 @@ import com.nanri.aiimage.modules.collectdata.util.CollectDataResultItemBatchWrit
|
||||
import com.nanri.aiimage.modules.invalidasin.mapper.InvalidAsinDataMapper;
|
||||
import com.nanri.aiimage.modules.file.service.LocalFileStorageService;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
import com.nanri.aiimage.modules.notification.service.NotificationDispatchService;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileResultMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.TaskChunkMapper;
|
||||
@@ -178,6 +179,7 @@ public class CollectDataService {
|
||||
/** 结果明细 chunk 级读取器:生成结果文件时按 chunk 一次读取,替代逐行对象读取。 */
|
||||
private final CollectDataResultDetailReader resultDetailReader;
|
||||
private final TaskProgressLightAssembler taskProgressLightAssembler;
|
||||
private final NotificationDispatchService notificationDispatchService;
|
||||
|
||||
@Value("${aiimage.collect-data.stale-timeout-minutes:30}")
|
||||
private long staleTimeoutMinutes;
|
||||
@@ -1140,6 +1142,14 @@ public class CollectDataService {
|
||||
log.warn("[collect-data] 结果文件已生成但任务已是 FAILED,保留失败态与原因 taskId={} rows={} reason={}",
|
||||
task.getId(), finalRowCount, failureReason);
|
||||
}
|
||||
// 品牌查询失败的行不进结果、也不落无效品牌表(见上面 rejected/queryFailed 的区分),
|
||||
// 用户端因此完全没有出口:只在任务确实翻成成功时补一条通知。
|
||||
if (updated > 0 && stats.brandQueryFailedCount > 0) {
|
||||
notificationDispatchService.pushPartialResult(task.getUserId(), task.getId(), MODULE_TYPE,
|
||||
task.getTaskNo(), stats.brandQueryFailedCount
|
||||
+ " 行商品的品牌检测未返回结果(品牌检测服务超时或被限流),这些行不计入结果条数,"
|
||||
+ "也没有被判定为无效品牌,可稍后单独重跑这些 ASIN");
|
||||
}
|
||||
} finally {
|
||||
FileUtil.del(xlsx);
|
||||
}
|
||||
|
||||
+25
@@ -1,6 +1,7 @@
|
||||
package com.nanri.aiimage.modules.notification.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.nanri.aiimage.common.module.TaskModuleRegistry;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
@@ -72,6 +73,30 @@ public class NotificationDispatchService {
|
||||
return pushed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 「任务成功,但有一部分行没跑出来」通知:整任务没失败、铃铛里的 task_failed 只覆盖终态失败,
|
||||
* 这类部分缺失过去对用户完全不可见(品牌检测的查询失败行只躺在结果文件的一张子表里)。
|
||||
*
|
||||
* <p>场景沿用 {@code task_failed}(大类仍是「任务异常」),去重键按任务维度:同一任务重复
|
||||
* 组装结果时刷新内容而不是刷屏。不写 task.errorMessage —— 结果组装的失败判据读那个字段,
|
||||
* 写了会把任务翻成 FAILED,与「状态保持成功、只提示交付不完整」的产品口径相悖。
|
||||
*/
|
||||
public void pushPartialResult(Long userId, Long taskId, String moduleType, String taskNo, String detail) {
|
||||
if (userId == null || userId <= 0 || taskId == null || detail == null || detail.isBlank()) {
|
||||
return;
|
||||
}
|
||||
String title = TaskModuleRegistry.labelOf(moduleType) + "任务部分结果缺失";
|
||||
String displayTaskNo = taskNo == null || taskNo.isBlank() ? "#" + taskId : taskNo.trim();
|
||||
notificationService.pushOrRefresh(userId, NotificationService.AUDIENCE_USER,
|
||||
NotificationService.SCENE_TASK_FAILED, NotificationService.LEVEL_WARNING,
|
||||
title, "任务 " + displayTaskNo + ":" + detail + "。任务已完成,其余结果正常,可在结果文件里查看缺失清单。",
|
||||
"task_partial:" + taskId);
|
||||
pushToAdmins(NotificationService.SCENE_TASK_FAILED, NotificationService.LEVEL_WARNING,
|
||||
"用户" + title,
|
||||
"用户 " + displayNameOf(userId) + "(uid=" + userId + ")任务 " + displayTaskNo + ":" + detail,
|
||||
"task_partial_admin:" + taskId, userId);
|
||||
}
|
||||
|
||||
/** 解析管理员受众:全部超管 + 管理员(非管理员角色一律排除),并预取各管理员可见用户集。 */
|
||||
public AdminAudience prepareAdminAudience() {
|
||||
List<AdminUserEntity> candidates = adminUserMapper.selectList(new LambdaQueryWrapper<AdminUserEntity>()
|
||||
|
||||
Reference in New Issue
Block a user