文件上传修复
This commit is contained in:
@@ -11,7 +11,7 @@ CREATE TABLE file.tb_sys_file (
|
||||
create_time TIMESTAMPTZ NOT NULL DEFAULT now(), -- 创建时间
|
||||
update_time TIMESTAMPTZ DEFAULT NULL, -- 更新时间
|
||||
delete_time TIMESTAMPTZ DEFAULT NULL, -- 删除时间
|
||||
deleted INTEGER NOT NULL DEFAULT 0, -- 是否已删除(0-未删除,1-已删除)
|
||||
deleted BOOLEAN NOT NULL DEFAULT false, -- 是否已删除(false-未删除,true-已删除)
|
||||
|
||||
-- TbSysFileDTO 特有字段
|
||||
file_id VARCHAR(50) NOT NULL, -- 文件ID (主键)
|
||||
@@ -48,7 +48,7 @@ COMMENT ON COLUMN file.tb_sys_file.remark IS '备注';
|
||||
COMMENT ON COLUMN file.tb_sys_file.create_time IS '创建时间';
|
||||
COMMENT ON COLUMN file.tb_sys_file.update_time IS '更新时间';
|
||||
COMMENT ON COLUMN file.tb_sys_file.delete_time IS '删除时间';
|
||||
COMMENT ON COLUMN file.tb_sys_file.deleted IS '是否已删除(0-未删除,1-已删除)';
|
||||
COMMENT ON COLUMN file.tb_sys_file.deleted IS '是否已删除(false-未删除,true-已删除)';
|
||||
|
||||
-- TbSysFileDTO 特有字段注释
|
||||
COMMENT ON COLUMN file.tb_sys_file.file_id IS '文件ID (主键)';
|
||||
@@ -71,9 +71,9 @@ COMMENT ON COLUMN file.tb_sys_file.md5_hash IS '文件MD5值';
|
||||
COMMENT ON COLUMN file.tb_sys_file.extension IS '文件扩展名';
|
||||
|
||||
-- 文件表索引
|
||||
CREATE INDEX idx_file_module_business ON file.tb_sys_file(module, business_id) WHERE deleted = 0;
|
||||
CREATE INDEX idx_file_uploader ON file.tb_sys_file(uploader) WHERE deleted = 0;
|
||||
CREATE INDEX idx_file_bucket ON file.tb_sys_file(bucket_name) WHERE deleted = 0;
|
||||
CREATE INDEX idx_file_status ON file.tb_sys_file(status) WHERE deleted = 0;
|
||||
CREATE INDEX idx_file_create_time ON file.tb_sys_file(create_time) WHERE deleted = 0;
|
||||
CREATE INDEX idx_file_md5 ON file.tb_sys_file(md5_hash) WHERE deleted = 0;
|
||||
-- CREATE INDEX idx_file_module_business ON file.tb_sys_file(module, business_id) WHERE deleted = false;
|
||||
-- CREATE INDEX idx_file_uploader ON file.tb_sys_file(uploader) WHERE deleted = false;
|
||||
-- CREATE INDEX idx_file_bucket ON file.tb_sys_file(bucket_name) WHERE deleted = false;
|
||||
-- CREATE INDEX idx_file_status ON file.tb_sys_file(status) WHERE deleted = false;
|
||||
-- CREATE INDEX idx_file_create_time ON file.tb_sys_file(create_time) WHERE deleted = false;
|
||||
-- CREATE INDEX idx_file_md5 ON file.tb_sys_file(md5_hash) WHERE deleted = false;
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -95,4 +95,17 @@ public interface FileService {
|
||||
*/
|
||||
ResultDomain<TbSysFileDTO> uploadFileVersion(MultipartFile file, String module, String businessId, String fileRootId);
|
||||
|
||||
/**
|
||||
* @description 通过字节数组上传文件(用于跨模块 Dubbo 调用)
|
||||
* @param fileBytes 文件字节数组
|
||||
* @param fileName 文件名
|
||||
* @param contentType 文件类型
|
||||
* @param module 所属模块
|
||||
* @param businessId 业务ID
|
||||
* @return ResultDomain<TbSysFileDTO> 上传结果
|
||||
* @author yslg
|
||||
* @since 2025-12-20
|
||||
*/
|
||||
ResultDomain<TbSysFileDTO> uploadFileBytes(byte[] fileBytes, String fileName, String contentType, String module, String businessId);
|
||||
|
||||
}
|
||||
|
||||
@@ -374,6 +374,74 @@ public class FileServiceImpl implements FileService {
|
||||
return ResultDomain.failure("文件上传失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysFileDTO> uploadFileBytes(byte[] fileBytes, String fileName, String contentType, String module, String businessId) {
|
||||
try {
|
||||
if (fileBytes == null || fileBytes.length == 0) {
|
||||
return ResultDomain.failure("文件不能为空");
|
||||
}
|
||||
|
||||
// 生成文件信息
|
||||
String extension = getFileExtension(fileName);
|
||||
long size = fileBytes.length;
|
||||
|
||||
// 生成唯一的对象名称
|
||||
String objectName = generateObjectName(fileName, module);
|
||||
|
||||
// 计算文件MD5
|
||||
String md5Hash = calculateMD5(fileBytes);
|
||||
|
||||
// 上传到MinIO
|
||||
String bucketName = minioConfig.getBucketName();
|
||||
java.io.ByteArrayInputStream inputStream = new java.io.ByteArrayInputStream(fileBytes);
|
||||
boolean uploadSuccess = minioUtil.uploadFile(
|
||||
bucketName,
|
||||
objectName,
|
||||
inputStream,
|
||||
size,
|
||||
contentType
|
||||
);
|
||||
|
||||
if (!uploadSuccess) {
|
||||
return ResultDomain.failure("文件上传到MinIO失败");
|
||||
}
|
||||
|
||||
// 生成文件URL
|
||||
String fileUrl = minioConfig.getEndpoint() + "/" + bucketName + "/" + objectName;
|
||||
|
||||
// 创建文件DTO
|
||||
TbSysFileDTO fileDTO = new TbSysFileDTO();
|
||||
fileDTO.setOptsn(UUID.randomUUID().toString());
|
||||
fileDTO.setFileId(UUID.randomUUID().toString().replace("-", ""));
|
||||
fileDTO.setName(fileName);
|
||||
fileDTO.setPath(objectName);
|
||||
fileDTO.setUrl(fileUrl);
|
||||
fileDTO.setSize(size);
|
||||
fileDTO.setMimeType(contentType);
|
||||
fileDTO.setExtension(extension);
|
||||
fileDTO.setMd5Hash(md5Hash);
|
||||
fileDTO.setModule(module);
|
||||
fileDTO.setBusinessId(businessId);
|
||||
fileDTO.setVersion(1);
|
||||
fileDTO.setFileRootId(fileDTO.getFileId());
|
||||
fileDTO.setCreateTime(new java.util.Date());
|
||||
|
||||
// 保存到数据库
|
||||
int result = fileMapper.insertFile(fileDTO);
|
||||
if (result <= 0) {
|
||||
minioUtil.deleteFile(bucketName, objectName);
|
||||
return ResultDomain.failure("文件信息保存失败");
|
||||
}
|
||||
|
||||
logger.info("字节数组文件上传成功: {}", fileName);
|
||||
return ResultDomain.success("文件上传成功", fileDTO);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("字节数组文件上传失败", e);
|
||||
return ResultDomain.failure("文件上传失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成唯一的对象名称
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.xyzh.system.controller;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -26,7 +25,7 @@ public class DeptRoleController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DeptRoleController.class);
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private DeptRoleService deptRoleService;
|
||||
|
||||
// ================= 部门角色相关接口 =================
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.xyzh.system.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -32,7 +32,7 @@ import jakarta.validation.constraints.NotNull;
|
||||
@RequestMapping("/system/guest")
|
||||
public class GuestController {
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private GuestService guestService;
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.xyzh.system.controller;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -25,7 +24,7 @@ public class PermissionController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PermissionController.class);
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private ModulePermissionService modulePermissionService;
|
||||
|
||||
// ================= 模块相关接口 =================
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.xyzh.system.controller;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,7 +23,7 @@ public class SysConfigController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SysConfigController.class);
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
// ================= 系统配置相关接口 =================
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.xyzh.system.controller;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -26,7 +25,7 @@ public class UserController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(UserController.class);
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
// ================= 用户相关接口 =================
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.xyzh.system.controller;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -23,7 +22,7 @@ public class ViewController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ViewController.class);
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "system", timeout = 3000, retries = 0, scope = "local")
|
||||
@Autowired
|
||||
private ViewService viewService;
|
||||
|
||||
// ================= 视图相关接口 =================
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.xyzh.workcase.controller;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -42,7 +41,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@RequestMapping("/workcase/chat")
|
||||
public class WorkcaseChatContorller {
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "workcase", check = false, scope = "local")
|
||||
@Autowired
|
||||
private WorkcaseChatService workcaseChatService;
|
||||
|
||||
// ========================= AI对话管理 =========================
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.xyzh.workcase.controller;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -36,7 +36,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@RequestMapping("/workcase")
|
||||
public class WorkcaseController {
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "workcase", check = false, scope = "local")
|
||||
@Autowired
|
||||
private WorkcaseService workcaseService;
|
||||
|
||||
// ========================= 工单管理 =========================
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.xyzh.workcase.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -38,7 +37,7 @@ public class WorkcaseServiceImpl implements WorkcaseService {
|
||||
@Autowired
|
||||
private TbWorkcaseDeviceMapper workcaseDeviceMapper;
|
||||
|
||||
@DubboReference(version = "1.0.0", group = "workcase", check = false, scope = "local")
|
||||
@Autowired
|
||||
private WorkcaseChatService workcaseChatService;
|
||||
|
||||
// ====================== 工单管理 ======================
|
||||
|
||||
Reference in New Issue
Block a user