package com.njcn.csdevice.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.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.api.RoleEngineerDevFeignClient;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author xy
 */
@Slf4j
@Component
public class RoleEngineerDevClientFallbackFactory implements FallbackFactory<RoleEngineerDevFeignClient> {
    @Override
    public RoleEngineerDevFeignClient create(Throwable cause) {
        //判断抛出异常是否为解码器抛出的业务异常
        Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
        if (cause.getCause() instanceof BusinessException) {
            BusinessException businessException = (BusinessException) cause.getCause();
//            exceptionEnum = UserEnumUtil.getExceptionEnum(businessException.getResult());
        }
        Enum<?> finalExceptionEnum = exceptionEnum;
        return new RoleEngineerDevFeignClient() {


            @Override
            public HttpResult<List<String>> getRoleengineer() {
                log.error("{}异常，降级处理，异常为：{}","查询角色工程异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public HttpResult<List<String>> getDevice() {
                log.error("{}异常，降级处理，异常为：{}","查询角色设备异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }

            @Override
            public  HttpResult<List<String>> getRoleProject() {
                log.error("{}异常，降级处理，异常为：{}","查询角色项目异常",cause.toString());
                throw new BusinessException(finalExceptionEnum);
            }
        };
    }
}
