master
王兵 6 years ago
parent 34d785da53
commit 2b0e781112

@ -211,4 +211,8 @@ public class MainController {
public void generateAndroid(ActionEvent actionEvent) {
Dialog.showAndroid();
}
@FXML
public void generateSBMDB(ActionEvent actionEvent) {
Dialog.showSBMDB();
}
}

@ -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<Api> 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() {

@ -266,24 +266,24 @@ public class ProjectManager {
e.printStackTrace();
}
Dialog.stopPopup();
Dialog.showSuccess("生成完.");
Dialog.showSuccess("生成完.");
}
}.start();
}
public void generateApi(File module, File sdk, List<Api> apis) {
public void generateApi(File module, File api, List<Api> 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();
}

@ -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<Api> apis) {
this.sdk = sdk;
public ApiCallable(File api, File req, File rsp, File ent, File enums, List<Api> 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<String, Object> ctx = new HashMap<String, Object>();
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<String, Object> ctx = new HashMap<String, Object>();
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("生成基础类");

@ -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;
}
}

@ -0,0 +1,4 @@
package xyz.wbsite.dbtool.javafx.po;
public class SBMDBOption {
}

@ -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<ActionEvent>() {
@ -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<String>() {
@Override
public void changed(ObservableValue<? extends String> 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 {

@ -23,10 +23,10 @@
GridPane.valignment="CENTER"/>
<Label text="生成路径" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER"/>
<TextField GridPane.columnIndex="1" fx:id="modulePath" promptText="...\**\module\"/>
<TextField GridPane.columnIndex="1" fx:id="sdkPath" GridPane.rowIndex="1"/>
<TextField GridPane.columnIndex="1" fx:id="apiPath" GridPane.rowIndex="1"/>
<Button mnemonicParsing="false" fx:id="selectModulePath" text="选择路径" GridPane.columnIndex="2" GridPane.halignment="CENTER"
GridPane.valignment="CENTER"/>
<Button mnemonicParsing="false" fx:id="selectSdkPath" text="选择路径" GridPane.columnIndex="2" GridPane.halignment="CENTER"
<Button mnemonicParsing="false" fx:id="selectApiPath" text="选择路径" GridPane.columnIndex="2" GridPane.halignment="CENTER"
GridPane.rowIndex="1" GridPane.valignment="CENTER"/>
</children>
<opaqueInsets>

@ -25,6 +25,7 @@
<MenuItem mnemonicParsing="false" onAction="#generateVue" text="生成Vue"/>
<MenuItem mnemonicParsing="false" onAction="#generateApi" text="生成Api"/>
<MenuItem mnemonicParsing="false" onAction="#generateAndroid" text="生成Android"/>
<MenuItem mnemonicParsing="false" onAction="#generateSBMDB" text="生成SB多库"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">

@ -22,7 +22,7 @@
<Label text="生成路径" GridPane.rowIndex="1"/>
<TextField fx:id="modulePath" GridPane.columnIndex="1" GridPane.rowIndex="0"
promptText="...\**\module\"/>
<TextField fx:id="sdkPath" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<TextField fx:id="apiPath" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
</children>
<BorderPane.margin>
<Insets bottom="10.0" left="10.0" right="20.0" top="10.0"/>

@ -1,8 +1,8 @@
package ${domain};
import com.alibaba.fastjson.JSON;
import com.wb.sdk.auth.request.LoginRequest;
import com.wb.sdk.auth.response.LoginResponse;
import com.wb.api.auth.request.LoginRequest;
import com.wb.api.auth.response.LoginResponse;
import java.io.File;
import java.text.SimpleDateFormat;

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.wb</groupId>
<artifactId>${sdk}</artifactId>
<artifactId>${api}</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

Loading…
Cancel
Save

Powered by TurnKey Linux.