master
wangbing 5 years ago
parent 9bfda0171c
commit 28c2bec7b1

@ -18,6 +18,8 @@ import javafx.util.Callback;
import javafx.util.converter.DefaultStringConverter; import javafx.util.converter.DefaultStringConverter;
import xyz.wbsite.dbtool.javafx.po.ApiMethod; import xyz.wbsite.dbtool.javafx.po.ApiMethod;
import xyz.wbsite.dbtool.javafx.po.Doc; import xyz.wbsite.dbtool.javafx.po.Doc;
import xyz.wbsite.dbtool.javafx.po.DocEnt;
import xyz.wbsite.dbtool.javafx.po.DocParam;
import xyz.wbsite.dbtool.javafx.tool.DocClassReader; import xyz.wbsite.dbtool.javafx.tool.DocClassReader;
import xyz.wbsite.dbtool.javafx.tool.DocRequestReader; import xyz.wbsite.dbtool.javafx.tool.DocRequestReader;
import xyz.wbsite.dbtool.javafx.tool.DocResponseReader; import xyz.wbsite.dbtool.javafx.tool.DocResponseReader;
@ -176,6 +178,12 @@ public class OptionDocController {
// doc.setFind("1".equals(docRequestReader.getFindOrSearchflag())); // doc.setFind("1".equals(docRequestReader.getFindOrSearchflag()));
doc.setTitle(docRequestReader.getClassNote()); doc.setTitle(docRequestReader.getClassNote());
doc.setReqParams(docRequestReader.getFieldDocList()); doc.setReqParams(docRequestReader.getFieldDocList());
for (String key : docRequestReader.getEnts().keySet()) {
List<DocParam> docParams = docRequestReader.getEnts().get(key);
DocEnt docEnt = new DocEnt();
docEnt.setEntParams(docParams);
doc.addParams(key.split("#")[1], docEnt);
}
} }
List<File> rspfiles = Tool.findResponse(moduleFile, apiMethod.getResponse() + ".java"); List<File> rspfiles = Tool.findResponse(moduleFile, apiMethod.getResponse() + ".java");
@ -186,6 +194,12 @@ public class OptionDocController {
} else { } else {
DocResponseReader docResponseReader = new DocResponseReader(rspfiles.get(0)); DocResponseReader docResponseReader = new DocResponseReader(rspfiles.get(0));
doc.setRspParams(docResponseReader.getFieldDocList()); doc.setRspParams(docResponseReader.getFieldDocList());
for (String key : docResponseReader.getEnts().keySet()) {
List<DocParam> docParams = docResponseReader.getEnts().get(key);
DocEnt docEnt = new DocEnt();
docEnt.setEntParams(docParams);
doc.addParams(key.split("#")[1], docEnt);
}
} }
doc.setCheck(true); doc.setCheck(true);
@ -249,6 +263,7 @@ public class OptionDocController {
initData(); initData();
} }
System.out.println();
} }
public List<String> findEntities(File file) { public List<String> findEntities(File file) {

@ -23,7 +23,6 @@ public class Doc {
this.check.set(check); this.check.set(check);
} }
//目标请求对象 //目标请求对象
private String request; private String request;
//目标请求响应 //目标请求响应
@ -122,6 +121,13 @@ public class Doc {
this.entParams = entParams; this.entParams = entParams;
} }
public void addParams(String name, DocEnt ent) {
if (this.entParams == null) {
this.entParams = new HashMap<>();
}
this.entParams.put(name, ent);
}
public String getTitle() { public String getTitle() {
return title; return title;
} }

@ -1,31 +1,16 @@
package xyz.wbsite.dbtool.javafx.po; package xyz.wbsite.dbtool.javafx.po;
public class DocEnt { import java.util.ArrayList;
private String name; import java.util.List;
private String type;
private String note;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() { public class DocEnt {
return type; private List<DocParam> entParams = new ArrayList<>();
}
public void setType(String type) {
this.type = type;
}
public String getNote() { public List<DocParam> getEntParams() {
return note; return entParams;
} }
public void setNote(String note) { public void setEntParams(List<DocParam> entParams) {
this.note = note; this.entParams = entParams;
} }
} }

