duhuizhe
2024-04-19 64c4fd3c7067c7626dc960a70b4bc2c3662bc653
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
package com.yqzx.generator.action.config;
 
import com.yqzx.generator.action.model.TableInfo;
import com.yqzx.generator.config.DataSourceConfig;
import com.yqzx.generator.engine.TemplateEngine;
import com.yqzx.generator.engine.base.AbstractTemplateEngine;
import com.yqzx.generator.engine.config.ContextConfig;
import com.yqzx.generator.service.GeneratorService;
 
import java.util.List;
 
/**
 * @description: 代码生成的抽象配置
 * @author: chaoyapeng
 * @time: 2020/8/18 15:47
 */
public abstract  class AbstractGeneratorConfig {
 
    ContextConfig contextConfig = new ContextConfig();
 
    DataSourceConfig dataSourceConfig = new DataSourceConfig();
 
    List<TableInfo> tableInfo;
 
    String columnStr;
 
    List<TableInfo> queryTableInfo;
 
    /**
     * 初始化配置
     */
    protected abstract void config();
 
    public void init() {
        config();
        GeneratorService generatorService = new GeneratorService();
        List<TableInfo> tableInfo = generatorService.setDataSourceConfig(dataSourceConfig)
                .getTableInfo(contextConfig.getTableName());
        this.tableInfo = tableInfo;
        String columnStr = "";
        for (TableInfo item : tableInfo) {
            columnStr += ", " + item.getName();
        }
        this.columnStr = columnStr.substring(2);
    }
 
    public void doGeneration() {
        init();
        AbstractTemplateEngine templateEngine = new TemplateEngine();
        templateEngine.setContextConfig(contextConfig);
        templateEngine.setTableInfo(tableInfo);
        templateEngine.setColumnStr(columnStr);
        templateEngine.setQueryTableInfo(queryTableInfo);
        templateEngine.start();
    }
 
    protected void setQueryTableInfo(List<TableInfo> queryTableInfo){
        this.queryTableInfo = queryTableInfo;
    }
 
}