package com.jwipc;

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> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
public class Codegen {

    public static void main(String[] args) {
        //测试
//        final String url = "jdbc:oracle:thin:@//10.100.103.95:1521/agile9";
//        final String username = "srm";
//        final String password = "srm123";

//        final String url = "jdbc:sqlserver://10.100.101.51:1433;databaseName=SapSyncDB;encrypt=false;";
//        final String username = "singledb";
//        final String password = "H3&kjG8m4#Go";

        final String url = "jdbc:mysql://10.100.103.74:3306/jwipc_srm_test?characterEncoding=utf-8";
        final String username = "root";
        final String password = "JWIPC@2024!jwipc";

        final String author = "qzc";
//        final String author = "zhangjie";
        final String outputDir = "E:\\代码生成\\aa";
//        final String outputDir = "/Users/jiez/workspace/base";
        final String[] includeTables = {"t_contract_return_order_detail","t_contract_return_order"};
        final String[] strings = {"dev_", "t_", "c_", "sp_", "basis", "sys_", "t_tender_", "fin_"};
        final String packageName = "com.jwipc.contract";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author(author) // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(outputDir); // 指定输出目录
                })
                .packageConfig(builder -> {

                    builder.parent(packageName) // 设置父包名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, outputDir)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder().enableLombok().enableFileOverride();
                    builder.mapperBuilder().enableFileOverride();
                    builder.serviceBuilder().enableFileOverride();
                    builder.addInclude(includeTables) // 设置需要生成的表名
                            .addTablePrefix(strings); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
