Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e4035e0ae | ||
|
|
e19324d0ef |
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,33 @@
|
|||||||
|
HELP.md
|
||||||
|
target/
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
@@ -12,88 +12,89 @@
|
|||||||
<artifactId>gym-dataCount</artifactId>
|
<artifactId>gym-dataCount</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<name>gym-dataCount</name>
|
<name>gym-dataCount</name>
|
||||||
<description>Data Statistics Module</description>
|
<description>Data Statistics Module for Gym Management</description>
|
||||||
<url/>
|
|
||||||
<licenses>
|
|
||||||
<license/>
|
|
||||||
</licenses>
|
|
||||||
<developers>
|
|
||||||
<developer/>
|
|
||||||
</developers>
|
|
||||||
<scm>
|
|
||||||
<connection/>
|
|
||||||
<developerConnection/>
|
|
||||||
<tag/>
|
|
||||||
<url/>
|
|
||||||
</scm>
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- Common模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
<groupId>cn.novalon.gym.manage</groupId>
|
||||||
<artifactId>manage-common</artifactId>
|
<artifactId>manage-common</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 数据库模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
<groupId>cn.novalon.gym.manage</groupId>
|
||||||
<artifactId>manage-db</artifactId>
|
<artifactId>manage-db</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- WebFlux -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- R2dbc -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
|
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
|
||||||
</dependency>
|
</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依赖-->
|
<!-- Redis -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 会员模块依赖 -->
|
<!-- Validation -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Swagger -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- POI for Excel export -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>5.2.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Gym Modules -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
<groupId>cn.novalon.gym.manage</groupId>
|
||||||
<artifactId>gym-member</artifactId>
|
<artifactId>gym-member</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 团课模块依赖 -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
<groupId>cn.novalon.gym.manage</groupId>
|
||||||
<artifactId>gym-groupCourse</artifactId>
|
<artifactId>gym-groupCourse</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 签到模块依赖 -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
<groupId>cn.novalon.gym.manage</groupId>
|
||||||
<artifactId>gym-checkIn</artifactId>
|
<artifactId>gym-checkIn</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -104,5 +105,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
</project>
|
||||||
</project>
|
|
||||||
|
|||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.datacount;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
|
||||||
|
|
||||||
@SpringBootApplication(scanBasePackages = "cn.novalon.gym.manage", exclude = {
|
|
||||||
ReactiveUserDetailsServiceAutoConfiguration.class })
|
|
||||||
@EnableR2dbcRepositories(basePackages = {
|
|
||||||
"cn.novalon.gym.manage.db.dao",
|
|
||||||
"cn.novalon.gym.manage.member.repository",
|
|
||||||
"cn.novalon.gym.manage.groupcourse.dao",
|
|
||||||
"cn.novalon.gym.manage.datacount.dao"
|
|
||||||
})
|
|
||||||
@ComponentScan(basePackages = "cn.novalon.gym.manage")
|
|
||||||
public class GymDataCountApplication {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GymDataCountApplication.class);
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
logger.info("数据统计模块启动中...");
|
|
||||||
SpringApplication.run(GymDataCountApplication.class, args);
|
|
||||||
logger.info("数据统计模块启动完成");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package cn.novalon.gym.manage.datacount.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据统计模块自动配置
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@AutoConfiguration
|
||||||
|
@ComponentScan(basePackages = "cn.novalon.gym.manage.datacount")
|
||||||
|
public class DataCountAutoConfiguration {
|
||||||
|
}
|
||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.datacount.config;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.datacount.handler.DataCountHandler;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
|
||||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
|
||||||
|
|
||||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class DataCountRouter {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RouterFunction<ServerResponse> dataCountRoutes(DataCountHandler dataCountHandler) {
|
|
||||||
return route()
|
|
||||||
// ========== 会员数据统计路由 ==========
|
|
||||||
.GET("/api/stats/member/date/{date}", dataCountHandler::getMemberStatisticsByDate)
|
|
||||||
.GET("/api/stats/member/range", dataCountHandler::getMemberStatisticsByDateRange)
|
|
||||||
.GET("/api/stats/member/summary", dataCountHandler::getMemberStatisticsSummary)
|
|
||||||
|
|
||||||
// ========== 预约数据统计路由 ==========
|
|
||||||
.GET("/api/stats/booking/date/{date}", dataCountHandler::getBookingStatisticsByDate)
|
|
||||||
.GET("/api/stats/booking/range", dataCountHandler::getBookingStatisticsByDateRange)
|
|
||||||
.GET("/api/stats/booking/summary", dataCountHandler::getBookingStatisticsSummary)
|
|
||||||
|
|
||||||
// ========== 签到数据统计路由 ==========
|
|
||||||
.GET("/api/stats/signin/date/{date}", dataCountHandler::getSignInStatisticsByDate)
|
|
||||||
.GET("/api/stats/signin/range", dataCountHandler::getSignInStatisticsByDateRange)
|
|
||||||
.GET("/api/stats/signin/summary", dataCountHandler::getSignInStatisticsSummary)
|
|
||||||
|
|
||||||
// ========== 数据导出路由 ==========
|
|
||||||
.GET("/api/stats/export/member", dataCountHandler::exportMemberStatistics)
|
|
||||||
.GET("/api/stats/export/booking", dataCountHandler::exportBookingStatistics)
|
|
||||||
.GET("/api/stats/export/signin", dataCountHandler::exportSignInStatistics)
|
|
||||||
.GET("/api/stats/export/all", dataCountHandler::exportAllStatistics)
|
|
||||||
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+183
@@ -0,0 +1,183 @@
|
|||||||
|
package cn.novalon.gym.manage.datacount.dao;
|
||||||
|
|
||||||
|
import org.springframework.r2dbc.core.DatabaseClient;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据统计 DAO - 使用 DatabaseClient 执行跨表聚合查询
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public class DataStatisticsDao {
|
||||||
|
|
||||||
|
private final DatabaseClient databaseClient;
|
||||||
|
|
||||||
|
public DataStatisticsDao(DatabaseClient databaseClient) {
|
||||||
|
this.databaseClient = databaseClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间范围内新增会员数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countNewMembers(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT COUNT(*) FROM member_user WHERE created_at >= :startTime AND created_at < :endTime AND is_deleted = false")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计总会员数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countTotalMembers() {
|
||||||
|
return databaseClient.sql("SELECT COUNT(*) FROM member_user WHERE is_deleted = false")
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间范围内的签到次数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countSignIns(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT COUNT(*) FROM sign_in_record WHERE sign_in_time >= :startTime AND sign_in_time < :endTime AND is_delete = false")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间范围内的成功签到次数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countSuccessSignIns(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT COUNT(*) FROM sign_in_record WHERE sign_in_time >= :startTime AND sign_in_time < :endTime AND sign_in_status = 'SUCCESS' AND is_delete = false")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间范围内签到的独立会员数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countDistinctSignInMembers(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT COUNT(DISTINCT member_id) FROM sign_in_record WHERE sign_in_time >= :startTime AND sign_in_time < :endTime AND is_delete = false")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间范围内的预约数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countBookings(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT COUNT(*) FROM group_course_booking WHERE booking_time >= :startTime AND booking_time < :endTime AND deleted_at IS NULL")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间范围内的取消预约数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countCancelBookings(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT COUNT(*) FROM group_course_booking WHERE booking_time >= :startTime AND booking_time < :endTime AND status = '1' AND deleted_at IS NULL")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间范围内的出席预约数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countAttendBookings(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT COUNT(*) FROM group_course_booking WHERE booking_time >= :startTime AND booking_time < :endTime AND status = '2' AND deleted_at IS NULL")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间范围内的缺席预约数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countAbsentBookings(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT COUNT(*) FROM group_course_booking WHERE booking_time >= :startTime AND booking_time < :endTime AND status = '3' AND deleted_at IS NULL")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间范围内有预约的独立会员数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countDistinctBookingMembers(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT COUNT(DISTINCT member_id) FROM group_course_booking WHERE booking_time >= :startTime AND booking_time < :endTime AND deleted_at IS NULL")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计指定时间范围内取消预约的独立会员数
|
||||||
|
*/
|
||||||
|
public Mono<Long> countDistinctCancelMembers(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT COUNT(DISTINCT member_id) FROM group_course_booking WHERE booking_time >= :startTime AND booking_time < :endTime AND status = '1' AND deleted_at IS NULL")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> row.get(0, Long.class))
|
||||||
|
.one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按签到类型统计次数
|
||||||
|
*/
|
||||||
|
public Flux<SignInTypeCount> countSignInsByType(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
return databaseClient.sql("SELECT sign_in_type as type, COUNT(*) as count FROM sign_in_record WHERE sign_in_time >= :startTime AND sign_in_time < :endTime AND is_delete = false GROUP BY sign_in_type")
|
||||||
|
.bind("startTime", startTime)
|
||||||
|
.bind("endTime", endTime)
|
||||||
|
.map(row -> {
|
||||||
|
SignInTypeCount result = new SignInTypeCount();
|
||||||
|
result.setType(row.get("type", String.class));
|
||||||
|
result.setCount(row.get("count", Long.class));
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
.all();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 签到类型计数结果
|
||||||
|
*/
|
||||||
|
public static class SignInTypeCount {
|
||||||
|
private String type;
|
||||||
|
private Long count;
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(Long count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
-270
@@ -1,270 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.datacount.dao;
|
|
||||||
|
|
||||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 统计数据访问层
|
|
||||||
* 使用 R2dbcEntityTemplate 执行原生SQL查询
|
|
||||||
*
|
|
||||||
* @author 数据统计模块
|
|
||||||
* @date 2026-06-06
|
|
||||||
*/
|
|
||||||
@Repository
|
|
||||||
public class StatisticsDao {
|
|
||||||
|
|
||||||
private final R2dbcEntityTemplate r2dbcEntityTemplate;
|
|
||||||
|
|
||||||
public StatisticsDao(R2dbcEntityTemplate r2dbcEntityTemplate) {
|
|
||||||
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 会员数据统计 ==========
|
|
||||||
|
|
||||||
public Mono<Integer> countTotalMembers() {
|
|
||||||
String sql = "SELECT COUNT(*) FROM member_user WHERE is_deleted = FALSE";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countNewMembersByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM member_user WHERE is_deleted = FALSE AND DATE(created_at) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countActiveMembersByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(DISTINCT m.id) FROM member_user m LEFT JOIN member_card_record r ON m.id = r.member_id WHERE m.is_deleted = FALSE AND r.deleted_at IS NULL AND DATE(r.created_at) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countMaleMembers() {
|
|
||||||
String sql = "SELECT COUNT(*) FROM member_user WHERE is_deleted = FALSE AND gender = 1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countFemaleMembers() {
|
|
||||||
String sql = "SELECT COUNT(*) FROM member_user WHERE is_deleted = FALSE AND gender = 2";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countCardPurchaseByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(DISTINCT r.member_id) FROM member_card_record r WHERE r.deleted_at IS NULL AND DATE(r.created_at) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Double> calculateAverageAge() {
|
|
||||||
String sql = "SELECT AVG(EXTRACT(YEAR FROM AGE(CURRENT_DATE, birthday))) FROM member_user WHERE is_deleted = FALSE AND birthday IS NOT NULL";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.map(row -> row.get(0, Double.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countActiveMembersByTimeRange(LocalDateTime startTime, LocalDateTime endTime) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM member_user WHERE is_deleted = FALSE AND last_login_at >= $1 AND last_login_at < $2";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, startTime)
|
|
||||||
.bind(1, endTime)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 预约数据统计 ==========
|
|
||||||
|
|
||||||
public Mono<Integer> countTotalBookingsByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM group_course_booking WHERE deleted_at IS NULL AND DATE(created_at) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countCancelledBookingsByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM group_course_booking WHERE deleted_at IS NULL AND status = '1' AND DATE(cancel_time) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countAttendedBookingsByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM group_course_booking WHERE deleted_at IS NULL AND status = '2' AND DATE(created_at) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countTotalCoursesByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM group_course WHERE deleted_at IS NULL AND DATE(start_time) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countFullCoursesByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM group_course WHERE deleted_at IS NULL AND current_members = max_members AND DATE(start_time) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Object[]> findMostPopularCourseByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT c.course_name, COUNT(b.id) as booking_count FROM group_course_booking b LEFT JOIN group_course c ON b.course_id = c.id WHERE b.deleted_at IS NULL AND c.deleted_at IS NULL AND DATE(b.created_at) = $1 GROUP BY c.id, c.course_name ORDER BY booking_count DESC LIMIT 1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> new Object[]{row.get(0, String.class), row.get(1, Integer.class)})
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 签到数据统计 ==========
|
|
||||||
|
|
||||||
public Mono<Integer> countTotalSignInsByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM sign_in_record WHERE is_delete = FALSE AND DATE(sign_in_time) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countSuccessSignInsByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM sign_in_record WHERE is_delete = FALSE AND sign_in_status = 'SUCCESS' AND DATE(sign_in_time) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countFailedSignInsByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM sign_in_record WHERE is_delete = FALSE AND sign_in_status = 'FAILED' AND DATE(sign_in_time) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countUniqueMembersByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(DISTINCT member_id) FROM sign_in_record WHERE is_delete = FALSE AND DATE(sign_in_time) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countQrCodeSignInsByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM sign_in_record WHERE is_delete = FALSE AND sign_in_type = 'QR_CODE' AND DATE(sign_in_time) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countManualSignInsByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM sign_in_record WHERE is_delete = FALSE AND sign_in_type = 'MANUAL' AND DATE(sign_in_time) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mono<Integer> countFaceSignInsByDate(LocalDate date) {
|
|
||||||
String sql = "SELECT COUNT(*) FROM sign_in_record WHERE is_delete = FALSE AND sign_in_type = 'FACE' AND DATE(sign_in_time) = $1";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, date)
|
|
||||||
.map(row -> row.get(0, Integer.class))
|
|
||||||
.one();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Flux<Object[]> findSignInStatisticsByDateRange(LocalDate startDate, LocalDate endDate) {
|
|
||||||
String sql = "SELECT DATE(s.sign_in_time) as date, " +
|
|
||||||
"COUNT(*) as total_sign_ins, " +
|
|
||||||
"SUM(CASE WHEN s.sign_in_status = 'SUCCESS' THEN 1 ELSE 0 END) as success_sign_ins, " +
|
|
||||||
"SUM(CASE WHEN s.sign_in_status = 'FAILED' THEN 1 ELSE 0 END) as failed_sign_ins, " +
|
|
||||||
"COUNT(DISTINCT s.member_id) as unique_members, " +
|
|
||||||
"SUM(CASE WHEN s.sign_in_type = 'QR_CODE' THEN 1 ELSE 0 END) as qr_code_sign_ins, " +
|
|
||||||
"SUM(CASE WHEN s.sign_in_type = 'MANUAL' THEN 1 ELSE 0 END) as manual_sign_ins, " +
|
|
||||||
"SUM(CASE WHEN s.sign_in_type = 'FACE' THEN 1 ELSE 0 END) as face_sign_ins " +
|
|
||||||
"FROM sign_in_record s " +
|
|
||||||
"WHERE s.is_delete = FALSE AND DATE(s.sign_in_time) BETWEEN $1 AND $2 " +
|
|
||||||
"GROUP BY DATE(s.sign_in_time) " +
|
|
||||||
"ORDER BY date";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, startDate)
|
|
||||||
.bind(1, endDate)
|
|
||||||
.map(row -> new Object[]{
|
|
||||||
row.get(0, LocalDate.class),
|
|
||||||
row.get(1, Integer.class),
|
|
||||||
row.get(2, Integer.class),
|
|
||||||
row.get(3, Integer.class),
|
|
||||||
row.get(4, Integer.class),
|
|
||||||
row.get(5, Integer.class),
|
|
||||||
row.get(6, Integer.class),
|
|
||||||
row.get(7, Integer.class)
|
|
||||||
})
|
|
||||||
.all();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 日期范围查询 ==========
|
|
||||||
|
|
||||||
public Flux<Object[]> findMemberStatisticsByDateRange(LocalDate startDate, LocalDate endDate) {
|
|
||||||
String sql = "SELECT DATE(m.created_at) as date, COUNT(*) as new_members FROM member_user m WHERE m.is_deleted = FALSE AND DATE(m.created_at) BETWEEN $1 AND $2 GROUP BY DATE(m.created_at) ORDER BY date";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, startDate)
|
|
||||||
.bind(1, endDate)
|
|
||||||
.map(row -> new Object[]{row.get(0, LocalDate.class), row.get(1, Integer.class)})
|
|
||||||
.all();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Flux<Object[]> findBookingStatisticsByDateRange(LocalDate startDate, LocalDate endDate) {
|
|
||||||
String sql = "SELECT DATE(b.created_at) as date, COUNT(*) as total_bookings, SUM(CASE WHEN b.status = '1' THEN 1 ELSE 0 END) as cancelled_bookings, SUM(CASE WHEN b.status = '2' THEN 1 ELSE 0 END) as attended_bookings FROM group_course_booking b WHERE b.deleted_at IS NULL AND DATE(b.created_at) BETWEEN $1 AND $2 GROUP BY DATE(b.created_at) ORDER BY date";
|
|
||||||
return r2dbcEntityTemplate.getDatabaseClient()
|
|
||||||
.sql(sql)
|
|
||||||
.bind(0, startDate)
|
|
||||||
.bind(1, endDate)
|
|
||||||
.map(row -> new Object[]{row.get(0, LocalDate.class), row.get(1, Integer.class), row.get(2, Integer.class), row.get(3, Integer.class)})
|
|
||||||
.all();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+50
-155
@@ -1,169 +1,64 @@
|
|||||||
package cn.novalon.gym.manage.datacount.domain;
|
package cn.novalon.gym.manage.datacount.domain;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
/**
|
||||||
|
* 预约数据统计结果
|
||||||
@Schema(description = "预约数据统计")
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class BookingStatistics {
|
public class BookingStatistics {
|
||||||
|
|
||||||
@Schema(description = "统计日期", example = "2026-01-01")
|
/**
|
||||||
private LocalDate date;
|
* 统计日期
|
||||||
|
*/
|
||||||
|
private String statDate;
|
||||||
|
|
||||||
@Schema(description = "预约总数", example = "100")
|
/**
|
||||||
private Integer totalBookings;
|
* 新增预约数
|
||||||
|
*/
|
||||||
|
private Long newBookings;
|
||||||
|
|
||||||
@Schema(description = "取消预约数", example = "10")
|
/**
|
||||||
private Integer cancelledBookings;
|
* 取消预约数
|
||||||
|
*/
|
||||||
|
private Long cancelBookings;
|
||||||
|
|
||||||
@Schema(description = "实际到场数", example = "85")
|
/**
|
||||||
private Integer attendedBookings;
|
* 出席预约数
|
||||||
|
*/
|
||||||
|
private Long attendBookings;
|
||||||
|
|
||||||
@Schema(description = "预约成功率", example = "0.85")
|
/**
|
||||||
private Double bookingSuccessRate;
|
* 缺席预约数
|
||||||
|
*/
|
||||||
|
private Long absentBookings;
|
||||||
|
|
||||||
@Schema(description = "取消率", example = "0.10")
|
/**
|
||||||
private Double cancellationRate;
|
* 预约出席率
|
||||||
|
*/
|
||||||
@Schema(description = "到场率", example = "0.85")
|
|
||||||
private Double attendanceRate;
|
private Double attendanceRate;
|
||||||
|
|
||||||
@Schema(description = "热门课程名称", example = "动感单车")
|
/**
|
||||||
private String popularCourseName;
|
* 取消率
|
||||||
|
*/
|
||||||
|
private Double cancelRate;
|
||||||
|
|
||||||
@Schema(description = "热门课程预约数", example = "25")
|
/**
|
||||||
private Integer popularCourseCount;
|
* 预约人数(独立会员数)
|
||||||
|
*/
|
||||||
|
private Long bookingMembers;
|
||||||
|
|
||||||
@Schema(description = "团课总数", example = "20")
|
/**
|
||||||
private Integer totalCourses;
|
* 取消人数(独立会员数)
|
||||||
|
*/
|
||||||
@Schema(description = "满员课程数", example = "5")
|
private Long cancelMembers;
|
||||||
private Integer fullCourses;
|
}
|
||||||
|
|
||||||
@Schema(description = "开始日期(用于汇总统计)")
|
|
||||||
private LocalDate startDate;
|
|
||||||
|
|
||||||
@Schema(description = "结束日期(用于汇总统计)")
|
|
||||||
private LocalDate endDate;
|
|
||||||
|
|
||||||
public BookingStatistics() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public BookingStatistics(LocalDate date) {
|
|
||||||
this.date = date;
|
|
||||||
this.totalBookings = 0;
|
|
||||||
this.cancelledBookings = 0;
|
|
||||||
this.attendedBookings = 0;
|
|
||||||
this.bookingSuccessRate = 0.0;
|
|
||||||
this.cancellationRate = 0.0;
|
|
||||||
this.attendanceRate = 0.0;
|
|
||||||
this.popularCourseName = "";
|
|
||||||
this.popularCourseCount = 0;
|
|
||||||
this.totalCourses = 0;
|
|
||||||
this.fullCourses = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getDate() {
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDate(LocalDate date) {
|
|
||||||
this.date = date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getTotalBookings() {
|
|
||||||
return totalBookings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotalBookings(Integer totalBookings) {
|
|
||||||
this.totalBookings = totalBookings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getCancelledBookings() {
|
|
||||||
return cancelledBookings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCancelledBookings(Integer cancelledBookings) {
|
|
||||||
this.cancelledBookings = cancelledBookings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getAttendedBookings() {
|
|
||||||
return attendedBookings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAttendedBookings(Integer attendedBookings) {
|
|
||||||
this.attendedBookings = attendedBookings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getBookingSuccessRate() {
|
|
||||||
return bookingSuccessRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBookingSuccessRate(Double bookingSuccessRate) {
|
|
||||||
this.bookingSuccessRate = bookingSuccessRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getCancellationRate() {
|
|
||||||
return cancellationRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCancellationRate(Double cancellationRate) {
|
|
||||||
this.cancellationRate = cancellationRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getAttendanceRate() {
|
|
||||||
return attendanceRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAttendanceRate(Double attendanceRate) {
|
|
||||||
this.attendanceRate = attendanceRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPopularCourseName() {
|
|
||||||
return popularCourseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPopularCourseName(String popularCourseName) {
|
|
||||||
this.popularCourseName = popularCourseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getPopularCourseCount() {
|
|
||||||
return popularCourseCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPopularCourseCount(Integer popularCourseCount) {
|
|
||||||
this.popularCourseCount = popularCourseCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getTotalCourses() {
|
|
||||||
return totalCourses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotalCourses(Integer totalCourses) {
|
|
||||||
this.totalCourses = totalCourses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getFullCourses() {
|
|
||||||
return fullCourses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFullCourses(Integer fullCourses) {
|
|
||||||
this.fullCourses = fullCourses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getStartDate() {
|
|
||||||
return startDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartDate(LocalDate startDate) {
|
|
||||||
this.startDate = startDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getEndDate() {
|
|
||||||
return endDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndDate(LocalDate endDate) {
|
|
||||||
this.endDate = endDate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+79
@@ -0,0 +1,79 @@
|
|||||||
|
package cn.novalon.gym.manage.datacount.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据统计结果域对象
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DataStatistics {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计类型:MEMBER-会员统计,BOOKING-预约统计,SIGN_IN-签到统计
|
||||||
|
*/
|
||||||
|
private String statType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计周期:DAY-日统计,WEEK-周统计,MONTH-月统计
|
||||||
|
*/
|
||||||
|
private String periodType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计日期(DAY时为具体日期,WEEK时为周开始日期,MONTH时为月份第一天)
|
||||||
|
*/
|
||||||
|
private LocalDateTime statDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计数据值
|
||||||
|
*/
|
||||||
|
private Long count;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联ID(如会员ID等)
|
||||||
|
*/
|
||||||
|
private Long relatedId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展数据(JSON格式存储额外信息)
|
||||||
|
*/
|
||||||
|
private String extraData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计周期常量
|
||||||
|
*/
|
||||||
|
public static final class PeriodType {
|
||||||
|
/** 日统计 */
|
||||||
|
public static final String DAY = "DAY";
|
||||||
|
/** 周统计 */
|
||||||
|
public static final String WEEK = "WEEK";
|
||||||
|
/** 月统计 */
|
||||||
|
public static final String MONTH = "MONTH";
|
||||||
|
|
||||||
|
private PeriodType() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计类型常量
|
||||||
|
*/
|
||||||
|
public static final class StatType {
|
||||||
|
/** 会员统计 */
|
||||||
|
public static final String MEMBER = "MEMBER";
|
||||||
|
/** 预约统计 */
|
||||||
|
public static final String BOOKING = "BOOKING";
|
||||||
|
/** 签到统计 */
|
||||||
|
public static final String SIGN_IN = "SIGN_IN";
|
||||||
|
|
||||||
|
private StatType() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
+43
-134
@@ -1,145 +1,54 @@
|
|||||||
package cn.novalon.gym.manage.datacount.domain;
|
package cn.novalon.gym.manage.datacount.domain;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
/**
|
||||||
|
* 会员数据统计结果
|
||||||
@Schema(description = "会员数据统计")
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class MemberStatistics {
|
public class MemberStatistics {
|
||||||
|
|
||||||
@Schema(description = "统计日期", example = "2026-01-01")
|
/**
|
||||||
private LocalDate date;
|
* 统计日期
|
||||||
|
*/
|
||||||
|
private String statDate;
|
||||||
|
|
||||||
@Schema(description = "新增会员数", example = "10")
|
/**
|
||||||
private Integer newMembers;
|
* 新增会员数
|
||||||
|
*/
|
||||||
|
private Long newMembers;
|
||||||
|
|
||||||
@Schema(description = "活跃会员数", example = "50")
|
/**
|
||||||
private Integer activeMembers;
|
* 活跃会员数(当天有签到或预约的会员)
|
||||||
|
*/
|
||||||
|
private Long activeMembers;
|
||||||
|
|
||||||
@Schema(description = "留存会员数", example = "45")
|
/**
|
||||||
private Integer retainedMembers;
|
* 累计会员总数
|
||||||
|
*/
|
||||||
|
private Long totalMembers;
|
||||||
|
|
||||||
@Schema(description = "总会员数", example = "200")
|
/**
|
||||||
private Integer totalMembers;
|
* 今日签到会员数
|
||||||
|
*/
|
||||||
|
private Long signInMembers;
|
||||||
|
|
||||||
@Schema(description = "男性会员数", example = "100")
|
/**
|
||||||
private Integer maleMembers;
|
* 今日预约会员数
|
||||||
|
*/
|
||||||
|
private Long bookingMembers;
|
||||||
|
|
||||||
@Schema(description = "女性会员数", example = "100")
|
/**
|
||||||
private Integer femaleMembers;
|
* 今日取消预约会员数
|
||||||
|
*/
|
||||||
@Schema(description = "会员卡购买人数", example = "30")
|
private Long cancelBookingMembers;
|
||||||
private Integer cardPurchaseCount;
|
}
|
||||||
|
|
||||||
@Schema(description = "平均年龄", example = "28")
|
|
||||||
private Double averageAge;
|
|
||||||
|
|
||||||
@Schema(description = "开始日期(用于汇总统计)")
|
|
||||||
private LocalDate startDate;
|
|
||||||
|
|
||||||
@Schema(description = "结束日期(用于汇总统计)")
|
|
||||||
private LocalDate endDate;
|
|
||||||
|
|
||||||
public MemberStatistics() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MemberStatistics(LocalDate date) {
|
|
||||||
this.date = date;
|
|
||||||
this.newMembers = 0;
|
|
||||||
this.activeMembers = 0;
|
|
||||||
this.retainedMembers = 0;
|
|
||||||
this.totalMembers = 0;
|
|
||||||
this.maleMembers = 0;
|
|
||||||
this.femaleMembers = 0;
|
|
||||||
this.cardPurchaseCount = 0;
|
|
||||||
this.averageAge = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getDate() {
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDate(LocalDate date) {
|
|
||||||
this.date = date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getNewMembers() {
|
|
||||||
return newMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNewMembers(Integer newMembers) {
|
|
||||||
this.newMembers = newMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getActiveMembers() {
|
|
||||||
return activeMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setActiveMembers(Integer activeMembers) {
|
|
||||||
this.activeMembers = activeMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getRetainedMembers() {
|
|
||||||
return retainedMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRetainedMembers(Integer retainedMembers) {
|
|
||||||
this.retainedMembers = retainedMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getTotalMembers() {
|
|
||||||
return totalMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotalMembers(Integer totalMembers) {
|
|
||||||
this.totalMembers = totalMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getMaleMembers() {
|
|
||||||
return maleMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaleMembers(Integer maleMembers) {
|
|
||||||
this.maleMembers = maleMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getFemaleMembers() {
|
|
||||||
return femaleMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFemaleMembers(Integer femaleMembers) {
|
|
||||||
this.femaleMembers = femaleMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getCardPurchaseCount() {
|
|
||||||
return cardPurchaseCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCardPurchaseCount(Integer cardPurchaseCount) {
|
|
||||||
this.cardPurchaseCount = cardPurchaseCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getAverageAge() {
|
|
||||||
return averageAge;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAverageAge(Double averageAge) {
|
|
||||||
this.averageAge = averageAge;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getStartDate() {
|
|
||||||
return startDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartDate(LocalDate startDate) {
|
|
||||||
this.startDate = startDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getEndDate() {
|
|
||||||
return endDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndDate(LocalDate endDate) {
|
|
||||||
this.endDate = endDate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+50
-143
@@ -1,157 +1,64 @@
|
|||||||
package cn.novalon.gym.manage.datacount.domain;
|
package cn.novalon.gym.manage.datacount.domain;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
/**
|
||||||
|
* 签到数据统计结果
|
||||||
@Schema(description = "签到数据统计")
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class SignInStatistics {
|
public class SignInStatistics {
|
||||||
|
|
||||||
@Schema(description = "统计日期", example = "2026-01-01")
|
/**
|
||||||
private LocalDate date;
|
* 统计日期
|
||||||
|
*/
|
||||||
|
private String statDate;
|
||||||
|
|
||||||
@Schema(description = "签到总次数", example = "100")
|
/**
|
||||||
private Integer totalSignIns;
|
* 签到总次数
|
||||||
|
*/
|
||||||
|
private Long totalSignIns;
|
||||||
|
|
||||||
@Schema(description = "成功签到次数", example = "95")
|
/**
|
||||||
private Integer successSignIns;
|
* 成功签到次数
|
||||||
|
*/
|
||||||
|
private Long successSignIns;
|
||||||
|
|
||||||
@Schema(description = "失败签到次数", example = "5")
|
/**
|
||||||
private Integer failedSignIns;
|
* 失败签到次数
|
||||||
|
*/
|
||||||
|
private Long failedSignIns;
|
||||||
|
|
||||||
@Schema(description = "签到成功率", example = "0.95")
|
/**
|
||||||
|
* 签到成功率
|
||||||
|
*/
|
||||||
private Double successRate;
|
private Double successRate;
|
||||||
|
|
||||||
@Schema(description = "签到会员数(去重)", example = "80")
|
/**
|
||||||
private Integer uniqueMembers;
|
* 签到人数(独立会员数)
|
||||||
|
*/
|
||||||
|
private Long signInMembers;
|
||||||
|
|
||||||
@Schema(description = "平均到店频次(月均)", example = "4.5")
|
/**
|
||||||
private Double averageFrequency;
|
* 扫码签到次数
|
||||||
|
*/
|
||||||
|
private Long qrCodeSignIns;
|
||||||
|
|
||||||
@Schema(description = "扫码签到次数", example = "80")
|
/**
|
||||||
private Integer qrCodeSignIns;
|
* 手动签到次数
|
||||||
|
*/
|
||||||
|
private Long manualSignIns;
|
||||||
|
|
||||||
@Schema(description = "手动签到次数", example = "15")
|
/**
|
||||||
private Integer manualSignIns;
|
* 人脸识别签到次数
|
||||||
|
*/
|
||||||
@Schema(description = "人脸识别签到次数", example = "5")
|
private Long faceSignIns;
|
||||||
private Integer faceSignIns;
|
}
|
||||||
|
|
||||||
@Schema(description = "开始日期(用于汇总统计)")
|
|
||||||
private LocalDate startDate;
|
|
||||||
|
|
||||||
@Schema(description = "结束日期(用于汇总统计)")
|
|
||||||
private LocalDate endDate;
|
|
||||||
|
|
||||||
public SignInStatistics() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public SignInStatistics(LocalDate date) {
|
|
||||||
this.date = date;
|
|
||||||
this.totalSignIns = 0;
|
|
||||||
this.successSignIns = 0;
|
|
||||||
this.failedSignIns = 0;
|
|
||||||
this.successRate = 0.0;
|
|
||||||
this.uniqueMembers = 0;
|
|
||||||
this.averageFrequency = 0.0;
|
|
||||||
this.qrCodeSignIns = 0;
|
|
||||||
this.manualSignIns = 0;
|
|
||||||
this.faceSignIns = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getDate() {
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDate(LocalDate date) {
|
|
||||||
this.date = date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getTotalSignIns() {
|
|
||||||
return totalSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotalSignIns(Integer totalSignIns) {
|
|
||||||
this.totalSignIns = totalSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getSuccessSignIns() {
|
|
||||||
return successSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSuccessSignIns(Integer successSignIns) {
|
|
||||||
this.successSignIns = successSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getFailedSignIns() {
|
|
||||||
return failedSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFailedSignIns(Integer failedSignIns) {
|
|
||||||
this.failedSignIns = failedSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getSuccessRate() {
|
|
||||||
return successRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSuccessRate(Double successRate) {
|
|
||||||
this.successRate = successRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getUniqueMembers() {
|
|
||||||
return uniqueMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUniqueMembers(Integer uniqueMembers) {
|
|
||||||
this.uniqueMembers = uniqueMembers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getAverageFrequency() {
|
|
||||||
return averageFrequency;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAverageFrequency(Double averageFrequency) {
|
|
||||||
this.averageFrequency = averageFrequency;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getQrCodeSignIns() {
|
|
||||||
return qrCodeSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQrCodeSignIns(Integer qrCodeSignIns) {
|
|
||||||
this.qrCodeSignIns = qrCodeSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getManualSignIns() {
|
|
||||||
return manualSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setManualSignIns(Integer manualSignIns) {
|
|
||||||
this.manualSignIns = manualSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getFaceSignIns() {
|
|
||||||
return faceSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFaceSignIns(Integer faceSignIns) {
|
|
||||||
this.faceSignIns = faceSignIns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getStartDate() {
|
|
||||||
return startDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartDate(LocalDate startDate) {
|
|
||||||
this.startDate = startDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getEndDate() {
|
|
||||||
return endDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndDate(LocalDate endDate) {
|
|
||||||
this.endDate = endDate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
-101
@@ -1,101 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.datacount.domain;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Schema(description = "统计数据导出DTO")
|
|
||||||
public class StatisticsExportDTO {
|
|
||||||
|
|
||||||
@Schema(description = "导出文件名", example = "statistics_report_20260101")
|
|
||||||
private String fileName;
|
|
||||||
|
|
||||||
@Schema(description = "导出格式", example = "EXCEL")
|
|
||||||
private String format;
|
|
||||||
|
|
||||||
@Schema(description = "开始日期", example = "2026-01-01")
|
|
||||||
private LocalDate startDate;
|
|
||||||
|
|
||||||
@Schema(description = "结束日期", example = "2026-01-31")
|
|
||||||
private LocalDate endDate;
|
|
||||||
|
|
||||||
@Schema(description = "导出类型", example = "MEMBER")
|
|
||||||
private String exportType;
|
|
||||||
|
|
||||||
@Schema(description = "会员统计数据")
|
|
||||||
private List<MemberStatistics> memberStatisticsList;
|
|
||||||
|
|
||||||
@Schema(description = "预约统计数据")
|
|
||||||
private List<BookingStatistics> bookingStatisticsList;
|
|
||||||
|
|
||||||
@Schema(description = "签到统计数据")
|
|
||||||
private List<SignInStatistics> signInStatisticsList;
|
|
||||||
|
|
||||||
public StatisticsExportDTO() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFileName() {
|
|
||||||
return fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFileName(String fileName) {
|
|
||||||
this.fileName = fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFormat() {
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFormat(String format) {
|
|
||||||
this.format = format;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getStartDate() {
|
|
||||||
return startDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartDate(LocalDate startDate) {
|
|
||||||
this.startDate = startDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDate getEndDate() {
|
|
||||||
return endDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndDate(LocalDate endDate) {
|
|
||||||
this.endDate = endDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExportType() {
|
|
||||||
return exportType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExportType(String exportType) {
|
|
||||||
this.exportType = exportType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MemberStatistics> getMemberStatisticsList() {
|
|
||||||
return memberStatisticsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMemberStatisticsList(List<MemberStatistics> memberStatisticsList) {
|
|
||||||
this.memberStatisticsList = memberStatisticsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<BookingStatistics> getBookingStatisticsList() {
|
|
||||||
return bookingStatisticsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBookingStatisticsList(List<BookingStatistics> bookingStatisticsList) {
|
|
||||||
this.bookingStatisticsList = bookingStatisticsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SignInStatistics> getSignInStatisticsList() {
|
|
||||||
return signInStatisticsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSignInStatisticsList(List<SignInStatistics> signInStatisticsList) {
|
|
||||||
this.signInStatisticsList = signInStatisticsList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package cn.novalon.gym.manage.datacount.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计数据查询请求
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class StatisticsQuery {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计类型:MEMBER-会员统计,BOOKING-预约统计,SIGN_IN-签到统计
|
||||||
|
* 空表示所有类型
|
||||||
|
*/
|
||||||
|
private String statType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计周期:DAY-日统计,WEEK-周统计,MONTH-月统计
|
||||||
|
*/
|
||||||
|
private String periodType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页页码
|
||||||
|
*/
|
||||||
|
private Integer page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每页大小
|
||||||
|
*/
|
||||||
|
private Integer size;
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package cn.novalon.gym.manage.datacount.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计数据汇总
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class StatisticsSummary {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计日期
|
||||||
|
*/
|
||||||
|
private String statDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员统计数据
|
||||||
|
*/
|
||||||
|
private MemberStatistics memberStatistics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预约统计数据
|
||||||
|
*/
|
||||||
|
private BookingStatistics bookingStatistics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 签到统计数据
|
||||||
|
*/
|
||||||
|
private SignInStatistics signInStatistics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计数据生成时间
|
||||||
|
*/
|
||||||
|
private String generatedAt;
|
||||||
|
}
|
||||||
-283
@@ -1,283 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.datacount.handler;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.datacount.domain.BookingStatistics;
|
|
||||||
import cn.novalon.gym.manage.datacount.domain.MemberStatistics;
|
|
||||||
import cn.novalon.gym.manage.datacount.domain.SignInStatistics;
|
|
||||||
import cn.novalon.gym.manage.datacount.service.IDataCountService;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
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.time.LocalDate;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Tag(name = "数据统计", description = "数据统计相关操作")
|
|
||||||
public class DataCountHandler {
|
|
||||||
|
|
||||||
private final IDataCountService dataCountService;
|
|
||||||
|
|
||||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
||||||
|
|
||||||
public DataCountHandler(IDataCountService dataCountService) {
|
|
||||||
this.dataCountService = dataCountService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "获取会员数据统计(按日期)", description = "获取指定日期的会员数据统计")
|
|
||||||
public Mono<ServerResponse> getMemberStatisticsByDate(ServerRequest request) {
|
|
||||||
String dateStr = request.pathVariable("date");
|
|
||||||
LocalDate date = LocalDate.parse(dateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
return dataCountService.getMemberStatisticsByDate(date)
|
|
||||||
.flatMap(stats -> ServerResponse.ok().bodyValue(stats))
|
|
||||||
.switchIfEmpty(ServerResponse.notFound().build())
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "获取会员数据统计(按日期范围)", description = "获取指定日期范围内的会员数据统计")
|
|
||||||
public Mono<ServerResponse> getMemberStatisticsByDateRange(ServerRequest request) {
|
|
||||||
String startDateStr = request.queryParam("startDate").orElseThrow(() -> new IllegalArgumentException("startDate必填"));
|
|
||||||
String endDateStr = request.queryParam("endDate").orElseThrow(() -> new IllegalArgumentException("endDate必填"));
|
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
|
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
return dataCountService.getMemberStatisticsByDateRange(startDate, endDate)
|
|
||||||
.collectList()
|
|
||||||
.flatMap(list -> ServerResponse.ok().bodyValue(list))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "获取会员数据统计汇总", description = "获取指定日期范围内的会员数据统计汇总")
|
|
||||||
public Mono<ServerResponse> getMemberStatisticsSummary(ServerRequest request) {
|
|
||||||
String startDateStr = request.queryParam("startDate").orElseThrow(() -> new IllegalArgumentException("startDate必填"));
|
|
||||||
String endDateStr = request.queryParam("endDate").orElseThrow(() -> new IllegalArgumentException("endDate必填"));
|
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
|
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
return dataCountService.getMemberStatisticsSummary(startDate, endDate)
|
|
||||||
.flatMap(summary -> ServerResponse.ok().bodyValue(summary))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "获取预约数据统计(按日期)", description = "获取指定日期的预约数据统计")
|
|
||||||
public Mono<ServerResponse> getBookingStatisticsByDate(ServerRequest request) {
|
|
||||||
String dateStr = request.pathVariable("date");
|
|
||||||
LocalDate date = LocalDate.parse(dateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
return dataCountService.getBookingStatisticsByDate(date)
|
|
||||||
.flatMap(stats -> ServerResponse.ok().bodyValue(stats))
|
|
||||||
.switchIfEmpty(ServerResponse.notFound().build())
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "获取预约数据统计(按日期范围)", description = "获取指定日期范围内的预约数据统计")
|
|
||||||
public Mono<ServerResponse> getBookingStatisticsByDateRange(ServerRequest request) {
|
|
||||||
String startDateStr = request.queryParam("startDate").orElseThrow(() -> new IllegalArgumentException("startDate必填"));
|
|
||||||
String endDateStr = request.queryParam("endDate").orElseThrow(() -> new IllegalArgumentException("endDate必填"));
|
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
|
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
return dataCountService.getBookingStatisticsByDateRange(startDate, endDate)
|
|
||||||
.collectList()
|
|
||||||
.flatMap(list -> ServerResponse.ok().bodyValue(list))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "获取预约数据统计汇总", description = "获取指定日期范围内的预约数据统计汇总")
|
|
||||||
public Mono<ServerResponse> getBookingStatisticsSummary(ServerRequest request) {
|
|
||||||
String startDateStr = request.queryParam("startDate").orElseThrow(() -> new IllegalArgumentException("startDate必填"));
|
|
||||||
String endDateStr = request.queryParam("endDate").orElseThrow(() -> new IllegalArgumentException("endDate必填"));
|
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
|
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
return dataCountService.getBookingStatisticsSummary(startDate, endDate)
|
|
||||||
.flatMap(summary -> ServerResponse.ok().bodyValue(summary))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "导出会员数据统计", description = "导出指定日期范围内的会员数据统计为CSV文件")
|
|
||||||
public Mono<ServerResponse> exportMemberStatistics(ServerRequest request) {
|
|
||||||
String startDateStr = request.queryParam("startDate").orElseThrow(() -> new IllegalArgumentException("startDate必填"));
|
|
||||||
String endDateStr = request.queryParam("endDate").orElseThrow(() -> new IllegalArgumentException("endDate必填"));
|
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
|
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
String fileName = "member_statistics_" + startDateStr + "_" + endDateStr + ".csv";
|
|
||||||
|
|
||||||
return dataCountService.exportMemberStatistics(startDate, endDate)
|
|
||||||
.flatMap(data -> ServerResponse.ok()
|
|
||||||
.header("Content-Disposition", "attachment; filename=" + fileName)
|
|
||||||
.header("Content-Type", "text/csv; charset=UTF-8")
|
|
||||||
.bodyValue(data))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "导出预约数据统计", description = "导出指定日期范围内的预约数据统计为CSV文件")
|
|
||||||
public Mono<ServerResponse> exportBookingStatistics(ServerRequest request) {
|
|
||||||
String startDateStr = request.queryParam("startDate").orElseThrow(() -> new IllegalArgumentException("startDate必填"));
|
|
||||||
String endDateStr = request.queryParam("endDate").orElseThrow(() -> new IllegalArgumentException("endDate必填"));
|
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
|
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
String fileName = "booking_statistics_" + startDateStr + "_" + endDateStr + ".csv";
|
|
||||||
|
|
||||||
return dataCountService.exportBookingStatistics(startDate, endDate)
|
|
||||||
.flatMap(data -> ServerResponse.ok()
|
|
||||||
.header("Content-Disposition", "attachment; filename=" + fileName)
|
|
||||||
.header("Content-Type", "text/csv; charset=UTF-8")
|
|
||||||
.bodyValue(data))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "导出全部统计数据", description = "导出指定日期范围内的会员和预约数据统计为CSV文件")
|
|
||||||
public Mono<ServerResponse> exportAllStatistics(ServerRequest request) {
|
|
||||||
String startDateStr = request.queryParam("startDate").orElseThrow(() -> new IllegalArgumentException("startDate必填"));
|
|
||||||
String endDateStr = request.queryParam("endDate").orElseThrow(() -> new IllegalArgumentException("endDate必填"));
|
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
|
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
String fileName = "all_statistics_" + startDateStr + "_" + endDateStr + ".csv";
|
|
||||||
|
|
||||||
return dataCountService.exportAllStatistics(startDate, endDate)
|
|
||||||
.flatMap(data -> ServerResponse.ok()
|
|
||||||
.header("Content-Disposition", "attachment; filename=" + fileName)
|
|
||||||
.header("Content-Type", "text/csv; charset=UTF-8")
|
|
||||||
.bodyValue(data))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== 签到数据统计 ==========
|
|
||||||
|
|
||||||
@Operation(summary = "获取签到数据统计(按日期)", description = "获取指定日期的签到数据统计")
|
|
||||||
public Mono<ServerResponse> getSignInStatisticsByDate(ServerRequest request) {
|
|
||||||
String dateStr = request.pathVariable("date");
|
|
||||||
LocalDate date = LocalDate.parse(dateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
return dataCountService.getSignInStatisticsByDate(date)
|
|
||||||
.flatMap(stats -> ServerResponse.ok().bodyValue(stats))
|
|
||||||
.switchIfEmpty(ServerResponse.notFound().build())
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "获取签到数据统计(按日期范围)", description = "获取指定日期范围内的签到数据统计")
|
|
||||||
public Mono<ServerResponse> getSignInStatisticsByDateRange(ServerRequest request) {
|
|
||||||
String startDateStr = request.queryParam("startDate").orElseThrow(() -> new IllegalArgumentException("startDate必填"));
|
|
||||||
String endDateStr = request.queryParam("endDate").orElseThrow(() -> new IllegalArgumentException("endDate必填"));
|
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
|
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
return dataCountService.getSignInStatisticsByDateRange(startDate, endDate)
|
|
||||||
.collectList()
|
|
||||||
.flatMap(list -> ServerResponse.ok().bodyValue(list))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "获取签到数据统计汇总", description = "获取指定日期范围内的签到数据统计汇总")
|
|
||||||
public Mono<ServerResponse> getSignInStatisticsSummary(ServerRequest request) {
|
|
||||||
String startDateStr = request.queryParam("startDate").orElseThrow(() -> new IllegalArgumentException("startDate必填"));
|
|
||||||
String endDateStr = request.queryParam("endDate").orElseThrow(() -> new IllegalArgumentException("endDate必填"));
|
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
|
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
return dataCountService.getSignInStatisticsSummary(startDate, endDate)
|
|
||||||
.flatMap(summary -> ServerResponse.ok().bodyValue(summary))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "导出签到数据统计", description = "导出指定日期范围内的签到数据统计为CSV文件")
|
|
||||||
public Mono<ServerResponse> exportSignInStatistics(ServerRequest request) {
|
|
||||||
String startDateStr = request.queryParam("startDate").orElseThrow(() -> new IllegalArgumentException("startDate必填"));
|
|
||||||
String endDateStr = request.queryParam("endDate").orElseThrow(() -> new IllegalArgumentException("endDate必填"));
|
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
|
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
|
|
||||||
|
|
||||||
String fileName = "signin_statistics_" + startDateStr + "_" + endDateStr + ".csv";
|
|
||||||
|
|
||||||
return dataCountService.exportSignInStatistics(startDate, endDate)
|
|
||||||
.flatMap(data -> ServerResponse.ok()
|
|
||||||
.header("Content-Disposition", "attachment; filename=" + fileName)
|
|
||||||
.header("Content-Type", "text/csv; charset=UTF-8")
|
|
||||||
.bodyValue(data))
|
|
||||||
.onErrorResume(error -> {
|
|
||||||
Map<String, Object> response = new HashMap<>();
|
|
||||||
response.put("success", false);
|
|
||||||
response.put("message", error.getMessage());
|
|
||||||
return ServerResponse.badRequest().bodyValue(response);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+125
@@ -0,0 +1,125 @@
|
|||||||
|
package cn.novalon.gym.manage.datacount.handler;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.datacount.domain.*;
|
||||||
|
import cn.novalon.gym.manage.datacount.service.IDataStatisticsService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
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.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据统计 Handler
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Tag(name = "数据统计", description = "数据统计相关操作")
|
||||||
|
public class DataStatisticsHandler {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IDataStatisticsService dataStatisticsService;
|
||||||
|
|
||||||
|
@Operation(summary = "获取综合统计数据", description = "获取会员、预约、签到综合统计数据")
|
||||||
|
public Mono<ServerResponse> getStatisticsSummary(ServerRequest request) {
|
||||||
|
StatisticsQuery query = buildQueryFromRequest(request);
|
||||||
|
|
||||||
|
return dataStatisticsService.getStatisticsSummaryWithCache(query)
|
||||||
|
.flatMap(summary -> ServerResponse.ok().bodyValue(summary))
|
||||||
|
.onErrorResume(e -> {
|
||||||
|
StatisticsSummary errorSummary = StatisticsSummary.builder()
|
||||||
|
.statDate(LocalDateTime.now().toLocalDate().toString())
|
||||||
|
.generatedAt(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))
|
||||||
|
.build();
|
||||||
|
return ServerResponse.ok().bodyValue(errorSummary);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取会员统计数据", description = "获取会员统计数据")
|
||||||
|
public Mono<ServerResponse> getMemberStatistics(ServerRequest request) {
|
||||||
|
StatisticsQuery query = buildQueryFromRequest(request);
|
||||||
|
|
||||||
|
return dataStatisticsService.getMemberStatistics(query)
|
||||||
|
.flatMap(stats -> ServerResponse.ok().bodyValue(stats))
|
||||||
|
.onErrorResume(e -> ServerResponse.ok().bodyValue(MemberStatistics.builder().statDate(query.getStartTime() != null ? query.getStartTime().toLocalDate().toString() : LocalDateTime.now().toLocalDate().toString()).build()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取预约统计数据", description = "获取预约统计数据")
|
||||||
|
public Mono<ServerResponse> getBookingStatistics(ServerRequest request) {
|
||||||
|
StatisticsQuery query = buildQueryFromRequest(request);
|
||||||
|
|
||||||
|
return dataStatisticsService.getBookingStatistics(query)
|
||||||
|
.flatMap(stats -> ServerResponse.ok().bodyValue(stats))
|
||||||
|
.onErrorResume(e -> ServerResponse.ok().bodyValue(BookingStatistics.builder().statDate(query.getStartTime() != null ? query.getStartTime().toLocalDate().toString() : LocalDateTime.now().toLocalDate().toString()).build()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取签到统计数据", description = "获取签到统计数据")
|
||||||
|
public Mono<ServerResponse> getSignInStatistics(ServerRequest request) {
|
||||||
|
StatisticsQuery query = buildQueryFromRequest(request);
|
||||||
|
|
||||||
|
return dataStatisticsService.getSignInStatistics(query)
|
||||||
|
.flatMap(stats -> ServerResponse.ok().bodyValue(stats))
|
||||||
|
.onErrorResume(e -> ServerResponse.ok().bodyValue(SignInStatistics.builder().statDate(query.getStartTime() != null ? query.getStartTime().toLocalDate().toString() : LocalDateTime.now().toLocalDate().toString()).build()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "查询历史统计数据", description = "查询历史统计数据")
|
||||||
|
public Mono<ServerResponse> queryHistoricalStatistics(ServerRequest request) {
|
||||||
|
StatisticsQuery query = buildQueryFromRequest(request);
|
||||||
|
|
||||||
|
return dataStatisticsService.queryHistoricalStatistics(query)
|
||||||
|
.collectList()
|
||||||
|
.flatMap(stats -> ServerResponse.ok().bodyValue(stats));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "导出统计数据", description = "导出统计数据为Excel文件")
|
||||||
|
public Mono<ServerResponse> exportStatistics(ServerRequest request) {
|
||||||
|
StatisticsQuery query = buildQueryFromRequest(request);
|
||||||
|
|
||||||
|
return dataStatisticsService.exportStatistics(query)
|
||||||
|
.flatMap(bytes -> {
|
||||||
|
String filename = "statistics_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + ".xlsx";
|
||||||
|
return ServerResponse.ok()
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")
|
||||||
|
.contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
|
||||||
|
.bodyValue(bytes);
|
||||||
|
})
|
||||||
|
.onErrorResume(e -> ServerResponse.ok().bodyValue("导出失败: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private StatisticsQuery buildQueryFromRequest(ServerRequest request) {
|
||||||
|
StatisticsQuery.StatisticsQueryBuilder builder = StatisticsQuery.builder();
|
||||||
|
|
||||||
|
request.queryParam("statType").ifPresent(builder::statType);
|
||||||
|
request.queryParam("periodType").ifPresent(builder::periodType);
|
||||||
|
request.queryParam("startTime").ifPresent(startTimeStr -> {
|
||||||
|
try {
|
||||||
|
builder.startTime(LocalDateTime.parse(startTimeStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
builder.startTime(LocalDateTime.parse(startTimeStr));
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
request.queryParam("endTime").ifPresent(endTimeStr -> {
|
||||||
|
try {
|
||||||
|
builder.endTime(LocalDateTime.parse(endTimeStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
builder.endTime(LocalDateTime.parse(endTimeStr));
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
+109
@@ -0,0 +1,109 @@
|
|||||||
|
package cn.novalon.gym.manage.datacount.scheduler;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.datacount.domain.DataStatistics;
|
||||||
|
import cn.novalon.gym.manage.datacount.service.IDataStatisticsService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据统计定时任务
|
||||||
|
* 每日凌晨执行统计数据更新
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class DataStatisticsScheduler {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(DataStatisticsScheduler.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IDataStatisticsService dataStatisticsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每日凌晨2点执行前一天的日统计数据
|
||||||
|
* 使用cron表达式: 0 0 2 * * ?
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 2 * * ?")
|
||||||
|
public void executeDailyStatistics() {
|
||||||
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
||||||
|
log.info("Starting daily statistics task for date: {}", yesterday);
|
||||||
|
|
||||||
|
dataStatisticsService.executeDailyStatistics(yesterday)
|
||||||
|
.subscribe(
|
||||||
|
null,
|
||||||
|
error -> log.error("Daily statistics task failed for date: {}", yesterday, error),
|
||||||
|
() -> log.info("Daily statistics task completed for date: {}", yesterday)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每周一凌晨3点执行上周的周统计数据
|
||||||
|
* 使用cron表达式: 0 0 3 ? * MON
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 3 ? * MON")
|
||||||
|
public void executeWeeklyStatistics() {
|
||||||
|
LocalDate lastWeek = LocalDate.now().minusWeeks(1);
|
||||||
|
log.info("Starting weekly statistics task for week of: {}", lastWeek);
|
||||||
|
|
||||||
|
// 执行上周每天的统计数据汇总
|
||||||
|
LocalDate weekStart = lastWeek.with(java.time.temporal.TemporalAdjusters.previousOrSame(java.time.DayOfWeek.MONDAY));
|
||||||
|
LocalDate weekEnd = lastWeek.with(java.time.temporal.TemporalAdjusters.nextOrSame(java.time.DayOfWeek.SUNDAY));
|
||||||
|
|
||||||
|
for (LocalDate date = weekStart; !date.isAfter(weekEnd); date = date.plusDays(1)) {
|
||||||
|
final LocalDate statDate = date;
|
||||||
|
dataStatisticsService.executeDailyStatistics(statDate)
|
||||||
|
.block();
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Weekly statistics task completed for week: {} - {}", weekStart, weekEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每月1日凌晨3点执行上个月的月统计数据
|
||||||
|
* 使用cron表达式: 0 0 3 1 * ?
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 3 1 * ?")
|
||||||
|
public void executeMonthlyStatistics() {
|
||||||
|
LocalDate lastMonth = LocalDate.now().minusMonths(1);
|
||||||
|
log.info("Starting monthly statistics task for month: {}", lastMonth.getMonth());
|
||||||
|
|
||||||
|
// 执行上个月每天的统计数据补全
|
||||||
|
LocalDate startOfMonth = lastMonth.withDayOfMonth(1);
|
||||||
|
LocalDate endOfMonth = lastMonth.with(java.time.temporal.TemporalAdjusters.lastDayOfMonth());
|
||||||
|
|
||||||
|
for (LocalDate date = startOfMonth; !date.isAfter(endOfMonth); date = date.plusDays(1)) {
|
||||||
|
final LocalDate statDate = date;
|
||||||
|
dataStatisticsService.executeDailyStatistics(statDate)
|
||||||
|
.block();
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Monthly statistics task completed for month: {}", lastMonth.getMonth());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每月15日凌晨4点清理30天前的旧统计数据
|
||||||
|
* 使用cron表达式: 0 0 4 15 * ?
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 4 15 * ?")
|
||||||
|
public void cleanupOldStatistics() {
|
||||||
|
LocalDate cutoffDate = LocalDate.now().minusDays(30);
|
||||||
|
log.info("Starting cleanup old statistics task, removing data before: {}", cutoffDate);
|
||||||
|
|
||||||
|
// 清理Redis中的旧统计数据
|
||||||
|
String pattern = "datacount:statistics:*:" + cutoffDate.toString();
|
||||||
|
cn.novalon.gym.manage.common.util.RedisUtil redisUtil = null;
|
||||||
|
try {
|
||||||
|
// 这里可以通过注入的service来清理,但当前实现使用Redis缓存30天自动过期
|
||||||
|
log.info("Old statistics cleanup completed, cutoff date: {}", cutoffDate);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to cleanup old statistics", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
-138
@@ -1,138 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.datacount.scheduler;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.datacount.service.IDataCountService;
|
|
||||||
import cn.novalon.gym.manage.datacount.service.impl.DataCountServiceImpl;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据统计定时任务
|
|
||||||
*
|
|
||||||
* 功能:每日凌晨1点自动计算前一天的数据统计并缓存到Redis
|
|
||||||
*
|
|
||||||
* @author 数据统计模块
|
|
||||||
* @date 2026-06-06
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class StatisticsDailyScheduler {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(StatisticsDailyScheduler.class);
|
|
||||||
|
|
||||||
private final IDataCountService dataCountService;
|
|
||||||
|
|
||||||
public StatisticsDailyScheduler(IDataCountService dataCountService) {
|
|
||||||
this.dataCountService = dataCountService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 每日凌晨1点执行前一天的统计数据计算并缓存
|
|
||||||
* cron表达式:秒 分 时 日 月 周
|
|
||||||
*/
|
|
||||||
@Scheduled(cron = "0 0 1 * * ?")
|
|
||||||
public void calculateDailyStatistics() {
|
|
||||||
LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
||||||
logger.info("定时任务开始计算 {} 的数据统计", yesterday);
|
|
||||||
|
|
||||||
dataCountService.getMemberStatisticsByDate(yesterday)
|
|
||||||
.doOnSuccess(stats -> logger.info("会员统计计算完成: date={}, newMembers={}, totalMembers={}",
|
|
||||||
yesterday, stats.getNewMembers(), stats.getTotalMembers()))
|
|
||||||
.doOnError(error -> logger.error("会员统计计算失败: date={}", yesterday, error))
|
|
||||||
.subscribe();
|
|
||||||
|
|
||||||
dataCountService.getBookingStatisticsByDate(yesterday)
|
|
||||||
.doOnSuccess(stats -> logger.info("预约统计计算完成: date={}, totalBookings={}, attendanceRate={}%",
|
|
||||||
yesterday, stats.getTotalBookings(), stats.getAttendanceRate()))
|
|
||||||
.doOnError(error -> logger.error("预约统计计算失败: date={}", yesterday, error))
|
|
||||||
.subscribe();
|
|
||||||
|
|
||||||
dataCountService.getSignInStatisticsByDate(yesterday)
|
|
||||||
.doOnSuccess(stats -> logger.info("签到统计计算完成: date={}, totalSignIns={}, successRate={}%",
|
|
||||||
yesterday, stats.getTotalSignIns(), stats.getSuccessRate()))
|
|
||||||
.doOnError(error -> logger.error("签到统计计算失败: date={}", yesterday, error))
|
|
||||||
.subscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 每周一凌晨2点执行上周的数据汇总统计
|
|
||||||
*/
|
|
||||||
@Scheduled(cron = "0 0 2 * * 1")
|
|
||||||
public void calculateWeeklyStatistics() {
|
|
||||||
LocalDate lastWeekEnd = LocalDate.now().minusDays(1);
|
|
||||||
LocalDate lastWeekStart = lastWeekEnd.minusDays(6);
|
|
||||||
logger.info("定时任务开始计算上周汇总统计: {} ~ {}", lastWeekStart, lastWeekEnd);
|
|
||||||
|
|
||||||
dataCountService.getMemberStatisticsSummary(lastWeekStart, lastWeekEnd)
|
|
||||||
.doOnSuccess(stats -> logger.info("上周会员汇总统计完成: newMembers={}", stats.getNewMembers()))
|
|
||||||
.doOnError(error -> logger.error("上周会员汇总统计失败", error))
|
|
||||||
.subscribe();
|
|
||||||
|
|
||||||
dataCountService.getBookingStatisticsSummary(lastWeekStart, lastWeekEnd)
|
|
||||||
.doOnSuccess(stats -> logger.info("上周预约汇总统计完成: totalBookings={}", stats.getTotalBookings()))
|
|
||||||
.doOnError(error -> logger.error("上周预约汇总统计失败", error))
|
|
||||||
.subscribe();
|
|
||||||
|
|
||||||
dataCountService.getSignInStatisticsSummary(lastWeekStart, lastWeekEnd)
|
|
||||||
.doOnSuccess(stats -> logger.info("上周签到汇总统计完成: totalSignIns={}", stats.getTotalSignIns()))
|
|
||||||
.doOnError(error -> logger.error("上周签到汇总统计失败", error))
|
|
||||||
.subscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 每月1号凌晨3点执行上月的数据汇总统计
|
|
||||||
*/
|
|
||||||
@Scheduled(cron = "0 0 3 1 * ?")
|
|
||||||
public void calculateMonthlyStatistics() {
|
|
||||||
LocalDate lastMonthEnd = LocalDate.now().minusDays(1);
|
|
||||||
LocalDate lastMonthStart = lastMonthEnd.withDayOfMonth(1);
|
|
||||||
logger.info("定时任务开始计算上月汇总统计: {} ~ {}", lastMonthStart, lastMonthEnd);
|
|
||||||
|
|
||||||
dataCountService.getMemberStatisticsSummary(lastMonthStart, lastMonthEnd)
|
|
||||||
.doOnSuccess(stats -> logger.info("上月会员汇总统计完成: newMembers={}", stats.getNewMembers()))
|
|
||||||
.doOnError(error -> logger.error("上月会员汇总统计失败", error))
|
|
||||||
.subscribe();
|
|
||||||
|
|
||||||
dataCountService.getBookingStatisticsSummary(lastMonthStart, lastMonthEnd)
|
|
||||||
.doOnSuccess(stats -> logger.info("上月预约汇总统计完成: totalBookings={}", stats.getTotalBookings()))
|
|
||||||
.doOnError(error -> logger.error("上月预约汇总统计失败", error))
|
|
||||||
.subscribe();
|
|
||||||
|
|
||||||
dataCountService.getSignInStatisticsSummary(lastMonthStart, lastMonthEnd)
|
|
||||||
.doOnSuccess(stats -> logger.info("上月签到汇总统计完成: totalSignIns={}", stats.getTotalSignIns()))
|
|
||||||
.doOnError(error -> logger.error("上月签到汇总统计失败", error))
|
|
||||||
.subscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 每日凌晨4点清理30天前的统计缓存数据
|
|
||||||
* 业务规则:统计数据保留30天(用于趋势分析),业务记录永久保存
|
|
||||||
*/
|
|
||||||
@Scheduled(cron = "0 0 4 * * ?")
|
|
||||||
public void cleanOldStatisticsCache() {
|
|
||||||
LocalDate thirtyDaysAgo = LocalDate.now().minusDays(30);
|
|
||||||
logger.info("定时任务开始清理30天前的统计缓存数据: before {}", thirtyDaysAgo);
|
|
||||||
|
|
||||||
String thirtyDaysAgoStr = thirtyDaysAgo.toString();
|
|
||||||
|
|
||||||
// 清理会员统计缓存
|
|
||||||
String memberCacheKey = DataCountServiceImpl.MEMBER_STATS_CACHE_PREFIX + thirtyDaysAgoStr;
|
|
||||||
dataCountService.getRedisUtil().delete(memberCacheKey)
|
|
||||||
.doOnSuccess(deleted -> logger.info("清理会员统计缓存: key={}, deleted={}", memberCacheKey, deleted))
|
|
||||||
.subscribe();
|
|
||||||
|
|
||||||
// 清理预约统计缓存
|
|
||||||
String bookingCacheKey = DataCountServiceImpl.BOOKING_STATS_CACHE_PREFIX + thirtyDaysAgoStr;
|
|
||||||
dataCountService.getRedisUtil().delete(bookingCacheKey)
|
|
||||||
.doOnSuccess(deleted -> logger.info("清理预约统计缓存: key={}, deleted={}", bookingCacheKey, deleted))
|
|
||||||
.subscribe();
|
|
||||||
|
|
||||||
// 清理签到统计缓存
|
|
||||||
String signInCacheKey = DataCountServiceImpl.SIGN_IN_STATS_CACHE_PREFIX + thirtyDaysAgoStr;
|
|
||||||
dataCountService.getRedisUtil().delete(signInCacheKey)
|
|
||||||
.doOnSuccess(deleted -> logger.info("清理签到统计缓存: key={}, deleted={}", signInCacheKey, deleted))
|
|
||||||
.subscribe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-44
@@ -1,44 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.datacount.service;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
|
||||||
import cn.novalon.gym.manage.datacount.domain.BookingStatistics;
|
|
||||||
import cn.novalon.gym.manage.datacount.domain.MemberStatistics;
|
|
||||||
import cn.novalon.gym.manage.datacount.domain.SignInStatistics;
|
|
||||||
import cn.novalon.gym.manage.datacount.domain.StatisticsExportDTO;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
public interface IDataCountService {
|
|
||||||
|
|
||||||
Mono<MemberStatistics> getMemberStatisticsByDate(LocalDate date);
|
|
||||||
|
|
||||||
Flux<MemberStatistics> getMemberStatisticsByDateRange(LocalDate startDate, LocalDate endDate);
|
|
||||||
|
|
||||||
Mono<MemberStatistics> getMemberStatisticsSummary(LocalDate startDate, LocalDate endDate);
|
|
||||||
|
|
||||||
Mono<BookingStatistics> getBookingStatisticsByDate(LocalDate date);
|
|
||||||
|
|
||||||
Flux<BookingStatistics> getBookingStatisticsByDateRange(LocalDate startDate, LocalDate endDate);
|
|
||||||
|
|
||||||
Mono<BookingStatistics> getBookingStatisticsSummary(LocalDate startDate, LocalDate endDate);
|
|
||||||
|
|
||||||
// ========== 签到数据统计 ==========
|
|
||||||
|
|
||||||
Mono<SignInStatistics> getSignInStatisticsByDate(LocalDate date);
|
|
||||||
|
|
||||||
Flux<SignInStatistics> getSignInStatisticsByDateRange(LocalDate startDate, LocalDate endDate);
|
|
||||||
|
|
||||||
Mono<SignInStatistics> getSignInStatisticsSummary(LocalDate startDate, LocalDate endDate);
|
|
||||||
|
|
||||||
Mono<byte[]> exportSignInStatistics(LocalDate startDate, LocalDate endDate);
|
|
||||||
|
|
||||||
Mono<byte[]> exportMemberStatistics(LocalDate startDate, LocalDate endDate);
|
|
||||||
|
|
||||||
Mono<byte[]> exportBookingStatistics(LocalDate startDate, LocalDate endDate);
|
|
||||||
|
|
||||||
Mono<byte[]> exportAllStatistics(LocalDate startDate, LocalDate endDate);
|
|
||||||
|
|
||||||
RedisUtil getRedisUtil();
|
|
||||||
}
|
|
||||||
+78
@@ -0,0 +1,78 @@
|
|||||||
|
package cn.novalon.gym.manage.datacount.service;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.datacount.domain.*;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据统计服务接口
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
public interface IDataStatisticsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取会员统计数据
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @return 会员统计数据
|
||||||
|
*/
|
||||||
|
Mono<MemberStatistics> getMemberStatistics(StatisticsQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取预约统计数据
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @return 预约统计数据
|
||||||
|
*/
|
||||||
|
Mono<BookingStatistics> getBookingStatistics(StatisticsQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取签到统计数据
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @return 签到统计数据
|
||||||
|
*/
|
||||||
|
Mono<SignInStatistics> getSignInStatistics(StatisticsQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取综合统计数据(包含会员、预约、签到)
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @return 综合统计数据
|
||||||
|
*/
|
||||||
|
Mono<StatisticsSummary> getStatisticsSummary(StatisticsQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询历史统计数据
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @return 历史统计数据列表
|
||||||
|
*/
|
||||||
|
Flux<DataStatistics> queryHistoricalStatistics(StatisticsQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行每日统计数据更新(定时任务调用)
|
||||||
|
*
|
||||||
|
* @param statDate 统计日期
|
||||||
|
* @return 更新结果
|
||||||
|
*/
|
||||||
|
Mono<Void> executeDailyStatistics(java.time.LocalDate statDate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出统计数据为Excel
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @return Excel文件的字节数组
|
||||||
|
*/
|
||||||
|
Mono<byte[]> exportStatistics(StatisticsQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取统计数据(带缓存)
|
||||||
|
*
|
||||||
|
* @param query 查询条件
|
||||||
|
* @return 统计数据
|
||||||
|
*/
|
||||||
|
Mono<StatisticsSummary> getStatisticsSummaryWithCache(StatisticsQuery query);
|
||||||
|
}
|
||||||
-475
@@ -1,475 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.datacount.service.impl;
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.common.util.RedisUtil;
|
|
||||||
import cn.novalon.gym.manage.datacount.dao.StatisticsDao;
|
|
||||||
import cn.novalon.gym.manage.datacount.domain.BookingStatistics;
|
|
||||||
import cn.novalon.gym.manage.datacount.domain.MemberStatistics;
|
|
||||||
import cn.novalon.gym.manage.datacount.domain.SignInStatistics;
|
|
||||||
import cn.novalon.gym.manage.datacount.service.IDataCountService;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class DataCountServiceImpl implements IDataCountService {
|
|
||||||
|
|
||||||
private final StatisticsDao statisticsDao;
|
|
||||||
private final RedisUtil redisUtil;
|
|
||||||
private final ObjectMapper objectMapper;
|
|
||||||
|
|
||||||
public static final String MEMBER_STATS_CACHE_PREFIX = "stats:member:";
|
|
||||||
public static final String BOOKING_STATS_CACHE_PREFIX = "stats:booking:";
|
|
||||||
public static final String SIGN_IN_STATS_CACHE_PREFIX = "stats:signin:";
|
|
||||||
private static final long CACHE_EXPIRE_SECONDS = 3600;
|
|
||||||
|
|
||||||
public DataCountServiceImpl(StatisticsDao statisticsDao, RedisUtil redisUtil, ObjectMapper objectMapper) {
|
|
||||||
this.statisticsDao = statisticsDao;
|
|
||||||
this.redisUtil = redisUtil;
|
|
||||||
this.objectMapper = objectMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<MemberStatistics> getMemberStatisticsByDate(LocalDate date) {
|
|
||||||
String cacheKey = MEMBER_STATS_CACHE_PREFIX + date.toString();
|
|
||||||
return redisUtil.get(cacheKey)
|
|
||||||
.flatMap(cached -> {
|
|
||||||
if (cached != null) {
|
|
||||||
try {
|
|
||||||
MemberStatistics stats = objectMapper.readValue(cached.toString(), MemberStatistics.class);
|
|
||||||
log.debug("从缓存获取会员统计数据, date: {}", date);
|
|
||||||
return Mono.just(stats);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("缓存数据解析失败, date: {}", date, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Mono.empty();
|
|
||||||
})
|
|
||||||
.switchIfEmpty(fetchMemberStatisticsByDate(date)
|
|
||||||
.flatMap(stats -> {
|
|
||||||
try {
|
|
||||||
String json = objectMapper.writeValueAsString(stats);
|
|
||||||
return redisUtil.setWithExpire(cacheKey, json, CACHE_EXPIRE_SECONDS)
|
|
||||||
.then(Mono.just(stats));
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("缓存会员统计数据失败, date: {}", date, e);
|
|
||||||
return Mono.just(stats);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Mono<MemberStatistics> fetchMemberStatisticsByDate(LocalDate date) {
|
|
||||||
return Mono.zip(
|
|
||||||
statisticsDao.countTotalMembers(),
|
|
||||||
statisticsDao.countNewMembersByDate(date),
|
|
||||||
statisticsDao.countActiveMembersByDate(date),
|
|
||||||
statisticsDao.countMaleMembers(),
|
|
||||||
statisticsDao.countFemaleMembers(),
|
|
||||||
statisticsDao.countCardPurchaseByDate(date),
|
|
||||||
statisticsDao.calculateAverageAge()
|
|
||||||
).map(tuple -> {
|
|
||||||
MemberStatistics stats = new MemberStatistics(date);
|
|
||||||
stats.setTotalMembers(tuple.getT1());
|
|
||||||
stats.setNewMembers(tuple.getT2());
|
|
||||||
stats.setActiveMembers(tuple.getT3());
|
|
||||||
stats.setMaleMembers(tuple.getT4());
|
|
||||||
stats.setFemaleMembers(tuple.getT5());
|
|
||||||
stats.setCardPurchaseCount(tuple.getT6());
|
|
||||||
stats.setAverageAge(tuple.getT7() != null ? tuple.getT7() : 0.0);
|
|
||||||
return stats;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Flux<MemberStatistics> getMemberStatisticsByDateRange(LocalDate startDate, LocalDate endDate) {
|
|
||||||
return statisticsDao.findMemberStatisticsByDateRange(startDate, endDate)
|
|
||||||
.map(row -> {
|
|
||||||
LocalDate date = (LocalDate) row[0];
|
|
||||||
MemberStatistics stats = new MemberStatistics(date);
|
|
||||||
stats.setNewMembers(((Number) row[1]).intValue());
|
|
||||||
return stats;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<MemberStatistics> getMemberStatisticsSummary(LocalDate startDate, LocalDate endDate) {
|
|
||||||
return getMemberStatisticsByDateRange(startDate, endDate)
|
|
||||||
.collectList()
|
|
||||||
.flatMap(list -> {
|
|
||||||
MemberStatistics summary = new MemberStatistics();
|
|
||||||
summary.setStartDate(startDate);
|
|
||||||
summary.setEndDate(endDate);
|
|
||||||
summary.setNewMembers(list.stream().mapToInt(MemberStatistics::getNewMembers).sum());
|
|
||||||
|
|
||||||
return Mono.zip(
|
|
||||||
statisticsDao.countTotalMembers(),
|
|
||||||
statisticsDao.countMaleMembers(),
|
|
||||||
statisticsDao.countFemaleMembers(),
|
|
||||||
statisticsDao.calculateAverageAge()
|
|
||||||
).map(tuple -> {
|
|
||||||
summary.setTotalMembers(tuple.getT1());
|
|
||||||
summary.setMaleMembers(tuple.getT2());
|
|
||||||
summary.setFemaleMembers(tuple.getT3());
|
|
||||||
summary.setAverageAge(tuple.getT4() != null ? tuple.getT4() : 0.0);
|
|
||||||
return summary;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<BookingStatistics> getBookingStatisticsByDate(LocalDate date) {
|
|
||||||
String cacheKey = BOOKING_STATS_CACHE_PREFIX + date.toString();
|
|
||||||
return redisUtil.get(cacheKey)
|
|
||||||
.flatMap(cached -> {
|
|
||||||
if (cached != null) {
|
|
||||||
try {
|
|
||||||
BookingStatistics stats = objectMapper.readValue(cached.toString(), BookingStatistics.class);
|
|
||||||
log.debug("从缓存获取预约统计数据, date: {}", date);
|
|
||||||
return Mono.just(stats);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("缓存数据解析失败, date: {}", date, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Mono.empty();
|
|
||||||
})
|
|
||||||
.switchIfEmpty(fetchBookingStatisticsByDate(date)
|
|
||||||
.flatMap(stats -> {
|
|
||||||
try {
|
|
||||||
String json = objectMapper.writeValueAsString(stats);
|
|
||||||
return redisUtil.setWithExpire(cacheKey, json, CACHE_EXPIRE_SECONDS)
|
|
||||||
.then(Mono.just(stats));
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("缓存预约统计数据失败, date: {}", date, e);
|
|
||||||
return Mono.just(stats);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Mono<BookingStatistics> fetchBookingStatisticsByDate(LocalDate date) {
|
|
||||||
return Mono.zip(
|
|
||||||
statisticsDao.countTotalBookingsByDate(date),
|
|
||||||
statisticsDao.countCancelledBookingsByDate(date),
|
|
||||||
statisticsDao.countAttendedBookingsByDate(date),
|
|
||||||
statisticsDao.countTotalCoursesByDate(date),
|
|
||||||
statisticsDao.countFullCoursesByDate(date),
|
|
||||||
statisticsDao.findMostPopularCourseByDate(date)
|
|
||||||
).map(tuple -> {
|
|
||||||
int totalBookings = tuple.getT1();
|
|
||||||
int cancelledBookings = tuple.getT2();
|
|
||||||
int attendedBookings = tuple.getT3();
|
|
||||||
|
|
||||||
BookingStatistics stats = new BookingStatistics(date);
|
|
||||||
stats.setTotalBookings(totalBookings);
|
|
||||||
stats.setCancelledBookings(cancelledBookings);
|
|
||||||
stats.setAttendedBookings(attendedBookings);
|
|
||||||
stats.setTotalCourses(tuple.getT4());
|
|
||||||
stats.setFullCourses(tuple.getT5());
|
|
||||||
|
|
||||||
if (totalBookings > 0) {
|
|
||||||
stats.setCancellationRate(Math.round(cancelledBookings * 10000.0 / totalBookings) / 100.0);
|
|
||||||
stats.setAttendanceRate(Math.round(attendedBookings * 10000.0 / totalBookings) / 100.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object[] popularCourse = tuple.getT6();
|
|
||||||
if (popularCourse != null && popularCourse.length >= 2) {
|
|
||||||
stats.setPopularCourseName((String) popularCourse[0]);
|
|
||||||
stats.setPopularCourseCount(((Number) popularCourse[1]).intValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
return stats;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Flux<BookingStatistics> getBookingStatisticsByDateRange(LocalDate startDate, LocalDate endDate) {
|
|
||||||
return statisticsDao.findBookingStatisticsByDateRange(startDate, endDate)
|
|
||||||
.map(row -> {
|
|
||||||
LocalDate date = (LocalDate) row[0];
|
|
||||||
int totalBookings = ((Number) row[1]).intValue();
|
|
||||||
int cancelledBookings = ((Number) row[2]).intValue();
|
|
||||||
int attendedBookings = ((Number) row[3]).intValue();
|
|
||||||
|
|
||||||
BookingStatistics stats = new BookingStatistics(date);
|
|
||||||
stats.setTotalBookings(totalBookings);
|
|
||||||
stats.setCancelledBookings(cancelledBookings);
|
|
||||||
stats.setAttendedBookings(attendedBookings);
|
|
||||||
|
|
||||||
if (totalBookings > 0) {
|
|
||||||
stats.setCancellationRate(Math.round(cancelledBookings * 10000.0 / totalBookings) / 100.0);
|
|
||||||
stats.setAttendanceRate(Math.round(attendedBookings * 10000.0 / totalBookings) / 100.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stats;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<BookingStatistics> getBookingStatisticsSummary(LocalDate startDate, LocalDate endDate) {
|
|
||||||
return getBookingStatisticsByDateRange(startDate, endDate)
|
|
||||||
.collectList()
|
|
||||||
.map(list -> {
|
|
||||||
BookingStatistics summary = new BookingStatistics();
|
|
||||||
summary.setStartDate(startDate);
|
|
||||||
summary.setEndDate(endDate);
|
|
||||||
summary.setTotalBookings(list.stream().mapToInt(BookingStatistics::getTotalBookings).sum());
|
|
||||||
summary.setCancelledBookings(list.stream().mapToInt(BookingStatistics::getCancelledBookings).sum());
|
|
||||||
summary.setAttendedBookings(list.stream().mapToInt(BookingStatistics::getAttendedBookings).sum());
|
|
||||||
|
|
||||||
int total = summary.getTotalBookings();
|
|
||||||
if (total > 0) {
|
|
||||||
summary.setCancellationRate(Math.round(summary.getCancelledBookings() * 10000.0 / total) / 100.0);
|
|
||||||
summary.setAttendanceRate(Math.round(summary.getAttendedBookings() * 10000.0 / total) / 100.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return summary;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<SignInStatistics> getSignInStatisticsByDate(LocalDate date) {
|
|
||||||
String cacheKey = SIGN_IN_STATS_CACHE_PREFIX + date.toString();
|
|
||||||
return redisUtil.get(cacheKey)
|
|
||||||
.flatMap(cached -> {
|
|
||||||
if (cached != null) {
|
|
||||||
try {
|
|
||||||
SignInStatistics stats = objectMapper.readValue(cached.toString(), SignInStatistics.class);
|
|
||||||
log.debug("从缓存获取签到统计数据, date: {}", date);
|
|
||||||
return Mono.just(stats);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("缓存数据解析失败, date: {}", date, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Mono.empty();
|
|
||||||
})
|
|
||||||
.switchIfEmpty(fetchSignInStatisticsByDate(date)
|
|
||||||
.flatMap(stats -> {
|
|
||||||
try {
|
|
||||||
String json = objectMapper.writeValueAsString(stats);
|
|
||||||
return redisUtil.setWithExpire(cacheKey, json, CACHE_EXPIRE_SECONDS)
|
|
||||||
.then(Mono.just(stats));
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("缓存签到统计数据失败, date: {}", date, e);
|
|
||||||
return Mono.just(stats);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Mono<SignInStatistics> fetchSignInStatisticsByDate(LocalDate date) {
|
|
||||||
return Mono.zip(
|
|
||||||
statisticsDao.countTotalSignInsByDate(date),
|
|
||||||
statisticsDao.countSuccessSignInsByDate(date),
|
|
||||||
statisticsDao.countFailedSignInsByDate(date),
|
|
||||||
statisticsDao.countUniqueMembersByDate(date),
|
|
||||||
statisticsDao.countQrCodeSignInsByDate(date),
|
|
||||||
statisticsDao.countManualSignInsByDate(date),
|
|
||||||
statisticsDao.countFaceSignInsByDate(date)
|
|
||||||
).map(tuple -> {
|
|
||||||
int totalSignIns = tuple.getT1();
|
|
||||||
int successSignIns = tuple.getT2();
|
|
||||||
int failedSignIns = tuple.getT3();
|
|
||||||
|
|
||||||
SignInStatistics stats = new SignInStatistics(date);
|
|
||||||
stats.setTotalSignIns(totalSignIns);
|
|
||||||
stats.setSuccessSignIns(successSignIns);
|
|
||||||
stats.setFailedSignIns(failedSignIns);
|
|
||||||
stats.setUniqueMembers(tuple.getT4());
|
|
||||||
stats.setQrCodeSignIns(tuple.getT5());
|
|
||||||
stats.setManualSignIns(tuple.getT6());
|
|
||||||
stats.setFaceSignIns(tuple.getT7());
|
|
||||||
|
|
||||||
if (totalSignIns > 0) {
|
|
||||||
stats.setSuccessRate(Math.round(successSignIns * 10000.0 / totalSignIns) / 100.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stats;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Flux<SignInStatistics> getSignInStatisticsByDateRange(LocalDate startDate, LocalDate endDate) {
|
|
||||||
return statisticsDao.findSignInStatisticsByDateRange(startDate, endDate)
|
|
||||||
.map(row -> {
|
|
||||||
LocalDate date = (LocalDate) row[0];
|
|
||||||
int totalSignIns = ((Number) row[1]).intValue();
|
|
||||||
int successSignIns = ((Number) row[2]).intValue();
|
|
||||||
int failedSignIns = ((Number) row[3]).intValue();
|
|
||||||
int uniqueMembers = ((Number) row[4]).intValue();
|
|
||||||
int qrCodeSignIns = ((Number) row[5]).intValue();
|
|
||||||
int manualSignIns = ((Number) row[6]).intValue();
|
|
||||||
int faceSignIns = ((Number) row[7]).intValue();
|
|
||||||
|
|
||||||
SignInStatistics stats = new SignInStatistics(date);
|
|
||||||
stats.setTotalSignIns(totalSignIns);
|
|
||||||
stats.setSuccessSignIns(successSignIns);
|
|
||||||
stats.setFailedSignIns(failedSignIns);
|
|
||||||
stats.setUniqueMembers(uniqueMembers);
|
|
||||||
stats.setQrCodeSignIns(qrCodeSignIns);
|
|
||||||
stats.setManualSignIns(manualSignIns);
|
|
||||||
stats.setFaceSignIns(faceSignIns);
|
|
||||||
|
|
||||||
if (totalSignIns > 0) {
|
|
||||||
stats.setSuccessRate(Math.round(successSignIns * 10000.0 / totalSignIns) / 100.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stats;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<SignInStatistics> getSignInStatisticsSummary(LocalDate startDate, LocalDate endDate) {
|
|
||||||
return getSignInStatisticsByDateRange(startDate, endDate)
|
|
||||||
.collectList()
|
|
||||||
.map(list -> {
|
|
||||||
SignInStatistics summary = new SignInStatistics();
|
|
||||||
summary.setStartDate(startDate);
|
|
||||||
summary.setEndDate(endDate);
|
|
||||||
summary.setTotalSignIns(list.stream().mapToInt(SignInStatistics::getTotalSignIns).sum());
|
|
||||||
summary.setSuccessSignIns(list.stream().mapToInt(SignInStatistics::getSuccessSignIns).sum());
|
|
||||||
summary.setFailedSignIns(list.stream().mapToInt(SignInStatistics::getFailedSignIns).sum());
|
|
||||||
summary.setUniqueMembers(list.stream().mapToInt(SignInStatistics::getUniqueMembers).sum());
|
|
||||||
summary.setQrCodeSignIns(list.stream().mapToInt(SignInStatistics::getQrCodeSignIns).sum());
|
|
||||||
summary.setManualSignIns(list.stream().mapToInt(SignInStatistics::getManualSignIns).sum());
|
|
||||||
summary.setFaceSignIns(list.stream().mapToInt(SignInStatistics::getFaceSignIns).sum());
|
|
||||||
|
|
||||||
int total = summary.getTotalSignIns();
|
|
||||||
if (total > 0) {
|
|
||||||
summary.setSuccessRate(Math.round(summary.getSuccessSignIns() * 10000.0 / total) / 100.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return summary;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<byte[]> exportSignInStatistics(LocalDate startDate, LocalDate endDate) {
|
|
||||||
return getSignInStatisticsByDateRange(startDate, endDate)
|
|
||||||
.collectList()
|
|
||||||
.map(this::generateSignInStatisticsCSV);
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] generateSignInStatisticsCSV(List<SignInStatistics> statsList) {
|
|
||||||
return generateSignInStatisticsCSVContent(statsList).getBytes(StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateSignInStatisticsCSVContent(List<SignInStatistics> statsList) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("统计日期,签到总次数,成功签到次数,失败签到次数,签到成功率(%),签到会员数,扫码签到次数,手动签到次数,人脸识别签到次数\n");
|
|
||||||
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
||||||
for (SignInStatistics stats : statsList) {
|
|
||||||
sb.append(stats.getDate().format(formatter)).append(",");
|
|
||||||
sb.append(stats.getTotalSignIns()).append(",");
|
|
||||||
sb.append(stats.getSuccessSignIns()).append(",");
|
|
||||||
sb.append(stats.getFailedSignIns()).append(",");
|
|
||||||
sb.append(String.format("%.2f", stats.getSuccessRate())).append(",");
|
|
||||||
sb.append(stats.getUniqueMembers()).append(",");
|
|
||||||
sb.append(stats.getQrCodeSignIns()).append(",");
|
|
||||||
sb.append(stats.getManualSignIns()).append(",");
|
|
||||||
sb.append(stats.getFaceSignIns()).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<byte[]> exportMemberStatistics(LocalDate startDate, LocalDate endDate) {
|
|
||||||
return getMemberStatisticsByDateRange(startDate, endDate)
|
|
||||||
.collectList()
|
|
||||||
.map(this::generateMemberStatisticsCSV);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<byte[]> exportBookingStatistics(LocalDate startDate, LocalDate endDate) {
|
|
||||||
return getBookingStatisticsByDateRange(startDate, endDate)
|
|
||||||
.collectList()
|
|
||||||
.map(this::generateBookingStatisticsCSV);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mono<byte[]> exportAllStatistics(LocalDate startDate, LocalDate endDate) {
|
|
||||||
return Mono.zip(
|
|
||||||
getMemberStatisticsByDateRange(startDate, endDate).collectList(),
|
|
||||||
getBookingStatisticsByDateRange(startDate, endDate).collectList(),
|
|
||||||
getSignInStatisticsByDateRange(startDate, endDate).collectList()
|
|
||||||
).map(tuple -> {
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
PrintWriter writer = new PrintWriter(new OutputStreamWriter(baos, StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
writer.println("=== 会员数据统计 ===");
|
|
||||||
writer.println(generateMemberStatisticsCSVContent(tuple.getT1()));
|
|
||||||
writer.println();
|
|
||||||
writer.println("=== 预约数据统计 ===");
|
|
||||||
writer.println(generateBookingStatisticsCSVContent(tuple.getT2()));
|
|
||||||
writer.println();
|
|
||||||
writer.println("=== 签到数据统计 ===");
|
|
||||||
writer.println(generateSignInStatisticsCSVContent(tuple.getT3()));
|
|
||||||
|
|
||||||
writer.flush();
|
|
||||||
return baos.toByteArray();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] generateMemberStatisticsCSV(List<MemberStatistics> statsList) {
|
|
||||||
return generateMemberStatisticsCSVContent(statsList).getBytes(StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateMemberStatisticsCSVContent(List<MemberStatistics> statsList) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("统计日期,新增会员数,活跃会员数,总会员数,男性会员数,女性会员数,购卡人数,平均年龄\n");
|
|
||||||
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
||||||
for (MemberStatistics stats : statsList) {
|
|
||||||
sb.append(stats.getDate().format(formatter)).append(",");
|
|
||||||
sb.append(stats.getNewMembers()).append(",");
|
|
||||||
sb.append(stats.getActiveMembers()).append(",");
|
|
||||||
sb.append(stats.getTotalMembers()).append(",");
|
|
||||||
sb.append(stats.getMaleMembers()).append(",");
|
|
||||||
sb.append(stats.getFemaleMembers()).append(",");
|
|
||||||
sb.append(stats.getCardPurchaseCount()).append(",");
|
|
||||||
sb.append(String.format("%.1f", stats.getAverageAge())).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] generateBookingStatisticsCSV(List<BookingStatistics> statsList) {
|
|
||||||
return generateBookingStatisticsCSVContent(statsList).getBytes(StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateBookingStatisticsCSVContent(List<BookingStatistics> statsList) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("统计日期,预约总数,取消预约数,实际到场数,取消率(%),到场率(%),热门课程,热门课程预约数,团课总数,满员课程数\n");
|
|
||||||
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
||||||
for (BookingStatistics stats : statsList) {
|
|
||||||
sb.append(stats.getDate().format(formatter)).append(",");
|
|
||||||
sb.append(stats.getTotalBookings()).append(",");
|
|
||||||
sb.append(stats.getCancelledBookings()).append(",");
|
|
||||||
sb.append(stats.getAttendedBookings()).append(",");
|
|
||||||
sb.append(String.format("%.2f", stats.getCancellationRate())).append(",");
|
|
||||||
sb.append(String.format("%.2f", stats.getAttendanceRate())).append(",");
|
|
||||||
sb.append(stats.getPopularCourseName() != null ? stats.getPopularCourseName() : "").append(",");
|
|
||||||
sb.append(stats.getPopularCourseCount()).append(",");
|
|
||||||
sb.append(stats.getTotalCourses()).append(",");
|
|
||||||
sb.append(stats.getFullCourses()).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RedisUtil getRedisUtil() {
|
|
||||||
return redisUtil;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+513
@@ -0,0 +1,513 @@
|
|||||||
|
package cn.novalon.gym.manage.datacount.service.impl;
|
||||||
|
|
||||||
|
import cn.novalon.gym.manage.checkIn.entity.SignInRecord;
|
||||||
|
import cn.novalon.gym.manage.common.util.RedisUtil;
|
||||||
|
import cn.novalon.gym.manage.datacount.dao.DataStatisticsDao;
|
||||||
|
import cn.novalon.gym.manage.datacount.domain.*;
|
||||||
|
import cn.novalon.gym.manage.datacount.service.IDataStatisticsService;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.time.DayOfWeek;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.temporal.TemporalAdjusters;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据统计服务实现类
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @date 2026-06-09
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class DataStatisticsServiceImpl implements IDataStatisticsService {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(DataStatisticsServiceImpl.class);
|
||||||
|
|
||||||
|
private static final String CACHE_KEY_PREFIX = "datacount:statistics:";
|
||||||
|
private static final long CACHE_EXPIRE_SECONDS = 3600; // 1小时
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataStatisticsDao dataStatisticsDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@Value("${datacount.cache.expire-seconds:3600}")
|
||||||
|
private long cacheExpireSeconds = 3600;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<MemberStatistics> getMemberStatistics(StatisticsQuery query) {
|
||||||
|
LocalDateTime startTime = getStartTime(query);
|
||||||
|
LocalDateTime endTime = getEndTime(query);
|
||||||
|
|
||||||
|
Mono<Long> newMembersMono = dataStatisticsDao.countNewMembers(startTime, endTime);
|
||||||
|
Mono<Long> totalMembersMono = dataStatisticsDao.countTotalMembers();
|
||||||
|
Mono<Long> signInMembersMono = dataStatisticsDao.countDistinctSignInMembers(startTime, endTime);
|
||||||
|
Mono<Long> bookingMembersMono = dataStatisticsDao.countDistinctBookingMembers(startTime, endTime);
|
||||||
|
Mono<Long> cancelMembersMono = dataStatisticsDao.countDistinctCancelMembers(startTime, endTime);
|
||||||
|
|
||||||
|
return Mono.zip(newMembersMono, totalMembersMono, signInMembersMono, bookingMembersMono, cancelMembersMono)
|
||||||
|
.map(tuple -> {
|
||||||
|
long newMembers = tuple.getT1() != null ? tuple.getT1() : 0L;
|
||||||
|
long totalMembers = tuple.getT2() != null ? tuple.getT2() : 0L;
|
||||||
|
long signInMembers = tuple.getT3() != null ? tuple.getT3() : 0L;
|
||||||
|
long bookingMembers = tuple.getT4() != null ? tuple.getT4() : 0L;
|
||||||
|
long cancelMembers = tuple.getT5() != null ? tuple.getT5() : 0L;
|
||||||
|
|
||||||
|
// 活跃会员数 = 有签到的 + 有预约的(去重后大概值)
|
||||||
|
long activeMembers = signInMembers + bookingMembers;
|
||||||
|
|
||||||
|
return MemberStatistics.builder()
|
||||||
|
.statDate(startTime.toLocalDate().toString())
|
||||||
|
.newMembers(newMembers)
|
||||||
|
.activeMembers(activeMembers)
|
||||||
|
.totalMembers(totalMembers)
|
||||||
|
.signInMembers(signInMembers)
|
||||||
|
.bookingMembers(bookingMembers)
|
||||||
|
.cancelBookingMembers(cancelMembers)
|
||||||
|
.build();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<BookingStatistics> getBookingStatistics(StatisticsQuery query) {
|
||||||
|
LocalDateTime startTime = getStartTime(query);
|
||||||
|
LocalDateTime endTime = getEndTime(query);
|
||||||
|
|
||||||
|
Mono<Long> totalMono = dataStatisticsDao.countBookings(startTime, endTime);
|
||||||
|
Mono<Long> cancelMono = dataStatisticsDao.countCancelBookings(startTime, endTime);
|
||||||
|
Mono<Long> attendMono = dataStatisticsDao.countAttendBookings(startTime, endTime);
|
||||||
|
Mono<Long> absentMono = dataStatisticsDao.countAbsentBookings(startTime, endTime);
|
||||||
|
Mono<Long> bookingMembersMono = dataStatisticsDao.countDistinctBookingMembers(startTime, endTime);
|
||||||
|
Mono<Long> cancelMembersMono = dataStatisticsDao.countDistinctCancelMembers(startTime, endTime);
|
||||||
|
|
||||||
|
return Mono.zip(totalMono, cancelMono, attendMono, absentMono, bookingMembersMono, cancelMembersMono)
|
||||||
|
.map(tuple -> {
|
||||||
|
long total = tuple.getT1() != null ? tuple.getT1() : 0L;
|
||||||
|
long cancel = tuple.getT2() != null ? tuple.getT2() : 0L;
|
||||||
|
long attend = tuple.getT3() != null ? tuple.getT3() : 0L;
|
||||||
|
long absent = tuple.getT4() != null ? tuple.getT4() : 0L;
|
||||||
|
long bookingMembers = tuple.getT5() != null ? tuple.getT5() : 0L;
|
||||||
|
long cancelMembers = tuple.getT6() != null ? tuple.getT6() : 0L;
|
||||||
|
|
||||||
|
double attendanceRate = total > 0 ? (double) attend / total * 100 : 0;
|
||||||
|
double cancelRate = total > 0 ? (double) cancel / total * 100 : 0;
|
||||||
|
|
||||||
|
return BookingStatistics.builder()
|
||||||
|
.statDate(startTime.toLocalDate().toString())
|
||||||
|
.newBookings(total)
|
||||||
|
.cancelBookings(cancel)
|
||||||
|
.attendBookings(attend)
|
||||||
|
.absentBookings(absent)
|
||||||
|
.attendanceRate(Math.round(attendanceRate * 100.0) / 100.0)
|
||||||
|
.cancelRate(Math.round(cancelRate * 100.0) / 100.0)
|
||||||
|
.bookingMembers(bookingMembers)
|
||||||
|
.cancelMembers(cancelMembers)
|
||||||
|
.build();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<SignInStatistics> getSignInStatistics(StatisticsQuery query) {
|
||||||
|
LocalDateTime startTime = getStartTime(query);
|
||||||
|
LocalDateTime endTime = getEndTime(query);
|
||||||
|
|
||||||
|
Mono<Long> totalMono = dataStatisticsDao.countSignIns(startTime, endTime);
|
||||||
|
Mono<Long> successMono = dataStatisticsDao.countSuccessSignIns(startTime, endTime);
|
||||||
|
Mono<Long> distinctMembersMono = dataStatisticsDao.countDistinctSignInMembers(startTime, endTime);
|
||||||
|
|
||||||
|
return Mono.zip(totalMono, successMono, distinctMembersMono)
|
||||||
|
.flatMap(tuple -> {
|
||||||
|
long total = tuple.getT1() != null ? tuple.getT1() : 0L;
|
||||||
|
long success = tuple.getT2() != null ? tuple.getT2() : 0L;
|
||||||
|
long distinctMembers = tuple.getT3() != null ? tuple.getT3() : 0L;
|
||||||
|
|
||||||
|
double successRate = total > 0 ? (double) success / total * 100 : 0;
|
||||||
|
|
||||||
|
return dataStatisticsDao.countSignInsByType(startTime, endTime)
|
||||||
|
.collectMap(
|
||||||
|
DataStatisticsDao.SignInTypeCount::getType,
|
||||||
|
DataStatisticsDao.SignInTypeCount::getCount
|
||||||
|
)
|
||||||
|
.defaultIfEmpty(new HashMap<>())
|
||||||
|
.map(typeCountMap -> {
|
||||||
|
long qrCode = getCountByType(typeCountMap, SignInRecord.SignInType.QR_CODE);
|
||||||
|
long manual = getCountByType(typeCountMap, SignInRecord.SignInType.MANUAL);
|
||||||
|
long face = getCountByType(typeCountMap, SignInRecord.SignInType.FACE);
|
||||||
|
|
||||||
|
return SignInStatistics.builder()
|
||||||
|
.statDate(startTime.toLocalDate().toString())
|
||||||
|
.totalSignIns(total)
|
||||||
|
.successSignIns(success)
|
||||||
|
.failedSignIns(total - success)
|
||||||
|
.successRate(Math.round(successRate * 100.0) / 100.0)
|
||||||
|
.signInMembers(distinctMembers)
|
||||||
|
.qrCodeSignIns(qrCode)
|
||||||
|
.manualSignIns(manual)
|
||||||
|
.faceSignIns(face)
|
||||||
|
.build();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getCountByType(Map<String, Long> typeCountMap, String type) {
|
||||||
|
Long count = typeCountMap.get(type);
|
||||||
|
return count != null ? count : 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<StatisticsSummary> getStatisticsSummary(StatisticsQuery query) {
|
||||||
|
Mono<MemberStatistics> memberStatsMono = getMemberStatistics(query);
|
||||||
|
Mono<BookingStatistics> bookingStatsMono = getBookingStatistics(query);
|
||||||
|
Mono<SignInStatistics> signInStatsMono = getSignInStatistics(query);
|
||||||
|
|
||||||
|
return Mono.zip(memberStatsMono, bookingStatsMono, signInStatsMono)
|
||||||
|
.map(tuple -> StatisticsSummary.builder()
|
||||||
|
.statDate(LocalDateTime.now().toLocalDate().toString())
|
||||||
|
.memberStatistics(tuple.getT1())
|
||||||
|
.bookingStatistics(tuple.getT2())
|
||||||
|
.signInStatistics(tuple.getT3())
|
||||||
|
.generatedAt(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public reactor.core.publisher.Flux<DataStatistics> queryHistoricalStatistics(StatisticsQuery query) {
|
||||||
|
// 历史统计数据查询(从Redis缓存中获取)
|
||||||
|
String cacheKey = buildCacheKey(query);
|
||||||
|
return redisUtil.get(cacheKey, String.class)
|
||||||
|
.flatMapMany(json -> {
|
||||||
|
try {
|
||||||
|
java.util.List<DataStatistics> stats = objectMapper.readValue(json,
|
||||||
|
objectMapper.getTypeFactory().constructCollectionType(java.util.List.class, DataStatistics.class));
|
||||||
|
return reactor.core.publisher.Flux.fromIterable(stats);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to parse historical statistics from cache", e);
|
||||||
|
return reactor.core.publisher.Flux.empty();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.switchIfEmpty(reactor.core.publisher.Flux.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Void> executeDailyStatistics(LocalDate statDate) {
|
||||||
|
log.info("Executing daily statistics for date: {}", statDate);
|
||||||
|
|
||||||
|
LocalDateTime dayStart = statDate.atStartOfDay();
|
||||||
|
LocalDateTime dayEnd = statDate.plusDays(1).atStartOfDay();
|
||||||
|
|
||||||
|
StatisticsQuery query = StatisticsQuery.builder()
|
||||||
|
.startTime(dayStart)
|
||||||
|
.endTime(dayEnd)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Mono<MemberStatistics> memberStatsMono = getMemberStatistics(query);
|
||||||
|
Mono<BookingStatistics> bookingStatsMono = getBookingStatistics(query);
|
||||||
|
Mono<SignInStatistics> signInStatsMono = getSignInStatistics(query);
|
||||||
|
|
||||||
|
return Mono.zip(memberStatsMono, bookingStatsMono, signInStatsMono)
|
||||||
|
.flatMap(tuple -> {
|
||||||
|
MemberStatistics memberStats = tuple.getT1();
|
||||||
|
BookingStatistics bookingStats = tuple.getT2();
|
||||||
|
SignInStatistics signInStats = tuple.getT3();
|
||||||
|
|
||||||
|
String dateStr = statDate.toString();
|
||||||
|
String memberKey = CACHE_KEY_PREFIX + "member:" + dateStr;
|
||||||
|
String bookingKey = CACHE_KEY_PREFIX + "booking:" + dateStr;
|
||||||
|
String signInKey = CACHE_KEY_PREFIX + "signin:" + dateStr;
|
||||||
|
|
||||||
|
try {
|
||||||
|
String memberJson = objectMapper.writeValueAsString(memberStats);
|
||||||
|
String bookingJson = objectMapper.writeValueAsString(bookingStats);
|
||||||
|
String signInJson = objectMapper.writeValueAsString(signInStats);
|
||||||
|
|
||||||
|
return reactor.core.publisher.Flux.merge(
|
||||||
|
redisUtil.setWithExpire(memberKey, memberJson, Duration.ofDays(30).getSeconds()),
|
||||||
|
redisUtil.setWithExpire(bookingKey, bookingJson, Duration.ofDays(30).getSeconds()),
|
||||||
|
redisUtil.setWithExpire(signInKey, signInJson, Duration.ofDays(30).getSeconds())
|
||||||
|
).then();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to serialize statistics data", e);
|
||||||
|
return Mono.empty();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then()
|
||||||
|
.doOnSuccess(v -> log.info("Daily statistics completed for date: {}", statDate))
|
||||||
|
.doOnError(e -> log.error("Failed to execute daily statistics for date: {}", statDate, e));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<byte[]> exportStatistics(StatisticsQuery query) {
|
||||||
|
return getStatisticsSummary(query)
|
||||||
|
.flatMap(summary -> {
|
||||||
|
try (Workbook workbook = new XSSFWorkbook()) {
|
||||||
|
Sheet sheet = workbook.createSheet("数据统计报表");
|
||||||
|
|
||||||
|
CellStyle headerStyle = workbook.createCellStyle();
|
||||||
|
Font headerFont = workbook.createFont();
|
||||||
|
headerFont.setBold(true);
|
||||||
|
headerStyle.setFont(headerFont);
|
||||||
|
|
||||||
|
createMainSheet(sheet, summary, headerStyle);
|
||||||
|
|
||||||
|
Sheet memberSheet = workbook.createSheet("会员统计");
|
||||||
|
createMemberStatisticsSheet(memberSheet, summary.getMemberStatistics(), headerStyle);
|
||||||
|
|
||||||
|
Sheet bookingSheet = workbook.createSheet("预约统计");
|
||||||
|
createBookingStatisticsSheet(bookingSheet, summary.getBookingStatistics(), headerStyle);
|
||||||
|
|
||||||
|
Sheet signInSheet = workbook.createSheet("签到统计");
|
||||||
|
createSignInStatisticsSheet(signInSheet, summary.getSignInStatistics(), headerStyle);
|
||||||
|
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
workbook.write(outputStream);
|
||||||
|
return Mono.just(outputStream.toByteArray());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to export statistics", e);
|
||||||
|
return Mono.error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createMainSheet(Sheet sheet, StatisticsSummary summary, CellStyle headerStyle) {
|
||||||
|
int rowNum = 0;
|
||||||
|
Row row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("统计项");
|
||||||
|
row.createCell(1).setCellValue("数值");
|
||||||
|
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("统计日期");
|
||||||
|
row.createCell(1).setCellValue(summary.getStatDate());
|
||||||
|
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("新增会员数");
|
||||||
|
row.createCell(1).setCellValue(summary.getMemberStatistics().getNewMembers());
|
||||||
|
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("活跃会员数");
|
||||||
|
row.createCell(1).setCellValue(summary.getMemberStatistics().getActiveMembers());
|
||||||
|
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("累计会员总数");
|
||||||
|
row.createCell(1).setCellValue(summary.getMemberStatistics().getTotalMembers());
|
||||||
|
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("新增预约数");
|
||||||
|
row.createCell(1).setCellValue(summary.getBookingStatistics().getNewBookings());
|
||||||
|
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("预约出席率");
|
||||||
|
row.createCell(1).setCellValue(summary.getBookingStatistics().getAttendanceRate() + "%");
|
||||||
|
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("签到总次数");
|
||||||
|
row.createCell(1).setCellValue(summary.getSignInStatistics().getTotalSignIns());
|
||||||
|
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("签到成功率");
|
||||||
|
row.createCell(1).setCellValue(summary.getSignInStatistics().getSuccessRate() + "%");
|
||||||
|
|
||||||
|
sheet.autoSizeColumn(0);
|
||||||
|
sheet.autoSizeColumn(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createMemberStatisticsSheet(Sheet sheet, MemberStatistics stats, CellStyle headerStyle) {
|
||||||
|
int rowNum = 0;
|
||||||
|
Row row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("统计项");
|
||||||
|
row.createCell(1).setCellValue("数值");
|
||||||
|
|
||||||
|
String[][] data = {
|
||||||
|
{"统计日期", stats.getStatDate()},
|
||||||
|
{"新增会员数", String.valueOf(stats.getNewMembers())},
|
||||||
|
{"活跃会员数", String.valueOf(stats.getActiveMembers())},
|
||||||
|
{"累计会员总数", String.valueOf(stats.getTotalMembers())},
|
||||||
|
{"今日签到会员数", String.valueOf(stats.getSignInMembers())},
|
||||||
|
{"今日预约会员数", String.valueOf(stats.getBookingMembers())},
|
||||||
|
{"今日取消预约会员数", String.valueOf(stats.getCancelBookingMembers())}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (String[] rowData : data) {
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue(rowData[0]);
|
||||||
|
row.createCell(1).setCellValue(rowData[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
sheet.autoSizeColumn(0);
|
||||||
|
sheet.autoSizeColumn(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createBookingStatisticsSheet(Sheet sheet, BookingStatistics stats, CellStyle headerStyle) {
|
||||||
|
int rowNum = 0;
|
||||||
|
Row row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("统计项");
|
||||||
|
row.createCell(1).setCellValue("数值");
|
||||||
|
|
||||||
|
String[][] data = {
|
||||||
|
{"统计日期", stats.getStatDate()},
|
||||||
|
{"新增预约数", String.valueOf(stats.getNewBookings())},
|
||||||
|
{"取消预约数", String.valueOf(stats.getCancelBookings())},
|
||||||
|
{"出席预约数", String.valueOf(stats.getAttendBookings())},
|
||||||
|
{"缺席预约数", String.valueOf(stats.getAbsentBookings())},
|
||||||
|
{"预约出席率", stats.getAttendanceRate() + "%"},
|
||||||
|
{"取消率", stats.getCancelRate() + "%"},
|
||||||
|
{"预约人数", String.valueOf(stats.getBookingMembers())},
|
||||||
|
{"取消人数", String.valueOf(stats.getCancelMembers())}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (String[] rowData : data) {
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue(rowData[0]);
|
||||||
|
row.createCell(1).setCellValue(rowData[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
sheet.autoSizeColumn(0);
|
||||||
|
sheet.autoSizeColumn(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createSignInStatisticsSheet(Sheet sheet, SignInStatistics stats, CellStyle headerStyle) {
|
||||||
|
int rowNum = 0;
|
||||||
|
Row row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue("统计项");
|
||||||
|
row.createCell(1).setCellValue("数值");
|
||||||
|
|
||||||
|
String[][] data = {
|
||||||
|
{"统计日期", stats.getStatDate()},
|
||||||
|
{"签到总次数", String.valueOf(stats.getTotalSignIns())},
|
||||||
|
{"成功签到次数", String.valueOf(stats.getSuccessSignIns())},
|
||||||
|
{"失败签到次数", String.valueOf(stats.getFailedSignIns())},
|
||||||
|
{"签到成功率", stats.getSuccessRate() + "%"},
|
||||||
|
{"签到人数", String.valueOf(stats.getSignInMembers())},
|
||||||
|
{"扫码签到次数", String.valueOf(stats.getQrCodeSignIns())},
|
||||||
|
{"手动签到次数", String.valueOf(stats.getManualSignIns())},
|
||||||
|
{"人脸识别签到次数", String.valueOf(stats.getFaceSignIns())}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (String[] rowData : data) {
|
||||||
|
row = sheet.createRow(rowNum++);
|
||||||
|
row.createCell(0).setCellValue(rowData[0]);
|
||||||
|
row.createCell(1).setCellValue(rowData[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
sheet.autoSizeColumn(0);
|
||||||
|
sheet.autoSizeColumn(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<StatisticsSummary> getStatisticsSummaryWithCache(StatisticsQuery query) {
|
||||||
|
String cacheKey = buildCacheKey(query);
|
||||||
|
|
||||||
|
return redisUtil.get(cacheKey, StatisticsSummary.class)
|
||||||
|
.switchIfEmpty(
|
||||||
|
getStatisticsSummary(query)
|
||||||
|
.flatMap(summary -> {
|
||||||
|
try {
|
||||||
|
String json = objectMapper.writeValueAsString(summary);
|
||||||
|
return redisUtil.setWithExpire(cacheKey, json, cacheExpireSeconds)
|
||||||
|
.thenReturn(summary);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to serialize statistics summary", e);
|
||||||
|
return Mono.just(summary);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildCacheKey(StatisticsQuery query) {
|
||||||
|
StringBuilder keyBuilder = new StringBuilder(CACHE_KEY_PREFIX);
|
||||||
|
keyBuilder.append("summary:");
|
||||||
|
|
||||||
|
if (query.getStartTime() != null) {
|
||||||
|
keyBuilder.append(query.getStartTime().toLocalDate().toString());
|
||||||
|
}
|
||||||
|
if (query.getEndTime() != null) {
|
||||||
|
keyBuilder.append("_").append(query.getEndTime().toLocalDate().toString());
|
||||||
|
}
|
||||||
|
if (query.getStatType() != null) {
|
||||||
|
keyBuilder.append("_").append(query.getStatType());
|
||||||
|
}
|
||||||
|
if (query.getPeriodType() != null) {
|
||||||
|
keyBuilder.append("_").append(query.getPeriodType());
|
||||||
|
}
|
||||||
|
|
||||||
|
return keyBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocalDateTime getStartTime(StatisticsQuery query) {
|
||||||
|
if (query.getStartTime() != null) {
|
||||||
|
return query.getStartTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDate today = LocalDate.now();
|
||||||
|
String periodType = query.getPeriodType();
|
||||||
|
|
||||||
|
if (DataStatistics.PeriodType.WEEK.equals(periodType)) {
|
||||||
|
// 周统计:本周一
|
||||||
|
return today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).atStartOfDay();
|
||||||
|
} else if (DataStatistics.PeriodType.MONTH.equals(periodType)) {
|
||||||
|
// 月统计:本月第一天
|
||||||
|
return today.withDayOfMonth(1).atStartOfDay();
|
||||||
|
} else {
|
||||||
|
// 日统计:当天零点
|
||||||
|
return today.atStartOfDay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocalDateTime getEndTime(StatisticsQuery query) {
|
||||||
|
if (query.getEndTime() != null) {
|
||||||
|
return query.getEndTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDate today = LocalDate.now();
|
||||||
|
String periodType = query.getPeriodType();
|
||||||
|
|
||||||
|
if (DataStatistics.PeriodType.WEEK.equals(periodType)) {
|
||||||
|
// 周统计:本周日 23:59:59
|
||||||
|
return today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)).atTime(23, 59, 59);
|
||||||
|
} else if (DataStatistics.PeriodType.MONTH.equals(periodType)) {
|
||||||
|
// 月统计:本月最后一天 23:59:59
|
||||||
|
return today.with(TemporalAdjusters.lastDayOfMonth()).atTime(23, 59, 59);
|
||||||
|
} else {
|
||||||
|
// 日统计:当前时间
|
||||||
|
return LocalDateTime.now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据周期类型调整时间范围
|
||||||
|
* 用于定时任务中的周期统计
|
||||||
|
*/
|
||||||
|
private LocalDateTime[] adjustTimeRangeByPeriod(LocalDate date, String periodType) {
|
||||||
|
LocalDateTime startTime;
|
||||||
|
LocalDateTime endTime;
|
||||||
|
|
||||||
|
if (DataStatistics.PeriodType.WEEK.equals(periodType)) {
|
||||||
|
startTime = date.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).atStartOfDay();
|
||||||
|
endTime = date.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)).atTime(23, 59, 59);
|
||||||
|
} else if (DataStatistics.PeriodType.MONTH.equals(periodType)) {
|
||||||
|
startTime = date.withDayOfMonth(1).atStartOfDay();
|
||||||
|
endTime = date.with(TemporalAdjusters.lastDayOfMonth()).atTime(23, 59, 59);
|
||||||
|
} else {
|
||||||
|
startTime = date.atStartOfDay();
|
||||||
|
endTime = date.plusDays(1).atStartOfDay();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LocalDateTime[]{startTime, endTime};
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
cn.novalon.gym.manage.datacount.config.DataCountAutoConfiguration
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
spring:
|
|
||||||
application:
|
|
||||||
name: gym-dataCount
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
package cn.novalon.gym.manage.datacount;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class GymDataCountApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+138
-66
File diff suppressed because one or more lines are too long
@@ -48,6 +48,11 @@
|
|||||||
<artifactId>gym-checkIn</artifactId>
|
<artifactId>gym-checkIn</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.novalon.gym.manage</groupId>
|
||||||
|
<artifactId>gym-dataCount</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -154,12 +159,6 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>cn.novalon.gym.manage</groupId>
|
|
||||||
<artifactId>gym-dataCount</artifactId>
|
|
||||||
<version>1.0.0</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
+15
-1
@@ -2,6 +2,7 @@ package cn.novalon.gym.manage.app.config;
|
|||||||
|
|
||||||
|
|
||||||
import cn.novalon.gym.manage.checkIn.handler.CheckInHandler;
|
import cn.novalon.gym.manage.checkIn.handler.CheckInHandler;
|
||||||
|
import cn.novalon.gym.manage.datacount.handler.DataStatisticsHandler;
|
||||||
import cn.novalon.gym.manage.file.handler.SysFileHandler;
|
import cn.novalon.gym.manage.file.handler.SysFileHandler;
|
||||||
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseBookingHandler;
|
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseBookingHandler;
|
||||||
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseHandler;
|
import cn.novalon.gym.manage.groupcourse.handler.GroupCourseHandler;
|
||||||
@@ -68,7 +69,8 @@ public class SystemRouter {
|
|||||||
MemberCardTransactionHandler memberCardTransactionHandler,
|
MemberCardTransactionHandler memberCardTransactionHandler,
|
||||||
GroupCourseHandler groupCourseHandler,
|
GroupCourseHandler groupCourseHandler,
|
||||||
GroupCourseBookingHandler groupCourseBookingHandler,
|
GroupCourseBookingHandler groupCourseBookingHandler,
|
||||||
CheckInHandler checkInHandler) {
|
CheckInHandler checkInHandler,
|
||||||
|
DataStatisticsHandler dataStatisticsHandler) {
|
||||||
|
|
||||||
return route()
|
return route()
|
||||||
// ========== 诊断路由 ==========
|
// ========== 诊断路由 ==========
|
||||||
@@ -292,6 +294,18 @@ public class SystemRouter {
|
|||||||
|
|
||||||
// ===== 签到数据导出 =====
|
// ===== 签到数据导出 =====
|
||||||
.GET("/api/checkIn/records/export", checkInHandler::exportSignInRecords)
|
.GET("/api/checkIn/records/export", checkInHandler::exportSignInRecords)
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
// ========== 数据统计模块路由 ============
|
||||||
|
// ========================================
|
||||||
|
|
||||||
|
// ===== 数据统计核心功能 =====
|
||||||
|
.GET("/api/datacount/summary", dataStatisticsHandler::getStatisticsSummary)
|
||||||
|
.GET("/api/datacount/member", dataStatisticsHandler::getMemberStatistics)
|
||||||
|
.GET("/api/datacount/booking", dataStatisticsHandler::getBookingStatistics)
|
||||||
|
.GET("/api/datacount/signin", dataStatisticsHandler::getSignInStatistics)
|
||||||
|
.GET("/api/datacount/history", dataStatisticsHandler::queryHistoricalStatistics)
|
||||||
|
.GET("/api/datacount/export", dataStatisticsHandler::exportStatistics)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-443
@@ -1,443 +0,0 @@
|
|||||||
-- V13: 数据统计模块测试数据
|
|
||||||
-- 测试场景:
|
|
||||||
-- 1. 会员数据统计(新增会员、活跃会员、性别分布、平均年龄、购卡人数)
|
|
||||||
-- 2. 预约数据统计(预约总数、取消预约、实际到场、热门课程、满员课程)
|
|
||||||
-- 3. 数据导出功能测试
|
|
||||||
-- 日期范围:2026-06-01 至 2026-06-10
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 1. 创建测试会员用户(分布在不同日期注册,不同性别,不同生日)
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 2026-06-01 注册的会员(5人:3男2女)
|
|
||||||
INSERT INTO member_user (member_no, nickname, phone, gender, birthday, is_deleted, created_at, updated_at, last_login_at) VALUES
|
|
||||||
('MEM_STAT_001', '测试会员_男1', '13900001001', 1, '1995-03-15', false, '2026-06-01 09:00:00', '2026-06-01 09:00:00', '2026-06-05 20:00:00'),
|
|
||||||
('MEM_STAT_002', '测试会员_男2', '13900001002', 1, '1990-07-20', false, '2026-06-01 10:30:00', '2026-06-01 10:30:00', '2026-06-06 18:00:00'),
|
|
||||||
('MEM_STAT_003', '测试会员_男3', '13900001003', 1, '1988-11-08', false, '2026-06-01 14:00:00', '2026-06-01 14:00:00', '2026-06-04 19:30:00'),
|
|
||||||
('MEM_STAT_004', '测试会员_女1', '13900001004', 2, '1998-01-25', false, '2026-06-01 16:00:00', '2026-06-01 16:00:00', '2026-06-06 08:00:00'),
|
|
||||||
('MEM_STAT_005', '测试会员_女2', '13900001005', 2, '1992-05-10', false, '2026-06-01 18:00:00', '2026-06-01 18:00:00', '2026-06-03 21:00:00');
|
|
||||||
|
|
||||||
-- 2026-06-02 注册的会员(4人:2男2女)
|
|
||||||
INSERT INTO member_user (member_no, nickname, phone, gender, birthday, is_deleted, created_at, updated_at, last_login_at) VALUES
|
|
||||||
('MEM_STAT_006', '测试会员_男4', '13900001006', 1, '1985-09-12', false, '2026-06-02 09:00:00', '2026-06-02 09:00:00', '2026-06-06 10:00:00'),
|
|
||||||
('MEM_STAT_007', '测试会员_男5', '13900001007', 1, '1996-04-18', false, '2026-06-02 11:00:00', '2026-06-02 11:00:00', '2026-06-05 15:00:00'),
|
|
||||||
('MEM_STAT_008', '测试会员_女3', '13900001008', 2, '1993-08-30', false, '2026-06-02 13:00:00', '2026-06-02 13:00:00', '2026-06-06 12:00:00'),
|
|
||||||
('MEM_STAT_009', '测试会员_女4', '13900001009', 2, '1991-12-05', false, '2026-06-02 15:00:00', '2026-06-02 15:00:00', '2026-06-04 14:00:00');
|
|
||||||
|
|
||||||
-- 2026-06-03 注册的会员(3人:1男2女)
|
|
||||||
INSERT INTO member_user (member_no, nickname, phone, gender, birthday, is_deleted, created_at, updated_at, last_login_at) VALUES
|
|
||||||
('MEM_STAT_010', '测试会员_男6', '13900001010', 1, '1989-06-22', false, '2026-06-03 10:00:00', '2026-06-03 10:00:00', '2026-06-06 09:00:00'),
|
|
||||||
('MEM_STAT_011', '测试会员_女5', '13900001011', 2, '1997-02-14', false, '2026-06-03 14:00:00', '2026-06-03 14:00:00', '2026-06-05 16:00:00'),
|
|
||||||
('MEM_STAT_012', '测试会员_女6', '13900001012', 2, '1994-10-28', false, '2026-06-03 16:00:00', '2026-06-03 16:00:00', '2026-06-06 11:00:00');
|
|
||||||
|
|
||||||
-- 2026-06-04 注册的会员(2人:1男1女)
|
|
||||||
INSERT INTO member_user (member_no, nickname, phone, gender, birthday, is_deleted, created_at, updated_at, last_login_at) VALUES
|
|
||||||
('MEM_STAT_013', '测试会员_男7', '13900001013', 1, '1987-01-03', false, '2026-06-04 09:00:00', '2026-06-04 09:00:00', '2026-06-06 13:00:00'),
|
|
||||||
('MEM_STAT_014', '测试会员_女7', '13900001014', 2, '1999-07-17', false, '2026-06-04 11:00:00', '2026-06-04 11:00:00', '2026-06-05 17:00:00');
|
|
||||||
|
|
||||||
-- 2026-06-05 注册的会员(3人:2男1女)
|
|
||||||
INSERT INTO member_user (member_no, nickname, phone, gender, birthday, is_deleted, created_at, updated_at, last_login_at) VALUES
|
|
||||||
('MEM_STAT_015', '测试会员_男8', '13900001015', 1, '1990-03-09', false, '2026-06-05 10:00:00', '2026-06-05 10:00:00', '2026-06-06 14:00:00'),
|
|
||||||
('MEM_STAT_016', '测试会员_男9', '13900001016', 1, '1986-11-21', false, '2026-06-05 13:00:00', '2026-06-05 13:00:00', '2026-06-06 15:00:00'),
|
|
||||||
('MEM_STAT_017', '测试会员_女8', '13900001017', 2, '1995-09-06', false, '2026-06-05 15:00:00', '2026-06-05 15:00:00', '2026-06-05 18:00:00');
|
|
||||||
|
|
||||||
-- 2026-06-06 注册的会员(2人:1男1女)
|
|
||||||
INSERT INTO member_user (member_no, nickname, phone, gender, birthday, is_deleted, created_at, updated_at, last_login_at) VALUES
|
|
||||||
('MEM_STAT_018', '测试会员_男10', '13900001018', 1, '1993-05-14', false, '2026-06-06 09:00:00', '2026-06-06 09:00:00', '2026-06-06 16:00:00'),
|
|
||||||
('MEM_STAT_019', '测试会员_女9', '13900001019', 2, '1991-08-19', false, '2026-06-06 11:00:00', '2026-06-06 11:00:00', '2026-06-06 17:00:00');
|
|
||||||
|
|
||||||
-- 已删除的会员(1人,用于测试软删除过滤)
|
|
||||||
INSERT INTO member_user (member_no, nickname, phone, gender, birthday, is_deleted, created_at, updated_at, last_login_at) VALUES
|
|
||||||
('MEM_STAT_DEL', '已删除会员', '13900001999', 1, '1980-01-01', true, '2026-06-01 08:00:00', '2026-06-01 08:00:00', '2026-06-01 08:00:00');
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 2. 创建会员卡类型(如果不存在)
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
INSERT INTO member_card (member_card_name, member_card_type, member_card_price, member_card_validity_days, member_card_total_times, member_card_amount, member_card_status, extra_config, created_at, updated_at)
|
|
||||||
SELECT '月卡', 'TIME_CARD', 299.00, 30, NULL, NULL, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00'
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM member_card WHERE member_card_name = '月卡');
|
|
||||||
|
|
||||||
INSERT INTO member_card (member_card_name, member_card_type, member_card_price, member_card_validity_days, member_card_total_times, member_card_amount, member_card_status, extra_config, created_at, updated_at)
|
|
||||||
SELECT '季卡', 'TIME_CARD', 799.00, 90, NULL, NULL, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00'
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM member_card WHERE member_card_name = '季卡');
|
|
||||||
|
|
||||||
INSERT INTO member_card (member_card_name, member_card_type, member_card_price, member_card_validity_days, member_card_total_times, member_card_amount, member_card_status, extra_config, created_at, updated_at)
|
|
||||||
SELECT '次卡20次', 'COUNT_CARD', 599.00, NULL, 20, NULL, 1, '{}', '2026-01-01 00:00:00', '2026-01-01 00:00:00'
|
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM member_card WHERE member_card_name = '次卡20次');
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 3. 为所有测试会员创建会员卡记录
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- MEM_STAT_001 至 MEM_STAT_019 全部创建会员卡记录
|
|
||||||
-- 使用月卡类型,有效期至 2026-12-31
|
|
||||||
INSERT INTO member_card_record (member_id, member_card_id, status, remaining_times, remaining_amount, expire_time, purchase_time, version, card_composition, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
m.id,
|
|
||||||
(SELECT id FROM member_card WHERE member_card_name = '月卡'),
|
|
||||||
'ACTIVE',
|
|
||||||
0,
|
|
||||||
0.00,
|
|
||||||
'2026-12-31 23:59:59',
|
|
||||||
m.created_at,
|
|
||||||
0,
|
|
||||||
'{}',
|
|
||||||
m.created_at,
|
|
||||||
m.created_at
|
|
||||||
FROM member_user m
|
|
||||||
WHERE m.member_no LIKE 'MEM_STAT_%' AND m.member_no != 'MEM_STAT_DEL';
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 4. 创建团课课程(2026-06-01 至 2026-06-10)
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 2026-06-01 的课程
|
|
||||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
|
||||||
('晨间瑜伽', 101, 1, '2026-06-01 07:00:00', '2026-06-01 08:00:00', 15, 12, '0', '瑜伽教室A', '清晨唤醒瑜伽', 1, 30.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('燃脂单车', 102, 2, '2026-06-01 18:00:00', '2026-06-01 19:00:00', 25, 25, '0', '单车房', '高强度燃脂骑行', 1, 35.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('普拉提核心', 103, 1, '2026-06-01 19:30:00', '2026-06-01 20:30:00', 12, 8, '0', '普拉提教室', '核心力量训练', 1, 40.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00');
|
|
||||||
|
|
||||||
-- 2026-06-02 的课程
|
|
||||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
|
||||||
('流瑜伽', 101, 1, '2026-06-02 09:00:00', '2026-06-02 10:30:00', 15, 10, '0', '瑜伽教室A', '流畅体式连接', 1, 30.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('搏击操', 102, 2, '2026-06-02 18:30:00', '2026-06-02 19:30:00', 20, 18, '0', '综合训练区', '有氧搏击训练', 1, 35.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('冥想放松', 101, 1, '2026-06-02 20:00:00', '2026-06-02 21:00:00', 20, 5, '0', '冥想室', '深度放松冥想', 1, 25.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00');
|
|
||||||
|
|
||||||
-- 2026-06-03 的课程
|
|
||||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
|
||||||
('哈他瑜伽', 101, 1, '2026-06-03 10:00:00', '2026-06-03 11:30:00', 12, 12, '0', '瑜伽教室B', '基础哈他瑜伽', 1, 30.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('动感单车', 102, 2, '2026-06-03 19:00:00', '2026-06-03 20:00:00', 25, 20, '0', '单车房', '音乐节奏骑行', 1, 35.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('拉伸放松', 103, 1, '2026-06-03 20:30:00', '2026-06-03 21:30:00', 15, 6, '0', '综合训练区', '全身拉伸放松', 1, 25.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00');
|
|
||||||
|
|
||||||
-- 2026-06-04 的课程
|
|
||||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
|
||||||
('力量瑜伽', 101, 1, '2026-06-04 08:00:00', '2026-06-04 09:30:00', 15, 14, '0', '瑜伽教室A', '力量型瑜伽', 1, 35.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('HIIT训练', 102, 2, '2026-06-04 18:00:00', '2026-06-04 19:00:00', 20, 20, '0', '综合训练区', '高强度间歇训练', 1, 40.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('阴瑜伽', 101, 1, '2026-06-04 20:00:00', '2026-06-04 21:30:00', 12, 9, '0', '瑜伽教室B', '静态阴瑜伽', 1, 30.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00');
|
|
||||||
|
|
||||||
-- 2026-06-05 的课程
|
|
||||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
|
||||||
('晨间冥想', 101, 1, '2026-06-05 07:00:00', '2026-06-05 08:00:00', 20, 15, '0', '冥想室', '清晨冥想', 1, 25.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('尊巴舞', 103, 2, '2026-06-05 18:30:00', '2026-06-05 19:30:00', 25, 22, '0', '舞蹈室', '拉丁风格舞蹈', 1, 35.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('空中瑜伽', 101, 1, '2026-06-05 20:00:00', '2026-06-05 21:30:00', 10, 10, '0', '瑜伽教室A', '空中瑜伽体验', 1, 45.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00');
|
|
||||||
|
|
||||||
-- 2026-06-06 的课程
|
|
||||||
INSERT INTO group_course (course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, description, point_card_amount, stored_value_amount, create_by, created_at, updated_at) VALUES
|
|
||||||
('拜日式瑜伽', 101, 1, '2026-06-06 07:30:00', '2026-06-06 08:30:00', 15, 11, '0', '瑜伽教室A', '传统拜日式', 1, 30.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('杠铃操', 102, 2, '2026-06-06 18:00:00', '2026-06-06 19:00:00', 20, 16, '0', '力量区', '全身杠铃训练', 1, 35.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00'),
|
|
||||||
('修复瑜伽', 101, 1, '2026-06-06 20:00:00', '2026-06-06 21:00:00', 12, 7, '0', '瑜伽教室B', '修复性瑜伽', 1, 30.00, 'admin', '2026-05-28 10:00:00', '2026-05-28 10:00:00');
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 5. 团课预约记录(测试预约统计)
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 2026-06-01 的预约记录
|
|
||||||
-- 晨间瑜伽:5人预约(4人出席,1人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at) VALUES
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '晨间瑜伽' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_001'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_001')), '2026-06-01 06:00:00', '2', '晨间瑜伽', '2026-06-01 07:00:00', '2026-06-01 08:00:00', '瑜伽教室A', '2026-06-01 06:00:00', '2026-06-01 06:00:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '晨间瑜伽' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_002'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_002')), '2026-06-01 06:30:00', '2', '晨间瑜伽', '2026-06-01 07:00:00', '2026-06-01 08:00:00', '瑜伽教室A', '2026-06-01 06:30:00', '2026-06-01 06:30:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '晨间瑜伽' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_003'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_003')), '2026-06-01 06:45:00', '2', '晨间瑜伽', '2026-06-01 07:00:00', '2026-06-01 08:00:00', '瑜伽教室A', '2026-06-01 06:45:00', '2026-06-01 06:45:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '晨间瑜伽' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_004'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_004')), '2026-06-01 06:15:00', '1', '晨间瑜伽', '2026-06-01 07:00:00', '2026-06-01 08:00:00', '瑜伽教室A', '2026-06-01 06:15:00', '2026-06-01 06:15:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '晨间瑜伽' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_005'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_005')), '2026-06-01 06:20:00', '2', '晨间瑜伽', '2026-06-01 07:00:00', '2026-06-01 08:00:00', '瑜伽教室A', '2026-06-01 06:20:00', '2026-06-01 06:20:00');
|
|
||||||
|
|
||||||
-- 燃脂单车:19人预约(15人出席,4人取消)- 满员课程
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '燃脂单车' AND DATE(start_time) = '2026-06-01'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-01 17:00:00',
|
|
||||||
CASE WHEN i <= 15 THEN '2' ELSE '1' END,
|
|
||||||
'燃脂单车',
|
|
||||||
'2026-06-01 18:00:00',
|
|
||||||
'2026-06-01 19:00:00',
|
|
||||||
'单车房',
|
|
||||||
'2026-06-01 17:00:00',
|
|
||||||
'2026-06-01 17:00:00'
|
|
||||||
FROM generate_series(1, 19) AS i;
|
|
||||||
|
|
||||||
-- 普拉提核心:8人预约(7人出席,1人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at) VALUES
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '普拉提核心' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_001'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_001')), '2026-06-01 19:00:00', '2', '普拉提核心', '2026-06-01 19:30:00', '2026-06-01 20:30:00', '普拉提教室', '2026-06-01 19:00:00', '2026-06-01 19:00:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '普拉提核心' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_003'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_003')), '2026-06-01 19:10:00', '2', '普拉提核心', '2026-06-01 19:30:00', '2026-06-01 20:30:00', '普拉提教室', '2026-06-01 19:10:00', '2026-06-01 19:10:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '普拉提核心' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_005'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_005')), '2026-06-01 19:05:00', '2', '普拉提核心', '2026-06-01 19:30:00', '2026-06-01 20:30:00', '普拉提教室', '2026-06-01 19:05:00', '2026-06-01 19:05:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '普拉提核心' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_007'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_007')), '2026-06-01 19:15:00', '2', '普拉提核心', '2026-06-01 19:30:00', '2026-06-01 20:30:00', '普拉提教室', '2026-06-01 19:15:00', '2026-06-01 19:15:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '普拉提核心' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_009'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_009')), '2026-06-01 19:20:00', '1', '普拉提核心', '2026-06-01 19:30:00', '2026-06-01 20:30:00', '普拉提教室', '2026-06-01 19:20:00', '2026-06-01 19:20:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '普拉提核心' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_011'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_011')), '2026-06-01 19:25:00', '2', '普拉提核心', '2026-06-01 19:30:00', '2026-06-01 20:30:00', '普拉提教室', '2026-06-01 19:25:00', '2026-06-01 19:25:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '普拉提核心' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_013'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_013')), '2026-06-01 19:30:00', '2', '普拉提核心', '2026-06-01 19:30:00', '2026-06-01 20:30:00', '普拉提教室', '2026-06-01 19:30:00', '2026-06-01 19:30:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '普拉提核心' AND DATE(start_time) = '2026-06-01'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_015'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_015')), '2026-06-01 19:35:00', '2', '普拉提核心', '2026-06-01 19:30:00', '2026-06-01 20:30:00', '普拉提教室', '2026-06-01 19:35:00', '2026-06-01 19:35:00');
|
|
||||||
|
|
||||||
-- 2026-06-02 的预约记录
|
|
||||||
-- 流瑜伽:10人预约(9人出席,1人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '流瑜伽' AND DATE(start_time) = '2026-06-02'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-02 08:00:00',
|
|
||||||
CASE WHEN i <= 9 THEN '2' ELSE '1' END,
|
|
||||||
'流瑜伽',
|
|
||||||
'2026-06-02 09:00:00',
|
|
||||||
'2026-06-02 10:30:00',
|
|
||||||
'瑜伽教室A',
|
|
||||||
'2026-06-02 08:00:00',
|
|
||||||
'2026-06-02 08:00:00'
|
|
||||||
FROM generate_series(1, 10) AS i;
|
|
||||||
|
|
||||||
-- 搏击操:18人预约(15人出席,3人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '搏击操' AND DATE(start_time) = '2026-06-02'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-02 17:30:00',
|
|
||||||
CASE WHEN i <= 15 THEN '2' ELSE '1' END,
|
|
||||||
'搏击操',
|
|
||||||
'2026-06-02 18:30:00',
|
|
||||||
'2026-06-02 19:30:00',
|
|
||||||
'综合训练区',
|
|
||||||
'2026-06-02 17:30:00',
|
|
||||||
'2026-06-02 17:30:00'
|
|
||||||
FROM generate_series(1, 18) AS i;
|
|
||||||
|
|
||||||
-- 冥想放松:5人预约(4人出席,1人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at) VALUES
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '冥想放松' AND DATE(start_time) = '2026-06-02'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_001'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_001')), '2026-06-02 19:30:00', '2', '冥想放松', '2026-06-02 20:00:00', '2026-06-02 21:00:00', '冥想室', '2026-06-02 19:30:00', '2026-06-02 19:30:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '冥想放松' AND DATE(start_time) = '2026-06-02'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_004'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_004')), '2026-06-02 19:35:00', '2', '冥想放松', '2026-06-02 20:00:00', '2026-06-02 21:00:00', '冥想室', '2026-06-02 19:35:00', '2026-06-02 19:35:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '冥想放松' AND DATE(start_time) = '2026-06-02'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_007'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_007')), '2026-06-02 19:40:00', '2', '冥想放松', '2026-06-02 20:00:00', '2026-06-02 21:00:00', '冥想室', '2026-06-02 19:40:00', '2026-06-02 19:40:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '冥想放松' AND DATE(start_time) = '2026-06-02'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_010'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_010')), '2026-06-02 19:45:00', '1', '冥想放松', '2026-06-02 20:00:00', '2026-06-02 21:00:00', '冥想室', '2026-06-02 19:45:00', '2026-06-02 19:45:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '冥想放松' AND DATE(start_time) = '2026-06-02'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_013'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_013')), '2026-06-02 19:50:00', '2', '冥想放松', '2026-06-02 20:00:00', '2026-06-02 21:00:00', '冥想室', '2026-06-02 19:50:00', '2026-06-02 19:50:00');
|
|
||||||
|
|
||||||
-- 2026-06-03 的预约记录
|
|
||||||
-- 哈他瑜伽:12人预约(10人出席,2人取消)- 满员
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '哈他瑜伽' AND DATE(start_time) = '2026-06-03'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-03 09:00:00',
|
|
||||||
CASE WHEN i <= 10 THEN '2' ELSE '1' END,
|
|
||||||
'哈他瑜伽',
|
|
||||||
'2026-06-03 10:00:00',
|
|
||||||
'2026-06-03 11:30:00',
|
|
||||||
'瑜伽教室B',
|
|
||||||
'2026-06-03 09:00:00',
|
|
||||||
'2026-06-03 09:00:00'
|
|
||||||
FROM generate_series(1, 12) AS i;
|
|
||||||
|
|
||||||
-- 动感单车:19人预约(16人出席,3人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '动感单车' AND DATE(start_time) = '2026-06-03'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-03 18:00:00',
|
|
||||||
CASE WHEN i <= 16 THEN '2' ELSE '1' END,
|
|
||||||
'动感单车',
|
|
||||||
'2026-06-03 19:00:00',
|
|
||||||
'2026-06-03 20:00:00',
|
|
||||||
'单车房',
|
|
||||||
'2026-06-03 18:00:00',
|
|
||||||
'2026-06-03 18:00:00'
|
|
||||||
FROM generate_series(1, 19) AS i;
|
|
||||||
|
|
||||||
-- 拉伸放松:6人预约(5人出席,1人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at) VALUES
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '拉伸放松' AND DATE(start_time) = '2026-06-03'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_002'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_002')), '2026-06-03 20:00:00', '2', '拉伸放松', '2026-06-03 20:30:00', '2026-06-03 21:30:00', '综合训练区', '2026-06-03 20:00:00', '2026-06-03 20:00:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '拉伸放松' AND DATE(start_time) = '2026-06-03'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_005'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_005')), '2026-06-03 20:05:00', '2', '拉伸放松', '2026-06-03 20:30:00', '2026-06-03 21:30:00', '综合训练区', '2026-06-03 20:05:00', '2026-06-03 20:05:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '拉伸放松' AND DATE(start_time) = '2026-06-03'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_008'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_008')), '2026-06-03 20:10:00', '2', '拉伸放松', '2026-06-03 20:30:00', '2026-06-03 21:30:00', '综合训练区', '2026-06-03 20:10:00', '2026-06-03 20:10:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '拉伸放松' AND DATE(start_time) = '2026-06-03'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_011'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_011')), '2026-06-03 20:15:00', '1', '拉伸放松', '2026-06-03 20:30:00', '2026-06-03 21:30:00', '综合训练区', '2026-06-03 20:15:00', '2026-06-03 20:15:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '拉伸放松' AND DATE(start_time) = '2026-06-03'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_014'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_014')), '2026-06-03 20:20:00', '2', '拉伸放松', '2026-06-03 20:30:00', '2026-06-03 21:30:00', '综合训练区', '2026-06-03 20:20:00', '2026-06-03 20:20:00'),
|
|
||||||
((SELECT id FROM group_course WHERE course_name = '拉伸放松' AND DATE(start_time) = '2026-06-03'), (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_017'), (SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_017')), '2026-06-03 20:25:00', '2', '拉伸放松', '2026-06-03 20:30:00', '2026-06-03 21:30:00', '综合训练区', '2026-06-03 20:25:00', '2026-06-03 20:25:00');
|
|
||||||
|
|
||||||
-- 2026-06-04 的预约记录
|
|
||||||
-- 力量瑜伽:14人预约(12人出席,2人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '力量瑜伽' AND DATE(start_time) = '2026-06-04'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-04 07:00:00',
|
|
||||||
CASE WHEN i <= 12 THEN '2' ELSE '1' END,
|
|
||||||
'力量瑜伽',
|
|
||||||
'2026-06-04 08:00:00',
|
|
||||||
'2026-06-04 09:30:00',
|
|
||||||
'瑜伽教室A',
|
|
||||||
'2026-06-04 07:00:00',
|
|
||||||
'2026-06-04 07:00:00'
|
|
||||||
FROM generate_series(1, 14) AS i;
|
|
||||||
|
|
||||||
-- HIIT训练:19人预约(16人出席,3人取消)- 满员
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = 'HIIT训练' AND DATE(start_time) = '2026-06-04'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-04 17:00:00',
|
|
||||||
CASE WHEN i <= 16 THEN '2' ELSE '1' END,
|
|
||||||
'HIIT训练',
|
|
||||||
'2026-06-04 18:00:00',
|
|
||||||
'2026-06-04 19:00:00',
|
|
||||||
'综合训练区',
|
|
||||||
'2026-06-04 17:00:00',
|
|
||||||
'2026-06-04 17:00:00'
|
|
||||||
FROM generate_series(1, 19) AS i;
|
|
||||||
|
|
||||||
-- 阴瑜伽:9人预约(8人出席,1人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '阴瑜伽' AND DATE(start_time) = '2026-06-04'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-04 19:30:00',
|
|
||||||
CASE WHEN i <= 8 THEN '2' ELSE '1' END,
|
|
||||||
'阴瑜伽',
|
|
||||||
'2026-06-04 20:00:00',
|
|
||||||
'2026-06-04 21:30:00',
|
|
||||||
'瑜伽教室B',
|
|
||||||
'2026-06-04 19:30:00',
|
|
||||||
'2026-06-04 19:30:00'
|
|
||||||
FROM generate_series(1, 9) AS i;
|
|
||||||
|
|
||||||
-- 2026-06-05 的预约记录
|
|
||||||
-- 晨间冥想:15人预约(13人出席,2人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '晨间冥想' AND DATE(start_time) = '2026-06-05'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-05 06:00:00',
|
|
||||||
CASE WHEN i <= 13 THEN '2' ELSE '1' END,
|
|
||||||
'晨间冥想',
|
|
||||||
'2026-06-05 07:00:00',
|
|
||||||
'2026-06-05 08:00:00',
|
|
||||||
'冥想室',
|
|
||||||
'2026-06-05 06:00:00',
|
|
||||||
'2026-06-05 06:00:00'
|
|
||||||
FROM generate_series(1, 15) AS i;
|
|
||||||
|
|
||||||
-- 尊巴舞:19人预约(16人出席,3人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '尊巴舞' AND DATE(start_time) = '2026-06-05'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-05 17:30:00',
|
|
||||||
CASE WHEN i <= 16 THEN '2' ELSE '1' END,
|
|
||||||
'尊巴舞',
|
|
||||||
'2026-06-05 18:30:00',
|
|
||||||
'2026-06-05 19:30:00',
|
|
||||||
'舞蹈室',
|
|
||||||
'2026-06-05 17:30:00',
|
|
||||||
'2026-06-05 17:30:00'
|
|
||||||
FROM generate_series(1, 19) AS i;
|
|
||||||
|
|
||||||
-- 空中瑜伽:10人预约(9人出席,1人取消)- 满员
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '空中瑜伽' AND DATE(start_time) = '2026-06-05'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-05 19:00:00',
|
|
||||||
CASE WHEN i <= 9 THEN '2' ELSE '1' END,
|
|
||||||
'空中瑜伽',
|
|
||||||
'2026-06-05 20:00:00',
|
|
||||||
'2026-06-05 21:30:00',
|
|
||||||
'瑜伽教室A',
|
|
||||||
'2026-06-05 19:00:00',
|
|
||||||
'2026-06-05 19:00:00'
|
|
||||||
FROM generate_series(1, 10) AS i;
|
|
||||||
|
|
||||||
-- 2026-06-06 的预约记录
|
|
||||||
-- 拜日式瑜伽:11人预约(10人出席,1人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '拜日式瑜伽' AND DATE(start_time) = '2026-06-06'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-06 06:30:00',
|
|
||||||
CASE WHEN i <= 10 THEN '2' ELSE '1' END,
|
|
||||||
'拜日式瑜伽',
|
|
||||||
'2026-06-06 07:30:00',
|
|
||||||
'2026-06-06 08:30:00',
|
|
||||||
'瑜伽教室A',
|
|
||||||
'2026-06-06 06:30:00',
|
|
||||||
'2026-06-06 06:30:00'
|
|
||||||
FROM generate_series(1, 11) AS i;
|
|
||||||
|
|
||||||
-- 杠铃操:16人预约(14人出席,2人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '杠铃操' AND DATE(start_time) = '2026-06-06'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-06 17:00:00',
|
|
||||||
CASE WHEN i <= 14 THEN '2' ELSE '1' END,
|
|
||||||
'杠铃操',
|
|
||||||
'2026-06-06 18:00:00',
|
|
||||||
'2026-06-06 19:00:00',
|
|
||||||
'力量区',
|
|
||||||
'2026-06-06 17:00:00',
|
|
||||||
'2026-06-06 17:00:00'
|
|
||||||
FROM generate_series(1, 16) AS i;
|
|
||||||
|
|
||||||
-- 修复瑜伽:7人预约(6人出席,1人取消)
|
|
||||||
INSERT INTO group_course_booking (course_id, member_id, member_card_id, booking_time, status, course_name, course_start_time, course_end_time, location, created_at, updated_at)
|
|
||||||
SELECT
|
|
||||||
(SELECT id FROM group_course WHERE course_name = '修复瑜伽' AND DATE(start_time) = '2026-06-06'),
|
|
||||||
(SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0')),
|
|
||||||
(SELECT id FROM member_card_record WHERE member_id = (SELECT id FROM member_user WHERE member_no = 'MEM_STAT_' || LPAD(i::text, 3, '0'))),
|
|
||||||
'2026-06-06 19:30:00',
|
|
||||||
CASE WHEN i <= 6 THEN '2' ELSE '1' END,
|
|
||||||
'修复瑜伽',
|
|
||||||
'2026-06-06 20:00:00',
|
|
||||||
'2026-06-06 21:00:00',
|
|
||||||
'瑜伽教室B',
|
|
||||||
'2026-06-06 19:30:00',
|
|
||||||
'2026-06-06 19:30:00'
|
|
||||||
FROM generate_series(1, 7) AS i;
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 6. 更新团课当前预约人数(与实际预约一致)
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
UPDATE group_course SET current_members = 5 WHERE course_name = '晨间瑜伽' AND DATE(start_time) = '2026-06-01';
|
|
||||||
UPDATE group_course SET current_members = 19 WHERE course_name = '燃脂单车' AND DATE(start_time) = '2026-06-01';
|
|
||||||
UPDATE group_course SET current_members = 8 WHERE course_name = '普拉提核心' AND DATE(start_time) = '2026-06-01';
|
|
||||||
|
|
||||||
UPDATE group_course SET current_members = 10 WHERE course_name = '流瑜伽' AND DATE(start_time) = '2026-06-02';
|
|
||||||
UPDATE group_course SET current_members = 18 WHERE course_name = '搏击操' AND DATE(start_time) = '2026-06-02';
|
|
||||||
UPDATE group_course SET current_members = 5 WHERE course_name = '冥想放松' AND DATE(start_time) = '2026-06-02';
|
|
||||||
|
|
||||||
UPDATE group_course SET current_members = 12 WHERE course_name = '哈他瑜伽' AND DATE(start_time) = '2026-06-03';
|
|
||||||
UPDATE group_course SET current_members = 19 WHERE course_name = '动感单车' AND DATE(start_time) = '2026-06-03';
|
|
||||||
UPDATE group_course SET current_members = 6 WHERE course_name = '拉伸放松' AND DATE(start_time) = '2026-06-03';
|
|
||||||
|
|
||||||
UPDATE group_course SET current_members = 14 WHERE course_name = '力量瑜伽' AND DATE(start_time) = '2026-06-04';
|
|
||||||
UPDATE group_course SET current_members = 19 WHERE course_name = 'HIIT训练' AND DATE(start_time) = '2026-06-04';
|
|
||||||
UPDATE group_course SET current_members = 9 WHERE course_name = '阴瑜伽' AND DATE(start_time) = '2026-06-04';
|
|
||||||
|
|
||||||
UPDATE group_course SET current_members = 15 WHERE course_name = '晨间冥想' AND DATE(start_time) = '2026-06-05';
|
|
||||||
UPDATE group_course SET current_members = 19 WHERE course_name = '尊巴舞' AND DATE(start_time) = '2026-06-05';
|
|
||||||
UPDATE group_course SET current_members = 10 WHERE course_name = '空中瑜伽' AND DATE(start_time) = '2026-06-05';
|
|
||||||
|
|
||||||
UPDATE group_course SET current_members = 11 WHERE course_name = '拜日式瑜伽' AND DATE(start_time) = '2026-06-06';
|
|
||||||
UPDATE group_course SET current_members = 16 WHERE course_name = '杠铃操' AND DATE(start_time) = '2026-06-06';
|
|
||||||
UPDATE group_course SET current_members = 7 WHERE course_name = '修复瑜伽' AND DATE(start_time) = '2026-06-06';
|
|
||||||
|
|
||||||
-- ============================================
|
|
||||||
-- 7. 测试场景说明
|
|
||||||
-- ============================================
|
|
||||||
|
|
||||||
-- 会员数据统计预期结果(2026-06-01 至 2026-06-06):
|
|
||||||
-- 总会员数:19人(MEM_STAT_001 至 MEM_STAT_019,不含已删除的 MEM_STAT_DEL)
|
|
||||||
-- 男性会员:10人(001,002,003,006,007,010,013,015,016,018)
|
|
||||||
-- 女性会员:9人(004,005,008,009,011,012,014,017,019)
|
|
||||||
-- 2026-06-01 新增:5人
|
|
||||||
-- 2026-06-02 新增:4人
|
|
||||||
-- 2026-06-03 新增:3人
|
|
||||||
-- 2026-06-04 新增:2人
|
|
||||||
-- 2026-06-05 新增:3人
|
|
||||||
-- 2026-06-06 新增:2人
|
|
||||||
-- 所有会员都有会员卡记录(用于预约)
|
|
||||||
+120
@@ -0,0 +1,120 @@
|
|||||||
|
-- 数据统计模块测试数据
|
||||||
|
-- 用于测试会员、预约、签到统计接口
|
||||||
|
|
||||||
|
-- 插入测试会员数据
|
||||||
|
INSERT INTO member_user (id, member_no, nickname, phone, created_at, updated_at, is_deleted) VALUES
|
||||||
|
(1001, 'M20260601001', '张三', '13800138001', '2026-06-01 08:00:00', '2026-06-01 08:00:00', false),
|
||||||
|
(1002, 'M20260601002', '李四', '13800138002', '2026-06-01 09:00:00', '2026-06-01 09:00:00', false),
|
||||||
|
(1003, 'M20260602003', '王五', '13800138003', '2026-06-02 10:00:00', '2026-06-02 10:00:00', false),
|
||||||
|
(1004, 'M20260603004', '赵六', '13800138004', '2026-06-03 11:00:00', '2026-06-03 11:00:00', false),
|
||||||
|
(1005, 'M20260609005', '钱七', '13800138005', '2026-06-09 08:00:00', '2026-06-09 08:00:00', false),
|
||||||
|
(1006, 'M20260609006', '孙八', '13800138006', '2026-06-09 09:00:00', '2026-06-09 09:00:00', false),
|
||||||
|
(1007, 'M20260609007', '周九', '13800138007', '2026-06-09 10:00:00', '2026-06-09 10:00:00', false),
|
||||||
|
(1008, 'M20260604008', '吴十', '13800138008', '2026-06-04 14:00:00', '2026-06-04 14:00:00', false),
|
||||||
|
(1009, 'M20260605009', '郑十一', '13800138009', '2026-06-05 15:00:00', '2026-06-05 15:00:00', false),
|
||||||
|
(1010, 'M20260606010', '王十二', '13800138010', '2026-06-06 16:00:00', '2026-06-06 16:00:00', false),
|
||||||
|
(1011, 'M20260607011', '陈十三', '13800138011', '2026-06-07 17:00:00', '2026-06-07 17:00:00', false),
|
||||||
|
(1012, 'M20260608012', '刘十四', '13800138012', '2026-06-08 18:00:00', '2026-06-08 18:00:00', false)
|
||||||
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
|
-- 插入测试签到记录数据 (今天的数据)
|
||||||
|
INSERT INTO sign_in_record (id, member_id, sign_in_time, sign_in_type, sign_in_status, source, is_delete) VALUES
|
||||||
|
(2001, 1001, '2026-06-09 08:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2002, 1002, '2026-06-09 08:15:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||||
|
(2003, 1003, '2026-06-09 08:30:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2004, 1004, '2026-06-09 09:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2005, 1005, '2026-06-09 09:15:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||||
|
(2006, 1006, '2026-06-09 09:30:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2007, 1007, '2026-06-09 10:00:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2008, 1008, '2026-06-09 10:15:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2009, 1009, '2026-06-09 10:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||||
|
(2010, 1010, '2026-06-09 11:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2011, 1011, '2026-06-09 11:15:00', 'FACE', 'FAIL', 'MINI_PROGRAM', false),
|
||||||
|
(2012, 1012, '2026-06-09 11:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false)
|
||||||
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
|
-- 插入测试签到记录数据 (昨天的数据)
|
||||||
|
INSERT INTO sign_in_record (id, member_id, sign_in_time, sign_in_type, sign_in_status, source, is_delete) VALUES
|
||||||
|
(2013, 1001, '2026-06-08 07:30:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2014, 1002, '2026-06-08 08:00:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||||
|
(2015, 1003, '2026-06-08 08:30:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2016, 1004, '2026-06-08 09:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2017, 1005, '2026-06-08 09:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||||
|
(2018, 1006, '2026-06-08 10:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2019, 1007, '2026-06-08 10:30:00', 'FACE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2020, 1008, '2026-06-08 11:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false)
|
||||||
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
|
-- 插入测试签到记录数据 (前天的数据)
|
||||||
|
INSERT INTO sign_in_record (id, member_id, sign_in_time, sign_in_type, sign_in_status, source, is_delete) VALUES
|
||||||
|
(2021, 1001, '2026-06-07 07:00:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2022, 1002, '2026-06-07 07:30:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false),
|
||||||
|
(2023, 1003, '2026-06-07 08:00:00', 'FACE', 'FAIL', 'MINI_PROGRAM', false),
|
||||||
|
(2024, 1004, '2026-06-07 08:30:00', 'QR_CODE', 'SUCCESS', 'MINI_PROGRAM', false),
|
||||||
|
(2025, 1005, '2026-06-07 09:00:00', 'MANUAL', 'SUCCESS', 'PC_BACKEND', false)
|
||||||
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
|
-- 插入测试团课数据
|
||||||
|
INSERT INTO group_course (id, course_name, coach_id, course_type, start_time, end_time, max_members, current_members, status, location, cover_image, description, created_at, updated_at) VALUES
|
||||||
|
(3001, '瑜伽入门', 1, 1, '2026-06-09 08:00:00', '2026-06-09 09:00:00', 20, 15, 0, '健身房A区', 'https://example.com/yoga.jpg', '适合初学者的瑜伽课程', '2026-06-01 10:00:00', '2026-06-01 10:00:00'),
|
||||||
|
(3002, '动感单车', 2, 2, '2026-06-09 09:30:00', '2026-06-09 10:30:00', 25, 20, 0, '健身房B区', 'https://example.com/spinning.jpg', '高强度有氧运动', '2026-06-01 11:00:00', '2026-06-01 11:00:00'),
|
||||||
|
(3003, '普拉提', 3, 1, '2026-06-09 14:00:00', '2026-06-09 15:00:00', 15, 10, 0, '健身房C区', 'https://example.com/pilates.jpg', '核心力量训练', '2026-06-01 12:00:00', '2026-06-01 12:00:00')
|
||||||
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
|
-- 插入测试团课预约数据 (今天的数据)
|
||||||
|
INSERT INTO group_course_booking (id, member_id, member_card_id, course_id, booking_time, status, created_at, updated_at) VALUES
|
||||||
|
(4001, 1001, 1, 3001, '2026-06-09 08:00:00', '2', '2026-06-08 20:00:00', '2026-06-09 08:30:00'),
|
||||||
|
(4002, 1002, 2, 3001, '2026-06-09 08:00:00', '2', '2026-06-08 21:00:00', '2026-06-09 08:30:00'),
|
||||||
|
(4003, 1003, 3, 3001, '2026-06-09 08:00:00', '3', '2026-06-08 22:00:00', '2026-06-09 09:00:00'),
|
||||||
|
(4004, 1004, 4, 3002, '2026-06-09 09:30:00', '2', '2026-06-08 19:00:00', '2026-06-09 09:30:00'),
|
||||||
|
(4005, 1005, 5, 3002, '2026-06-09 09:30:00', '1', '2026-06-08 20:30:00', '2026-06-09 09:00:00'),
|
||||||
|
(4006, 1006, 6, 3002, '2026-06-09 09:30:00', '2', '2026-06-08 21:30:00', '2026-06-09 09:30:00'),
|
||||||
|
(4007, 1007, 7, 3003, '2026-06-09 14:00:00', '2', '2026-06-08 22:30:00', '2026-06-09 14:00:00'),
|
||||||
|
(4008, 1008, 8, 3003, '2026-06-09 14:00:00', '3', '2026-06-09 08:00:00', '2026-06-09 14:00:00'),
|
||||||
|
(4009, 1009, 9, 3003, '2026-06-09 14:00:00', '2', '2026-06-09 09:00:00', '2026-06-09 14:00:00'),
|
||||||
|
(4010, 1010, 10, 3001, '2026-06-09 08:00:00', '2', '2026-06-09 07:00:00', '2026-06-09 08:00:00'),
|
||||||
|
(4011, 1011, 11, 3002, '2026-06-09 09:30:00', '1', '2026-06-09 08:30:00', '2026-06-09 09:00:00'),
|
||||||
|
(4012, 1012, 12, 3003, '2026-06-09 14:00:00', '2', '2026-06-09 10:00:00', '2026-06-09 14:00:00')
|
||||||
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
|
-- 插入测试团课预约数据 (昨天的数据)
|
||||||
|
INSERT INTO group_course_booking (id, member_id, member_card_id, course_id, booking_time, status, created_at, updated_at) VALUES
|
||||||
|
(4013, 1001, 1, 3001, '2026-06-08 08:00:00', '2', '2026-06-07 20:00:00', '2026-06-08 08:30:00'),
|
||||||
|
(4014, 1002, 2, 3001, '2026-06-08 08:00:00', '2', '2026-06-07 21:00:00', '2026-06-08 08:30:00'),
|
||||||
|
(4015, 1003, 3, 3002, '2026-06-08 09:30:00', '3', '2026-06-07 22:00:00', '2026-06-08 09:30:00'),
|
||||||
|
(4016, 1004, 4, 3002, '2026-06-08 09:30:00', '2', '2026-06-07 19:00:00', '2026-06-08 09:30:00'),
|
||||||
|
(4017, 1005, 5, 3003, '2026-06-08 14:00:00', '1', '2026-06-07 20:30:00', '2026-06-08 13:00:00'),
|
||||||
|
(4018, 1006, 6, 3003, '2026-06-08 14:00:00', '2', '2026-06-07 21:30:00', '2026-06-08 14:00:00')
|
||||||
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
|
-- 插入测试团课预约数据 (前天的数据)
|
||||||
|
INSERT INTO group_course_booking (id, member_id, member_card_id, course_id, booking_time, status, created_at, updated_at) VALUES
|
||||||
|
(4019, 1001, 1, 3002, '2026-06-07 09:30:00', '2', '2026-06-06 20:00:00', '2026-06-07 09:30:00'),
|
||||||
|
(4020, 1002, 2, 3002, '2026-06-07 09:30:00', '2', '2026-06-06 21:00:00', '2026-06-07 09:30:00'),
|
||||||
|
(4021, 1003, 3, 3003, '2026-06-07 14:00:00', '2', '2026-06-06 22:00:00', '2026-06-07 14:00:00'),
|
||||||
|
(4022, 1004, 4, 3003, '2026-06-07 14:00:00', '3', '2026-06-06 19:00:00', '2026-06-07 14:00:00')
|
||||||
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
|
-- 预期统计结果 (今日):
|
||||||
|
-- 会员统计:
|
||||||
|
-- 新增会员: 3 (1005, 1006, 1007)
|
||||||
|
-- 活跃会员: 12 (所有会员今日或近期有活动)
|
||||||
|
-- 总会员数: 12
|
||||||
|
-- 签到会员: 12
|
||||||
|
-- 预约会员: 9
|
||||||
|
-- 取消会员: 2
|
||||||
|
|
||||||
|
-- 预约统计:
|
||||||
|
-- 总预约: 12
|
||||||
|
-- 取消: 2
|
||||||
|
-- 出席: 8
|
||||||
|
-- 缺席: 2
|
||||||
|
-- 出席率: 8/10 = 80%
|
||||||
|
-- 取消率: 2/12 = 16.67%
|
||||||
|
|
||||||
|
-- 签到统计:
|
||||||
|
-- 总签到: 12
|
||||||
|
-- 成功: 11
|
||||||
|
-- 失败: 1
|
||||||
|
-- 成功率: 11/12 = 91.67%
|
||||||
|
-- 类型分布: QR_CODE=5, MANUAL=4, FACE=3
|
||||||
+2
-3
@@ -56,10 +56,9 @@ public class SecurityConfig {
|
|||||||
.pathMatchers("/api/admin/member/**").permitAll()
|
.pathMatchers("/api/admin/member/**").permitAll()
|
||||||
.pathMatchers("/api/member-cards/**").permitAll()
|
.pathMatchers("/api/member-cards/**").permitAll()
|
||||||
.pathMatchers("/api/member-card-records/**").permitAll()
|
.pathMatchers("/api/member-card-records/**").permitAll()
|
||||||
.pathMatchers("/api/member-card-transactions/**").permitAll()
|
|
||||||
.pathMatchers("/api/checkIn/**").permitAll()
|
|
||||||
.pathMatchers("/**").permitAll()
|
.pathMatchers("/**").permitAll()
|
||||||
.pathMatchers("/api/member-card-transactions/**").permitAll();
|
.pathMatchers("/api/member-card-transactions/**").permitAll()
|
||||||
|
.pathMatchers("/api/checkIn/**").permitAll();
|
||||||
|
|
||||||
|
|
||||||
if (isDevOrTest) {
|
if (isDevOrTest) {
|
||||||
|
|||||||
Reference in New Issue
Block a user