package com.eco.common.mapper.core.impl;

import com.eco.common.mapper.core.FieldMapperInterface;
import com.eco.common.mapper.annotation.FieldMapperType;
import com.eco.common.mapper.constant.MapperConstant;
import lombok.AllArgsConstructor;
import org.eco.common.core.service.UserService;

/**
 * @Description: UserNameMapperImpl 用户名映射
 * @Author: GaoKun Wang
 * @Date: 2024/7/1
 */
@AllArgsConstructor
@FieldMapperType(type = MapperConstant.USER_ID_TO_NAME)
public class UserNameMapperImpl implements FieldMapperInterface<String> {

    private final UserService userService;

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