package com.gic.haoban.manage.service.util;

import com.gic.api.base.commons.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.Supplier;

/**
 * Created by wangzubo on 2024/9/8.
 */
public class ExecuteServiceUtil {

    private static final Logger logger = LoggerFactory.getLogger(ExecuteServiceUtil.class);


    public static  <T> T executeService(Supplier<T> serviceCall, String errorMsg) throws BusinessException {
        try {
            return serviceCall.get();
        } catch (Exception e) {
            logger.error(errorMsg, e);
            throw new BusinessException("-1", errorMsg);
        }
    }

    public static void executeService(Runnable serviceCall, String errorMsg) {
        try {
            serviceCall.run();
        } catch (Exception e) {
            logger.error(errorMsg, e);
        }
    }
}
