1
1
package tech .washmore .autocode .core .generator .mysql ;
2
2
3
3
import tech .washmore .autocode .core .config .ConfigManager ;
4
+ import tech .washmore .autocode .core .generator .base .AutoCodeFileWriter ;
4
5
import tech .washmore .autocode .model .Constants ;
5
6
import tech .washmore .autocode .model .config .*;
6
7
import tech .washmore .autocode .model .enums .DataFileMethod ;
@@ -48,17 +49,6 @@ private void generateServiceExtends(TableModel tm) throws IOException {
48
49
Doc doc = config .getDoc ();
49
50
Project project = config .getProject ();
50
51
51
- File dic = new File (project .getPath () + Constants .pathSplitor + project .getJavaRoot () + Constants .pathSplitor + service .getExtendsPackagePath ());
52
- if (!dic .exists ()) {
53
- dic .mkdirs ();
54
- }
55
-
56
- File file = new File (dic , tm .getClsName () + service .getSuffix () + ".java" );
57
- if (file .exists ()) {
58
- return ;
59
- }
60
- file .createNewFile ();
61
-
62
52
StringBuffer sb = new StringBuffer ("" );
63
53
sb .append ("package " ).append (service .getExtendsPackageName ()).append (";" ).append (System .lineSeparator ()).append (System .lineSeparator ());
64
54
sb .append ("import org.springframework.stereotype.Service;" ).append (System .lineSeparator ());
@@ -78,11 +68,11 @@ private void generateServiceExtends(TableModel tm) throws IOException {
78
68
.append (System .lineSeparator ());
79
69
sb .append ("}" );
80
70
81
- OutputStream ops = new FileOutputStream ( file );
82
- ops . write ( sb . toString (). getBytes ());
83
- ops . flush ();
84
- ops . close ();
85
- System . out . println ( " \t 输出文件:" + file . getPath (). replace ( new File ( config . getProject (). getPath ()). getPath (), "" ) );
71
+ AutoCodeFileWriter . writeStringToFile (
72
+ project . getPath () + Constants . pathSplitor + project . getJavaRoot ()
73
+ + Constants . pathSplitor + service . getExtendsPackagePath (),
74
+ tm . getClsName () + service . getSuffix () + ".java" , sb . toString (), false
75
+ );
86
76
}
87
77
88
78
private void generateService (TableModel tm ) throws IOException {
@@ -169,21 +159,12 @@ private void generateService(TableModel tm) throws IOException {
169
159
170
160
insertDependencies (sb , tm );
171
161
172
- File dic = new File (project .getPath () + Constants .pathSplitor + project .getJavaRoot () + Constants .pathSplitor + service .getBasePackagePath ());
173
- if (!dic .exists ()) {
174
- dic .mkdirs ();
175
- }
162
+ AutoCodeFileWriter .writeStringToFile (
163
+ project .getPath () + Constants .pathSplitor + project .getJavaRoot ()
164
+ + Constants .pathSplitor + service .getBasePackagePath (),
165
+ tm .getClsName () + service .getBaseSuffix () + ".java" , sb .toString (), true
166
+ );
176
167
177
- File file = new File (dic , tm .getClsName () + service .getBaseSuffix () + ".java" );
178
- if (file .exists ()) {
179
- file .delete ();
180
- }
181
- file .createNewFile ();
182
- OutputStream ops = new FileOutputStream (file );
183
- ops .write (sb .toString ().getBytes ());
184
- ops .flush ();
185
- ops .close ();
186
- System .out .println ("\t 输出文件:" + file .getPath ().replace (new File (config .getProject ().getPath ()).getPath (), "" ));
187
168
}
188
169
189
170
0 commit comments