package com.fs.qw.cache.impl;

import com.fs.qw.cache.IQwUserCacheService;
import com.fs.qw.domain.QwUser;
import com.fs.qw.service.IQwUserService;
import com.fs.store.domain.FsUser;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class QwUserCacheServiceImpl implements IQwUserCacheService {
    @Autowired
    private IQwUserService qwUserService;
    /**
     * 企微用户名昵称缓存类
     */
    private static final Cache<String, String> QW_USER_CACHE = Caffeine.newBuilder()
            .maximumSize(5000)
            .expireAfterWrite(12, TimeUnit.HOURS)
            .build();
    @Override
    public String queryQwUserNameByUserId(String userId) {
        return QW_USER_CACHE.get(userId,e-> {
            QwUser qwUser = qwUserService.selectQwUserByQwUserId(userId);
            if(qwUser != null) {
                return String.format("%s_%s",qwUser.getQwUserId(),qwUser.getQwUserName());
            }
            return "-";
        });
    }
}
