diff --git a/openspec/changes/phase-1-infrastructure/tasks.md b/openspec/changes/phase-1-infrastructure/tasks.md index 42840b1..236bd68 100644 --- a/openspec/changes/phase-1-infrastructure/tasks.md +++ b/openspec/changes/phase-1-infrastructure/tasks.md @@ -32,8 +32,8 @@ ## 4. 代码结构重构 - [x] 4.1 包名重构 (org.example → com.superbiz.agent) -- [ ] 4.2 分层结构优化 (controller/service/repository/domain/tool/config/exception) -- [ ] 4.3 创建 DTO 类 (DiagnosisRequest, DiagnosisResponse, DocumentUploadRequest, DocumentQueryResponse, Result) +- [x] 4.2 分层结构优化 (controller/service/repository/domain/tool/config/exception) +- [x] 4.3 创建 DTO 类 (DiagnosisRequest, DiagnosisResponse, DocumentUploadRequest, DocumentQueryResponse, Result) ## 5. 文档管理服务 diff --git a/src/main/java/com/superbiz/agent/dto/DiagnosisRequest.java b/src/main/java/com/superbiz/agent/dto/DiagnosisRequest.java new file mode 100644 index 0000000..f20f4ad --- /dev/null +++ b/src/main/java/com/superbiz/agent/dto/DiagnosisRequest.java @@ -0,0 +1,61 @@ +package com.superbiz.agent.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 诊断请求 DTO + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DiagnosisRequest { + + /** + * 业务ID(订单号/请求ID等) + */ + private String businessId; + + /** + * 链路追踪ID + */ + private String traceId; + + /** + * 故障类别 + */ + private String faultCategory; + + /** + * 故障源(省份/服务名/类名等) + */ + private String faultSource; + + /** + * 故障目标(接口URL/方法名/SQL等) + */ + private String faultTarget; + + /** + * 错误码 + */ + private String errorCode; + + /** + * 错误消息 + */ + private String errorMessage; + + /** + * 堆栈信息 + */ + private String stackTrace; + + /** + * 用户描述 + */ + private String userDescription; +} diff --git a/src/main/java/com/superbiz/agent/dto/DiagnosisResponse.java b/src/main/java/com/superbiz/agent/dto/DiagnosisResponse.java new file mode 100644 index 0000000..e1ae016 --- /dev/null +++ b/src/main/java/com/superbiz/agent/dto/DiagnosisResponse.java @@ -0,0 +1,92 @@ +package com.superbiz.agent.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; + +/** + * 诊断响应 DTO + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DiagnosisResponse { + + /** + * 诊断ID + */ + private String diagnosisId; + + /** + * 会话ID + */ + private String sessionId; + + /** + * 诊断状态(PENDING/RUNNING/SUCCESS/FAILED) + */ + private String status; + + /** + * 问题类型 + */ + private String problemType; + + /** + * 根因分析 + */ + private String rootCause; + + /** + * 修复方案 + */ + private String solution; + + /** + * 完整诊断报告(Markdown格式) + */ + private String reportMarkdown; + + /** + * 诊断置信度(0-100) + */ + private Integer confidence; + + /** + * 诊断耗时(毫秒) + */ + private Integer duration; + + /** + * 工具调用记录 + */ + private List> toolCalls; + + /** + * 创建时间 + */ + private LocalDateTime createdAt; + + /** + * 相似案例推荐 + */ + private List recommendedCases; + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class RecommendedCase { + private String caseId; + private String title; + private String rootCause; + private String solution; + private Double similarity; + } +} diff --git a/src/main/java/com/superbiz/agent/dto/DocumentQueryResponse.java b/src/main/java/com/superbiz/agent/dto/DocumentQueryResponse.java new file mode 100644 index 0000000..b29b1a9 --- /dev/null +++ b/src/main/java/com/superbiz/agent/dto/DocumentQueryResponse.java @@ -0,0 +1,89 @@ +package com.superbiz.agent.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 文档查询响应 DTO + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DocumentQueryResponse { + + /** + * 文档ID + */ + private String docId; + + /** + * 文件名 + */ + private String fileName; + + /** + * 故障类别 + */ + private String faultCategory; + + /** + * 故障源 + */ + private String faultSource; + + /** + * 接口名称 + */ + private String apiName; + + /** + * 版本 + */ + private String version; + + /** + * 文件大小(字节) + */ + private Long fileSize; + + /** + * 索引状态 + */ + private String status; + + /** + * 分块数量 + */ + private Integer chunkCount; + + /** + * 索引完成时间 + */ + private LocalDateTime indexedAt; + + /** + * 创建时间 + */ + private LocalDateTime createdAt; + + /** + * 检索到的相关内容(语义检索结果) + */ + private List searchResults; + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class SearchResult { + private String content; + private Double score; + private Integer chunkIndex; + } +} diff --git a/src/main/java/com/superbiz/agent/dto/DocumentUploadRequest.java b/src/main/java/com/superbiz/agent/dto/DocumentUploadRequest.java new file mode 100644 index 0000000..535077c --- /dev/null +++ b/src/main/java/com/superbiz/agent/dto/DocumentUploadRequest.java @@ -0,0 +1,52 @@ +package com.superbiz.agent.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.web.multipart.MultipartFile; + +/** + * 文档上传请求 DTO + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DocumentUploadRequest { + + /** + * 上传的文件 + */ + private MultipartFile file; + + /** + * 故障类别(默认 EXTERNAL_API) + */ + private String faultCategory; + + /** + * 故障源(省份/服务名) + */ + private String faultSource; + + /** + * 接口名称 + */ + private String apiName; + + /** + * 文档版本 + */ + private String version; + + /** + * 分块大小(默认 500) + */ + private Integer chunkSize; + + /** + * 重叠大小(默认 50) + */ + private Integer chunkOverlap; +} diff --git a/src/main/java/com/superbiz/agent/dto/Result.java b/src/main/java/com/superbiz/agent/dto/Result.java new file mode 100644 index 0000000..2fc3a3d --- /dev/null +++ b/src/main/java/com/superbiz/agent/dto/Result.java @@ -0,0 +1,76 @@ +package com.superbiz.agent.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 统一响应结果 DTO + * + * @param 数据类型 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Result { + + /** + * 响应码(200 成功,其他失败) + */ + private Integer code; + + /** + * 响应消息 + */ + private String message; + + /** + * 响应数据 + */ + private T data; + + /** + * 时间戳 + */ + private Long timestamp; + + /** + * 成功响应 + */ + public static Result success(T data) { + return Result.builder() + .code(200) + .message("success") + .data(data) + .timestamp(System.currentTimeMillis()) + .build(); + } + + /** + * 成功响应(无数据) + */ + public static Result success() { + return success(null); + } + + /** + * 失败响应 + */ + public static Result error(Integer code, String message) { + return Result.builder() + .code(code) + .message(message) + .data(null) + .timestamp(System.currentTimeMillis()) + .build(); + } + + /** + * 失败响应(默认 500) + */ + public static Result error(String message) { + return error(500, message); + } +} diff --git a/src/main/java/com/superbiz/agent/exception/DocumentProcessException.java b/src/main/java/com/superbiz/agent/exception/DocumentProcessException.java new file mode 100644 index 0000000..b1ad4f3 --- /dev/null +++ b/src/main/java/com/superbiz/agent/exception/DocumentProcessException.java @@ -0,0 +1,30 @@ +package com.superbiz.agent.exception; + +/** + * 文档处理异常 + */ +public class DocumentProcessException extends RuntimeException { + + private final String docId; + private final String operation; + + public DocumentProcessException(String docId, String operation, String message) { + super(String.format("Document process failed [docId=%s, operation=%s]: %s", docId, operation, message)); + this.docId = docId; + this.operation = operation; + } + + public DocumentProcessException(String docId, String operation, String message, Throwable cause) { + super(String.format("Document process failed [docId=%s, operation=%s]: %s", docId, operation, message), cause); + this.docId = docId; + this.operation = operation; + } + + public String getDocId() { + return docId; + } + + public String getOperation() { + return operation; + } +} diff --git a/src/main/java/com/superbiz/agent/exception/SessionNotFoundException.java b/src/main/java/com/superbiz/agent/exception/SessionNotFoundException.java new file mode 100644 index 0000000..b15b24e --- /dev/null +++ b/src/main/java/com/superbiz/agent/exception/SessionNotFoundException.java @@ -0,0 +1,23 @@ +package com.superbiz.agent.exception; + +/** + * 会话未找到异常 + */ +public class SessionNotFoundException extends RuntimeException { + + private final String sessionId; + + public SessionNotFoundException(String sessionId) { + super("Session not found: " + sessionId); + this.sessionId = sessionId; + } + + public SessionNotFoundException(String sessionId, String message) { + super(message); + this.sessionId = sessionId; + } + + public String getSessionId() { + return sessionId; + } +}