Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 493ecd3021 | |||
| 7340f02102 | |||
| 68fefae774 | |||
| ffb3f20774 |
@@ -0,0 +1,3 @@
|
|||||||
|
wrapperVersion=3.3.4
|
||||||
|
distributionType=only-script
|
||||||
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.15/apache-maven-3.9.15-bin.zip
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
<?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 https://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>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<groupId>cn.novalon.gym.manage</groupId>
|
||||||
|
<artifactId>gym-groupCourse</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<name>gym-groupCourse</name>
|
||||||
|
<description>Group Course Management Module</description>
|
||||||
|
<url/>
|
||||||
|
<licenses>
|
||||||
|
<license/>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer/>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection/>
|
||||||
|
<developerConnection/>
|
||||||
|
<tag/>
|
||||||
|
<url/>
|
||||||
|
</scm>
|
||||||
|
<properties>
|
||||||
|
<java.version>21</java.version>
|
||||||
|
</properties>
|
||||||
|
<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>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger.core.v3</groupId>
|
||||||
|
<artifactId>swagger-annotations-jakarta</artifactId>
|
||||||
|
<version>2.2.43</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Redis依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
package cn.novalon.gym.manage.groupcourse.converter;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseEntity;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class GroupCourseConverter {
|
||||||
|
public GroupCourse toDomain(GroupCourseEntity entity){
|
||||||
|
if(entity == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
GroupCourse groupCourse = new GroupCourse();
|
||||||
|
BeanUtil.copyProperties(entity,groupCourse);
|
||||||
|
log.info("转换bean,entity-domain:",groupCourse);
|
||||||
|
return groupCourse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupCourseEntity toEntity(GroupCourse domain){
|
||||||
|
if(domain == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
GroupCourseEntity entity = new GroupCourseEntity();
|
||||||
|
BeanUtil.copyProperties(domain,entity);
|
||||||
|
log.info("转换bean,domain-entity:",entity);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GroupCourse> toDomainList(List<GroupCourseEntity> entities){
|
||||||
|
if (entities == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return entities.stream()
|
||||||
|
.map(this::toDomain)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GroupCourseEntity> toEntityList(List<GroupCourse> domains){
|
||||||
|
if (domains == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return domains.stream()
|
||||||
|
.map(this::toEntity)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
package cn.novalon.gym.manage.groupcourse.dao;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.groupcourse.entity.GroupCourseEntity;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.r2dbc.repository.R2dbcRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface GroupCourseDao extends R2dbcRepository<GroupCourseEntity, Long> {
|
||||||
|
|
||||||
|
Mono<GroupCourseEntity> findByIdIsAndDeletedAtIsNull(Long id);
|
||||||
|
|
||||||
|
Flux<GroupCourseEntity> findAll();
|
||||||
|
|
||||||
|
Flux<GroupCourseEntity> findAll(Sort sort);
|
||||||
|
|
||||||
|
Flux<GroupCourseEntity> findAllByDeletedAtIsNull();
|
||||||
|
|
||||||
|
Flux<GroupCourseEntity> findAllByDeletedAtIsNull(Sort sort);
|
||||||
|
}
|
||||||
+142
@@ -0,0 +1,142 @@
|
|||||||
|
|
||||||
|
package cn.novalon.gym.manage.groupcourse.domain;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.sys.core.domain.BaseDomain;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public class GroupCourse extends BaseDomain{
|
||||||
|
|
||||||
|
//课程名称
|
||||||
|
@Schema(description = "团课名", example = "Push-up")
|
||||||
|
private String courseName;
|
||||||
|
|
||||||
|
//教练id
|
||||||
|
@Schema(description = "教练id", example = "1")
|
||||||
|
private Long coachId;
|
||||||
|
|
||||||
|
//课程类型
|
||||||
|
@Schema(description = "课程类型", example = "1")
|
||||||
|
private Long courseType;
|
||||||
|
|
||||||
|
//开始时间
|
||||||
|
@Schema(description = "开始时间", example = "2026-01-01")
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
|
||||||
|
//结束时间
|
||||||
|
@Schema(description = "结束时间", example = "2026-01-02")
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
|
//最大参与人数
|
||||||
|
@Schema(description = "最大参与人数", example = "20")
|
||||||
|
private Integer maxMembers;
|
||||||
|
|
||||||
|
//当前参与人数
|
||||||
|
@Schema(description = "当前参与人数", example = "2")
|
||||||
|
private Integer currentMembers;
|
||||||
|
|
||||||
|
//课程状态:0-正常,1-已取消,2-已结束
|
||||||
|
@Schema(description = "课程状态", example = "0")
|
||||||
|
private Long status;
|
||||||
|
|
||||||
|
//上课地点
|
||||||
|
@Schema(description = "上课地点", example = "龙泉驿区幸福路")
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
//封面图URL
|
||||||
|
@Schema(description = "封面图URL", example = "https://12345.com")
|
||||||
|
private String coverImage;
|
||||||
|
|
||||||
|
//课程描述
|
||||||
|
@Schema(description = "课程描述", example = "从入门到入土")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public String getCourseName() {
|
||||||
|
return courseName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCourseName(String courseName) {
|
||||||
|
this.courseName = courseName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCoachId() {
|
||||||
|
return coachId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoachId(Long coachId) {
|
||||||
|
this.coachId = coachId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCourseType() {
|
||||||
|
return courseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCourseType(Long courseType) {
|
||||||
|
this.courseType = courseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTime(LocalDateTime startTime) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndTime(LocalDateTime endTime) {
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxMembers() {
|
||||||
|
return maxMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxMembers(Integer maxMembers) {
|
||||||
|
this.maxMembers = maxMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCurrentMembers() {
|
||||||
|
return currentMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentMembers(Integer currentMembers) {
|
||||||
|
this.currentMembers = currentMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Long status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(String location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCoverImage() {
|
||||||
|
return coverImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoverImage(String coverImage) {
|
||||||
|
this.coverImage = coverImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
||||||
+144
@@ -0,0 +1,144 @@
|
|||||||
|
|
||||||
|
package cn.novalon.gym.manage.groupcourse.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;
|
||||||
|
|
||||||
|
@Table("group_course")
|
||||||
|
public class GroupCourseEntity extends BaseEntity {
|
||||||
|
|
||||||
|
//课程名称
|
||||||
|
@Column("course_name")
|
||||||
|
private String courseName;
|
||||||
|
|
||||||
|
//教练id
|
||||||
|
@Column("coach_id")
|
||||||
|
private Long coachId;
|
||||||
|
|
||||||
|
//课程类型
|
||||||
|
@Column("course_type")
|
||||||
|
private Long courseType;
|
||||||
|
|
||||||
|
//开始时间
|
||||||
|
@Column("start_time")
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
|
||||||
|
//结束时间
|
||||||
|
@Column("end_time")
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
|
//最大参与人数
|
||||||
|
@Column("max_members")
|
||||||
|
private Integer maxMembers;
|
||||||
|
|
||||||
|
//当前参与人数
|
||||||
|
@Column("current_members")
|
||||||
|
private Integer currentMembers;
|
||||||
|
|
||||||
|
//课程状态:0-正常,1-已取消,2-已结束
|
||||||
|
@Column("status")
|
||||||
|
private Long status;
|
||||||
|
|
||||||
|
//上课地点
|
||||||
|
@Column("location")
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
//封面图URL
|
||||||
|
@Column("cover_image")
|
||||||
|
private String coverImage;
|
||||||
|
|
||||||
|
//课程描述
|
||||||
|
@Column("description")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public String getCourseName() {
|
||||||
|
return courseName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCourseName(String courseName) {
|
||||||
|
this.courseName = courseName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCoachId() {
|
||||||
|
return coachId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoachId(Long coachId) {
|
||||||
|
this.coachId = coachId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCourseType() {
|
||||||
|
return courseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCourseType(Long courseType) {
|
||||||
|
this.courseType = courseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTime(LocalDateTime startTime) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndTime(LocalDateTime endTime) {
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxMembers() {
|
||||||
|
return maxMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxMembers(Integer maxMembers) {
|
||||||
|
this.maxMembers = maxMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCurrentMembers() {
|
||||||
|
return currentMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentMembers(Integer currentMembers) {
|
||||||
|
this.currentMembers = currentMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Long status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(String location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCoverImage() {
|
||||||
|
return coverImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoverImage(String coverImage) {
|
||||||
|
this.coverImage = coverImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
||||||
+128
@@ -0,0 +1,128 @@
|
|||||||
|
|
||||||
|
package cn.novalon.gym.manage.groupcourse.handler;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseService;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.service.RedisService;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Validator;
|
||||||
|
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.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Tag(name="团课管理",description = "团课相关操作")
|
||||||
|
public class GroupCourseHandler {
|
||||||
|
private final IGroupCourseService groupCourseService;
|
||||||
|
private final Validator validator;
|
||||||
|
private final RedisService redisService;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
public GroupCourseHandler(IGroupCourseService groupCourseService,
|
||||||
|
Validator validator,
|
||||||
|
RedisService redisService,
|
||||||
|
ObjectMapper objectMapper){
|
||||||
|
this.groupCourseService = groupCourseService;
|
||||||
|
this.validator = validator;
|
||||||
|
this.redisService = redisService;
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取所有团课", description = "获取系统中所有团课列表")
|
||||||
|
public Mono<ServerResponse> getAllGroupCourse(ServerRequest request){
|
||||||
|
boolean includeDeleted = Boolean.valueOf(request.queryParam("includeDeleted").orElse("false"));
|
||||||
|
return ServerResponse.ok()
|
||||||
|
.body(groupCourseService.findAll(includeDeleted), GroupCourse.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "分页获取团课", description = "根据分页参数获取团课列表")
|
||||||
|
public Mono<ServerResponse> getGroupCoursesByPage(ServerRequest request) {
|
||||||
|
return request.bodyToMono(PageRequest.class)
|
||||||
|
.flatMap(pageRequest -> {
|
||||||
|
boolean includeDeleted = request.queryParam("includeDeleted")
|
||||||
|
.map(Boolean::parseBoolean)
|
||||||
|
.orElse(false);
|
||||||
|
|
||||||
|
if (pageRequest.getPage() < 0) {
|
||||||
|
pageRequest.setPage(0);
|
||||||
|
}
|
||||||
|
if (pageRequest.getSize() <= 0 || pageRequest.getSize() > 100) {
|
||||||
|
pageRequest.setSize(10);
|
||||||
|
}
|
||||||
|
if (pageRequest.getSort() == null || pageRequest.getSort().isEmpty()) {
|
||||||
|
pageRequest.setSort("id");
|
||||||
|
}
|
||||||
|
if (pageRequest.getOrder() == null || pageRequest.getOrder().isEmpty()) {
|
||||||
|
pageRequest.setOrder("asc");
|
||||||
|
}
|
||||||
|
|
||||||
|
return groupCourseService.findByPage(pageRequest, includeDeleted)
|
||||||
|
.flatMap(response -> ServerResponse.ok().bodyValue(response));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "根据ID获取团课", description = "根据ID获取团课详情")
|
||||||
|
public Mono<ServerResponse> getGroupCourseById(ServerRequest request){
|
||||||
|
Long id = Long.valueOf(request.pathVariable("id"));
|
||||||
|
return ServerResponse.ok()
|
||||||
|
.body(groupCourseService.findById(id), GroupCourse.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "测试-根据Key获取Redis缓存", description = "测试接口:根据传入的key值获取Redis中缓存的数据")
|
||||||
|
public Mono<ServerResponse> getCacheByKey(ServerRequest request) {
|
||||||
|
return request.bodyToMono(Map.class)
|
||||||
|
.flatMap(body -> {
|
||||||
|
String key = (String) body.get("key");
|
||||||
|
|
||||||
|
if (key == null || key.isEmpty()) {
|
||||||
|
Map<String, Object> error = new HashMap<>();
|
||||||
|
error.put("success", false);
|
||||||
|
error.put("message", "key参数不能为空");
|
||||||
|
return ServerResponse.badRequest().bodyValue(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object cachedValue = redisService.get(key);
|
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
if (cachedValue != null) {
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("key", key);
|
||||||
|
result.put("value", cachedValue);
|
||||||
|
result.put("message", "缓存命中");
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (cachedValue instanceof String) {
|
||||||
|
Object jsonObject = objectMapper.readValue((String) cachedValue, Object.class);
|
||||||
|
result.put("parsedValue", jsonObject);
|
||||||
|
result.put("valueType", "JSON字符串");
|
||||||
|
} else {
|
||||||
|
result.put("valueType", cachedValue.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("parsedValue", null);
|
||||||
|
result.put("valueType", "无法解析");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("key", key);
|
||||||
|
result.put("value", null);
|
||||||
|
result.put("message", "缓存未命中");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ServerResponse.ok().bodyValue(result);
|
||||||
|
})
|
||||||
|
.onErrorResume(error -> {
|
||||||
|
Map<String, Object> errorResponse = new HashMap<>();
|
||||||
|
errorResponse.put("success", false);
|
||||||
|
errorResponse.put("message", "请求处理失败: " + error.getMessage());
|
||||||
|
return ServerResponse.status(500).bodyValue(errorResponse);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
package cn.novalon.gym.manage.groupcourse.repository;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||||
|
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
public interface IGroupCourseRepository {
|
||||||
|
Mono<GroupCourse> findByIdAndDeletedAtIsNull(Long id);
|
||||||
|
Flux<GroupCourse> findAll();
|
||||||
|
Flux<GroupCourse> findAll(Sort sort);
|
||||||
|
Flux<GroupCourse> findByDeletedAtIsNull();
|
||||||
|
Flux<GroupCourse> findByDeletedAtIsNull(Sort sort);
|
||||||
|
|
||||||
|
Mono<PageResponse<GroupCourse>> findByPage(PageRequest pageRequest);
|
||||||
|
Mono<PageResponse<GroupCourse>> findByPageAndNotDeleted(PageRequest pageRequest);
|
||||||
|
}
|
||||||
+131
@@ -0,0 +1,131 @@
|
|||||||
|
|
||||||
|
package cn.novalon.gym.manage.groupcourse.repository.impl;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||||
|
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.converter.GroupCourseConverter;
|
||||||
|
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.repository.IGroupCourseRepository;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||||
|
import org.springframework.data.relational.core.query.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class GroupCourseRepository implements IGroupCourseRepository {
|
||||||
|
private final GroupCourseDao groupCourseDao;
|
||||||
|
private final GroupCourseConverter groupCourseConverter;
|
||||||
|
private final R2dbcEntityTemplate r2dbcEntityTemplate;
|
||||||
|
|
||||||
|
public GroupCourseRepository(GroupCourseDao groupCourseDao, GroupCourseConverter groupCourseConverter,
|
||||||
|
R2dbcEntityTemplate r2dbcEntityTemplate){
|
||||||
|
this.groupCourseDao = groupCourseDao;
|
||||||
|
this.groupCourseConverter = groupCourseConverter;
|
||||||
|
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<GroupCourse> findByIdAndDeletedAtIsNull(Long id) {
|
||||||
|
return groupCourseDao.findByIdIsAndDeletedAtIsNull(id)
|
||||||
|
.map(groupCourseConverter::toDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<GroupCourse> findAll() {
|
||||||
|
return groupCourseDao.findAll()
|
||||||
|
.map(groupCourseConverter::toDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<GroupCourse> findAll(Sort sort) {
|
||||||
|
return groupCourseDao.findAll(sort)
|
||||||
|
.map(groupCourseConverter::toDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<GroupCourse> findByDeletedAtIsNull() {
|
||||||
|
return groupCourseDao.findAllByDeletedAtIsNull()
|
||||||
|
.map(groupCourseConverter::toDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<GroupCourse> findByDeletedAtIsNull(Sort sort) {
|
||||||
|
return groupCourseDao.findAllByDeletedAtIsNull(sort)
|
||||||
|
.map(groupCourseConverter::toDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<PageResponse<GroupCourse>> findByPage(PageRequest pageRequest) {
|
||||||
|
int page = pageRequest.getPage();
|
||||||
|
int size = pageRequest.getSize();
|
||||||
|
String sort = pageRequest.getSort();
|
||||||
|
String order = pageRequest.getOrder();
|
||||||
|
|
||||||
|
Sort sortObj = Sort.unsorted();
|
||||||
|
if (sort != null && !sort.isEmpty()) {
|
||||||
|
sortObj = Sort.by(Sort.Direction.fromString(order), sort);
|
||||||
|
}
|
||||||
|
|
||||||
|
org.springframework.data.domain.PageRequest pageable = org.springframework.data.domain.PageRequest.of(page, size, sortObj);
|
||||||
|
|
||||||
|
Query query = Query.empty();
|
||||||
|
|
||||||
|
return r2dbcEntityTemplate.select(GroupCourseEntity.class)
|
||||||
|
.matching(query.with(pageable))
|
||||||
|
.all()
|
||||||
|
.collectList()
|
||||||
|
.zipWith(r2dbcEntityTemplate.count(query, GroupCourseEntity.class))
|
||||||
|
.map(tuple -> {
|
||||||
|
long total = tuple.getT2();
|
||||||
|
int totalPages = (int) Math.ceil((double) total / size);
|
||||||
|
List<GroupCourse> courseList = tuple.getT1().stream()
|
||||||
|
.map(groupCourseConverter::toDomain)
|
||||||
|
.toList();
|
||||||
|
return new PageResponse<>(courseList, totalPages, total, page, size);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<PageResponse<GroupCourse>> findByPageAndNotDeleted(PageRequest pageRequest) {
|
||||||
|
int page = pageRequest.getPage();
|
||||||
|
int size = pageRequest.getSize();
|
||||||
|
String sort = pageRequest.getSort();
|
||||||
|
String order = pageRequest.getOrder();
|
||||||
|
|
||||||
|
Sort sortObj = Sort.unsorted();
|
||||||
|
if (sort != null && !sort.isEmpty()) {
|
||||||
|
sortObj = Sort.by(Sort.Direction.fromString(order), sort);
|
||||||
|
}
|
||||||
|
|
||||||
|
org.springframework.data.domain.PageRequest pageable = org.springframework.data.domain.PageRequest.of(page, size, sortObj);
|
||||||
|
|
||||||
|
return groupCourseDao.findAllByDeletedAtIsNull(sortObj)
|
||||||
|
.collectList()
|
||||||
|
.zipWith(groupCourseDao.findAllByDeletedAtIsNull().count())
|
||||||
|
.map(tuple -> {
|
||||||
|
List<GroupCourseEntity> allEntities = tuple.getT1();
|
||||||
|
long total = tuple.getT2();
|
||||||
|
|
||||||
|
int fromIndex = page * size;
|
||||||
|
int toIndex = Math.min(fromIndex + size, allEntities.size());
|
||||||
|
|
||||||
|
List<GroupCourse> courseList;
|
||||||
|
if (fromIndex < allEntities.size()) {
|
||||||
|
courseList = allEntities.subList(fromIndex, toIndex).stream()
|
||||||
|
.map(groupCourseConverter::toDomain)
|
||||||
|
.toList();
|
||||||
|
} else {
|
||||||
|
courseList = List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalPages = (int) Math.ceil((double) total / size);
|
||||||
|
return new PageResponse<>(courseList, totalPages, total, page, size);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
package cn.novalon.gym.manage.groupcourse.service;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||||
|
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
public interface IGroupCourseService {
|
||||||
|
Mono<GroupCourse> findById(Long id);
|
||||||
|
Flux<GroupCourse> findAll();
|
||||||
|
Flux<GroupCourse> findAll(boolean includeDeleted);
|
||||||
|
|
||||||
|
Mono<PageResponse<GroupCourse>> findByPage(PageRequest pageRequest, boolean includeDeleted);
|
||||||
|
}
|
||||||
+76
@@ -0,0 +1,76 @@
|
|||||||
|
package cn.novalon.gym.manage.groupcourse.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:liwentao
|
||||||
|
* @date:2026/5/15-05-15-16:05
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class RedisService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
// 设置值
|
||||||
|
public void set(String key, Object value) {
|
||||||
|
redisTemplate.opsForValue().set(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置值并指定过期时间(秒)
|
||||||
|
public void setWithExpire(String key, Object value, long timeout) {
|
||||||
|
redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取值
|
||||||
|
public Object get(String key) {
|
||||||
|
return redisTemplate.opsForValue().get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除key
|
||||||
|
public Boolean delete(String key) {
|
||||||
|
return redisTemplate.delete(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断key是否存在
|
||||||
|
public Boolean hasKey(String key) {
|
||||||
|
return redisTemplate.hasKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置过期时间
|
||||||
|
public Boolean expire(String key, long timeout) {
|
||||||
|
return redisTemplate.expire(key, timeout, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hash操作
|
||||||
|
public void putHash(String key, String hashKey, Object value) {
|
||||||
|
redisTemplate.opsForHash().put(key, hashKey, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getHash(String key, String hashKey) {
|
||||||
|
return redisTemplate.opsForHash().get(key, hashKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
// List操作
|
||||||
|
public void leftPush(String key, Object value) {
|
||||||
|
redisTemplate.opsForList().leftPush(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object rightPop(String key) {
|
||||||
|
return redisTemplate.opsForList().rightPop(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set操作
|
||||||
|
public void addToSet(String key, Object... values) {
|
||||||
|
redisTemplate.opsForSet().add(key, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Object> getSet(String key) {
|
||||||
|
return redisTemplate.opsForSet().members(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
+138
@@ -0,0 +1,138 @@
|
|||||||
|
|
||||||
|
package cn.novalon.gym.manage.groupcourse.service.impl;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||||
|
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.domain.GroupCourse;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.service.IGroupCourseService;
|
||||||
|
import cn.novalon.gym.manage.groupcourse.service.RedisService;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GroupCourseService implements IGroupCourseService {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(GroupCourseService.class);
|
||||||
|
|
||||||
|
private final IGroupCourseRepository groupCourseRepository;
|
||||||
|
private final RedisService redisService;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
private static final String CACHE_KEY_PREFIX = "group_course:page:";
|
||||||
|
private static final String CACHE_KEY_ID_PREFIX = "group_course:id:";
|
||||||
|
private static final long CACHE_EXPIRE_SECONDS = 300;
|
||||||
|
|
||||||
|
public GroupCourseService(IGroupCourseRepository groupCourseRepository,
|
||||||
|
RedisService redisService,
|
||||||
|
ObjectMapper objectMapper){
|
||||||
|
this.groupCourseRepository = groupCourseRepository;
|
||||||
|
this.redisService = redisService;
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<GroupCourse> findById(Long id) {
|
||||||
|
String cacheKey = CACHE_KEY_ID_PREFIX + id;
|
||||||
|
|
||||||
|
Object cachedData = redisService.get(cacheKey);
|
||||||
|
if (cachedData != null) {
|
||||||
|
try {
|
||||||
|
String json;
|
||||||
|
if (cachedData instanceof String) {
|
||||||
|
json = (String) cachedData;
|
||||||
|
} else {
|
||||||
|
json = objectMapper.writeValueAsString(cachedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupCourse groupCourse = objectMapper.readValue(json, GroupCourse.class);
|
||||||
|
logger.info("缓存命中 - findById: id={}", id);
|
||||||
|
return Mono.just(groupCourse);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
logger.warn("缓存解析失败,删除缓存 - id: {}, error: {}", id, e.getMessage());
|
||||||
|
redisService.delete(cacheKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("缓存未命中,查询数据库 - findById: id={}", id);
|
||||||
|
return groupCourseRepository.findByIdAndDeletedAtIsNull(id)
|
||||||
|
.doOnSuccess(groupCourse -> {
|
||||||
|
if (groupCourse != null) {
|
||||||
|
try {
|
||||||
|
String jsonData = objectMapper.writeValueAsString(groupCourse);
|
||||||
|
redisService.setWithExpire(cacheKey, jsonData, CACHE_EXPIRE_SECONDS);
|
||||||
|
logger.debug("缓存已设置 - findById: id={}", id);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
logger.error("缓存设置失败 - id: {}, error: {}", id, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<GroupCourse> findAll() {
|
||||||
|
return groupCourseRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<GroupCourse> findAll(boolean includeDeleted) {
|
||||||
|
if(includeDeleted){
|
||||||
|
return groupCourseRepository.findAll();
|
||||||
|
}else{
|
||||||
|
return groupCourseRepository.findByDeletedAtIsNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<PageResponse<GroupCourse>> findByPage(PageRequest pageRequest, boolean includeDeleted) {
|
||||||
|
int page = pageRequest.getPage();
|
||||||
|
int size = pageRequest.getSize();
|
||||||
|
|
||||||
|
String cacheKey = CACHE_KEY_PREFIX + page + ":" + size + ":" + includeDeleted;
|
||||||
|
|
||||||
|
Object cachedData = redisService.get(cacheKey);
|
||||||
|
if (cachedData != null) {
|
||||||
|
try {
|
||||||
|
String json;
|
||||||
|
if (cachedData instanceof String) {
|
||||||
|
json = (String) cachedData;
|
||||||
|
} else {
|
||||||
|
json = objectMapper.writeValueAsString(cachedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
PageResponse<GroupCourse> pageResponse = objectMapper.readValue(json,
|
||||||
|
objectMapper.getTypeFactory().constructParametricType(PageResponse.class, GroupCourse.class));
|
||||||
|
logger.info("缓存命中 - findByPage: key={}", cacheKey);
|
||||||
|
return Mono.just(pageResponse);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
logger.warn("缓存解析失败,删除缓存 - key: {}, error: {}", cacheKey, e.getMessage());
|
||||||
|
redisService.delete(cacheKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("缓存未命中,查询数据库 - findByPage: key={}", cacheKey);
|
||||||
|
Mono<PageResponse<GroupCourse>> resultMono;
|
||||||
|
if (includeDeleted) {
|
||||||
|
resultMono = groupCourseRepository.findByPage(pageRequest);
|
||||||
|
} else {
|
||||||
|
resultMono = groupCourseRepository.findByPageAndNotDeleted(pageRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultMono.doOnSuccess(pageResponse -> {
|
||||||
|
try {
|
||||||
|
String jsonData = objectMapper.writeValueAsString(pageResponse);
|
||||||
|
redisService.setWithExpire(cacheKey, jsonData, CACHE_EXPIRE_SECONDS);
|
||||||
|
logger.debug("缓存已设置 - findByPage: key={}", cacheKey);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
logger.error("缓存设置失败 - key: {}, error: {}", cacheKey, e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: gym-groupCourse
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package cn.novalon.gym.manage.groupcourse;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class GymGroupCourseApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,6 +18,11 @@
|
|||||||
<description>Application module for Novalon Manage API</description>
|
<description>Application module for Novalon Manage API</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.novalon.gym.manage</groupId>
|
||||||
|
<artifactId>gym-groupCourse</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
<groupId>cn.novalon.gym.manage</groupId>
|
||||||
<artifactId>manage-sys</artifactId>
|
<artifactId>manage-sys</artifactId>
|
||||||
@@ -133,6 +138,12 @@
|
|||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
|
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.novalon.gym.manage</groupId>
|
||||||
|
<artifactId>gym-groupCourse</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
+2
-2
@@ -15,10 +15,10 @@ import org.springframework.web.server.WebFilter;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootApplication(scanBasePackages = "cn.novalon.gym.manage", exclude = {
|
@SpringBootApplication(scanBasePackages = {"cn.novalon.gym.manage", "cn.novalon.gym.manage.groupcourse"}, exclude = {
|
||||||
ReactiveUserDetailsServiceAutoConfiguration.class })
|
ReactiveUserDetailsServiceAutoConfiguration.class })
|
||||||
@EnableR2dbcRepositories(basePackages = { "cn.novalon.gym.manage.db.dao",
|
@EnableR2dbcRepositories(basePackages = { "cn.novalon.gym.manage.db.dao",
|
||||||
"cn.novalon.gym.manage.sys.audit.repository" })
|
"cn.novalon.gym.manage.sys.audit.repository", "cn.novalon.gym.manage.groupcourse.dao" })
|
||||||
public class ManageApplication {
|
public class ManageApplication {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ManageApplication.class);
|
private static final Logger logger = LoggerFactory.getLogger(ManageApplication.class);
|
||||||
|
|||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
package cn.novalon.gym.manage.app.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author:liwentao
|
||||||
|
* @date:2026/5/15-05-15-16:01
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RedisConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||||
|
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||||
|
template.setConnectionFactory(factory);
|
||||||
|
|
||||||
|
// 创建ObjectMapper并配置
|
||||||
|
ObjectMapper om = new ObjectMapper();
|
||||||
|
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||||
|
om.activateDefaultTyping(om.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL);
|
||||||
|
|
||||||
|
// 使用GenericJackson2JsonRedisSerializer替代已弃用的方式
|
||||||
|
GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer(om);
|
||||||
|
|
||||||
|
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||||
|
StringRedisSerializer stringSerializer = new StringRedisSerializer();
|
||||||
|
template.setKeySerializer(stringSerializer);
|
||||||
|
template.setValueSerializer(genericJackson2JsonRedisSerializer);
|
||||||
|
template.setHashKeySerializer(stringSerializer);
|
||||||
|
template.setHashValueSerializer(genericJackson2JsonRedisSerializer);
|
||||||
|
|
||||||
|
template.afterPropertiesSet();
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
-40
@@ -1,10 +1,12 @@
|
|||||||
package cn.novalon.gym.manage.app.config;
|
package cn.novalon.gym.manage.app.config;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.auth.SysAuthHandler;
|
import cn.novalon.gym.manage.sys.handler.auth.SysAuthHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.auth.PasswordDiagnosticHandler;
|
import cn.novalon.gym.manage.sys.handler.auth.PasswordDiagnosticHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.config.SysConfigHandler;
|
import cn.novalon.gym.manage.sys.handler.config.SysConfigHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.dictionary.DictionaryHandler;
|
import cn.novalon.gym.manage.sys.handler.dictionary.DictionaryHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.dict.SysDictHandler;
|
import cn.novalon.gym.manage.sys.handler.dict.SysDictHandler;
|
||||||
|
|
||||||
import cn.novalon.gym.manage.sys.handler.log.SysLogHandler;
|
import cn.novalon.gym.manage.sys.handler.log.SysLogHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.log.OperationLogHandler;
|
import cn.novalon.gym.manage.sys.handler.log.OperationLogHandler;
|
||||||
import cn.novalon.gym.manage.sys.handler.menu.MenuHandler;
|
import cn.novalon.gym.manage.sys.handler.menu.MenuHandler;
|
||||||
@@ -22,21 +24,11 @@ import org.springframework.web.reactive.function.server.ServerResponse;
|
|||||||
|
|
||||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统路由配置类
|
|
||||||
*
|
|
||||||
* 文件定义:配置WebFlux函数式路由,将HTTP请求映射到对应的Handler方法
|
|
||||||
* 涉及业务:用户、角色、字典、菜单、公告、文件等所有RESTful API路由
|
|
||||||
* 算法:使用RouterFunctions.route()构建函数式路由规则
|
|
||||||
*
|
|
||||||
* @author 张翔
|
|
||||||
* @date 2026-03-13
|
|
||||||
*/
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SystemRouter {
|
public class SystemRouter {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RouterFunction<ServerResponse> systemRoutes(
|
public RouterFunction<ServerResponse> systemRoutes(
|
||||||
|
GroupCourseHandler groupCourseHandler,
|
||||||
DictionaryHandler dictionaryHandler,
|
DictionaryHandler dictionaryHandler,
|
||||||
SysUserHandler userHandler,
|
SysUserHandler userHandler,
|
||||||
MenuHandler menuHandler,
|
MenuHandler menuHandler,
|
||||||
@@ -52,12 +44,10 @@ public class SystemRouter {
|
|||||||
SysFileHandler fileHandler,
|
SysFileHandler fileHandler,
|
||||||
SysPermissionHandler permissionHandler,
|
SysPermissionHandler permissionHandler,
|
||||||
PasswordDiagnosticHandler passwordDiagnosticHandler) {
|
PasswordDiagnosticHandler passwordDiagnosticHandler) {
|
||||||
|
|
||||||
return route()
|
return route()
|
||||||
// ========== 诊断路由 ==========
|
|
||||||
.GET("/api/diagnostic/password", passwordDiagnosticHandler::diagnose)
|
.GET("/api/diagnostic/password", passwordDiagnosticHandler::diagnose)
|
||||||
|
|
||||||
// ========== 字典路由 ==========
|
|
||||||
.GET("/api/dictionaries", dictionaryHandler::getAllDictionaries)
|
.GET("/api/dictionaries", dictionaryHandler::getAllDictionaries)
|
||||||
.GET("/api/dictionaries/{id}", dictionaryHandler::getDictionaryById)
|
.GET("/api/dictionaries/{id}", dictionaryHandler::getDictionaryById)
|
||||||
.GET("/api/dictionaries/type/{type}", dictionaryHandler::getDictionariesByType)
|
.GET("/api/dictionaries/type/{type}", dictionaryHandler::getDictionariesByType)
|
||||||
@@ -65,8 +55,7 @@ public class SystemRouter {
|
|||||||
.POST("/api/dictionaries", dictionaryHandler::createDictionary)
|
.POST("/api/dictionaries", dictionaryHandler::createDictionary)
|
||||||
.PUT("/api/dictionaries/{id}", dictionaryHandler::updateDictionary)
|
.PUT("/api/dictionaries/{id}", dictionaryHandler::updateDictionary)
|
||||||
.DELETE("/api/dictionaries/{id}", dictionaryHandler::deleteDictionary)
|
.DELETE("/api/dictionaries/{id}", dictionaryHandler::deleteDictionary)
|
||||||
|
|
||||||
// ========== 用户路由 ==========
|
|
||||||
.GET("/api/users", userHandler::getAllUsers)
|
.GET("/api/users", userHandler::getAllUsers)
|
||||||
.GET("/api/users/page", userHandler::getUsersByPage)
|
.GET("/api/users/page", userHandler::getUsersByPage)
|
||||||
.GET("/api/users/count", userHandler::getUserCount)
|
.GET("/api/users/count", userHandler::getUserCount)
|
||||||
@@ -84,16 +73,14 @@ public class SystemRouter {
|
|||||||
.POST("/api/users/{id}/action/restore", userHandler::restoreUser)
|
.POST("/api/users/{id}/action/restore", userHandler::restoreUser)
|
||||||
.GET("/api/users/{id}/roles", userHandler::getUserRoles)
|
.GET("/api/users/{id}/roles", userHandler::getUserRoles)
|
||||||
.POST("/api/users/{id}/roles", userHandler::assignRoles)
|
.POST("/api/users/{id}/roles", userHandler::assignRoles)
|
||||||
|
|
||||||
// ========== 菜单路由 ==========
|
|
||||||
.GET("/api/menus", menuHandler::getAllMenus)
|
.GET("/api/menus", menuHandler::getAllMenus)
|
||||||
.GET("/api/menus/tree", menuHandler::getMenuTree)
|
.GET("/api/menus/tree", menuHandler::getMenuTree)
|
||||||
.GET("/api/menus/{id}", menuHandler::getMenuById)
|
.GET("/api/menus/{id}", menuHandler::getMenuById)
|
||||||
.POST("/api/menus", menuHandler::createMenu)
|
.POST("/api/menus", menuHandler::createMenu)
|
||||||
.PUT("/api/menus/{id}", menuHandler::updateMenu)
|
.PUT("/api/menus/{id}", menuHandler::updateMenu)
|
||||||
.DELETE("/api/menus/{id}", menuHandler::deleteMenu)
|
.DELETE("/api/menus/{id}", menuHandler::deleteMenu)
|
||||||
|
|
||||||
// ========== 角色路由 ==========
|
|
||||||
.GET("/api/roles", roleHandler::getAllRoles)
|
.GET("/api/roles", roleHandler::getAllRoles)
|
||||||
.GET("/api/roles/page", roleHandler::getRolesByPage)
|
.GET("/api/roles/page", roleHandler::getRolesByPage)
|
||||||
.GET("/api/roles/count", roleHandler::getRoleCount)
|
.GET("/api/roles/count", roleHandler::getRoleCount)
|
||||||
@@ -106,16 +93,14 @@ public class SystemRouter {
|
|||||||
.POST("/api/roles/{id}/restore", roleHandler::restoreRole)
|
.POST("/api/roles/{id}/restore", roleHandler::restoreRole)
|
||||||
.GET("/api/roles/{id}/permissions", permissionHandler::getPermissionsByRoleId)
|
.GET("/api/roles/{id}/permissions", permissionHandler::getPermissionsByRoleId)
|
||||||
.POST("/api/roles/{id}/permissions", permissionHandler::assignPermissionsToRole)
|
.POST("/api/roles/{id}/permissions", permissionHandler::assignPermissionsToRole)
|
||||||
|
|
||||||
// ========== 配置路由 ==========
|
|
||||||
.GET("/api/config", configHandler::getAllConfigs)
|
.GET("/api/config", configHandler::getAllConfigs)
|
||||||
.GET("/api/config/{id}", configHandler::getConfigById)
|
.GET("/api/config/{id}", configHandler::getConfigById)
|
||||||
.GET("/api/config/key/{configKey}", configHandler::getConfigByKey)
|
.GET("/api/config/key/{configKey}", configHandler::getConfigByKey)
|
||||||
.POST("/api/config", configHandler::createConfig)
|
.POST("/api/config", configHandler::createConfig)
|
||||||
.PUT("/api/config/{id}", configHandler::updateConfig)
|
.PUT("/api/config/{id}", configHandler::updateConfig)
|
||||||
.DELETE("/api/config/{id}", configHandler::deleteConfig)
|
.DELETE("/api/config/{id}", configHandler::deleteConfig)
|
||||||
|
|
||||||
// ========== 日志路由 ==========
|
|
||||||
.GET("/api/logs/login", logHandler::getAllLoginLogs)
|
.GET("/api/logs/login", logHandler::getAllLoginLogs)
|
||||||
.GET("/api/logs/login/page", logHandler::getLoginLogsByPage)
|
.GET("/api/logs/login/page", logHandler::getLoginLogsByPage)
|
||||||
.GET("/api/logs/login/count", logHandler::getLoginLogCount)
|
.GET("/api/logs/login/count", logHandler::getLoginLogCount)
|
||||||
@@ -134,16 +119,13 @@ public class SystemRouter {
|
|||||||
.GET("/api/logs/operation/count", operationLogHandler::getOperationLogCount)
|
.GET("/api/logs/operation/count", operationLogHandler::getOperationLogCount)
|
||||||
.GET("/api/logs/operation/{id}", operationLogHandler::getOperationLogById)
|
.GET("/api/logs/operation/{id}", operationLogHandler::getOperationLogById)
|
||||||
.POST("/api/logs/operation", operationLogHandler::createOperationLog)
|
.POST("/api/logs/operation", operationLogHandler::createOperationLog)
|
||||||
|
|
||||||
// ========== 认证路由 ==========
|
|
||||||
.POST("/api/auth/login", authHandler::login)
|
.POST("/api/auth/login", authHandler::login)
|
||||||
.POST("/api/auth/register", authHandler::register)
|
.POST("/api/auth/register", authHandler::register)
|
||||||
.POST("/api/auth/logout", authHandler::logout)
|
.POST("/api/auth/logout", authHandler::logout)
|
||||||
|
|
||||||
// ========== 统计路由 ==========
|
|
||||||
.GET("/api/stats/overview", statsHandler::getOverview)
|
.GET("/api/stats/overview", statsHandler::getOverview)
|
||||||
|
|
||||||
// ========== 数据字典路由 ==========
|
|
||||||
.GET("/api/dict/types", dictHandler::getAllDictTypes)
|
.GET("/api/dict/types", dictHandler::getAllDictTypes)
|
||||||
.GET("/api/dict/types/{id}", dictHandler::getDictTypeById)
|
.GET("/api/dict/types/{id}", dictHandler::getDictTypeById)
|
||||||
.GET("/api/dict/types/type/{dictType}", dictHandler::getDictTypeByType)
|
.GET("/api/dict/types/type/{dictType}", dictHandler::getDictTypeByType)
|
||||||
@@ -156,24 +138,21 @@ public class SystemRouter {
|
|||||||
.POST("/api/dict/data", dictHandler::createDictData)
|
.POST("/api/dict/data", dictHandler::createDictData)
|
||||||
.PUT("/api/dict/data/{id}", dictHandler::updateDictData)
|
.PUT("/api/dict/data/{id}", dictHandler::updateDictData)
|
||||||
.DELETE("/api/dict/data/{id}", dictHandler::deleteDictData)
|
.DELETE("/api/dict/data/{id}", dictHandler::deleteDictData)
|
||||||
|
|
||||||
// ========== 公告路由 ==========
|
|
||||||
.GET("/api/notices", noticeHandler::getAllNotices)
|
.GET("/api/notices", noticeHandler::getAllNotices)
|
||||||
.GET("/api/notices/{id}", noticeHandler::getNoticeById)
|
.GET("/api/notices/{id}", noticeHandler::getNoticeById)
|
||||||
.GET("/api/notices/status/{status}", noticeHandler::getNoticesByStatus)
|
.GET("/api/notices/status/{status}", noticeHandler::getNoticesByStatus)
|
||||||
.POST("/api/notices", noticeHandler::createNotice)
|
.POST("/api/notices", noticeHandler::createNotice)
|
||||||
.PUT("/api/notices/{id}", noticeHandler::updateNotice)
|
.PUT("/api/notices/{id}", noticeHandler::updateNotice)
|
||||||
.DELETE("/api/notices/{id}", noticeHandler::deleteNotice)
|
.DELETE("/api/notices/{id}", noticeHandler::deleteNotice)
|
||||||
|
|
||||||
// ========== 消息路由 ==========
|
|
||||||
.GET("/api/messages/user/{userId}", messageHandler::getMessagesByUser)
|
.GET("/api/messages/user/{userId}", messageHandler::getMessagesByUser)
|
||||||
.GET("/api/messages/user/{userId}/unread", messageHandler::getUnreadCount)
|
.GET("/api/messages/user/{userId}/unread", messageHandler::getUnreadCount)
|
||||||
.GET("/api/messages/user/{userId}/unread/list", messageHandler::getUnreadList)
|
.GET("/api/messages/user/{userId}/unread/list", messageHandler::getUnreadList)
|
||||||
.POST("/api/messages", messageHandler::createMessage)
|
.POST("/api/messages", messageHandler::createMessage)
|
||||||
.PUT("/api/messages/{id}/read", messageHandler::markAsRead)
|
.PUT("/api/messages/{id}/read", messageHandler::markAsRead)
|
||||||
.DELETE("/api/messages/{id}", messageHandler::deleteMessage)
|
.DELETE("/api/messages/{id}", messageHandler::deleteMessage)
|
||||||
|
|
||||||
// ========== 文件路由 ==========
|
|
||||||
.GET("/api/files", fileHandler::getAllFiles)
|
.GET("/api/files", fileHandler::getAllFiles)
|
||||||
.GET("/api/files/{id}", fileHandler::getFileById)
|
.GET("/api/files/{id}", fileHandler::getFileById)
|
||||||
.POST("/api/files/upload", fileHandler::uploadFile)
|
.POST("/api/files/upload", fileHandler::uploadFile)
|
||||||
@@ -182,8 +161,7 @@ public class SystemRouter {
|
|||||||
.GET("/api/files/{id}/preview", fileHandler::previewFile)
|
.GET("/api/files/{id}/preview", fileHandler::previewFile)
|
||||||
.GET("/api/files/preview/{fileName}", fileHandler::previewFileByName)
|
.GET("/api/files/preview/{fileName}", fileHandler::previewFileByName)
|
||||||
.DELETE("/api/files/{id}", fileHandler::deleteFile)
|
.DELETE("/api/files/{id}", fileHandler::deleteFile)
|
||||||
|
|
||||||
// ========== 权限路由 ==========
|
|
||||||
.GET("/api/permissions", permissionHandler::getAllPermissions)
|
.GET("/api/permissions", permissionHandler::getAllPermissions)
|
||||||
.GET("/api/permissions/{id}", permissionHandler::getPermissionById)
|
.GET("/api/permissions/{id}", permissionHandler::getPermissionById)
|
||||||
.GET("/api/permissions/code/{code}", permissionHandler::getPermissionByCode)
|
.GET("/api/permissions/code/{code}", permissionHandler::getPermissionByCode)
|
||||||
@@ -192,7 +170,12 @@ public class SystemRouter {
|
|||||||
.POST("/api/permissions", permissionHandler::createPermission)
|
.POST("/api/permissions", permissionHandler::createPermission)
|
||||||
.PUT("/api/permissions/{id}", permissionHandler::updatePermission)
|
.PUT("/api/permissions/{id}", permissionHandler::updatePermission)
|
||||||
.DELETE("/api/permissions/{id}", permissionHandler::deletePermission)
|
.DELETE("/api/permissions/{id}", permissionHandler::deletePermission)
|
||||||
|
|
||||||
|
.GET("/api/groupCourse", groupCourseHandler::getAllGroupCourse)
|
||||||
|
.POST("/api/groupCourse/page", groupCourseHandler::getGroupCoursesByPage)
|
||||||
|
.POST("/api/groupCourse/cache/get", groupCourseHandler::getCacheByKey)
|
||||||
|
.GET("/api/groupCourse/{id}", groupCourseHandler::getGroupCourseById)
|
||||||
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ spring:
|
|||||||
max-life-time: 30m
|
max-life-time: 30m
|
||||||
acquire-timeout: 3s
|
acquire-timeout: 3s
|
||||||
flyway:
|
flyway:
|
||||||
|
url: jdbc:postgresql://localhost:55432/manage_system
|
||||||
|
user: novalon
|
||||||
|
password: novalon123
|
||||||
enabled: true
|
enabled: true
|
||||||
locations: classpath:db/migration
|
locations: classpath:db/migration
|
||||||
baseline-on-migrate: true
|
baseline-on-migrate: true
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ spring:
|
|||||||
acquire-timeout: 5s
|
acquire-timeout: 5s
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:55432}/${DB_NAME:manage_system}
|
url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:55432}/${DB_NAME:manage_system}
|
||||||
username: ${DB_USERNAME:postgres}
|
username: ${DB_USERNAME:novalon}
|
||||||
password: ${DB_PASSWORD:postgres}
|
password: ${DB_PASSWORD:novalon123}
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
flyway:
|
flyway:
|
||||||
enabled: true
|
enabled: true
|
||||||
@@ -38,6 +38,21 @@ spring:
|
|||||||
user:
|
user:
|
||||||
name: disabled
|
name: disabled
|
||||||
password: disabled
|
password: disabled
|
||||||
|
data:
|
||||||
|
redis:
|
||||||
|
host: ${REDIS_HOST:localhost}
|
||||||
|
port: ${REDIS_PORT:6379}
|
||||||
|
password: ${REDIS_PASSWORD:novalon123}
|
||||||
|
timeout: 5000
|
||||||
|
lettuce:
|
||||||
|
pool:
|
||||||
|
max-active: 8 # 最大连接数
|
||||||
|
max-idle: 8 # 最大空闲连接
|
||||||
|
min-idle: 0 # 最小空闲连接
|
||||||
|
max-wait: -1ms # 连接等待时间
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
|
||||||
|
|
||||||
management:
|
management:
|
||||||
endpoints:
|
endpoints:
|
||||||
|
|||||||
@@ -99,6 +99,8 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
+1
@@ -10,6 +10,7 @@ import cn.novalon.gym.manage.sys.core.query.SysUserQuery;
|
|||||||
import cn.novalon.gym.manage.sys.core.repository.ISysUserRepository;
|
import cn.novalon.gym.manage.sys.core.repository.ISysUserRepository;
|
||||||
import cn.novalon.gym.manage.common.dto.PageRequest;
|
import cn.novalon.gym.manage.common.dto.PageRequest;
|
||||||
import cn.novalon.gym.manage.common.dto.PageResponse;
|
import cn.novalon.gym.manage.common.dto.PageResponse;
|
||||||
|
import cn.novalon.gym.manage.sys.dto.response.UserResponse;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||||
import org.springframework.data.relational.core.query.Query;
|
import org.springframework.data.relational.core.query.Query;
|
||||||
|
|||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
-- ============================================
|
||||||
|
-- 团课相关表
|
||||||
|
-- ============================================
|
||||||
|
|
||||||
|
-- 团课课程表
|
||||||
|
CREATE TABLE IF NOT EXISTS group_course (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
course_name VARCHAR(100) NOT NULL,
|
||||||
|
coach_id BIGINT,
|
||||||
|
course_type BIGINT,
|
||||||
|
start_time TIMESTAMP NOT NULL,
|
||||||
|
end_time TIMESTAMP NOT NULL,
|
||||||
|
max_members INTEGER DEFAULT 20,
|
||||||
|
current_members INTEGER DEFAULT 0,
|
||||||
|
status VARCHAR(1) DEFAULT '0',
|
||||||
|
location VARCHAR(255),
|
||||||
|
cover_image VARCHAR(500),
|
||||||
|
description TEXT,
|
||||||
|
create_by VARCHAR(50),
|
||||||
|
update_by VARCHAR(50),
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
deleted_at TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 团课预约记录表
|
||||||
|
CREATE TABLE IF NOT EXISTS group_course_booking (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
course_id BIGINT NOT NULL,
|
||||||
|
user_id BIGINT NOT NULL,
|
||||||
|
booking_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
status VARCHAR(1) DEFAULT '0',
|
||||||
|
cancel_time TIMESTAMP,
|
||||||
|
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 group_course IS '团课课程表';
|
||||||
|
COMMENT ON COLUMN group_course.id IS '主键ID';
|
||||||
|
COMMENT ON COLUMN group_course.course_name IS '课程名称';
|
||||||
|
COMMENT ON COLUMN group_course.coach_id IS '教练ID(关联sys_user)';
|
||||||
|
COMMENT ON COLUMN group_course.course_type IS '课程类型(如瑜伽/普拉提/动感单车)';
|
||||||
|
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已结束)';
|
||||||
|
COMMENT ON COLUMN group_course.location IS '上课地点';
|
||||||
|
COMMENT ON COLUMN group_course.cover_image IS '封面图URL';
|
||||||
|
COMMENT ON COLUMN group_course.description IS '课程描述';
|
||||||
|
COMMENT ON COLUMN group_course.create_by IS '创建人';
|
||||||
|
COMMENT ON COLUMN group_course.update_by IS '更新人';
|
||||||
|
COMMENT ON COLUMN group_course.created_at IS '创建时间';
|
||||||
|
COMMENT ON COLUMN group_course.updated_at IS '更新时间';
|
||||||
|
COMMENT ON COLUMN group_course.deleted_at IS '删除时间(软删除)';
|
||||||
|
|
||||||
|
COMMENT ON TABLE group_course_booking IS '团课预约记录表';
|
||||||
|
COMMENT ON COLUMN group_course_booking.id IS '主键ID';
|
||||||
|
COMMENT ON COLUMN group_course_booking.course_id IS '团课ID';
|
||||||
|
COMMENT ON COLUMN group_course_booking.user_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.cancel_time IS '取消时间';
|
||||||
|
COMMENT ON COLUMN group_course_booking.create_by IS '创建人';
|
||||||
|
COMMENT ON COLUMN group_course_booking.update_by IS '更新人';
|
||||||
|
COMMENT ON COLUMN group_course_booking.created_at IS '创建时间';
|
||||||
|
COMMENT ON COLUMN group_course_booking.updated_at IS '更新时间';
|
||||||
|
COMMENT ON COLUMN group_course_booking.deleted_at IS '删除时间(软删除)';
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
-- 测试数据1: 进行中的瑜伽课程 (已有部分学员)
|
||||||
|
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||||
|
('清晨流瑜伽', 101, 1, '2026-05-10 09:00:00', '2026-05-10 10:30:00', 15, 8, '1', 'A座3楼瑜伽教室', '/images/yoga_flow.jpg', '适合有一定基础的学员,通过流畅的体式连接呼吸,唤醒身体能量。', 'admin', '2026-05-01 10:00:00', '2026-05-01 10:00:00');
|
||||||
|
|
||||||
|
-- 测试数据2: 即将开始的搏击课 (几乎满员)
|
||||||
|
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||||
|
('燃脂搏击', 102, 2, '2026-05-12 18:30:00', '2026-05-12 19:30:00', 20, 19, '1', '综合训练区', '/images/kickboxing.jpg', '高强度间歇训练,配合音乐快速燃脂,释放压力。', 'coach_zhang', '2026-05-02 14:30:00', '2026-05-02 14:30:00');
|
||||||
|
|
||||||
|
-- 测试数据3: 已结束的私教小团课 (课程号已满)
|
||||||
|
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||||
|
('蜜桃臀塑造', 103, 3, '2026-04-25 19:00:00', '2026-04-25 20:00:00', 10, 10, '2', '私教专区', '/images/glute.jpg', '针对性训练臀部肌肉群,打造完美臀线。小班教学,动作一对一纠正。', 'coach_li', '2026-04-20 09:15:00', '2026-04-20 09:15:00');
|
||||||
|
|
||||||
|
-- 测试数据4: 即将开始的动感单车 (名额充足,尚未有人报名)
|
||||||
|
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at) VALUES
|
||||||
|
('极速燃脂单车', 104, 2, '2026-05-15 19:30:00', '2026-05-15 20:20:00', 25, 0, '0', '单车房', '/images/spinning.jpg', '跟随音乐节奏变换阻力和速度,体验爬坡与冲刺的快感,一节课消耗800大卡。', 'admin', '2026-05-06 11:00:00', '2026-05-06 11:00:00');
|
||||||
|
|
||||||
|
-- 测试数据5: 已删除/作废的课程 (deleted_at 不为空)
|
||||||
|
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, create_by, created_at, updated_at, deleted_at) VALUES
|
||||||
|
('周末冥想修复', 101, 1, '2026-05-03 15:00:00', '2026-05-03 16:00:00', 12, 3, '3', '冥想室', '/images/meditation.jpg', '通过呼吸和正念冥想,深度放松身心,缓解一周疲劳。', 'coach_wang', '2026-04-28 08:00:00', '2026-04-28 08:00:00', '2026-04-29 16:20:00');
|
||||||
+3
-1
@@ -50,7 +50,9 @@ public class SecurityConfig {
|
|||||||
spec.pathMatchers("/api/auth/**").permitAll()
|
spec.pathMatchers("/api/auth/**").permitAll()
|
||||||
.pathMatchers("/api/public/**").permitAll()
|
.pathMatchers("/api/public/**").permitAll()
|
||||||
.pathMatchers("/ws/**").permitAll()
|
.pathMatchers("/ws/**").permitAll()
|
||||||
.pathMatchers("/actuator/**").permitAll();
|
.pathMatchers("/actuator/**").permitAll()
|
||||||
|
.pathMatchers("/api/groupCourse/**").permitAll();
|
||||||
|
|
||||||
|
|
||||||
if (isDevOrTest) {
|
if (isDevOrTest) {
|
||||||
spec.pathMatchers("/swagger-ui.html").permitAll()
|
spec.pathMatchers("/swagger-ui.html").permitAll()
|
||||||
|
|||||||
+1
@@ -15,6 +15,7 @@ import cn.novalon.gym.manage.sys.core.repository.IUserRoleRepository;
|
|||||||
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
import cn.novalon.gym.manage.sys.core.service.ISysUserService;
|
||||||
import cn.novalon.gym.manage.sys.core.command.CreateUserCommand;
|
import cn.novalon.gym.manage.sys.core.command.CreateUserCommand;
|
||||||
import cn.novalon.gym.manage.sys.core.command.UpdateUserCommand;
|
import cn.novalon.gym.manage.sys.core.command.UpdateUserCommand;
|
||||||
|
import cn.novalon.gym.manage.sys.dto.response.UserResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
<module>manage-audit</module>
|
<module>manage-audit</module>
|
||||||
<module>manage-notify</module>
|
<module>manage-notify</module>
|
||||||
<module>manage-file</module>
|
<module>manage-file</module>
|
||||||
|
<module>gym-groupCourse</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@@ -221,6 +222,13 @@
|
|||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- HuTool工具箱-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.38</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
Reference in New Issue
Block a user