package com.ningdatech.generator.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;

/**
 * @description: 自动生成code代码
 * @author: zpf
 * @date: 2023/01/03 09:20
 */
public class GeneratorCodeKingbaseConfig {

    private static final String PATH_LXX = "/Users/liuxinxin/IdeaProjects/project-management/pmapi/src/main/java";
    private static final String PATH_YYD = "/Users/wendy/code project/java/project-management/pmapi/src/main/java";
    private static final String PATH_LS = "";
    private static final String PATH_ZPF = "D:\\ningda\\project-management\\pmapi\\src\\main\\java";
    private static final String PATH_CMM = "D:\\work\\project-management\\project-management\\pmapi\\src\\main\\java";

    private static final String URL = "jdbc:kingbase8://120.26.44.207:54321/nd_project_management?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8";
    private static final String USER_NAME = "SYSTEM";
    private static final String PASSWORD = "Ndkj1234";

    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.ningdatech")
                            // 设置父包模块名
                            .moduleName("pmapi." + packageName)
                            // 设置mapperXml生成路径
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml,
                                    //设置自己的生成路径
                                    path + "/com/ningdatech/pmapi/" + packageName + "/mapper"));
                })
                .strategyConfig(builder -> {
                    builder.addTablePrefix("");
                    // 设置需要生成的表名
                    builder.addInclude(tableNames);
                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }

    public static void main(String[] args) {
        generate("Liuxinxin", "organization", PATH_LXX, "organization_tag");
    }

}
