Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.timemachinelab.demo;
package io.github.timemachinelab.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ApiResult<RetryResponse>> 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()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DTO包
此包用于存放数据传输对象(Data Transfer Object)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ENTITY包
此包用于存放实体对象(Entity Object)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# REQ包
此包用于存放请求对象(Request Object)
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# RESP包
此包用于存放响应对象(Response Object)
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package io.github.timemachinelab.entity.resp;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

/**
* 统一API响应结果类
*
* @param <T> 数据类型
* @author suifeng
* @date 2025/1/20
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApiResult<T> {

/**
* 响应状态码
*/
private Integer code;

/**
* 响应消息
*/
private String message;

/**
* 响应数据
*/
private T data;

/**
* 时间戳
*/
private Long timestamp;

/**
* 是否成功
*/
private Boolean success;

/**
* 成功响应
*/
public static <T> ApiResult<T> success(T data) {
return new ApiResult<>(200, "操作成功", data, System.currentTimeMillis(), true);
}

/**
* 成功响应(自定义消息)
*/
public static <T> ApiResult<T> success(String message, T data) {
return new ApiResult<>(200, message, data, System.currentTimeMillis(), true);
}

/**
* 成功响应(无数据)
*/
public static <T> ApiResult<T> success(String message) {
return new ApiResult<>(200, message, null, System.currentTimeMillis(), true);
}

/**
* 失败响应
*/
public static <T> ApiResult<T> error(String message) {
return new ApiResult<>(400, message, null, System.currentTimeMillis(), false);
}

/**
* 失败响应(自定义状态码)
*/
public static <T> ApiResult<T> error(Integer code, String message) {
return new ApiResult<>(code, message, null, System.currentTimeMillis(), false);
}

/**
* 参数校验失败
*/
public static <T> ApiResult<T> validateError(String message) {
return new ApiResult<>(400, message, null, System.currentTimeMillis(), false);
}

/**
* 服务器内部错误
*/
public static <T> ApiResult<T> serverError(String message) {
return new ApiResult<>(500, message, null, System.currentTimeMillis(), false);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Loading