feat(phase1): 完成分层结构优化和 DTO 创建
Task 4.2: 分层结构优化 - 创建 exception 包 - SessionNotFoundException: 会话未找到异常 - DocumentProcessException: 文档处理异常 - 已有分层结构验证 - controller: 控制器层 ✅ - service: 业务逻辑层 ✅ - repository: 数据访问层 ✅ - domain: 领域模型层 (entity/model/enums) ✅ - config: 配置层 ✅ - tool: 工具类 ✅ Task 4.3: 创建 DTO 类 - DiagnosisRequest: 诊断请求 DTO (10 个字段) - DiagnosisResponse: 诊断响应 DTO (12 个字段 + 内部类) - DocumentUploadRequest: 文档上传请求 DTO (7 个字段) - DocumentQueryResponse: 文档查询响应 DTO (11 个字段 + 内部类) - Result<T>: 统一响应结果 DTO (泛型包装) 功能特性: - 异常类支持自定义错误信息和原因链 - DTO 使用 Lombok 简化代码 - Result 提供静态工厂方法(success/error) - DocumentUploadRequest 支持 MultipartFile - Response DTO 支持嵌套数据结构 编译验证:BUILD SUCCESS Progress: 23/33 tasks completed (70%)
This commit is contained in:
@@ -32,8 +32,8 @@
|
|||||||
## 4. 代码结构重构
|
## 4. 代码结构重构
|
||||||
|
|
||||||
- [x] 4.1 包名重构 (org.example → com.superbiz.agent)
|
- [x] 4.1 包名重构 (org.example → com.superbiz.agent)
|
||||||
- [ ] 4.2 分层结构优化 (controller/service/repository/domain/tool/config/exception)
|
- [x] 4.2 分层结构优化 (controller/service/repository/domain/tool/config/exception)
|
||||||
- [ ] 4.3 创建 DTO 类 (DiagnosisRequest, DiagnosisResponse, DocumentUploadRequest, DocumentQueryResponse, Result)
|
- [x] 4.3 创建 DTO 类 (DiagnosisRequest, DiagnosisResponse, DocumentUploadRequest, DocumentQueryResponse, Result)
|
||||||
|
|
||||||
## 5. 文档管理服务
|
## 5. 文档管理服务
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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<Map<String, Object>> toolCalls;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相似案例推荐
|
||||||
|
*/
|
||||||
|
private List<RecommendedCase> recommendedCases;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class RecommendedCase {
|
||||||
|
private String caseId;
|
||||||
|
private String title;
|
||||||
|
private String rootCause;
|
||||||
|
private String solution;
|
||||||
|
private Double similarity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<SearchResult> searchResults;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class SearchResult {
|
||||||
|
private String content;
|
||||||
|
private Double score;
|
||||||
|
private Integer chunkIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.superbiz.agent.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一响应结果 DTO
|
||||||
|
*
|
||||||
|
* @param <T> 数据类型
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Result<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应码(200 成功,其他失败)
|
||||||
|
*/
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应消息
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应数据
|
||||||
|
*/
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间戳
|
||||||
|
*/
|
||||||
|
private Long timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功响应
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> success(T data) {
|
||||||
|
return Result.<T>builder()
|
||||||
|
.code(200)
|
||||||
|
.message("success")
|
||||||
|
.data(data)
|
||||||
|
.timestamp(System.currentTimeMillis())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功响应(无数据)
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> success() {
|
||||||
|
return success(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败响应
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> error(Integer code, String message) {
|
||||||
|
return Result.<T>builder()
|
||||||
|
.code(code)
|
||||||
|
.message(message)
|
||||||
|
.data(null)
|
||||||
|
.timestamp(System.currentTimeMillis())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败响应(默认 500)
|
||||||
|
*/
|
||||||
|
public static <T> Result<T> error(String message) {
|
||||||
|
return error(500, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user