aix
2024-08-05 52d6a8ddb4a1f631edffa7c339a3ba848c0e7a1e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.dji.sample.common.model;
 
import com.dji.sample.common.error.IErrorInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;
 
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonInclude
public class ResponseResult<T> {
 
    public static final int CODE_SUCCESS = 0;
    public static final String MESSAGE_SUCCESS = "success";
 
    private int code;
 
    private String message;
 
    private T data;
 
    public static <T> ResponseResult<T> success(T data) {
        return ResponseResult.<T>builder()
                .code(CODE_SUCCESS)
                .message(MESSAGE_SUCCESS)
                .data(data)
                .build();
    }
 
    public static ResponseResult success() {
        return ResponseResult.builder()
                .code(0)
                .message(MESSAGE_SUCCESS)
                .build();
    }
    public static ResponseResult success(int code) {
        return ResponseResult.builder()
                .code(code)
                .message(MESSAGE_SUCCESS)
                .build();
    }
 
    public static ResponseResult error() {
        return ResponseResult.builder()
                .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .message(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
                .build();
    }
 
    public static ResponseResult error(String message) {
        return ResponseResult.builder()
                .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .message(message)
                .build();
    }
 
    public static ResponseResult error(int code, String message) {
        return ResponseResult.builder()
                .code(code)
                .message(message)
                .build();
    }
 
    public static ResponseResult error(IErrorInfo errorInfo) {
        return ResponseResult.builder()
                .code(errorInfo.getErrorCode())
                .message(errorInfo.getErrorMsg())
                .build();
    }
}