package com.zd.system.api.forward.factory;

import com.zd.common.core.domain.R;
import com.zd.system.api.domain.SysFile;
import com.zd.system.api.forward.RemoteForwardService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 文件服务降级处理
 *
 * @author zd
 */
@Component
public class RemoteForwardFallbackFactory implements FallbackFactory<RemoteForwardService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteForwardFallbackFactory.class);

    @Override
    public RemoteForwardService create(Throwable throwable) {
        log.error("实验室服务调用失败:{}", throwable.getMessage());
        return new RemoteForwardService() {
            /**
             * 保存检查记录
             */
            @Override
            public R add(Map<String, Object> map) {
                return R.fail("实验室检查项结果保存调用失败:" + throwable.getMessage());
            }

            @Override
            public Object saveData(Map<String, Object> data) {

                return R.fail("保存调用失败:" + throwable.getMessage());
            }

            @Override
            public R<SysFile> photograph(String streamUrl) {
                return R.fail("报警拍照服务调用失败:" + throwable.getMessage());
            }
        };
    }
}
