package com.njcn.harmonic.api.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.harmonic.api.PmsTemProcessReportFeignClient;
import com.njcn.harmonic.api.UploadGwDataFeignClient;
import com.njcn.harmonic.pojo.param.UploadDataParam;
import com.njcn.harmonic.pojo.param.UploadParam;
import com.njcn.harmonic.utils.HarmonicEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author xuyang
 * @version 1.0.0
 * @date 2023年12月15日 13:50
 */
@Slf4j
@Component
public class PmsTemProcessReportFallbackFactory implements FallbackFactory<PmsTemProcessReportFeignClient> {
    @Override
    public PmsTemProcessReportFeignClient create(Throwable throwable) {
        //判断抛出异常是否为解码器抛出的业务异常
        Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
        if (throwable.getCause() instanceof BusinessException) {
            BusinessException businessException = (BusinessException) throwable.getCause();
            exceptionEnum = HarmonicEnumUtil.getExceptionEnum(businessException.getResult());
        }
        Enum<?> finalExceptionEnum = exceptionEnum;
        return new PmsTemProcessReportFeignClient() {


            @Override
            public HttpResult<Boolean> dayCalReport() {
                log.error("{}异常，降级处理，异常为：{}", "电能质量全过程月报", throwable.toString());
                return new HttpResult<>(CommonResponseEnum.FAIL.getCode(),CommonResponseEnum.FAIL.getMessage());
            }

        };
    }
}
