package com.centreproject.common.utils;

import com.baomidou.mybatisplus.annotation.TableName;

import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * 拼接表名
 * @author zhonglei.xu
 */
public class TableNameUtils {
    private static final Map<Class<?>, String> TABLE_NAME_CACHE = new ConcurrentHashMap<>();

    public static String getTableNames(String separator, Class<?>... entityClasses) {
        return Arrays.stream(entityClasses)
                .map(cls -> TABLE_NAME_CACHE.computeIfAbsent(
                        cls,
                        key -> key.getAnnotation(TableName.class).value()
                ))
                .collect(Collectors.joining(separator));
    }
}