懒羊羊
2023-11-14 8286c62256f23bc2367a6729c0f46f84215e380b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package cn.stylefeng.guns.gen.core.generator.guns;
 
import cn.stylefeng.guns.gen.core.generator.base.model.ContextParam;
import cn.stylefeng.guns.gen.core.generator.guns.controller.GunsControllerGenerator;
import cn.stylefeng.guns.gen.core.generator.guns.html.GunsPageAddGenerator;
import cn.stylefeng.guns.gen.core.generator.guns.html.GunsPageEditGenerator;
import cn.stylefeng.guns.gen.core.generator.guns.html.GunsPageIndexGenerator;
import cn.stylefeng.guns.gen.core.generator.guns.js.GunsPageAddJsGenerator;
import cn.stylefeng.guns.gen.core.generator.guns.js.GunsPageEditJsGenerator;
import cn.stylefeng.guns.gen.core.generator.guns.js.GunsPageIndexJsGenerator;
import cn.stylefeng.guns.gen.core.generator.guns.mybatisplus.GunsMpGenerator;
import cn.stylefeng.guns.gen.core.generator.guns.sqls.GunsMenuSqlGenerator;
import cn.stylefeng.guns.gen.core.generator.restful.mybatisplus.param.MpParam;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
 
import java.util.List;
import java.util.Map;
 
/**
 * 测试的执行器
 *
 * @author fengshuonan
 * @date 2018-12-18-6:39 PM
 */
public class GunsExecutor {
 
    /**
     * 默认的生成器
     *
     * @author fengshuonan
     * @Date 2019/1/13 22:18
     */
    public static void executor(ContextParam contextParam, MpParam mpContext) {
 
        //执行mp的代码生成,生成entity,dao,service,model,生成后保留数据库元数据
        GunsMpGenerator gunsMpGenerator = new GunsMpGenerator(mpContext);
        gunsMpGenerator.initContext(contextParam);
        gunsMpGenerator.doGeneration();
 
        //获取元数据
        List<TableInfo> tableInfos = gunsMpGenerator.getTableInfos();
        Map<String, Map<String, Object>> everyTableContexts = gunsMpGenerator.getEveryTableContexts();
 
        //遍历所有表
        for (TableInfo tableInfo : tableInfos) {
            Map<String, Object> map = everyTableContexts.get(tableInfo.getName());
 
            //生成控制器
            GunsControllerGenerator gunsControllerGenerator = new GunsControllerGenerator(map);
            gunsControllerGenerator.initContext(contextParam);
            gunsControllerGenerator.doGeneration();
 
            //生成主页面html
            GunsPageIndexGenerator gunsPageIndexGenerator = new GunsPageIndexGenerator(map);
            gunsPageIndexGenerator.initContext(contextParam);
            gunsPageIndexGenerator.doGeneration();
 
            //生成主页面js
            GunsPageIndexJsGenerator gunsPageIndexJsGenerator = new GunsPageIndexJsGenerator(map);
            gunsPageIndexJsGenerator.initContext(contextParam);
            gunsPageIndexJsGenerator.doGeneration();
 
            //生成添加页面html
            GunsPageAddGenerator gunsPageAddGenerator = new GunsPageAddGenerator(map);
            gunsPageAddGenerator.initContext(contextParam);
            gunsPageAddGenerator.doGeneration();
 
            //生成添加页面的js
            GunsPageAddJsGenerator gunsPageAddJsGenerator = new GunsPageAddJsGenerator(map);
            gunsPageAddJsGenerator.initContext(contextParam);
            gunsPageAddJsGenerator.doGeneration();
 
            //生成编辑页面html
            GunsPageEditGenerator gunsPageEditGenerator = new GunsPageEditGenerator(map);
            gunsPageEditGenerator.initContext(contextParam);
            gunsPageEditGenerator.doGeneration();
 
            //生成编辑页面的js
            GunsPageEditJsGenerator gunsPageEditJsGenerator = new GunsPageEditJsGenerator(map);
            gunsPageEditJsGenerator.initContext(contextParam);
            gunsPageEditJsGenerator.doGeneration();
 
            //生成菜单的sql
            GunsMenuSqlGenerator gunsMenuSqlGenerator = new GunsMenuSqlGenerator(map);
            gunsMenuSqlGenerator.initContext(contextParam);
            gunsMenuSqlGenerator.doGeneration();
        }
    }
 
    public static void main(String[] args) {
 
        ContextParam contextParam = new ContextParam();
 
        contextParam.setJdbcDriver("com.mysql.jdbc.Driver");
        contextParam.setJdbcUserName("root");
        contextParam.setJdbcPassword("root");
        contextParam.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/generator_platform?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=CTT");
        contextParam.setOutputPath("temp");
        contextParam.setAuthor("fengshuonan");
        contextParam.setProPackage("cn.stylefeng.guns.modular.test");
 
        MpParam mpContextParam = new MpParam();
        mpContextParam.setGeneratorInterface(true);
        mpContextParam.setIncludeTables(new String[]{"test"});
        mpContextParam.setRemoveTablePrefix(new String[]{"sys_"});
 
        GunsExecutor.executor(contextParam, mpContextParam);
    }
 
}