package com.ruoyi.component.translation.core.impl;

import com.ruoyi.component.core.service.UserService;
import com.ruoyi.component.translation.annotation.TranslationType;
import com.ruoyi.component.translation.constant.TransConstant;
import com.ruoyi.component.translation.core.TranslationInterface;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.stereotype.Component;

/**
 * 用户名翻译实现
 *
 * @author Lion Li
 */
@AutoConfiguration
@AllArgsConstructor
@TranslationType(type = TransConstant.USER_ID_TO_NAME)
public class UserNameTranslationImpl implements TranslationInterface<String> {

    private final UserService userService;

    @Override
    public String translation(Object key, String other) {
        if (key instanceof Long) {
            return userService.selectUserNameById((Long) key);
        }
        return null;
    }
}
