123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- 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://10.150.10.139: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<TableConfig> 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 generateCodesTest1() throws IOException {
- List<TableConfig> 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<TableConfig> 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<TableConfig> 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<TableConfig> 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<TableConfig> 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<TableConfig> 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<TableConfig> 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 gcAppFunction() throws IOException {
- List<TableConfig> tableConfigs = new ArrayList<>();
- TableConfig mainTable = new TableConfig();
- mainTable.setTableName("base_app_function");
- 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("app");
- params.setTableConfigs(tableConfigs);
- params.setPage(true);
- params.setImport(false);
- params.setExport(false);
- params.setOutMainDir(false);
- params.setDs(ds);
- IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl();
- apiGeneratorService.generateCodes(params);
- }
- @Test
- public void gcOauthFunction() throws IOException {
- List<TableConfig> tableConfigs = new ArrayList<>();
- TableConfig mainTable = new TableConfig();
- mainTable.setTableName("oauth_client_details");
- 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(true);
- params.setDs(ds);
- IApiGeneratorService apiGeneratorService = new ApiGeneratorServiceImpl();
- apiGeneratorService.generateCodes(params);
- }
- }
|