add method search

This commit is contained in:
huoyo 2021-09-08 21:11:22 +08:00
parent 9c83800758
commit 50eb5bd2d4
7 changed files with 140 additions and 355 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.langpy</groupId>
<artifactId>ko-time</artifactId>
<version>2.0.3-PREPARE</version>
<version>2.0.3</version>
<name>koTime</name>
<description>koTime</description>
<licenses>

View File

@ -118,12 +118,25 @@ public class KoTimeController {
@GetMapping("/getApis")
@ResponseBody
@Auth
public List<MethodInfo> getApis() {
public List<MethodInfo> getApis(String question) {
GraphService graphService = GraphService.getInstance();
List<MethodInfo> list = graphService.getControllers();
List<MethodInfo> list = null;
if (StringUtils.hasText(question)) {
list = graphService.searchMethods(question);
}else {
list = graphService.getControllers();
}
Collections.sort(list);
return list;
}
@GetMapping("/getApiTips")
@ResponseBody
@Auth
public List<String> getApiTips(String question) {
GraphService graphService = GraphService.getInstance();
List<String> list = graphService.getCondidates(question);
return list;
}
@GetMapping("/getExceptions")

View File

@ -146,6 +146,53 @@ public class MemoryBase implements GraphService {
return methodInfos;
}
@Override
public List<MethodInfo> searchMethods(String question) {
List<MethodInfo> methodInfos = new ArrayList<>();
for (MethodNode methodNode : methodNodes.values()) {
if (methodNode.getName().toLowerCase().contains(question.toLowerCase())) {
String id = methodNode.getId();
Optional<MethodRelation> relations = methodRelations.values().stream().filter(methodRelation -> methodRelation.getTargetId().equals(id)).findFirst();
MethodRelation relation = null;
if (relations.isPresent()) {
relation = relations.get();
}else{
continue;
}
MethodInfo methodInfo = new MethodInfo();
methodInfo.setId(methodNode.getId());
methodInfo.setName(methodNode.getName());
methodInfo.setClassName(methodNode.getClassName());
methodInfo.setMethodName(methodNode.getMethodName());
methodInfo.setMethodType(methodNode.getMethodType());
methodInfo.setValue(relation.getAvgRunTime());
methodInfo.setAvgRunTime(relation.getAvgRunTime());
methodInfo.setMaxRunTime(relation.getMaxRunTime());
methodInfo.setMinRunTime(relation.getMinRunTime());
if (!methodInfos.contains(methodInfo)) {
methodInfos.add(methodInfo);
}
}
}
return methodInfos;
}
@Override
public List<String> getCondidates(String question) {
List<String> methodInfos = new ArrayList<>();
for (MethodNode methodNode : methodNodes.values()) {
if (methodNode.getName().toLowerCase().contains(question.toLowerCase())) {
if (!methodInfos.contains(methodNode.getName())) {
methodInfos.add(methodNode.getName());
}
}
if (methodInfos.size()>=10) {
break;
}
}
return methodInfos;
}
@Override
public List<ExceptionInfo> getExceptionInfos(String exceptionId) {
List<ExceptionInfo> exceptionInfos = new ArrayList<>();
@ -260,4 +307,5 @@ public class MemoryBase implements GraphService {
}
}
}

View File

@ -32,6 +32,16 @@ public class MysqlBase implements GraphService {
return null;
}
@Override
public List<String> getCondidates(String question) {
return null;
}
@Override
public List<MethodInfo> searchMethods(String question) {
return null;
}
@Override
public List<MethodInfo> getChildren(String methodId) {
return null;

View File

@ -9,6 +9,7 @@ import java.util.List;
public interface GraphService {
static GraphService getInstance() {
GraphService graphService = null;
if (Context.getConfig().getSaveSaver().equals("memory")) {
@ -27,8 +28,12 @@ public interface GraphService {
SystemStatistic getRunStatistic();
List<MethodInfo> searchMethods(String question);
List<MethodInfo> getControllers();
List<String> getCondidates(String question);
List<MethodInfo> getChildren(String methodId);
List<ExceptionInfo> getExceptionInfos(String exceptionId);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long