package com.sptg.device.api.feigns.fallback;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.device.api.dto.TimeStrategyDto;
import com.sptg.device.api.entity.TimeStrategy;
import com.sptg.device.api.feigns.TimeStrategyFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * title: TimeStrategyFeignFallbackFactory
 * package: com.sptg.device.api.feigns.fallback
 * description:时间策略-对外服务接口容错处理
 */
@Component
@Slf4j
public class TimeStrategyFeignFallbackFactory implements FallbackFactory<TimeStrategyFeign> {
    @Override
    public TimeStrategyFeign create(Throwable cause) {
        return new TimeStrategyFeign(){

            @Override
            public ResultBean<Page<TimeStrategy>> pagingQuery(TimeStrategyDto dto) {
                log.error(cause.getMessage(),cause);
                return  new ResultBean<>(ResultEnum.ERROR) ;
            }

            @Override
            public TimeStrategy selectById(Long id) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public ResultBean<Boolean> addEntity(TimeStrategyDto entity) {
                log.error(cause.getMessage(),cause);
                return  new ResultBean<>(ResultEnum.ERROR) ;
            }

            @Override
            public ResultBean<TimeStrategy> getEntityById(TimeStrategyDto dto) {
                log.error(cause.getMessage(),cause);
                return  new ResultBean<>(ResultEnum.ERROR) ;
            }

            @Override
            public ResultBean<Boolean> editEntity(TimeStrategyDto dto) {
                log.error(cause.getMessage(),cause);
                return  new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> deleteEntity(TimeStrategyDto dto) {
                log.error(cause.getMessage(),cause);
                return  new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public List<TimeStrategy> getEntityList(TimeStrategyDto dto) {
                log.error(cause.getMessage(),cause);
                return  new ArrayList<>(0);
            }
        };
    }
}
