素材上传
This commit is contained in:
@@ -2,13 +2,17 @@ package com.rj.controller;
|
||||
|
||||
import com.rj.entity.KnowledgeBase;
|
||||
import com.rj.service.IKnowledgeBaseService;
|
||||
import com.rj.service.MinIOService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -20,6 +24,7 @@ import java.util.Map;
|
||||
* @author 李中华 ,spllzh
|
||||
* @since 2025-01-27
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/knowledgeBase")
|
||||
@Tag(name = "知识库管理", description = "知识库管理相关接口")
|
||||
@@ -28,14 +33,35 @@ public class KnowledgeBaseController {
|
||||
@Autowired
|
||||
private IKnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private MinIOService minIOService;
|
||||
|
||||
/**
|
||||
* 新增知识
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增知识", description = "添加新的知识信息")
|
||||
public ResponseEntity<Map<String, Object>> addKnowledge(
|
||||
@RequestParam(value = "file", required = false) MultipartFile file,
|
||||
@Parameter(description = "知识信息", required = true)
|
||||
@RequestBody KnowledgeBase knowledgeBase) {
|
||||
@ModelAttribute KnowledgeBase knowledgeBase) {
|
||||
// 如果提供了文件,上传到MinIO并保存路径
|
||||
if (file != null && !file.isEmpty()) {
|
||||
try {
|
||||
log.info("开始上传文件到MinIO,文件名:{}", file.getOriginalFilename());
|
||||
String fileUrl = minIOService.uploadFile(file);
|
||||
log.info("文件上传到MinIO成功,URL: {}", fileUrl);
|
||||
// 将上传的文件URL保存到知识库对象的附件URL字段
|
||||
knowledgeBase.setAttachmentUrl(fileUrl);
|
||||
} catch (Exception e) {
|
||||
log.error("文件上传到MinIO失败: {}", e.getMessage(), e);
|
||||
Map<String, Object> errorResult = new HashMap<>();
|
||||
errorResult.put("success", false);
|
||||
errorResult.put("message", "文件上传失败:" + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(errorResult);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> result = knowledgeBaseService.addKnowledge(knowledgeBase);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
|
||||
Reference in New Issue
Block a user