feat: add admin site stats page with DAU chart

This commit is contained in:
Tim
2025-07-14 21:39:01 +08:00
parent 1b09a8c7ae
commit 40331886df
9 changed files with 204 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
@RestController
@@ -23,4 +24,15 @@ public class StatController {
long count = userVisitService.countDau(date);
return Map.of("dau", count);
}
@GetMapping("/dau-range")
public List<Map<String, Object>> dauRange(@RequestParam(value = "days", defaultValue = "30") int days) {
if (days < 1) days = 1;
LocalDate end = LocalDate.now();
LocalDate start = end.minusDays(days - 1L);
var data = userVisitService.countDauRange(start, end);
return data.entrySet().stream()
.map(e -> Map.of("date", e.getKey().toString(), "value", e.getValue()))
.toList();
}
}