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

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

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

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

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

Loading…
Cancel
Save

Powered by TurnKey Linux.