package com.njcn.event.api.fallback;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.device.pq.pojo.param.GridDiagramParam;
import com.njcn.event.api.EventDetailFeignClient;
import com.njcn.event.api.RmpEventDetailFeignClient;
import com.njcn.event.pojo.dto.EventCount;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import com.njcn.event.pojo.vo.AdvanceEventDetailVO;
import com.njcn.event.pojo.vo.GeneralVO;
import com.njcn.event.utils.EventlEnumUtil;
import com.njcn.web.pojo.param.BaseParam;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @date 2023/07/21
 */
@Slf4j
@Component
public class RmpEventDetailFeignClientFallbackFactory implements FallbackFactory<RmpEventDetailFeignClient> {
    @Override
    public RmpEventDetailFeignClient create(Throwable throwable) {
        //判断抛出异常是否为解码器抛出的业务异常
        Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
        if (throwable.getCause() instanceof BusinessException) {
            BusinessException businessException = (BusinessException) throwable.getCause();
            exceptionEnum = EventlEnumUtil.getExceptionEnum(businessException.getResult());
        }
        Enum<?> finalExceptionEnum = exceptionEnum;
        return new RmpEventDetailFeignClient() {

            @Override
            public HttpResult<RmpEventDetailPO> queryEventDetailByEventId(String eventId) {
                log.error("{}异常，降级处理，异常为：{}", "查询暂降明细", throwable.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<EventCount>> getEventCount(GridDiagramParam param) {
                log.error("{}异常，降级处理，异常为：{}", "根据特征幅值进行统计", throwable.toString());
                throw new BusinessException(finalExceptionEnum);
            }
        };
    }
}
