新增教练端,实现业务闭环:会员登录注册→查询团课→预约团课→扫码签到→教练端开课→记录实际开课时间→教练端结课→记录实际结课时间→后台查询数据
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.novalon.gym.manage</groupId>
|
||||
<artifactId>gym-manage-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>gym-coach</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Gym Coach</name>
|
||||
<description>Coach Management Module - Course Start/End, Violation Tracking</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.novalon.gym.manage</groupId>
|
||||
<artifactId>manage-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.novalon.gym.manage</groupId>
|
||||
<artifactId>manage-db</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.novalon.gym.manage</groupId>
|
||||
<artifactId>manage-sys</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.novalon.gym.manage</groupId>
|
||||
<artifactId>gym-groupCourse</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package cn.novalon.gym.manage.coach.dao;
|
||||
|
||||
import cn.novalon.gym.manage.coach.entity.CoachViolationEntity;
|
||||
import org.springframework.data.r2dbc.repository.R2dbcRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 教练违规记录 DAO
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-07-20
|
||||
*/
|
||||
@Repository
|
||||
public interface CoachViolationDao extends R2dbcRepository<CoachViolationEntity, Long> {
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package cn.novalon.gym.manage.coach.entity;
|
||||
|
||||
import cn.novalon.gym.manage.db.entity.BaseEntity;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 教练违规记录实体类 - 对应 coach_violation 表
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-07-20
|
||||
*/
|
||||
@Table("coach_violation")
|
||||
public class CoachViolationEntity extends BaseEntity {
|
||||
|
||||
@Column("coach_id")
|
||||
private Long coachId;
|
||||
|
||||
@Column("course_id")
|
||||
private Long courseId;
|
||||
|
||||
@Column("violation_time")
|
||||
private LocalDateTime violationTime;
|
||||
|
||||
@Column("violation_reason")
|
||||
private String violationReason;
|
||||
|
||||
public Long getCoachId() {
|
||||
return coachId;
|
||||
}
|
||||
|
||||
public void setCoachId(Long coachId) {
|
||||
this.coachId = coachId;
|
||||
}
|
||||
|
||||
public Long getCourseId() {
|
||||
return courseId;
|
||||
}
|
||||
|
||||
public void setCourseId(Long courseId) {
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public LocalDateTime getViolationTime() {
|
||||
return violationTime;
|
||||
}
|
||||
|
||||
public void setViolationTime(LocalDateTime violationTime) {
|
||||
this.violationTime = violationTime;
|
||||
}
|
||||
|
||||
public String getViolationReason() {
|
||||
return violationReason;
|
||||
}
|
||||
|
||||
public void setViolationReason(String violationReason) {
|
||||
this.violationReason = violationReason;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package cn.novalon.gym.manage.coach.enums;
|
||||
|
||||
/**
|
||||
* 团课预约状态枚举
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-07-20
|
||||
*/
|
||||
public enum BookingStatus {
|
||||
|
||||
BOOKED("0", "已预约"),
|
||||
CANCELLED("1", "已取消"),
|
||||
ATTENDED("2", "已出席"),
|
||||
ABSENT("3", "缺席"),
|
||||
COACH_ABSENT("4", "教练缺席"),
|
||||
LATE("5", "迟到");
|
||||
|
||||
private final String value;
|
||||
private final String desc;
|
||||
|
||||
BookingStatus(String value, String desc) {
|
||||
this.value = value;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public static BookingStatus fromValue(String value) {
|
||||
for (BookingStatus status : values()) {
|
||||
if (status.value.equals(value)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return BOOKED;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package cn.novalon.gym.manage.coach.enums;
|
||||
|
||||
/**
|
||||
* 教练违规原因枚举
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-07-20
|
||||
*/
|
||||
public enum ViolationReason {
|
||||
|
||||
COACH_LATE("COACH_LATE", "教练迟到"),
|
||||
COACH_ABSENT("COACH_ABSENT", "教练缺席"),
|
||||
NOT_MANUAL_END("NOT_MANUAL_END", "教练未手动结课");
|
||||
|
||||
private final String value;
|
||||
private final String desc;
|
||||
|
||||
ViolationReason(String value, String desc) {
|
||||
this.value = value;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package cn.novalon.gym.manage.coach.handler;
|
||||
|
||||
import cn.novalon.gym.manage.coach.service.CoachCourseService;
|
||||
import cn.novalon.gym.manage.sys.util.AuthUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 教练开课/结课处理器
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-07-20
|
||||
*/
|
||||
@Component
|
||||
@Tag(name = "教练开课结课", description = "教练开课与结课操作")
|
||||
public class CoachCourseHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CoachCourseHandler.class);
|
||||
private final CoachCourseService coachCourseService;
|
||||
private final AuthUtil authUtil;
|
||||
|
||||
public CoachCourseHandler(CoachCourseService coachCourseService, AuthUtil authUtil) {
|
||||
this.coachCourseService = coachCourseService;
|
||||
this.authUtil = authUtil;
|
||||
}
|
||||
|
||||
@Operation(summary = "教练开课", description = "教练手动开课,记录实际开课时间,若超时则判定迟到")
|
||||
public Mono<ServerResponse> startCourse(ServerRequest request) {
|
||||
Long courseId = Long.valueOf(request.pathVariable("courseId"));
|
||||
Long coachId = authUtil.getMemberIdOrThrow(request);
|
||||
|
||||
return coachCourseService.startCourse(courseId, coachId)
|
||||
.flatMap(result -> ServerResponse.ok().bodyValue(Map.of(
|
||||
"message", "开课成功",
|
||||
"status", result.getStatus(),
|
||||
"actualStartTime", result.getActualStartTime() != null ? result.getActualStartTime().toString() : ""
|
||||
)))
|
||||
.onErrorResume(e -> {
|
||||
logger.error("开课失败: {}", e.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(Map.of("error", e.getMessage()));
|
||||
});
|
||||
}
|
||||
|
||||
@Operation(summary = "教练结课", description = "教练手动结课,记录实际结课时间")
|
||||
public Mono<ServerResponse> endCourse(ServerRequest request) {
|
||||
Long courseId = Long.valueOf(request.pathVariable("courseId"));
|
||||
Long coachId = authUtil.getMemberIdOrThrow(request);
|
||||
|
||||
return coachCourseService.endCourse(courseId, coachId)
|
||||
.flatMap(result -> ServerResponse.ok().bodyValue(Map.of(
|
||||
"message", "结课成功",
|
||||
"status", result.getStatus(),
|
||||
"actualEndTime", result.getActualEndTime() != null ? result.getActualEndTime().toString() : ""
|
||||
)))
|
||||
.onErrorResume(e -> {
|
||||
logger.error("结课失败: {}", e.getMessage());
|
||||
return ServerResponse.badRequest().bodyValue(Map.of("error", e.getMessage()));
|
||||
});
|
||||
}
|
||||
}
|
||||
+27
-11
@@ -1,6 +1,6 @@
|
||||
package cn.novalon.gym.manage.app.handler;
|
||||
package cn.novalon.gym.manage.coach.handler;
|
||||
|
||||
import cn.novalon.gym.manage.app.service.CoachService;
|
||||
import cn.novalon.gym.manage.coach.service.CoachCourseService;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysUser;
|
||||
import cn.novalon.gym.manage.sys.dto.request.CoachCreateRequest;
|
||||
import cn.novalon.gym.manage.sys.dto.request.CoachUpdateRequest;
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 教练处理器(放在 manage-app 中避免模块循环依赖)
|
||||
* 教练管理处理器(从 manage-app 迁移至 gym-coach 模块)
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-07-19
|
||||
@@ -30,18 +30,18 @@ import java.util.Map;
|
||||
public class CoachHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CoachHandler.class);
|
||||
private final CoachService coachService;
|
||||
private final CoachCourseService coachCourseService;
|
||||
private final Validator validator;
|
||||
|
||||
public CoachHandler(CoachService coachService, Validator validator) {
|
||||
this.coachService = coachService;
|
||||
public CoachHandler(CoachCourseService coachCourseService, Validator validator) {
|
||||
this.coachCourseService = coachCourseService;
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有教练", description = "获取系统中所有教练列表")
|
||||
public Mono<ServerResponse> getAllCoaches(ServerRequest request) {
|
||||
return ServerResponse.ok()
|
||||
.body(coachService.getAllCoaches(), SysUser.class);
|
||||
.body(coachCourseService.getAllCoaches(), SysUser.class);
|
||||
}
|
||||
|
||||
@Operation(summary = "创建教练", description = "创建新教练(创建用户并分配教练角色)")
|
||||
@@ -54,7 +54,7 @@ public class CoachHandler {
|
||||
violations.forEach(v -> errors.put(v.getPropertyPath().toString(), v.getMessage()));
|
||||
return ServerResponse.badRequest().bodyValue(errors);
|
||||
}
|
||||
return coachService.createCoach(
|
||||
return coachCourseService.createCoach(
|
||||
req.getUsername(), req.getPassword(),
|
||||
req.getNickname(), req.getEmail(), req.getPhone())
|
||||
.flatMap(user -> ServerResponse.status(HttpStatus.CREATED).bodyValue(user))
|
||||
@@ -70,7 +70,7 @@ public class CoachHandler {
|
||||
public Mono<ServerResponse> updateCoach(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
return request.bodyToMono(CoachUpdateRequest.class)
|
||||
.flatMap(req -> coachService.updateCoach(id, req.getNickname(), req.getEmail(), req.getPhone())
|
||||
.flatMap(req -> coachCourseService.updateCoach(id, req.getNickname(), req.getEmail(), req.getPhone())
|
||||
.flatMap(user -> ServerResponse.ok().bodyValue(user))
|
||||
.switchIfEmpty(ServerResponse.notFound().build())
|
||||
.onErrorResume(e -> {
|
||||
@@ -83,7 +83,7 @@ public class CoachHandler {
|
||||
@Operation(summary = "禁用教练", description = "禁用教练账号,自动取消其所有非进行中的团课")
|
||||
public Mono<ServerResponse> disableCoach(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
return coachService.disableCoach(id)
|
||||
return coachCourseService.disableCoach(id)
|
||||
.then(ServerResponse.ok().bodyValue(Map.of("message", "教练已禁用")))
|
||||
.onErrorResume(e -> {
|
||||
logger.error("禁用教练失败: {}", e.getMessage());
|
||||
@@ -94,9 +94,25 @@ public class CoachHandler {
|
||||
@Operation(summary = "获取教练的团课", description = "获取指定教练教授的所有团课")
|
||||
public Mono<ServerResponse> getCoachCourses(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
return coachService.getCoachCourses(id)
|
||||
return coachCourseService.getCoachCourses(id)
|
||||
.collectList()
|
||||
.flatMap(courses -> ServerResponse.ok().bodyValue(courses))
|
||||
.switchIfEmpty(ServerResponse.ok().bodyValue(List.of()));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取教练违规次数统计", description = "获取所有教练的违规次数")
|
||||
public Mono<ServerResponse> getViolationCounts(ServerRequest request) {
|
||||
return coachCourseService.getViolationCounts()
|
||||
.collectList()
|
||||
.flatMap(counts -> ServerResponse.ok().bodyValue(counts));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取教练违规记录", description = "获取指定教练的违规记录")
|
||||
public Mono<ServerResponse> getCoachViolations(ServerRequest request) {
|
||||
Long id = Long.valueOf(request.pathVariable("id"));
|
||||
return coachCourseService.getCoachViolations(id)
|
||||
.collectList()
|
||||
.flatMap(violations -> ServerResponse.ok().bodyValue(violations))
|
||||
.switchIfEmpty(ServerResponse.ok().bodyValue(List.of()));
|
||||
}
|
||||
}
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
package cn.novalon.gym.manage.coach.scheduler;
|
||||
|
||||
import cn.novalon.gym.manage.coach.enums.ViolationReason;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.groupcourse.dao.GroupCourseBookingDao;
|
||||
import cn.novalon.gym.manage.groupcourse.dao.GroupCourseDao;
|
||||
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseEntity;
|
||||
import cn.novalon.gym.manage.groupcourse.enums.CourseStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 教练课程定时调度器
|
||||
*
|
||||
* 功能:
|
||||
* 1. 检查未手动开课的课程,超时标记为教练缺席(5)并记录违规
|
||||
* 2. 检查未手动结课的课程,超时标记为自动结束(6)并记录违规
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-07-20
|
||||
*/
|
||||
@Component
|
||||
public class CoachCourseScheduler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CoachCourseScheduler.class);
|
||||
private static final long ONE_HOUR_MINUTES = 60;
|
||||
private static final long END_GRACE_MINUTES = 10;
|
||||
|
||||
private final GroupCourseDao groupCourseDao;
|
||||
private final GroupCourseBookingDao groupCourseBookingDao;
|
||||
private final DatabaseClient databaseClient;
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
public CoachCourseScheduler(GroupCourseDao groupCourseDao,
|
||||
GroupCourseBookingDao groupCourseBookingDao,
|
||||
DatabaseClient databaseClient,
|
||||
RedisUtil redisUtil) {
|
||||
this.groupCourseDao = groupCourseDao;
|
||||
this.groupCourseBookingDao = groupCourseBookingDao;
|
||||
this.databaseClient = databaseClient;
|
||||
this.redisUtil = redisUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每分钟检查一次:
|
||||
* - status=0(NORMAL) 的课程是否已过开课缺席阈值
|
||||
* - status=3(IN_PROGRESS) 或 status=7(COACH_LATE) 的课程是否已过结课宽限期
|
||||
*/
|
||||
@Scheduled(fixedRate = 60000)
|
||||
public void checkAndProcessCourses() {
|
||||
logger.debug("教练课程调度器开始检查");
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 1. 检查未开课的课程
|
||||
processAbsentCourses(now)
|
||||
.subscribe(
|
||||
count -> {
|
||||
if (count > 0) {
|
||||
logger.info("教练课程调度器:处理了 {} 门教练缺席课程", count);
|
||||
invalidateCache();
|
||||
}
|
||||
},
|
||||
error -> logger.error("教练课程调度器(缺席检查)执行失败:{}", error.getMessage(), error)
|
||||
);
|
||||
|
||||
// 2. 检查未结课的课程
|
||||
processAutoEndCourses(now)
|
||||
.subscribe(
|
||||
count -> {
|
||||
if (count > 0) {
|
||||
logger.info("教练课程调度器:处理了 {} 门自动结束课程", count);
|
||||
invalidateCache();
|
||||
}
|
||||
},
|
||||
error -> logger.error("教练课程调度器(自动结课)执行失败:{}", error.getMessage(), error)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理缺席课程:status=0 且已过开课缺席阈值
|
||||
*/
|
||||
private Mono<Long> processAbsentCourses(LocalDateTime now) {
|
||||
return groupCourseDao.findByStatusAndStartTimeBefore(databaseClient, "0", now)
|
||||
.filter(course -> isAbsentThresholdExceeded(course, now))
|
||||
.flatMap(course -> markAsCoachAbsent(course, now))
|
||||
.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理自动结课:status IN ('3','7') 且 end_time + 10分钟 已过
|
||||
*/
|
||||
private Mono<Long> processAutoEndCourses(LocalDateTime now) {
|
||||
LocalDateTime endThreshold = now.minusMinutes(END_GRACE_MINUTES);
|
||||
return groupCourseDao.findByStatusInAndEndTimeBefore(databaseClient,
|
||||
new String[]{String.valueOf(CourseStatus.IN_PROGRESS.getValue()),
|
||||
String.valueOf(CourseStatus.COACH_LATE.getValue())},
|
||||
endThreshold)
|
||||
.flatMap(course -> markAsAutoEnded(course, now))
|
||||
.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断课程是否已过缺席阈值
|
||||
*/
|
||||
private boolean isAbsentThresholdExceeded(GroupCourseEntity course, LocalDateTime now) {
|
||||
long courseDurationMinutes = Duration.between(course.getStartTime(), course.getEndTime()).toMinutes();
|
||||
long minutesSinceStart = Duration.between(course.getStartTime(), now).toMinutes();
|
||||
|
||||
if (courseDurationMinutes >= ONE_HOUR_MINUTES) {
|
||||
return minutesSinceStart > 30;
|
||||
} else {
|
||||
long thresholdB = Math.max(1, (long) (courseDurationMinutes * 0.25));
|
||||
return minutesSinceStart > thresholdB;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记课程为教练缺席(5),更新预约记录为教练缺席(4),记录违规
|
||||
*/
|
||||
private Mono<GroupCourseEntity> markAsCoachAbsent(GroupCourseEntity course, LocalDateTime now) {
|
||||
logger.info("课程 {} 教练缺席,标记为 COACH_ABSENT", course.getId());
|
||||
|
||||
return insertViolation(course.getCoachId(), course.getId(), now, ViolationReason.COACH_ABSENT)
|
||||
.then(groupCourseDao.updateToCoachAbsent(course.getId(), now, now))
|
||||
.then(groupCourseBookingDao.updateStatusByCourseId(course.getId(), "0", "4"))
|
||||
.thenReturn(course);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记课程为自动结束(6),记录违规
|
||||
*/
|
||||
private Mono<GroupCourseEntity> markAsAutoEnded(GroupCourseEntity course, LocalDateTime now) {
|
||||
logger.info("课程 {} 未手动结课,标记为 AUTO_ENDED", course.getId());
|
||||
|
||||
return insertViolation(course.getCoachId(), course.getId(), now, ViolationReason.NOT_MANUAL_END)
|
||||
.then(groupCourseDao.updateToAutoEnded(course.getId(), now, now))
|
||||
.thenReturn(course);
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入违规记录(使用 DatabaseClient 直连)
|
||||
*/
|
||||
private Mono<Void> insertViolation(Long coachId, Long courseId, LocalDateTime violationTime,
|
||||
ViolationReason reason) {
|
||||
return databaseClient.sql("""
|
||||
INSERT INTO coach_violation (coach_id, course_id, violation_time, violation_reason, created_at, updated_at)
|
||||
VALUES (:coachId, :courseId, :violationTime, :reason, :now, :now)
|
||||
""")
|
||||
.bind("coachId", coachId)
|
||||
.bind("courseId", courseId)
|
||||
.bind("violationTime", violationTime)
|
||||
.bind("reason", reason.getValue())
|
||||
.bind("now", LocalDateTime.now())
|
||||
.then();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除统计缓存和团课缓存 —— 调度器触发时,如有课程状态变更则必须及时失效
|
||||
*/
|
||||
private void invalidateCache() {
|
||||
redisUtil.deleteByPattern("datacount:statistics:*").subscribe(
|
||||
deleted -> logger.debug("调度器清除统计缓存,已删除 {} 条", deleted),
|
||||
error -> logger.warn("调度器清除统计缓存失败: {}", error.getMessage())
|
||||
);
|
||||
redisUtil.deleteByPattern("group_course:*").subscribe(
|
||||
deleted -> logger.debug("调度器清除团课缓存,已删除 {} 条", deleted),
|
||||
error -> logger.warn("调度器清除团课缓存失败: {}", error.getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
+357
@@ -0,0 +1,357 @@
|
||||
package cn.novalon.gym.manage.coach.service;
|
||||
|
||||
import cn.novalon.gym.manage.coach.dao.CoachViolationDao;
|
||||
import cn.novalon.gym.manage.coach.entity.CoachViolationEntity;
|
||||
import cn.novalon.gym.manage.coach.enums.ViolationReason;
|
||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||
import cn.novalon.gym.manage.common.util.StatusConstants;
|
||||
import cn.novalon.gym.manage.groupcourse.dao.GroupCourseBookingDao;
|
||||
import cn.novalon.gym.manage.groupcourse.dao.GroupCourseDao;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseEntity;
|
||||
import cn.novalon.gym.manage.groupcourse.enums.CourseStatus;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseBookingRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysRole;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysUser;
|
||||
import cn.novalon.gym.manage.sys.core.domain.UserRole;
|
||||
import cn.novalon.gym.manage.sys.core.repository.ISysRoleRepository;
|
||||
import cn.novalon.gym.manage.sys.core.repository.ISysUserRepository;
|
||||
import cn.novalon.gym.manage.sys.core.repository.IUserRoleRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 教练课程服务(含教练管理 + 开课/结课逻辑 + 违规记录)
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-07-20
|
||||
*/
|
||||
@Service
|
||||
public class CoachCourseService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CoachCourseService.class);
|
||||
private static final String COACH_ROLE_NAME = "教练";
|
||||
private static final long ONE_HOUR_MINUTES = 60;
|
||||
|
||||
private final ISysUserRepository userRepository;
|
||||
private final ISysRoleRepository roleRepository;
|
||||
private final IUserRoleRepository userRoleRepository;
|
||||
private final IGroupCourseRepository groupCourseRepository;
|
||||
private final IGroupCourseBookingRepository bookingRepository;
|
||||
private final GroupCourseDao groupCourseDao;
|
||||
private final GroupCourseBookingDao groupCourseBookingDao;
|
||||
private final CoachViolationDao violationDao;
|
||||
private final DatabaseClient databaseClient;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
public CoachCourseService(ISysUserRepository userRepository,
|
||||
ISysRoleRepository roleRepository,
|
||||
IUserRoleRepository userRoleRepository,
|
||||
IGroupCourseRepository groupCourseRepository,
|
||||
IGroupCourseBookingRepository bookingRepository,
|
||||
GroupCourseDao groupCourseDao,
|
||||
GroupCourseBookingDao groupCourseBookingDao,
|
||||
CoachViolationDao violationDao,
|
||||
DatabaseClient databaseClient,
|
||||
PasswordEncoder passwordEncoder,
|
||||
RedisUtil redisUtil) {
|
||||
this.userRepository = userRepository;
|
||||
this.roleRepository = roleRepository;
|
||||
this.userRoleRepository = userRoleRepository;
|
||||
this.groupCourseRepository = groupCourseRepository;
|
||||
this.bookingRepository = bookingRepository;
|
||||
this.groupCourseDao = groupCourseDao;
|
||||
this.groupCourseBookingDao = groupCourseBookingDao;
|
||||
this.violationDao = violationDao;
|
||||
this.databaseClient = databaseClient;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.redisUtil = redisUtil;
|
||||
}
|
||||
|
||||
// ==================== 教练管理(从原 CoachService 迁移) ====================
|
||||
|
||||
public Flux<SysUser> getAllCoaches() {
|
||||
return getCoachRoleId()
|
||||
.flatMapMany(roleId -> userRoleRepository.findByRoleId(roleId)
|
||||
.map(UserRole::getUserId)
|
||||
.collectList()
|
||||
.flatMapMany(userIds -> {
|
||||
if (userIds.isEmpty()) {
|
||||
return Flux.empty();
|
||||
}
|
||||
return Flux.fromIterable(userIds)
|
||||
.flatMap(userRepository::findById)
|
||||
.filter(user -> user.getDeletedAt() == null);
|
||||
}));
|
||||
}
|
||||
|
||||
public Mono<SysUser> createCoach(String username, String password, String nickname, String email, String phone) {
|
||||
return getCoachRoleId().flatMap(coachRoleId -> {
|
||||
SysUser user = new SysUser();
|
||||
user.generateId();
|
||||
user.setUsername(username);
|
||||
user.setPassword(passwordEncoder.encode(password));
|
||||
user.setNickname(nickname);
|
||||
user.setEmail(email);
|
||||
user.setPhone(phone);
|
||||
user.setStatus(StatusConstants.ENABLED);
|
||||
|
||||
return userRepository.save(user)
|
||||
.flatMap(saved -> {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setUserId(saved.getId());
|
||||
userRole.setRoleId(coachRoleId);
|
||||
return userRoleRepository.save(userRole).thenReturn(saved);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public Mono<SysUser> updateCoach(Long id, String nickname, String email, String phone) {
|
||||
return userRepository.findById(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("教练不存在")))
|
||||
.flatMap(user -> {
|
||||
if (nickname != null) user.setNickname(nickname);
|
||||
if (email != null) user.setEmail(email);
|
||||
if (phone != null) user.setPhone(phone);
|
||||
user.setUpdatedAt(LocalDateTime.now());
|
||||
return userRepository.update(user);
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "connectionFactoryTransactionManager")
|
||||
public Mono<Void> disableCoach(Long id) {
|
||||
return userRepository.findById(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("教练不存在")))
|
||||
.flatMap(user ->
|
||||
groupCourseRepository.countByCoachIdAndStatus(id, 3L)
|
||||
.flatMap(inProgressCount -> {
|
||||
if (inProgressCount > 0) {
|
||||
return Mono.error(new RuntimeException(
|
||||
"该教练有 " + inProgressCount + " 门正在进行中的团课,无法禁用"));
|
||||
}
|
||||
return groupCourseRepository.cancelCoursesByCoachIdExceptStatus(id, 3L)
|
||||
.then();
|
||||
})
|
||||
.then(Mono.defer(() -> {
|
||||
user.setStatus(StatusConstants.DISABLED);
|
||||
user.setUpdatedAt(LocalDateTime.now());
|
||||
return userRepository.update(user).then();
|
||||
}))
|
||||
)
|
||||
.then(invalidateStatisticsCache());
|
||||
}
|
||||
|
||||
public Flux<GroupCourse> getCoachCourses(Long coachId) {
|
||||
return groupCourseRepository.findByCoachId(coachId, Sort.by(Sort.Direction.DESC, "startTime"))
|
||||
.flatMap(course ->
|
||||
bookingRepository.countValidBookings(course.getId())
|
||||
.map(count -> {
|
||||
course.setCurrentMembers(count.intValue());
|
||||
return course;
|
||||
})
|
||||
.defaultIfEmpty(course)
|
||||
);
|
||||
}
|
||||
|
||||
public Mono<Long> getCoachRoleId() {
|
||||
return roleRepository.findByRoleName(COACH_ROLE_NAME)
|
||||
.map(SysRole::getId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("教练角色未找到,请先执行数据库迁移")));
|
||||
}
|
||||
|
||||
// ==================== 开课逻辑 ====================
|
||||
|
||||
/**
|
||||
* 教练手动开课
|
||||
* 判定逻辑:
|
||||
* - 长课时(>=1h): 10分钟内正常,10~30分钟迟到,>30分钟拒绝
|
||||
* - 短课时(<1h): 10%时长内正常,10%~25%迟到,>25%拒绝
|
||||
*/
|
||||
public Mono<GroupCourseEntity> startCourse(Long courseId, Long coachId) {
|
||||
return groupCourseDao.findByIdIsAndDeletedAtIsNull(courseId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("团课不存在")))
|
||||
.flatMap(course -> {
|
||||
// 验证教练身份
|
||||
if (!course.getCoachId().equals(coachId)) {
|
||||
return Mono.error(new RuntimeException("您不是该课程的教练,无权开课"));
|
||||
}
|
||||
// 验证课程状态:只有 NORMAL(0) 可以开课
|
||||
if (!CourseStatus.NORMAL.getValue().equals(course.getStatus())) {
|
||||
return Mono.error(new RuntimeException("当前课程状态不允许开课,当前状态: " + course.getStatus()));
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
long courseDurationMinutes = Duration.between(course.getStartTime(), course.getEndTime()).toMinutes();
|
||||
|
||||
if (courseDurationMinutes >= ONE_HOUR_MINUTES) {
|
||||
return handleLongCourseStart(course, now);
|
||||
} else {
|
||||
return handleShortCourseStart(course, now, courseDurationMinutes);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Mono<GroupCourseEntity> handleLongCourseStart(GroupCourseEntity course, LocalDateTime now) {
|
||||
long minutesSinceStart = Duration.between(course.getStartTime(), now).toMinutes();
|
||||
|
||||
if (minutesSinceStart < 0) {
|
||||
return Mono.error(new RuntimeException("课程尚未到开课时间"));
|
||||
}
|
||||
if (minutesSinceStart <= 10) {
|
||||
// 正常开课
|
||||
return doStartCourse(course, now, CourseStatus.IN_PROGRESS, null);
|
||||
}
|
||||
if (minutesSinceStart <= 30) {
|
||||
// 教练迟到
|
||||
return recordViolation(course.getCoachId(), course.getId(), now, ViolationReason.COACH_LATE)
|
||||
.then(doStartCourse(course, now, CourseStatus.COACH_LATE, ViolationReason.COACH_LATE));
|
||||
}
|
||||
// >30分钟,拒绝(调度器应已标记为缺席)
|
||||
return Mono.error(new RuntimeException("已超过开课时间30分钟,无法开课"));
|
||||
}
|
||||
|
||||
private Mono<GroupCourseEntity> handleShortCourseStart(GroupCourseEntity course, LocalDateTime now,
|
||||
long courseDurationMinutes) {
|
||||
long minutesSinceStart = Duration.between(course.getStartTime(), now).toMinutes();
|
||||
long thresholdA = Math.max(1, (long) (courseDurationMinutes * 0.10));
|
||||
long thresholdB = Math.max(1, (long) (courseDurationMinutes * 0.25));
|
||||
|
||||
if (minutesSinceStart < 0) {
|
||||
return Mono.error(new RuntimeException("课程尚未到开课时间"));
|
||||
}
|
||||
if (minutesSinceStart <= thresholdA) {
|
||||
// 正常开课
|
||||
return doStartCourse(course, now, CourseStatus.IN_PROGRESS, null);
|
||||
}
|
||||
if (minutesSinceStart <= thresholdB) {
|
||||
// 教练迟到
|
||||
return recordViolation(course.getCoachId(), course.getId(), now, ViolationReason.COACH_LATE)
|
||||
.then(doStartCourse(course, now, CourseStatus.COACH_LATE, ViolationReason.COACH_LATE));
|
||||
}
|
||||
// >thresholdB,拒绝
|
||||
return Mono.error(new RuntimeException("已超过开课时间,无法开课"));
|
||||
}
|
||||
|
||||
private Mono<GroupCourseEntity> doStartCourse(GroupCourseEntity course, LocalDateTime now,
|
||||
CourseStatus newStatus, ViolationReason violationReason) {
|
||||
course.setStatus(newStatus.getValue());
|
||||
course.setActualStartTime(now);
|
||||
course.setUpdatedAt(now);
|
||||
return groupCourseDao.updateStartInfo(course.getId(), String.valueOf(newStatus.getValue()), now, now)
|
||||
.then(groupCourseDao.findByIdIsAndDeletedAtIsNull(course.getId()))
|
||||
.flatMap(entity -> invalidateStatisticsCache().thenReturn(entity));
|
||||
}
|
||||
|
||||
// ==================== 结课逻辑 ====================
|
||||
|
||||
/**
|
||||
* 教练手动结课
|
||||
* 可在 IN_PROGRESS(3) 或 COACH_LATE(7) 状态下结课
|
||||
* 必须在标注结课时间 + 10分钟内
|
||||
*/
|
||||
public Mono<GroupCourseEntity> endCourse(Long courseId, Long coachId) {
|
||||
return groupCourseDao.findByIdIsAndDeletedAtIsNull(courseId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("团课不存在")))
|
||||
.flatMap(course -> {
|
||||
// 验证教练身份
|
||||
if (!course.getCoachId().equals(coachId)) {
|
||||
return Mono.error(new RuntimeException("您不是该课程的教练,无权结课"));
|
||||
}
|
||||
// 验证状态:IN_PROGRESS(3) 或 COACH_LATE(7)
|
||||
Long status = course.getStatus();
|
||||
if (!CourseStatus.IN_PROGRESS.getValue().equals(status)
|
||||
&& !CourseStatus.COACH_LATE.getValue().equals(status)) {
|
||||
return Mono.error(new RuntimeException("当前课程状态不允许结课,当前状态: " + status));
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
long minutesAfterEnd = Duration.between(course.getEndTime(), now).toMinutes();
|
||||
|
||||
if (minutesAfterEnd > 10) {
|
||||
return Mono.error(new RuntimeException("已超过结课时间10分钟,请等待系统自动结课"));
|
||||
}
|
||||
|
||||
course.setStatus(CourseStatus.ENDED.getValue());
|
||||
course.setActualEndTime(now);
|
||||
course.setUpdatedAt(now);
|
||||
return groupCourseDao.updateEndInfo(course.getId(), String.valueOf(CourseStatus.ENDED.getValue()), now, now)
|
||||
.then(groupCourseDao.findByIdIsAndDeletedAtIsNull(course.getId()))
|
||||
.flatMap(entity -> invalidateStatisticsCache().thenReturn(entity));
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 违规记录 ====================
|
||||
|
||||
/**
|
||||
* 记录教练违规行为(使用 DatabaseClient 直连,避免 R2DBC Entity 映射问题)
|
||||
*/
|
||||
public Mono<Void> recordViolation(Long coachId, Long courseId, LocalDateTime violationTime,
|
||||
ViolationReason reason) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
return databaseClient.sql("""
|
||||
INSERT INTO coach_violation (coach_id, course_id, violation_time, violation_reason, created_at, updated_at)
|
||||
VALUES (:coachId, :courseId, :violationTime, :reason, :now, :now)
|
||||
""")
|
||||
.bind("coachId", coachId)
|
||||
.bind("courseId", courseId)
|
||||
.bind("violationTime", violationTime)
|
||||
.bind("reason", reason.getValue())
|
||||
.bind("now", now)
|
||||
.then();
|
||||
}
|
||||
|
||||
// ==================== 违规查询 ====================
|
||||
|
||||
/**
|
||||
* 获取所有教练的违规次数统计
|
||||
*/
|
||||
public Flux<Map<String, Object>> getViolationCounts() {
|
||||
return databaseClient.sql("""
|
||||
SELECT coach_id, COUNT(*) AS count
|
||||
FROM coach_violation
|
||||
WHERE deleted_at IS NULL
|
||||
GROUP BY coach_id
|
||||
""")
|
||||
.fetch()
|
||||
.all();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定教练的违规记录
|
||||
*/
|
||||
public Flux<Map<String, Object>> getCoachViolations(Long coachId) {
|
||||
return databaseClient.sql("""
|
||||
SELECT v.*, gc.course_name
|
||||
FROM coach_violation v
|
||||
LEFT JOIN group_course gc ON v.course_id = gc.id AND gc.deleted_at IS NULL
|
||||
WHERE v.coach_id = :coachId AND v.deleted_at IS NULL
|
||||
ORDER BY v.violation_time DESC
|
||||
""")
|
||||
.bind("coachId", coachId)
|
||||
.fetch()
|
||||
.all();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除统计缓存和团课缓存 —— 课程状态变更后调用,返回 Mono 确保链式执行
|
||||
*/
|
||||
private Mono<Void> invalidateStatisticsCache() {
|
||||
return redisUtil.deleteByPattern("datacount:statistics:*")
|
||||
.then(redisUtil.deleteByPattern("group_course:*"))
|
||||
.doOnNext(count -> {})
|
||||
.then();
|
||||
}
|
||||
}
|
||||
+65
@@ -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();
|
||||
}
|
||||
}
|
||||
+40
@@ -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;
|
||||
}
|
||||
+5
@@ -37,6 +37,11 @@ public class StatisticsSummary {
|
||||
*/
|
||||
private SignInStatistics signInStatistics;
|
||||
|
||||
/**
|
||||
* 教练统计数据
|
||||
*/
|
||||
private CoachStatistics coachStatistics;
|
||||
|
||||
/**
|
||||
* 统计数据生成时间
|
||||
*/
|
||||
|
||||
+30
-1
@@ -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());
|
||||
}
|
||||
|
||||
+7
@@ -114,4 +114,11 @@ public interface GroupCourseBookingDao extends R2dbcRepository<GroupCourseBookin
|
||||
@org.springframework.data.r2dbc.repository.Modifying
|
||||
@org.springframework.data.r2dbc.repository.Query("UPDATE group_course_booking SET status = '3', updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> updateToAbsent(Long id, java.time.LocalDateTime updatedAt);
|
||||
|
||||
/**
|
||||
* 批量更新某课程的预约状态(教练缺席场景)
|
||||
*/
|
||||
@org.springframework.data.r2dbc.repository.Modifying
|
||||
@org.springframework.data.r2dbc.repository.Query("UPDATE group_course_booking SET status = :newStatus, updated_at = NOW() WHERE course_id = :courseId AND status = :oldStatus AND deleted_at IS NULL")
|
||||
Mono<Integer> updateStatusByCourseId(Long courseId, String oldStatus, String newStatus);
|
||||
}
|
||||
+40
-2
@@ -37,9 +37,45 @@ public interface GroupCourseDao extends R2dbcRepository<GroupCourseEntity, Long>
|
||||
@Query("UPDATE group_course SET deleted_at = :deletedAt WHERE id = :id")
|
||||
Mono<Integer> softDelete(Long id, LocalDateTime deletedAt);
|
||||
|
||||
// ---------- 教练相关 SQL 方法 ----------
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course SET status = '2', updated_at = :updatedAt WHERE status = '0' AND end_time <= NOW() AND deleted_at IS NULL")
|
||||
Mono<Integer> completeExpiredCourses(LocalDateTime updatedAt);
|
||||
@Query("UPDATE group_course SET status = :status, actual_start_time = :actualStartTime, updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> updateStartInfo(Long id, String status, LocalDateTime actualStartTime, LocalDateTime updatedAt);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course SET status = :status, actual_end_time = :actualEndTime, updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> updateEndInfo(Long id, String status, LocalDateTime actualEndTime, LocalDateTime updatedAt);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course SET status = '5', actual_end_time = :actualEndTime, updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> updateToCoachAbsent(Long id, LocalDateTime actualEndTime, LocalDateTime updatedAt);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE group_course SET status = '6', actual_end_time = :actualEndTime, updated_at = :updatedAt WHERE id = :id AND deleted_at IS NULL")
|
||||
Mono<Integer> updateToAutoEnded(Long id, LocalDateTime actualEndTime, LocalDateTime updatedAt);
|
||||
|
||||
/**
|
||||
* 查询指定状态且开始时间早于指定时间的课程(用于缺席检查)
|
||||
*/
|
||||
default Flux<GroupCourseEntity> findByStatusAndStartTimeBefore(DatabaseClient databaseClient, String status, LocalDateTime time) {
|
||||
return databaseClient.sql("SELECT * FROM group_course WHERE status = :status AND start_time < :time AND deleted_at IS NULL")
|
||||
.bind("status", status)
|
||||
.bind("time", time)
|
||||
.map((row, meta) -> mapRowToEntity(row))
|
||||
.all();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定状态集合且结束时间早于指定时间的课程(用于自动结课检查)
|
||||
*/
|
||||
default Flux<GroupCourseEntity> findByStatusInAndEndTimeBefore(DatabaseClient databaseClient, String[] statuses, LocalDateTime time) {
|
||||
return databaseClient.sql("SELECT * FROM group_course WHERE status = ANY(:statuses::varchar[]) AND end_time < :time AND deleted_at IS NULL")
|
||||
.bind("statuses", statuses)
|
||||
.bind("time", time)
|
||||
.map((row, meta) -> mapRowToEntity(row))
|
||||
.all();
|
||||
}
|
||||
|
||||
Flux<GroupCourseEntity> findByCourseTypeAndDeletedAtIsNull(Long courseType);
|
||||
|
||||
@@ -328,6 +364,8 @@ public interface GroupCourseDao extends R2dbcRepository<GroupCourseEntity, Long>
|
||||
entity.setCoverImage(row.get("cover_image", String.class));
|
||||
entity.setDescription(row.get("description", String.class));
|
||||
entity.setStoredValueAmount(row.get("stored_value_amount", java.math.BigDecimal.class));
|
||||
entity.setActualStartTime(row.get("actual_start_time", LocalDateTime.class));
|
||||
entity.setActualEndTime(row.get("actual_end_time", LocalDateTime.class));
|
||||
entity.setQrCodePath(row.get("qr_code_path", String.class));
|
||||
entity.setCreateBy(row.get("create_by", String.class));
|
||||
entity.setUpdateBy(row.get("update_by", String.class));
|
||||
|
||||
+24
@@ -40,6 +40,14 @@ public class GroupCourse extends BaseDomain{
|
||||
@Schema(description = "课程状态", example = "0")
|
||||
private Long status;
|
||||
|
||||
//实际开课时间
|
||||
@Schema(description = "实际开课时间")
|
||||
private LocalDateTime actualStartTime;
|
||||
|
||||
//实际结课时间
|
||||
@Schema(description = "实际结课时间")
|
||||
private LocalDateTime actualEndTime;
|
||||
|
||||
//上课地点
|
||||
@Schema(description = "上课地点", example = "龙泉驿区幸福路")
|
||||
private String location;
|
||||
@@ -124,6 +132,22 @@ public class GroupCourse extends BaseDomain{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public LocalDateTime getActualStartTime() {
|
||||
return actualStartTime;
|
||||
}
|
||||
|
||||
public void setActualStartTime(LocalDateTime actualStartTime) {
|
||||
this.actualStartTime = actualStartTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getActualEndTime() {
|
||||
return actualEndTime;
|
||||
}
|
||||
|
||||
public void setActualEndTime(LocalDateTime actualEndTime) {
|
||||
this.actualEndTime = actualEndTime;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
+25
-1
@@ -38,7 +38,15 @@ public class GroupCourseEntity extends BaseEntity {
|
||||
@Column("current_members")
|
||||
private Integer currentMembers;
|
||||
|
||||
//课程状态:0-正常,1-已取消,2-已结束
|
||||
//实际开课时间
|
||||
@Column("actual_start_time")
|
||||
private LocalDateTime actualStartTime;
|
||||
|
||||
//实际结课时间
|
||||
@Column("actual_end_time")
|
||||
private LocalDateTime actualEndTime;
|
||||
|
||||
//课程状态:0-正常,1-已取消,2-已结束,3-进行中,5-教练缺席,6-自动结束,7-教练迟到
|
||||
@Column("status")
|
||||
private Long status;
|
||||
|
||||
@@ -158,6 +166,22 @@ public class GroupCourseEntity extends BaseEntity {
|
||||
this.storedValueAmount = storedValueAmount;
|
||||
}
|
||||
|
||||
public LocalDateTime getActualStartTime() {
|
||||
return actualStartTime;
|
||||
}
|
||||
|
||||
public void setActualStartTime(LocalDateTime actualStartTime) {
|
||||
this.actualStartTime = actualStartTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getActualEndTime() {
|
||||
return actualEndTime;
|
||||
}
|
||||
|
||||
public void setActualEndTime(LocalDateTime actualEndTime) {
|
||||
this.actualEndTime = actualEndTime;
|
||||
}
|
||||
|
||||
public String getQrCodePath() {
|
||||
return qrCodePath;
|
||||
}
|
||||
|
||||
+4
-1
@@ -11,7 +11,10 @@ public enum CourseStatus {
|
||||
NORMAL(0L, "正常"),
|
||||
CANCELLED(1L, "已取消"),
|
||||
ENDED(2L, "已结束"),
|
||||
IN_PROGRESS(3L, "进行中");
|
||||
IN_PROGRESS(3L, "进行中"),
|
||||
COACH_ABSENT(5L, "教练缺席"),
|
||||
AUTO_ENDED(6L, "自动结束"),
|
||||
COACH_LATE(7L, "教练迟到");
|
||||
|
||||
private final Long value;
|
||||
private final String desc;
|
||||
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package cn.novalon.gym.manage.groupcourse.scheduler;
|
||||
|
||||
import cn.novalon.gym.manage.groupcourse.dao.GroupCourseDao;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 团课过期状态自动更新定时任务
|
||||
*
|
||||
* 功能:定期检查已过期的团课(end_time <= NOW()),自动将 status 从 0 更新为 2(已结束)
|
||||
*
|
||||
* @date 2026-06-24
|
||||
*/
|
||||
@Component
|
||||
public class GroupCourseExpireScheduler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GroupCourseExpireScheduler.class);
|
||||
|
||||
private final GroupCourseDao groupCourseDao;
|
||||
|
||||
public GroupCourseExpireScheduler(GroupCourseDao groupCourseDao) {
|
||||
this.groupCourseDao = groupCourseDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每分钟检查一次,将已过期但状态仍为 0 的团课标记为已结束(status = 2)
|
||||
*/
|
||||
@Scheduled(fixedRate = 60000)
|
||||
public void completeExpiredCourses() {
|
||||
logger.debug("定时任务开始检查已过期团课,更新状态为已结束");
|
||||
|
||||
groupCourseDao.completeExpiredCourses(LocalDateTime.now())
|
||||
.subscribe(
|
||||
count -> {
|
||||
if (count > 0) {
|
||||
logger.info("定时任务完成,更新了 {} 条过期团课状态为已结束", count);
|
||||
}
|
||||
},
|
||||
error -> logger.error("过期团课状态更新定时任务执行失败:{}", error.getMessage(), error)
|
||||
);
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -741,7 +741,9 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
private Mono<Void> clearCache() {
|
||||
return redisUtil.deleteByPattern(CACHE_KEY_PREFIX + "*")
|
||||
.then(redisUtil.deleteByPattern(CACHE_KEY_ID_PREFIX + "*"))
|
||||
.then(redisUtil.deleteByPattern(CACHE_KEY_DETAIL_PREFIX + "*")).then();
|
||||
.then(redisUtil.deleteByPattern(CACHE_KEY_DETAIL_PREFIX + "*"))
|
||||
.then(redisUtil.deleteByPattern("datacount:statistics:*"))
|
||||
.then();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
@@ -21,6 +21,8 @@ public class GroupCourseVO {
|
||||
private Long courseType;
|
||||
private LocalDateTime startTime;
|
||||
private LocalDateTime endTime;
|
||||
private LocalDateTime actualStartTime;
|
||||
private LocalDateTime actualEndTime;
|
||||
private Integer maxMembers;
|
||||
private Integer currentMembers;
|
||||
private Long status;
|
||||
@@ -48,6 +50,8 @@ public class GroupCourseVO {
|
||||
vo.setCourseType(course.getCourseType());
|
||||
vo.setStartTime(course.getStartTime());
|
||||
vo.setEndTime(course.getEndTime());
|
||||
vo.setActualStartTime(course.getActualStartTime());
|
||||
vo.setActualEndTime(course.getActualEndTime());
|
||||
vo.setMaxMembers(course.getMaxMembers());
|
||||
vo.setCurrentMembers(course.getCurrentMembers());
|
||||
vo.setStatus(course.getStatus());
|
||||
@@ -86,6 +90,12 @@ public class GroupCourseVO {
|
||||
public LocalDateTime getEndTime() { return endTime; }
|
||||
public void setEndTime(LocalDateTime endTime) { this.endTime = endTime; }
|
||||
|
||||
public LocalDateTime getActualStartTime() { return actualStartTime; }
|
||||
public void setActualStartTime(LocalDateTime actualStartTime) { this.actualStartTime = actualStartTime; }
|
||||
|
||||
public LocalDateTime getActualEndTime() { return actualEndTime; }
|
||||
public void setActualEndTime(LocalDateTime actualEndTime) { this.actualEndTime = actualEndTime; }
|
||||
|
||||
public Integer getMaxMembers() { return maxMembers; }
|
||||
public void setMaxMembers(Integer maxMembers) { this.maxMembers = maxMembers; }
|
||||
|
||||
|
||||
@@ -169,6 +169,12 @@
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.novalon.gym.manage</groupId>
|
||||
<artifactId>gym-coach</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+2
-1
@@ -25,7 +25,8 @@ import java.util.List;
|
||||
"cn.novalon.gym.manage.member.repository",
|
||||
"cn.novalon.gym.manage.groupcourse.dao",
|
||||
"cn.novalon.gym.manage.checkIn.repository",
|
||||
"cn.novalon.gym.manage.payment.repository"
|
||||
"cn.novalon.gym.manage.payment.repository",
|
||||
"cn.novalon.gym.manage.coach.dao"
|
||||
})
|
||||
@EnableReactiveElasticsearchRepositories(basePackages = "cn.novalon.gym.manage.member.es.repository")
|
||||
public class ManageApplication {
|
||||
|
||||
+8
-2
@@ -20,7 +20,8 @@ import cn.novalon.gym.manage.notify.handler.BannerHandler;
|
||||
import cn.novalon.gym.manage.notify.handler.SysNoticeHandler;
|
||||
import cn.novalon.gym.manage.notify.handler.SysUserMessageHandler;
|
||||
import cn.novalon.gym.manage.payment.handler.PaymentHandler;
|
||||
import cn.novalon.gym.manage.app.handler.CoachHandler;
|
||||
import cn.novalon.gym.manage.coach.handler.CoachCourseHandler;
|
||||
import cn.novalon.gym.manage.coach.handler.CoachHandler;
|
||||
import cn.novalon.gym.manage.sys.handler.auth.PasswordDiagnosticHandler;
|
||||
import cn.novalon.gym.manage.sys.handler.auth.SysAuthHandler;
|
||||
import cn.novalon.gym.manage.sys.handler.config.SysConfigHandler;
|
||||
@@ -86,7 +87,8 @@ public class SystemRouter {
|
||||
DataStatisticsHandler dataStatisticsHandler,
|
||||
PhoneAuthHandler phoneAuthHandler,
|
||||
PaymentHandler paymentHandler,
|
||||
CoachHandler coachHandler) {
|
||||
CoachHandler coachHandler,
|
||||
CoachCourseHandler coachCourseHandler) {
|
||||
|
||||
return route()
|
||||
// ========== 诊断路由 ==========
|
||||
@@ -126,6 +128,10 @@ public class SystemRouter {
|
||||
.PUT("/api/coach/{id}", coachHandler::updateCoach)
|
||||
.POST("/api/coach/{id}/disable", coachHandler::disableCoach)
|
||||
.GET("/api/coach/{id}/courses", coachHandler::getCoachCourses)
|
||||
.GET("/api/coach/violation-counts", coachHandler::getViolationCounts)
|
||||
.GET("/api/coach/{id}/violations", coachHandler::getCoachViolations)
|
||||
.POST("/api/coach/courses/{courseId}/start", coachCourseHandler::startCourse)
|
||||
.POST("/api/coach/courses/{courseId}/end", coachCourseHandler::endCourse)
|
||||
|
||||
// ========== 菜单路由 ==========
|
||||
.GET("/api/menus", menuHandler::getAllMenus)
|
||||
|
||||
-144
@@ -1,144 +0,0 @@
|
||||
package cn.novalon.gym.manage.app.service;
|
||||
|
||||
import cn.novalon.gym.manage.common.util.StatusConstants;
|
||||
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseBookingRepository;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysRole;
|
||||
import cn.novalon.gym.manage.sys.core.domain.SysUser;
|
||||
import cn.novalon.gym.manage.sys.core.domain.UserRole;
|
||||
import cn.novalon.gym.manage.sys.core.repository.ISysRoleRepository;
|
||||
import cn.novalon.gym.manage.sys.core.repository.ISysUserRepository;
|
||||
import cn.novalon.gym.manage.sys.core.repository.IUserRoleRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 教练服务(跨模块编排,放在 manage-app 中避免模块循环依赖)
|
||||
*
|
||||
* @author 张翔
|
||||
* @date 2026-07-19
|
||||
*/
|
||||
@Service
|
||||
public class CoachService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CoachService.class);
|
||||
private static final String COACH_ROLE_NAME = "教练";
|
||||
|
||||
private final ISysUserRepository userRepository;
|
||||
private final ISysRoleRepository roleRepository;
|
||||
private final IUserRoleRepository userRoleRepository;
|
||||
private final IGroupCourseRepository groupCourseRepository;
|
||||
private final IGroupCourseBookingRepository bookingRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
public CoachService(ISysUserRepository userRepository,
|
||||
ISysRoleRepository roleRepository,
|
||||
IUserRoleRepository userRoleRepository,
|
||||
IGroupCourseRepository groupCourseRepository,
|
||||
IGroupCourseBookingRepository bookingRepository,
|
||||
PasswordEncoder passwordEncoder) {
|
||||
this.userRepository = userRepository;
|
||||
this.roleRepository = roleRepository;
|
||||
this.userRoleRepository = userRoleRepository;
|
||||
this.groupCourseRepository = groupCourseRepository;
|
||||
this.bookingRepository = bookingRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
public Flux<SysUser> getAllCoaches() {
|
||||
return getCoachRoleId()
|
||||
.flatMapMany(roleId -> userRoleRepository.findByRoleId(roleId)
|
||||
.map(UserRole::getUserId)
|
||||
.collectList()
|
||||
.flatMapMany(userIds -> {
|
||||
if (userIds.isEmpty()) {
|
||||
return Flux.empty();
|
||||
}
|
||||
return Flux.fromIterable(userIds)
|
||||
.flatMap(userRepository::findById)
|
||||
.filter(user -> user.getDeletedAt() == null);
|
||||
}));
|
||||
}
|
||||
|
||||
public Mono<SysUser> createCoach(String username, String password, String nickname, String email, String phone) {
|
||||
return getCoachRoleId().flatMap(coachRoleId -> {
|
||||
SysUser user = new SysUser();
|
||||
user.generateId();
|
||||
user.setUsername(username);
|
||||
user.setPassword(passwordEncoder.encode(password));
|
||||
user.setNickname(nickname);
|
||||
user.setEmail(email);
|
||||
user.setPhone(phone);
|
||||
user.setStatus(StatusConstants.ENABLED);
|
||||
|
||||
return userRepository.save(user)
|
||||
.flatMap(saved -> {
|
||||
UserRole userRole = new UserRole();
|
||||
userRole.setUserId(saved.getId());
|
||||
userRole.setRoleId(coachRoleId);
|
||||
return userRoleRepository.save(userRole).thenReturn(saved);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public Mono<SysUser> updateCoach(Long id, String nickname, String email, String phone) {
|
||||
return userRepository.findById(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("教练不存在")))
|
||||
.flatMap(user -> {
|
||||
if (nickname != null) user.setNickname(nickname);
|
||||
if (email != null) user.setEmail(email);
|
||||
if (phone != null) user.setPhone(phone);
|
||||
user.setUpdatedAt(LocalDateTime.now());
|
||||
return userRepository.update(user);
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "connectionFactoryTransactionManager")
|
||||
public Mono<Void> disableCoach(Long id) {
|
||||
return userRepository.findById(id)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("教练不存在")))
|
||||
.flatMap(user ->
|
||||
groupCourseRepository.countByCoachIdAndStatus(id, 3L)
|
||||
.flatMap(inProgressCount -> {
|
||||
if (inProgressCount > 0) {
|
||||
return Mono.error(new RuntimeException(
|
||||
"该教练有 " + inProgressCount + " 门正在进行中的团课,无法禁用"));
|
||||
}
|
||||
return groupCourseRepository.cancelCoursesByCoachIdExceptStatus(id, 3L)
|
||||
.then();
|
||||
})
|
||||
.then(Mono.defer(() -> {
|
||||
user.setStatus(StatusConstants.DISABLED);
|
||||
user.setUpdatedAt(LocalDateTime.now());
|
||||
return userRepository.update(user).then();
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
public Flux<GroupCourse> getCoachCourses(Long coachId) {
|
||||
return groupCourseRepository.findByCoachId(coachId, Sort.by(Sort.Direction.DESC, "startTime"))
|
||||
.flatMap(course ->
|
||||
bookingRepository.countValidBookings(course.getId())
|
||||
.map(count -> {
|
||||
course.setCurrentMembers(count.intValue());
|
||||
return course;
|
||||
})
|
||||
.defaultIfEmpty(course)
|
||||
);
|
||||
}
|
||||
|
||||
public Mono<Long> getCoachRoleId() {
|
||||
return roleRepository.findByRoleName(COACH_ROLE_NAME)
|
||||
.map(SysRole::getId)
|
||||
.switchIfEmpty(Mono.error(new RuntimeException("教练角色未找到,请先执行数据库迁移")));
|
||||
}
|
||||
}
|
||||
+26
-26
@@ -66,121 +66,121 @@ ON CONFLICT DO NOTHING;
|
||||
|
||||
-- ============================================
|
||||
-- 4. 团课课程数据(5个类型 × 5个课程 = 25个)
|
||||
-- start_time / end_time 分布在 2026-07-20 至 2026-08-02
|
||||
-- start_time / end_time 分布在 2026-07-22 至 2026-07-28
|
||||
-- ============================================
|
||||
|
||||
-- ---------- 瑜伽课程(5个)----------
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '哈他瑜伽入门', gt.id, '2026-07-20 08:00:00'::TIMESTAMP, '2026-07-20 09:00:00'::TIMESTAMP, 25, 12, '0', '瑜伽室A', '/static/course/yoga_hatha.jpg', '经典哈他瑜伽,从基础体式入手,配合呼吸引导,帮助初学者建立正确的瑜伽练习基础,感受身心的和谐统一。', 88.00, 'system'
|
||||
SELECT '哈他瑜伽入门', gt.id, '2026-07-22 08:00:00'::TIMESTAMP, '2026-07-22 09:00:00'::TIMESTAMP, 25, 12, '0', '瑜伽室A', '/static/course/yoga_hatha.jpg', '经典哈他瑜伽,从基础体式入手,配合呼吸引导,帮助初学者建立正确的瑜伽练习基础,感受身心的和谐统一。', 88.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '瑜伽';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '流瑜伽', gt.id, '2026-07-22 10:00:00'::TIMESTAMP, '2026-07-22 11:00:00'::TIMESTAMP, 20, 18, '0', '瑜伽室A', '/static/course/yoga_flow.jpg', '体式之间流畅串联,如行云流水般一气呵成。以拜日式为根基,结合站姿、平衡和扭转,提升力量与柔韧的整合能力。', 98.00, 'system'
|
||||
SELECT '流瑜伽', gt.id, '2026-07-24 10:00:00'::TIMESTAMP, '2026-07-24 11:00:00'::TIMESTAMP, 20, 18, '0', '瑜伽室A', '/static/course/yoga_flow.jpg', '体式之间流畅串联,如行云流水般一气呵成。以拜日式为根基,结合站姿、平衡和扭转,提升力量与柔韧的整合能力。', 98.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '瑜伽';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '阴瑜伽', gt.id, '2026-07-24 18:00:00'::TIMESTAMP, '2026-07-24 19:15:00'::TIMESTAMP, 20, 8, '0', '瑜伽室B', '/static/course/yoga_yin.jpg', '阴瑜伽以长时间保持体式为特点,深度伸展筋膜和结缔组织,帮助你释放身体深层紧张,缓解一周的工作疲劳。适合所有级别。', 88.00, 'system'
|
||||
SELECT '阴瑜伽', gt.id, '2026-07-26 18:00:00'::TIMESTAMP, '2026-07-26 19:15:00'::TIMESTAMP, 20, 8, '0', '瑜伽室B', '/static/course/yoga_yin.jpg', '阴瑜伽以长时间保持体式为特点,深度伸展筋膜和结缔组织,帮助你释放身体深层紧张,缓解一周的工作疲劳。适合所有级别。', 88.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '瑜伽';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '阿斯汤加瑜伽', gt.id, '2026-07-21 07:00:00'::TIMESTAMP, '2026-07-21 08:30:00'::TIMESTAMP, 15, 10, '0', '瑜伽室A', '/static/course/yoga_ashtanga.jpg', '阿斯汤加瑜伽以固定的体式序列和独特的呼吸法为核心,节奏紧凑,强度较高,能有效提升力量、柔韧和专注力。建议有一定瑜伽基础者参加。', 128.00, 'system'
|
||||
SELECT '阿斯汤加瑜伽', gt.id, '2026-07-23 07:00:00'::TIMESTAMP, '2026-07-23 08:30:00'::TIMESTAMP, 15, 10, '0', '瑜伽室A', '/static/course/yoga_ashtanga.jpg', '阿斯汤加瑜伽以固定的体式序列和独特的呼吸法为核心,节奏紧凑,强度较高,能有效提升力量、柔韧和专注力。建议有一定瑜伽基础者参加。', 128.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '瑜伽';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '空中瑜伽', gt.id, '2026-07-23 19:00:00'::TIMESTAMP, '2026-07-23 20:00:00'::TIMESTAMP, 12, 12, '0', '瑜伽室B', '/static/course/yoga_aerial.jpg', '利用悬挂的瑜伽吊床完成各种体式,借助重力让脊柱自然延展,体验"飞翔"般的自由感。深受女性学员喜爱,名额有限请提前预约。', 128.00, 'system'
|
||||
SELECT '空中瑜伽', gt.id, '2026-07-25 19:00:00'::TIMESTAMP, '2026-07-25 20:00:00'::TIMESTAMP, 12, 12, '0', '瑜伽室B', '/static/course/yoga_aerial.jpg', '利用悬挂的瑜伽吊床完成各种体式,借助重力让脊柱自然延展,体验"飞翔"般的自由感。深受女性学员喜爱,名额有限请提前预约。', 128.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '瑜伽';
|
||||
|
||||
|
||||
-- ---------- 动感单车课程(5个)----------
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '初级燃脂骑行', gt.id, '2026-07-20 19:00:00'::TIMESTAMP, '2026-07-20 19:45:00'::TIMESTAMP, 30, 22, '0', '单车房', '/static/course/spin_beginner.jpg', '适合新手的入门级骑行课程,教练将带领你掌握正确的骑行姿势和阻力调节技巧。在动感音乐中轻松燃烧300-400卡路里。', 58.00, 'system'
|
||||
SELECT '初级燃脂骑行', gt.id, '2026-07-22 19:00:00'::TIMESTAMP, '2026-07-22 19:45:00'::TIMESTAMP, 30, 22, '0', '单车房', '/static/course/spin_beginner.jpg', '适合新手的入门级骑行课程,教练将带领你掌握正确的骑行姿势和阻力调节技巧。在动感音乐中轻松燃烧300-400卡路里。', 58.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '动感单车';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '节奏爬坡', gt.id, '2026-07-22 18:30:00'::TIMESTAMP, '2026-07-22 19:15:00'::TIMESTAMP, 30, 15, '0', '单车房', '/static/course/spin_climb.jpg', '模拟山路爬坡骑行,通过逐渐增加阻力来挑战你的耐力和意志力。每一段爬坡后都有短暂的平路冲刺,节奏感十足,大汗淋漓的畅快体验。', 68.00, 'system'
|
||||
SELECT '节奏爬坡', gt.id, '2026-07-24 18:30:00'::TIMESTAMP, '2026-07-24 19:15:00'::TIMESTAMP, 30, 15, '0', '单车房', '/static/course/spin_climb.jpg', '模拟山路爬坡骑行,通过逐渐增加阻力来挑战你的耐力和意志力。每一段爬坡后都有短暂的平路冲刺,节奏感十足,大汗淋漓的畅快体验。', 68.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '动感单车';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '极速冲刺', gt.id, '2026-07-24 20:00:00'::TIMESTAMP, '2026-07-24 20:45:00'::TIMESTAMP, 25, 25, '0', '单车房', '/static/course/spin_sprint.jpg', '高强度冲刺为主题的骑行课,多组30秒极限冲刺搭配短暂恢复,彻底引爆你的心肺极限。周五夜间的爆款课程,约满速度极快!', 68.00, 'system'
|
||||
SELECT '极速冲刺', gt.id, '2026-07-26 20:00:00'::TIMESTAMP, '2026-07-26 20:45:00'::TIMESTAMP, 25, 25, '0', '单车房', '/static/course/spin_sprint.jpg', '高强度冲刺为主题的骑行课,多组30秒极限冲刺搭配短暂恢复,彻底引爆你的心肺极限。周五夜间的爆款课程,约满速度极快!', 68.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '动感单车';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '耐力骑行', gt.id, '2026-07-25 10:00:00'::TIMESTAMP, '2026-07-25 11:00:00'::TIMESTAMP, 30, 18, '0', '单车房', '/static/course/spin_endurance.jpg', '60分钟中低强度耐力骑行,适合周末早晨唤醒身体。在稳定的节奏中持续燃脂,配以舒缓的收尾拉伸,开启元气满满的周末。', 58.00, 'system'
|
||||
SELECT '耐力骑行', gt.id, '2026-07-27 10:00:00'::TIMESTAMP, '2026-07-27 11:00:00'::TIMESTAMP, 30, 18, '0', '单车房', '/static/course/spin_endurance.jpg', '60分钟中低强度耐力骑行,适合周末早晨唤醒身体。在稳定的节奏中持续燃脂,配以舒缓的收尾拉伸,开启元气满满的周末。', 58.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '动感单车';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '音乐主题骑行', gt.id, '2026-07-21 19:30:00'::TIMESTAMP, '2026-07-21 20:15:00'::TIMESTAMP, 30, 20, '0', '单车房', '/static/course/spin_music.jpg', '以热门流行音乐为主题的骑行派对!每首歌曲对应一套骑行组合,跟着节拍加速、爬坡、冲刺,在音乐中忘记疲惫。', 68.00, 'system'
|
||||
SELECT '音乐主题骑行', gt.id, '2026-07-23 19:30:00'::TIMESTAMP, '2026-07-23 20:15:00'::TIMESTAMP, 30, 20, '0', '单车房', '/static/course/spin_music.jpg', '以热门流行音乐为主题的骑行派对!每首歌曲对应一套骑行组合,跟着节拍加速、爬坡、冲刺,在音乐中忘记疲惫。', 68.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '动感单车';
|
||||
|
||||
|
||||
-- ---------- HIIT训练课程(5个)----------
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT 'Tabata燃脂', gt.id, '2026-07-20 07:00:00'::TIMESTAMP, '2026-07-20 07:30:00'::TIMESTAMP, 15, 8, '0', '多功能训练区', '/static/course/hiit_tabata.jpg', '经典的Tabata模式:20秒全力运动 + 10秒休息,循环8轮共4分钟,搭配热身和拉伸,30分钟全身燃爆。早晨空腹训练燃脂效果加倍!', 98.00, 'system'
|
||||
SELECT 'Tabata燃脂', gt.id, '2026-07-22 07:00:00'::TIMESTAMP, '2026-07-22 07:30:00'::TIMESTAMP, 15, 8, '0', '多功能训练区', '/static/course/hiit_tabata.jpg', '经典的Tabata模式:20秒全力运动 + 10秒休息,循环8轮共4分钟,搭配热身和拉伸,30分钟全身燃爆。早晨空腹训练燃脂效果加倍!', 98.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = 'HIIT训练';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '全身循环训练', gt.id, '2026-07-22 12:00:00'::TIMESTAMP, '2026-07-22 12:45:00'::TIMESTAMP, 15, 12, '0', '多功能训练区', '/static/course/hiit_circuit.jpg', '午间燃脂利器!8个动作站点轮流进行,涵盖深蹲跳、波比跳、壶铃摇摆、登山跑等,每个动作45秒,休息15秒,3轮循环让你全身湿透。', 98.00, 'system'
|
||||
SELECT '全身循环训练', gt.id, '2026-07-24 12:00:00'::TIMESTAMP, '2026-07-24 12:45:00'::TIMESTAMP, 15, 12, '0', '多功能训练区', '/static/course/hiit_circuit.jpg', '午间燃脂利器!8个动作站点轮流进行,涵盖深蹲跳、波比跳、壶铃摇摆、登山跑等,每个动作45秒,休息15秒,3轮循环让你全身湿透。', 98.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = 'HIIT训练';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '核心爆发力', gt.id, '2026-07-24 17:30:00'::TIMESTAMP, '2026-07-24 18:15:00'::TIMESTAMP, 12, 5, '0', '多功能训练区', '/static/course/hiit_core.jpg', '专注于核心肌群的HIIT训练,结合药球砸地、悬垂举腿、俄罗斯转体和平板支撑变式,打造钢铁般的核心力量,提升所有运动表现。', 108.00, 'system'
|
||||
SELECT '核心爆发力', gt.id, '2026-07-26 17:30:00'::TIMESTAMP, '2026-07-26 18:15:00'::TIMESTAMP, 12, 5, '0', '多功能训练区', '/static/course/hiit_core.jpg', '专注于核心肌群的HIIT训练,结合药球砸地、悬垂举腿、俄罗斯转体和平板支撑变式,打造钢铁般的核心力量,提升所有运动表现。', 108.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = 'HIIT训练';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '战绳挑战', gt.id, '2026-07-25 08:00:00'::TIMESTAMP, '2026-07-25 08:45:00'::TIMESTAMP, 10, 10, '0', '户外训练区', '/static/course/hiit_battle.jpg', '风靡全球的战绳训练!通过波浪、猛击、旋转等动作模式激活全身肌群,30秒一组高强度间歇,燃脂同时雕刻上肢线条。名额有限,已约满!', 128.00, 'system'
|
||||
SELECT '战绳挑战', gt.id, '2026-07-27 08:00:00'::TIMESTAMP, '2026-07-27 08:45:00'::TIMESTAMP, 10, 10, '0', '户外训练区', '/static/course/hiit_battle.jpg', '风靡全球的战绳训练!通过波浪、猛击、旋转等动作模式激活全身肌群,30秒一组高强度间歇,燃脂同时雕刻上肢线条。名额有限,已约满!', 128.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = 'HIIT训练';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '药球HIIT', gt.id, '2026-07-26 10:00:00'::TIMESTAMP, '2026-07-26 10:45:00'::TIMESTAMP, 12, 6, '0', '多功能训练区', '/static/course/hiit_medball.jpg', '以药球为主要工具的HIIT训练。药球砸地、旋转投掷、过头抛接等动作兼具力量和爆发力训练,动作多样不枯燥,周日上午的爆汗之选。', 108.00, 'system'
|
||||
SELECT '药球HIIT', gt.id, '2026-07-28 10:00:00'::TIMESTAMP, '2026-07-28 10:45:00'::TIMESTAMP, 12, 6, '0', '多功能训练区', '/static/course/hiit_medball.jpg', '以药球为主要工具的HIIT训练。药球砸地、旋转投掷、过头抛接等动作兼具力量和爆发力训练,动作多样不枯燥,周日上午的爆汗之选。', 108.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = 'HIIT训练';
|
||||
|
||||
|
||||
-- ---------- 普拉提课程(5个)----------
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '垫上普拉提', gt.id, '2026-07-21 10:00:00'::TIMESTAMP, '2026-07-21 11:00:00'::TIMESTAMP, 20, 14, '0', '普拉提室', '/static/course/pilates_mat.jpg', '经典垫上普拉提,通过精准的动作控制激活深层核心肌群。从呼吸到骨盆稳定,从脊柱逐节卷动到四肢协调,一节课改善你的身体感知。', 108.00, 'system'
|
||||
SELECT '垫上普拉提', gt.id, '2026-07-23 10:00:00'::TIMESTAMP, '2026-07-23 11:00:00'::TIMESTAMP, 20, 14, '0', '普拉提室', '/static/course/pilates_mat.jpg', '经典垫上普拉提,通过精准的动作控制激活深层核心肌群。从呼吸到骨盆稳定,从脊柱逐节卷动到四肢协调,一节课改善你的身体感知。', 108.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '普拉提';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '器械普拉提', gt.id, '2026-07-23 09:00:00'::TIMESTAMP, '2026-07-23 10:00:00'::TIMESTAMP, 10, 8, '0', '普拉提室', '/static/course/pilates_reformer.jpg', '使用专业普拉提核心床(Reformer)进行训练,弹簧阻力提供精准的负荷控制,适合需要针对性改善体态、康复训练或追求高效塑形的学员。', 158.00, 'system'
|
||||
SELECT '器械普拉提', gt.id, '2026-07-25 09:00:00'::TIMESTAMP, '2026-07-25 10:00:00'::TIMESTAMP, 10, 8, '0', '普拉提室', '/static/course/pilates_reformer.jpg', '使用专业普拉提核心床(Reformer)进行训练,弹簧阻力提供精准的负荷控制,适合需要针对性改善体态、康复训练或追求高效塑形的学员。', 158.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '普拉提';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '核心塑形', gt.id, '2026-07-25 14:00:00'::TIMESTAMP, '2026-07-25 15:00:00'::TIMESTAMP, 15, 9, '0', '普拉提室', '/static/course/pilates_sculpt.jpg', '专注于腹部、腰部和臀部的普拉提塑形课程。百次拍击、剪刀腿、肩桥等经典动作持续刺激目标肌群,打造紧致核心线条。', 128.00, 'system'
|
||||
SELECT '核心塑形', gt.id, '2026-07-27 14:00:00'::TIMESTAMP, '2026-07-27 15:00:00'::TIMESTAMP, 15, 9, '0', '普拉提室', '/static/course/pilates_sculpt.jpg', '专注于腹部、腰部和臀部的普拉提塑形课程。百次拍击、剪刀腿、肩桥等经典动作持续刺激目标肌群,打造紧致核心线条。', 128.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '普拉提';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '脊柱健康', gt.id, '2026-07-20 16:00:00'::TIMESTAMP, '2026-07-20 17:00:00'::TIMESTAMP, 15, 6, '0', '普拉提室', '/static/course/pilates_spine.jpg', '专为久坐办公人群设计,通过普拉提脊柱逐节运动改善驼背、圆肩等不良体态。融合猫牛式、脊柱旋转和游泳式,给你的脊柱一次深度保养。', 108.00, 'system'
|
||||
SELECT '脊柱健康', gt.id, '2026-07-22 16:00:00'::TIMESTAMP, '2026-07-22 17:00:00'::TIMESTAMP, 15, 6, '0', '普拉提室', '/static/course/pilates_spine.jpg', '专为久坐办公人群设计,通过普拉提脊柱逐节运动改善驼背、圆肩等不良体态。融合猫牛式、脊柱旋转和游泳式,给你的脊柱一次深度保养。', 108.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '普拉提';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '产后恢复普拉提', gt.id, '2026-07-22 11:00:00'::TIMESTAMP, '2026-07-22 12:00:00'::TIMESTAMP, 10, 4, '0', '普拉提室', '/static/course/pilates_postnatal.jpg', '专为产后妈妈设计的温和修复课程,重点激活盆底肌和腹横肌,循序渐进恢复核心力量。小班教学,教练一对一关注每位学员的姿势质量。', 158.00, 'system'
|
||||
SELECT '产后恢复普拉提', gt.id, '2026-07-24 11:00:00'::TIMESTAMP, '2026-07-24 12:00:00'::TIMESTAMP, 10, 4, '0', '普拉提室', '/static/course/pilates_postnatal.jpg', '专为产后妈妈设计的温和修复课程,重点激活盆底肌和腹横肌,循序渐进恢复核心力量。小班教学,教练一对一关注每位学员的姿势质量。', 158.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '普拉提';
|
||||
|
||||
|
||||
-- ---------- 搏击操课程(5个)----------
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '有氧搏击基础', gt.id, '2026-07-21 18:00:00'::TIMESTAMP, '2026-07-21 19:00:00'::TIMESTAMP, 25, 20, '0', '操厅A', '/static/course/boxing_basic.jpg', '零基础友好的搏击操入门课。从直拳、摆拳、勾拳到前踢、侧踹,教练分步讲解每个动作的要领,配合动感音乐串联成完整的搏击组合。', 68.00, 'system'
|
||||
SELECT '有氧搏击基础', gt.id, '2026-07-23 18:00:00'::TIMESTAMP, '2026-07-23 19:00:00'::TIMESTAMP, 25, 20, '0', '操厅A', '/static/course/boxing_basic.jpg', '零基础友好的搏击操入门课。从直拳、摆拳、勾拳到前踢、侧踹,教练分步讲解每个动作的要领,配合动感音乐串联成完整的搏击组合。', 68.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '搏击操';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT 'Kickboxing进阶', gt.id, '2026-07-23 19:00:00'::TIMESTAMP, '2026-07-23 20:00:00'::TIMESTAMP, 20, 15, '0', '操厅A', '/static/course/boxing_kickboxing.jpg', '融合踢拳技术的进阶搏击课程,增加连击组合、闪躲步法和膝肘技术。强度较基础课明显提升,汗如雨下的同时释放工作压力,宣泄效果一流。', 88.00, 'system'
|
||||
SELECT 'Kickboxing进阶', gt.id, '2026-07-25 19:00:00'::TIMESTAMP, '2026-07-25 20:00:00'::TIMESTAMP, 20, 15, '0', '操厅A', '/static/course/boxing_kickboxing.jpg', '融合踢拳技术的进阶搏击课程,增加连击组合、闪躲步法和膝肘技术。强度较基础课明显提升,汗如雨下的同时释放工作压力,宣泄效果一流。', 88.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '搏击操';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '综合格斗体能', gt.id, '2026-07-25 16:00:00'::TIMESTAMP, '2026-07-25 17:00:00'::TIMESTAMP, 20, 12, '0', '操厅A', '/static/course/boxing_mma.jpg', '融合拳击、泰拳、摔跤元素的综合体能训练。沙袋击打、地面对抗和爆发力训练交替进行,全面提升力量、速度和耐力。周六下午的硬核之选!', 98.00, 'system'
|
||||
SELECT '综合格斗体能', gt.id, '2026-07-27 16:00:00'::TIMESTAMP, '2026-07-27 17:00:00'::TIMESTAMP, 20, 12, '0', '操厅A', '/static/course/boxing_mma.jpg', '融合拳击、泰拳、摔跤元素的综合体能训练。沙袋击打、地面对抗和爆发力训练交替进行,全面提升力量、速度和耐力。周六下午的硬核之选!', 98.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '搏击操';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '燃脂拳击', gt.id, '2026-07-20 12:00:00'::TIMESTAMP, '2026-07-20 13:00:00'::TIMESTAMP, 25, 16, '0', '操厅A', '/static/course/boxing_fatburn.jpg', '午间燃脂拳击课。空击组合与沙袋击打间歇进行,心率维持在高燃脂区间。一节课可消耗500-700卡路里,中午来打拳比喝咖啡更提神!', 68.00, 'system'
|
||||
SELECT '燃脂拳击', gt.id, '2026-07-22 12:00:00'::TIMESTAMP, '2026-07-22 13:00:00'::TIMESTAMP, 25, 16, '0', '操厅A', '/static/course/boxing_fatburn.jpg', '午间燃脂拳击课。空击组合与沙袋击打间歇进行,心率维持在高燃脂区间。一节课可消耗500-700卡路里,中午来打拳比喝咖啡更提神!', 68.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '搏击操';
|
||||
|
||||
INSERT INTO group_course (course_name, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, stored_value_amount, create_by)
|
||||
SELECT '泰拳基础', gt.id, '2026-07-26 15:00:00'::TIMESTAMP, '2026-07-26 16:00:00'::TIMESTAMP, 15, 7, '0', '操厅A', '/static/course/boxing_muaythai.jpg', '学习泰拳的八肢艺术(双拳、双腿、双膝、双肘),从基本站架到肘膝组合,感受泰拳的刚猛魅力。小班教学保证动作纠正质量。', 98.00, 'system'
|
||||
SELECT '泰拳基础', gt.id, '2026-07-28 15:00:00'::TIMESTAMP, '2026-07-28 16:00:00'::TIMESTAMP, 15, 7, '0', '操厅A', '/static/course/boxing_muaythai.jpg', '学习泰拳的八肢艺术(双拳、双腿、双膝、双肘),从基本站架到肘膝组合,感受泰拳的刚猛魅力。小班教学保证动作纠正质量。', 98.00, 'system'
|
||||
FROM group_course_type gt WHERE gt.type_name = '搏击操';
|
||||
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
-- ============================================
|
||||
-- 教练违规记录表
|
||||
-- 版本: V23
|
||||
-- 描述: 创建教练违规记录表
|
||||
-- ============================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS coach_violation (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
coach_id BIGINT NOT NULL,
|
||||
course_id BIGINT NOT NULL,
|
||||
violation_time TIMESTAMP NOT NULL,
|
||||
violation_reason VARCHAR(50) NOT NULL,
|
||||
create_by VARCHAR(50),
|
||||
update_by VARCHAR(50),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP
|
||||
);
|
||||
|
||||
COMMENT ON TABLE coach_violation IS '教练违规记录表';
|
||||
COMMENT ON COLUMN coach_violation.id IS '主键ID';
|
||||
COMMENT ON COLUMN coach_violation.coach_id IS '教练ID(关联sys_user)';
|
||||
COMMENT ON COLUMN coach_violation.course_id IS '团课ID(关联group_course)';
|
||||
COMMENT ON COLUMN coach_violation.violation_time IS '违规时间';
|
||||
COMMENT ON COLUMN coach_violation.violation_reason IS '违规原因(COACH_LATE-教练迟到, COACH_ABSENT-教练缺席, NOT_MANUAL_END-教练未手动结课)';
|
||||
COMMENT ON COLUMN coach_violation.create_by IS '创建人';
|
||||
COMMENT ON COLUMN coach_violation.update_by IS '更新人';
|
||||
COMMENT ON COLUMN coach_violation.created_at IS '创建时间';
|
||||
COMMENT ON COLUMN coach_violation.updated_at IS '更新时间';
|
||||
COMMENT ON COLUMN coach_violation.deleted_at IS '删除时间(软删除)';
|
||||
@@ -0,0 +1,82 @@
|
||||
-- ============================================
|
||||
-- V24: 教练测试数据
|
||||
-- 描述: 创建5个教练用户并分配团课,每教练负责一种课型
|
||||
-- 确保同教练的课程时间不冲突
|
||||
-- ============================================
|
||||
|
||||
-- ============================================
|
||||
-- 1. 教练用户数据(密码均为 Test@123)
|
||||
-- ============================================
|
||||
INSERT INTO sys_user (id, username, password, email, phone, nickname, status, create_by, update_by, created_at, updated_at)
|
||||
VALUES
|
||||
(11, 'coach_zhang', '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C', 'coach_zhang@novalon.com', '13800138011', '张教练(瑜伽)', 1, 'system', 'system', NOW(), NOW()),
|
||||
(12, 'coach_li', '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C', 'coach_li@novalon.com', '13800138012', '李教练(动感单车)', 1, 'system', 'system', NOW(), NOW()),
|
||||
(13, 'coach_wang', '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C', 'coach_wang@novalon.com', '13800138013', '王教练(HIIT)', 1, 'system', 'system', NOW(), NOW()),
|
||||
(14, 'coach_zhao', '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C', 'coach_zhao@novalon.com', '13800138014', '赵教练(普拉提)', 1, 'system', 'system', NOW(), NOW()),
|
||||
(15, 'coach_chen', '$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C', 'coach_chen@novalon.com', '13800138015', '陈教练(搏击操)', 1, 'system', 'system', NOW(), NOW())
|
||||
ON CONFLICT (username) DO UPDATE SET
|
||||
password = EXCLUDED.password,
|
||||
status = EXCLUDED.status;
|
||||
|
||||
SELECT setval('sys_user_id_seq', 15);
|
||||
|
||||
-- ============================================
|
||||
-- 2. 分配教练角色(role_id=5)
|
||||
-- ============================================
|
||||
INSERT INTO user_role (user_id, role_id, created_by, created_at)
|
||||
VALUES
|
||||
(11, 5, 'system', NOW()),
|
||||
(12, 5, 'system', NOW()),
|
||||
(13, 5, 'system', NOW()),
|
||||
(14, 5, 'system', NOW()),
|
||||
(15, 5, 'system', NOW())
|
||||
ON CONFLICT (user_id, role_id) DO NOTHING;
|
||||
|
||||
-- ============================================
|
||||
-- 3. 为团课分配教练(按课型,无时间冲突)
|
||||
-- coach_id=11 张教练: 瑜伽 5门
|
||||
-- coach_id=12 李教练: 动感单车 5门
|
||||
-- coach_id=13 王教练: HIIT训练 5门
|
||||
-- coach_id=14 赵教练: 普拉提 5门
|
||||
-- coach_id=15 陈教练: 搏击操 5门
|
||||
-- ============================================
|
||||
|
||||
-- 瑜伽课程 → 张教练(11)
|
||||
UPDATE group_course SET coach_id = 11, updated_at = NOW()
|
||||
WHERE course_type = (SELECT id FROM group_course_type WHERE type_name = '瑜伽')
|
||||
AND deleted_at IS NULL;
|
||||
|
||||
-- 动感单车课程 → 李教练(12)
|
||||
UPDATE group_course SET coach_id = 12, updated_at = NOW()
|
||||
WHERE course_type = (SELECT id FROM group_course_type WHERE type_name = '动感单车')
|
||||
AND deleted_at IS NULL;
|
||||
|
||||
-- HIIT训练课程 → 王教练(13)
|
||||
UPDATE group_course SET coach_id = 13, updated_at = NOW()
|
||||
WHERE course_type = (SELECT id FROM group_course_type WHERE type_name = 'HIIT训练')
|
||||
AND deleted_at IS NULL;
|
||||
|
||||
-- 普拉提课程 → 赵教练(14)
|
||||
UPDATE group_course SET coach_id = 14, updated_at = NOW()
|
||||
WHERE course_type = (SELECT id FROM group_course_type WHERE type_name = '普拉提')
|
||||
AND deleted_at IS NULL;
|
||||
|
||||
-- 搏击操课程 → 陈教练(15)
|
||||
UPDATE group_course SET coach_id = 15, updated_at = NOW()
|
||||
WHERE course_type = (SELECT id FROM group_course_type WHERE type_name = '搏击操')
|
||||
AND deleted_at IS NULL;
|
||||
|
||||
-- ============================================
|
||||
-- 4. 验证:确认每个团课都有教练
|
||||
-- ============================================
|
||||
DO $$
|
||||
DECLARE
|
||||
null_count INTEGER;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO null_count FROM group_course WHERE coach_id IS NULL AND deleted_at IS NULL;
|
||||
IF null_count > 0 THEN
|
||||
RAISE NOTICE '警告:仍有 % 门团课缺少教练', null_count;
|
||||
ELSE
|
||||
RAISE NOTICE '所有团课已成功分配教练';
|
||||
END IF;
|
||||
END $$;
|
||||
+2
-2
@@ -53,7 +53,7 @@ COMMENT ON COLUMN group_course.start_time IS '开始时间';
|
||||
COMMENT ON COLUMN group_course.end_time IS '结束时间';
|
||||
COMMENT ON COLUMN group_course.max_members IS '最大参与人数';
|
||||
COMMENT ON COLUMN group_course.current_members IS '当前参与人数';
|
||||
COMMENT ON COLUMN group_course.status IS '状态(0正常 1已取消 2已结束 3进行中 4超时)';
|
||||
COMMENT ON COLUMN group_course.status IS '状态(0正常 1已取消 2已结束 3进行中 4超时 5教练缺席 6自动结束 7教练迟到)';
|
||||
COMMENT ON COLUMN group_course.actual_start_time IS '实际开课时间(教练点击开课时记录)';
|
||||
COMMENT ON COLUMN group_course.actual_end_time IS '实际结课时间(教练点击结课时记录)';
|
||||
COMMENT ON COLUMN group_course.location IS '上课地点';
|
||||
@@ -72,7 +72,7 @@ COMMENT ON COLUMN group_course_booking.course_id IS '团课ID';
|
||||
COMMENT ON COLUMN group_course_booking.member_id IS '用户ID';
|
||||
COMMENT ON COLUMN group_course_booking.member_card_id IS '会员卡ID';
|
||||
COMMENT ON COLUMN group_course_booking.booking_time IS '预约时间';
|
||||
COMMENT ON COLUMN group_course_booking.status IS '状态(0已预约 1已取消 2已出席 3缺席)';
|
||||
COMMENT ON COLUMN group_course_booking.status IS '状态(0已预约 1已取消 2已出席 3缺席 4教练缺席 5迟到)';
|
||||
COMMENT ON COLUMN group_course_booking.cancel_time IS '取消时间';
|
||||
COMMENT ON COLUMN group_course_booking.create_by IS '创建人';
|
||||
COMMENT ON COLUMN group_course_booking.update_by IS '更新人';
|
||||
|
||||
+2
-1
@@ -66,7 +66,8 @@ public class SecurityConfig {
|
||||
.pathMatchers("/api/payment/query").permitAll()
|
||||
.pathMatchers("/api/payment/notify").permitAll()
|
||||
.pathMatchers("/api/payment/refund").permitAll()
|
||||
.pathMatchers("/api/files/**").permitAll();
|
||||
.pathMatchers("/api/files/**").permitAll()
|
||||
.pathMatchers("/api/coach/**").permitAll();
|
||||
|
||||
if (isDevOrTest) {
|
||||
spec.pathMatchers("/swagger-ui.html").permitAll()
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
<module>gym-dataCount</module>
|
||||
<module>gym-auth</module>
|
||||
<module>gym-payment</module>
|
||||
<module>gym-coach</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
Reference in New Issue
Block a user