package com.moka.gdtauto;

import java.nio.file.Paths;
import java.util.Collections;

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

public class BaseCodeGenerator {

    public final static String TABLE_NAMES = "rep_daily_adgroup_report,req_daily_adgroup_report";
    public static void main(String[] args) {
        String url = "jdbc:mysql://rm-uf65d6xsxrp743w3aio.mysql.rds.aliyuncs.com:3306/gdt_auto?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true";
        FastAutoGenerator.create(url, "gdt_auto", "QA_GDT_AUTO%$PDL")
        .globalConfig(builder -> builder
                .author("mokamvp")
                .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                .commentDate("yyyy-MM-dd")
        )
        .packageConfig(builder -> builder
                .parent("com.moka.gdtauto")
                .entity("entity")
                .mapper("mapper")
                .service("service")
                .serviceImpl("service.impl")
                .pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir") + "/src/main/resources/mapper"))
        )
        .strategyConfig(builder -> builder
                .addInclude(TABLE_NAMES)
                .entityBuilder().enableLombok().enableFileOverride()
                .mapperBuilder().enableFileOverride()
                .serviceBuilder().formatServiceFileName("%sService")
                .formatServiceImplFileName("%sServiceImp").enableFileOverride()
                .controllerBuilder().enableRestStyle().enableFileOverride()
        )
        .templateEngine(new FreemarkerTemplateEngine())
        .execute();
    }
}
