package com.njcn.prepare.harmonic.api.upload.fallback;

import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.prepare.harmonic.api.upload.DimBusGlobalFeignClient;
import com.njcn.prepare.harmonic.pojo.param.DeviceAbnormaStatisticsParam;
import com.njcn.prepare.harmonic.utils.PrepareEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

@Slf4j
@Component
public class DimBusGlobalFeignClientFallbackFactory implements FallbackFactory<DimBusGlobalFeignClient> {
    @Override
    public DimBusGlobalFeignClient create(Throwable throwable) {
        Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
        if (throwable.getCause() instanceof BusinessException) {
            BusinessException businessException = (BusinessException)throwable.getCause();
            exceptionEnum = PrepareEnumUtil.getExceptionEnum(businessException.getResult());
        }

        Enum<?> finalExceptionEnum = exceptionEnum;
        return new DimBusGlobalFeignClient() {
            @Override
            public void runLedgerStatistic(@RequestParam("date")String date) {
                log.error("{}异常，降级处理，异常为：{}", "统计周期台账运行详细信息:  ", throwable.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public void dimBusUpEveryDay(String date) {
                log.error("{}异常，降级处理，异常为：{}", "统计每日母线稳态超标详情:  ", throwable.toString());
                throw new BusinessException(finalExceptionEnum);
            }
        };
    }
}
