package com.hz.pm.gen.config;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * <p>
 * CodeGen
 * </p>
 *
 * @author WendyYang
 * @since 13:27 2023/12/25
 */
public class CodeGen {

    private static final String PATH_YYD = "/Users/wendy/coding/java/hz-project-management/hz-pm-api/src/main/java";

    private static final String URL = "jdbc:dm://47.98.125.47:5236/HZ_PROJECT_MANAGEMENT?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8";
    private static final String USER_NAME = "SYSDBA";
    private static final String PASSWORD = "SYSDBA";

    private static void generate(String author, String packageName, String path, String... tableNames) {
        FastAutoGenerator.create(URL, USER_NAME, PASSWORD)
                .globalConfig(builder -> {
                    // 设置作者
                    builder.author(author)
                            // 开启 swagger 模式
                            .enableSwagger()
                            // 覆盖已生成文件
                            .fileOverride()
                            // 指定输出目录
                            .outputDir(path);
                })
                .packageConfig(builder -> {
                    // 设置父包名
                    builder.parent("com.hz.pm")
                            // 设置父包模块名
                            .moduleName("api." + packageName)
                            // 设置mapperXml生成路径
                            .pathInfo(Collections.singletonMap(OutputFile.xml,
                                    //设置自己的生成路径
                                    path + "/com/hz/pm/api/" + packageName + "/mapper"));
                })
                .strategyConfig(builder -> {
                    builder.addTablePrefix("");
                    // 设置需要生成的表名
                    builder.addInclude(tableNames);
                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }

    public static void main(String[] args) {
        generate("WendyYang", "meeting", PATH_YYD, "meeting_settings");
    }

}
