UserNameConverter.java 972 Bytes
package vion.config.excel;

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

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

    private final RedissonClient redissonClient;

    @Override
    public String convert(Long originalData, CustomWriteContext customWriteContext) {

        return Opt.ofNullable(redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + originalData).get())
                .map(u -> (User) u)
                .map(User::getUsername)
                .orElse("未知");
    }
}