package com.microservices.system.api.factory;

import com.microservices.common.core.domain.R;
import com.microservices.system.api.RemoteNoticeService;
import com.microservices.system.api.domain.SysNotice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

public class RemoteNoticeFallbackFactory implements FallbackFactory<RemoteNoticeService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteNoticeFallbackFactory.class);

    @Override
    public RemoteNoticeService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteNoticeService()
        {
            @Override
            public R<Long> addNotice(SysNotice sysNotice, String source)
            {
                return R.fail("添加公告失败:" + throwable.getMessage());
            }

            @Override
            public R<SysNotice> getNotice(Long noticeId, String source) {
                return R.fail("获取公告详情失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> editNotice(SysNotice sysNotice, String source) {
                return R.fail("编辑公告失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> deleteNotice(Long[] noticeIds, String source) {
                return R.fail("删除公告失败:" + throwable.getMessage());
            }
        };
    }
}
