吉安感知网项目-后端
xiebin
2026-01-06 d207a86cdf1ab52ef8cb7cd83bad8fceab8038cf
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package org.sxkj.common.model;
 
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;
 
    private String traceid;
 
    public static <T> ResponseResult<T> success(T data) {
        return ResponseResult.<T>builder()
            .code(CODE_SUCCESS)
            .message(MESSAGE_SUCCESS)
            .data(data)
            .build();
    }
 
    /**
     * 废弃
     * @param data 数据
     * @return
     * @param <T>
     */
    @Deprecated
    public static <T> ResponseResult<T> data(T data) {
        return ResponseResult.<T>builder()
            .code(200)
            .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<T> ResponseResult success(int code, String message,T data,String traceid) {
        return ResponseResult.builder()
            .code(code)
            .data(data)
            .message(message)
            .traceid(traceid)
            .build();
    }
    public static<T> ResponseResult success(int code, String message,T data) {
        return ResponseResult.builder()
            .code(code)
            .data(data)
            .message(message)
            .build();
    }
    public static ResponseResult success(int code, String message,String traceid) {
        return ResponseResult.builder()
            .code(code)
            .message(message)
            .traceid(traceid)
            .build();
    }
 
    public static ResponseResult warn(String msg) {
        return ResponseResult.builder()
            .code(-2)
            .message(msg)
            .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();
    }
}