Prechádzať zdrojové kódy

更新 search-service 的 log 包

reghao 2 mesiacov pred
rodič
commit
9b624cef81

+ 1 - 8
search/search-service/src/main/java/cn/reghao/tnb/search/app/log/controller/NginxLogController.java

@@ -42,13 +42,6 @@ public class NginxLogController {
         return WebResult.success(total);
     }
 
-    @Operation(summary = "不超过 24 小时", description = "N")
-    @PostMapping(value = "/log2", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String nginxLog2(@RequestBody @Validated DateTimeQuery dateTimeQuery) {
-        List<Object> chartData = nginxLogService.getNginxLog2(dateTimeQuery);
-        return WebResult.success(chartData);
-    }
-
     @Operation(summary = "指定日期和 url 的最近一周内 NginxLog 在每天的数量", description = "N")
     @GetMapping(value = "/log/chart5", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getLogChart5(@Validated DateTimeQuery dateTimeQuery) {
@@ -81,6 +74,6 @@ public class NginxLogController {
     @GetMapping(value = "/log/chart6", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getLogChart6(@Validated LogQuery logQuery) {
         ChartMap chartMap = nginxLogService.getChartMap(logQuery);
-        return chartMap != null ? WebResult.success(chartMap) : WebResult.failWithMsg("");
+        return chartMap != null ? WebResult.success(chartMap) : WebResult.failWithMsg("aggregateField unknown");
     }
 }

+ 1 - 0
search/search-service/src/main/java/cn/reghao/tnb/search/app/log/model/dto/LogQuery.java

@@ -19,6 +19,7 @@ public class LogQuery {
     @NotBlank
     @DateVerify(dateFormat = "yyyy-MM-dd")
     private String dateStr;
+    // aggregateField 和 url 只能同时存在一个
     private String aggregateField;
     private String url;
 }

+ 13 - 21
search/search-service/src/main/java/cn/reghao/tnb/search/app/log/service/NginxLogService.java

@@ -83,27 +83,6 @@ public class NginxLogService {
                 .collect(Collectors.toList());
     }
 
-    public List<Object> getNginxLog2(DateTimeQuery dateTimeQuery) {
-        try {
-            String start = dateTimeQuery.getStart();
-            LocalDateTime start1 = DateTimeConverter.localDateTime2(start);
-            String end = dateTimeQuery.getEnd();
-            LocalDateTime end1 = DateTimeConverter.localDateTime2(end);
-
-            Duration duration = Duration.between(start1, end1);
-            long days = duration.toHours();
-            if (days < 0) {
-                return Collections.emptyList();
-            } else if (days > 24) {
-                return Collections.emptyList();
-            }
-        } catch (Exception e) {
-            // ignore
-        }
-
-        return null;
-    }
-
     public List<ChartData> getTopN(String dateStr) {
         int pageSize = 100;
         int pageNumber = 1;
@@ -307,6 +286,19 @@ public class NginxLogService {
     }
 
     public List<Object> getChartData5(DateTimeQuery dateTimeQuery) {
+        try {
+            LocalDateTime start = DateTimeConverter.localDateTime2(dateTimeQuery.getStart());
+            LocalDateTime end = DateTimeConverter.localDateTime2(dateTimeQuery.getEnd());
+            Duration duration = Duration.between(start, end);
+            long days = duration.toDays();
+            long hours = duration.toHours();
+            if (days < 0 || days > 7) {
+                return Collections.emptyList();
+            }
+        } catch (Exception e) {
+            // ignore
+        }
+
         String aggregateField = "timeIso8601";
         String fieldName = "methodUrl.raw";