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

import com.zd.common.core.domain.R;
import com.zd.system.api.face.FaceCompare;
import com.zd.system.api.face.RemoteFaceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

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

    @Override
    public RemoteFaceService create(Throwable throwable) {
        log.error("人脸检测服务调用失败:{}", throwable.getMessage());
        return new RemoteFaceService() {
            @Override
            public R<byte[]> upload(MultipartFile file) {

                return R.fail("人脸检测服务调用失败:" + throwable.getMessage());
            }

            /**
             * 人脸特征对比
             *
             * @param faceCompare 文件信息
             * @return 结果
             */
            @Override
            public R compare(FaceCompare faceCompare) {
                return R.fail("人脸对比服务调用失败:" + throwable.getMessage());
            }
        };
    }
}
