feat: 完善知识库批量导入与公共 API

- 新增批量异步导入、状态查询、失败重试与中断恢复链路

- 拆分知识库读取、导入、维护权限并完善 Public API 契约

- 补充数据库迁移、管理端交互、接口说明与相关测试
This commit is contained in:
2026-08-03 11:13:48 +08:00
parent 6df3dd9981
commit 51dbfd41b6
99 changed files with 16274 additions and 480 deletions

View File

@@ -0,0 +1,78 @@
package tech.easyflow.publicapi.dto;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mybatisflex.core.paginate.Page;
import org.junit.Assert;
import org.junit.Test;
import tech.easyflow.ai.entity.Document;
import tech.easyflow.ai.entity.DocumentCollection;
import java.math.BigInteger;
import java.util.Collections;
import java.util.List;
/**
* {@link PublicKnowledgeDetailResponse} 响应结构测试。
*/
public class PublicKnowledgeDetailResponseTest {
/**
* 验证知识库字段保持在顶层,文档只暴露公开摘要。
*
*/
@Test
public void shouldKeepKnowledgeFieldsAtTopLevelAndExposeDocumentSummary() {
DocumentCollection knowledge = new DocumentCollection();
knowledge.setId(BigInteger.valueOf(100));
knowledge.setTitle("测试知识库");
knowledge.setCollectionType(DocumentCollection.TYPE_DOCUMENT);
Document document = new Document();
document.setId(BigInteger.valueOf(200));
document.setTitle("manual.pdf");
document.setDocumentType("pdf");
document.setContentType("application/pdf");
document.setDocumentPath("private/path/manual.pdf");
document.setContent("内部正文");
document.setProcessStatus("INDEXED");
document.setTotalChunks(12);
document.setProgressPercent(100);
Page<Document> source = new Page<>(List.of(document), 1, 10, 1L);
PublicKnowledgeDetailResponse response =
new PublicKnowledgeDetailResponse(knowledge, source);
JSONObject json = JSON.parseObject(JSON.toJSONString(response));
Assert.assertEquals("100", json.getString("id"));
Assert.assertEquals("测试知识库", json.getString("title"));
Assert.assertFalse(json.containsKey("knowledge"));
JSONObject summary = json.getJSONObject("documents")
.getJSONArray("records")
.getJSONObject(0);
Assert.assertEquals("manual.pdf", summary.getString("title"));
Assert.assertEquals(12L, summary.getLongValue("chunkCount"));
Assert.assertFalse(summary.containsKey("documentPath"));
Assert.assertFalse(summary.containsKey("content"));
Assert.assertFalse(summary.containsKey("options"));
}
/**
* 验证空文档分页保留调用方请求的分页参数。
*/
@Test
public void shouldKeepRequestedPaginationForEmptyDocumentPage() {
DocumentCollection knowledge = new DocumentCollection();
knowledge.setId(BigInteger.valueOf(300));
knowledge.setCollectionType(DocumentCollection.TYPE_FAQ);
Page<Document> source = new Page<>(Collections.emptyList(), 3, 7, 0L);
PublicKnowledgeDetailResponse response =
new PublicKnowledgeDetailResponse(knowledge, source);
Assert.assertEquals(3L, response.getDocuments().getPageNumber());
Assert.assertEquals(7L, response.getDocuments().getPageSize());
Assert.assertEquals(0L, response.getDocuments().getTotalRow());
Assert.assertTrue(response.getDocuments().getRecords().isEmpty());
}
}