package com.tofly.base.converter;

import com.tofly.base.entity.User;
import com.tofly.base.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class UserRealNameConverter implements Converter {

    @Autowired
    private UserService userService;
    @Override
    public String convert(Object value) {
        if(Objects.isNull(value)) {
            return "";
        }
        User user = userService.getById(Long.parseLong(value.toString()));
        return Objects.isNull(user) ? "" : user.getRealName();
    }
}