cc il y a 3 semaines
Parent
commit
1a148b7f2c

+ 1 - 1
.zcode/plans/plan-sess_682c09ab-aea3-475c-808b-e64e6686044a.md

@@ -111,7 +111,7 @@
 
 
 **数据入库/路由**
 **数据入库/路由**
 1. 主数据 MyBatis 批量插入 → DuckDB Appender;写入目标改为案件 DuckDB `slave`。
 1. 主数据 MyBatis 批量插入 → DuckDB Appender;写入目标改为案件 DuckDB `slave`。
-2. `EdsImportMaterialMapper` 增加 `@DS(StrConsts.DS_KEY_SLAVE)`;`extraZipData` 用 `CaseContextHolder` 包裹,`FileInfoMapper` 的 `@DS("slave")` 才有案件上下文。
+2. `EdsMaterialMapper` 增加 `@DS(StrConsts.DS_KEY_SLAVE)`;`extraZipData` 用 `CaseContextHolder` 包裹,`FileInfoMapper` 的 `@DS("slave")` 才有案件上下文。
 3. `DuckDbEdsSchema` 保证新案件库有 EDS 表。
 3. `DuckDbEdsSchema` 保证新案件库有 EDS 表。
 4. Appender 列顺序/类型按 `information_schema`,修实体声明顺序与 DuckDB 顺序不一致的 9 张表。
 4. Appender 列顺序/类型按 `information_schema`,修实体声明顺序与 DuckDB 顺序不一致的 9 张表。
 5. `id` 显式生成雪花 ID;`eds_media_file.case_id` 写入;`EdsTreeCount.id` 无 DB 列时跳过。
 5. `id` 显式生成雪花 ID;`eds_media_file.case_id` 写入;`EdsTreeCount.id` 无 DB 列时跳过。

+ 9 - 0
ai-server/src/main/java/com/zsjz/ai/common/model/govern/entity/GovernTree.java

@@ -53,4 +53,13 @@ public class GovernTree extends TreeNode<GovernTree> {
      */
      */
     @TableField(exist = false)
     @TableField(exist = false)
     private String aiTemplateId;
     private String aiTemplateId;
+
+    /**
+     * EDS 检材节点对应的采集编号。
+     *
+     * <p>{@code type=eds} 的顶层节点由 {@code GovernTreeService#fillEds} 按
+     * {@code eds_material} 追加,前端用它继续取该检材的目录树;其他节点为 null。
+     */
+    @TableField(exist = false)
+    private String edsCollectTargetId;
 }
 }

+ 1 - 1
ai-server/src/main/java/com/zsjz/ai/module/eds/mapper/EdsImportMaterialMapper.java → ai-server/src/main/java/com/zsjz/ai/module/eds/mapper/EdsMaterialMapper.java

@@ -17,7 +17,7 @@ import static com.zsjz.ai.common.constants.StrConsts.DS_KEY_SLAVE;
  */
  */
 @Mapper
 @Mapper
 @DS(DS_KEY_SLAVE)
 @DS(DS_KEY_SLAVE)
