package com.ld.igds.phone.util;
|
|
|
import com.ld.igds.constant.RespCodeEnum;
|
import com.ld.igds.phone.dto.PhoneResponse;
|
import com.ld.igds.phone.param.PhoneRequest;
|
|
/**
|
* @author chen
|
*
|
**/
|
@SuppressWarnings({"unchecked","rawtypes"})
|
public class PhoneRespUtil {
|
|
/**
|
* 响应成功,根据req自动回填需要的参数
|
*
|
* @param data
|
* @param req
|
* @return
|
*/
|
public static PhoneResponse success(Object data, PhoneRequest req) {
|
return new PhoneResponse(RespCodeEnum.CODE_0000.getCode(),RespCodeEnum.CODE_0000.getMsg(), req.getOutId(), data);
|
}
|
|
public static PhoneResponse success(Object data) {
|
return new PhoneResponse(RespCodeEnum.CODE_0000.getCode(),RespCodeEnum.CODE_0000.getMsg(), data);
|
}
|
|
/**
|
* 响应异常的封装,自定义异常编码和原因
|
*
|
* @param code
|
* @param msg
|
* @param req
|
* @return
|
*/
|
public static PhoneResponse error(RespCodeEnum code, PhoneRequest req, String msg) {
|
return error(code,req.getOutId(),msg);
|
}
|
|
public static PhoneResponse error(RespCodeEnum code, String msg) {
|
return new PhoneResponse(code,null, msg);
|
}
|
|
/**
|
*
|
* @param code
|
* @param outId
|
* @param msg
|
* @return
|
*/
|
public static PhoneResponse error(RespCodeEnum code, String outId, String msg) {
|
if (null == msg) {
|
return new PhoneResponse(code,outId, code.getMsg() );
|
}
|
return new PhoneResponse(code, outId, msg);
|
}
|
|
/**
|
* 响应异常的封装,通过编码获取异常原因
|
*
|
* @param code
|
* @param req
|
* @return
|
*/
|
public static PhoneResponse error(RespCodeEnum code, PhoneRequest req) {
|
return new PhoneResponse(code.getCode(),code.getMsg(), req.getOutId(),null);
|
}
|
|
|
}
|