package com.vctgo.system.api.factory;

import com.vctgo.common.core.domain.R;
import com.vctgo.system.api.RemoteBookService;
import com.vctgo.system.api.domain.BookBaseInfoDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 图书服务降级处理
 *
 * @author vctgo
 */
@Component
public class RemoteBookFallbackFactory implements FallbackFactory<RemoteBookService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteBookFallbackFactory.class);

    @Override
    public RemoteBookService create(Throwable throwable) {
        log.error("获取图书服务调用失败:{}", throwable.getMessage());
        return new RemoteBookService() {

            @Override
            public R<List<BookBaseInfoDto>> getBookListByLabelId(Long labelId) {
                return R.fail("通过标签ID查询图书列表信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<BookBaseInfoDto>> innerGetBookBaseInfoByIds(String ids) {
                return R.fail("通过图书ID查询图书列表信息失败:" + throwable.getMessage());
            }
        };
    }
}
