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: liushuai
 * @date: 2022/3/25 14:20
 */
public class GeneratorCodeConfig {

    private static final String PATH_LXX = "/Users/LiuXinXin/IdeaProjects/car-manage/ningda-car-api/src/main/java";
    private static final String PATH_YYD = "/Users/wendy/coding/java/car-manage/ningda-car-api/src/main/java";
    private static final String PATH_LS = "/Users/qinxianyun/Documents/qin/ningdatech/secret-file-manage/ningda-api/src/main/java";
    private static final String PATH_ZPF = "D:\\ningda\\car-manage\\ningda-car-api\\src\\main\\java";
    //private static final String PATH_CMM = "D:\\work\\shuiniche\\car-manage\\ningda-car-api\\src\\main\\java";
    private static final String PATH_CMM = "D:\\work\\yw-road\\nd-yw-road\\ningda-yw-api\\src\\main\\java";

    private static final String URL = "jdbc:mysql://47.98.125.47:3306/nd-yw-road?serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false";
    private static final String USER_NAME = "root";
    private static final String PASSWORD = "Ndkj@1104";

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

    public static void main(String[] args) {
        //generate("PoffyZhang", "car.monitor",PATH_ZPF, "nd_vehicle_security_monitor");
        //generate("WendyYang", "irs",PATH_YYD, "nd_drivers_license");
        generate("CMM", "test",PATH_CMM, "nd_radar_original_data");
    }

}
