duhuizhe
2024-04-17 c389984b5d3e5523e1b22de1fc045dc415261330
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
package com.yqzx.common.domain.result;
 
import cn.hutool.core.util.ObjectUtil;
import com.yqzx.common.domain.emnu.CommonResultEmnu;
 
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
 
/**
 * @Description: 公共返回对象
 * @Author: liujun
 * @Date: 2019-08-02 20:00
 **/
@Data
public class CommonResult<T> {
 
    /**
     * 请求成功返回码
     */
    public static final Integer CODE_OK = 10000;
    public static final String STATUS_OK = "1"; // 请求成功状态
    public static final String STATUS_ERR = "0";// 请求失败状态
 
    @ApiModelProperty("接口返回信息")
    private String info = CommonResultEmnu.OK.getInfo();
 
    @ApiModelProperty("接口返回信息 code ")
    private Integer code = CommonResultEmnu.OK.getCode();
 
    @ApiModelProperty("接口返回状态 1:成功 0:失败 ")
    private String status = STATUS_OK;
 
    @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;
    }
 
    public CommonResult(CommonResultEmnu resultEmnu, String description,T data) {
        if (!resultEmnu.getCode().equals(CODE_OK)) {
            this.status = STATUS_ERR;
        }
        this.code = resultEmnu.getCode();
        this.info = resultEmnu.getInfo();
        this.description = description;
        this.data = ObjectUtil.cloneIfPossible(data);
    }
 
}