14 changed files with 431 additions and 31 deletions
-
19src/main/java/com/wok/supportbot/config/DatabaseInitConfig.java
-
80src/main/java/com/wok/supportbot/config/FileStorageConfig.java
-
36src/main/java/com/wok/supportbot/controller/DocumentController.java
-
35src/main/java/com/wok/supportbot/document/extract/JsonDocumentLoader.java
-
37src/main/java/com/wok/supportbot/document/extract/MarkdownDocumentLoader.java
-
41src/main/java/com/wok/supportbot/document/extract/TikaDocumentReader.java
-
6src/main/java/com/wok/supportbot/entity/KnowledgeDocument.java
-
122src/main/java/com/wok/supportbot/service/DocumentService.java
-
5src/main/resources/application-dev.yml
-
9src/main/resources/application-prod.yml
-
4src/main/resources/application.yml
-
7src/main/resources/init-database.sql
-
9src/main/resources/static/components/DocList.js
-
52src/main/resources/static/js/api.js
@ -0,0 +1,80 @@ |
|||
package com.wok.supportbot.config; |
|||
|
|||
import jakarta.annotation.PostConstruct; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.io.File; |
|||
import java.nio.file.Path; |
|||
import java.nio.file.Paths; |
|||
|
|||
/** |
|||
* 文件存储配置 |
|||
* 管理上传文件的本地存储路径 |
|||
*/ |
|||
@Component |
|||
@Slf4j |
|||
public class FileStorageConfig { |
|||
|
|||
@Value("${knowledge.storage.local-path:./uploads}") |
|||
private String localPath; |
|||
|
|||
private Path storageRootPath; |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
storageRootPath = Paths.get(localPath).toAbsolutePath().normalize(); |
|||
File rootDir = storageRootPath.toFile(); |
|||
if (!rootDir.exists()) { |
|||
boolean created = rootDir.mkdirs(); |
|||
if (created) { |
|||
log.info("创建文件存储根目录: {}", storageRootPath); |
|||
} else { |
|||
log.warn("创建文件存储根目录失败: {}", storageRootPath); |
|||
} |
|||
} |
|||
log.info("文件存储路径: {}", storageRootPath); |
|||
} |
|||
|
|||
/** |
|||
* 获取存储根路径 |
|||
*/ |
|||
public Path getStorageRootPath() { |
|||
return storageRootPath; |
|||
} |
|||
|
|||
/** |
|||
* 获取指定文件的完整路径 |
|||
* |
|||
* @param relativePath 相对路径(如 "2024/01/xxx.docx") |
|||
*/ |
|||
public Path getFilePath(String relativePath) { |
|||
return storageRootPath.resolve(relativePath).normalize(); |
|||
} |
|||
|
|||
/** |
|||
* 生成按年月组织的相对路径 |
|||
* |
|||
* @param originalFilename 原始文件名 |
|||
* @return 相对路径,如 "2024/01/uuid.docx" |
|||
*/ |
|||
public String generateRelativePath(String originalFilename) { |
|||
String extension = getExtension(originalFilename); |
|||
String uniqueName = java.util.UUID.randomUUID().toString() + extension; |
|||
|
|||
// 按年月分目录 |
|||
java.time.LocalDate now = java.time.LocalDate.now(); |
|||
return String.format("%d/%02d/%s", now.getYear(), now.getMonthValue(), uniqueName); |
|||
} |
|||
|
|||
/** |
|||
* 获取文件扩展名(含点号) |
|||
*/ |
|||
private String getExtension(String filename) { |
|||
if (filename == null || !filename.contains(".")) { |
|||
return ""; |
|||
} |
|||
return filename.substring(filename.lastIndexOf(".")).toLowerCase(); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue