package com.malk.huagao.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://113.45.187.194:1433;databaseName=dingding",
                        "hgdd", "hgdd@2025")
                .globalConfig(builder -> {
                    builder.author("WZY")
                            .disableOpenDir()
                            .outputDir(System.getProperty("user.dir")+
                                    "/mjava-huagao/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.huagao")
                            .controller("controller")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .entity("entity");
                })
                .strategyConfig(builder -> {
                    builder.addInclude("YD_PROD_WORK_HOURS_PRICE")
                            .entityBuilder().enableLombok();
                })
                .templateEngine(new VelocityTemplateEngine())
                .execute();
    }
}
