package com.pj.api.client.transport;

import com.pj.api.dto.DriverDto;
import com.pj.api.dto.PurchaserDto;
import com.pj.api.dto.TbLogisticsDto;
import com.pj.api.dto.VehicleDto;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @Author Mechrevo
 * @Date 2023 07 27 17 06
 **/
@Component
public class TransportInterfaceFallback implements FallbackFactory<TransportInterface> {

    private static final Logger log = LoggerFactory.getLogger(TransportInterfaceFallback.class);

    @Override
    public TransportInterface create(Throwable throwable) {
        return new TransportInterface() {
            @Override
            public PurchaserDto getByPurchaserId(Long id) {
                System.out.println(throwable.getMessage());
                log.error("触发降级熔断机制,id为:{}",id);
                return null;
            }

            @Override
            public DriverDto getByDriverId(Long id) {
                System.out.println(throwable.getMessage());
                log.error("触发降级熔断机制,id为:{}",id);
                return null;
            }

            @Override
            public TbLogisticsDto selectByOrderId(Long orderId) {
                System.out.println(throwable.getMessage());
                log.error("触发降级熔断机制,id为:{}",orderId);
                return null;
            }

            @Override
            public boolean driverDto(DriverDto driverDto) {
                System.out.println(throwable.getMessage());
                log.error("司机信息添加错误:{},错误信息是{}",driverDto,throwable.getMessage());
                return false;
            }

            @Override
            public boolean vehicleDto(VehicleDto vehicleDto){
                System.out.println(throwable.getMessage());
                log.error("车辆信息添加错误:{},错误信息是{}",vehicleDto,throwable.getMessage());
                return false;
            }
        };
    }
}
