package com.wechat.model.responseDto;

import org.nutz.lang.util.NutMap;

import com.wechat.common.utils.JacksonUtils;
import com.wechat.global.message.InfoMsg;

/**
 * @ClassName: JsonResp
 * @Description: Json返回对象
 */
public class JsonResp<T> {

	/**
	 * @Fields success : 请求是否成功
	 *         <p>
	 *         1：成功 0：失败
	 *         </p>
	 */
	private int result;

	private String code = "";

	/**
	 * @Fields error_msg : 请求错误信息
	 *         <p>
	 *         成功时为空,失败时会返回失败信息
	 *         </p>
	 */
	private String msg = "";

	private T info;

	public JsonResp() {
		this.result = 1;
		this.code = InfoMsg.SUCCESS_REQUEST.getCode();
		this.msg = InfoMsg.SUCCESS_REQUEST.getMsg();
	}

	public JsonResp(String _code, String _msg) {
		this.code = _code;
		this.msg = _msg;
		this.result = 0;
	}

	public JsonResp(int _result, String _code, String _msg) {
		this.result = _result;
		this.code = _code;
		this.msg = _msg;
	}

	public JsonResp(int _result, InfoMsg msgInfo) {
		this.result = _result;
		this.code = msgInfo.getCode();
		this.msg = msgInfo.getMsg();
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(InfoMsg msgInfo) {
		this.code = msgInfo.getCode();
		this.msg = msgInfo.getMsg();
	}

	public T getInfo() {
		return info;
	}

	public void setInfo(T info) {
		this.info = info;
	}

	public String getCode() {
		return code;
	}

	public NutMap fomartResp() {
		return JacksonUtils.writeNullToString(this);
	}
}
