Former-commit-id: 17d6b07a60333951e60d0e558835514b8d21e8c2
master
wangbing 6 years ago
parent bd925e0284
commit 79ed641b71

@ -107,13 +107,13 @@ public class ApiCallable implements Callable {
for (File file : files) {
EntityReader entReader = new EntityReader(file);
if (Package.equals(entReader.getPackageName())) {
if (Package.equals(entReader.getModuleName())) {
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("package", "package " + entReader.getDomainName() + "." + entReader.getModuleName() + "." + "req;");
ctx.put("domain", entReader.getDomainName());
ctx.put("module", entReader.getModuleName());
ctx.put("importList", entReader.getImportList());
ctx.put("annotation", entReader.getAnnotationList());
ctx.put("annotation", entReader.getNotesList());
ctx.put("className", entReader.getClassName().replaceAll("Entity", ""));
ctx.put("body", entReader.getBody());
ctx.put("tool", tool);
@ -126,43 +126,41 @@ public class ApiCallable implements Callable {
}
}
List<String> reqNames = new ArrayList<>();
for (String s : requestReader.getDeptReqList()) {
Pattern compile = Pattern.compile("(.*\\.req)\\.(.*)");
Matcher matcher = compile.matcher(s);
if (matcher.find()) {
String Package = matcher.group(1);
String EntName = matcher.group(2);
reqNames.add(EntName);
List<File> files = Tool.find(this.module, EntName + ".java");
for (String reqName : requestReader.getDeptReqList()) {
List<File> files = Tool.find(this.module, reqName + ".java");
for (File file : files) {
RequestReader reqReader = new RequestReader(file);
if (requestReader.getModuleName().equals(reqReader.getModuleName())) {
boolean isTempReq = true;
for (Api api1 : apiList) {
if (api1.isCheck() && api1.getRequest().equals(reqName) && api1.getModule().equals(api.getModule())) {
isTempReq = false;
}
}
for (File file : files) {
RequestReader reqReader = new RequestReader(file);
if (Package.equals(reqReader.getPackageName())) {
if (isTempReq){
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("package", "package " + requestReader.getDomainName() + "." + requestReader.getModuleName() + "." + "req;");
ctx.put("domain", requestReader.getDomainName());
ctx.put("module", requestReader.getModuleName());
ctx.put("package", "package " + reqReader.getDomainName() + "." + reqReader.getModuleName() + "." + "req;");
ctx.put("domain", reqReader.getDomainName());
ctx.put("module", reqReader.getModuleName());
ctx.put("target", api.getTarget());
ctx.put("method", api.getMethod());
ctx.put("importList", requestReader.getImportList());
ctx.put("isTempReq", isTempReq);
ctx.put("importList", reqReader.getImportList());
ctx.put("entNames", entNames);
ctx.put("annotation", requestReader.getAnnotationList());
ctx.put("className", requestReader.getClassName().replaceAll("Request", ""));
ctx.put("body", requestReader.getBody());
ctx.put("annotation", reqReader.getNotesList());
ctx.put("className", reqReader.getClassName().replaceAll("Request", ""));
ctx.put("body", reqReader.getBody());
ctx.put("tool", tool);
ctx.put("hasList", requestReader.isHasList());
ctx.put("findOrSearchflag", requestReader.getFindOrSearchflag());
File reqfile = new File(apiRequest.getAbsolutePath(), api.getRequestFile().getName());
ctx.put("hasList", reqReader.isHasList());
ctx.put("findOrSearchflag", reqReader.getFindOrSearchflag());
File reqfile = new File(apiRequest.getAbsolutePath(), reqName + ".java");
freeMarkerManager.outputTemp(reqfile, "Java_api/module/req/request.java", ctx);
System.out.println("生成文件" + reqfile.getName() + "成功");
}
}
}
}
@ -173,10 +171,10 @@ public class ApiCallable implements Callable {
ctx.put("module", requestReader.getModuleName());
ctx.put("target", api.getTarget());
ctx.put("method", api.getMethod());
ctx.put("isTempReq", false);
ctx.put("importList", requestReader.getImportList());
ctx.put("entNames", entNames);
ctx.put("reqNames", reqNames);
ctx.put("annotation", requestReader.getAnnotationList());
ctx.put("annotation", requestReader.getNotesList());
ctx.put("className", requestReader.getClassName().replaceAll("Request", ""));
ctx.put("body", requestReader.getBody());
ctx.put("tool", tool);
@ -217,13 +215,13 @@ public class ApiCallable implements Callable {
for (File file : files) {
EntityReader entReader = new EntityReader(file);
if (Package.equals(entReader.getPackageName())) {
if (Package.equals(entReader.getModuleName())) {
HashMap<String, Object> ctx = new HashMap<String, Object>();
ctx.put("package", "package " + entReader.getDomainName() + "." + entReader.getModuleName() + "." + "request;");
ctx.put("domain", entReader.getDomainName());
ctx.put("module", entReader.getModuleName());
ctx.put("importList", entReader.getImportList());
ctx.put("annotation", entReader.getAnnotationList());
ctx.put("annotation", entReader.getNotesList());
ctx.put("className", entReader.getClassName().replaceAll("Entity", ""));
ctx.put("body", entReader.getBody());
ctx.put("tool", tool);
@ -243,7 +241,7 @@ public class ApiCallable implements Callable {
ctx.put("module", responseReader.getModuleName());
ctx.put("importList", responseReader.getImportList());
ctx.put("entNames", entNames);
ctx.put("annotation", responseReader.getAnnotationList());
ctx.put("annotation", responseReader.getNotesList());
ctx.put("className", responseReader.getClassName().replaceAll("Response", ""));
ctx.put("body", responseReader.getBody());
ctx.put("tool", tool);
@ -255,15 +253,12 @@ public class ApiCallable implements Callable {
System.out.println("生成文件" + api.getResponseFile().getName() + "成功");
}
//endregion
} catch (IOException e) {
e.printStackTrace();
}
}
}
{
System.out.println("生成模块:Pom");
HashMap<String, Object> ctx = new HashMap<String, Object>();

@ -8,11 +8,10 @@ import java.util.regex.Pattern;
public class EntityReader {
private File javaClass;
private String packageName;
private String domainName;
private String moduleName;
private List<String> annotationList;
private List<String> importList;
private List<String> notesList;
private Set<String> deptReqList;
private Set<String> deptEntList;
private String className;
@ -25,9 +24,10 @@ public class EntityReader {
public EntityReader(File javaClass) throws IOException {
this.javaClass = javaClass;
importList = new ArrayList<>();
annotationList = new ArrayList<>();
notesList = new ArrayList<>();
deptReqList = new HashSet<>();
deptEntList = new HashSet<>();
body = new ArrayList<>();
domainName = "";
read();
}
@ -35,28 +35,14 @@ public class EntityReader {
private void read() throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8"));
int step = 1;//1-读取package2-读取import3-读取类注释4-读取类名、父类5-读取类体
String line = null;
StringBuffer zs = new StringBuffer();
StringBuffer sb = new StringBuffer();
while ((line = bufferedReader.readLine()) != null) {
if (line.matches("\\s*package\\s(.*);")) {
{
Pattern compile = Pattern.compile("\\s*package\\s(.*);");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
packageName = matcher.group(1);
}
}
{
Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).ent;");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
domainName = matcher.group(1);
moduleName = matcher.group(2);
}
Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).req;");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
domainName = matcher.group(1);
moduleName = matcher.group(2);
}
continue;
}
@ -68,85 +54,45 @@ public class EntityReader {
String group = matcher.group(1);
deptEntList.add(group);
}
} else if (line.contains(".req.")) {
Pattern compile = Pattern.compile("import\\s+(.*\\.req\\..*);");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
String group = matcher.group(1);
deptReqList.add(group);
}
} else if (!line.contains("frame")) {
} else if (line.contains("frame")) {
} else if (line.contains("javax.validation")) {
} else if (line.contains("org.hibernate.validator")) {
} else {
importList.add(line);
}
continue;
}
if (line.contains("/**") || line.contains("*") || line.contains("*/")) {
if (zs != null) {
zs.append(line + "\n");
annotationList.add(line);
if (line.contains("*/")) {
zs = null;
}
}
notesList.add(line);
}
if (line.contains("class")) {
line = line.replaceAll("\\{", " { ");
line = line.replaceAll("}", " } ");
line = line.replaceAll("\\s+", " ");
String[] split = line.split("\\s");
for (int i = 0; i < split.length; i++) {
if ("class".equals(split[i])) {
className = split[i + 1];
}
if ("extends".equals(split[i])) {
fatherName = split[i + 1];
if (fatherName.contains("FindResponse") || fatherName.contains("GetAllResponse")) {
hasList = true;
Pattern pattern = Pattern.compile("<(.*?)>");
Matcher matcher = pattern.matcher(fatherName);
if (matcher.find()) {
String group = matcher.group(1);
Tclass = group;
}
}
if (fatherName.contains("FindRequest")) {
findOrSearchflag = "1";
} else if (fatherName.contains("SearchRequest")) {
findOrSearchflag = "2";
}
}
}
}
sb.append(line + "\n");
}
body = new ArrayList<>(Arrays.asList(sb.substring(sb.indexOf("{")).split("\n")));
if (line.matches("public class\\s+(.*)\\s+extends\\s+BaseEntity\\s*\\{")) {
Pattern compile = Pattern.compile("public class\\s+(.*)\\s+extends\\s+BaseEntity\\s*\\{");
Matcher matcher = compile.matcher(line);
for (int i = 0; i < body.size(); i++) {
if (body.get(i).contains("{")) {
body.set(i, body.get(i).replaceAll("\\{", ""));
String s = body.get(i);
if (s.length() <= 1) {
body.remove(i);
if (matcher.find()) {
className = matcher.group(1);
fatherName = "BaseEntity";
}
break;
}
}
Iterator<String> iterator = body.iterator();
while (iterator.hasNext()) {
String next = iterator.next();
if (next.contains("@ColumnName")) {
iterator.remove();
continue;
}
if (className != null) {
body.add(line);
if (line.matches("\\s*private\\s+(.*Request)\\s+(.*);")) {
Pattern compile = Pattern.compile("\\s*private\\s+(.*Request)\\s+(.*);");
Matcher matcher = compile.matcher(line);
if (next.contains("@ColumnDescription")) {
iterator.remove();
if (matcher.find()) {
String group = matcher.group(1);
deptReqList.add(group);
}
}
}
}
for (int i = body.size() - 1; i >= 0; i--) {
if (body.get(i).contains("}")) {
body.set(i, body.get(i).replaceAll("}", ""));
@ -163,14 +109,6 @@ public class EntityReader {
bufferedReader.close();
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getDomainName() {
return domainName;
}
@ -187,12 +125,12 @@ public class EntityReader {
this.moduleName = moduleName;
}
public List<String> getAnnotationList() {
return annotationList;
public List<String> getNotesList() {
return notesList;
}
public void setAnnotationList(List<String> annotationList) {
this.annotationList = annotationList;
public void setNotesList(List<String> notesList) {
this.notesList = notesList;
}
public List<String> getImportList() {

@ -1,18 +1,20 @@
package xyz.wbsite.dbtool.javafx.tool;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RequestReader {
private File javaClass;
private String packageName;
private String domainName;
private String moduleName;
private List<String> annotationList;
private List<String> importList;
private List<String> notesList;
private Set<String> deptReqList;
private Set<String> deptEntList;
private String className;
@ -25,9 +27,10 @@ public class RequestReader {
public RequestReader(File javaClass) throws IOException {
this.javaClass = javaClass;
importList = new ArrayList<>();
annotationList = new ArrayList<>();
notesList = new ArrayList<>();
deptReqList = new HashSet<>();
deptEntList = new HashSet<>();
body = new ArrayList<>();
domainName = "";
read();
}
@ -35,28 +38,14 @@ public class RequestReader {
private void read() throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8"));
int step = 1;//1-读取package2-读取import3-读取类注释4-读取类名、父类5-读取类体
String line = null;
StringBuffer zs = new StringBuffer();
StringBuffer sb = new StringBuffer();
while ((line = bufferedReader.readLine()) != null) {
if (line.matches("\\s*package\\s(.*);")) {
{
Pattern compile = Pattern.compile("\\s*package\\s(.*);");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
packageName = matcher.group(1);
}
}
{
Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).req;");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
domainName = matcher.group(1);
moduleName = matcher.group(2);
}
Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).req;");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
domainName = matcher.group(1);
moduleName = matcher.group(2);
}
continue;
}
@ -68,72 +57,56 @@ public class RequestReader {
String group = matcher.group(1);
deptEntList.add(group);
}
} else if (line.contains(".req.")) {
Pattern compile = Pattern.compile("import\\s+(.*\\.req\\..*);");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
String group = matcher.group(1);
deptReqList.add(group);
}
} else if (!line.contains("frame")) {
} else if (line.contains("frame")) {
} else if (line.contains("javax.validation")) {
} else if (line.contains("org.hibernate.validator")) {
} else {
importList.add(line);
}
continue;
}
if (line.contains("/**") || line.contains("*") || line.contains("*/")) {
if (zs != null) {
zs.append(line + "\n");
annotationList.add(line);
if (line.contains("*/")) {
zs = null;
}
}
if ((line.contains("/**") || line.contains("*") || line.contains("*/")) && body.size() == 0) {
notesList.add(line);
}
if (line.contains("class")) {
line = line.replaceAll("\\{", " { ");
line = line.replaceAll("}", " } ");
line = line.replaceAll("\\s+", " ");
String[] split = line.split("\\s");
for (int i = 0; i < split.length; i++) {
if ("class".equals(split[i])) {
className = split[i + 1];
if (line.matches("public class (.*Request) extends (.*)Request\\s*\\{")) {
Pattern compile = Pattern.compile("public class (.*Request) extends (.*)Request\\s\\{");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
className = matcher.group(1);
fatherName = matcher.group(2);
if (fatherName.contains("BaseFindRequest")) {
hasList = true;
findOrSearchflag = "1";
}
if ("extends".equals(split[i])) {
fatherName = split[i + 1];
if (fatherName.contains("FindResponse") || fatherName.contains("GetAllResponse")) {
hasList = true;
Pattern pattern = Pattern.compile("<(.*?)>");
Matcher matcher = pattern.matcher(fatherName);
if (matcher.find()) {
String group = matcher.group(1);
Tclass = group;
}
}
if (fatherName.contains("FindRequest")) {
findOrSearchflag = "1";
} else if (fatherName.contains("SearchRequest")) {
findOrSearchflag = "2";
}
if (fatherName.contains("BaseGetAllRequest")) {
hasList = true;
findOrSearchflag = "2";
}
}
continue;
}
sb.append(line + "\n");
}
if (className != null) {
body.add(line);
if (line.matches("\\s*private\\s+(.*Request)\\s+(.*);")) {
body = new ArrayList<>(Arrays.asList(sb.substring(sb.indexOf("{")).split("\n")));
Pattern compile = Pattern.compile("\\s*private\\s+(.*Request)\\s+(.*);");
Matcher matcher = compile.matcher(line);
for (int i = 0; i < body.size(); i++) {
if (body.get(i).contains("{")) {
body.set(i, body.get(i).replaceAll("\\{", ""));
String s = body.get(i);
if (s.length() <= 1) {
body.remove(i);
if (matcher.find()) {
String group = matcher.group(1);
deptReqList.add(group);
}
}
break;
}
}
for (int i = body.size() - 1; i >= 0; i--) {
if (body.get(i).contains("}")) {
body.set(i, body.get(i).replaceAll("}", ""));
@ -150,14 +123,6 @@ public class RequestReader {
bufferedReader.close();
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getDomainName() {
return domainName;
}
@ -174,12 +139,12 @@ public class RequestReader {
this.moduleName = moduleName;
}
public List<String> getAnnotationList() {
return annotationList;
public List<String> getNotesList() {
return notesList;
}
public void setAnnotationList(List<String> annotationList) {
this.annotationList = annotationList;
public void setNotesList(List<String> notesList) {
this.notesList = notesList;
}
public List<String> getImportList() {

@ -8,11 +8,10 @@ import java.util.regex.Pattern;
public class ResponseReader {
private File javaClass;
private String packageName;
private String domainName;
private String moduleName;
private List<String> annotationList;
private List<String> importList;
private List<String> notesList;
private Set<String> deptReqList;
private Set<String> deptEntList;
private String className;
@ -25,9 +24,10 @@ public class ResponseReader {
public ResponseReader(File javaClass) throws IOException {
this.javaClass = javaClass;
importList = new ArrayList<>();
annotationList = new ArrayList<>();
notesList = new ArrayList<>();
deptReqList = new HashSet<>();
deptEntList = new HashSet<>();
body = new ArrayList<>();
domainName = "";
read();
}
@ -35,28 +35,14 @@ public class ResponseReader {
private void read() throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8"));
int step = 1;//1-读取package2-读取import3-读取类注释4-读取类名、父类5-读取类体
String line = null;
StringBuffer zs = new StringBuffer();
StringBuffer sb = new StringBuffer();
while ((line = bufferedReader.readLine()) != null) {
if (line.matches("\\s*package\\s(.*);")) {
{
Pattern compile = Pattern.compile("\\s*package\\s(.*);");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
packageName = matcher.group(1);
}
}
{
Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).rsp;");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
domainName = matcher.group(1);
moduleName = matcher.group(2);
}
Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).rsp;");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
domainName = matcher.group(1);
moduleName = matcher.group(2);
}
continue;
}
@ -80,60 +66,29 @@ public class ResponseReader {
}
continue;
}
if (line.contains("/**") || line.contains("*") || line.contains("*/")) {
if (zs != null) {
zs.append(line + "\n");
annotationList.add(line);
if (line.contains("*/")) {
zs = null;
}
}
if ((line.contains("/**") || line.contains("*") || line.contains("*/")) && body.size() == 0) {
notesList.add(line);
}
if (line.contains("class")) {
line = line.replaceAll("\\{", " { ");
line = line.replaceAll("}", " } ");
line = line.replaceAll("\\s+", " ");
String[] split = line.split("\\s");
for (int i = 0; i < split.length; i++) {
if ("class".equals(split[i])) {
className = split[i + 1];
}
if ("extends".equals(split[i])) {
fatherName = split[i + 1];
if (fatherName.contains("FindResponse") || fatherName.contains("GetAllResponse")) {
hasList = true;
Pattern pattern = Pattern.compile("<(.*?)>");
Matcher matcher = pattern.matcher(fatherName);
if (matcher.find()) {
String group = matcher.group(1);
Tclass = group;
}
}
if (fatherName.contains("FindRequest")) {
findOrSearchflag = "1";
} else if (fatherName.contains("SearchRequest")) {
findOrSearchflag = "2";
}
}
}
}
sb.append(line + "\n");
}
if (line.matches("public class (.*Response) extends (.*)Response\\s*\\{")) {
Pattern compile = Pattern.compile("public class (.*Response) extends (.*)Response\\s\\{");
Matcher matcher = compile.matcher(line);
body = new ArrayList<>(Arrays.asList(sb.substring(sb.indexOf("{")).split("\n")));
if (matcher.find()) {
className = matcher.group(1);
fatherName = matcher.group(2);
for (int i = 0; i < body.size(); i++) {
if (body.get(i).contains("{")) {
body.set(i, body.get(i).replaceAll("\\{", ""));
String s = body.get(i);
if (s.length() <= 1) {
body.remove(i);
if (fatherName.contains("BaseFindResponse")) {
hasList = true;
findOrSearchflag = "1";
}
}
break;
continue;
}
if (className != null) {
body.add(line);
}
}
for (int i = body.size() - 1; i >= 0; i--) {
if (body.get(i).contains("}")) {
body.set(i, body.get(i).replaceAll("}", ""));
@ -150,14 +105,6 @@ public class ResponseReader {
bufferedReader.close();
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getDomainName() {
return domainName;
}
@ -174,12 +121,12 @@ public class ResponseReader {
this.moduleName = moduleName;
}
public List<String> getAnnotationList() {
return annotationList;
public List<String> getNotesList() {
return notesList;
}
public void setAnnotationList(List<String> annotationList) {
this.annotationList = annotationList;
public void setNotesList(List<String> notesList) {
this.notesList = notesList;
}
public List<String> getImportList() {

@ -1,17 +1,14 @@
package ${domain}.${module}.req;
<#list importList as i>
<#if !i?contains("javax.validation") && !i?contains("org.hibernate.validator")>
${i}
</#if>
</#list>
<#list entNames as entName>
import ${domain}.${module}.ent.${entName};
</#list>
<#list reqNames as reqName>
import ${domain}.${module}.ent.${reqName};
</#list>
<#if !isTempReq>
import ${domain}.${module}.rsp.${className}Response;
</#if>
import ${domain}.ApiRequest;
<#if findOrSearchflag=='1'>
import ${domain}.ApiFindRequest;
@ -22,7 +19,19 @@ import ${domain}.ApiSearchRequest;
<#list annotation as i>
${i}
</#list>
public class ${className}Request <#if findOrSearchflag=='1'>extends ApiFindRequest<#elseif findOrSearchflag=='2'>extends ApiSearchRequest</#if> implements ApiRequest<${className}Response> {
<#if findOrSearchflag=='1' && !isTempReq>
public class ${className}Request extends ApiFindRequest implements ApiRequest<${className}Response> {
<#elseif findOrSearchflag=='1' && isTempReq>
public class ${className}Request extends ApiFindRequest implements ApiRequest {
<#elseif findOrSearchflag=='2' && !isTempReq>
public class ${className}Request extends ApiSearchRequest implements ApiRequest<${className}Response> {
<#elseif findOrSearchflag=='2' && isTempReq>
public class ${className}Request extends ApiSearchRequest implements ApiRequest {
<#elseif !isTempReq>
public class ${className}Request implements ApiRequest<${className}Response> {
<#elseif isTempReq>
public class ${className}Request implements ApiRequest {
</#if>
<#list body as i>
<#if !i?contains("@")>
@ -38,8 +47,13 @@ ${i}
return "${module}/${target}/${method}";
}
<#if !isTempReq>
public Class<${className}Response> responseClass() {
return ${className}Response.class;
}
<#elseif isTempReq>
public Class responseClass() {
return null;
}
</#if>
}

Loading…
Cancel
Save

Powered by TurnKey Linux.