懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
提交 | 用户 | 时间
1ac2bc 1 package cn.stylefeng.guns.gen.core.generator.restful;
2
3 import cn.stylefeng.guns.gen.core.generator.base.model.ContextParam;
4 import cn.stylefeng.guns.gen.core.generator.restful.controller.RestfulControllerGenerator;
5 import cn.stylefeng.guns.gen.core.generator.restful.feign.FeignApiGenerator;
6 import cn.stylefeng.guns.gen.core.generator.restful.feign.FeignProviderGenerator;
7 import cn.stylefeng.guns.gen.core.generator.restful.mybatisplus.DefaultMpGenerator;
8 import cn.stylefeng.guns.gen.core.generator.restful.mybatisplus.param.MpParam;
9 import com.baomidou.mybatisplus.generator.config.po.TableInfo;
10
11 import java.util.List;
12 import java.util.Map;
13
14 /**
15  * 测试的执行器
16  *
17  * @author fengshuonan
18  * @date 2018-12-18-6:39 PM
19  */
20 public class RestfulApiExecutor {
21
22     /**
23      * 默认的生成器
24      *
25      * @author fengshuonan
26      * @Date 2019/1/13 22:18
27      */
28     public static void executor(ContextParam contextParam, MpParam mpContext) {
29
30         //执行mp的代码生成,生成entity,dao,service,model,生成后保留数据库元数据
31         DefaultMpGenerator defaultMpGenerator = new DefaultMpGenerator(mpContext);
32         defaultMpGenerator.initContext(contextParam);
33         defaultMpGenerator.doGeneration();
34
35         //获取元数据
36         List<TableInfo> tableInfos = defaultMpGenerator.getTableInfos();
37         Map<String, Map<String, Object>> everyTableContexts = defaultMpGenerator.getEveryTableContexts();
38
39         //遍历所有表
40         for (TableInfo tableInfo : tableInfos) {
41             Map<String, Object> map = everyTableContexts.get(tableInfo.getName());
42
43             //是否生成远程接口
44             if (contextParam.getRemote()) {
45
46                 //生成api接口
47                 FeignApiGenerator feignApiGenerator = new FeignApiGenerator(map);
48                 feignApiGenerator.initContext(contextParam);
49                 feignApiGenerator.doGeneration();
50
51                 //生成provider
52                 FeignProviderGenerator feignProviderGenerator = new FeignProviderGenerator(map);
53                 feignProviderGenerator.initContext(contextParam);
54                 feignProviderGenerator.doGeneration();
55
56             }
57
58
59             //生成控制器
60             RestfulControllerGenerator restfulControllerGenerator = new RestfulControllerGenerator(map);
61             restfulControllerGenerator.initContext(contextParam);
62             restfulControllerGenerator.doGeneration();
63         }
64     }
65
66 }