package org.wfc.user.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.user.api.RemoteULogService;
import org.wfc.user.api.domain.ULogininfor;
import org.wfc.user.api.domain.UOperLog;

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

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

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

    }
}
