录音时长统计修改

This commit is contained in:
2026-02-07 21:40:05 +08:00
parent 69043e765a
commit a4577a89e1
10 changed files with 15 additions and 261 deletions

View File

@@ -95,7 +95,7 @@ public class AudioStatisticsController {
* 查询指定销售人员的统计数据
*/
@Operation(summary = "查询指定销售人员的统计数据", description = "根据销售人员ID或电话号码查询指定日期范围内的录音统计数据")
@GetMapping("/sales")
@PostMapping("/sales")
public Result<?> getStatisticsBySales(
@Parameter(description = "销售人员ID")
@RequestParam(required = false) String salesId,
@@ -141,27 +141,7 @@ public class AudioStatisticsController {
}
}
/**
* 查询指定项目的统计数据
*/
@Operation(summary = "查询指定项目的统计数据", description = "查询指定项目在指定日期范围内的录音统计数据")
@GetMapping("/project/{projectId}")
public Result<?> getStatisticsByProject(
@Parameter(description = "项目ID")
@PathVariable String projectId,
@Parameter(description = "开始日期格式yyyy-MM-dd")
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
@Parameter(description = "结束日期格式yyyy-MM-dd")
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
try {
List<AudioManagementStatistics> statistics = audioStatisticsService.getStatisticsByProject(projectId, startDate, endDate);
Result<?> result = Result.ok(statistics);
result.setMsg("查询成功");
return result;
} catch (Exception e) {
return Result.error("查询失败:" + e.getMessage());
}
}
/**
* 查询指定日期的统计数据

View File

@@ -61,42 +61,18 @@ public class AudioManagementStatistics implements Serializable {
@TableField("sales_id")
private String salesId;
@Schema(description = "销售人员姓名")
@TableField("sales_name")
private String salesName;
@Schema(description = "销售人员录音总时长(分钟)")
@TableField("sales_total_duration")
@TableField("personal_total_duration")
private Long salesTotalDuration;
@Schema(description = "销售人员录音数量")
@TableField("sales_recording_count")
@TableField("personal_recording_count")
private Integer salesRecordingCount;
@Schema(description = "销售人员录音平均时长(分钟)")
@TableField("sales_avg_duration")
@TableField("personal_avg_duration")
private BigDecimal salesAvgDuration;
@Schema(description = "项目ID")
@TableField("project_id")
private String projectId;
@Schema(description = "项目名称")
@TableField("project_name")
private String projectName;
@Schema(description = "项目录音总时长(分钟)")
@TableField("project_total_duration")
private Long projectTotalDuration;
@Schema(description = "项目录音数量")
@TableField("project_recording_count")
private Integer projectRecordingCount;
@Schema(description = "项目录音平均时长(分钟)")
@TableField("project_avg_duration")
private BigDecimal projectAvgDuration;
@Schema(description = "统计日期")
@TableField("statistics_date")
private LocalDate statisticsDate;

View File

@@ -124,37 +124,6 @@ public class AudioStatisticsExample {
}
}
/**
* 示例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批量生成历史统计数据
*/
@@ -179,37 +148,5 @@ public class AudioStatisticsExample {
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("示例运行完成!");
}
}

View File

