fix(文案出口): 用户可见提示语一律走 UserMessages 把关,并补结果作业租约围栏

两件事同源:2026-10-09 任务 30456 的卡片上同时出现中文进度和一句英文异常原文。

围栏:派发链在执行前重读 job 行,让 activateRunningClaim 的 CAS 恒真,撞锁方
deferRunning 把在跑的行翻回 PENDING,markSuccess 静默写 0 行——成功被判成失败。
claim 快照现在贯穿到 runClaimed 不再回读,markSuccess 返回布尔并补 stage=SUCCESS_LOST
日志,让这次丢失可观测。

文案:普查数出 61 处把 ex.getMessage() 拼进用户可见字段(异常响应、任务 error_message、
结果作业 error_msg、看板 message),逐条翻译追不上新增速度,改为出口把关——
UserMessages.with(中文主干, 异常) 只拼接中文详情、orFallback(原文, 兜底句) 只放行含中文的串,
被换掉的原文进日志;GlobalExceptionHandler 按码分档兜底(401/4011/40902 各说各的话)。
另把 chunk-read-failed[N] 摘要写成"第 N 分片读取失败"、TASK_LOCK_BUSY 换成中文(40902 码不动,
客户端按码分支)。数字人两处与结果作业 worker 故意仍存原文:孤儿判定与三条 preserves raw
用例按 error_message 读它,界面侧由前端 userNotice 兜住,已在新尺子里点名豁免并反查豁免是否还被用到。

