王飞
2025-01-23 8b878300a3b44426d20b72ad4aea0291571a76ce
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
/*
 *
 *      Copyright (c) 2018-2025, 信智慧通 All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the pig4cloud.com developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: 信智慧通科技
 *
 */
 
package com.hxzkmonitor.util;
 
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
 
import java.io.Serializable;
 
/**
 * 响应信息主体
 *
 * @param <T>
 * @author 信智慧通
 */
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ApiModel(value = "响应信息主体")
public class R<T> implements Serializable {
    private static final long serialVersionUID = 1L;
 
    @Getter
    @Setter
    @ApiModelProperty(value = "返回标记:成功标记=0,失败标记=1")
    private int code;
 
    @Getter
    @Setter
    @ApiModelProperty(value = "返回信息")
    private String msg;
 
 
    @Getter
    @Setter
    @ApiModelProperty(value = "数据")
    private T data;
 
    public static <T> R<T> ok() {
        return restResult(null, CommonConstants.SUCCESS, null);
    }
 
    public static <T> R<T> ok(T data) {
        return restResult(data, CommonConstants.SUCCESS, null);
    }
 
    public static <T> R<T> ok(T data, int code, String msg) {
        return restResult(data, code, msg);
    }
 
    public static <T> R<T> ok(T data, String msg) {
        return restResult(data, CommonConstants.SUCCESS, msg);
    }
 
    public static <T> R<T> failed() {
        return restResult(null, CommonConstants.FAIL, null);
    }
 
    public static <T> R<T> failed(String msg) {
        return restResult(null, CommonConstants.FAIL, msg);
    }
 
    public static <T> R<T> failed(T data) {
        return restResult(data, CommonConstants.FAIL, null);
    }
 
    public static <T> R<T> failed(T data, String msg) {
        return restResult(data, CommonConstants.FAIL, msg);
    }
 
    private static <T> R<T> restResult(T data, int code, String msg) {
        R<T> apiResult = new R<>();
        apiResult.setCode(code);
        apiResult.setData(data);
        apiResult.setMsg(msg);
        return apiResult;
    }
}