package com.trs.project.util;

/**
 * 封装接口返回类
 * @author 汤伟
 * @version 1.0
 *
 */
public class Result {
	public static final Integer OK = 200;// 正常
	public static final Integer NODATA = 201;// 无数据
	public static final Integer APPERROR = 400;// APP参数异常
	public static final Integer SERERROR = 500;// 服务器内部异常
	private String msg = "";//信息
	private Integer state;//状态

	private Object data;

	/**
	 * 处理成功返回，默认msg:success，state:200
	 * @param data
	 * @return
	 */
	public static Result OK(Object data){
		return new Result("success",200,data);
	}

	/**
	 * 处理成功返回，默认state:200
	 * @param data
	 * @param msg
	 * @return
	 */
	public static Result OK(Object data,String msg){
		return new Result(msg,200,data);
	}

	/**
	 * 处理错误返回，带状态码参数和data
	 * @param msg
	 * @param state
	 * @param data
	 * @return
	 */
	public static Result ERROR(String msg, Integer state, Object data){
		return new Result(msg,state,data);
	}

	/**
	 * 简单处理错误返回，默认data为null,状态码默认500
	 * @param msg
	 * @return
	 */
	public static Result ERROR(String msg){
		return new Result(msg,500,null);
	}

	/**
	 * 处理错误返回，传值data,无状态码参数，默认500
	 * @param msg
	 * @param data
	 * @return
	 */
	public static Result ERROR(String msg, Object data){
		return new Result(msg,500,data);
	}
	public Result(Integer state) {
		this.state = state;
	}

	public Result(String msg, Integer state, Object data) {
		this.msg = msg;
		this.state = state;
		this.data = data;
	}


	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "{msg：" + msg + ", state：" + state + ", data：" + data + "}";
	}

}
