package com.neusoft.smart.pos.framework.exception;


import com.neusoft.smart.pos.framework.constants.CommonCode;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import org.slf4j.helpers.MessageFormatter;

/**
 * @author zcf
 * @date 2017-08-13 10：43
 * @description 公共业务错误异常类
 */
public class BusinessCommonException extends RuntimeException {
    
    private String code;
    
    private String message;
    
    private static final long serialVersionUID = 7863499794674516484L;
    
    public BusinessCommonException(String code, String message) {
        super();
        this.code = code;
        this.message = message;
    }
    
    public BusinessCommonException(ResponseData<?> responseData) {
        super();
        this.code = responseData.getCode();
        this.message = responseData.getMessage();
    }
    
    public BusinessCommonException(CommonCode commonCode) {
        this(commonCode.getCode(), commonCode.getMessage());
    }
    
    public BusinessCommonException(CommonCode commonCode, String... filledMessages) {
        this(commonCode.getCode(), MessageFormatter.arrayFormat(commonCode.getMessage(), filledMessages).getMessage());
    }
    
    public String getCode() {
        return code;
    }
    
    public void setCode(String code) {
        this.code = code;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
}
