2024-12-23 10:18:23 +08:00
|
|
|
package com.dpkj.common.vo;
|
|
|
|
|
|
|
|
import com.dpkj.common.constant.CommonConst;
|
2025-01-15 17:17:27 +08:00
|
|
|
import com.dpkj.common.exception.ErrorEnum;
|
2024-12-23 10:18:23 +08:00
|
|
|
import lombok.Data;
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 接口返回数据格式
|
|
|
|
*/
|
|
|
|
@Data
|
|
|
|
public class Result<T> implements Serializable {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 成功标志
|
|
|
|
*/
|
|
|
|
private boolean success = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 返回处理消息
|
|
|
|
*/
|
|
|
|
private String message = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 返回代码
|
|
|
|
*/
|
|
|
|
private Integer code = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 返回数据对象 data
|
|
|
|
*/
|
|
|
|
private T result;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 时间戳
|
|
|
|
*/
|
|
|
|
private long timestamp = System.currentTimeMillis();
|
|
|
|
|
|
|
|
public Result() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> Result<T> ok() {
|
|
|
|
return ok("", null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> Result<T> ok(String msg) {
|
|
|
|
return ok(msg, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> Result<T> ok(T data) {
|
2025-02-08 15:53:34 +08:00
|
|
|
return ok("", data);
|
2024-12-23 10:18:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> Result<T> ok(String msg, T data) {
|
|
|
|
Result<T> r = new Result<T>();
|
|
|
|
r.setSuccess(true);
|
|
|
|
r.setCode(CommonConst.SC_200);
|
|
|
|
r.setMessage(msg);
|
|
|
|
r.setResult(data);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> Result<T> error(String msg, T data) {
|
|
|
|
return error(CommonConst.SC_500, msg, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> Result<T> error(String msg) {
|
|
|
|
return error(CommonConst.SC_500, msg, null);
|
|
|
|
}
|
|
|
|
|
2025-01-15 17:17:27 +08:00
|
|
|
public static <T> Result<T> error(ErrorEnum errorEnum) {
|
|
|
|
return error(errorEnum.getCode(), errorEnum.getMessage(), null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> Result<T> error(int code, String message) {
|
|
|
|
return error(code, message, null);
|
|
|
|
}
|
|
|
|
|
2024-12-23 10:18:23 +08:00
|
|
|
public static <T> Result<T> error(int code, String msg, T data) {
|
|
|
|
Result<T> r = new Result<T>();
|
|
|
|
r.setCode(code);
|
|
|
|
r.setMessage(msg);
|
|
|
|
r.setSuccess(false);
|
|
|
|
r.setResult(data);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|