AmisMessage.java 1.61 KB
package com.diligrp.assistant.shared.domain;

import com.diligrp.assistant.shared.ErrorCode;

/**
 * @author jy
 */
public class AmisMessage<T> {
    protected static final int CODE_SUCCESS = 0;
    protected static final int CODE_FAILURE = ErrorCode.SYSTEM_UNKNOWN_ERROR;
    protected static final String MSG_SUCCESS = "success";
    private Integer status;
    private String msg;
    private T data;
    public AmisMessage() {
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

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

    public T getData() {
        return this.data;
    }

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

    public static AmisMessage<?> success() {
        AmisMessage<?> result = new AmisMessage();
        result.status = 0;
        result.msg = "success";
        return result;
    }

    public static <E> AmisMessage<E> success(E data) {
        AmisMessage<E> result = new AmisMessage();
        result.status = 0;
        result.data = data;
        result.msg = "success";
        return result;
    }

    public static AmisMessage<?> failure(String message) {
        AmisMessage<?> result = new AmisMessage();
        result.status = 1000;
        result.msg = message;
        return result;
    }

    public static AmisMessage<?> failure(int code, String message) {
        AmisMessage<?> result = new AmisMessage();
        result.status = code;
        result.msg = message;
        return result;
    }
}