package com.xueyi.system.api.pass.feign.factory;

import com.alibaba.fastjson2.JSONObject;
import com.xueyi.common.core.web.result.R;
import com.xueyi.system.api.pass.domain.dto.DmRecognizedMultiRecordsDto;
import com.xueyi.system.api.pass.domain.dto.DmRecognizedRecordsDto;
import com.xueyi.system.api.pass.feign.RemoteRecognizedRecordsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 通行上传服务 降级处理
 *
 * @author xueyi
 */
@Slf4j
@Component
public class RemotePassFallbackFactory implements FallbackFactory<RemoteRecognizedRecordsService> {

    @Override
    public RemoteRecognizedRecordsService create(Throwable throwable) {
        log.error("通行记录上传调用失败:{}", throwable.getMessage());
        return new RemoteRecognizedRecordsService() {

            @Override
            public JSONObject uploadPass(DmRecognizedRecordsDto recognizedRecordsDto, Long enterpriseId, String sourceName, String source) {
                return  R.fail("通行记录上传失败:" + throwable.getMessage()).toJson();
            }

            @Override
            public JSONObject uploadMultiPass(DmRecognizedMultiRecordsDto recognizedMultiRecordsDto, Long enterpriseId, String sourceName, String source) {
                return  R.fail("通行记录上传失败:" + throwable.getMessage()).toJson();
            }
        };
    }
}