9
9
import com .tml .otowbackend .engine .generator .engine .VelocityCodeEngine ;
10
10
import com .tml .otowbackend .engine .generator .template .VelocityOTOWTemplate ;
11
11
import com .tml .otowbackend .engine .generator .template .java .model .EntityTemplate ;
12
+ import com .tml .otowbackend .engine .generator .template .java .model .ReqTemplate ;
13
+ import com .tml .otowbackend .engine .generator .template .java .model .VOTemplate ;
12
14
import com .tml .otowbackend .engine .generator .template .java .service .ControllerTemplate ;
13
15
import com .tml .otowbackend .engine .generator .template .java .service .MapperTemplate ;
14
16
import com .tml .otowbackend .engine .generator .template .java .service .ServiceImplTemplate ;
15
17
import com .tml .otowbackend .engine .generator .template .java .service .ServiceTemplate ;
16
18
import com .tml .otowbackend .engine .generator .template .meta .MetaAnnotation ;
17
- import com .tml .otowbackend .engine .generator .template .meta .MetaMethodParam ;
18
19
import com .tml .otowbackend .engine .generator .template .meta .MetalField ;
19
20
import lombok .NoArgsConstructor ;
20
21
27
28
@ NoArgsConstructor
28
29
public class InitTemplate {
29
30
30
- public static final String entityPackagePath = "io.github.geniusay.velocity.generate" ;
31
- public static final String servicePackagePath = "io.github.geniusay.velocity.generate.service" ;
32
- public static final String reqPackagePath = "io.github.geniusay.velocity.generate.pojo.req" ;
33
- public static final String mapperPackagePath = "io.github.geniusay.velocity.generate.mapper" ;
34
- public static final String serviceImplPackagePath = "io.github.geniusay.velocity.generate.service.impl" ;
31
+ public static String entityPackagePath = "model.entity" ;
32
+ public static String controllerPackagePath = "controller" ;
33
+ public static String servicePackagePath = "service" ;
34
+ public static String reqPackagePath = "model.req" ;
35
+ public static String voPackagePath = "model.vo" ;
36
+ public static String mapperPackagePath = "mapper" ;
37
+ public static String serviceImplPackagePath = "service.impl" ;
35
38
36
39
public static VelocityCodeEngine engine = VelocityCodeEngine .getCodeEngine ();
37
40
41
+
42
+ public String prefix ;
38
43
public FuncPackManager funcPackManager ;
39
44
public String className ;
40
45
public String tableName ;
41
46
public String describe ;
42
- public LinkedList <MetalField > fields ;
47
+ public LinkedList <MetalField > fields = new LinkedList <>();
48
+ public LinkedList <MetalField > fieldsVO = new LinkedList <>();
49
+ public LinkedList <MetalField > fieldsReq = new LinkedList <>();
43
50
public List <String > featureIds ;
44
51
45
52
private ServiceTemplate serviceTemplate ;
46
53
private ControllerTemplate controllerTemplate ;
47
54
private ServiceImplTemplate serviceImplTemplate ;
48
55
private MapperTemplate mapperTemplate ;
49
56
private EntityTemplate entityTemplate ;
50
-
51
- public InitTemplate (FuncPackManager funcPackManager , String className , String tableName , String describe , LinkedList <MetalField > fields , List <String > featureIds ) {
57
+ private ReqTemplate entityReqTemplate ;
58
+ private VOTemplate entityVOTemplate ;
59
+
60
+ public InitTemplate (String prefix , FuncPackManager funcPackManager , String className , String tableName , String describe , LinkedList <MetalField > fields , List <String > featureIds ) {
61
+ this .prefix = prefix ;
62
+ this .entityPackagePath = prefix + entityPackagePath ;
63
+ this .servicePackagePath = prefix + servicePackagePath ;
64
+ this .reqPackagePath = prefix + reqPackagePath ;
65
+ this .voPackagePath = prefix + voPackagePath ;
66
+ this .mapperPackagePath = prefix + mapperPackagePath ;
67
+ this .serviceImplPackagePath = prefix + serviceImplPackagePath ;
68
+ this .controllerPackagePath = prefix + controllerPackagePath ;
52
69
this .funcPackManager = funcPackManager ;
53
70
this .className = className ;
54
71
this .tableName = tableName ;
@@ -58,8 +75,16 @@ public InitTemplate(FuncPackManager funcPackManager, String className, String ta
58
75
}
59
76
60
77
public void initTemplate () {
78
+ // 将属性添加到新集合中 给req、VO使用
79
+ for (MetalField field : fields ) {
80
+ MetalField clone = field .getClone ();
81
+ fieldsReq .add (clone );
82
+ fieldsVO .add (clone );
83
+ }
61
84
judgeMetalField ();
62
85
entityTemplate = getEntityTemplate ();
86
+ entityReqTemplate = getEntityReqTemplate ();
87
+ entityVOTemplate = getEntityVOTemplate ();
63
88
mapperTemplate = getMapperTemplate ();
64
89
serviceTemplate = getServiceTemplate ();
65
90
serviceImplTemplate = getServiceImplTemplate ();
@@ -73,6 +98,12 @@ private String generateStringWithTemplate(VelocityOTOWTemplate template) {
73
98
public String generateEntity () {
74
99
return generateStringWithTemplate (entityTemplate );
75
100
}
101
+ public String generateEntityReq (){
102
+ return generateStringWithTemplate (entityReqTemplate );
103
+ }
104
+ public String generateEntityVO (){
105
+ return generateStringWithTemplate (entityVOTemplate );
106
+ }
76
107
77
108
public String generateMapper () {
78
109
return generateStringWithTemplate (mapperTemplate );
@@ -97,16 +128,29 @@ private EntityTemplate getEntityTemplate() {
97
128
return entityTemplate ;
98
129
}
99
130
131
+ // 根据给定的实体类名、字段生成实体Req模板
132
+ private ReqTemplate getEntityReqTemplate () {
133
+ ReqTemplate reqTemplate = new ReqTemplate (reqPackagePath ,className );
134
+ reqTemplate .addModelFields (fieldsReq );
135
+ return reqTemplate ;
136
+ }
137
+
138
+ // 根据给定的实体类名、字段生成实体VO模板
139
+ private VOTemplate getEntityVOTemplate () {
140
+ VOTemplate voTemplate = new VOTemplate (voPackagePath ,className );
141
+ voTemplate .addModelFields (fieldsVO );
142
+ return voTemplate ;
143
+ }
144
+
100
145
private MapperTemplate getMapperTemplate () {
101
146
return new MapperTemplate (mapperPackagePath , className , entityTemplate );
102
147
}
103
148
104
149
private ServiceTemplate getServiceTemplate () {
105
150
ServiceTemplate userService = new ServiceTemplate (servicePackagePath , className );
106
- MetaMethodParam metaMethodParam = new MetaMethodParam (className , userService .getAllPackagePath (), className .toLowerCase ());
107
151
for (String featureId : featureIds ) {
108
152
AbstrateFunctionPack pack = funcPackManager .getFunctionPackById (featureId );
109
- pack .addParams ("metaMethodParam " , metaMethodParam );
153
+ pack .addParams ("className " , className );
110
154
pack .generateService (userService );
111
155
}
112
156
return userService ;
@@ -124,9 +168,9 @@ private ServiceImplTemplate getServiceImplTemplate() {
124
168
}
125
169
126
170
private ControllerTemplate getControllerTemplate () {
127
- ControllerTemplate userController = new ControllerTemplate (entityPackagePath , className , "/" + className .toLowerCase ());
171
+ ControllerTemplate userController = new ControllerTemplate (controllerPackagePath , className , "/" + className .toLowerCase ());
128
172
userController .addService (serviceTemplate );
129
- String classLower = serviceTemplate .getClassName (). toLowerCase ( );
173
+ String classLower = StringUtils . firstToLowerCase ( serviceTemplate .getClassName ());
130
174
for (String featureId : featureIds ) {
131
175
AbstrateFunctionPack pack = funcPackManager .getFunctionPackById (featureId );
132
176
pack .addParams ("className" , className );
0 commit comments