package com.hdkj.lt.core.log.exception;

import com.hdkj.lt.base.constants.ErrorLogConstant;
import com.hdkj.lt.base.exception.BusinessException;
import com.hdkj.lt.core.hussar.SpringContextHolder;
import com.hdkj.lt.core.log.model.param.ErrorLogParam;
import com.hdkj.lt.core.log.service.FhzgLogInfoService;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description: 用于抛出自定义异常的类
 * @Author: liuAini
 * @Create: 2025/07/18 10:55
 * @Version: 1.0
 */
public class ExceptionErrorLogCast {

    /**
     * 抛出异常/保存错误日志
     *
     * @param logParam 异常信息
     */
    public static void cast(ErrorLogParam logParam) {
        FhzgLogInfoService service = SpringContextHolder.getBean(FhzgLogInfoService.class);
        service.saveLog(logParam);
        //严重和错误抛异常
        if(StringUtils.equalsAny(logParam.getErrorLevel(), ErrorLogConstant.ErrorLevel.FATAL,ErrorLogConstant.ErrorLevel.ERROR)){
            cast(logParam.getDetails());
        }
    }



    /**
     * 抛出异常
     *
     * @param message 异常信息
     */
    public static void cast(String message) {
        throw new BusinessException(message);
    }

}