尺子:RawExceptionMessageSinkGuardTest(出口行数下限硬钉 1500+内存造违例自证)、UserMessagesTest、
UserFacingMessageChineseGuardTest 豁免表收到只剩 JSON 键 msg 一条。mvn -o test 4205 例 0 失败。
This commit is contained in:
2026-10-09 19:34:25 +08:00
parent 6325a63b52
commit 2a4d15b801
76 changed files with 1160 additions and 279 deletions
@@ -94,12 +94,10 @@ public class DedupeTotalDataController {
HttpServletRequest request) {
RequestOperator operator = requireDedupeTotalDataAccess(request);
AdminUserEntity user = operator.user();
List<Long> memberIds = operator.superAdmin()
? dataReadScope.readScope(user, companyId).userIdsOr(null)
: null;
Long scopedCompanyId = dataReadScope.superAdminScopedCompanyId(user, companyId);
return ApiResponse.success(dedupeTotalDataService.page(
page, pageSize, keyword, username, startDate, endDate, groupId, country, lastId,
operator.id(), memberIds));
operator.id(), scopedCompanyId));
}
@GetMapping("/export")
@@ -115,14 +113,12 @@ public class DedupeTotalDataController {
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
HttpServletRequest request) {
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
throw new BusinessException(400, "invalid export date range");
throw new BusinessException(400, "导出的日期范围不对,请重新选择开始和结束日期");
}
RequestOperator operator = requireDedupeTotalDataAccess(request);
AdminUserEntity user = operator.user();
Long operatorId = operator.id();
List<Long> memberIds = operator.superAdmin()
? dataReadScope.readScope(user, companyId).userIdsOr(null)
: null;
Long scopedCompanyId = dataReadScope.superAdminScopedCompanyId(user, companyId);
boolean monthlyZip = isCrossMonthRange(startDate, endDate);
String filename = "dedupe-total-data-" + LocalDateTime.now().format(EXPORT_FILENAME_FORMATTER)
+ (monthlyZip ? ".zip" : ".xlsx");
@@ -130,9 +126,9 @@ public class DedupeTotalDataController {
// 会把它当成"范围没交给任何调用"而假红),所以 operatorId 先在局部变量里落好。
StreamingResponseBody body = monthlyZip
? outputStream -> dedupeTotalDataService.writeMonthlyZipExport(
outputStream, username, startDate, endDate, groupId, country, operatorId, memberIds)
outputStream, username, startDate, endDate, groupId, country, operatorId, scopedCompanyId)
: outputStream -> dedupeTotalDataService.writeExport(
outputStream, username, startDate, endDate, groupId, country, operatorId, memberIds);
outputStream, username, startDate, endDate, groupId, country, operatorId, scopedCompanyId);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, DownloadHeaderUtil.contentDisposition(filename))
.contentType(MediaType.parseMediaType(monthlyZip ? ZIP_CONTENT_TYPE : XLSX_CONTENT_TYPE))
@@ -301,10 +297,12 @@ public class DedupeTotalDataController {
// 公司 tab 的读范围与写侧归属(create / import / delete-import)都就地算在 handler 里,
// 不留私有收口方法:G2 的断言 A 只在这支 handler 的
// 块内找 readScope(,私有方法在它自己的闭括号处收口、不算在内(CompanyIdParamGoesThroughReadScopeTest
// 类注释第 5、7 条),挪进去 = 这一页的 tab 没人看守。收窄只给超管:非超管已由 resolveAccessScope
// 按会话裁剪,且他的可见集里含「靠分组可见」的行,叠一层账号 IN 会把那批行静默删掉
// (同 ShopManageController 的口径)。
// 块内找正门调用,私有方法在它自己的闭括号处收口、不算在内(CompanyIdParamGoesThroughReadScopeTest
// 类注释第 5、7 条),挪进去 = 这一页的 tab 没人看守。读侧收窄走 superAdminScopedCompanyId
// (2026-10-09 口径切换:从"上传账号集合"改到"行自己的 company_id",超管代导入与上传者已删
// 两类行原口径都归错,见该方法 javadoc);写侧 create/import 走 readCompanyIdOrOwn。
// 两条都只对超管生效:非超管已由 resolveAccessScope 按会话裁剪,且他的可见集里含
// 「靠分组可见」的行,叠一层公司谓词会把那批行静默删掉(同 ShopManageController 的口径)。
private record RequestOperator(Long id, boolean superAdmin, AdminUserEntity user) {
}
@@ -1,5 +1,6 @@
package com.nanri.aiimage.modules.dedupe.service;
import com.nanri.aiimage.common.util.UserMessages;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
@@ -197,7 +198,7 @@ public class DedupeRunService {
} catch (Exception e) {
runProgressMap.remove(runId);
decrementRunningCount(request.getUserId());
throw new BusinessException("提交去重任务失败:" + e.getMessage());
throw new BusinessException(UserMessages.with("提交去重任务失败", e));
}
return snapshot(progress);
@@ -375,7 +376,7 @@ public class DedupeRunService {
synchronized (progress) {
progress.setStatus("failed");
progress.setFinished(true);
progress.setError("去重任务收尾失败:" + ex.getMessage());
progress.setError(UserMessages.with("去重任务收尾失败", ex));
}
task.setStatus("FAILED");
task.setErrorMessage(progress.getError());
@@ -558,7 +559,7 @@ public class DedupeRunService {
return item;
} catch (Exception ex) {
item.setSuccess(false);
item.setError(ex.getMessage());
item.setError(UserMessages.orFallback(ex.getMessage(), "这个文件去重失败,请检查内容后重新上传"));
log.error("dedupe run file failed fileKey={} filename={} error",
sourceFile.getFileKey(), sourceFile.getOriginalFilename(), ex);
try {
@@ -567,7 +568,7 @@ public class DedupeRunService {
resultEntity.setModuleType("DEDUPE");
resultEntity.setSourceFilename(sourceFile.getOriginalFilename());
resultEntity.setSuccess(0);
resultEntity.setErrorMessage(ex.getMessage());
resultEntity.setErrorMessage(UserMessages.orFallback(ex.getMessage(), "这个文件去重失败,请检查内容后重新上传"));
resultEntity.setUserId(request.getUserId());
resultEntity.setCreatedAt(LocalDateTime.now());
fileResultMapper.insert(resultEntity);
@@ -963,7 +964,7 @@ public class DedupeRunService {
zos.closeEntry();
}
} catch (Exception ex) {
throw new BusinessException("去重结果打包失败:" + ex.getMessage());
throw new BusinessException(UserMessages.with("去重结果打包失败", ex));
}
return zipFile;
}
@@ -1,5 +1,6 @@
package com.nanri.aiimage.modules.dedupe.service;
import com.nanri.aiimage.common.util.UserMessages;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -279,7 +280,7 @@ public class DedupeTotalDataService {
throw new BusinessException("导出输出流不能为空");
}
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
throw new BusinessException("invalid export date range");
throw new BusinessException("导出的日期范围不对,请重新选择开始和结束日期");
}
String safeUsername = username == null ? "" : username.trim();
AccessScope scope = resolveAccessScope(operatorId);
@@ -315,14 +316,14 @@ public class DedupeTotalDataService {
Long operatorId,
List<Long> companyMemberIds) {
if (outputStream == null) {
throw new BusinessException("export output stream cannot be null");
throw new BusinessException("导出文件写入失败,请稍后重试");
}
if (startDate == null || endDate == null || YearMonth.from(startDate).equals(YearMonth.from(endDate))) {
writeExport(outputStream, username, startDate, endDate, groupId, country, operatorId, companyMemberIds);
return;
}
if (startDate.isAfter(endDate)) {
throw new BusinessException("invalid export date range");
throw new BusinessException("导出的日期范围不对,请重新选择开始和结束日期");
}
String safeUsername = username == null ? "" : username.trim();
String safeCountry = country == null ? "" : country.trim();
@@ -350,7 +351,7 @@ public class DedupeTotalDataService {
} catch (BusinessException ex) {
throw ex;
} catch (Exception ex) {
throw new BusinessException("export dedupe total data failed");
throw new BusinessException("去重库数据导出失败,请稍后重试");
}
}
@@ -670,7 +671,7 @@ public class DedupeTotalDataService {
progress.setStatus("success");
} catch (Exception e) {
progress.setStatus("failed");
progress.setErrorMessage(e instanceof BusinessException ? e.getMessage() : "删除 Excel 匹配数据失败");
progress.setErrorMessage(UserMessages.orFallback(e.getMessage(), "删除 Excel 匹配数据失败"));
} finally {
deleteQuietly(tempFile);
deleteImportCompletedAtMap.put(importId, System.currentTimeMillis());
@@ -697,7 +698,7 @@ public class DedupeTotalDataService {
progress.setStatus("success");
} catch (Exception e) {
progress.setStatus("failed");
progress.setErrorMessage(e instanceof BusinessException ? e.getMessage() : "导入 Excel 失败");
progress.setErrorMessage(UserMessages.orFallback(e.getMessage(), "导入 Excel 失败"));
// 此前该 catch 既不记日志也不带 cause,线上只有一句「导入 Excel 失败」,无栈无定位线索
log.error("[dedupe-total-data] 异步导入失败 filename={} userId={}", filename, uploaderUserId, e);
} finally {