diff --git a/src/main/java/cn/langpy/kotime/controller/KoTimeController.java b/src/main/java/cn/langpy/kotime/controller/KoTimeController.java index 965e3c4..41a9038 100644 --- a/src/main/java/cn/langpy/kotime/controller/KoTimeController.java +++ b/src/main/java/cn/langpy/kotime/controller/KoTimeController.java @@ -13,6 +13,7 @@ import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.io.*; import java.util.*; import java.util.logging.Logger; @@ -72,6 +73,32 @@ public class KoTimeController { return list; } + @GetMapping("/exportApis") + @ResponseBody + @Auth + public void exportApis(String question, String orderBy, String sort, HttpServletResponse response) { + List apis = getApis(question, orderBy, sort); + response.setCharacterEncoding("utf-8"); + response.addHeader("Content-Disposition", "attachment; filename=interfaces.csv"); + + try( OutputStream out = response.getOutputStream(); + BufferedOutputStream bufferedOut = new BufferedOutputStream(out)){ + String line = "序号,类名,方法名,路由,平均响应(ms),调用次数\n"; + if ("english".equals(Context.getConfig().getLanguage())) { + line = "No,ClassName,Method,Route,Avg(ms),CallNum\n"; + } + bufferedOut.write(line.getBytes("utf-8")); + for (int i = 0; i < apis.size(); i++) { + MethodInfo methodInfo = apis.get(i); + line = (i+1)+","+methodInfo.getClassName()+","+methodInfo.getMethodName()+"(),"+methodInfo.getRouteName()+","+methodInfo.getAvgRunTime()+","+methodInfo.getCallNum()+"\n"; + bufferedOut.write(line.getBytes("utf-8")); + } + bufferedOut.flush(); + }catch (Exception e){ + e.printStackTrace(); + } + } + @GetMapping("/getParamGraph") @ResponseBody @Auth diff --git a/src/main/resources/koapp.properties b/src/main/resources/koapp.properties index 3de7387..10c98e6 100644 --- a/src/main/resources/koapp.properties +++ b/src/main/resources/koapp.properties @@ -1 +1 @@ -ko-time.version=2.4.6 \ No newline at end of file +ko-time.version=2.4.8 \ No newline at end of file diff --git a/src/main/resources/kostatic/dict/chinese.properties b/src/main/resources/kostatic/dict/chinese.properties index 92b3714..fc5724c 100644 --- a/src/main/resources/kostatic/dict/chinese.properties +++ b/src/main/resources/kostatic/dict/chinese.properties @@ -42,6 +42,8 @@ tab.summary.sysusage-metric.physical-memory.current-used=此程序占用 tab.interface.search-tip=搜索方法名或者类名... tab.interface.interface-list.avg-tip=平均响应 +tab.interface.interface-list.sort-desc-tip=降序 +tab.interface.interface-list.sort-asc-tip=升序 tab.interface.interface-list.call-num-tip=调用次数 tab.interface.interface-list.show-metric.type=类型 tab.interface.interface-list.show-metric.avg=平均耗时 diff --git a/src/main/resources/kostatic/dict/english.properties b/src/main/resources/kostatic/dict/english.properties index c752c7e..34c9a45 100644 --- a/src/main/resources/kostatic/dict/english.properties +++ b/src/main/resources/kostatic/dict/english.properties @@ -42,6 +42,8 @@ tab.summary.sysusage-metric.physical-memory.current-used=ThisUsed tab.interface.search-tip=search method name or class name... tab.interface.interface-list.avg-tip=avg +tab.interface.interface-list.sort-desc-tip=desc +tab.interface.interface-list.sort-asc-tip=asc tab.interface.interface-list.call-num-tip=callNum tab.interface.interface-list.show-metric.type=type tab.interface.interface-list.show-metric.avg=avg time diff --git a/src/main/resources/kotime.html b/src/main/resources/kotime.html index 6637670..b4723fe 100644 --- a/src/main/resources/kotime.html +++ b/src/main/resources/kotime.html @@ -92,11 +92,11 @@ className = data[i]['name'].split('.')[0]; } if (methodType == 'Controller' && routeName != null && routeName != '') { - html += "
  • " + className + "#" + methodName + " (" + routeName + ")   {{tab.interface.interface-list.avg-tip}} " + avgRunTime + " ms" + + html += "
  • " + className + "#" + methodName + "()  <" + routeName + ">    {{tab.interface.interface-list.avg-tip}} " + avgRunTime + " ms" + "   {{tab.interface.interface-list.call-num-tip}} " + callNum + "
  • "; } else { - html += "
  • " + className + "#" + methodName + "   {{tab.interface.interface-list.avg-tip}} " + avgRunTime + " ms" + - "   {{tab.interface.interface-list.call-num-tip}} " + callNum + "
  • "; + html += "
  • " + className + "#" + methodName + "()   {{tab.interface.interface-list.avg-tip}} " + avgRunTime + " ms" + + "   {{tab.interface.interface-list.call-num-tip}} " + callNum + "
  • "; } }; element.innerHTML = html; @@ -633,6 +633,19 @@ loadApis(); } + function exportApis() { + let searchDom = getDom("searchText"); + let searchText = searchDom.value; + let apiSortName = getDom('apiSortName') + let apiSortType = getDom('apiSortType') + let url = concatToken(`contextPath/koTime/exportApis?question=${searchText}&orderBy=${apiSortName.value}&sort=${apiSortType.value}`); + let a = document.createElement("a"); + a.style.display='none'; + a.href = url; + a.click(); + setTimeout(()=>{a.remove();},3000); + } + $(document).ready(function () { refreshData(); }); @@ -805,18 +818,19 @@
    - + +
    -
    - + + +