package com.ym.mec.collectfee.common.web;

import org.springframework.http.HttpStatus;

public class BaseController {

	public static HttpResponseResult succeed(Object object) {
		return getResponseData(true, HttpStatus.OK, object, "");
	}

	public static HttpResponseResult succeed() {
		return getResponseData(true, HttpStatus.OK, null, "");
	}

	public static HttpResponseResult succeed(String message) {
		return failed(HttpStatus.OK, message);
	}

	public static HttpResponseResult succeedData(Object obj) {
		return getResponseData(true, HttpStatus.OK, obj, "操作成功");
	}

	public static HttpResponseResult warned(String message) {
		return failed(HttpStatus.MULTI_STATUS, message);
	}

	public static HttpResponseResult failed() {
		return failed("");
	}

	public static HttpResponseResult failed(String msg) {
		return failed(HttpStatus.INTERNAL_SERVER_ERROR, msg);
	}

	public static HttpResponseResult failed(HttpStatus statusCode, String msg) {
		return getResponseData(false, statusCode, null, msg);
	}

	private static HttpResponseResult getResponseData(boolean status, HttpStatus statusCode, Object data, String message) {
		HttpResponseResult obj = new HttpResponseResult();
		obj.setStatus(status);
		obj.setCode(statusCode.value());
		obj.setData(data);
		obj.setMsg(message);
		return obj;
	}

}
