package com.sptg.iot.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.iot.api.dto.IotApiLogDto;
import com.sptg.iot.api.entity.IotApiLog;
import com.sptg.iot.api.feigns.IotApiLogFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * @author zwx
 * @create 2020/10/21 0:43
 */
@Component
@Slf4j
public class IotApiLogFeignFallbackFactory implements FallbackFactory<IotApiLogFeign> {
    @Override
    public IotApiLogFeign create(Throwable cause) {
        return new IotApiLogFeign() {
            @Override
            public ResultBean<String> recordIotApiLog(Map<String, Object> map) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

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

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