派生自 projectDept/qhighschool

胡仁荣
2022-10-31 fe7381d6e8ec1f427408de0297ac7f41533202f6
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
package com.qxueyou.scc.base.model;
 
/**
 * apiרÓ÷µ»Ø½á¹ûmodel
 * @author cyq
 *
 */
public class ApiResult {
    
    /**
     * ·µ»Ø½á¹ûµÄö¾Ù
     * @author cyq
     *
     */
    public enum ResultCode {
        Success(1),                        // ³É¹¦
        UserNotExist(40001),            // Óû§²»´æÔÚ
        PasswordInvalid(40002),            // ÃÜÂë²»ÕýÈ·
        TokenInvalid(50001),            // TokenÎÞЧ
        ParamInvalid(60001),            // ²ÎÊýÎÞЧ
        SystemException(60002),            // ÏµÍ³Òì³£
        DataNotExist(60003);            // Êý¾Ý²»´æÔÚ
        
        private Integer resultCode;
 
        ResultCode(int code) {
            this.resultCode = code;
        }
        
        public Integer getCode() {
            return resultCode;
        }
    }
    
    
    private boolean result;
    
    /**
     * 40001Óû§²»´æÔÚ
     * 40002ÃÜÂë´íÎó
     * 50001tokenÎÞЧ
     * 60001²ÎÊý´íÎó
     * 60001ϵͳÒì³£
     * 60003Êý¾Ý²»´æÔÚ
     */
    private int code = 1;
    
    private Object data;
    
    public ApiResult (boolean result) {
        this.result = result;
    }
    
    public ApiResult (boolean result, int code) {
        this.result = result;
        this.code = code;
    }
 
    public ApiResult (boolean result, ResultCode code) {
        this.result = result;
        this.code = code.getCode();
    }
    
    public ApiResult (boolean result, int code, Object data) {
        this.result = result;
        this.code = code;
        this.data = data;
    }
    
    public static ApiResult resultTrue() {
        return new ApiResult(true);
    }
    
    public static ApiResult resultTrue(Object data) {
        return new ApiResult(true, 1, data);
    }
    
    public static ApiResult resultFalse(int code) {
        return new ApiResult(false, code);
    }
 
    public boolean isResult() {
        return result;
    }
 
    public void setResult(boolean result) {
        this.result = result;
    }
 
    public int getCode() {
        return code;
    }
 
    public void setCode(int code) {
        this.code = code;
    }
 
    public Object getData() {
        return data;
    }
 
    public void setData(Object data) {
        this.data = data;
    }
 
}