@@ -46,7 +46,6 @@ public interface AudioManagementStatisticsMapper extends BaseMapper<AudioManagem
*/
@Select("SELECT " +
"sales_id, " +
"sales_name, " +
"SUM(duration) as total_duration_minutes, " +
"COUNT(*) as recording_count, " +
"AVG(duration) as avg_duration_minutes " +
@@ -54,27 +53,9 @@ public interface AudioManagementStatisticsMapper extends BaseMapper<AudioManagem
"WHERE DATE(recording_time) = #{date} " +
"AND sales_id IS NOT NULL " +
"AND sales_id != '' " +
"GROUP BY sales_id, sales_name")
"GROUP BY sales_id")
List<Map<String, Object>> getSalesStatisticsByDate(@Param("date") LocalDate date);
/**
* 按项目统计指定日期的录音数据
* @param date 统计日期
* @return 项目统计结果列表
*/
@Select("SELECT " +
"project_id, " +
"project_name, " +
"SUM(duration) as total_duration_minutes, " +
"COUNT(*) as recording_count, " +
"AVG(duration) as avg_duration_minutes " +
"FROM audio_management " +
"WHERE DATE(recording_time) = #{date} " +
"AND project_id IS NOT NULL " +
"AND project_id != '' " +
"GROUP BY project_id, project_name")
List<Map<String, Object>> getProjectStatisticsByDate(@Param("date") LocalDate date);
/**
* 检查指定日期的统计数据是否已存在
* @param date 统计日期
@@ -99,12 +80,11 @@ public interface AudioManagementStatisticsMapper extends BaseMapper<AudioManagem
*/
@Select("SELECT " +
"sales_id, " +
"MAX(sales_name) as sales_name, " +
"SUM(sales_total_duration) as total_duration, " +
"SUM(sales_recording_count) as total_count, " +
"SUM(personal_total_duration) as total_duration, " +
"SUM(personal_recording_count) as total_count, " +
"CASE " +
" WHEN SUM(sales_recording_count) > 0 THEN " +
" ROUND(SUM(sales_total_duration) / SUM(sales_recording_count), 2) " +
" WHEN SUM(personal_recording_count) > 0 THEN " +
" ROUND(SUM(personal_total_duration) / SUM(personal_recording_count), 2) " +
" ELSE 0 " +
"END as avg_duration " +
"FROM audio_management_statistics " +

View File

@@ -64,13 +64,4 @@ public interface IAudioManagementStatisticsService extends IService<AudioManagem
* @return 统计记录列表
*/
List<AudioManagementStatistics> getStatisticsBySales(String salesId, String salesPhone, LocalDate startDate, LocalDate endDate);
/**
* 查询指定项目的统计数据
* @param projectId 项目ID
* @param startDate 开始日期
* @param endDate 结束日期
* @return 统计记录列表
*/
List<AudioManagementStatistics> getStatisticsByProject(String projectId, LocalDate startDate, LocalDate endDate);
}

View File

