新增教练端,实现业务闭环:会员登录注册→查询团课→预约团课→扫码签到→教练端开课→记录实际开课时间→教练端结课→记录实际结课时间→后台查询数据

This commit is contained in:
2026-07-20 17:21:28 +08:00
parent df0e68469b
commit 4a4697c816
84 changed files with 6914 additions and 258 deletions
@@ -6,6 +6,7 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.time.LocalDateTime;
import java.util.Map;
/**
* 数据统计 DAO - 使用 DatabaseClient 执行跨表聚合查询
@@ -180,4 +181,68 @@ public class DataStatisticsDao {
this.count = count;
}
}
// ========== 教练相关统计 ==========
/** 统计教练总数(角色为"教练"的用户) */
public Mono<Long> countTotalCoaches() {
return databaseClient.sql("""
SELECT COUNT(*) FROM sys_user u
INNER JOIN user_role ur ON u.id = ur.user_id
INNER JOIN sys_role sr ON ur.role_id = sr.id
WHERE sr.role_name = '教练' AND u.deleted_at IS NULL
""")
.map(row -> row.get(0, Long.class))
.one();
}
/** 统计违规总数(时间范围) */
public Mono<Long> countTotalViolations(LocalDateTime startTime, LocalDateTime endTime) {
return databaseClient.sql("""
SELECT COUNT(*) FROM coach_violation
WHERE violation_time >= :startTime AND violation_time < :endTime AND deleted_at IS NULL
""")
.bind("startTime", startTime)
.bind("endTime", endTime)
.map(row -> row.get(0, Long.class))
.one();
}
/** 按违规类型统计次数 */
public Flux<Map<String, Object>> countViolationsByReason(LocalDateTime startTime, LocalDateTime endTime) {
return databaseClient.sql("""
SELECT violation_reason, COUNT(*) AS count
FROM coach_violation
WHERE violation_time >= :startTime AND violation_time < :endTime AND deleted_at IS NULL
GROUP BY violation_reason
""")
.bind("startTime", startTime)
.bind("endTime", endTime)
.fetch()
.all();
}
/** 统计有违规记录的教练数 */
public Mono<Long> countViolatedCoaches(LocalDateTime startTime, LocalDateTime endTime) {
return databaseClient.sql("""
SELECT COUNT(DISTINCT coach_id) FROM coach_violation
WHERE violation_time >= :startTime AND violation_time < :endTime AND deleted_at IS NULL
""")
.bind("startTime", startTime)
.bind("endTime", endTime)
.map(row -> row.get(0, Long.class))
.one();
}
/** 统计区间内开课的团课数 */
public Mono<Long> countCourses(LocalDateTime startTime, LocalDateTime endTime) {
return databaseClient.sql("""
SELECT COUNT(*) FROM group_course
WHERE start_time >= :startTime AND start_time < :endTime AND deleted_at IS NULL
""")
.bind("startTime", startTime)
.bind("endTime", endTime)
.map(row -> row.get(0, Long.class))
.one();
}
}
@@ -0,0 +1,40 @@
package cn.novalon.gym.manage.datacount.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 教练统计数据
*
* @author 张翔
* @date 2026-07-20
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CoachStatistics {
/** 教练总数 */
private Long totalCoaches;
/** 违规总数 */
private Long totalViolations;
/** 迟到次数 */
private Long lateCount;
/** 缺席次数 */
private Long absentCount;
/** 未手动结课次数 */
private Long notManualEndCount;
/** 有违规记录的教练数 */
private Long violatedCoaches;
/** 统计区间内开课的团课数 */
private Long totalCourses;
}
@@ -37,6 +37,11 @@ public class StatisticsSummary {
*/
private SignInStatistics signInStatistics;
/**
* 教练统计数据
*/
private CoachStatistics coachStatistics;
/**
* 统计数据生成时间
*/
@@ -171,18 +171,47 @@ public class DataStatisticsServiceImpl implements IDataStatisticsService {
return count != null ? count : 0L;
}
private Mono<CoachStatistics> getCoachStatistics(StatisticsQuery query) {
LocalDateTime startTime = getStartTime(query);
LocalDateTime endTime = getEndTime(query);
Mono<Long> totalCoachesMono = dataStatisticsDao.countTotalCoaches();
Mono<Long> totalViolationsMono = dataStatisticsDao.countTotalViolations(startTime, endTime);
Mono<Long> violatedCoachesMono = dataStatisticsDao.countViolatedCoaches(startTime, endTime);
Mono<Long> totalCoursesMono = dataStatisticsDao.countCourses(startTime, endTime);
Mono<Map<String, Long>> violationByReasonMono = dataStatisticsDao.countViolationsByReason(startTime, endTime)
.collectMap(row -> (String) row.get("violation_reason"),
row -> ((Number) row.get("count")).longValue());
return Mono.zip(totalCoachesMono, totalViolationsMono, violatedCoachesMono, totalCoursesMono, violationByReasonMono)
.map(tuple -> {
Map<String, Long> reasonMap = tuple.getT5();
return CoachStatistics.builder()
.totalCoaches(tuple.getT1())
.totalViolations(tuple.getT2())
.lateCount(reasonMap.getOrDefault("COACH_LATE", 0L))
.absentCount(reasonMap.getOrDefault("COACH_ABSENT", 0L))
.notManualEndCount(reasonMap.getOrDefault("NOT_MANUAL_END", 0L))
.violatedCoaches(tuple.getT3())
.totalCourses(tuple.getT4())
.build();
});
}
@Override
public Mono<StatisticsSummary> getStatisticsSummary(StatisticsQuery query) {
Mono<MemberStatistics> memberStatsMono = getMemberStatistics(query);
Mono<BookingStatistics> bookingStatsMono = getBookingStatistics(query);
Mono<SignInStatistics> signInStatsMono = getSignInStatistics(query);
Mono<CoachStatistics> coachStatsMono = getCoachStatistics(query);
return Mono.zip(memberStatsMono, bookingStatsMono, signInStatsMono)
return Mono.zip(memberStatsMono, bookingStatsMono, signInStatsMono, coachStatsMono)
.map(tuple -> StatisticsSummary.builder()
.statDate(LocalDateTime.now().toLocalDate().toString())
.memberStatistics(tuple.getT1())
.bookingStatistics(tuple.getT2())
.signInStatistics(tuple.getT3())
.coachStatistics(tuple.getT4())
.generatedAt(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))
.build());
}