自定义结果集

自定义结果集

package com.xx.smart.common;

import lombok.Data;

@Data
public class BaseResponseEntity<T> {
    private int status;
    private String msg;
    private T data;

    public static <T> BaseResponseEntity<T> success(T data) {
        BaseResponseEntity<T> response = new BaseResponseEntity<>();
        response.setStatus(StatusEnum.SUCCESS.getRetCode());
        response.setMsg(StatusEnum.SUCCESS.getRetMsg());
        response.setData(data);
        return response;
    }

    public static <T> BaseResponseEntity<T> error() {
        BaseResponseEntity<T> response = new BaseResponseEntity<>();
        response.setStatus(StatusEnum.ERROR.getRetCode());
        response.setMsg(StatusEnum.ERROR.getRetMsg());
        return response;
    }

    public static <T> BaseResponseEntity<T> error(int status, String msg) {
        BaseResponseEntity<T> response = new BaseResponseEntity<>();
        response.setStatus(status);
        response.setMsg(msg);
        return response;
    }
}

package com.xx.smart.common;

/**
 * 如果产品比较大   状态码就可以细一点   如果是项目比较小,建议不要定义的太细
 */
public enum StatusEnum {
    /**
     * 返回成功
     */
    SUCCESS(200, "success", "成功"),
    ERROR(40000, "error", "错误"),
    // 用户相关
    UN_LOGIN(40001, "no login", "未登录"),
    UN_AUTH(40003, "no auth  account", "未授权"),
    LOGIN_SUCCESS(40008, "login success", "登录成功"),
    RESTART_LOGIN(40009, "restart login", "登录失败,重新登录"),
    /*用户未登录*/
    ACCOUNT_NOT_LOGIN(10001, "user no login", "用户未登录"),
    /*账号不存在或密码错误*/
    ACCOUNT_LOGIN_ERROR(10002, "user login error", "账号不存在或密码错误"),
    /*账号已存在*/
    ACCOUNT_IS_EXISTENT(10003, "account is existent", "账号已存在"),
    /*账号不存在*/
    ACCOUNT_NOT_EXIST(40004, "account not exist", "账号不存在!"),
    /*账号已禁止  请与管理员联系*/
    USER_ACCOUNT_LOCKED(10005, "user account locked", "账号被锁定, 请与管理员联系"),

    LOGIN_COUNT_LIMIT(10006, "account is existent", "登录失败多次,请稍后在试"),
    /* 参数错误*/
    /*参数不为空*/
    PARAMS_NOT_IS_BLANK(20001, "params not is blank", "参数不能为空"),
    /*参数无效*/
    PARAMS_IS_INVALID(20002, "params is invalid", "无效参数"),
    /*参数类型错误*/
    PARAM_TYPE_ERROR(20003, "param type error", "参数类型错误"),
    /*参数缺失*/
    PARAM_IS_DEFICIENCY(20004, "param is deficiency", "参数缺失"),
    /*暂无权限*/
    PERMISSION_NO_ACCESS(20006, "no permissions access", "暂无权限"),
    AUTH_ERROR(20007, "auth error", "认证失败"),
    /* 业务错误 */

    /* 业务繁忙 请稍后在试 */
    BUSINESS_UNKNOW_ERROR(30001, " busy with business", "业务繁忙 请稍后在试"),
    SYSTEM_ERROR(99999, "system  error", "接口错误"),

    /* ======系统错误:40001-49999===== */
    /* 提示语 "系统繁忙,请稍后重试"*/
    SYSTEM_INNER_ERROR(40001, "system error", "系统繁忙,请稍后重试"),
    /*未知错误 请稍后在试*/
    SYSTEM_UNKNOW_ERROR(40002, "system unknow error", "未知错误 请稍后在试"),
    /*内部系统接口调用异常*/
    INNER_INVOKE_ERROR(50001, "inner invoke error", "内部系统接口调用异常"),
    /*外部系统接口调用异常*/
    OUTER_INVOKE_ERROR(50002, "outer invoke error", "外部系统接口调用异常"),
    /*该接口禁止访问*/
    NO_ACCESS_FORBIDDEN(50003, "no access forbidden", "禁止访问"),
    /*接口地址无效*/
    NO_FOUND_ERROR(50004, "no found error", "接口地址无效"),
    /* 数据错误 */
    DATA_IS_WRONG(60001, "data is wrong", "数据错误");


    /**
     * 返回码
     */
    protected int retCode;
    /**
     * 返回说明
     */
    protected String retMsg;
    /**
     * 提示消息
     */
    protected String tips;

    StatusEnum(int retCode, String retMsg, String tips) {
        this.retCode = retCode;
        this.retMsg = retMsg;
        this.tips = tips;
    }

    public int getRetCode() {
        return retCode;
    }

    public void setRetCode(int retCode) {
        this.retCode = retCode;
    }

    public String getRetMsg() {
        return retMsg;
    }

    public void setRetMsg(String retMsg) {
        this.retMsg = retMsg;
    }

    public String getTips() {
        return tips;
    }

    public void setTips(String tips) {
        this.tips = tips;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值