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.common.core.constant.OperationConstant;
import com.sptg.device.api.dto.DevicePathDto;
import com.sptg.device.api.entity.DevicePath;
import com.sptg.device.api.feigns.DevicePathFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * title: DevicePathFeignFallbackFactory
 * package: com.sptg.device.api.feigns.fallback
 * description:设备位置对外服务接口容错处理
 */
@Component
@Slf4j
public class DevicePathFeignFallbackFactory implements FallbackFactory<DevicePathFeign> {

    @Override
    public DevicePathFeign create(Throwable cause) {
        return new DevicePathFeign() {

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

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

            @Override
            public DevicePath getEntityById(DevicePathDto dto) {
                log.error(cause.getMessage(),cause);
                return null;
            }

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

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

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

            @Override
            public List<DevicePath> getList(DevicePathDto dto) {
                log.error(cause.getMessage(),cause);
                return new ArrayList<>(OperationConstant.ZERO);
            }

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

            @Override
            public Boolean updateBatchById(List<DevicePath> devicePathList) {
                log.error(cause.getMessage(),cause);
                return null;
            }
        };
    }
}
