懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
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
package cn.stylefeng.guns.gen.core.generator.restful;
 
import cn.stylefeng.guns.gen.core.generator.base.model.ContextParam;
import cn.stylefeng.guns.gen.core.generator.restful.controller.RestfulControllerGenerator;
import cn.stylefeng.guns.gen.core.generator.restful.feign.FeignApiGenerator;
import cn.stylefeng.guns.gen.core.generator.restful.feign.FeignProviderGenerator;
import cn.stylefeng.guns.gen.core.generator.restful.mybatisplus.DefaultMpGenerator;
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 RestfulApiExecutor {
 
    /**
     * 默认的生成器
     *
     * @author fengshuonan
     * @Date 2019/1/13 22:18
     */
    public static void executor(ContextParam contextParam, MpParam mpContext) {
 
        //执行mp的代码生成,生成entity,dao,service,model,生成后保留数据库元数据
        DefaultMpGenerator defaultMpGenerator = new DefaultMpGenerator(mpContext);
        defaultMpGenerator.initContext(contextParam);
        defaultMpGenerator.doGeneration();
 
        //获取元数据
        List<TableInfo> tableInfos = defaultMpGenerator.getTableInfos();
        Map<String, Map<String, Object>> everyTableContexts = defaultMpGenerator.getEveryTableContexts();
 
        //遍历所有表
        for (TableInfo tableInfo : tableInfos) {
            Map<String, Object> map = everyTableContexts.get(tableInfo.getName());
 
            //是否生成远程接口
            if (contextParam.getRemote()) {
 
                //生成api接口
                FeignApiGenerator feignApiGenerator = new FeignApiGenerator(map);
                feignApiGenerator.initContext(contextParam);
                feignApiGenerator.doGeneration();
 
                //生成provider
                FeignProviderGenerator feignProviderGenerator = new FeignProviderGenerator(map);
                feignProviderGenerator.initContext(contextParam);
                feignProviderGenerator.doGeneration();
 
            }
 
 
            //生成控制器
            RestfulControllerGenerator restfulControllerGenerator = new RestfulControllerGenerator(map);
            restfulControllerGenerator.initContext(contextParam);
            restfulControllerGenerator.doGeneration();
        }
    }
 
}