feat: 新增DashboardController统计接口
This commit is contained in:
parent
b3d8874496
commit
76c7eeb553
1 changed files with 85 additions and 0 deletions
|
|
@ -0,0 +1,85 @@
|
||||||
|
package edu.situ.stlserver.controller;
|
||||||
|
|
||||||
|
import edu.situ.stlserver.model.vo.HttpResult;
|
||||||
|
import edu.situ.stlserver.service.CourseService;
|
||||||
|
import edu.situ.stlserver.service.CoachService;
|
||||||
|
import edu.situ.stlserver.service.MemberService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/dashboard")
|
||||||
|
public class DashboardController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CoachService coachService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MemberService memberService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CourseService courseService;
|
||||||
|
|
||||||
|
@GetMapping("/stats")
|
||||||
|
public HttpResult getStats() {
|
||||||
|
Map<String, Object> stats = new HashMap<>();
|
||||||
|
// 教练总数
|
||||||
|
stats.put("coachCount", coachService.getAll().size());
|
||||||
|
// 会员总数
|
||||||
|
stats.put("memberCount", memberService.getAll().size());
|
||||||
|
// 课程总数
|
||||||
|
stats.put("courseCount", courseService.getAll().size());
|
||||||
|
// 在职教练数
|
||||||
|
long activeCoachCount = coachService.getAll().stream()
|
||||||
|
.filter(c -> c.getQuitDate() == null)
|
||||||
|
.count();
|
||||||
|
stats.put("activeCoachCount", activeCoachCount);
|
||||||
|
// 有效会员数
|
||||||
|
long activeMemberCount = memberService.getAll().stream()
|
||||||
|
.filter(m -> m.getExpireDate() == null)
|
||||||
|
.count();
|
||||||
|
stats.put("activeMemberCount", activeMemberCount);
|
||||||
|
// 进行中课程数
|
||||||
|
long activeCourseCount = courseService.getAll().stream()
|
||||||
|
.filter(c -> "进行中".equals(c.getStatus()))
|
||||||
|
.count();
|
||||||
|
stats.put("activeCourseCount", activeCourseCount);
|
||||||
|
return HttpResult.success(stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/member-level")
|
||||||
|
public HttpResult getMemberLevel() {
|
||||||
|
Map<String, Long> levelMap = new HashMap<>();
|
||||||
|
levelMap.put("钻石", memberService.getAll().stream().filter(m -> "钻石".equals(m.getLevel())).count());
|
||||||
|
levelMap.put("金卡", memberService.getAll().stream().filter(m -> "金卡".equals(m.getLevel())).count());
|
||||||
|
levelMap.put("银卡", memberService.getAll().stream().filter(m -> "银卡".equals(m.getLevel())).count());
|
||||||
|
levelMap.put("普通", memberService.getAll().stream().filter(m -> "普通".equals(m.getLevel())).count());
|
||||||
|
return HttpResult.success(levelMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/course-type")
|
||||||
|
public HttpResult getCourseType() {
|
||||||
|
Map<String, Long> typeMap = new HashMap<>();
|
||||||
|
courseService.getAll().forEach(c -> {
|
||||||
|
typeMap.merge(c.getType(), 1L, Long::sum);
|
||||||
|
});
|
||||||
|
return HttpResult.success(typeMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/member-trend")
|
||||||
|
public HttpResult getMemberTrend() {
|
||||||
|
Map<String, Long> trendMap = new HashMap<>();
|
||||||
|
memberService.getAll().forEach(m -> {
|
||||||
|
String month = m.getJoinDate().substring(0, 7); // yyyy-MM
|
||||||
|
trendMap.merge(month, 1L, Long::sum);
|
||||||
|
});
|
||||||
|
// 按月份排序
|
||||||
|
Map<String, Long> sortedMap = new java.util.TreeMap<>(trendMap);
|
||||||
|
return HttpResult.success(sortedMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue