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


import com.zd.common.core.domain.R;
import com.zd.common.core.exception.ServiceException;
import com.zd.system.api.chemical.RemoteCabinetService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Component
public class RemoteCabinetFallbackFactory implements FallbackFactory<RemoteCabinetService> {
    private final static Logger logger = LoggerFactory.getLogger(RemoteCabinetFallbackFactory.class);

    @Override
    public RemoteCabinetService create(Throwable throwable) {
        logger.error("化学品服务调用失败:{}", throwable.getMessage());
        return new RemoteCabinetService() {

            @Override
            public R<List<LinkedHashMap <String, String>>> getCabinetList(Map subMap) {
                throw new ServiceException("获取机柜列表失败:" + throwable.getMessage());
            }
        };
    }
}
