package com.qmth.teachcloud.report.business.cache;

import com.qmth.teachcloud.common.bean.dto.UserAuthenticationDto;
import com.qmth.teachcloud.common.contant.SpringContextHolder;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.util.RedisUtil;

import java.util.concurrent.TimeUnit;

/**
 * @Description: 武大开发鉴权用户临时授权cache
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2021/6/29
 */
public class WhuUserAuthCacheUtil {
    private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);

    public static void setAuthCode(UserAuthenticationDto userAuthenticationDto) {
        redisUtil.set(RedisKeyHelper.whuUserAuth(userAuthenticationDto.getUid()), userAuthenticationDto.getCode(), SystemConstant.REDIS_WHU_USER_AUTH_EXPIRE_TIME, TimeUnit.SECONDS);
    }

    public static String getAuthCode(String key) {
        return (String) redisUtil.get(RedisKeyHelper.whuUserAuth(key));
    }

    public static void deleteAuthCode(String key) {
        redisUtil.delete(RedisKeyHelper.whuUserAuth(key));
    }
}
