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.entity.MqConf;
import com.sptg.device.api.feigns.MqConfFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * title: MqConfFeignFallbackFactory
 * package: com.sptg.device.api.feigns.fallback
 * description: 队列配置服务接口容错处理
 */
@Component
@Slf4j
public class MqConfFeignFallbackFactory implements FallbackFactory<MqConfFeign> {

    @Override
    public MqConfFeign create(Throwable cause) {
        return new MqConfFeign() {
            @Override
            public Page<MqConf> pagingQuery(Page<MqConf> page) {
                log.error(cause.getMessage(),cause);
                return page;
            }

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

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

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

            @Override
            public ResultBean<Boolean> deleteEntityById(Long id) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> startServer(Long id) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> stopServer(Long id) {
                log.error(cause.getMessage(),cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
        };
    }
}