@ -54,9 +54,9 @@ public class DocRequestReader extends RequestReader {
Matcher matcher = compile.matcher(s); Matcher matcher = compile.matcher(s);
if (matcher.find()) { if (matcher.find()) {
String type = matcher.group(1); String type = matcher.group(1);
docParam.setName(matcher.group(2));
docParam.setType(type); docParam.setType(type);
if (!Tool.getJavaField().contains(type)) {//读取自定义对象 if (!Tool.getJavaField().contains(type)) {//读取自定义对象
if (type.endsWith("Request")) { if (type.endsWith("Request")) {
String module = null; String module = null;
for (String s1 : getImportList()) { for (String s1 : getImportList()) {
@ -106,7 +106,6 @@ public class DocRequestReader extends RequestReader {
} }
} }
} }
docParam.setName(matcher.group(2));
fieldDocList.add(docParam); fieldDocList.add(docParam);
docParam = new DocParam(); docParam = new DocParam();
} }
@ -133,4 +132,12 @@ public class DocRequestReader extends RequestReader {
public void setClassNote(String classNote) { public void setClassNote(String classNote) {
this.classNote = classNote; this.classNote = classNote;
} }
public Map<String, List<DocParam>> getEnts() {
return ents;
}
public void setEnts(Map<String, List<DocParam>> ents) {
this.ents = ents;
}
} }

