package com.sptg.estate.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.estate.api.dto.AgencyDto;
import com.sptg.estate.api.entity.Agency;
import com.sptg.estate.api.feigns.AgencyFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created By lidexi in 2021/1/8
 * 社区对外接口容错处理
 **/
@Component
@Slf4j
public class AgencyFeignFallbackFactory implements FallbackFactory<AgencyFeign> {
    @Override
    public AgencyFeign create(Throwable cause) {
        return new AgencyFeign() {
            @Override
            public ResultBean<Page<Agency>> showAgencyList(AgencyDto agencyDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Agency> addAgency(AgencyDto agencyDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

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

            @Override
            public ResultBean<Boolean> updateAgency(AgencyDto agencyDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> deleteAgency(AgencyDto agencyDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> deleteAgencyList(AgencyDto agencyDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Agency> findListByPosition(AgencyDto agencyDto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public List<Agency> getListByCondition(AgencyDto agencyDto) {
                log.error(cause.getMessage(),cause);
                return null;
            }
        };
    }
}
