文件上传修复
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package org.xyzh.ai.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -30,7 +30,7 @@ import java.util.Arrays;
|
||||
@RequestMapping("/ai/agent")
|
||||
public class AgentController {
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 3000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private AgentService agentService;
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.xyzh.ai.controller;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -38,10 +38,10 @@ import java.util.Map;
|
||||
@RequestMapping("/ai/chat")
|
||||
public class ChatController {
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private AgentChatService chatService;
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private AIFileUploadService fileUploadService;
|
||||
|
||||
// ====================== 会话管理 ======================
|
||||
|
||||
@@ -7,7 +7,9 @@ import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -40,10 +42,10 @@ import java.util.Map;
|
||||
public class KnowledgeController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(KnowledgeController.class);
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private KnowledgeService knowledgeService;
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private DifyProxyService difyProxyService;
|
||||
|
||||
// ====================== 知识库管理 ======================
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.xyzh.ai.service.impl;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -35,7 +34,7 @@ public class AIFileUploadServiceImpl implements AIFileUploadService {
|
||||
@Autowired
|
||||
private DifyApiClient difyApiClient;
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private AgentService agentService;
|
||||
|
||||
// ============================ 对话文件管理 ============================
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.xyzh.ai.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -58,7 +57,7 @@ public class AgentChatServiceImpl implements AgentChatService {
|
||||
@Autowired
|
||||
private TbChatMessageMapper chatMessageMapper;
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 3000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private AgentService agentService;
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -55,7 +55,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
||||
@DubboReference(version = "1.0.0", group = "file", timeout = 30000)
|
||||
private FileService fileService;
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "ai", timeout = 30000, scope = "local")
|
||||
@Autowired
|
||||
private AIFileUploadService aiFileUploadService;
|
||||
|
||||
// ================================= 知识库管理 =================================
|
||||
@@ -464,8 +464,16 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
||||
return ResultDomain.failure("知识库未关联Dify");
|
||||
}
|
||||
|
||||
// 3. 调用FileService上传到minio
|
||||
ResultDomain<TbSysFileDTO> fileResult = fileService.uploadFile(file, "knowledge", knowledgeId);
|
||||
// 3. 调用FileService上传到minio(使用字节数组方式,支持跨模块Dubbo调用)
|
||||
byte[] fileBytes;
|
||||
try {
|
||||
fileBytes = file.getBytes();
|
||||
} catch (Exception e) {
|
||||
logger.error("读取文件字节失败", e);
|
||||
return ResultDomain.failure("读取文件失败: " + e.getMessage());
|
||||
}
|
||||
ResultDomain<TbSysFileDTO> fileResult = fileService.uploadFileBytes(
|
||||
fileBytes, file.getOriginalFilename(), file.getContentType(), "knowledge", knowledgeId);
|
||||
if (!fileResult.getSuccess() || fileResult.getData() == null) {
|
||||
return ResultDomain.failure("上传文件到存储服务失败: " + fileResult.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user