@ -5,16 +5,21 @@ import xyz.wbsite.dbtool.web.frame.utils.MapperUtil;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class DocResponseReader extends ResponseReader { public class DocResponseReader extends ResponseReader {
private List<DocParam> fieldDocList; private List<DocParam> fieldDocList;
private Map<String, List<DocParam>> ents;
public DocResponseReader(File javaClass) { public DocResponseReader(File javaClass) {
super(javaClass); super(javaClass);
fieldDocList = new ArrayList<>(); fieldDocList = new ArrayList<>();
ents = new HashMap<>();
DocParam docParam = new DocParam(); DocParam docParam = new DocParam();
for (String s : getBody()) { for (String s : getBody()) {
s = s.trim(); s = s.trim();
@ -31,8 +36,59 @@ public class DocResponseReader extends ResponseReader {
Pattern compile = Pattern.compile("private\\s(.*)\\s(.*);"); Pattern compile = Pattern.compile("private\\s(.*)\\s(.*);");
Matcher matcher = compile.matcher(s); Matcher matcher = compile.matcher(s);
if (matcher.find()) { if (matcher.find()) {
docParam.setType(matcher.group(1)); String type = matcher.group(1);
docParam.setName(matcher.group(2)); docParam.setName(matcher.group(2));
docParam.setType(type);
if (!Tool.getJavaField().contains(type)) {//读取自定义对象
if (type.endsWith("Request")) {
String module = null;
for (String s1 : getImportList()) {
Pattern compile1 = Pattern.compile("import\\s+.*\\.module\\.(.*)\\.req\\." + type);
Matcher matcher1 = compile1.matcher(s1);
if (matcher1.find()) {
module = matcher1.group(1);
}
}
if (module == null) {// 同目录下查找
List<File> files = Tool.find(this.getJavaClass().getParentFile().getParentFile(), type + ".java");
if (files.size() == 1) {
DocRequestReader docRequestReader = new DocRequestReader(files.get(0));
ents.put(docRequestReader.getModuleName() + "#" + type, docRequestReader.getFieldDocList());
}
} else {//其他模块下查找
File path = Tool.createPath(this.getJavaClass().getParentFile().getParentFile().getParentFile(), module);
List<File> files = Tool.find(path, type + ".java");
if (files.size() == 1) {
DocRequestReader docRequestReader = new DocRequestReader(files.get(0));
ents.put(docRequestReader.getModuleName() + "#" + type, docRequestReader.getFieldDocList());
}
}
} else {
String module = null;
for (String s1 : getImportList()) {
Pattern compile1 = Pattern.compile("import\\s+.*\\.module\\.(.*)\\.ent\\." + type);
Matcher matcher1 = compile1.matcher(s1);
if (matcher1.find()) {
module = matcher1.group(1);
}
}
if (module == null) {// 同目录下查找
List<File> files = Tool.find(this.getJavaClass().getParentFile().getParentFile(), type + ".java");
if (files.size() == 1) {
DocEntityReader docEntityReader = new DocEntityReader(files.get(0));
ents.put(docEntityReader.getModuleName() + "#" + type, docEntityReader.getFieldDocList());
}
} else {//其他模块下查找
File path = Tool.createPath(this.getJavaClass().getParentFile().getParentFile().getParentFile(), module);
List<File> files = Tool.find(path, type + ".java");
if (files.size() == 1) {
DocEntityReader docEntityReader = new DocEntityReader(files.get(0));
ents.put(docEntityReader.getModuleName() + "#" + type, docEntityReader.getFieldDocList());
}
}
}
}
fieldDocList.add(docParam); fieldDocList.add(docParam);
docParam = new DocParam(); docParam = new DocParam();
} }
@ -51,4 +107,12 @@ public class DocResponseReader extends ResponseReader {
public void setFieldDocList(List<DocParam> fieldDocList) { public void setFieldDocList(List<DocParam> fieldDocList) {
this.fieldDocList = fieldDocList; this.fieldDocList = fieldDocList;
} }
public Map<String, List<DocParam>> getEnts() {
return ents;
}
public void setEnts(Map<String, List<DocParam>> ents) {
this.ents = ents;
}
} }

@ -47,7 +47,7 @@
<th>说明</th> <th>说明</th>
</tr> </tr>
<tr v-for="p in select.reqParams"> <tr v-for="p in select.reqParams">
<td>{{p.name}}</td> <td v-if="p.type == 'Object'"><a href="#{{p.name}}">{{p.name}}</a></td>
<td>{{p.type}}</td> <td>{{p.type}}</td>
<td v-if="p.required && p.name" style="color: red"></td> <td v-if="p.required && p.name" style="color: red"></td>
<td v-if="!p.required && p.name"></td> <td v-if="!p.required && p.name"></td>
@ -72,7 +72,7 @@
<th>说明</th> <th>说明</th>
</tr> </tr>
<tr v-for="p in select.rspParams"> <tr v-for="p in select.rspParams">
<td v-if="p.type == 'Object'"><a href="#User">{{p.name}}</a></td> <td v-if="p.type == 'Object'"><a href="#{{p.name}}">{{p.name}}</a></td>
<td v-if="p.type != 'Object'">{{p.name}}</td> <td v-if="p.type != 'Object'">{{p.name}}</td>
<td>{{p.type}}</td> <td>{{p.type}}</td>
<td>{{p.note}}</td> <td>{{p.note}}</td>
@ -108,16 +108,16 @@
<pre>Assert.assertTrue(!response.hasError());</pre> <pre>Assert.assertTrue(!response.hasError());</pre>
</div> </div>
<h5 id="User">附录参数(<span class="object">User</span>)</h5> <div class="wrapper" v-for="item in select.entList">
<h5 id="User">附录参数(<span class="object">{{item.name}}</span>)</h5>
<div class="wrapper">
<table> <table>
<tr> <tr>
<th width="200">参数</th> <th width="200">参数</th>
<th width="100">类型</th> <th width="100">类型</th>
<th>说明</th> <th>说明</th>
</tr> </tr>
<tr v-for="p in select.entParams"> <tr v-for="p in item.entParams">
<td v-if="p.type == 'Object'"><a href="javascript:;">{{p.name}}</a></td> <td v-if="p.type == 'Object'"><a href="javascript:;">{{p.name}}</a></td>
<td v-if="p.type != 'Object'">{{p.name}}</td> <td v-if="p.type != 'Object'">{{p.name}}</td>
<td>{{p.type}}</td> <td>{{p.type}}</td>

@ -34,11 +34,11 @@ var app = new Vue({
</#list> </#list>
], ],
"entList": [ "entList": [
<#list item.entParams?keys as key> <#list item.entParams as key,value>
{ {
"name": "${key}", "name": "${key}",
"params": [ "entParams": [
<#list item.entParams[key] as param> <#list value.entParams as param>
{ {
"name": "${param.name?default('')}", "name": "${param.name?default('')}",
"type": "${param.type?default('')}", "type": "${param.type?default('')}",

Loading…
Cancel
Save

Powered by TurnKey Linux.