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> <groupId>cn.langpy</groupId>
<artifactId>ko-time</artifactId> <artifactId>ko-time</artifactId>
<version>2.0.3-PREPARE</version> <version>2.0.3</version>
<name>koTime</name> <name>koTime</name>
<description>koTime</description> <description>koTime</description>
<licenses> <licenses>

View File

@ -118,12 +118,25 @@ public class KoTimeController {
@GetMapping("/getApis") @GetMapping("/getApis")
@ResponseBody @ResponseBody
@Auth @Auth
public List<MethodInfo> getApis() { public List<MethodInfo> getApis(String question) {
GraphService graphService = GraphService.getInstance(); 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); Collections.sort(list);
return 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") @GetMapping("/getExceptions")

View File

@ -146,6 +146,53 @@ public class MemoryBase implements GraphService {
return methodInfos; 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 @Override
public List<ExceptionInfo> getExceptionInfos(String exceptionId) { public List<ExceptionInfo> getExceptionInfos(String exceptionId) {
List<ExceptionInfo> exceptionInfos = new ArrayList<>(); 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; return null;
} }
@Override
public List<String> getCondidates(String question) {
return null;
}
@Override
public List<MethodInfo> searchMethods(String question) {
return null;
}
@Override @Override
public List<MethodInfo> getChildren(String methodId) { public List<MethodInfo> getChildren(String methodId) {
return null; return null;

View File

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