package com.mini.capi.mybatis;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class demo {

    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://crontab.club:33069/work?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC", "dream", "info_dream")
                .globalConfig(builder -> {
                    builder.author("gaoxq")
                            .outputDir(System.getProperty("user.dir") + "/src/main/java")
                            .disableOpenDir();
                })
                .packageConfig(builder -> {
                    builder.parent("com.mini.capi")
                            .moduleName("biz")
                            .entity("domain")
                            .mapper("mapper")
                            .xml("mapper.xml")
                            .service("service")
                            .serviceImpl("service.impl")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir") + "/src/main/resources/mapper"));
                })
                .strategyConfig(builder -> {
                    builder.addInclude("data_table_info,data_table_field")
                            .addTablePrefix("biz_,erp_")
                            .entityBuilder()
                            .enableLombok()
                            .naming(NamingStrategy.underline_to_camel)
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .idType(IdType.AUTO)
                            .enableTableFieldAnnotation()
                            .enableFileOverride()
                            .controllerBuilder()
                            .enableRestStyle()
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .formatServiceImplFileName("%sServiceImpl")
                            .mapperBuilder()
                            .enableBaseResultMap()
                            .enableBaseColumnList()
                            .enableFileOverride(); // 开启mapper接口和xml文件覆盖
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
