package  bus;

import com.orcas.deve.tool.common.enums.ProjectType;
import com.orcas.deve.tool.common.model.generate.GenerateConfig;
import com.orcas.deve.tool.common.model.generate.ProjectInfo;
import com.orcas.deve.tool.common.model.generate.TableInfo;
import com.orcas.deve.tool.core.service.CodeGenerator;
import com.orcas.deve.tool.core.service.strategy.StrategySelector;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;


@SpringBootTest(classes = {Application.class})
public class CodeGenerateTest {

	@Test
	public void codeGenerate(){
		GenerateConfig generateConfig = new GenerateConfig();
		//设置输出目录
		CodeGenerator.baseOutputDir="F:\\360MoveData\\Users\\sdy\\Desktop\\1731132063887";
		//设置项目信息
		ProjectInfo projectInfo = new ProjectInfo();
		//1表示多模块0表示单模块
		projectInfo.setType(ProjectType.multyModule.getValue());
		projectInfo.setAuthor("zy");
		projectInfo.setBasePackage("bus");
		projectInfo.setProjectName("bus");
		generateConfig.setProjectInfo(projectInfo);
		//获取数据源信息
		generateConfig.getDataSourceInfo().setJdbcUrl("jdbc:mysql://metapixels.top:13306/bus_allot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
		generateConfig.getDataSourceInfo().setJdbcUserName("root");
		generateConfig.getDataSourceInfo().setJdbcPassword("9a41012499f38251");
		generateConfig.getDataSourceInfo().setJdbcDriverName("com.mysql.cj.jdbc.Driver");
		//设置生成的表
		List<TableInfo> tables = new ArrayList<>();
		TableInfo tableInfo = new TableInfo();
		tableInfo.setTableName("b_advert");
		tableInfo.setTableAlias("bAdvert");
		tables.add(tableInfo);
		generateConfig.setTableInfos(tables);
		//生成代码
		StrategySelector selector = new StrategySelector();
		//代码生成
		try {
			//生成控制层目录
			String moduleName = generateConfig.getProjectInfo().getProjectName()+"-web";
			generateConfig.getProjectInfo().setModuleName(moduleName);
			selector.generateWeb(generateConfig,"");
			//生成业务层目录
			moduleName = generateConfig.getProjectInfo().getProjectName()+"-biz";
			generateConfig.getProjectInfo().setModuleName(moduleName);
			selector.generateBiz(generateConfig,"");
			//生成公共实体层目录
			moduleName = generateConfig.getProjectInfo().getProjectName()+"-common";
			generateConfig.getProjectInfo().setModuleName(moduleName);
			selector.generateCommon(generateConfig,"");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
