package com.siwei.spatial.api.factory;

import com.siwei.common.core.domain.R;
import com.siwei.spatial.api.RemoteSpatialFilesDbService;
import com.siwei.spatial.api.domain.file.TGeomDb;
import com.siwei.spatial.api.domain.file.TGeomDbDetails;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 日志服务降级处理
 *
 * @author siwei-zhx
 */
@Component
public class RemoteSpatialFilesDbFallbackFactory implements FallbackFactory<RemoteSpatialFilesDbService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteSpatialFilesDbFallbackFactory.class);

    @Override
    public RemoteSpatialFilesDbService create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new RemoteSpatialFilesDbService() {
            @Override
            public R<TGeomDb> readShp(String shpFileName, String shpFilePath, String fromRoute, String source) {
                return R.fail("内部调用异常");
            }

            @Override
            public R<TGeomDb> readWkt(String shpFileName, String wkt, String fromRoute, String source) {
                return R.fail("内部调用异常");
            }

            @Override
            public R<TGeomDb> readWkt(String shpFileName, String geom, String fromRoute, String fromType, String source) {
                return R.fail("内部调用异常");
            }

            @Override
            public R<TGeomDb> queryGeom(String id, Integer isDetail, String source) {
                return R.fail("内部调用异常");
            }

            @Override
            public R<List<TGeomDbDetails>> queryGeomDetails(String id, String source) {
                return R.fail("内部调用异常");
            }

            @Override
            public R<List<TGeomDbDetails>> queryGeomDetailsPage(String id, String source) {
                return R.fail("内部调用异常");
            }
        };

    }
}
