package com.zd.system.api.factory;

import com.zd.common.core.web.domain.AjaxResult;
import com.zd.system.api.domain.SysLogoConfigVO;
import com.zd.system.api.model.SimpleUserVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.zd.common.core.domain.R;
import com.zd.system.api.RemoteUserService;
import com.zd.system.api.domain.SysUser;
import com.zd.system.api.model.LoginUser;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 用户服务降级处理
 *
 * @author zd
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService() {

            private static final String MESSAGE_HEAD="获取用户失败:";
            @Override
            public R<LoginUser> getUserInfo(String username, String source) {
                return R.fail(MESSAGE_HEAD + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getUserInfo(String username, Integer loginType, String source) {
                return R.fail(MESSAGE_HEAD + throwable.getMessage());
            }

            /**
             * 通过用户ID查询用户信息
             *
             * @param id     用户id
             * @param source 请求来源
             * @return 结果
             */
            @Override
            public R<SysUser> getUserInfoByUserId(Long id, String source) {
                return R.fail(MESSAGE_HEAD + throwable.getMessage());
            }

            /**
             * 通过用户账户查询用户信息
             *
             * @param userName 用户账户
             * @param source   请求来源
             * @return 结果
             */
            @Override
            public R<SysUser> getUserInfoByUserName(String userName, String source) {
                return R.fail(MESSAGE_HEAD + throwable.getMessage());
            }
            /**
             * 通过用户卡号查询用户信息
             *
             * @param userName 用户账户
             * @param source   请求来源
             * @return 结果
             */
            @Override
            public R<SysUser> getUserInfoByCardNum(String userName, String source) {
                return R.fail("通过用户卡号查询用户信息失败:" + throwable.getMessage());
            }



            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source) {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<SimpleUserVO> myInfoSimple(String source) {
                return R.fail("查询当前用户简略信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Long>> userALLIDS(String source) {
                return R.fail("获取所有用户ID失败:" + throwable.getMessage());
            }

            /**
             * 根据用户ids获取电话
             *
             * @param ids
             * @return 结果
             */
            @Override
            public R<List<String>> getPhoneByUserIDS(String ids) {
                return R.fail("获取所有用户手机号失败:" + throwable.getMessage());
            }

            @Override
            public R<List<Long>> userDeptIDS(String deptId, String source) {
                return R.fail("获取院系下用户ID失败:" + throwable.getMessage());
            }

            @Override
            public R<Object> departmentsList() {
                return R.fail("获取小程序查询院系列表失败:" + throwable.getMessage());
            }

            @Override
            public R<Object> building(Long deptId) {
                return R.fail("获取小程序查询院系下楼栋列表失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult getRouters(Long userId) {
                return AjaxResult.error("登录获取菜单失败：" + throwable.getMessage());
            }

            @Override
            public AjaxResult selectAuthUserPower(Long userId) {
                return AjaxResult.error("大屏用户权限失败：" + throwable.getMessage());
            }

            @Override
            public AjaxResult editUser(SysUser user) { return AjaxResult.error("学生信息更新失败：" + throwable.getMessage()); }

            @Override
            public AjaxResult editStudent(SysUser user) { return AjaxResult.error("安全准入学生信息更新失败：" + throwable.getMessage()); }

            @Override
            public R updateSignature(MultipartFile file) {
                return R.fail("修改签名信息失败：" + throwable.getMessage());
            }

            @Override
            public AjaxResult getConfigKey(String configKey) {
                return AjaxResult.error("获取默认密码数据失败：" + throwable.getMessage());
            }

            @Override
            public R querySignature() {
                return R.fail("查询签名信息失败：" + throwable.getMessage());
            }

            @Override
            public R <SysLogoConfigVO> getConfigLogo() {
                return R.fail("查询一体机logo信息失败：" + throwable.getMessage());
            }

            @Override
            public AjaxResult remove(Long[] userIds) {
                return AjaxResult.error("用户账号信息删除失败："+throwable.getMessage());
            }

            /**
             * 获取当前登录用户所属学校以及院系id集合
             *
             * @return
             */
            @Override
            public R<List<Long>> getLogingUserDeptids() {
                return R.fail("获取登录用户所属学校及院系失败:" + throwable.getMessage());
            }

            /**
             * 获取当前登录用户所属学校的deptid
             *
             * @return
             */
            @Override
            public R<Long> getLoginUserSchoolDeptid() {
                return R.fail("获取当前登录用户所属学校的deptid失败:" + throwable.getMessage());
            }

            /***
             * 根据电话查询用户信息
             * @param phone
             * @return
             */
            @Override
            public R<SysUser> getUserByPhone(String phone) {
                return R.fail("根据电话查询用户信息失败:" + throwable.getMessage());
            }


        };
    }
}
