From 2b0e781112c68ac28b26554d0f729f05cd53694e Mon Sep 17 00:00:00 2001 From: wangbing Date: Tue, 11 Jun 2019 10:51:25 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dbtool/javafx/ctrl/MainController.java | 4 + .../javafx/ctrl/OptionApiController.java | 16 ++-- .../dbtool/javafx/manger/ProjectManager.java | 40 ++++++++-- .../{SDKCallable.java => ApiCallable.java} | 44 +++++------ .../javafx/manger/callable/SBMDBCallable.java | 43 +++++++++++ .../wbsite/dbtool/javafx/po/SBMDBOption.java | 4 + .../xyz/wbsite/dbtool/javafx/tool/Dialog.java | 71 ++++++++++++++---- src/main/resources/fxml/apiOption.fxml | 4 +- src/main/resources/fxml/main.fxml | 1 + src/main/resources/fxml/sdkInfo.fxml | 2 +- src/main/resources/modules/Java_api/Main.ftl | 4 +- src/main/resources/modules/Java_api/pom.ftl | 2 +- .../SpringBootMDB.zip} | Bin 5720 -> 5766 bytes 13 files changed, 176 insertions(+), 59 deletions(-) rename src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/{SDKCallable.java => ApiCallable.java} (96%) create mode 100644 src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SBMDBCallable.java create mode 100644 src/main/java/xyz/wbsite/dbtool/javafx/po/SBMDBOption.java rename src/main/resources/modules/{SpringBoot/resources/MultiDatabase.zip => SpringBootMDB/SpringBootMDB.zip} (75%) diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java index 8999e4c3..8815286d 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/MainController.java @@ -211,4 +211,8 @@ public class MainController { public void generateAndroid(ActionEvent actionEvent) { Dialog.showAndroid(); } + @FXML + public void generateSBMDB(ActionEvent actionEvent) { + Dialog.showSBMDB(); + } } diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/OptionApiController.java b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/OptionApiController.java index 5723dbec..8b23ecf7 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/OptionApiController.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/ctrl/OptionApiController.java @@ -27,11 +27,11 @@ public class OptionApiController { @FXML private TextField modulePath; @FXML - private TextField sdkPath; + private TextField apiPath; @FXML private Button selectModulePath; @FXML - private Button selectSdkPath; + private Button selectApiPath; @FXML private Button start; @FXML @@ -68,11 +68,11 @@ public class OptionApiController { } public Button getSelectSdkPath() { - return selectSdkPath; + return selectApiPath; } public void setSelectSdkPath(Button selectSdkPath) { - this.selectSdkPath = selectSdkPath; + this.selectApiPath = selectSdkPath; } public List getData() { @@ -155,12 +155,12 @@ public class OptionApiController { this.modulePath = modulePath; } - public TextField getSdkPath() { - return sdkPath; + public TextField getApiPath() { + return apiPath; } - public void setSdkPath(TextField sdkPath) { - this.sdkPath = sdkPath; + public void setApiPath(TextField apiPath) { + this.apiPath = apiPath; } public Button getStart() { diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java index 9bc24d69..98425cd6 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/ProjectManager.java @@ -266,24 +266,24 @@ public class ProjectManager { e.printStackTrace(); } Dialog.stopPopup(); - Dialog.showSuccess("生成完成."); + Dialog.showSuccess("生成完毕."); } }.start(); } - public void generateApi(File module, File sdk, List apis) { + public void generateApi(File module, File api, List apis) { if (module.exists()) { Dialog.showProgress("生成中..."); new Thread() { @Override public void run() { - boolean mkdirs = sdk.mkdirs(); + boolean mkdirs = api.mkdirs(); File reqList = new File(module, "req"); File rspList = new File(module, "rsp"); File entList = new File(module, "ent"); File enumsList = new File(module, "enums"); - SDKCallable sdkCallable = new SDKCallable(sdk, reqList, rspList, entList, enumsList, apis); - Future submit = service.submit(sdkCallable); + ApiCallable apiCallable = new ApiCallable(api, reqList, rspList, entList, enumsList, apis); + Future submit = service.submit(apiCallable); try { Boolean b = (Boolean) submit.get(); if (!b) { @@ -296,7 +296,7 @@ public class ProjectManager { } Dialog.stopPopup(); - Dialog.showSuccess("Api生成完成."); + Dialog.showSuccess("Api生成完毕."); } }.start(); } @@ -321,7 +321,7 @@ public class ProjectManager { } Dialog.stopPopup(); - Dialog.showSuccess("Android生成完成."); + Dialog.showSuccess("Android生成完毕."); } }.start(); } @@ -345,7 +345,31 @@ public class ProjectManager { } Dialog.stopPopup(); - Dialog.showSuccess("Vue生成完成."); + Dialog.showSuccess("Vue生成完毕."); + } + }.start(); + } + + public void generate(final String path, SBMDBOption option) { + Dialog.showProgress("生成中..."); + new Thread() { + @Override + public void run() { + SBMDBCallable callable = new SBMDBCallable(path, option); + Future submit = service.submit(callable); + try { + Boolean b = (Boolean) submit.get(); + if (!b) { + Dialog.showError("请确认目录结构是否存在或正确!"); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + + Dialog.stopPopup(); + Dialog.showSuccess("生成完毕."); } }.start(); } diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SDKCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java similarity index 96% rename from src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SDKCallable.java rename to src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java index 5b929ba3..d771cec7 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SDKCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java @@ -14,9 +14,9 @@ import java.io.IOException; import java.util.*; import java.util.concurrent.Callable; -public class SDKCallable implements Callable { +public class ApiCallable implements Callable { - private File sdk; + private File api; private File req; private File rsp; private File ent; @@ -26,8 +26,8 @@ public class SDKCallable implements Callable { private FreeMarkerManager freeMarkerManager; - public SDKCallable(File sdk, File req, File rsp, File ent, File enums, List apis) { - this.sdk = sdk; + public ApiCallable(File api, File req, File rsp, File ent, File enums, List apis) { + this.api = api; this.req = req; this.rsp = rsp; this.ent = ent; @@ -39,10 +39,10 @@ public class SDKCallable implements Callable { private AbstractDBmapper dBmapper; public Boolean call() throws Exception { - if (!sdk.exists()) { - sdk.mkdir(); + if (!api.exists()) { + api.mkdir(); } else { - Tool.clear(sdk); + Tool.clear(api); } dBmapper = ProjectManager.dBmapper; @@ -50,8 +50,8 @@ public class SDKCallable implements Callable { { System.out.println("生成模块:Pom"); HashMap ctx = new HashMap(); - ctx.put("sdk", sdk.getName().toLowerCase()); - File file = new File(sdk, "pom.xml"); + ctx.put("api", api.getName().toLowerCase()); + File file = new File(api, "pom.xml"); freeMarkerManager.outputTemp(file, "Java_api/pom.ftl", ctx); } @@ -76,7 +76,7 @@ public class SDKCallable implements Callable { method.setManager(Tool.getRequestTarget(javaClassReader.getClassName()) + "Manager"); methodList.add(method); StringBuffer stringBuffer = new StringBuffer(""); - stringBuffer.append(sdk.getPath() + File.separator); + stringBuffer.append(this.api.getPath() + File.separator); stringBuffer.append("src" + File.separator); stringBuffer.append("main" + File.separator); stringBuffer.append("java" + File.separator); @@ -132,7 +132,7 @@ public class SDKCallable implements Callable { JavaClassReader javaClassReader = new JavaClassReader(api.getRsp()); StringBuffer stringBuffer = new StringBuffer(""); - stringBuffer.append(sdk.getPath() + File.separator); + stringBuffer.append(this.api.getPath() + File.separator); stringBuffer.append("src" + File.separator); stringBuffer.append("main" + File.separator); stringBuffer.append("java" + File.separator); @@ -188,7 +188,7 @@ public class SDKCallable implements Callable { method.setManager(Tool.getRequestTarget(javaClassReader.getClassName()) + "Manager"); StringBuffer stringBuffer = new StringBuffer(""); - stringBuffer.append(sdk.getPath() + File.separator); + stringBuffer.append(this.api.getPath() + File.separator); stringBuffer.append("src" + File.separator); stringBuffer.append("main" + File.separator); stringBuffer.append("java" + File.separator); @@ -244,7 +244,7 @@ public class SDKCallable implements Callable { JavaClassReader javaClassReader = new JavaClassReader(f); StringBuffer stringBuffer = new StringBuffer(""); - stringBuffer.append(sdk.getPath() + File.separator); + stringBuffer.append(this.api.getPath() + File.separator); stringBuffer.append("src" + File.separator); stringBuffer.append("main" + File.separator); stringBuffer.append("java" + File.separator); @@ -295,7 +295,7 @@ public class SDKCallable implements Callable { JavaClassReader javaClassReader = new JavaClassReader(f); StringBuffer stringBuffer = new StringBuffer(""); - stringBuffer.append(sdk.getPath() + File.separator); + stringBuffer.append(this.api.getPath() + File.separator); stringBuffer.append("src" + File.separator); stringBuffer.append("main" + File.separator); stringBuffer.append("java" + File.separator); @@ -342,7 +342,7 @@ public class SDKCallable implements Callable { JavaEnumReader javaEnumReader = new JavaEnumReader(f); StringBuffer stringBuffer = new StringBuffer(""); - stringBuffer.append(sdk.getPath() + File.separator); + stringBuffer.append(this.api.getPath() + File.separator); stringBuffer.append("src" + File.separator); stringBuffer.append("main" + File.separator); stringBuffer.append("java" + File.separator); @@ -399,7 +399,7 @@ public class SDKCallable implements Callable { // method.setManager(Tool.getRequestTarget(javaClassReader.getClassName()) + "Manager"); // methodList.add(method); // StringBuffer stringBuffer = new StringBuffer(""); -// stringBuffer.append(sdk.getPath() + File.separator); +// stringBuffer.append(api.getPath() + File.separator); // stringBuffer.append("src" + File.separator); // stringBuffer.append("main" + File.separator); // stringBuffer.append("java" + File.separator); @@ -454,7 +454,7 @@ public class SDKCallable implements Callable { // JavaClassReader javaClassReader = new JavaClassReader(r); // // StringBuffer stringBuffer = new StringBuffer(""); -// stringBuffer.append(sdk.getPath() + File.separator); +// stringBuffer.append(api.getPath() + File.separator); // stringBuffer.append("src" + File.separator); // stringBuffer.append("main" + File.separator); // stringBuffer.append("java" + File.separator); @@ -501,7 +501,7 @@ public class SDKCallable implements Callable { // managerList.add(javaClassReader.getClassName() + "Manager"); // // StringBuffer stringBuffer = new StringBuffer(""); -// stringBuffer.append(sdk.getPath() + File.separator); +// stringBuffer.append(api.getPath() + File.separator); // stringBuffer.append("src" + File.separator); // stringBuffer.append("main" + File.separator); // stringBuffer.append("java" + File.separator); @@ -549,7 +549,7 @@ public class SDKCallable implements Callable { // JavaEnumReader javaEnumReader = new JavaEnumReader(f); // // StringBuffer stringBuffer = new StringBuffer(""); -// stringBuffer.append(sdk.getPath() + File.separator); +// stringBuffer.append(api.getPath() + File.separator); // stringBuffer.append("src" + File.separator); // stringBuffer.append("main" + File.separator); // stringBuffer.append("java" + File.separator); @@ -589,15 +589,15 @@ public class SDKCallable implements Callable { // } { - System.out.println("生成模块:OptionApiController"); + System.out.println("生成模块:ApiController"); HashMap ctx = new HashMap(); ctx.put("tool", tool); ctx.put("domain", domain); ctx.put("module", module); ctx.put("managerList", managerList); ctx.put("methodList", methodList); - File file = new File(frameWork.getAbsolutePath() + File.separator + module + File.separator + "OptionApiController.java"); - freeMarkerManager.outputTemp(file, "Java_api/module/controller/OptionApiController.ftl", ctx); + File file = new File(frameWork.getAbsolutePath() + File.separator + module + File.separator + "ApiController.java"); + freeMarkerManager.outputTemp(file, "Java_api/module/controller/ApiController.ftl", ctx); } System.out.println("生成基础类"); diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SBMDBCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SBMDBCallable.java new file mode 100644 index 00000000..da3f0237 --- /dev/null +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SBMDBCallable.java @@ -0,0 +1,43 @@ +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.po.SBMDBOption; +import xyz.wbsite.dbtool.javafx.tool.Tool; +import xyz.wbsite.dbtool.javafx.tool.ZipUtil; + +import javax.validation.constraints.NotNull; +import java.io.File; +import java.util.concurrent.Callable; + +public class SBMDBCallable implements Callable { + + private String path; + private SBMDBOption option; + + private FreeMarkerManager freeMarkerManager; + + public SBMDBCallable(@NotNull String path, SBMDBOption option) { + this.path = path; + this.option = option; + this.freeMarkerManager = ManagerFactory.getFreeMarkerManager(); + } + + public Boolean call() throws Exception { + // 文件输出文件 + File zipFile = new File(path, "SpringBootMDB.zip"); + // 文件输出目录 + File dir = new File(path, "SpringBootMDB"); + // 清空输出目录 + Tool.clear(dir); + System.out.println("清空文件" + dir.getAbsolutePath()); + // 输出文件 + Tool.outputResource("SpringBootMDB/SpringBootMDB.zip", zipFile); + // 解压文件 + new ZipUtil().unZip(zipFile, new File(path)); + // 删除文件 + zipFile.delete(); + System.out.println("删除文件" + zipFile.getAbsolutePath()); + return true; + } +} diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/po/SBMDBOption.java b/src/main/java/xyz/wbsite/dbtool/javafx/po/SBMDBOption.java new file mode 100644 index 00000000..d5825d5c --- /dev/null +++ b/src/main/java/xyz/wbsite/dbtool/javafx/po/SBMDBOption.java @@ -0,0 +1,4 @@ +package xyz.wbsite.dbtool.javafx.po; + +public class SBMDBOption { +} diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java index c15abdb5..147e9825 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Dialog.java @@ -24,15 +24,14 @@ import xyz.wbsite.dbtool.javafx.enums.DataBase; import xyz.wbsite.dbtool.javafx.listener.GenerateOptionListener; import xyz.wbsite.dbtool.javafx.manger.ManagerFactory; import xyz.wbsite.dbtool.javafx.manger.ProjectManager; -import xyz.wbsite.dbtool.javafx.po.AndroidOption; -import xyz.wbsite.dbtool.javafx.po.Api; -import xyz.wbsite.dbtool.javafx.po.Module; -import xyz.wbsite.dbtool.javafx.po.VueOption; +import xyz.wbsite.dbtool.javafx.po.*; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class Dialog { @@ -388,7 +387,7 @@ public class Dialog { OptionApiController controller = dbdetailloader.getController(); TextField modulePath = controller.getModulePath(); - TextField sdkPath = controller.getSdkPath(); + TextField apiPath = controller.getApiPath(); TableView apis = controller.getApis(); controller.getSelectModulePath().setOnAction(new EventHandler() { @@ -404,11 +403,18 @@ public class Dialog { } modulePath.setText(file.getAbsolutePath()); + String absolutePath = file.getAbsolutePath(); - File api = new File(sdkPath.getText()); - sdkPath.setText(new File(api.getParentFile().getAbsolutePath(), file.getName() + "-api").getAbsolutePath()); - - + String s = absolutePath.replaceAll(File.separator, "#"); + Pattern compile = Pattern.compile("#project#(.*)#src#main#java#"); + Matcher matcher = compile.matcher(s); + File api = new File(apiPath.getText()); + if (!matcher.find()) { + apiPath.setText(new File(api.getParentFile().getAbsolutePath(), "api").getAbsolutePath()); + } else { + String group = matcher.group(1); + apiPath.setText(new File(api.getParentFile().getAbsolutePath(), group + "-api").getAbsolutePath()); + } System.out.println(file.getAbsolutePath()); } }); @@ -426,7 +432,7 @@ public class Dialog { String text = modulePath.getText(); File moduleFile = new File(text); - sdkPath.setText(new File(file.getAbsolutePath(), moduleFile.getName() + "-api").getAbsolutePath()); + apiPath.setText(new File(file.getAbsolutePath(), moduleFile.getName() + "-api").getAbsolutePath()); System.out.println(file.getAbsolutePath()); } }); @@ -486,7 +492,7 @@ public class Dialog { } }); - sdkPath.requestFocus(); + apiPath.requestFocus(); modulePath.textProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, String oldValue, String newValue) { @@ -504,10 +510,25 @@ public class Dialog { File modul = findModul(f); if (modul == null) { modulePath.setText(""); - sdkPath.setText(""); + apiPath.setText(""); } else { modulePath.setText(modul.getAbsolutePath()); - sdkPath.setText(new File(f.getParentFile().getAbsolutePath(), modul.getName() + "-api").getAbsolutePath()); + + + String projectName = ""; + // 尝试查找Windows下的项目名称 + String path = modul.getAbsolutePath(); + String pathReplace = path.replaceAll("\\\\", "#"); + if (pathReplace.equals(path)) { + pathReplace = path.replaceAll("/", "#"); + } + Pattern compile = Pattern.compile("#project#(.*)#src#main#java#"); + Matcher matcher = compile.matcher(pathReplace); + if (matcher.find()) { + projectName = matcher.group(1); + } + + apiPath.setText(new File(ProjectManager.getPath(), projectName + "-api").getAbsolutePath()); break s; } @@ -519,11 +540,11 @@ public class Dialog { @Override public void handle(ActionEvent event) { String module = controller.getModulePath().getText(); - String sdk = controller.getSdkPath().getText(); + String api = controller.getApiPath().getText(); if (new File(module).exists()) { Dialog.showProgress("生成中..."); - dBmanger.generateApi(new File(module), new File(sdk), controller.getData()); + dBmanger.generateApi(new File(module), new File(api), controller.getData()); Dialog.stopPopup(); Platform.runLater(new Runnable() { @Override @@ -609,6 +630,26 @@ public class Dialog { popup.show(); } + public static void showSBMDB() { + ProjectManager dBmanger = ManagerFactory.getdBManager(); + DirectoryChooser directoryChooser = new DirectoryChooser(); + directoryChooser.setInitialDirectory(dBmanger.getPath()); + Stage stage = new Stage(); + File file = directoryChooser.showDialog(stage); + if (file != null) { + System.out.println("生成目录:" + file.getAbsolutePath()); + SBMDBOption option = new SBMDBOption(); + + dBmanger.generate(file.getAbsolutePath(), option); + Platform.runLater(new Runnable() { + @Override + public void run() { + stage.close(); + } + }); + } + } + public static void showVue() { FXMLLoader dbdetailloader = new FXMLLoader(Application.class.getResource("../../../fxml/vueOption.fxml")); try { diff --git a/src/main/resources/fxml/apiOption.fxml b/src/main/resources/fxml/apiOption.fxml index d29fde74..22961aae 100644 --- a/src/main/resources/fxml/apiOption.fxml +++ b/src/main/resources/fxml/apiOption.fxml @@ -23,10 +23,10 @@ GridPane.valignment="CENTER"/>