package com.zd.system.api.factory;

import com.zd.common.core.domain.R;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.system.api.RemoteDeptService;
import com.zd.system.api.domain.SysDept;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

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

/**
 * 部门服务降级处理
 *
 * @author zd
 */
@Component
public class RemoteDeptFallbackFactory implements FallbackFactory<RemoteDeptService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteDeptFallbackFactory.class);

    @Override
    public RemoteDeptService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteDeptService() {
            @Override
            public R<List<SysDept>> getDeptList(SysDept sysDept) {
                return R.fail("获取部门失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult allParentId(List<Long> deptIds) {
                return AjaxResult.error("查询部门ID失败：" + throwable.getMessage());
            }

            @Override
            public Map<String, Object> queryDeptSignByUserId() {
                return AjaxResult.error("查询部门电子签章失败：" + throwable.getMessage());
            }

            @Override
            public AjaxResult getInfoById(Long id) {
                return AjaxResult.error("查询部门信息失败：" + throwable.getMessage());
            }
        };
    }
}
