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
@@ -1,5 +1,6 @@
package com.nanri.aiimage.modules.pricetrack.service;
import com.nanri.aiimage.common.util.UserMessages;
import com.nanri.aiimage.common.exception.BusinessException;
import com.nanri.aiimage.common.util.SxssfWorkbookWriter;
import com.nanri.aiimage.modules.pricetrack.model.dto.PriceTrackSubmitResultRequest;
@@ -71,7 +72,7 @@ public class PriceTrackExcelAssemblyService {
writer.write(outputXlsx);
} catch (Exception ex) {
log.warn("[price-track] write workbook failed: {}", ex.getMessage());
throw new BusinessException("generate price-track excel failed: " + ex.getMessage());
throw new BusinessException(UserMessages.with("生成跟价 Excel 失败", ex));
}
}
@@ -1,5 +1,6 @@
package com.nanri.aiimage.modules.pricetrack.service;
import com.nanri.aiimage.common.util.UserMessages;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -238,11 +239,11 @@ public class PriceTrackService {
} catch (BusinessException ex) {
item.setMatched(false);
item.setMatchStatus("PENDING");
item.setMatchMessage(ex.getMessage());
item.setMatchMessage(UserMessages.orFallback(ex.getMessage(), "该行匹配失败,请稍后重试"));
} catch (Exception ex) {
item.setMatched(false);
item.setMatchStatus("PENDING");
item.setMatchMessage(Objects.toString(ex.getMessage(), "匹配异常"));
item.setMatchMessage(UserMessages.orFallback(ex.getMessage(), "匹配异常"));
}
return item;
}
@@ -1,5 +1,6 @@
package com.nanri.aiimage.modules.pricetrack.service;
import com.nanri.aiimage.common.util.UserMessages;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -240,7 +241,7 @@ public class PriceTrackTaskService {
inNewTransaction(() -> {
FileResultEntity latestEntity = fileResultMapper.selectById(resultId);
if (latestEntity == null || !MODULE_TYPE.equals(latestEntity.getModuleType()) || !userId.equals(latestEntity.getUserId())) {
throw new BusinessException("record not found");
throw new BusinessException("没有找到对应记录");
}
fileResultMapper.deleteById(resultId);
reconcileTaskAfterResultRemoval(taskId);
@@ -1245,7 +1246,7 @@ public class PriceTrackTaskService {
} catch (BusinessException ex) {
throw ex;
} catch (Exception ex) {
throw new BusinessException("任务请求参数解析失败: " + ex.getMessage());
throw new BusinessException(UserMessages.with("任务请求参数解析失败", ex));
}
}
@@ -1569,7 +1570,7 @@ public class PriceTrackTaskService {
mergeCountryRows(merged, parseWorkbookAsinRows(file, countryCodes));
continue;
}
throw new BusinessException("Unsupported ASIN file type: " + file.getName());
throw new BusinessException("不支持的 ASIN 文件类型: " + file.getName());
}
return merged;
}
@@ -1626,14 +1627,14 @@ public class PriceTrackTaskService {
} catch (BusinessException ex) {
throw ex;
} catch (Exception ex) {
throw new BusinessException("Failed to parse ASIN workbook");
throw new BusinessException("解析 ASIN 表格失败");
}
return out;
}
private Map<String, List<Map<String, String>>> parseCsvAsinRows(File file, List<String> countryCodes) {
if (countryCodes == null || countryCodes.size() != 1) {
throw new BusinessException("CSV ASIN file requires exactly one selected country");
throw new BusinessException("CSV 格式的 ASIN 文件只能选择一个国家");
}
Map<String, List<Map<String, String>>> out = new LinkedHashMap<>();
List<Map<String, String>> rows = out.computeIfAbsent(countryCodes.get(0), key -> new ArrayList<>());
@@ -1655,7 +1656,7 @@ public class PriceTrackTaskService {
} catch (BusinessException ex) {
throw ex;
} catch (Exception ex) {
throw new BusinessException("Failed to parse ASIN csv");
throw new BusinessException("解析 ASIN CSV 失败");
}
return out;
}