package com.microservices.system.api.factory;

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

import java.util.List;

/**
 * 部门服务降级处理
 *
 * @author microservices
 */
@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>> getDeptInDeptIds(List<Long> ids, String source) {
                return R.fail("获取部门列表失败:" + throwable.getMessage());
            }

            @Override
            public R<SysDept> getDeptByDeptId(Long deptId, String source) {
                return R.fail("获取部门失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> addDeptByZone(String zoneName, String source) {
                return R.fail("根据专区名称创建部门失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Long>> getSelfAndChildrenDeptIdListByDeptId(Long deptId, String source) {
                return R.fail("获取自身及子部门Id列表失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> addDeptByPmsEnterprise(String pmsEnterpriseName, String source) {
                return R.fail("根据企业名称新增部门失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> updateDeptNameByDeptId(Long deptId, String deptName, String source) {
                return R.fail("根据部门Id更新部门名称失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> deleteDeptByDeptId(Long deptId, String source) {
                return R.fail("根据部门Id删除部门失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> deleteDeptByPmsEnterprise(String pmsEnterpriseName, String source) {
                return R.fail("根据企业名称删除部门失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SysUserDeptRole>> getSysUserDeptRoleListByDeptId(Long deptId, String source) {
                return R.fail("通过组织Id查询组织下用户身份列表失败:" + throwable.getMessage());
            }

            @Override
            public R<List<String>> getGitLinkUserNamesByDeptIdAndRoleKeys(Long deptId, String roleKeys, String source) {
                return R.fail("查询组织编号下拥有传入角色权限字符串的用户名失败:" + throwable.getMessage());
            }
            @Override
            public R<Boolean> checkUserInDeptHasRole(Long deptId, Long userId, String roleKey, String source) {
                return R.fail("查询组织编号下拥有传入角色权限字符串的用户名失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> checkUserInDeptHasPerms(Long currentDeptId, Long userId, String perms, String source) {
                return R.fail("检查用户是否在指定部门下具有指定菜单权限失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> checkUserInDept(Long currentDeptId, Long userId, String source) {
                return R.fail("检查用户是否在指定部门下失败:" + throwable.getMessage());
            }
        };
    }
}
