package com.xjrsoft.xjrsoftboot; import cn.dev33.satoken.secure.SaSecureUtil; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.db.ds.simple.SimpleDataSource; import cn.hutool.db.meta.Column; import cn.hutool.db.meta.MetaUtil; import cn.hutool.db.meta.Table; import cn.hutool.http.HttpUtil; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.xjrsoft.XjrSoftApplication; import com.xjrsoft.common.constant.GlobalConstant; import com.xjrsoft.common.utils.DatasourceUtil; import com.xjrsoft.common.utils.JdbcToJavaUtil; import com.xjrsoft.module.generator.constant.EntityConstant; import com.xjrsoft.module.generator.dto.ApiGenerateCodesDto; import com.xjrsoft.module.generator.entity.FieldConfig; import com.xjrsoft.module.generator.entity.GeneratorConfig; import com.xjrsoft.module.generator.entity.TableConfig; import com.xjrsoft.module.generator.service.IApiGeneratorService; import com.xjrsoft.module.generator.service.impl.ApiGeneratorServiceImpl; import freemarker.template.Template; import freemarker.template.TemplateException; import lombok.AllArgsConstructor; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; import javax.sql.DataSource; import java.io.FileNotFoundException; import java.io.IOException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; public class FreeMarkerGeneratorTest { private static final DataSource ds = new SimpleDataSource("jdbc:mysql://8.142.26.206:3306/tl?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true", "root" , "Zwr~-f6H,u6QE^]C-AD_" ); @Test public void generateCodesTest() throws IOException { List tableConfigs = new ArrayList<>(); TableConfig mainTable = new TableConfig(); mainTable.setTableName("xjr_oa_news"); mainTable.setIsMain(true); mainTable.setPkField(GlobalConstant.DEFAULT_PK); mainTable.setPkType(GlobalConstant.DEFAULT_PK_TYPE); TableConfig childTable1 = new TableConfig(); childTable1.setTableName("xjr_oa_news_relation"); childTable1.setIsMain(false); childTable1.setPkField(GlobalConstant.DEFAULT_PK); childTable1.setPkType(GlobalConstant.DEFAULT_PK_TYPE); childTable1.setRelationField("news_id"); childTable1.setRelationTableField(GlobalConstant.DEFAULT_PK); TableConfig childTable2 = new TableConfig(); childTable2.setTableName("xjr_oa_news_relation_config"); childTable2.setIsMain(false); childTable2.setPkField(GlobalConstant.DEFAULT_PK); childTable2.setPkType(GlobalConstant.DEFAULT_PK_TYPE); childTable2.setRelationField("news_id"); childTable2.setRelationTableField(GlobalConstant.DEFAULT_PK); tableConfigs.add(mainTable); tableConfigs.add(childTable1); // tableConfigs.add(childTable2); ApiGenerateCodesDto params = new ApiGenerateCodesDto(); params.setAuthor("fanxp"); params.setPackageName("test"); params.setTableConfigs(tableConfigs); params.setPage(true); params.setImport(true); params.setExport(true); params.setOutMainDir(true); params.setDs(ds); IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl(); apiGeneratorService.generateCodes(params); } @Test public void generateCodesTest1() throws IOException { List tableConfigs = new ArrayList<>(); TableConfig mainTable = new TableConfig(); mainTable.setTableName("xjr_oa_news"); mainTable.setIsMain(true); mainTable.setPkField(GlobalConstant.DEFAULT_PK); mainTable.setPkType(GlobalConstant.DEFAULT_PK_TYPE); TableConfig childTable1 = new TableConfig(); childTable1.setTableName("xjr_oa_news_relation"); childTable1.setIsMain(false); childTable1.setPkField(GlobalConstant.DEFAULT_PK); childTable1.setPkType(GlobalConstant.DEFAULT_PK_TYPE); childTable1.setRelationField("news_id"); childTable1.setRelationTableField(GlobalConstant.DEFAULT_PK); TableConfig childTable2 = new TableConfig(); childTable2.setTableName("xjr_oa_news_relation_config"); childTable2.setIsMain(false); childTable2.setPkField(GlobalConstant.DEFAULT_PK); childTable2.setPkType(GlobalConstant.DEFAULT_PK_TYPE); childTable2.setRelationField("news_id"); childTable2.setRelationTableField(GlobalConstant.DEFAULT_PK); tableConfigs.add(mainTable); tableConfigs.add(childTable1); // tableConfigs.add(childTable2); ApiGenerateCodesDto params = new ApiGenerateCodesDto(); params.setAuthor("fanxp"); params.setPackageName("test"); params.setTableConfigs(tableConfigs); params.setPage(true); params.setImport(true); params.setExport(true); params.setOutMainDir(false); params.setDs(ds); IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl(); apiGeneratorService.generateCodes(params); } @Test public void gcMaterialType() throws IOException { List tableConfigs = new ArrayList<>(); TableConfig mainTable = new TableConfig(); mainTable.setTableName("material_type"); mainTable.setIsMain(true); mainTable.setPkField(GlobalConstant.DEFAULT_PK); mainTable.setPkType(GlobalConstant.DEFAULT_PK_TYPE); TableConfig childTable1 = new TableConfig(); childTable1.setTableName("material_type_assign"); childTable1.setIsMain(false); childTable1.setPkField(GlobalConstant.DEFAULT_PK); childTable1.setPkType(GlobalConstant.DEFAULT_PK_TYPE); childTable1.setRelationField("material_type_id"); childTable1.setRelationTableField(GlobalConstant.DEFAULT_PK); tableConfigs.add(mainTable); tableConfigs.add(childTable1); ApiGenerateCodesDto params = new ApiGenerateCodesDto(); params.setAuthor("baicai"); params.setPackageName("material"); params.setTableConfigs(tableConfigs); params.setPage(true); params.setImport(true); params.setExport(true); params.setOutMainDir(false); params.setDs(ds); IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl(); apiGeneratorService.generateCodes(params); } @Test public void gcMaterialTask() throws IOException { List tableConfigs = new ArrayList<>(); TableConfig mainTable = new TableConfig(); mainTable.setTableName("material_task"); mainTable.setIsMain(true); mainTable.setPkField(GlobalConstant.DEFAULT_PK); mainTable.setPkType(GlobalConstant.DEFAULT_PK_TYPE); TableConfig childTable1 = new TableConfig(); childTable1.setTableName("material_task_assign"); childTable1.setIsMain(false); childTable1.setPkField(GlobalConstant.DEFAULT_PK); childTable1.setPkType(GlobalConstant.DEFAULT_PK_TYPE); childTable1.setRelationField("material_task_id"); childTable1.setRelationTableField(GlobalConstant.DEFAULT_PK); TableConfig childTable2 = new TableConfig(); childTable2.setTableName("material_task_appendix"); childTable2.setIsMain(false); childTable2.setPkField(GlobalConstant.DEFAULT_PK); childTable2.setPkType(GlobalConstant.DEFAULT_PK_TYPE); childTable2.setRelationField("material_task_id"); childTable2.setRelationTableField(GlobalConstant.DEFAULT_PK); tableConfigs.add(mainTable); tableConfigs.add(childTable1); tableConfigs.add(childTable2); ApiGenerateCodesDto params = new ApiGenerateCodesDto(); params.setAuthor("baicai"); params.setPackageName("material"); params.setTableConfigs(tableConfigs); params.setPage(true); params.setImport(true); params.setExport(true); params.setOutMainDir(false); params.setDs(ds); IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl(); apiGeneratorService.generateCodes(params); } @Test public void gcLiteFlowTest() throws IOException { List tableConfigs = new ArrayList<>(); TableConfig mainTable = new TableConfig(); mainTable.setTableName("xjr_liteflow_chain"); mainTable.setIsMain(true); mainTable.setPkField(GlobalConstant.DEFAULT_PK); mainTable.setPkType(GlobalConstant.DEFAULT_PK_TYPE); tableConfigs.add(mainTable); ApiGenerateCodesDto params = new ApiGenerateCodesDto(); params.setAuthor("fanxp"); params.setPackageName("liteflow"); params.setTableConfigs(tableConfigs); params.setPage(false); params.setImport(false); params.setExport(false); params.setOutMainDir(false); params.setDs(ds); IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl(); apiGeneratorService.generateCodes(params); } @Test public void gcWFPushTest() throws IOException { List tableConfigs = new ArrayList<>(); TableConfig mainTable = new TableConfig(); mainTable.setTableName("wf_oa_push"); mainTable.setIsMain(true); mainTable.setPkField(GlobalConstant.DEFAULT_PK); mainTable.setPkType(GlobalConstant.DEFAULT_PK_TYPE); tableConfigs.add(mainTable); ApiGenerateCodesDto params = new ApiGenerateCodesDto(); params.setAuthor("fanxp"); params.setPackageName("oa"); params.setTableConfigs(tableConfigs); params.setPage(false); params.setImport(false); params.setExport(false); params.setOutMainDir(false); params.setDs(ds); IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl(); apiGeneratorService.generateCodes(params); } @Test public void gcWFPullest() throws IOException { List tableConfigs = new ArrayList<>(); TableConfig mainTable = new TableConfig(); mainTable.setTableName("wf_oa_pull"); mainTable.setIsMain(true); mainTable.setPkField(GlobalConstant.DEFAULT_PK); mainTable.setPkType(GlobalConstant.DEFAULT_PK_TYPE); tableConfigs.add(mainTable); ApiGenerateCodesDto params = new ApiGenerateCodesDto(); params.setAuthor("fanxp"); params.setPackageName("oa"); params.setTableConfigs(tableConfigs); params.setPage(false); params.setImport(false); params.setExport(false); params.setOutMainDir(false); params.setDs(ds); IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl(); apiGeneratorService.generateCodes(params); } @Test public void gcfileReceiveTest() throws IOException { List tableConfigs = new ArrayList<>(); TableConfig mainTable = new TableConfig(); mainTable.setTableName("file_receive"); mainTable.setIsMain(true); mainTable.setPkField(GlobalConstant.DEFAULT_PK); mainTable.setPkType(GlobalConstant.DEFAULT_PK_TYPE); tableConfigs.add(mainTable); ApiGenerateCodesDto params = new ApiGenerateCodesDto(); params.setAuthor("fanxp"); params.setPackageName("oa"); params.setTableConfigs(tableConfigs); params.setPage(true); params.setImport(false); params.setExport(false); params.setOutMainDir(true); params.setDs(ds); IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl(); apiGeneratorService.generateCodes(params); } @Test public void gcMobileWorkflowConfig() throws IOException { List tableConfigs = new ArrayList<>(); TableConfig mainTable = new TableConfig(); mainTable.setTableName("base_mobile_workflow_config"); mainTable.setIsMain(true); mainTable.setPkField(GlobalConstant.DEFAULT_PK); mainTable.setPkType(GlobalConstant.DEFAULT_PK_TYPE); tableConfigs.add(mainTable); ApiGenerateCodesDto params = new ApiGenerateCodesDto(); params.setAuthor("fanxp"); params.setPackageName("system"); params.setTableConfigs(tableConfigs); params.setPage(false); params.setImport(false); params.setExport(false); params.setOutMainDir(false); params.setDs(ds); IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl(); apiGeneratorService.generateCodes(params); } }