-public interface EdsImportMaterialMapper extends BaseMapper<EdsMaterial> {
+public interface EdsMaterialMapper extends BaseMapper<EdsMaterial> {
     @Select("""
     @Select("""
             select count(collect_target_id)
             select count(collect_target_id)
                 from wa_mforensics_010100
                 from wa_mforensics_010100

+ 3 - 0
ai-server/src/main/java/com/zsjz/ai/module/eds/po/EdsMaterial.java

@@ -24,6 +24,9 @@ public class EdsMaterial {
     @TableId(type = IdType.ASSIGN_ID)
     @TableId(type = IdType.ASSIGN_ID)
     private Long id;
     private Long id;
 
 
+    @TableField(value = "file_name")
+    private String fileName;
+
     /**
     /**
      * 采集目标编号。
      * 采集目标编号。
      */
      */

+ 99 - 11
ai-server/src/main/java/com/zsjz/ai/module/eds/xml/EdsExtra.java

@@ -10,11 +10,13 @@ import com.zsjz.ai.module.dm.mapper.FileInfoMapper;
 import com.zsjz.ai.module.eds.duckdb.EdsImportActivityProbe;
 import com.zsjz.ai.module.eds.duckdb.EdsImportActivityProbe;
 import com.zsjz.ai.module.eds.enums.EdsEntityEnum;
 import com.zsjz.ai.module.eds.enums.EdsEntityEnum;
 import com.zsjz.ai.module.eds.enums.EdsTreeEnum;
 import com.zsjz.ai.module.eds.enums.EdsTreeEnum;
-import com.zsjz.ai.module.eds.mapper.EdsImportMaterialMapper;
+import com.zsjz.ai.module.eds.mapper.EdsMaterialMapper;
 import com.zsjz.ai.module.eds.mapper.EdsTreeCountMapper;
 import com.zsjz.ai.module.eds.mapper.EdsTreeCountMapper;
 import com.zsjz.ai.module.eds.po.EdsEntityFieldInfo;
 import com.zsjz.ai.module.eds.po.EdsEntityFieldInfo;
+import com.zsjz.ai.module.eds.po.EdsMaterial;
 import com.zsjz.ai.module.eds.po.EdsTreeCount;
 import com.zsjz.ai.module.eds.po.EdsTreeCount;
 import com.zsjz.ai.module.eds.po.basic.EdsMforensics010100;
 import com.zsjz.ai.module.eds.po.basic.EdsMforensics010100;
+import com.zsjz.ai.module.eds.po.checkmaterial.EdsMforensics160100;
 import com.zsjz.ai.module.eds.utils.DataCountInfo;
 import com.zsjz.ai.module.eds.utils.DataCountInfo;
 import com.zsjz.ai.module.eds.utils.Eds;
 import com.zsjz.ai.module.eds.utils.Eds;
 import com.zsjz.ai.module.eds.utils.EdsConstant;
 import com.zsjz.ai.module.eds.utils.EdsConstant;
@@ -27,6 +29,7 @@ import org.springframework.stereotype.Service;
 import javax.sql.DataSource;
 import javax.sql.DataSource;
 import java.nio.file.Files;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Path;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -63,7 +66,7 @@ public class EdsExtra {
     private final XStream xStream;
     private final XStream xStream;
 
 
     private final StringRedisTemplate stringRedisTemplate;
     private final StringRedisTemplate stringRedisTemplate;
-    private final EdsImportMaterialMapper edsImportMaterialMapper;
+    private final EdsMaterialMapper edsMaterialMapper;
 
 
     private final FileInfoMapper fileInfoMapper;
     private final FileInfoMapper fileInfoMapper;
 
 
@@ -149,7 +152,32 @@ public class EdsExtra {
         message.setTask(dto);
         message.setTask(dto);
 
 
         //解析数据并批量入库
         //解析数据并批量入库
-        dataStorage(message);
+        EdsMaterial material = buildMaterial(baseInfo, message, ctId);
+        material.setFileName(dto.getFileName());
+        dataStorage(message, material);
+    }
+
+    /**
+     * 组装检材登记信息(数据量在 finish 阶段从 Redis 读取后回填)。
+     *
+     * @param baseInfo 010100 基础信息
+     * @param message  索引文件消息
+     * @param ctId     清洗后的采集编号
+     * @return 检材登记草稿
+     */
+    private EdsMaterial buildMaterial(EdsMforensics010100 baseInfo, DataMessage message, String ctId) {
+        EdsMaterial material = new EdsMaterial();
+        material.setCollectTargetId(ctId);
+        material.setPoliceName(baseInfo.getPrincipalName());
+        material.setPoliceNo(baseInfo.getPoliceNo());
+        material.setInchargeDepartment(baseInfo.getInchargeWaDepartment());
+        material.setCaseType(baseInfo.getCaseType());
+        //检材类型在 160100 中描述,缺失时留空
+        List<EdsMforensics160100> materialRows = message.readRows(EdsMforensics160100.class);
+        if (CollUtil.isNotEmpty(materialRows)) {
+            material.setMaterialType(materialRows.getFirst().getMaterialType());
+        }
+        return material;
     }
     }
 
 
     /**
     /**
@@ -181,9 +209,10 @@ public class EdsExtra {
     /**
     /**
      * 逐表解析并入库。
      * 逐表解析并入库。
      *
      *
-     * @param message         索引文件消息
+     * @param message  索引文件消息
+     * @param material 检材登记草稿
      */
      */
-    private void dataStorage(DataMessage message) {
+    private void dataStorage(DataMessage message, EdsMaterial material) {
         String collectTargetId = message.getCollectTargetId();
         String collectTargetId = message.getCollectTargetId();
         List<DataInfo> dataInfoList = message.tables();
         List<DataInfo> dataInfoList = message.tables();
         DataCountInfo dataCountInfo = new DataCountInfo(collectTargetId);
         DataCountInfo dataCountInfo = new DataCountInfo(collectTargetId);
@@ -195,7 +224,7 @@ public class EdsExtra {
         EdsExtraFile dto = message.getTask();
         EdsExtraFile dto = message.getTask();
         if (dataInfoList.isEmpty()) {
         if (dataInfoList.isEmpty()) {
             //没有需要提取的数据集,也要走清理/登记,否则 Redis key 与 file_info 会残留
             //没有需要提取的数据集,也要走清理/登记,否则 Redis key 与 file_info 会残留
-            finish(dto, dataCountInfo);
+            finish(dto, dataCountInfo, material);
             return;
             return;
         }
         }
         for (DataInfo dataInfo : dataInfoList) {
         for (DataInfo dataInfo : dataInfoList) {
@@ -206,7 +235,7 @@ public class EdsExtra {
                 //当前数据集处理完成,剩余计数减一
                 //当前数据集处理完成,剩余计数减一
                 Long remaining = stringRedisTemplate.opsForValue().decrement(remainingKey);
                 Long remaining = stringRedisTemplate.opsForValue().decrement(remainingKey);
                 if (remaining != null && remaining <= 0) {
                 if (remaining != null && remaining <= 0) {
-                    finish(dto, dataCountInfo);
+                    finish(dto, dataCountInfo, material);
                 }
                 }
             }
             }
         }
         }
@@ -264,7 +293,7 @@ public class EdsExtra {
 
 
         //确认采集编号未被导入
         //确认采集编号未被导入
         try {
         try {
-            int count = edsImportMaterialMapper.countByCid(ctId);
+            int count = edsMaterialMapper.countByCid(ctId);
             return count <= 0;
             return count <= 0;
         } catch (Exception e) {
         } catch (Exception e) {
             log.error("包:{},基本信息采集编号异常或基本信息表不存在, 无法解析", ctId, e);
             log.error("包:{},基本信息采集编号异常或基本信息表不存在, 无法解析", ctId, e);
@@ -275,24 +304,83 @@ public class EdsExtra {
     /**
     /**
      * 提取完成后的清理与登记。
      * 提取完成后的清理与登记。
      *
      *
-     * @param dto 提取任务信息
+     * @param dto           提取任务信息
+     * @param dataCountInfo 目录树统计
+     * @param material      检材登记草稿
      */
      */
-    public void finish(EdsExtraFile dto, DataCountInfo dataCountInfo) {
-        Eds.delZip(dto.getExtractDir(), dto.getArchivePath());
+    public void finish(EdsExtraFile dto, DataCountInfo dataCountInfo, EdsMaterial material) {
         String dataCntKey = EtlRedisKey.dataCountKey(dto.getCollectTargetId());
         String dataCntKey = EtlRedisKey.dataCountKey(dto.getCollectTargetId());
+        //入库计数必须在删除前读取:BcpTableWriter 每批 flush 成功后累计
+        int importedRows = readDataCount(dataCntKey);
         String dataSetKey = EtlRedisKey.dataSetKey(dto.getCollectTargetId());
         String dataSetKey = EtlRedisKey.dataSetKey(dto.getCollectTargetId());
         stringRedisTemplate.delete(List.of(dataCntKey, dataSetKey));
         stringRedisTemplate.delete(List.of(dataCntKey, dataSetKey));
 
 
+        Eds.delZip(dto.getExtractDir(), dto.getArchivePath());
+
         FileInfo fileInfo = new FileInfo();
         FileInfo fileInfo = new FileInfo();
         fileInfo.setPid(0L);
         fileInfo.setPid(0L);
         fileInfo.setFileName(dto.getFileName());
         fileInfo.setFileName(dto.getFileName());
         fileInfo.setFileType(FILE_TYPE_DATA_PACKAGE);
         fileInfo.setFileType(FILE_TYPE_DATA_PACKAGE);
         fileInfo.setFilePath(dto.getPath().toString());
         fileInfo.setFilePath(dto.getPath().toString());
         fileInfoMapper.insert(fileInfo);
         fileInfoMapper.insert(fileInfo);
+        registerMaterial(material, importedRows);
         addDirTreeCount(dataCountInfo);
         addDirTreeCount(dataCountInfo);
         log.info("数据包[{}]:已提取完成。", dto.getFileName());
         log.info("数据包[{}]:已提取完成。", dto.getFileName());
     }
     }
 
 
+    /**
+     * 读取 Redis 中累计的入库数据量。
+     */
+    private int readDataCount(String dataCntKey) {
+        try {
+            String value = stringRedisTemplate.opsForValue().get(dataCntKey);
+            if (StrUtil.isBlank(value)) {
+                return 0;
+            }
+            return (int) Math.min(Long.parseLong(value.trim()), Integer.MAX_VALUE);
+        } catch (Exception e) {
+            log.warn("读取入库数据量失败: key={}, err={}", dataCntKey, e.getMessage());
+            return 0;
+        }
+    }
+
+    /**
+     * 登记检材导入记录,供治理树展示(fillEds)。
+     *
+     * <p>旧案件库可能没有 {@code eds_material} 表,登记失败只记日志,不影响提取结果。</p>
+     */
+    private void registerMaterial(EdsMaterial material, int dataCount) {
+        if (material == null || StrUtil.isEmpty(material.getCollectTargetId())) {
+            return;
+        }
+        material.setDataCount(dataCount);
+        material.setImportTime(LocalDateTime.now());
+        try {
+            edsMaterialMapper.insert(material);
+            log.info("检材登记完成: cid={}, dataCount={}", material.getCollectTargetId(), dataCount);
+        } catch (Exception e) {
+            log.warn("检材登记失败: cid={}, err={}", material.getCollectTargetId(), e.getMessage());
+            retryWithoutFileName(material, dataCount);
+        }
+    }
+
+    /**
+     * 旧案件库可能还没有 {@code file_name} 列:去掉文件名重试一次,保证检材登记不丢。
+     */
+    private void retryWithoutFileName(EdsMaterial material, int dataCount) {
+        if (StrUtil.isEmpty(material.getFileName())) {
+            return;
+        }
+        material.setFileName(null);
+        try {
+            edsMaterialMapper.insert(material);
+            log.info("检材登记完成(库中无 file_name 列,未记录文件名): cid={}, dataCount={}",
+                    material.getCollectTargetId(), dataCount);
+        } catch (Exception e) {
+            log.warn("检材登记重试失败: cid={}, err={}", material.getCollectTargetId(), e.getMessage());
+        }
+    }
+
     /**
     /**
      * 将目录树统计写入 DuckDB(数据量很小,走 MyBatis)。
      * 将目录树统计写入 DuckDB(数据量很小,走 MyBatis)。
      *
      *

+ 81 - 0
ai-server/src/main/java/com/zsjz/ai/module/govern/serivce/GovernTreeService.java

@@ -32,6 +32,8 @@ import com.zsjz.ai.common.utils.TreeUtils;
 import com.zsjz.ai.module.call.mapper.CallRecordAllMapper;
 import com.zsjz.ai.module.call.mapper.CallRecordAllMapper;
 import com.zsjz.ai.module.call.mapper.CallRecordMapper;
 import com.zsjz.ai.module.call.mapper.CallRecordMapper;
 import com.zsjz.ai.module.call.mapper.UseOpenInfoCallRecordMapper;
 import com.zsjz.ai.module.call.mapper.UseOpenInfoCallRecordMapper;
+import com.zsjz.ai.module.eds.mapper.EdsMaterialMapper;
+import com.zsjz.ai.module.eds.po.EdsMaterial;
 import com.zsjz.ai.module.govern.mapper.GovernTreeMapper;
 import com.zsjz.ai.module.govern.mapper.GovernTreeMapper;
 import com.zsjz.ai.module.person.mapper.PersonBasicInfoMapper;
 import com.zsjz.ai.module.person.mapper.PersonBasicInfoMapper;
 import com.zsjz.ai.module.trans.mapper.AcctOpenInfoMapper;
 import com.zsjz.ai.module.trans.mapper.AcctOpenInfoMapper;
@@ -44,6 +46,7 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.StandardCharsets;
 import java.time.LocalDate;
 import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Objects;
@@ -58,6 +61,20 @@ import java.util.stream.Collectors;
 @Service
 @Service
 @Slf4j
 @Slf4j
 public class GovernTreeService extends ServiceImpl<GovernTreeMapper, GovernTree> {
 public class GovernTreeService extends ServiceImpl<GovernTreeMapper, GovernTree> {
+
+    /**
+     * EDS 检材节点类型(前端按该类型 + edsCollectTargetId 取检材目录树)
+     */
+    private static final String TYPE_EDS = "eds";
+
+    /**
+     * EDS 节点 id 起始值:保留正数段,避开 table_info.id 与 AI 节点的负数 id;
+     * 9e12 仍在 JS 安全整数范围内,前端按 JSON number 处理不会丢精度。
+     */
+    private static final long EDS_NODE_ID_BASE = 9_000_000_000_000L;
+
+    private static final DateTimeFormatter EDS_NODE_TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
+
     @Autowired
     @Autowired
     private PersonBasicInfoMapper personBasicInfoMapper;
     private PersonBasicInfoMapper personBasicInfoMapper;
     @Autowired
     @Autowired
@@ -74,6 +91,8 @@ public class GovernTreeService extends ServiceImpl<GovernTreeMapper, GovernTree>
     private UseOpenInfoCallRecordMapper useOpenInfoCallRecordMapper;
     private UseOpenInfoCallRecordMapper useOpenInfoCallRecordMapper;
     @Autowired
     @Autowired
     private AcctOpenInfoMapper acctOpenInfoMapper;
     private AcctOpenInfoMapper acctOpenInfoMapper;
+    @Autowired
+    private EdsMaterialMapper edsMaterialMapper;
 
 
 
 
     /**
     /**
@@ -85,9 +104,71 @@ public class GovernTreeService extends ServiceImpl<GovernTreeMapper, GovernTree>
     public List<GovernTree> getTree() {
     public List<GovernTree> getTree() {
         List<GovernTree> tree = TreeUtils.build(list(Wrappers.lambdaQuery(GovernTree.class).gt(GovernTree::getDataCount, 0)));
         List<GovernTree> tree = TreeUtils.build(list(Wrappers.lambdaQuery(GovernTree.class).gt(GovernTree::getDataCount, 0)));
         fillAiTemplateIds(tree);
         fillAiTemplateIds(tree);
+        fillEds(tree);
         return tree;
         return tree;
     }
     }
 
 
+    /**
+     * 把已导入的 EDS 检材挂到治理树顶层(每个采集编号一个节点)。
+     *
+     * <p>节点不落库,仅在 {@link #getTree()} 的响应里追加;前端按
+     * {@code type=eds} + {@code edsCollectTargetId} 继续取该检材的目录树。
+     * 读取检材登记失败时只跳过 EDS 节点,不影响治理树本身。</p>
+     *
+     * @param tree 已构建完成的治理树
+     */
+    private void fillEds(List<GovernTree> tree) {
+        if (tree == null) {
+            return;
+        }
+        List<EdsMaterial> materials;
+        try {
+            materials = edsMaterialMapper.selectList(Wrappers.<EdsMaterial>lambdaQuery()
+                    .orderByDesc(EdsMaterial::getImportTime)
+                    .orderByDesc(EdsMaterial::getId));
+        } catch (Exception e) {
+            //旧案件库可能没有 eds_material 表,不能因此让整个治理树接口失败
+            log.warn("读取检材登记失败,跳过 EDS 节点: {}", e.getMessage());
+            return;
+        }
+        if (CollUtil.isEmpty(materials)) {
+            return;
+        }
+
+        int index = 0;
+        for (EdsMaterial material : materials) {
+            if (material == null || StrUtil.isEmpty(material.getCollectTargetId())) {
+                continue;
+            }
+            tree.add(buildEdsNode(material, index++));
+        }
+    }
+
+    private static GovernTree buildEdsNode(EdsMaterial material, int index) {
+        GovernTree node = new GovernTree();
+        node.setId(EDS_NODE_ID_BASE + index);
+        node.setPid(0L);
+        node.setType(TYPE_EDS);
+        //检材没有单一物理表,tableNameEn 放采集编号,方便只读该字段的调用方取数
+        node.setTableNameEn(material.getCollectTargetId());
+        node.setTableNameCn(buildEdsNodeName(material, index));
+        node.setDataCount(material.getDataCount() == null ? 0 : material.getDataCount());
+        node.setEdsCollectTargetId(material.getCollectTargetId());
+        return node;
+    }
+
+    private static String buildEdsNodeName(EdsMaterial material, int index) {
+        //优先展示数据包文件名;旧数据没有文件名时退回"检材N(导入时间)"
+        if (StrUtil.isNotBlank(material.getFileName())) {
+            return material.getFileName();
+        }
+        String prefix = "检材" + (index + 1);
+        if (material.getImportTime() == null) {
+            return prefix;
+        }
+        return prefix + "(" + material.getImportTime().format(EDS_NODE_TIME_FORMAT) + ")";
+    }
+
     /**
     /**
      * 给 AI 动态表节点补字符串形式的模板 id(id 取负存放,雪花 id 超过 JS 安全整数范围,
      * 给 AI 动态表节点补字符串形式的模板 id(id 取负存放,雪花 id 超过 JS 安全整数范围,
      * 前端用 JSON number 换算会丢精度,必须下发字符串)。
      * 前端用 JSON number 换算会丢精度,必须下发字符串)。

+ 8 - 3
ai-server/src/test/java/com/zsjz/ai/module/eds/xml/DemoBcpImportTest.java

@@ -11,7 +11,7 @@ import com.zsjz.ai.common.config.DuckdbUnpooledDataSource;
 import com.zsjz.ai.common.utils.LocalFileStorageUtil;
 import com.zsjz.ai.common.utils.LocalFileStorageUtil;
 import com.zsjz.ai.module.dm.mapper.FileInfoMapper;
 import com.zsjz.ai.module.dm.mapper.FileInfoMapper;
 import com.zsjz.ai.module.eds.duckdb.EdsImportActivityProbe;
 import com.zsjz.ai.module.eds.duckdb.EdsImportActivityProbe;
-import com.zsjz.ai.module.eds.mapper.EdsImportMaterialMapper;
+import com.zsjz.ai.module.eds.mapper.EdsMaterialMapper;
 import com.zsjz.ai.module.eds.mapper.EdsMediaFileMapper;
 import com.zsjz.ai.module.eds.mapper.EdsMediaFileMapper;
 import com.zsjz.ai.module.eds.mapper.EdsTreeCountMapper;
 import com.zsjz.ai.module.eds.mapper.EdsTreeCountMapper;
 import org.apache.ibatis.mapping.Environment;
 import org.apache.ibatis.mapping.Environment;
@@ -127,7 +127,7 @@ class DemoBcpImportTest {
         MybatisConfiguration configuration = new MybatisConfiguration(
         MybatisConfiguration configuration = new MybatisConfiguration(
                 new Environment("demo-case", new JdbcTransactionFactory(), caseDataSource));
                 new Environment("demo-case", new JdbcTransactionFactory(), caseDataSource));
         GlobalConfigUtils.setGlobalConfig(configuration, GlobalConfigUtils.defaults());
         GlobalConfigUtils.setGlobalConfig(configuration, GlobalConfigUtils.defaults());
-        configuration.addMapper(EdsImportMaterialMapper.class);
+        configuration.addMapper(EdsMaterialMapper.class);
         configuration.addMapper(FileInfoMapper.class);
         configuration.addMapper(FileInfoMapper.class);
         configuration.addMapper(EdsTreeCountMapper.class);
         configuration.addMapper(EdsTreeCountMapper.class);
         configuration.addMapper(EdsMediaFileMapper.class);
         configuration.addMapper(EdsMediaFileMapper.class);
@@ -140,7 +140,7 @@ class DemoBcpImportTest {
         EdsExtraFile dto = new EdsExtraFile(zipName, null, zipCopy, "test", 999L);
         EdsExtraFile dto = new EdsExtraFile(zipName, null, zipCopy, "test", 999L);
 
 
         try (SqlSession sqlSession = sqlSessionFactory.openSession(true)) {
         try (SqlSession sqlSession = sqlSessionFactory.openSession(true)) {
-            EdsImportMaterialMapper importMapper = sqlSession.getMapper(EdsImportMaterialMapper.class);
+            EdsMaterialMapper importMapper = sqlSession.getMapper(EdsMaterialMapper.class);
             FileInfoMapper fileInfoMapper = sqlSession.getMapper(FileInfoMapper.class);
             FileInfoMapper fileInfoMapper = sqlSession.getMapper(FileInfoMapper.class);
             EdsTreeCountMapper treeCountMapper = sqlSession.getMapper(EdsTreeCountMapper.class);
             EdsTreeCountMapper treeCountMapper = sqlSession.getMapper(EdsTreeCountMapper.class);
             EdsMediaFileMapper mediaFileMapper = sqlSession.getMapper(EdsMediaFileMapper.class);
             EdsMediaFileMapper mediaFileMapper = sqlSession.getMapper(EdsMediaFileMapper.class);
@@ -180,6 +180,11 @@ class DemoBcpImportTest {
             assertEquals(0L, fileInfoPid(connection, zipName));
             assertEquals(0L, fileInfoPid(connection, zipName));
             assertTrue(countByCid(connection, "eds_tree_count", dto.getCollectTargetId()) > 0);
             assertTrue(countByCid(connection, "eds_tree_count", dto.getCollectTargetId()) > 0);
             assertTrue(countByCid(connection, "eds_media_file", dto.getCollectTargetId()) > 0);
             assertTrue(countByCid(connection, "eds_media_file", dto.getCollectTargetId()) > 0);
+            assertEquals(1L, countByCid(connection, "eds_material", dto.getCollectTargetId()),
+                    "检材登记记录缺失或重复");
+            assertEquals(zipName, queryString(connection,
+                    "select file_name from eds_material where collect_target_id = '"
+                            + dto.getCollectTargetId() + "' limit 1"));
 
 
             // 校验 160100 的字段错位修复:索引里是 " FILE_SIZE"(带前导空格)
             // 校验 160100 的字段错位修复:索引里是 " FILE_SIZE"(带前导空格)
             try (Statement st = connection.createStatement();
             try (Statement st = connection.createStatement();

+ 73 - 0
ai-server/src/test/java/com/zsjz/ai/module/govern/serivce/GovernTreeServiceTest.java

@@ -0,0 +1,73 @@
+package com.zsjz.ai.module.govern.serivce;
+
+import com.zsjz.ai.common.model.govern.entity.GovernTree;
+import com.zsjz.ai.module.eds.mapper.EdsMaterialMapper;
+import com.zsjz.ai.module.eds.po.EdsMaterial;
+import com.zsjz.ai.module.govern.mapper.GovernTreeMapper;
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * 治理树 EDS 节点:每个检材追加一个 type=eds 的顶层节点。
+ */
+class GovernTreeServiceTest {
+
+    @Test
+    @SuppressWarnings("unchecked")
+    void appendsOneEdsNodePerMaterial() {
+        GovernTreeService service = new GovernTreeService();
+        GovernTreeMapper treeMapper = mock(GovernTreeMapper.class);
+        EdsMaterialMapper materialMapper = mock(EdsMaterialMapper.class);
+        ReflectionTestUtils.setField(service, "baseMapper", treeMapper);
+        ReflectionTestUtils.setField(service, "edsMaterialMapper", materialMapper);
+
+        GovernTree tableNode = new GovernTree();
+        tableNode.setId(1L);
+        tableNode.setPid(0L);
+        tableNode.setType("table");
+        tableNode.setTableNameEn("call_record");
+        tableNode.setDataCount(5);
+        when(treeMapper.selectList(any())).thenReturn(List.of(tableNode));
+
+        EdsMaterial first = material("CID-1", 10, LocalDateTime.of(2026, 11, 2, 12, 0), "李如云演示数据.zip");
+        EdsMaterial second = material("CID-2", 20, LocalDateTime.of(2026, 11, 1, 9, 30), null);
+        when(materialMapper.selectList(any())).thenReturn(List.of(first, second));
+
+        List<GovernTree> tree = service.getTree();
+
+        assertTrue(tree.contains(tableNode));
+        List<GovernTree> edsNodes = tree.stream().filter(node -> "eds".equals(node.getType())).toList();
+        assertEquals(2, edsNodes.size());
+
+        GovernTree firstNode = edsNodes.get(0);
+        assertEquals("CID-1", firstNode.getEdsCollectTargetId());
+        assertEquals("CID-1", firstNode.getTableNameEn());
+        assertEquals("李如云演示数据.zip", firstNode.getTableNameCn());
+        assertEquals(10, firstNode.getDataCount());
+        assertEquals(9_000_000_000_000L, firstNode.getId());
+        assertEquals(0L, firstNode.getPid());
+
+        GovernTree secondNode = edsNodes.get(1);
+        assertEquals("CID-2", secondNode.getEdsCollectTargetId());
+        assertEquals("检材2(2026-11-01 09:30)", secondNode.getTableNameCn());
+        assertEquals(9_000_000_000_001L, secondNode.getId());
+    }
+
+    private static EdsMaterial material(String cid, int dataCount, LocalDateTime importTime, String fileName) {
+        EdsMaterial material = new EdsMaterial();
+        material.setCollectTargetId(cid);
+        material.setDataCount(dataCount);
+        material.setImportTime(importTime);
+        material.setFileName(fileName);
+        return material;
+    }
+}