18586361686
2025-05-12 3bd375ab120c6c90df48120390af0b9ec6573690
feat: 知识库增加excel文件导入
close #IC6IY6
7个文件已修改
49 ■■■■ 已修改文件
aiflowy-commons/aiflowy-common-ai/pom.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aiflowy-commons/aiflowy-common-ai/src/main/java/tech/aiflowy/common/ai/DocumentParserFactory.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/service/impl/AiDocumentServiceImpl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aiflowy-modules/aiflowy-module-core/src/main/java/tech/aiflowy/core/utils/JudgeFileTypeUtil.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aiflowy-ui-react/src/pages/ai/aiKnowledge/Document.tsx 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aiflowy-ui-react/src/pages/ai/aiKnowledge/FileImportPanel.tsx 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aiflowy-commons/aiflowy-common-ai/pom.xml
@@ -119,6 +119,11 @@
            <artifactId>hutool-json</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
        </dependency>
    </dependencies>
</project>
aiflowy-commons/aiflowy-common-ai/src/main/java/tech/aiflowy/common/ai/DocumentParserFactory.java
@@ -25,6 +25,9 @@
        if (typeOrFileName.endsWith(".md")) {
            return new MarkdownDocumentParser();
        }
        if (typeOrFileName.endsWith(".xlsx")) {
            return new ExcelDocumentParser();
        }
        return null;
    }
}
aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/service/impl/AiDocumentServiceImpl.java
@@ -164,6 +164,12 @@
                return ResponseEntity.ok()
                        .contentType(MediaType.TEXT_PLAIN)
                        .body(textContent);
            case "xlsx":
                // 文本文件:直接返回内容
                String excelToMarkdownContent = aiDocument.getContent();
                return ResponseEntity.ok()
                        .contentType(MediaType.TEXT_PLAIN)
                        .body(excelToMarkdownContent);
            case "jpg":
            case "jpeg":
aiflowy-modules/aiflowy-module-core/src/main/java/tech/aiflowy/core/utils/JudgeFileTypeUtil.java
@@ -16,7 +16,10 @@
            return "md";
        } else if (fileName.endsWith(".docx")) {
            return "docx";
        } else {
        } else if (fileName.endsWith(".xlsx")) {
            return "xlsx";
        }
        else {
            return null;
        }
    }
aiflowy-ui-react/src/pages/ai/aiKnowledge/Document.tsx
@@ -373,7 +373,12 @@
                setFileContent(data);
                setIsDocPreviewContent(true);
            } else {
            }else if (contentType.includes('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')) {
                // 纯文本文件
                setFileContent(data);
                setIsDocPreviewContent(true);
            }
            else {
                setError('不支持的文件类型');
                setIsDocPreviewContent(true);
aiflowy-ui-react/src/pages/ai/aiKnowledge/FileImportPanel.tsx
@@ -84,23 +84,24 @@
            file.type === "application/pdf" ||
            file.type === "application/markdown" ||
            file.type === "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ||
            file.type === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ||
            file.name.endsWith(".md");
        const isLt15M = file.size / 1024 / 1024 < 200;
        const isLt20M = file.size / 1024 / 1024 < 20;
        if (!isAllowedType) {
            message.error("仅支持 txt, pdf, md, docx 格式的文件!");
            message.error("仅支持 txt, pdf, md, docx, xlsx 格式的文件!");
        }
        if (!isLt15M) {
            message.error("单个文件大小不能超过 15MB!");
        if (!isLt20M) {
            message.error("单个文件大小不能超过 20MB!");
        }
        if (isAllowedType && isLt15M){
        if (isAllowedType && isLt20M){
            setPreviewListLoading({
                spinning: true,
                tip: '正在加载数据,请稍候...'
            })
        }
        return isAllowedType && isLt15M;
        return isAllowedType && isLt20M;
    };
    // 状态管理:当前选中的选项
    const [selectedOption, setSelectedOption] = useState("document");
@@ -151,7 +152,7 @@
                    {/* 上传文件 */}
                    <p className="section-description">
                        支持 txt, pdf, docx, md 格式文件,单次最多上传 {maxCount} 个文件,单个大小不超过 15M。
                        支持 txt, pdf, docx, md, xlsx 格式文件,单次最多上传 {maxCount} 个文件,单个大小不超过 20M。
                    </p>
@@ -276,7 +277,7 @@
                        <Upload.Dragger
                            name="file"
                            multiple
                            accept=".txt,.pdf,.md,.docx"
                            accept=".txt,.pdf,.md,.docx,.xlsx"
                            beforeUpload={beforeUpload}
                            fileList={fileList}
                            onChange={(info) => handleFileChange(info.fileList)}
pom.xml
@@ -37,6 +37,7 @@
        <commons-io.version>2.18.0</commons-io.version>
        <hutool-http.version>5.8.28</hutool-http.version>
        <hutool-json.version>5.8.32</hutool-json.version>
        <easyexcel.version>4.0.3</easyexcel.version>
    </properties>
    <dependencyManagement>
        <dependencies>
@@ -247,6 +248,11 @@
                <artifactId>commons-io</artifactId>
                <version>${commons-io.version}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>easyexcel</artifactId>
                <version>${easyexcel.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>