xuekang
2024-05-11 bac0878349a1db23e7b420ea164e22fb9db73a99
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
package com.nuvole.common.domain.result;
 
import cn.hutool.core.util.ObjectUtil;
import com.nuvole.common.domain.emnu.CommonResultEmnu;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
 
@Data
public class CommonResult<T> {
 
    public static final String STATUS_OK = "1";//成功
    public static final String STATUS_ERR = "0";//失败
 
    public static final Integer CODE_OK = 10000;//请求成功返回码
 
    @ApiModelProperty("状态值 0:失败 1:成功 ")
    private String status = STATUS_OK;
 
    @ApiModelProperty("接口返回信息")
    private String info = CommonResultEmnu.OK.getInfo();
 
    @ApiModelProperty("接口返回信息 code ")
    private Integer code = CommonResultEmnu.OK.getCode();
 
    @ApiModelProperty("接口返回信息描述 ")
    private String description = "";
 
    @ApiModelProperty("接口返回值 ")
    private T data;
 
    public CommonResult() {
 
    }
 
    public CommonResult(T data) {
        this.data = ObjectUtil.cloneIfPossible(data);
    }
 
    public CommonResult(CommonResultEmnu resultEmnu) {
        if (!resultEmnu.getCode().equals(CODE_OK)) {
            this.status = STATUS_ERR;
        }
        this.code = resultEmnu.getCode();
        this.info = resultEmnu.getInfo();
    }
 
    public CommonResult(CommonResultEmnu resultEmnu, String description) {
        if (!resultEmnu.getCode().equals(CODE_OK)) {
            this.status = STATUS_ERR;
        }
        this.code = resultEmnu.getCode();
        this.info = resultEmnu.getInfo();
        this.description = description;
    }
 
}