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.Connection;
import java.sql.DriverManager;
import java.sql.Types;

public class MPGenerator {
    public static void main(String[] args) {
        //可以直接去官方文档上查看
        FastAutoGenerator
                .create("jdbc:sqlserver://113.45.187.194:1433;databaseName=dingding;encrypt=true;trustServerCertificate=true;",
                        "hgdd", "hgdd@2025")
                .globalConfig(builder -> {
                    builder.author("LQY")
                            .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("KD_YD_TRANSFER_DETAIL")
                            .entityBuilder().enableLombok();
                })
                .templateEngine(new VelocityTemplateEngine())
                .execute();
    }
//    public static void main(String[] args) {
//        String url = "jdbc:sqlserver://113.45.187.194:1433;"+"databaseName=dingding;"+"encrypt=false;"+"trustServerCertificate=true;";
//
//        try (Connection conn = DriverManager.getConnection(url, "hgdd", "hgdd@2025")) {
//            System.out.println("✅ 连接 SQL Server 成功！");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
}
