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 com.zd.system.api.chemical.RemoteChemicalAlarmService;
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 RemoteChemicalAlarmFallbackFactory implements FallbackFactory<RemoteChemicalAlarmService> {
    private final static Logger logger = LoggerFactory.getLogger(RemoteChemicalAlarmFallbackFactory.class);

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

            @Override
            public R<List<LinkedHashMap <String, String>>> getList(Map alarmMap) {
                throw new ServiceException("获取智能报警列表失败:" + throwable.getMessage());
            }

            @Override
            public R <Boolean> updateStatus(Map alarmMap) {
                throw new ServiceException("变更智能报警日志已处理失败:" + throwable.getMessage());
            }

        };
    }
}