@@ -44,9 +44,6 @@ public class AudioManagementStatisticsServiceImpl extends ServiceImpl<AudioManag
// 查询该日期的销售人员录音统计数据
List<Map<String, Object>> salesStatsList = baseMapper.getSalesStatisticsByDate(date);
// 查询该日期的项目录音统计数据
List<Map<String, Object>> projectStatsList = baseMapper.getProjectStatisticsByDate(date);
int count = 0;
// 处理门店统计数据
@@ -102,9 +99,6 @@ public class AudioManagementStatisticsServiceImpl extends ServiceImpl<AudioManag
Object salesIdObj = salesStat.get("sales_id");
statistics.setSalesId(salesIdObj != null ? salesIdObj.toString() : "");
Object salesNameObj = salesStat.get("sales_name");
statistics.setSalesName(salesNameObj != null ? salesNameObj.toString() : "未知销售");
// 设置销售人员录音统计数据
Object salesTotalDurationObj = salesStat.get("total_duration_minutes");
if (salesTotalDurationObj != null) {
@@ -131,56 +125,11 @@ public class AudioManagementStatisticsServiceImpl extends ServiceImpl<AudioManag
} else {
// 如果没有找到对应的销售人员数据,设置为空
statistics.setSalesId("");
statistics.setSalesName("");
statistics.setSalesTotalDuration(0L);
statistics.setSalesRecordingCount(0);
statistics.setSalesAvgDuration(BigDecimal.ZERO);
}
// 查找该门店对应的项目统计数据
String dealershipIdForProject = dealershipIdObj != null ? dealershipIdObj.toString() : "";
Map<String, Object> projectStat = findProjectStatByDealership(projectStatsList, dealershipIdForProject);
if (projectStat != null) {
// 设置项目信息
Object projectIdObj = projectStat.get("project_id");
statistics.setProjectId(projectIdObj != null ? projectIdObj.toString() : "");
Object projectNameObj = projectStat.get("project_name");
statistics.setProjectName(projectNameObj != null ? projectNameObj.toString() : "未知项目");
// 设置项目录音统计数据
Object projectTotalDurationObj = projectStat.get("total_duration_minutes");
if (projectTotalDurationObj != null) {
statistics.setProjectTotalDuration(Long.valueOf(projectTotalDurationObj.toString()));
} else {
statistics.setProjectTotalDuration(0L);
}
Object projectRecordingCountObj = projectStat.get("recording_count");
if (projectRecordingCountObj != null) {
statistics.setProjectRecordingCount(Integer.valueOf(projectRecordingCountObj.toString()));
} else {
statistics.setProjectRecordingCount(0);
}
// 计算项目平均时长
if (statistics.getProjectRecordingCount() > 0 && statistics.getProjectTotalDuration() > 0) {
BigDecimal projectAvgDuration = BigDecimal.valueOf(statistics.getProjectTotalDuration())
.divide(BigDecimal.valueOf(statistics.getProjectRecordingCount()), 2, RoundingMode.HALF_UP);
statistics.setProjectAvgDuration(projectAvgDuration);
} else {
statistics.setProjectAvgDuration(BigDecimal.ZERO);
}
} else {
// 如果没有找到对应的项目数据,设置为空
statistics.setProjectId("");
statistics.setProjectName("");
statistics.setProjectTotalDuration(0L);
statistics.setProjectRecordingCount(0);
statistics.setProjectAvgDuration(BigDecimal.ZERO);
}
// 设置统计日期和时间
statistics.setStatisticsDate(date);
statistics.setCreatedAt(LocalDateTime.now());
@@ -210,22 +159,6 @@ public class AudioManagementStatisticsServiceImpl extends ServiceImpl<AudioManag
return null;
}
/**
* 根据门店ID查找对应的项目统计数据
* @param projectStatsList 项目统计列表
* @param dealershipId 门店ID
* @return 项目统计数据
*/
private Map<String, Object> findProjectStatByDealership(List<Map<String, Object>> projectStatsList, String dealershipId) {
// 这里需要根据业务逻辑来确定门店和项目的对应关系
// 由于原始数据中可能没有直接的关联关系,这里返回第一个项目数据作为示例
// 实际使用时需要根据具体的业务逻辑来调整
if (!projectStatsList.isEmpty()) {
return projectStatsList.get(0);
}
return null;
}
@Override
public int generateYesterdayStatistics() {
LocalDate yesterday = LocalDate.now().minusDays(1);
@@ -302,7 +235,6 @@ public class AudioManagementStatisticsServiceImpl extends ServiceImpl<AudioManag
Long totalDuration = null;
Integer totalCount = null;
BigDecimal avgDuration = null;
String salesName = null;
// 获取总录音时长
Object totalDurationObj = aggregateResult.get("total_duration");
@@ -322,12 +254,6 @@ public class AudioManagementStatisticsServiceImpl extends ServiceImpl<AudioManag
avgDuration = new BigDecimal(avgDurationObj.toString());
}
// 获取销售人员姓名
Object salesNameObj = aggregateResult.get("sales_name");
if (salesNameObj != null) {
salesName = salesNameObj.toString();
}
// 将聚合统计结果设置到每条记录上
for (AudioManagementStatistics stat : statisticsList) {
// 设置总录音时长(汇总)
@@ -346,23 +272,9 @@ public class AudioManagementStatisticsServiceImpl extends ServiceImpl<AudioManag
} else {
stat.setSalesAvgDuration(BigDecimal.ZERO);
}
// 如果聚合结果中有销售人员姓名,且当前记录没有,则设置
if (salesName != null && (stat.getSalesName() == null || stat.getSalesName().isEmpty())) {
stat.setSalesName(salesName);
}
}
}
return statisticsList;
}
@Override
public List<AudioManagementStatistics> getStatisticsByProject(String projectId, LocalDate startDate, LocalDate endDate) {
LambdaQueryWrapper<AudioManagementStatistics> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AudioManagementStatistics::getProjectId, projectId)
.between(AudioManagementStatistics::getStatisticsDate, startDate, endDate)
.orderByAsc(AudioManagementStatistics::getStatisticsDate);
return list(queryWrapper);
}
}

View File

@@ -1 +0,0 @@
spring.application.name=Langchain4j-cst20250803

View File

@@ -224,10 +224,10 @@ springdoc:
swagger:
api:
base-url: http://localhost:8090
base-url: http://localhost:8091
# http://localhost:9060/swagger-ui/index.html?urls.primaryName=public-api
server:
port: 8090
port: 8091
# Dify API 配置
dify: