diff --git a/prompto-lab-app/src/main/java/io/github/timemachinelab/demo/SSEDemoController.java b/prompto-lab-app/src/main/java/io/github/timemachinelab/controller/SSEDemoController.java similarity index 99% rename from prompto-lab-app/src/main/java/io/github/timemachinelab/demo/SSEDemoController.java rename to prompto-lab-app/src/main/java/io/github/timemachinelab/controller/SSEDemoController.java index df237fd..0fa6ad3 100644 --- a/prompto-lab-app/src/main/java/io/github/timemachinelab/demo/SSEDemoController.java +++ b/prompto-lab-app/src/main/java/io/github/timemachinelab/controller/SSEDemoController.java @@ -1,4 +1,4 @@ -package io.github.timemachinelab.demo; +package io.github.timemachinelab.controller; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; diff --git a/prompto-lab-app/src/main/java/io/github/timemachinelab/controller/UserInteractionController.java b/prompto-lab-app/src/main/java/io/github/timemachinelab/controller/UserInteractionController.java new file mode 100644 index 0000000..a3b2955 --- /dev/null +++ b/prompto-lab-app/src/main/java/io/github/timemachinelab/controller/UserInteractionController.java @@ -0,0 +1,56 @@ +package io.github.timemachinelab.controller; + +import io.github.timemachinelab.entity.req.RetryRequest; +import io.github.timemachinelab.entity.resp.ApiResult; +import io.github.timemachinelab.entity.resp.RetryResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +/** + * 用户交互控制器 + * 提供用户交互相关的API接口 + * + * @author suifeng + * @date 2025/1/20 + */ +@Slf4j +@RestController +@RequestMapping("/api/user-interaction") +@Validated +public class UserInteractionController { + + /** + * 重试接口 + * + * @param request 重试请求参数 + * @return 重试结果 + */ + @PostMapping("/retry") + public ResponseEntity> retry(@Valid @RequestBody RetryRequest request) { + try { + log.info("收到重试请求 - nodeId: {}, sessionId: {}, whyretry: {}", + request.getNodeId(), request.getSessionId(), request.getWhyretry()); + + // 构建响应数据 + RetryResponse response = RetryResponse.builder() + .nodeId(request.getNodeId()) + .sessionId(request.getSessionId()) + .whyretry(request.getWhyretry()) + .processTime(System.currentTimeMillis()) + .build(); + + log.info("重试请求处理成功 - nodeId: {}, sessionId: {}", + request.getNodeId(), request.getSessionId()); + + return ResponseEntity.ok(ApiResult.success("重试请求处理成功", response)); + + } catch (Exception e) { + log.error("重试请求处理失败: {}", e.getMessage(), e); + return ResponseEntity.badRequest().body(ApiResult.serverError("重试请求处理失败: " + e.getMessage())); + } + } +} \ No newline at end of file diff --git a/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/dto/.gitkeep b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/dto/.gitkeep new file mode 100644 index 0000000..aba87a9 --- /dev/null +++ b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/dto/.gitkeep @@ -0,0 +1,2 @@ +# DTO包 +此包用于存放数据传输对象(Data Transfer Object) \ No newline at end of file diff --git a/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/entity/.gitkeep b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/entity/.gitkeep new file mode 100644 index 0000000..b5d130e --- /dev/null +++ b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/entity/.gitkeep @@ -0,0 +1,2 @@ +# ENTITY包 +此包用于存放实体对象(Entity Object) \ No newline at end of file diff --git a/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/req/.gitkeep b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/req/.gitkeep new file mode 100644 index 0000000..afeb242 --- /dev/null +++ b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/req/.gitkeep @@ -0,0 +1,2 @@ +# REQ包 +此包用于存放请求对象(Request Object) \ No newline at end of file diff --git a/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/req/RetryRequest.java b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/req/RetryRequest.java new file mode 100644 index 0000000..bc802da --- /dev/null +++ b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/req/RetryRequest.java @@ -0,0 +1,41 @@ +package io.github.timemachinelab.entity.req; + +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.AllArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 重试请求参数 + * + * @author suifeng + * @date 2025/1/20 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class RetryRequest { + + /** + * 节点ID + */ + @NotNull(message = "nodeId不能为null") + @NotBlank(message = "nodeId不能为空") + private String nodeId; + + /** + * 会话ID + */ + @NotNull(message = "sessionId不能为null") + @NotBlank(message = "sessionId不能为空") + private String sessionId; + + /** + * 重试原因 + */ + @NotNull(message = "whyretry不能为null") + @NotBlank(message = "whyretry不能为空") + private String whyretry; +} \ No newline at end of file diff --git a/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/resp/.gitkeep b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/resp/.gitkeep new file mode 100644 index 0000000..9630020 --- /dev/null +++ b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/resp/.gitkeep @@ -0,0 +1,2 @@ +# RESP包 +此包用于存放响应对象(Response Object) \ No newline at end of file diff --git a/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/resp/ApiResult.java b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/resp/ApiResult.java new file mode 100644 index 0000000..d5aeae5 --- /dev/null +++ b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/resp/ApiResult.java @@ -0,0 +1,92 @@ +package io.github.timemachinelab.entity.resp; + +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.AllArgsConstructor; + +/** + * 统一API响应结果类 + * + * @param 数据类型 + * @author suifeng + * @date 2025/1/20 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ApiResult { + + /** + * 响应状态码 + */ + private Integer code; + + /** + * 响应消息 + */ + private String message; + + /** + * 响应数据 + */ + private T data; + + /** + * 时间戳 + */ + private Long timestamp; + + /** + * 是否成功 + */ + private Boolean success; + + /** + * 成功响应 + */ + public static ApiResult success(T data) { + return new ApiResult<>(200, "操作成功", data, System.currentTimeMillis(), true); + } + + /** + * 成功响应(自定义消息) + */ + public static ApiResult success(String message, T data) { + return new ApiResult<>(200, message, data, System.currentTimeMillis(), true); + } + + /** + * 成功响应(无数据) + */ + public static ApiResult success(String message) { + return new ApiResult<>(200, message, null, System.currentTimeMillis(), true); + } + + /** + * 失败响应 + */ + public static ApiResult error(String message) { + return new ApiResult<>(400, message, null, System.currentTimeMillis(), false); + } + + /** + * 失败响应(自定义状态码) + */ + public static ApiResult error(Integer code, String message) { + return new ApiResult<>(code, message, null, System.currentTimeMillis(), false); + } + + /** + * 参数校验失败 + */ + public static ApiResult validateError(String message) { + return new ApiResult<>(400, message, null, System.currentTimeMillis(), false); + } + + /** + * 服务器内部错误 + */ + public static ApiResult serverError(String message) { + return new ApiResult<>(500, message, null, System.currentTimeMillis(), false); + } +} \ No newline at end of file diff --git a/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/resp/RetryResponse.java b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/resp/RetryResponse.java new file mode 100644 index 0000000..a2b5fbd --- /dev/null +++ b/prompto-lab-app/src/main/java/io/github/timemachinelab/entity/resp/RetryResponse.java @@ -0,0 +1,39 @@ +package io.github.timemachinelab.entity.resp; + +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.AllArgsConstructor; +import lombok.Builder; + +/** + * 重试响应结果 + * + * @author suifeng + * @date 2025/1/20 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class RetryResponse { + + /** + * 节点ID + */ + private String nodeId; + + /** + * 会话ID + */ + private String sessionId; + + /** + * 重试原因 + */ + private String whyretry; + + /** + * 处理时间戳 + */ + private Long processTime; +} \ No newline at end of file