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

import com.zd.common.core.domain.R;
import com.zd.system.api.domain.LabStudentsInfo;
import com.zd.system.api.students.RemoteStudentsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.multipart.MultipartFile;

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

    @Override
    public RemoteStudentsService create(Throwable throwable) {
        log.error("学生信息调用失败:{}", throwable.getMessage());
        return new RemoteStudentsService() {
            @Override
            public R<LabStudentsInfo> getInfo(@PathVariable("joinStudentsId") Long id) {
                return R.fail("学生信息调用失败:" + throwable.getMessage());
            }
            @Override
            public R commitCard(MultipartFile file) {
                return R.fail("学生卡上传调用失败:" + throwable.getMessage());
            }
        };
    }
}
