统一异常处理

package com.first.pet.exception;

import com.first.pet.enums.ResultCode;

/**
 * 基础业务异常
 */
public class BusinessException extends RuntimeException {
    /**
     * 错误码
     */
    private String code;
    /**
     * 错误消息
     */
    private String msg;

    /**
     * 异常信息
     *
     * @param code
     * @param msg
     */
    public BusinessException(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 异常信息
     */
    public BusinessException(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    /**
     * 异常信息
     *
     * @param resultCode
     * @param formatParam
     */
    public BusinessException(ResultCode resultCode, Object... formatParam) {
        this.code = resultCode.getCode();
        this.msg = String.format(resultCode.getMsg(), formatParam);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

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

      // 获取总行数(含表头)
                    Integer rowNumber = context.readSheetHolder().getApproximateTotalRowNumber();
                    if (rowNumber > GoodsConstants.MAX_BATCH_COUNT) {
                        throw new BusinessException(GoodsResultCode.MAX_ROW_NUMBER, GoodsConstants.MAX_BATCH_COUNT);
                    }
/**
 * 基础redis常量类
 */
public class GoodsConstants {


    public static final String MANAGER_ADD_GOODS = "MANAGER_ADD_GOODS";

    public static final Integer FAVORABLE_COMMENT_INIT_COUNT = 4;

    /**
     * 单次缓存的数据量
     */
    public static final int BATCH_COUNT = 200;

    /**
     * 单次最大数据量
     */
    public static final int MAX_BATCH_COUNT = 2000;

    /**
     * 文件格式后缀
     */
    public static final String FORMAT = ".xlsx";


}

import com.first.pet.enums.ResultCode;

/**
 * 描述:
 * 错误码
 *
 * @author yangquan
 * @date 2023-09-01
 */
public enum GoodsResultCode implements ResultCode {

    MAX_ROW_NUMBER("002230","单次最大数据量不可超过s%条"),
    ;
    /**
     * 错误码
     */
    private String code;
    /**
     * 提示信息
     */
    private String msg;

    /**
     * @param code
     * @param msg
     */
    GoodsResultCode(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值