init: rebuild myplayer-backend

This commit is contained in:
merlin
2025-11-13 11:10:07 +08:00
commit 575041905b
16 changed files with 1062 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package xin.merlin.myplayerbackend.utils.result;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Response<T> {
private int code;
private String message;
private T data;
// 请求成功
public static <T> Response<T> success(ResultCode code , T data){
System.out.println( LocalDateTime.now()+" success : \n"+code);
return new Response<T>(code.getCode(), code.getMessage(), data);
}
public static <T> Response<T> success(ResultCode code){
System.out.println( LocalDateTime.now()+" success : \n"+code);
return new Response<T>(code.getCode(), code.getMessage(),null);
}
// 请求失败
public static <T> Response<T> fail(ResultCode code){
System.out.println( LocalDateTime.now()+" fail : \n"+code);
return new Response<T>(code.getCode(),code.getMessage(), null);
}
}

View File

@@ -0,0 +1,37 @@
package xin.merlin.myplayerbackend.utils.result;
import lombok.Getter;
/**
* 通用状态码枚举类
*/
@Getter
public enum ResultCode {
SUCCESS(200, "成功"),
BAD_REQUEST(400, "请求参数错误"),
UNAUTHORIZED(401, "未认证或登录已过期"),
FORBIDDEN(403, "无权限访问"),
NOT_FOUND(404, "资源不存在"),
SERVER_ERROR(500, "服务器内部错误"),
// 自定义业务错误码
USER_BANNED(1000,"用户被封禁"),
USER_NOT_FOUND(1001, "用户不存在"),
USER_EXIST(1003,"用户已存在"),
USER_PASSWORD_ERROR(1004,"用户密码错误"),
USER_VERIFICATION_ERROR(1005,"验证码不存在或错误"),
USER_SEND_TOO_FAST(1006,"用户请求过快"),
USER_SEND_TOO_OFTEN(1007,"请求次数过多,已被限制"),
ORDER_NOT_FOUND(2000, "订单不存在");
private final int code;
private final String message;
ResultCode(int code, String message) {
this.code = code;
this.message = message;
}
}