com.jdkhome.blzo.ex.basic.pojo.ApiResponse Maven / Gradle / Ivy
The newest version!
package com.jdkhome.blzo.ex.basic.pojo;
import com.jdkhome.blzo.ex.basic.enums.BasicResponseError;
import com.jdkhome.blzo.ex.basic.enums.I18nEnums;
import com.jdkhome.blzo.ex.basic.exception.ServiceException;
import lombok.Data;
/**
* author link.ji
* createTime 上午11:18 2018/6/20
* 基础返回
*/
@Data
public class ApiResponse {
private Integer code;
private String msg;
private Object debug;
private T data;
/**
* 禁用直接创建
*/
private ApiResponse() {
}
/**
* 由BaseError 创建ApiResponse
*
* @param baseError
*/
public ApiResponse(BaseError baseError) {
this.code = baseError.getCode();
this.msg = baseError.getMsg();
}
public ApiResponse(BaseError baseError, I18nEnums i18n) {
this.code = baseError.getCode();
this.msg = baseError.getMsg(i18n);
}
/**
* 由BaseError 创建带有额外信息的ApiResponse
*
* @param baseError
*/
public ApiResponse(BaseError baseError, T data) {
this.code = baseError.getCode();
this.msg = baseError.getMsg();
this.data = data;
}
public ApiResponse(BaseError baseError, T data, I18nEnums i18n) {
this.code = baseError.getCode();
this.msg = baseError.getMsg(i18n);
this.data = data;
}
public ApiResponse(BaseError baseError, T data, Object debug, I18nEnums i18n) {
this.code = baseError.getCode();
this.msg = baseError.getMsg(i18n);
this.data = data;
this.debug = debug;
}
/**
* ServiceException 创建ApiResponse
*
* @param se
*/
public ApiResponse(ServiceException se) {
this.code = se.getErrorCode();
this.msg = se.getErrorMsg();
this.debug = se.getDebug();
}
public ApiResponse(ServiceException se, I18nEnums i18n) {
this.code = se.getErrorCode();
this.msg = se.getBaseError().getMsg(i18n);
if (!se.getErrorCode().equals(se.getBaseError().getCode())) {
this.msg = se.getErrorMsg();
}
this.debug = se.getDebug();
}
/**
* 返回成功
*
* @param data
* @return
*/
static public ApiResponse