package com.ag.mybatisplusgenerator.config;

import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import org.apache.ibatis.annotations.Mapper;

public class GeneratorConfig {


    //生成策略
    private static StrategyConfig.Builder STRATEGY_CONFIG = new StrategyConfig.Builder();

    private static GlobalConfig.Builder GLOBAL_CONFIG = new GlobalConfig.Builder()
            .disableOpenDir();

    private static PackageConfig.Builder PACKAGE_CONFIG = new PackageConfig.Builder();

    private static TemplateConfig TEMPLATE_CONFIG = new TemplateConfig.Builder()
            .disable(TemplateType.CONTROLLER)
//            .disable(TemplateType.SERVICE)
//            .disable(TemplateType.SERVICE_IMPL)
            .build();



    public static StrategyConfig.Builder getSTRATEGY_CONFIG() {
        STRATEGY_CONFIG.mapperBuilder()
                //xml
//                .enableBaseResultMap()
//                .enableBaseColumnList()
                //mapper接口的注解
                .mapperAnnotation(Mapper.class);
        STRATEGY_CONFIG.entityBuilder()
                .enableTableFieldAnnotation()
                //覆盖
                .enableFileOverride();
        return STRATEGY_CONFIG;
    }

    /**
     * MYBATIS-PLUS 生成方法
     */
    public static GlobalConfig.Builder getGlobalConfig(String projectName) {
        String src;
        String parentProjectSrc = System.getProperty("user.dir");
        String srcBase = "\\src\\main\\java";
        src = parentProjectSrc.substring(0,parentProjectSrc.lastIndexOf("\\")+1)+projectName+srcBase;
        GLOBAL_CONFIG.outputDir(src);
        GLOBAL_CONFIG.dateType(DateType.ONLY_DATE);
        return GLOBAL_CONFIG;
    }

    public static PackageConfig.Builder getPACKAGE_CONFIG() {
        return PACKAGE_CONFIG;
    }

    public static TemplateConfig getTemplateConfig() {
        return TEMPLATE_CONFIG;
    }

}
