diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java index dc1126cd..914878cf 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java @@ -2,8 +2,6 @@ package xyz.wbsite.dbtool.javafx.manger.callable; import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager; import xyz.wbsite.dbtool.javafx.manger.ManagerFactory; -import xyz.wbsite.dbtool.javafx.manger.ProjectManager; -import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper; import xyz.wbsite.dbtool.javafx.po.Api; import xyz.wbsite.dbtool.javafx.tool.EntityReader; import xyz.wbsite.dbtool.javafx.tool.RequestReader; @@ -15,6 +13,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.Callable; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -26,9 +25,10 @@ public class ApiCallable implements Callable { private List apiList; private List domainList; private Tool tool = new Tool(); - File domain; - File frame; - File testdomain; + File apiDomain; + File apiModule; + File apiFrame; + File testApiDomain; private FreeMarkerManager freeMarkerManager; public ApiCallable(File module, File apiFile, List domainList, List apiList) { @@ -46,9 +46,6 @@ public class ApiCallable implements Callable { Tool.clear(apiFile); } - AbstractDBmapper dBmapper = ProjectManager.dBmapper; - - StringBuffer sbmain = new StringBuffer(""); sbmain.append(this.apiFile.getPath() + File.separator); sbmain.append("src" + File.separator); @@ -66,22 +63,13 @@ public class ApiCallable implements Callable { sbtest.append(s1 + File.separator); } - domain = Tool.createPath(sbmain.toString(),"module"); - frame = Tool.createPath(sbmain.toString(),"frame"); - testdomain = new File(sbtest.toString()); - testdomain.mkdirs(); + apiDomain = Tool.createPath(sbmain.toString()); + apiModule = Tool.createPath(sbmain.toString(), "module"); + apiFrame = Tool.createPath(sbmain.toString(), "frame"); + testApiDomain = Tool.createPath(sbtest.toString()); for (Api api : apiList) { if (api.isCheck()) { - File apiModule = new File(domain, api.getModule()); - apiModule.mkdirs(); - File apiRequest = new File(apiModule, "req"); - apiRequest.mkdirs(); - File apiResponse = new File(apiModule, "rsp"); - apiResponse.mkdirs(); - File entity = new File(apiModule, "ent"); - entity.mkdirs(); - RequestReader requestReader = new RequestReader(api.getRequestFile()); generateRequest(requestReader); @@ -93,99 +81,124 @@ public class ApiCallable implements Callable { { System.out.println("生成模块:Pom"); HashMap ctx = new HashMap(); - ctx.put("module", apiFile.getName()); + ctx.put("domain", String.join(".", domainList)); + ctx.put("projectName", apiFile.getName()); File file = new File(apiFile, "pom.xml"); freeMarkerManager.outputTemp(file, "Java_api/pom.xml", ctx); } + { + HashMap ctx = new HashMap(); + ctx.put("domain", String.join(".", domainList)); + File file = new File(apiDomain, "ApiClient.java"); + freeMarkerManager.outputTemp(file, "/Java_api/ApiClient.java", ctx); + } + { System.out.println("生成基础类"); HashMap ctx = new HashMap(); ctx.put("domain", String.join(".", domainList)); { - File file = new File(frame, "ApiEntity.java"); - freeMarkerManager.outputTemp(file, "/Java_api/ApiEntity.java", ctx); - } - { - File file = new File(frame, "AESUtil.java"); - freeMarkerManager.outputTemp(file, "/Java_api/AESUtil.java", ctx); + File file = new File(apiFrame, "ApiEntity.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiEntity.java", ctx); } { - File file = new File(frame, "ApiClient.java"); - freeMarkerManager.outputTemp(file, "/Java_api/ApiClient.java", ctx); + File file = new File(apiFrame, "AESUtil.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/AESUtil.java", ctx); } { - File file = new File(frame, "ApiRequest.java"); - freeMarkerManager.outputTemp(file, "/Java_api/ApiRequest.java", ctx); + File file = new File(apiFrame, "ApiRequest.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiRequest.java", ctx); } { - File file = new File(frame, "ApiFindRequest.java"); - freeMarkerManager.outputTemp(file, "/Java_api/ApiFindRequest.java", ctx); + File file = new File(apiFrame, "ApiFindRequest.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiFindRequest.java", ctx); } { - File file = new File(frame, "ApiSearchRequest.java"); - freeMarkerManager.outputTemp(file, "/Java_api/ApiSearchRequest.java", ctx); + File file = new File(apiFrame, "ApiSearchRequest.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiSearchRequest.java", ctx); } { - File file = new File(frame, "ApiResponse.java"); - freeMarkerManager.outputTemp(file, "/Java_api/ApiResponse.java", ctx); + File file = new File(apiFrame, "ApiResponse.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiResponse.java", ctx); } { - File file = new File(frame, "ApiFindResponse.java"); - freeMarkerManager.outputTemp(file, "/Java_api/ApiFindResponse.java", ctx); + File file = new File(apiFrame, "ApiFindResponse.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/ApiFindResponse.java", ctx); } { - File file = new File(frame, "Base64Util.java"); - freeMarkerManager.outputTemp(file, "/Java_api/Base64Util.java", ctx); + File file = new File(apiFrame, "Base64Util.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/Base64Util.java", ctx); } { - File file = new File(frame, "DownloadUtil.java"); - freeMarkerManager.outputTemp(file, "/Java_api/DownloadUtil.java", ctx); + File file = new File(apiFrame, "DownloadUtil.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/DownloadUtil.java", ctx); } { - File file = new File(frame, "Error.java"); - freeMarkerManager.outputTemp(file, "/Java_api/Error.java", ctx); + File file = new File(apiFrame, "Error.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/Error.java", ctx); } { - File file = new File(frame, "ErrorType.java"); - freeMarkerManager.outputTemp(file, "/Java_api/ErrorType.java", ctx); + File file = new File(apiFrame, "ErrorType.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/ErrorType.java", ctx); } { - File file = new File(frame, "MapperUtil.java"); - freeMarkerManager.outputTemp(file, "/Java_api/MapperUtil.java", ctx); + File file = new File(apiFrame, "MapperUtil.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/MapperUtil.java", ctx); } { - File file = new File(frame, "MD5Util.java"); - freeMarkerManager.outputTemp(file, "/Java_api/MD5Util.java", ctx); + File file = new File(apiFrame, "MD5Util.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/MD5Util.java", ctx); } { - File file = new File(frame, "RSAUtil.java"); - freeMarkerManager.outputTemp(file, "/Java_api/RSAUtil.java", ctx); + File file = new File(apiFrame, "RSAUtil.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/RSAUtil.java", ctx); } { - File file = new File(frame, "ProgressRequestBody.java"); - freeMarkerManager.outputTemp(file, "/Java_api/ProgressRequestBody.java", ctx); + File file = new File(apiFrame, "ProgressRequestBody.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/ProgressRequestBody.java", ctx); } { - File file = new File(frame, "SortType.java"); - freeMarkerManager.outputTemp(file, "/Java_api/SortType.java", ctx); + File file = new File(apiFrame, "SortType.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/SortType.java", ctx); } { - File file = new File(frame, "StringUtils.java"); - freeMarkerManager.outputTemp(file, "/Java_api/StringUtils.java", ctx); + File file = new File(apiFrame, "StringUtils.java"); + freeMarkerManager.outputTemp(file, "/Java_api/frame/StringUtils.java", ctx); } //4.0.1 去掉验证 减少体积 // { // File file = new File(frameWork , "ValidationUtil.java"); -// freeMarkerManager.outputTemp(file, "/Java_api/ValidationUtil.java", ctx); +// freeMarkerManager.outputTemp(file, "/Java_api/frame/ValidationUtil.java", ctx); // } } - {//生成Test + generateTest(); + + System.out.println("finish"); + return true; + } + + + private void generateTest() { + Set modules = new HashSet<>(); + for (Api api : apiList) { + modules.add(api.getModule()); + } + for (String m : modules) { + + ArrayList apis = new ArrayList<>(); + for (Api api : apiList) { + if (m.equals(api.getModule())){ + apis.add(api); + } + } + + //生成Test System.out.println("生成模块:Test"); HashMap ctx = new HashMap(); ctx.put("tool", tool); @@ -195,13 +208,12 @@ public class ApiCallable implements Callable { for (Api api : apiList) { hashSet.add(api.getModule()); } - ctx.put("modules", hashSet); - ctx.put("apiList", apiList); - freeMarkerManager.outputTemp(new File(testdomain.getAbsolutePath(), "ApiTest.java"), "Java_api/ApiTest.java", ctx); + ctx.put("module", m); + ctx.put("apiList", apis); + ctx.put("className", Tool.abb2Abb(m) + "ApiTest"); + File api = Tool.createFile(testApiDomain.getAbsolutePath(), Tool.abb2Abb(m) + "ApiTest.java"); + freeMarkerManager.outputTemp(api, "Java_api/ApiTest.java", ctx); } - - System.out.println("finish"); - return true; } private void generateRequest(RequestReader reader) { @@ -217,7 +229,7 @@ public class ApiCallable implements Callable { List entNames = new ArrayList<>(); for (String entName : reader.getDeptEntList()) { - if (entName.matches("(.*\\.ent)\\.(.*)")){ + if (entName.matches("(.*\\.ent)\\.(.*)")) { Pattern compile = Pattern.compile("(.*\\.ent)\\.(.*)"); Matcher matcher = compile.matcher(entName); @@ -231,7 +243,7 @@ public class ApiCallable implements Callable { generateEntity(entReader); } } - }else { + } else { List files = Tool.findEntity(this.module, entName + ".java"); for (File file : files) { EntityReader entReader = new EntityReader(file); @@ -285,7 +297,7 @@ public class ApiCallable implements Callable { ctx.put("hasList", reader.isHasList()); ctx.put("findOrSearchflag", reader.getFindOrSearchflag()); - File req = Tool.createPath(domain.getAbsolutePath(), reader.getModuleName(), "req"); + File req = Tool.createPath(apiModule.getAbsolutePath(), reader.getModuleName(), "req"); File file = new File(req, reader.getClassName() + ".java"); freeMarkerManager.outputTemp(file, "Java_api/module/req/request.java", ctx); @@ -326,7 +338,7 @@ public class ApiCallable implements Callable { ctx.put("hasList", reader.isHasList()); ctx.put("Tclass", reader.getTclass()); - File rsp = Tool.createPath(domain.getAbsolutePath(), reader.getModuleName(), "rsp"); + File rsp = Tool.createPath(apiModule.getAbsolutePath(), reader.getModuleName(), "rsp"); File file = new File(rsp, reader.getClassName() + ".java"); freeMarkerManager.outputTemp(file, "Java_api/module/rsp/response.java", ctx); @@ -343,7 +355,7 @@ public class ApiCallable implements Callable { ctx.put("className", reader.getClassName()); ctx.put("body", reader.getBody()); ctx.put("tool", tool); - File ent = Tool.createPath(domain.getAbsolutePath(), reader.getModuleName(), "ent"); + File ent = Tool.createPath(apiModule.getAbsolutePath(), reader.getModuleName(), "ent"); File EntFile = new File(ent, reader.getClassName() + ".java"); freeMarkerManager.outputTemp(EntFile, "Java_api/module/ent/entity.java", ctx); System.out.println("生成文件" + reader.getClassName() + "成功"); diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Tool.java b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Tool.java index 78ce8b9d..c7933938 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Tool.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Tool.java @@ -1,8 +1,18 @@ package xyz.wbsite.dbtool.javafx.tool; -import java.io.*; +import java.io.File; +import java.io.FileFilter; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -460,6 +470,19 @@ public class Tool { return file; } + public static File createFile(String path, String fileName) { + File path1 = createPath(path); + File f = new File(path1, fileName); + if (!f.exists()) { + try { + f.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return f; + } + public static boolean hasChild(File file, String child) { if (file == null || child == null || "".equals(child) || file.listFiles() == null) { return false; diff --git a/src/main/resources/modules/Java_api/ApiClient.java b/src/main/resources/modules/Java_api/ApiClient.java index 940ae1c7..39061731 100644 --- a/src/main/resources/modules/Java_api/ApiClient.java +++ b/src/main/resources/modules/Java_api/ApiClient.java @@ -1,6 +1,17 @@ -package ${domain}.frame; - -import okhttp3.*; +package ${domain}; + +import ${domain}.frame.AESUtil; +import ${domain}.frame.ApiRequest; +import ${domain}.frame.ApiResponse; +import ${domain}.frame.ErrorType; +import ${domain}.frame.MD5Util; +import ${domain}.frame.MapperUtil; +import ${domain}.frame.ProgressRequestBody; +import okhttp3.MultipartBody; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; import java.io.IOException; import java.net.ConnectException; diff --git a/src/main/resources/modules/Java_api/ApiTest.java b/src/main/resources/modules/Java_api/ApiTest.java index 0811eebe..7f4a7254 100644 --- a/src/main/resources/modules/Java_api/ApiTest.java +++ b/src/main/resources/modules/Java_api/ApiTest.java @@ -1,8 +1,13 @@ package ${domain}; -<#list modules as module> -import ${domain}.module.${module}.req.*; -import ${domain}.module.${module}.rsp.*; +import ${domain}.frame.ApiRequest; +import ${domain}.frame.ApiResponse; +import ${domain}.frame.MapperUtil; +<#list apiList as item> +import ${domain}.module.${module}.req.${item.request}; + +<#list apiList as item> +import ${domain}.module.${module}.rsp.${item.response}; import org.junit.Assert; import org.junit.Before; @@ -18,7 +23,7 @@ import java.util.Date; * @version 0.0.1 * @since 2019-06-11 */ -public class ApiTest { +public class ${className} { private ApiClient apiClient; diff --git a/src/main/resources/modules/Java_api/AESUtil.java b/src/main/resources/modules/Java_api/frame/AESUtil.java similarity index 100% rename from src/main/resources/modules/Java_api/AESUtil.java rename to src/main/resources/modules/Java_api/frame/AESUtil.java diff --git a/src/main/resources/modules/Java_api/ApiEntity.java b/src/main/resources/modules/Java_api/frame/ApiEntity.java similarity index 100% rename from src/main/resources/modules/Java_api/ApiEntity.java rename to src/main/resources/modules/Java_api/frame/ApiEntity.java diff --git a/src/main/resources/modules/Java_api/ApiFindRequest.java b/src/main/resources/modules/Java_api/frame/ApiFindRequest.java similarity index 100% rename from src/main/resources/modules/Java_api/ApiFindRequest.java rename to src/main/resources/modules/Java_api/frame/ApiFindRequest.java diff --git a/src/main/resources/modules/Java_api/ApiFindResponse.java b/src/main/resources/modules/Java_api/frame/ApiFindResponse.java similarity index 100% rename from src/main/resources/modules/Java_api/ApiFindResponse.java rename to src/main/resources/modules/Java_api/frame/ApiFindResponse.java diff --git a/src/main/resources/modules/Java_api/ApiRequest.java b/src/main/resources/modules/Java_api/frame/ApiRequest.java similarity index 100% rename from src/main/resources/modules/Java_api/ApiRequest.java rename to src/main/resources/modules/Java_api/frame/ApiRequest.java diff --git a/src/main/resources/modules/Java_api/ApiResponse.java b/src/main/resources/modules/Java_api/frame/ApiResponse.java similarity index 100% rename from src/main/resources/modules/Java_api/ApiResponse.java rename to src/main/resources/modules/Java_api/frame/ApiResponse.java diff --git a/src/main/resources/modules/Java_api/ApiSearchRequest.java b/src/main/resources/modules/Java_api/frame/ApiSearchRequest.java similarity index 100% rename from src/main/resources/modules/Java_api/ApiSearchRequest.java rename to src/main/resources/modules/Java_api/frame/ApiSearchRequest.java diff --git a/src/main/resources/modules/Java_api/Base64Util.java b/src/main/resources/modules/Java_api/frame/Base64Util.java similarity index 100% rename from src/main/resources/modules/Java_api/Base64Util.java rename to src/main/resources/modules/Java_api/frame/Base64Util.java diff --git a/src/main/resources/modules/Java_api/DownloadUtil.java b/src/main/resources/modules/Java_api/frame/DownloadUtil.java similarity index 100% rename from src/main/resources/modules/Java_api/DownloadUtil.java rename to src/main/resources/modules/Java_api/frame/DownloadUtil.java diff --git a/src/main/resources/modules/Java_api/Error.java b/src/main/resources/modules/Java_api/frame/Error.java similarity index 100% rename from src/main/resources/modules/Java_api/Error.java rename to src/main/resources/modules/Java_api/frame/Error.java diff --git a/src/main/resources/modules/Java_api/ErrorType.java b/src/main/resources/modules/Java_api/frame/ErrorType.java similarity index 100% rename from src/main/resources/modules/Java_api/ErrorType.java rename to src/main/resources/modules/Java_api/frame/ErrorType.java diff --git a/src/main/resources/modules/Java_api/MD5Util.java b/src/main/resources/modules/Java_api/frame/MD5Util.java similarity index 100% rename from src/main/resources/modules/Java_api/MD5Util.java rename to src/main/resources/modules/Java_api/frame/MD5Util.java diff --git a/src/main/resources/modules/Java_api/Main.java b/src/main/resources/modules/Java_api/frame/Main.java similarity index 100% rename from src/main/resources/modules/Java_api/Main.java rename to src/main/resources/modules/Java_api/frame/Main.java diff --git a/src/main/resources/modules/Java_api/MapperUtil.java b/src/main/resources/modules/Java_api/frame/MapperUtil.java similarity index 100% rename from src/main/resources/modules/Java_api/MapperUtil.java rename to src/main/resources/modules/Java_api/frame/MapperUtil.java diff --git a/src/main/resources/modules/Java_api/ProgressRequestBody.java b/src/main/resources/modules/Java_api/frame/ProgressRequestBody.java similarity index 100% rename from src/main/resources/modules/Java_api/ProgressRequestBody.java rename to src/main/resources/modules/Java_api/frame/ProgressRequestBody.java diff --git a/src/main/resources/modules/Java_api/RSAUtil.java b/src/main/resources/modules/Java_api/frame/RSAUtil.java similarity index 100% rename from src/main/resources/modules/Java_api/RSAUtil.java rename to src/main/resources/modules/Java_api/frame/RSAUtil.java diff --git a/src/main/resources/modules/Java_api/SortType.java b/src/main/resources/modules/Java_api/frame/SortType.java similarity index 100% rename from src/main/resources/modules/Java_api/SortType.java rename to src/main/resources/modules/Java_api/frame/SortType.java diff --git a/src/main/resources/modules/Java_api/StringUtils.java b/src/main/resources/modules/Java_api/frame/StringUtils.java similarity index 100% rename from src/main/resources/modules/Java_api/StringUtils.java rename to src/main/resources/modules/Java_api/frame/StringUtils.java diff --git a/src/main/resources/modules/Java_api/ValidationUtil.java b/src/main/resources/modules/Java_api/frame/ValidationUtil.java similarity index 100% rename from src/main/resources/modules/Java_api/ValidationUtil.java rename to src/main/resources/modules/Java_api/frame/ValidationUtil.java diff --git a/src/main/resources/modules/Java_api/pom.ftl b/src/main/resources/modules/Java_api/pom.ftl deleted file mode 100644 index e46ccc78..00000000 --- a/src/main/resources/modules/Java_api/pom.ftl +++ /dev/null @@ -1,100 +0,0 @@ - - - 4.0.0 - - com.wb - ${api} - 1.0-SNAPSHOT - jar - - - true - - - - - com.fasterxml.jackson.core - jackson-databind - 2.9.6 - - - com.squareup.okhttp3 - okhttp - 3.4.1 - - - - junit - junit - 4.12 - - - <#-- - <#----> - <#--org.hibernate.validator--> - <#--hibernate-validator--> - <#--6.0.10.Final--> - <#----> - <#----> - <#--org.glassfish--> - <#--javax.el--> - <#--3.0.0--> - <#----> - - - - - ${r"${artifactId}"}-${r"${version}"} - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - UTF-8 - - - - org.apache.maven.plugins - maven-dependency-plugin - 2.7 - - - copy-dependencies - prepare-package - - copy-dependencies - - - - ${r"${project.build.directory}"}/lib - - false - - false - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - - true - lib/ - com.example.ApiClient - - - - - - - \ No newline at end of file diff --git a/src/main/resources/modules/Java_api/pom.xml b/src/main/resources/modules/Java_api/pom.xml index 7337de67..632797a5 100644 --- a/src/main/resources/modules/Java_api/pom.xml +++ b/src/main/resources/modules/Java_api/pom.xml @@ -4,8 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.wb - ${module} + ${domain} + ${projectName} 1.0-SNAPSHOT jar @@ -31,17 +31,17 @@ 4.12 - <#-- - <#----> - <#--org.hibernate.validator--> - <#--hibernate-validator--> - <#--6.0.10.Final--> - <#----> - <#----> - <#--org.glassfish--> - <#--javax.el--> - <#--3.0.0--> - <#----> + + + + + + + + + + +