import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@Accessors(chain = true)
public class ResultVO implements Serializable {
private static final long _serialVersionUID _= 3363592360269297637L;
private Integer code;
private Object data;
private String msg;
private String tradeNo;
_/**_<br />_ * 成功返回带参数_<br />_ *_<br />_ * _**_@param _**_data_<br />_ * _**_@return_**<br />**_ _**_*/_<br />_ _public static ResultVO success(Object data) {<br /> ResultVO resultVO = new ResultVO()<br /> .setCode(CodeEnum._SUCCESS_.getCode())<br /> .setMsg(CodeEnum._SUCCESS_.getMsg())<br /> .setData(data)<br /> .setTradeNo(UUIDUtils._getUUID_());<br /> return resultVO;<br /> }
_/**_<br />_ * 成功无参返回_<br />_ *_<br />_ * _**_@return_**<br />**_ _**_*/_<br />_ _public static ResultVO success() {<br /> ResultVO resultVO = new ResultVO()<br /> .setCode(CodeEnum._SUCCESS_.getCode())<br /> .setMsg(CodeEnum._SUCCESS_.getMsg())<br /> .setTradeNo(UUIDUtils._getUUID_());<br /> return resultVO;<br /> }
_/**_<br />_ * 异常返回_<br />_ *_<br />_ * _**_@param _**_codeEnum_<br />_ * _**_@return_**<br />**_ _**_*/_<br />_ _public static ResultVO error(CodeEnum codeEnum) {<br /> ResultVO resultVO = new ResultVO()<br /> .setCode(codeEnum.getCode())<br /> .setMsg(codeEnum.getMsg())<br /> .setTradeNo(UUIDUtils._getUUID_());<br /> return resultVO;<br /> }
_/**_<br />_ * 异常返回_<br />_ *_<br />_ * _**_@param _**_codeEnum_<br />_ * _**_@return_**<br />**_ _**_*/_<br />_ _public static ResultVO error(String tradeNo, CodeEnum codeEnum) {<br /> ResultVO resultVO = new ResultVO()<br /> .setCode(codeEnum.getCode())<br /> .setMsg(codeEnum.getMsg())<br /> .setTradeNo(tradeNo);<br /> return resultVO;<br /> }
_/**_<br />_ * _**_@param _**_message_<br />_ * _**_@param _**_code_<br />_ * _**_@return_**<br />**_ _**_*/_<br />_ _public static ResultVO error(String message, Integer code) {<br /> ResultVO resultVO = new ResultVO()<br /> .setCode(code)<br /> .setMsg(message)<br /> .setTradeNo(UUIDUtils._getUUID_());<br /> return resultVO;<br /> }
_/**_<br />_ * 异常返回_<br />_ *_<br />_ * _**_@param _**_codeEnum_<br />_ * _**_@return_**<br />**_ _**_*/_<br />_ _public static ResultVO error(CodeEnum codeEnum, String msg) {<br /> ResultVO resultVO = new ResultVO()<br /> .setCode(codeEnum.getCode())<br /> .setMsg(msg)<br /> .setTradeNo(UUIDUtils._getUUID_());<br /> return resultVO;<br /> }
}
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.io.Serializable;
@Getter
@AllArgsConstructor
public enum CodeEnum implements Serializable {
SUCCESS(10000, “成功”),
ERROR(10001, “失败”),
KEY_OR_SECRET_EMPTY(10002, “appKey或appSecret为空”),
NULL_COMPANY_KEY(10003, “秘钥对匹配失败或者token失效,请检查”),
TOKEN_NULL(10004, “token不能为空”),
TOKEN_EXPIRE(10005, “token已失效,请重新获取”),
TOKEN_NO_AUTH(10006, “token非法请重新获取”),
TOKEN_SIGN_ERROR(10007, “token签名错误”),
PARAMS_ERROR(10008, “参数%s不能为空”),
API_NULL_OR_CLOSE(10009, “服务暂未开通或已关闭”),
BALANCE_NOT_ENOUGTH(10010, “余额不足,请充值”),
;
public int code;
public String msg;
public static CodeEnum getByKey(Integer key){
for(CodeEnum cst : CodeEnum.values()){
if(key.intValue() == cst.code){
return cst;
}
}
return null;
}