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);
|
}
|
|
}
|