package com.malk.diwei.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.sql.Types;

public class MPGenerator {
    public static void main(String[] args) {
        //可以直接去官方文档上查看
        FastAutoGenerator
                .create("jdbc:sqlserver://47.98.200.166:1433;databaseName=GT_DB_Epi5",
                        "dw", "Goodtek2008")
                .globalConfig(builder -> {
                    builder.author("WZY")
                            .disableOpenDir()
                            .outputDir(System.getProperty("user.dir")+
                                    "/mjava-diwei/src/main/java");
                })
                .dataSourceConfig(builder ->
                        builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
                            int typeCode = metaInfo.getJdbcType().TYPE_CODE;
                            if (typeCode == Types.SMALLINT) {
                                return DbColumnType.INTEGER;
                            }
                            return typeRegistry.getColumnType(metaInfo);
                        }))
                .packageConfig(builder -> {
                    builder.parent("com.malk.diwei")
                            .controller("controller")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .entity("entity");
                })
                .strategyConfig(builder -> {
                    builder.addInclude("ProcessONDetail")
                            .entityBuilder().enableLombok();
                })
                .templateEngine(new VelocityTemplateEngine())
                .execute();
    }
}
