Selaa lähdekoodia

feat: 收敛文件元数据项目隔离查询

WangKang 5 päivää sitten
vanhempi
commit
95083df399

+ 2 - 3
emoon-infra/emoon-modules/emoon-ai/emoon-ai-file/src/main/java/com/emoon/ai/file/application/FileService.java

@@ -10,7 +10,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
 import java.util.Map;
-import java.util.Objects;
 
 @Slf4j
 @Service
@@ -45,8 +44,8 @@ public class FileService {
     }
 
     public Map<String, Object> getFile(String fileId, String projectId) {
-        AiFileObjectDO fo = fileMapper.selectByFileId(fileId);
-        if (fo == null || !Objects.equals(fo.getProjectId(), projectId)) return null;
+        AiFileObjectDO fo = fileMapper.selectByFileIdAndProjectId(fileId, projectId);
+        if (fo == null) return null;
         return Map.of(
             "fileId", fo.getFileId(),
             "businessType", fo.getBusinessType(),

+ 4 - 0
emoon-infra/emoon-modules/emoon-ai/emoon-ai-file/src/main/java/com/emoon/ai/file/mapper/FileObjectMapper.java

@@ -11,4 +11,8 @@ public interface FileObjectMapper extends BaseMapper<AiFileObjectDO> {
 
     @Select("SELECT * FROM ai_file_object WHERE file_id = #{fileId}")
     AiFileObjectDO selectByFileId(@Param("fileId") String fileId);
+
+    @Select("SELECT * FROM ai_file_object WHERE file_id = #{fileId} AND project_id = #{projectId}")
+    AiFileObjectDO selectByFileIdAndProjectId(@Param("fileId") String fileId,
+                                              @Param("projectId") String projectId);
 }

+ 4 - 2
emoon-infra/emoon-modules/emoon-ai/emoon-ai-file/src/test/java/com/emoon/ai/file/application/FileServiceTest.java

@@ -73,17 +73,19 @@ class FileServiceTest {
         existing.setProjectId("prj_001");
         existing.setSensitiveLevel("P3");
 
-        when(fileMapper.selectByFileId("file_001")).thenReturn(existing);
+        when(fileMapper.selectByFileIdAndProjectId("file_001", "prj_001")).thenReturn(existing);
 
         Map<String, Object> result = service.getFile("file_001", "prj_001");
 
         assertThat(result.get("fileId")).isEqualTo("file_001");
         assertThat(result.get("businessType")).isEqualTo("TONGUE_IMAGE");
+        verify(fileMapper).selectByFileIdAndProjectId("file_001", "prj_001");
+        verify(fileMapper, never()).selectByFileId("file_001");
     }
 
     @Test
     void getFileNotFoundReturnsNull() {
-        when(fileMapper.selectByFileId("file_999")).thenReturn(null);
+        when(fileMapper.selectByFileIdAndProjectId("file_999", "prj_001")).thenReturn(null);
         assertThat(service.getFile("file_999", "prj_001")).isNull();
     }
 }