package org.wfc.system.api.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.wfc.common.core.domain.R;
import org.wfc.system.api.RemoteLogService;
import org.wfc.system.api.domain.SysLogininfor;
import org.wfc.system.api.domain.SysOperLog;

/**
 * 日志服务降级处理
 * 
 * @author wfc
 */
@Component
public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteLogFallbackFactory.class);

    @Override
    public RemoteLogService create(Throwable throwable)
    {
        log.error("Log service call failed:{}", throwable.getMessage());
        return new RemoteLogService()
        {
            @Override
            public R<Boolean> saveLog(SysOperLog sysOperLog, String source)
            {
                return R.fail("Failed to save operation log:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> saveLogininfor(SysLogininfor sysLogininfor, String source)
            {
                return R.fail("Failed to save login log:" + throwable.getMessage());
            }
        };

    }
}
