package com.docus.server;//package com.docus.server.clinicqualitycontrol.all;
//
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.HashMap;
import java.util.Map;

/**
 * mybatis plus代码生成器
 */
public class MybatisPlusGenerator {

    public static void main(String[] args) {
        //获得entity目录
        String entity = "D:\\ideaProject\\docus_inspection\\docus-services\\docus-services-inspection\\docus-services-inspection-interfaces\\src\\main\\java\\com\\docus\\services\\system\\entity\\";
        //获取mapper目录
        String mapper = "D:\\ideaProject\\docus_inspection\\docus-services\\docus-services-inspection\\docus-services-inspection-application\\src\\main\\java\\com\\docus\\services\\system\\mapper";
        //获取mapper的xml目录
        String mapperxml = "D:\\ideaProject\\docus_inspection\\docus-services\\docus-services-inspection\\docus-services-inspection-application\\src\\main\\resources\\mapper";
        //获取模块名
        //获取service目录
        String service = "D:\\ideaProject\\docus_inspection\\docus-services\\docus-services-inspection\\docus-services-inspection-interfaces\\src\\main\\java\\com\\docus\\services\\system\\facade";
        //获得serviceimpl目录
        String serviceImpl = "D:\\ideaProject\\docus_inspection\\docus-services\\docus-services-inspection\\docus-services-inspection-application\\src\\main\\java\\com\\docus\\services\\system\\service";

//        //获得controller目录
        String controller = "D:\\ideaProject\\docus_inspection\\docus-services\\docus-services-inspection\\docus-services-inspection-controller\\src\\main\\java\\com\\docus\\services\\system\\controller";
        //1,代码生成器
        AutoGenerator mpg = new AutoGenerator();
        // 2、全局配置
        GlobalConfig gc = new GlobalConfig();
        gc.setFileOverride(true); //重新生成时文件是否覆盖

        //UserServie
        //gc.setServiceName("%sService");    //去掉Service接口的首字母I
        gc.setAuthor("jiashi");           //自定义作者
        gc.setOpen(false); //生成后是否打开资源管理器
        gc.setIdType(IdType.INPUT); //主键策略
        gc.setDateType(DateType.ONLY_DATE);//定义生成的实体类中日期类型
        gc.setSwagger2(true);//开启Swagger2模式
        mpg.setGlobalConfig(gc);

        //数据库配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl("jdbc:log4jdbc:mysql://8.134.10.251:3306/docus_inspection?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai");
        dataSourceConfig.setDriverName("net.sf.log4jdbc.sql.jdbcapi.DriverSpy");
        dataSourceConfig.setUsername("docus");
        dataSourceConfig.setPassword("docus702");
        mpg.setDataSource(dataSourceConfig);

        //包配置
        PackageConfig pc = new PackageConfig();
        //设置自定义输出目录（分布式项目使用）
        Map<String, String> pathInfo = new HashMap<>();
//        pathInfo.put(ConstVal.ENTITY_PATH, entity);
//        pathInfo.put(ConstVal.MAPPER_PATH, mapper);
//        pathInfo.put(ConstVal.XML_PATH, mapperxml);
//        pathInfo.put(ConstVal.SERVICE_PATH, service);
//        pathInfo.put(ConstVal.SERVICE_IMPL_PATH, serviceImpl);
        pathInfo.put(ConstVal.CONTROLLER_PATH, controller);
        pc.setPathInfo(pathInfo);
        mpg.setPackageInfo(pc);
        //设置自定义包名
        pc.setParent("com.docus.services.system");
        pc.setService("facade");
        pc.setServiceImpl("service");
        mpg.setPackageInfo(pc);

        // 5、策略配置
        StrategyConfig strategy = new StrategyConfig();

        strategy.setInclude("inspection_status"); //要生成的表

        strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
        strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀

        strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略
        strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作

        strategy.setRestControllerStyle(true); //restful api风格控制器
        strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符

        mpg.setStrategy(strategy);


        // 6、执行
        mpg.execute();

        //7，注意的是，需将service包中生成的serviceImpl中的@Service注解改成@DubboService注解
    }
}
