Former-commit-id: 2defdd8ea98e70df13b0c6ebd251b74ed86a7d64
master
wangbing 5 years ago
parent 0ee5c36cb8
commit ff278a6d78

@ -1,9 +1,5 @@
package xyz.wbsite.dbtool.javafx.ctrl;
import xyz.wbsite.dbtool.javafx.view.DBCheckBoxTableCell;
import xyz.wbsite.dbtool.javafx.po.Api;
import xyz.wbsite.dbtool.javafx.tool.Dialog;
import xyz.wbsite.dbtool.javafx.tool.Tool;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
@ -15,6 +11,12 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.util.Callback;
import javafx.util.converter.DefaultStringConverter;
import xyz.wbsite.dbtool.javafx.po.Api;
import xyz.wbsite.dbtool.javafx.po.ApiMethod;
import xyz.wbsite.dbtool.javafx.tool.ApiClassReader;
import xyz.wbsite.dbtool.javafx.tool.Dialog;
import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.javafx.view.DBCheckBoxTableCell;
import java.io.*;
import java.util.ArrayList;
@ -39,8 +41,6 @@ public class OptionApiController {
@FXML
private CheckBox All;
@FXML
private CheckBox api;
@FXML
private CheckBox create;
@FXML
private CheckBox delete;
@ -99,14 +99,6 @@ public class OptionApiController {
return create;
}
public CheckBox getApi() {
return api;
}
public void setApi(CheckBox api) {
this.api = api;
}
public void setCreate(CheckBox create) {
this.create = create;
}
@ -196,115 +188,84 @@ public class OptionApiController {
}
private static File find(File file, String name) {
if (file == null) {
return null;
} else if (file.equals(name)) {
return file;
}
if (file.listFiles() != null) {
for (File f : file.listFiles()) {
return find(f, name);
}
}
return null;
}
public void load() {
File moduleFile = new File(modulePath.getText());
data.clear();
if (moduleFile.exists()) {
File apiPath = find(moduleFile, "api");
List<File> apiPath = Tool.find(moduleFile, "api");
if (apiPath.size() == 0) {
return;
}
for (File file : apiPath.listFiles()) {
Dialog.showProgress("扫描API...");
for (File file : apiPath.get(0).listFiles()) {
String module = file.getName();
for (File tar : file.listFiles()) {
String target = tar.getName().replaceAll("Api", "");
try {
String target = tar.getName().replaceAll("Api", "").replaceAll(".java", "");
ApiClassReader apiClassReader = new ApiClassReader(tar);
for (ApiMethod apiMethod : apiClassReader.getMethodList()) {
Api api = new Api();
api.setModule(module);
api.setTarget(target);
}
}
File reqs = new File(moduleFile, "req");
if (!reqs.exists()) {
return;
}
Dialog.showProgress("扫描API...");
for (File req : reqs.listFiles()) {
Api api = new Api();
api.setReq(req);
api.setTargetRequest(req.getName().replace(".java", ""));
api.setRequest(apiMethod.getRequest());
api.setResponse(apiMethod.getResponse());
api.setMethod(apiMethod.getMethod());
List<File> reqFiles = Tool.find(moduleFile, apiMethod.getRequest() + ".java");
if (reqFiles.size() == 0) {
api.setError(api.getError() + "未找到请求");
} else if (reqFiles.size() > 1) {
api.setError(api.getError() + "找到多个请求");
} else {
api.setRequestFile(reqFiles.get(0));
//查找依赖ent
List<String> entities = findEntities(req);
List<String> entities = findEntities(reqFiles.get(0));
for (String entity : entities) {
api.getDepEnt().add(entity);
}
//查找依赖req
List<String> reqss = findReq(req);
List<String> reqss = findReq(reqFiles.get(0));
for (String string : reqss) {
api.getDepReq().add(string);
}
}
//找response
File rsp = new File(moduleFile.getAbsolutePath() + File.separator + "rsp" + File.separator + req.getName().replace("Request", "Response"));
if (rsp.exists()) {
api.setRsp(rsp);
api.setTargetResponse(rsp.getName().replace(".java", ""));
List<File> rspfiles = Tool.find(moduleFile, apiMethod.getResponse() + ".java");
if (rspfiles.size() == 0) {
api.setError(api.getError() + "未找到响应");
} else if (rspfiles.size() > 1) {
api.setError(api.getError() + "找到多个响应");
} else {
api.setResponseFile(rspfiles.get(0));
//查找依赖ent
List<String> entities_ = findEntities(rsp);
for (String entity : entities_) {
List<String> entities = findEntities(rspfiles.get(0));
for (String entity : entities) {
api.getDepEnt().add(entity);
}
//查找依赖req
List<String> reqss_ = findReq(rsp);
for (String string : reqss_) {
List<String> reqss = findReq(rspfiles.get(0));
for (String string : reqss) {
api.getDepReq().add(string);
}
}
// api.setMethod(module + "." + Tool.camelToPoint(req.getName().replaceAll("Request\\.java", "")));
if (api.getTargetRequest().startsWith("Api")) {
api.setCheck(true);
} else {
api.setCheck(false);
}
if (api.getRsp() == null || !api.getRsp().exists()) {
api.setError("响应不存在");
api.setCheck(false);
}
for (String s : api.getDepReq()) {
File en = new File(moduleFile.getAbsolutePath() + File.separator + "req" + File.separator + s + ".java");
if (!en.exists()) {
api.setError("依赖的" + s + "(Request)不存在、");
api.setCheck(false);
data.add(api);
}
} catch (IOException e) {
e.printStackTrace();
}
for (String s : api.getDepEnt()) {
File en = new File(moduleFile.getAbsolutePath() + File.separator + "ent" + File.separator + s + ".java");
if (!en.exists()) {
api.setError("依赖的" + s + "(Entity)不存在、");
api.setCheck(false);
}
}
data.add(api);
initData();
}
Dialog.stopPopup();
}
}
@ -340,37 +301,6 @@ public class OptionApiController {
return strings;
}
public List<String> findEnums(File file) {
ArrayList<String> strings = new ArrayList<>();
InputStreamReader read = null;//考虑到编码格式
try {
read = new InputStreamReader(new FileInputStream(file), "UTF-8");
BufferedReader bufferedReader = new BufferedReader(read);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
//指定字符串判断处
if (line.contains(".enums.")) {
Pattern compile = Pattern.compile(".*\\.enums\\.(.*);");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
String group = matcher.group(1);
strings.add(group);
// System.out.println(group);
}
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return strings;
}
public List<String> findReq(File file) {
ArrayList<String> strings = new ArrayList<>();
InputStreamReader read = null;//考虑到编码格式
@ -428,7 +358,6 @@ public class OptionApiController {
return strings;
}
public void initData() {
apis.setEditable(true);
apis.setSortPolicy(new Callback<TableView, Boolean>() {
@ -448,11 +377,6 @@ public class OptionApiController {
@Override
public ObservableValue<Boolean> call(Integer param) {
super.call(param);
// if (data.get(param).isCheck()) {
// checkBoxTableCell.setInvalid(true);
// } else {
// checkBoxTableCell.setInvalid(false);
// }
if (data.get(param).isCheck()) {
return new SimpleBooleanProperty(true);
} else {
@ -472,19 +396,10 @@ public class OptionApiController {
return checkBoxTableCell;
}
});
columns.get(1).setCellValueFactory(new PropertyValueFactory("error"));
columns.get(1).setCellValueFactory(new PropertyValueFactory("target"));
columns.get(1).setCellFactory(new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn param) {
// param.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent>() {
// @Override
// public void handle(TableColumn.CellEditEvent event) {
// int row = event.getTablePosition().getRow();
// Api api = data.get(row);
// api.setReqName((String) event.getNewValue());
// }
// });
TextFieldTableCell textFieldTableCell = new TextFieldTableCell(new DefaultStringConverter()) {
@Override
public void updateItem(Object item, boolean empty) {
@ -496,19 +411,10 @@ public class OptionApiController {
return textFieldTableCell;
}
});
columns.get(2).setCellValueFactory(new PropertyValueFactory("targetRequest"));
columns.get(2).setCellValueFactory(new PropertyValueFactory("method"));
columns.get(2).setCellFactory(new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn param) {
// param.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent>() {
// @Override
// public void handle(TableColumn.CellEditEvent event) {
// int row = event.getTablePosition().getRow();
// Api api = data.get(row);
// api.setTargetRequest((String) event.getNewValue());
// }
// });
TextFieldTableCell textFieldTableCell = new TextFieldTableCell(new DefaultStringConverter()) {
@Override
public void updateItem(Object item, boolean empty) {
@ -519,18 +425,10 @@ public class OptionApiController {
return textFieldTableCell;
}
});
columns.get(3).setCellValueFactory(new PropertyValueFactory("targetResponse"));
columns.get(3).setCellValueFactory(new PropertyValueFactory("error"));
columns.get(3).setCellFactory(new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn param) {
// param.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent>() {
// @Override
// public void handle(TableColumn.CellEditEvent event) {
// int row = event.getTablePosition().getRow();
// Api api = data.get(row);
// api.setTargetResponse((String) event.getNewValue());
// }
// });
TextFieldTableCell textFieldTableCell = new TextFieldTableCell(new DefaultStringConverter()) {
@Override
public void updateItem(Object item, boolean empty) {
@ -541,8 +439,7 @@ public class OptionApiController {
return textFieldTableCell;
}
});
columns.get(4).setCellValueFactory(new PropertyValueFactory("method"));
columns.get(4).setCellValueFactory(new PropertyValueFactory("request"));
columns.get(4).setCellFactory(new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn param) {
@ -556,6 +453,20 @@ public class OptionApiController {
return textFieldTableCell;
}
});
columns.get(5).setCellValueFactory(new PropertyValueFactory("response"));
columns.get(5).setCellFactory(new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn param) {
TextFieldTableCell textFieldTableCell = new TextFieldTableCell(new DefaultStringConverter()) {
@Override
public void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
}
};
textFieldTableCell.setEditable(false);
return textFieldTableCell;
}
});
ObservableList<Api> ObservableList = FXCollections.observableArrayList();
ObservableList.addAll(data);
apis.setItems(ObservableList);

@ -278,11 +278,7 @@ public class ProjectManager {
@Override
public void run() {
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");
ApiCallable apiCallable = new ApiCallable(api, reqList, rspList, entList, enumsList, apis);
ApiCallable apiCallable = new ApiCallable(module,api, apis);
Future submit = service.submit(apiCallable);
try {
Boolean b = (Boolean) submit.get();

@ -1,12 +1,11 @@
package xyz.wbsite.dbtool.javafx.manger.callable;
import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
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.JavaClassReader;
import xyz.wbsite.dbtool.javafx.tool.JavaEnumReader;
import xyz.wbsite.dbtool.javafx.tool.Tool;
import java.io.File;
@ -16,55 +15,45 @@ import java.util.concurrent.Callable;
public class ApiCallable implements Callable {
private File api;
private File req;
private File rsp;
private File ent;
private File module;
private File apiFile;
private List<Api> apiList;
private Tool tool = new Tool();
private FreeMarkerManager freeMarkerManager;
public ApiCallable(File api, File req, File rsp, File ent, File enums, List<Api> apiList) {
this.api = api;
this.req = req;
this.rsp = rsp;
this.ent = ent;
public ApiCallable(File module, File apiFile, List<Api> apiList) {
this.module = module;
this.apiFile = apiFile;
this.apiList = apiList;
this.freeMarkerManager = ManagerFactory.getFreeMarkerManager();
}
private AbstractDBmapper dBmapper;
public Boolean call() throws Exception {
if (!api.exists()) {
api.mkdir();
if (!apiFile.exists()) {
apiFile.mkdir();
} else {
Tool.clear(api);
Tool.clear(apiFile);
}
dBmapper = ProjectManager.dBmapper;
AbstractDBmapper dBmapper = ProjectManager.dBmapper;
File domain;
File testdomain;
File request;
File response;
File entity;
File enumeration;
StringBuffer sbmain = new StringBuffer("");
sbmain.append(this.api.getPath() + File.separator);
sbmain.append(this.apiFile.getPath() + File.separator);
sbmain.append("src" + File.separator);
sbmain.append("main" + File.separator);
sbmain.append("java" + File.separator);
StringBuffer sbtest = new StringBuffer("");
sbtest.append(this.api.getPath() + File.separator);
sbtest.append(this.apiFile.getPath() + File.separator);
sbtest.append("src" + File.separator);
sbtest.append("test" + File.separator);
sbtest.append("java" + File.separator);
JavaClassReader javaClass = new JavaClassReader(apiList.get(0).getReq());
JavaClassReader javaClass = new JavaClassReader(apiList.get(0).getRequestFile());
String[] split = javaClass.getDomainName().split("\\.");
for (String s1 : split) {
@ -76,37 +65,26 @@ public class ApiCallable implements Callable {
domain.mkdirs();
testdomain = new File(sbtest.toString());
testdomain.mkdirs();
request = new File(domain, "request");
for (Api api : apiList) {
if (api.isCheck()) {
File module = new File(domain, api.getModule());
module.mkdirs();
File request = new File(module, "req");
request.mkdirs();
response = new File(domain, "response");
File response = new File(module, "rsp");
response.mkdirs();
entity = new File(domain, "entity");
File entity = new File(module, "ent");
entity.mkdirs();
enumeration = new File(domain, "enums");
enumeration.mkdirs();
{
System.out.println("生成模块:Pom");
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("api", api.getName());
File file = new File(api, "pom.xml");
freeMarkerManager.outputTemp(file, "Java_api/pom.xml", ctx);
}
Set<String> managerList = new HashSet<>();
List<Method> methodList = new ArrayList<>();
for (Api api : apiList) {
if (api.isCheck()) {
try {
//region 生成request
JavaClassReader javaClassReader = new JavaClassReader(api.getReq());
JavaClassReader javaClassReader = new JavaClassReader(api.getRequestFile());
for (int i = 0; i < javaClassReader.getImportList().size(); i++) {
String s = javaClassReader.getImportList().get(i);
if (s.contains(".api.entity.")) {
javaClassReader.getImportList().set(i, s.replaceAll("\\.api\\.entity\\.", ".entity."));
if (s.contains(".module.entity.")) {
javaClassReader.getImportList().set(i, s);
}
}
@ -116,15 +94,14 @@ public class ApiCallable implements Callable {
method.setTarget(Tool.getRequestTarget(javaClassReader.getClassName()));
method.setMethod(Tool.getRequestAction(javaClassReader.getClassName()));
method.setManager(Tool.getRequestTarget(javaClassReader.getClassName()) + "Manager");
methodList.add(method);
managerList.add(method.getManager());
{
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
ctx.put("domain", javaClassReader.getDomainName());
ctx.put("module", javaClassReader.getModuleName());
ctx.put("target", api.getTarget());
ctx.put("method", api.getMethod());
ctx.put("importList", javaClassReader.getImportList());
ctx.put("annotation", javaClassReader.getAnnotationList());
ctx.put("className", javaClassReader.getClassName().replaceAll("Request", ""));
@ -132,9 +109,9 @@ public class ApiCallable implements Callable {
ctx.put("tool", tool);
ctx.put("hasList", javaClassReader.isHasList());
ctx.put("findOrSearchflag", javaClassReader.getFindOrSearchflag());
File file = new File(request.getAbsolutePath(), api.getReq().getName());
File file = new File(request.getAbsolutePath(), api.getRequestFile().getName());
freeMarkerManager.outputTemp(file, "Java_api/module/request/request.java", ctx);
freeMarkerManager.outputTemp(file, "Java_api/module/req/request.java", ctx);
System.out.println("生成文件" + file.getName() + "成功");
}
//endregion
@ -145,11 +122,11 @@ public class ApiCallable implements Callable {
try {
//region 生成response
JavaClassReader javaClassReader = new JavaClassReader(api.getRsp());
JavaClassReader javaClassReader = new JavaClassReader(api.getResponseFile());
for (int i = 0; i < javaClassReader.getImportList().size(); i++) {
String import_ = javaClassReader.getImportList().get(i);
if (import_.contains(".api.entity.")) {
javaClassReader.getImportList().set(i, import_.replaceAll("\\.api\\.entity\\.", ".entity."));
if (import_.contains(".module.entity.")) {
javaClassReader.getImportList().set(i, import_);
}
}
@ -165,132 +142,141 @@ public class ApiCallable implements Callable {
ctx.put("tool", tool);
ctx.put("hasList", javaClassReader.isHasList());
ctx.put("Tclass", javaClassReader.getTclass());
File file = new File(response.getAbsolutePath(), api.getRsp().getName().replaceAll("Request", "Response"));
freeMarkerManager.outputTemp(file, "Java_api/module/response/response.java", ctx);
System.out.println("生成文件" + api.getRsp().getName() + "成功");
}
//endregion
} catch (IOException e) {
e.printStackTrace();
}
for (String s : api.getDepReq()) {
try {
File f = new File(req.getAbsolutePath(), s + ".java");
if (!f.exists()) {
System.err.println("文件" + f.getAbsolutePath() + "不存在");
continue;
}
JavaClassReader javaClassReader = new JavaClassReader(f);
for (int i = 0; i < javaClassReader.getImportList().size(); i++) {
String import_ = javaClassReader.getImportList().get(i);
if (import_.contains(".api.entity.")) {
javaClassReader.getImportList().set(i, import_.replaceAll("\\.api\\.entity\\.", ".entity."));
}
}
File file = new File(response.getAbsolutePath(), api.getResponseFile().getName().replaceAll("Request", "Response"));
Method method = new Method();
method.setStringMethod(api.getMethod());
method.setRequest(javaClassReader.getClassName());
method.setTarget(Tool.getRequestTarget(javaClassReader.getClassName()));
method.setMethod(Tool.getRequestAction(javaClassReader.getClassName()));
method.setManager(Tool.getRequestTarget(javaClassReader.getClassName()) + "Manager");
{
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
ctx.put("domain", javaClassReader.getDomainName());
ctx.put("module", javaClassReader.getModuleName());
ctx.put("importList", javaClassReader.getImportList());
ctx.put("annotation", javaClassReader.getAnnotationList());
ctx.put("className", javaClassReader.getClassName().replaceAll("Request", ""));
ctx.put("body", javaClassReader.getBody());
ctx.put("tool", tool);
ctx.put("hasList", javaClassReader.isHasList());
ctx.put("findOrSearchflag", javaClassReader.getFindOrSearchflag());
File file = new File(request.getAbsolutePath(), f.getName());
freeMarkerManager.outputTemp(file, "Java_api/module/request/request.java", ctx);
System.out.println("生成文件" + file.getName() + "成功");
freeMarkerManager.outputTemp(file, "Java_api/module/rsp/response.java", ctx);
System.out.println("生成文件" + api.getResponseFile().getName() + "成功");
}
//endregion
} catch (IOException e) {
e.printStackTrace();
}
try {
File f = new File(rsp.getAbsolutePath(), s.replaceAll("Request", "Response.java"));
if (!f.exists()) {
System.err.println("文件" + f.getAbsolutePath() + "不存在");
}
JavaClassReader javaClassReader = new JavaClassReader(f);
for (int i = 0; i < javaClassReader.getImportList().size(); i++) {
String import_ = javaClassReader.getImportList().get(i);
if (import_.contains(".api.entity.")) {
javaClassReader.getImportList().set(i, import_.replaceAll("\\.api\\.entity\\.", ".entity."));
}
}
{
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
ctx.put("domain", javaClassReader.getDomainName());
ctx.put("module", javaClassReader.getModuleName());
ctx.put("importList", javaClassReader.getImportList());
ctx.put("annotation", javaClassReader.getAnnotationList());
ctx.put("className", javaClassReader.getClassName().replaceAll("Response", ""));
ctx.put("body", javaClassReader.getBody());
ctx.put("tool", tool);
ctx.put("hasList", javaClassReader.isHasList());
ctx.put("Tclass", javaClassReader.getTclass());
File file = new File(response.getAbsolutePath(), f.getName());
freeMarkerManager.outputTemp(file, "Java_api/module/response/response.java", ctx);
System.out.println("生成文件" + api.getRsp().getName() + "成功");
}
//endregion
} catch (IOException e) {
e.printStackTrace();
// for (String s : api.getDepReq()) {
// try {
// File f = new File(apiFile.getAbsolutePath(), s + ".java");
// if (!f.exists()) {
// System.err.println("文件" + f.getAbsolutePath() + "不存在");
// continue;
// }
// JavaClassReader javaClassReader = new JavaClassReader(f);
// for (int i = 0; i < javaClassReader.getImportList().size(); i++) {
// String import_ = javaClassReader.getImportList().get(i);
// if (import_.contains(".module.entity.")) {
// javaClassReader.getImportList().set(i, import_.replaceAll("\\.api\\.entity\\.", ".entity."));
// }
// }
//
// Method method = new Method();
// method.setStringMethod(api.getMethod());
// method.setRequest(javaClassReader.getClassName());
// method.setTarget(Tool.getRequestTarget(javaClassReader.getClassName()));
// method.setMethod(Tool.getRequestAction(javaClassReader.getClassName()));
// method.setManager(Tool.getRequestTarget(javaClassReader.getClassName()) + "Manager");
//
// {
// HashMap<String, Object> ctx = new HashMap<String, Object>();
// ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
// ctx.put("domain", javaClassReader.getDomainName());
// ctx.put("module", javaClassReader.getModuleName());
// ctx.put("importList", javaClassReader.getImportList());
// ctx.put("annotation", javaClassReader.getAnnotationList());
// ctx.put("className", javaClassReader.getClassName().replaceAll("Request", ""));
// ctx.put("body", javaClassReader.getBody());
// ctx.put("tool", tool);
// ctx.put("hasList", javaClassReader.isHasList());
// ctx.put("findOrSearchflag", javaClassReader.getFindOrSearchflag());
// File file = new File(request.getAbsolutePath(), f.getName());
//
// freeMarkerManager.outputTemp(file, "Java_api/module/req/request.java", ctx);
// System.out.println("生成文件" + file.getName() + "成功");
// }
// //endregion
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// try {
// File f = new File(rsp.getAbsolutePath(), s.replaceAll("Request", "Response.java"));
// if (!f.exists()) {
// System.err.println("文件" + f.getAbsolutePath() + "不存在");
// }
// JavaClassReader javaClassReader = new JavaClassReader(f);
// for (int i = 0; i < javaClassReader.getImportList().size(); i++) {
// String import_ = javaClassReader.getImportList().get(i);
// if (import_.contains(".module.entity.")) {
// javaClassReader.getImportList().set(i, import_.replaceAll("\\.api\\.entity\\.", ".entity."));
// }
// }
//
// {
// HashMap<String, Object> ctx = new HashMap<String, Object>();
// ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
// ctx.put("domain", javaClassReader.getDomainName());
// ctx.put("module", javaClassReader.getModuleName());
// ctx.put("importList", javaClassReader.getImportList());
// ctx.put("annotation", javaClassReader.getAnnotationList());
// ctx.put("className", javaClassReader.getClassName().replaceAll("Response", ""));
// ctx.put("body", javaClassReader.getBody());
// ctx.put("tool", tool);
// ctx.put("hasList", javaClassReader.isHasList());
// ctx.put("Tclass", javaClassReader.getTclass());
// File file = new File(response.getAbsolutePath(), f.getName());
//
// freeMarkerManager.outputTemp(file, "Java_api/module/rsp/response.java", ctx);
// System.out.println("生成文件" + api.getResponseFile().getName() + "成功");
// }
// //endregion
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// for (String s : api.getDepEnt()) {
//
// try {
// File f = new File(ent.getAbsolutePath(), s + ".java");
// if (!f.exists()) {
// System.out.println("文件" + f.getAbsolutePath() + "不存在");
// continue;
// }
// JavaClassReader javaClassReader = new JavaClassReader(f);
// for (int i = 0; i < javaClassReader.getImportList().size(); i++) {
// String import_ = javaClassReader.getImportList().get(i);
// if (import_.contains(".module.entity.")) {
// javaClassReader.getImportList().set(i, import_.replaceAll("\\.api\\.entity\\.", ".entity."));
// }
// }
//
// {
// HashMap<String, Object> ctx = new HashMap<String, Object>();
// ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
// ctx.put("domain", javaClassReader.getDomainName());
// ctx.put("module", javaClassReader.getModuleName());
// ctx.put("importList", javaClassReader.getImportList());
// ctx.put("annotation", javaClassReader.getAnnotationList());
// ctx.put("className", javaClassReader.getClassName().replaceAll("Entity", ""));
// ctx.put("body", javaClassReader.getBody());
// ctx.put("tool", tool);
// File file = new File(entity.getAbsolutePath(), f.getName());
// freeMarkerManager.outputTemp(file, "Java_api/module/ent/entity.java", ctx);
// System.out.println("生成文件" + file.getName() + "成功");
// }
// //endregion
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
}
}
for (String s : api.getDepEnt()) {
try {
File f = new File(ent.getAbsolutePath(), s + ".java");
if (!f.exists()) {
System.out.println("文件" + f.getAbsolutePath() + "不存在");
continue;
}
JavaClassReader javaClassReader = new JavaClassReader(f);
for (int i = 0; i < javaClassReader.getImportList().size(); i++) {
String import_ = javaClassReader.getImportList().get(i);
if (import_.contains(".api.entity.")) {
javaClassReader.getImportList().set(i, import_.replaceAll("\\.api\\.entity\\.", ".entity."));
}
}
{
System.out.println("生成模块:Pom");
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("package", "package " + javaClassReader.getDomainName() + "." + javaClassReader.getModuleName() + "." + "request;");
ctx.put("domain", javaClassReader.getDomainName());
ctx.put("module", javaClassReader.getModuleName());
ctx.put("importList", javaClassReader.getImportList());
ctx.put("annotation", javaClassReader.getAnnotationList());
ctx.put("className", javaClassReader.getClassName().replaceAll("Entity", ""));
ctx.put("body", javaClassReader.getBody());
ctx.put("tool", tool);
File file = new File(entity.getAbsolutePath(), f.getName());
freeMarkerManager.outputTemp(file, "Java_api/module/entity/entity.java", ctx);
System.out.println("生成文件" + file.getName() + "成功");
}
//endregion
} catch (IOException e) {
e.printStackTrace();
}
}
}
ctx.put("module", apiFile.getName());
File file = new File(apiFile, "pom.xml");
freeMarkerManager.outputTemp(file, "Java_api/pom.xml", ctx);
}
{
@ -387,8 +373,6 @@ public class ApiCallable implements Callable {
ctx.put("tool", tool);
ctx.put("domain", javaClass.getDomainName());
ctx.put("module", javaClass.getModuleName());
ctx.put("managerList", managerList);
ctx.put("methodList", methodList);
ctx.put("apiList", apiList);
freeMarkerManager.outputTemp(new File(testdomain.getAbsolutePath(), "ApiTest.java"), "Java_api/ApiTest.java", ctx);
}

@ -10,28 +10,20 @@ public class Api {
private boolean check;
//目标请求对象
private String targetRequest;
private String request;
//目标请求响应
private String targetResponse;
private String response;
private String module;
private String target;
private String method;
private File req;
private File rsp;
private File requestFile;
private File responseFile;
private Set<String> depReq = new HashSet<>();
private Set<String> depEnt = new HashSet<>();
private String error;
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
private String error = "";
public boolean isCheck() {
return check;
@ -41,20 +33,36 @@ public class Api {
this.check = check;
}
public String getTargetRequest() {
return targetRequest;
public String getRequest() {
return request;
}
public void setRequest(String request) {
this.request = request;
}
public void setTargetRequest(String targetRequest) {
this.targetRequest = targetRequest;
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
public String getTargetResponse() {
return targetResponse;
public String getTarget() {
return target;
}
public void setTargetResponse(String targetResponse) {
this.targetResponse = targetResponse;
public void setTarget(String target) {
this.target = target;
}
public String getMethod() {
@ -65,20 +73,20 @@ public class Api {
this.method = method;
}
public File getReq() {
return req;
public File getRequestFile() {
return requestFile;
}
public void setReq(File req) {
this.req = req;
public void setRequestFile(File requestFile) {
this.requestFile = requestFile;
}
public File getRsp() {
return rsp;
public File getResponseFile() {
return responseFile;
}
public void setRsp(File rsp) {
this.rsp = rsp;
public void setResponseFile(File responseFile) {
this.responseFile = responseFile;
}
public Set<String> getDepReq() {
@ -97,19 +105,11 @@ public class Api {
this.depEnt = depEnt;
}
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
public String getTarget() {
return target;
public String getError() {
return error;
}
public void setTarget(String target) {
this.target = target;
public void setError(String error) {
this.error = error;
}
}

@ -0,0 +1,31 @@
package xyz.wbsite.dbtool.javafx.po;
public class ApiMethod {
private String request;
private String response;
private String method;
public String getRequest() {
return request;
}
public void setRequest(String request) {
this.request = request;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
}

@ -0,0 +1,63 @@
package xyz.wbsite.dbtool.javafx.tool;
import xyz.wbsite.dbtool.javafx.po.ApiMethod;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ApiClassReader {
private File javaClass;
private List<ApiMethod> methodList;
public ApiClassReader(File javaClass) throws IOException {
this.javaClass = javaClass;
methodList = new ArrayList<>();
read();
}
private void read() throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8"));
String line = null;
Pattern compile = Pattern.compile("\\s+public (.*Response)\\s+(.*)\\((.*Request) request\\) \\{");
while ((line = bufferedReader.readLine()) != null) {
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
ApiMethod apiMethod = new ApiMethod();
apiMethod.setResponse(matcher.group(1));
apiMethod.setMethod(matcher.group(2));
apiMethod.setRequest(matcher.group(3));
methodList.add(apiMethod);
}
}
bufferedReader.close();
}
public File getJavaClass() {
return javaClass;
}
public void setJavaClass(File javaClass) {
this.javaClass = javaClass;
}
public List<ApiMethod> getMethodList() {
return methodList;
}
public void setMethodList(List<ApiMethod> methodList) {
this.methodList = methodList;
}
public static void main(String[] args) throws IOException {
ApiClassReader javaClassReader = new ApiClassReader(new File("D:\\wangbing\\Project\\dbtool\\target\\project\\EXAMPLE-WEB\\src\\main\\java\\com\\example\\action\\api\\system\\DictApi.java"));
System.out.println();
}
}

@ -444,12 +444,6 @@ public class Dialog {
check(controller, controller.getAll().isSelected(), "");
}
});
controller.getApi().setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
check(controller, controller.getApi().isSelected(), ".api.");
}
});
controller.getCreate().setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
@ -701,24 +695,11 @@ public class Dialog {
controller.initData();
}
private static boolean hasChild(File file, String child) {
if (file == null || child == null || "".equals(child) || file.listFiles() == null) {
return false;
}
for (File f : file.listFiles()) {
if (f.getName().equals(child)) {
return true;
}
}
return false;
}
private static File findAction(File file) {
if (file == null) {
return null;
} else if (hasChild(file, "action") && hasChild(file, "module")) {
} else if (Tool.hasChild(file, "action") && Tool.hasChild(file, "module")) {
return file;
}

@ -58,9 +58,6 @@ public class JavaClassReader {
}
if (line.startsWith("import")) {
if (!line.contains("frame")) {
if (line.contains(".ent.")) {
line = line.replaceAll("\\.ent\\.", ".entity.");
}
importList.add(line);
}

@ -2,6 +2,7 @@ package xyz.wbsite.dbtool.javafx.tool;
import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
@ -346,6 +347,43 @@ public class Tool {
}
}
public static List<File> find(File file, String name) {
List<File> fileList = new ArrayList<>();
if (file != null) {
if (file.getName().equals("target") ||
file.getName().equals("classes") ||
file.getName().equals(".idea")) {
return fileList;
}
if (file.getName().equals(name)) {
fileList.add(file);
}
if (file.listFiles() != null) {
for (File f : file.listFiles()) {
fileList.addAll(find(f, name));
}
}
}
return fileList;
}
public static boolean hasChild(File file, String child) {
if (file == null || child == null || "".equals(child) || file.listFiles() == null) {
return false;
}
for (File f : file.listFiles()) {
if (f.getName().equals(child)) {
return true;
}
}
return false;
}
public static void exchange(List list, int i, int j) {
Object o1 = list.get(i);
Object o2 = list.get(j);

@ -1,34 +0,0 @@
package xyz.wbsite.dbtool.web.frame.base;
public class FileUploadResponse extends BaseResponse {
private Long id;
private String url;
private String downloadUrl;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDownloadUrl() {
return downloadUrl;
}
public void setDownloadUrl(String downloadUrl) {
this.downloadUrl = downloadUrl;
}
}

@ -24,9 +24,11 @@
<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="apiPath" GridPane.rowIndex="1"/>
<Button mnemonicParsing="false" fx:id="selectModulePath" text="选择路径" GridPane.columnIndex="2" GridPane.halignment="CENTER"
<Button mnemonicParsing="false" fx:id="selectModulePath" text="选择路径" GridPane.columnIndex="2"
GridPane.halignment="CENTER"
GridPane.valignment="CENTER"/>
<Button mnemonicParsing="false" fx:id="selectApiPath" 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>
@ -43,11 +45,12 @@
<center>
<TableView fx:id="apis" prefHeight="270.0" prefWidth="700.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn prefWidth="60.0" text="选择"/>
<TableColumn prefWidth="140.0" text="错误"/>
<TableColumn prefWidth="150.0" text="request"/>
<TableColumn prefWidth="150.0" text="response"/>
<TableColumn prefWidth="200.0" text="method"/>
<TableColumn prefWidth="30.0" text="选择"/>
<TableColumn prefWidth="80.0" text="对象"/>
<TableColumn prefWidth="80.0" text="方法"/>
<TableColumn prefWidth="80.0" text="信息"/>
<TableColumn prefWidth="150.0" text="请求"/>
<TableColumn prefWidth="150.0" text="响应"/>
</columns>
</TableView>
@ -57,8 +60,6 @@
<items>
<CheckBox mnemonicParsing="false" fx:id="All" text="All" selected="false">
</CheckBox>
<CheckBox mnemonicParsing="false" fx:id="api" text="api" selected="true">
</CheckBox>
<CheckBox mnemonicParsing="false" fx:id="create" text="create" selected="false">
</CheckBox>
<CheckBox mnemonicParsing="false" fx:id="delete" text="delete" selected="false">

@ -50,9 +50,9 @@ public class ApiTest {
<#list apiList as item>
@Test
public void test${item.targetRequest}() {
${item.targetRequest} request = new ${item.targetRequest}();
${item.targetResponse} response = apiClient.execute(request);
public void test${item.request}() {
${item.request} request = new ${item.request}();
${item.response} response = apiClient.execute(request);
Assert.assertTrue(!response.hasError());
}
</#list>

@ -1,4 +1,4 @@
package ${domain}.entity;
package ${domain}.${module}.ent;
<#list importList as i>
${i}

@ -1,11 +1,11 @@
package ${domain}.request;
package ${domain}.${module}.req;
<#list importList as i>
<#if !i?contains("javax.validation") && !i?contains("org.hibernate.validator")>
${i}
</#if>
</#list>
import ${domain}.response.${className}Response;
import ${domain}.${module}.rsp.${className}Response;
import ${domain}.ApiRequest;
<#if findOrSearchflag=='1'>
import ${domain}.ApiFindRequest;
@ -27,8 +27,8 @@ ${i}
}
public String apiMethod() {
return "${module}.${tool.camelToPoint(className)}";
public String path() {
return "${module}/${target}/${method}";
}
public Class<${className}Response> responseClass() {

@ -1,4 +1,4 @@
package ${domain}.response;
package ${domain}.${module}.rsp;
<#list importList as i>
${i}

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

@ -16,7 +16,7 @@ web.welcome.page=/index.htm
# 需要验证授权, 既访问时组装Token
web.url.auth.included=/**
# 不需要验证授权, 或该请求有自己的验证机制
web.url.auth.excluded=/favicon.ico,/static/**,/api,/login.htm
web.url.auth.excluded=/favicon.ico,/static/**,/module,/login.htm
# 日志配置
logging.path=D://
logging.levels=DEBUG

@ -39,7 +39,7 @@ public class Authorizations implements Filter {
String path = httpServletRequest.getServletPath();
//以下Api无需授权Api自己会处理
if ("/api".equals(path)) {
if ("/module".equals(path)) {
chain.doFilter(request, response);
return;
}

@ -172,7 +172,7 @@
<!-- servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<artifactId>servlet-module</artifactId>
<version>3.0-alpha-1</version>
</dependency>
@ -228,7 +228,7 @@
<!-- 日志依赖 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<artifactId>slf4j-module</artifactId>
<version>${r"${slf4j.version}"}</version>
</dependency>
<dependency>

Loading…
Cancel
Save

Powered by TurnKey Linux.