UserNameConverter.java 956 Bytes
package vion.config;

import org.dromara.hutool.core.lang.Opt;
import com.github.liaochong.myexcel.core.converter.CustomWriteContext;
import com.github.liaochong.myexcel.core.converter.CustomWriteConverter;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import vion.constant.RedisKeyEnum;
import vion.model.User;

/**
 * @author HlQ
 * @date 2024/1/3
 */
@Component
@RequiredArgsConstructor
public class UserNameConverter implements CustomWriteConverter<Long, String> {

    private final RedisTemplate redisTemplate;

    @Override
    public String convert(Long originalData, CustomWriteContext customWriteContext) {
        return Opt.ofNullable(((User) redisTemplate.opsForValue().get(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + originalData)))
                .map(User::getUsername)
                .orElse("未知");
    }
}