|
|
@@ -98,6 +98,11 @@ public class DmService {
|
|
|
/** 非表格文件的 AI 识别档案:抽样本、建档、提交后台识别 */
|
|
|
@Autowired
|
|
|
private FileAiProfileService fileAiProfileService;
|
|
|
+ /** 清洗方式/备注回填:按 sheet 查 AI 任务与新建表元数据 */
|
|
|
+ @Autowired
|
|
|
+ private com.zsjz.ai.module.aiclean.mapper.AiCleanJobMapper aiCleanJobMapper;
|
|
|
+ @Autowired
|
|
|
+ private com.zsjz.ai.module.aiclean.mapper.AiCleanTemplateMapper aiCleanTemplateMapper;
|
|
|
|
|
|
/**
|
|
|
* 预览文件内容
|
|
|
@@ -889,6 +894,8 @@ public class DmService {
|
|
|
fileInfo.setDataNum(dataNum);
|
|
|
fileInfo.setFailNum(failNum);
|
|
|
fileInfo.setSuccessNum(dataNum - failNum);
|
|
|
+ // sheet 行展示「清洗方式 / 备注」:按 AI 任务记录回填瞬态字段
|
|
|
+ fillSheetCleanInfo(childrens);
|
|
|
}
|
|
|
return rootFiles
|
|
|
.stream()
|
|
|
@@ -897,6 +904,78 @@ public class DmService {
|
|
|
.toList();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 回填 sheet 的清洗方式与备注(瞬态字段,供「导入文件管理」列表展示):
|
|
|
+ * <ul>
|
|
|
+ * <li>有 AI 任务 → 「AI清洗」;备注 = AI 匹配结果(匹配到的模板名 / 新建表名)
|
|
|
+ * 或失败原因(无法清洗/失败/跳过的原因,无法清洗同属失败语义)</li>
|
|
|
+ * <li>无 AI 任务但已配模板(上传直配或手动清洗)→ 「系统清洗」</li>
|
|
|
+ * <li>都没有 → 留空(前端显示 -)</li>
|
|
|
+ * </ul>
|
|
|
+ * sheet 可能被多次清洗(多条 job),取最新一条(雪花 id 降序首个)。
|
|
|
+ */
|
|
|
+ private void fillSheetCleanInfo(List<FileInfo> sheets) {
|
|
|
+ if (CollUtil.isEmpty(sheets)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Long> sheetIds = sheets.stream().map(FileInfo::getId).filter(Objects::nonNull).toList();
|
|
|
+ Map<Long, com.zsjz.ai.module.aiclean.entity.AiCleanJob> latestJob = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(sheetIds)) {
|
|
|
+ for (com.zsjz.ai.module.aiclean.entity.AiCleanJob job : aiCleanJobMapper.selectList(
|
|
|
+ Wrappers.<com.zsjz.ai.module.aiclean.entity.AiCleanJob>lambdaQuery()
|
|
|
+ .in(com.zsjz.ai.module.aiclean.entity.AiCleanJob::getSheetId, sheetIds)
|
|
|
+ .orderByDesc(com.zsjz.ai.module.aiclean.entity.AiCleanJob::getId))) {
|
|
|
+ latestJob.putIfAbsent(job.getSheetId(), job);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<Long, String> aiTableNames = new HashMap<>();
|
|
|
+ for (FileInfo sheet : sheets) {
|
|
|
+ com.zsjz.ai.module.aiclean.entity.AiCleanJob job = latestJob.get(sheet.getId());
|
|
|
+ if (job == null) {
|
|
|
+ if (sheet.getTemplateId() != null) {
|
|
|
+ sheet.setCleanMode("系统清洗");
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ sheet.setCleanMode("AI清洗");
|
|
|
+ sheet.setCleanNote(cleanNoteOf(job, aiTableNames));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String cleanNoteOf(com.zsjz.ai.module.aiclean.entity.AiCleanJob job, Map<Long, String> aiTableNames) {
|
|
|
+ String status = StrUtil.nullToEmpty(job.getStatus() == null ? null : job.getStatus().name());
|
|
|
+ String reason = StrUtil.maxLength(StrUtil.nullToEmpty(job.getFailReason()), 120);
|
|
|
+ return switch (status) {
|
|
|
+ // 无法清洗同属失败语义(用户明确要求):统一带「清洗失败」前缀,原因如实带出
|
|
|
+ case "NEED_REVIEW", "FAIL" -> "清洗失败:" + StrUtil.blankToDefault(reason, "原因见处理日志");
|
|
|
+ case "SKIP" -> "已跳过:" + StrUtil.blankToDefault(reason, "源文件不可用");
|
|
|
+ default -> {
|
|
|
+ if ("A".equals(job.getExitCode())) {
|
|
|
+ String name = job.getRefTemplateId() == null ? null
|
|
|
+ : GlobalCache.idNameZhMap().get(job.getRefTemplateId());
|
|
|
+ yield "AI 匹配模板:" + StrUtil.blankToDefault(name,
|
|
|
+ job.getRefTemplateId() == null ? "未知模板" : String.valueOf(job.getRefTemplateId()));
|
|
|
+ }
|
|
|
+ if ("B".equals(job.getExitCode())) {
|
|
|
+ yield "AI 新建表:" + StrUtil.blankToDefault(
|
|
|
+ aiTableName(job.getAiTemplateId(), aiTableNames),
|
|
|
+ job.getAiTemplateId() == null ? "AI 表" : "ai_t" + job.getAiTemplateId());
|
|
|
+ }
|
|
|
+ yield ""; // 判定进行中,暂无备注
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ private String aiTableName(Long aiTemplateId, Map<Long, String> cache) {
|
|
|
+ if (aiTemplateId == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return cache.computeIfAbsent(aiTemplateId, id -> {
|
|
|
+ com.zsjz.ai.module.aiclean.entity.AiCleanTemplate tpl = aiCleanTemplateMapper.selectById(id);
|
|
|
+ return tpl == null ? null : tpl.getTableNameCn();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
public void deletedFiles(List<Long> ids) {
|
|
|
if (CollUtil.isEmpty(ids)) {
|
|
|
return;
|