package com.qs.mp.common.exception;

import com.qs.mp.common.enums.ErrorCodeEnum;

/**
 * 
 * 数据库接口访问异常，所有涉及到service事物调用接口都统一抛异常为失败操作。
 * 
 * @author duota
 *
 */
public class DataOperationException extends RuntimeException {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    protected final int code;
    protected final String message;

    public DataOperationException() {
        this.code = 1001; // 系统错误
        this.message = "数据操作失败.";
    }

    public DataOperationException(ErrorCodeEnum errorCodeEnum){
        this.code = errorCodeEnum.getCode();
        this.message = errorCodeEnum.getMsg();
    }

    public DataOperationException(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public DataOperationException(int code, String message, Throwable e) {
        super(message, e);
        this.code = code;
        this.message = message;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public int getCode() {
        return code;
    }

}
