commit | author | age
|
9bcb19
|
1 |
/* |
I |
2 |
Copyright [2020] [https://www.xiaonuo.vip] |
|
3 |
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
you may not use this file except in compliance with the License. |
|
6 |
You may obtain a copy of the License at |
|
7 |
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
|
|
10 |
Unless required by applicable law or agreed to in writing, software |
|
11 |
distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
See the License for the specific language governing permissions and |
|
14 |
limitations under the License. |
|
15 |
|
|
16 |
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: |
|
17 |
|
|
18 |
1.请不要删除和修改根目录下的LICENSE文件。 |
|
19 |
2.请不要删除和修改Snowy源码头部的版权声明。 |
|
20 |
3.请保留源码和相关描述文件的项目出处,作者声明等。 |
|
21 |
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
22 |
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
23 |
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip |
|
24 |
*/ |
|
25 |
package vip.xiaonuo.generate.core.context; |
|
26 |
|
|
27 |
import org.apache.velocity.VelocityContext; |
|
28 |
import vip.xiaonuo.core.enums.YesOrNotEnum; |
|
29 |
import vip.xiaonuo.generate.core.param.XnCodeGenParam; |
|
30 |
import vip.xiaonuo.generate.modular.entity.SysCodeGenerateConfig; |
|
31 |
|
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.List; |
|
34 |
import java.util.UUID; |
|
35 |
|
|
36 |
/** |
|
37 |
* 设置上下文缓存 |
|
38 |
* |
|
39 |
* @author yubaoshan |
|
40 |
* @date 2020年12月17日02:04:56 |
|
41 |
*/ |
|
42 |
public class XnVelocityContext { |
|
43 |
|
|
44 |
/** |
|
45 |
* 创建上下文用到的参数 |
|
46 |
* |
|
47 |
* @author yubaoshan |
|
48 |
* @date 2020年12月17日02:04:56 |
|
49 |
*/ |
|
50 |
public VelocityContext createVelContext (XnCodeGenParam xnCodeGenParam) { |
|
51 |
VelocityContext velocityContext = new VelocityContext(); |
|
52 |
// 取得类名 |
|
53 |
String DomainName = xnCodeGenParam.getClassName(); |
|
54 |
String domainName = DomainName.substring(0,1).toLowerCase()+DomainName.substring(1); |
|
55 |
// 类名称 |
|
56 |
velocityContext.put("ClassName",DomainName); |
|
57 |
// 类名(首字母小写) |
|
58 |
velocityContext.put("className",domainName); |
|
59 |
|
|
60 |
// 功能名 |
|
61 |
velocityContext.put("functionName",xnCodeGenParam.getFunctionName()); |
|
62 |
|
|
63 |
// 包名称 |
|
64 |
velocityContext.put("packageName",xnCodeGenParam.getPackageName()); |
|
65 |
// 模块名称 |
|
66 |
velocityContext.put("modularName",xnCodeGenParam.getModularNane()); |
|
67 |
// 业务名 |
|
68 |
velocityContext.put("busName",xnCodeGenParam.getBusName()); |
|
69 |
|
|
70 |
// 作者姓名 |
|
71 |
velocityContext.put("authorName", xnCodeGenParam.getAuthorName()); |
|
72 |
// 代码生成时间 |
|
73 |
velocityContext.put("createDateString", xnCodeGenParam.getCreateTimeString()); |
|
74 |
|
|
75 |
// 数据库表名 |
|
76 |
velocityContext.put("tableName", xnCodeGenParam.getTableName()); |
|
77 |
// 数据库字段 |
|
78 |
velocityContext.put("tableField", xnCodeGenParam.getConfigList()); |
|
79 |
|
|
80 |
// 前端查询所有 |
|
81 |
List<SysCodeGenerateConfig> codeGenerateConfigList = new ArrayList<>(); |
|
82 |
xnCodeGenParam.getConfigList().forEach(item -> { |
|
83 |
if (item.getQueryWhether().equals(YesOrNotEnum.Y.getCode())) { |
|
84 |
codeGenerateConfigList.add(item); |
|
85 |
} |
|
86 |
}); |
|
87 |
velocityContext.put("queryWhetherList", codeGenerateConfigList); |
|
88 |
|
|
89 |
velocityContext.put("appCode", xnCodeGenParam.getAppCode()); |
|
90 |
|
|
91 |
velocityContext.put("menuPids", xnCodeGenParam.getMenuPids() + "[" + xnCodeGenParam.getMenuPid() + "],"); |
|
92 |
|
|
93 |
// sql中id的创建 |
|
94 |
List<Long> idList = new ArrayList<>(); |
|
95 |
for (int a = 0; a <= 7; a++) { |
|
96 |
idList.add(Math.abs(UUID.randomUUID().getLeastSignificantBits())); |
|
97 |
} |
|
98 |
velocityContext.put("sqlMenuId", idList); |
|
99 |
|
|
100 |
return velocityContext; |
|
101 |
} |
|
102 |
} |