|
|
|
@ -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<Api> apiList;
|
|
|
|
|
private List<String> 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<String> domainList, List<Api> 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<String, Object> ctx = new HashMap<String, Object>();
|
|
|
|
|
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<String, Object> ctx = new HashMap<String, Object>();
|
|
|
|
|
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<String, Object> ctx = new HashMap<String, Object>();
|
|
|
|
|
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<String> modules = new HashSet<>();
|
|
|
|
|
for (Api api : apiList) {
|
|
|
|
|
modules.add(api.getModule());
|
|
|
|
|
}
|
|
|
|
|
for (String m : modules) {
|
|
|
|
|
|
|
|
|
|
ArrayList<Api> apis = new ArrayList<>();
|
|
|
|
|
for (Api api : apiList) {
|
|
|
|
|
if (m.equals(api.getModule())){
|
|
|
|
|
apis.add(api);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//生成Test
|
|
|
|
|
System.out.println("生成模块:Test");
|
|
|
|
|
HashMap<String, Object> ctx = new HashMap<String, Object>();
|
|
|
|
|
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<String> 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<File> 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() + "成功");
|
|
|
|
|