package com.bonus.gs.sub.evaluate.manager.utils;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class AjaxRes implements Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 返回码值,默认值Const.FAI
	 */
	private int res = GlobalConst.FAIL;
	/**
	 * 返回码值解析
	 */
	private String resMsg;
	/**
	 * 返回对象
	 */
	private Object obj;

	/** layui列表数据 */
	private List<?> data;

	/** 消息状态码 */
	private int code;
	private int statusCode;

	/** 消息内容 */
	private String msg;
	private String message;
	private Object status;

	/** layui总记录数 */
	private long count;
   
	public int getRes() {
		return res;
	}

	public void setRes(int res) {
		this.res = res;
	}

	public String getResMsg() {
		return resMsg;
	}

	public void setResMsg(String resMsg) {
		this.resMsg = resMsg;
	}

	public Object getObj() {
		return obj;
	}

	public void setObj(Object obj) {
		this.obj = obj;
	}

	/**
	 * 设置没有权限返回值
	 * 
	 * @param auth
	 *            原值返回
	 * @return
	 */
	public boolean setNoAuth(boolean auth) {
		if (!auth) {
			this.obj = null;
			this.setRes(GlobalConst.NO_AUTHORIZED);
			this.setResMsg(GlobalConst.NO_AUTHORIZED_MSG);
		}
		return auth;
	}

	/**
	 * 设置成功值
	 * 
	 * @param obj
	 *            设置对象
	 * @param resMsg
	 *            设置码值解析
	 */
	public void setSucceed(Object obj, String resMsg) {
		this.setResMsg(resMsg);
		this.setSucceed(obj);
	}

	public void getDataTableLayui(List<?> list, int count)
	{
		this.setCode(0);
		this.setData(list);
		this.setMsg("查询成功");
		this.setCount(count);
	}

	public void getDataTableLayuis(List<?> list, int count)
	{
		this.setCode(200);
		this.setData(list);
		this.setMsg("操作成功");
		this.setCount(count);
	}

	/**
	 * 设置成功值
	 * 
	 * @param obj
	 *            设置对象
	 */
	public void setSucceed(Object obj) {
		this.obj = obj;
		this.setRes(GlobalConst.SUCCEED);
	}
	public void setListSucceed(List<?> list) {
		this.setStatusCode(200);
		this.setCode(200);
		this.setMsg("操作成功");
		this.setData(list);
		this.setCount(list.size());
		StatusBean statusBean = new StatusBean();
		statusBean.setCode(200);
		statusBean.setMessage("操作成功");
		this.setStatus(statusBean);
	}

	/**
	 * 设置成功值
	 * 
	 * @param resMsg
	 *            返回码值解析
	 */
	public void setSucceedMsg(String resMsg) {
		this.setRes(GlobalConst.SUCCEED);
		this.setResMsg(resMsg);
	}

	/**
	 * 设置失败值
	 * 
	 * @param resMsg
	 *            返回码值解析
	 */
	public void setFailMsg(String resMsg) {
		this.obj = null;
		this.setRes(GlobalConst.FAIL);
		this.setResMsg(resMsg);
	}

	@Override
	public String toString() {
		return "AjaxRes [res=" + res + ", resMsg=" + resMsg + ", obj=" + obj
				+ "]";
	}

	class StatusBean {
		private Integer code;
		private String message;

		public Integer getCode() {
			return code;
		}

		public void setCode(Integer code) {
			this.code = code;
		}

		public String getMessage() {
			return message;
		}

		public void setMessage(String message) {
			this.message = message;
		}
	}
}
