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

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ExcelResultEnum;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.estate.api.dto.UnitDto;
import com.sptg.estate.api.entity.Unit;
import com.sptg.estate.api.feigns.UnitFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * title: UnitFallbcakFactory
 * package: com.sptg.estate.api.feigns.fallback
 * description: 单元 服务容错处理类
 *
 *
 *
 */
@Component
@Slf4j
public class UnitFeignFallbackFactory implements FallbackFactory<UnitFeign> {

    @Override
    public UnitFeign create(Throwable cause) {
        return new UnitFeign() {
            @Override
            public ResultBean<Page<Unit>> showUnitList(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<UnitDto> addUnit(UnitDto uitDto) {
                log.error(cause.getMessage(),cause);
                return null;
            }

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

            @Override
            public ResultBean<Boolean> updateUnit(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> deleteUnit(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> trashOrRecover(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> deleteUnitList(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Unit> findListByPosition(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public  ResultBean<Unit> findListByPid(UnitDto unitDto) {
                log.error(ResultEnum.ERROR.getCode(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public List<Unit> getListByXqId(Long xqId) {
                log.error(ResultEnum.ERROR.getCode(),cause);
                return new ArrayList<>(0);
            }

            @Override
            public List<Unit> getListByIdList(List<Long> dyIdList) {
                log.error(ResultEnum.ERROR.getCode(),cause);
                return null;
            }

            @Override
            public List<Unit> getListByIdListAndUnitName(List<Long> dyIdList, String unitName) {
                log.error(ResultEnum.ERROR.getCode(),cause);
                return null;
            }

            @Override
            public ResultBean<Boolean> importUnitList(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ExcelResultEnum.ERROR);
            }

            @Override
            public ResultBean<Map<String, Integer>> getUnitAccount(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public int getUnitCount(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return 0;
            }

            @Override
            public int findUnitByCondition(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return 0;
            }

            @Override
            public Unit findUnitByNameAndNumber(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public Unit getByUnitNumberAndXqId(Long xqId, String unitNumber) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public boolean updateEntity(Unit unit) {
                log.error(cause.getMessage(),cause);
                return false;
            }

            @Override
            public boolean updateUnitList(List<Unit> unitList) {
                log.error(cause.getMessage(),cause);
                return false;
            }

            @Override
            public List<Unit> getListByLikeName(UnitDto dto) {
                log.error(ResultEnum.ERROR.getCode(),cause);
                return new ArrayList<>(0);
            }

            @Override
            public Unit addUnitByImport(Unit unit) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public Unit getByOldId(String oldId) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public Unit getByUnitNumber(String unitNumber) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public int addUnitBySync(Unit unit) {
                log.error(cause.getMessage(),cause);
                return 0;
            }

            @Override
            public List<Unit> getListByBuildingId(Long buildingId) {
                log.error(cause.getMessage(),cause);
                return null;
            }

            @Override
            public List<Unit> getListByCondition(UnitDto unitDto) {
                log.error(cause.getMessage(),cause);
                return null;
            }
        };
    }
}
