Files
smartDriveEE/src/main/java/com/rj/example/AudioStatisticsExample.java
2025-08-16 06:13:09 +08:00

216 lines
8.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.rj.example;
import com.rj.entity.AudioManagementStatistics;
import com.rj.scheduler.AudioStatisticsScheduler;
import com.rj.service.IAudioManagementStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.List;
/**
* 门店录音统计功能使用示例
*
* @author 李中华 ,spllzh
* @since 2025-08-07
*/
@Component
public class AudioStatisticsExample {
@Autowired
private IAudioManagementStatisticsService audioStatisticsService;
@Autowired
private AudioStatisticsScheduler audioStatisticsScheduler;
/**
* 示例1手动生成指定日期的统计数据
*/
public void exampleGenerateStatistics() {
System.out.println("=== 示例1手动生成指定日期的统计数据 ===");
// 生成昨天的统计数据
LocalDate yesterday = LocalDate.now().minusDays(1);
int count = audioStatisticsScheduler.manualGenerateStatistics(yesterday);
System.out.println("生成统计记录数: " + count);
System.out.println("统计日期: " + yesterday);
}
/**
* 示例2查询最近7天的统计数据
*/
public void exampleQueryRecentStatistics() {
System.out.println("=== 示例2查询最近7天的统计数据 ===");
LocalDate endDate = LocalDate.now().minusDays(1); // 昨天
LocalDate startDate = endDate.minusDays(6); // 7天前
List<AudioManagementStatistics> statistics = audioStatisticsService.getStatisticsByDateRange(startDate, endDate);
System.out.println("查询到统计记录数: " + statistics.size());
System.out.println("查询日期范围: " + startDate + "" + endDate);
// 打印统计信息
for (AudioManagementStatistics stat : statistics) {
System.out.println("门店: " + stat.getDealershipName() +
", 日期: " + stat.getStatisticsDate() +
", 录音数量: " + stat.getDealershipRecordingCount() +
", 总时长: " + stat.getDealershipTotalDuration() + "" +
", 平均时长: " + stat.getDealershipAvgDuration() + "");
}
}
/**
* 示例3查询指定门店的统计数据
*/
public void exampleQueryDealershipStatistics() {
System.out.println("=== 示例3查询指定门店的统计数据 ===");
Long dealershipId = 1L; // 假设门店ID为1
LocalDate startDate = LocalDate.now().minusDays(30); // 最近30天
LocalDate endDate = LocalDate.now().minusDays(1);
List<AudioManagementStatistics> statistics = audioStatisticsService.getStatisticsByDealership(dealershipId, startDate, endDate);
System.out.println("门店ID: " + dealershipId);
System.out.println("查询到统计记录数: " + statistics.size());
// 计算该门店的总统计
long totalDuration = 0;
int totalCount = 0;
for (AudioManagementStatistics stat : statistics) {
totalDuration += stat.getDealershipTotalDuration();
totalCount += stat.getDealershipRecordingCount();
}
System.out.println("门店总录音时长: " + totalDuration + "");
System.out.println("门店总录音数量: " + totalCount);
if (totalCount > 0) {
System.out.println("门店平均录音时长: " + (totalDuration / totalCount) + "");
}
}
/**
* 示例4查询指定销售人员的统计数据
*/
public void exampleQuerySalesStatistics() {
System.out.println("=== 示例4查询指定销售人员的统计数据 ===");
String salesId = "sales001"; // 假设销售人员ID
LocalDate startDate = LocalDate.now().minusDays(30); // 最近30天
LocalDate endDate = LocalDate.now().minusDays(1);
List<AudioManagementStatistics> statistics = audioStatisticsService.getStatisticsBySales(salesId, startDate, endDate);
System.out.println("销售人员ID: " + salesId);
System.out.println("查询到统计记录数: " + statistics.size());
// 计算该销售人员的总统计
long totalDuration = 0;
int totalCount = 0;
for (AudioManagementStatistics stat : statistics) {
totalDuration += stat.getSalesTotalDuration();
totalCount += stat.getSalesRecordingCount();
}
System.out.println("销售人员总录音时长: " + totalDuration + "");
System.out.println("销售人员总录音数量: " + totalCount);
if (totalCount > 0) {
System.out.println("销售人员平均录音时长: " + (totalDuration / totalCount) + "");
}
}
/**
* 示例5查询指定项目的统计数据
*/
public void exampleQueryProjectStatistics() {
System.out.println("=== 示例5查询指定项目的统计数据 ===");
String projectId = "project001"; // 假设项目ID
LocalDate startDate = LocalDate.now().minusDays(30); // 最近30天
LocalDate endDate = LocalDate.now().minusDays(1);
List<AudioManagementStatistics> statistics = audioStatisticsService.getStatisticsByProject(projectId, startDate, endDate);
System.out.println("项目ID: " + projectId);
System.out.println("查询到统计记录数: " + statistics.size());
// 计算该项目的总统计
long totalDuration = 0;
int totalCount = 0;
for (AudioManagementStatistics stat : statistics) {
totalDuration += stat.getProjectTotalDuration();
totalCount += stat.getProjectRecordingCount();
}
System.out.println("项目总录音时长: " + totalDuration + "");
System.out.println("项目总录音数量: " + totalCount);
if (totalCount > 0) {
System.out.println("项目平均录音时长: " + (totalDuration / totalCount) + "");
}
}
/**
* 示例6批量生成历史统计数据
*/
public void exampleBatchGenerateStatistics() {
System.out.println("=== 示例6批量生成历史统计数据 ===");
// 生成最近30天的统计数据
LocalDate endDate = LocalDate.now().minusDays(1);
LocalDate startDate = endDate.minusDays(29);
int totalCount = 0;
for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
try {
int count = audioStatisticsScheduler.manualGenerateStatistics(date);
totalCount += count;
System.out.println("日期 " + date + " 生成统计记录数: " + count);
} catch (Exception e) {
System.err.println("日期 " + date + " 统计失败: " + e.getMessage());
}
}
System.out.println("批量生成完成,总记录数: " + totalCount);
}
/**
* 运行所有示例
*/
public void runAllExamples() {
System.out.println("开始运行门店录音统计功能示例...");
System.out.println();
try {
exampleGenerateStatistics();
System.out.println();
exampleQueryRecentStatistics();
System.out.println();
exampleQueryDealershipStatistics();
System.out.println();
exampleQuerySalesStatistics();
System.out.println();
exampleQueryProjectStatistics();
System.out.println();
exampleBatchGenerateStatistics();
System.out.println();
} catch (Exception e) {
System.err.println("示例运行失败: " + e.getMessage());
e.printStackTrace();
}
System.out.println("示例运行完成!");
}
}