提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.gen.core.generator.guns.sqls; |
懒 |
2 |
|
|
3 |
import cn.hutool.core.util.StrUtil; |
|
4 |
import cn.stylefeng.guns.gen.core.generator.base.AbstractCustomGenerator; |
|
5 |
import cn.stylefeng.guns.gen.core.util.TemplateUtil; |
|
6 |
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
7 |
import com.baomidou.mybatisplus.generator.config.po.TableInfo; |
|
8 |
import org.beetl.core.Template; |
|
9 |
|
|
10 |
import java.io.File; |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.List; |
|
13 |
import java.util.Map; |
|
14 |
|
|
15 |
/** |
|
16 |
* Guns菜单相关的sql生成器 |
|
17 |
* |
|
18 |
* @author fengshuonan |
|
19 |
* @date 2018-12-13-2:20 PM |
|
20 |
*/ |
|
21 |
public class GunsMenuSqlGenerator extends AbstractCustomGenerator { |
|
22 |
|
|
23 |
public GunsMenuSqlGenerator(Map<String, Object> tableContext) { |
|
24 |
super(tableContext); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public void bindingOthers(Template template) { |
|
29 |
TableInfo tableInfo = (TableInfo) tableContext.get("table"); |
|
30 |
template.binding("menus", getMenus(tableInfo)); |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
public String getTemplateResourcePath() { |
|
35 |
return "/gunsTemplates/menu_sql.sql.btl"; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public String getGenerateFileTempPath() { |
|
40 |
String lowerEntity = (String) this.tableContext.get("lowerEntity"); |
|
41 |
File file = new File(contextParam.getOutputPath() + "/sqls/" + lowerEntity + "_menus.sql"); |
|
42 |
return file.getAbsolutePath(); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public String getGenerateFileDirectPath() { |
|
47 |
return this.getGenerateFileTempPath(); |
|
48 |
} |
|
49 |
|
|
50 |
private List<MenuModel> getMenus(TableInfo tableInfo) { |
|
51 |
ArrayList<MenuModel> menuModels = new ArrayList<>(); |
|
52 |
|
|
53 |
MenuModel parentMenu = new MenuModel(); |
|
54 |
parentMenu.setMenuId(IdWorker.getId()); |
|
55 |
parentMenu.setCode(StrUtil.toUnderlineCase(tableInfo.getEntityName()).toUpperCase()); |
|
56 |
parentMenu.setPcode("0"); |
|
57 |
parentMenu.setPcodes("[0],"); |
|
58 |
if (StrUtil.isBlank(TemplateUtil.cleanWhite(tableInfo.getComment()))) { |
|
59 |
parentMenu.setName("空表名"); |
|
60 |
} else { |
|
61 |
parentMenu.setName(TemplateUtil.cleanWhite(tableInfo.getComment())); |
|
62 |
} |
|
63 |
parentMenu.setIcon("fa-star"); |
|
64 |
parentMenu.setUrl("/" + TemplateUtil.lowerFirst((String) tableContext.get("entity"))); |
|
65 |
parentMenu.setSort(999); |
|
66 |
parentMenu.setLevels(1); |
|
67 |
parentMenu.setMenuFlag("Y"); |
|
68 |
parentMenu.setSystemType("BASE_SYSTEM"); |
|
69 |
menuModels.add(parentMenu); |
|
70 |
|
|
71 |
MenuModel addMenu = new MenuModel(); |
|
72 |
addMenu.setMenuId(IdWorker.getId()); |
|
73 |
addMenu.setCode(StrUtil.toUnderlineCase(tableInfo.getEntityName()).toUpperCase() + "_ADD"); |
|
74 |
addMenu.setPcode(parentMenu.getCode()); |
|
75 |
addMenu.setPcodes("[0],[" + parentMenu.getCode() + "],"); |
|
76 |
addMenu.setName(parentMenu.getName() + "添加"); |
|
77 |
addMenu.setIcon("fa-star"); |
|
78 |
addMenu.setSort(999); |
|
79 |
addMenu.setLevels(2); |
|
80 |
addMenu.setMenuFlag("N"); |
|
81 |
addMenu.setSystemType("BASE_SYSTEM"); |
|
82 |
menuModels.add(addMenu); |
|
83 |
|
|
84 |
MenuModel editMenu = new MenuModel(); |
|
85 |
editMenu.setMenuId(IdWorker.getId()); |
|
86 |
editMenu.setCode(StrUtil.toUnderlineCase(tableInfo.getEntityName()).toUpperCase() + "_EDIT"); |
|
87 |
editMenu.setPcode(parentMenu.getCode()); |
|
88 |
editMenu.setPcodes("[0],[" + parentMenu.getCode() + "],"); |
|
89 |
editMenu.setName(parentMenu.getName() + "修改"); |
|
90 |
editMenu.setIcon("fa-star"); |
|
91 |
editMenu.setSort(999); |
|
92 |
editMenu.setLevels(2); |
|
93 |
editMenu.setMenuFlag("N"); |
|
94 |
editMenu.setSystemType("BASE_SYSTEM"); |
|
95 |
menuModels.add(editMenu); |
|
96 |
|
|
97 |
MenuModel deleteMenu = new MenuModel(); |
|
98 |
deleteMenu.setMenuId(IdWorker.getId()); |
|
99 |
deleteMenu.setCode(StrUtil.toUnderlineCase(tableInfo.getEntityName()).toUpperCase() + "_DELETE"); |
|
100 |
deleteMenu.setPcode(parentMenu.getCode()); |
|
101 |
deleteMenu.setPcodes("[0],[" + parentMenu.getCode() + "],"); |
|
102 |
deleteMenu.setName(parentMenu.getName() + "删除"); |
|
103 |
deleteMenu.setIcon("fa-star"); |
|
104 |
deleteMenu.setSort(999); |
|
105 |
deleteMenu.setLevels(2); |
|
106 |
deleteMenu.setMenuFlag("N"); |
|
107 |
deleteMenu.setSystemType("BASE_SYSTEM"); |
|
108 |
menuModels.add(deleteMenu); |
|
109 |
|
|
110 |
return menuModels; |
|
111 |
|
|
112 |
} |
|
113 |
} |