/*
 * Copyright (c) 2023 codvision.com All Rights Reserved.
 */

package com.codvision.base.config;

import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.builder.CustomFile;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import javax.validation.constraints.NotNull;
import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * velocity模板引擎扩展
 * <p>
 * 生成代码使用
 *
 * @author lingee
 * @date 2023/5/21
 */
public class EnhanceVelocityTemplateEngine extends VelocityTemplateEngine {

    @Override
    protected void outputCustomFile(@NotNull List<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
        String entityName = tableInfo.getEntityName();
        String otherPath = this.getPathInfo(OutputFile.entity);
        customFiles.forEach(item -> {
            String fileName = String.format(otherPath + File.separator + "vo" + File.separator + entityName + "%s",
                    item.getFileName());
            this.outputFile(new File(fileName), objectMap, item.getTemplatePath(), true);
        });
    }
}
