package com.sptg.permissions.api.feigns.fallback;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.PageBean;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.permissions.api.dto.AccountDto;
import com.sptg.permissions.api.dto.AccountRoleDto;
import com.sptg.permissions.api.entity.Account;
import com.sptg.permissions.api.entity.AccountRole;
import com.sptg.permissions.api.feigns.AccountRoleFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * title: AccountRoleFeignFallbackFactory
 * package: com.sptg.permissions.api.feigns.fallback
 * description: 账号角色对外服务接口-容错处理
 *
 *                  
 *                 
 */
@Component
@Slf4j
public class AccountRoleFeignFallbackFactory implements FallbackFactory<AccountRoleFeign> {

    @Override
    public AccountRoleFeign create(Throwable cause) {
        return new AccountRoleFeign(){
            @Override
            public ResultBean<Page> pagingQuery(PageBean<AccountRole,AccountRoleDto> pageBean) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Page> pagingQueryAccountListByNotHaveRole(PageBean<Account,AccountDto> pageBean) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> bindUser(AccountRoleDto dto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }

            @Override
            public ResultBean<Boolean> untieUser(AccountRoleDto dto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
        };
    }
}
