录音时长统计相关代码
This commit is contained in:
@@ -55,6 +55,16 @@ public interface IAudioManagementStatisticsService extends IService<AudioManagem
|
||||
*/
|
||||
List<AudioManagementStatistics> getStatisticsBySales(String salesId, LocalDate startDate, LocalDate endDate);
|
||||
|
||||
/**
|
||||
* 查询指定销售人员的统计数据(支持根据ID或电话号码查询)
|
||||
* @param salesId 销售人员ID(可选)
|
||||
* @param salesPhone 销售人员电话号码(可选)
|
||||
* @param startDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @return 统计记录列表
|
||||
*/
|
||||
List<AudioManagementStatistics> getStatisticsBySales(String salesId, String salesPhone, LocalDate startDate, LocalDate endDate);
|
||||
|
||||
/**
|
||||
* 查询指定项目的统计数据
|
||||
* @param projectId 项目ID
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.rj.service.impl;
|
||||
|
||||
import com.rj.entity.AudioManagementStatistics;
|
||||
import com.rj.entity.SalesManagement;
|
||||
import com.rj.mapper.AudioManagementStatisticsMapper;
|
||||
import com.rj.service.IAudioManagementStatisticsService;
|
||||
import com.rj.service.ISalesManagementService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -26,6 +29,9 @@ import java.util.Map;
|
||||
@Service
|
||||
public class AudioManagementStatisticsServiceImpl extends ServiceImpl<AudioManagementStatisticsMapper, AudioManagementStatistics> implements IAudioManagementStatisticsService {
|
||||
|
||||
@Autowired
|
||||
private ISalesManagementService salesManagementService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int generateStatisticsByDate(LocalDate date) {
|
||||
@@ -253,6 +259,104 @@ public class AudioManagementStatisticsServiceImpl extends ServiceImpl<AudioManag
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AudioManagementStatistics> getStatisticsBySales(String salesId, String salesPhone, LocalDate startDate, LocalDate endDate) {
|
||||
LambdaQueryWrapper<AudioManagementStatistics> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 如果提供了电话号码,先通过电话号码查询到salesId
|
||||
String finalSalesId = salesId;
|
||||
if ((finalSalesId == null || finalSalesId.trim().isEmpty()) &&
|
||||
salesPhone != null && !salesPhone.trim().isEmpty()) {
|
||||
// 通过电话号码查询销售人员
|
||||
LambdaQueryWrapper<SalesManagement> salesQueryWrapper = new LambdaQueryWrapper<>();
|
||||
salesQueryWrapper.eq(SalesManagement::getLoginAccount, salesPhone);
|
||||
List<SalesManagement> salesList = salesManagementService.list(salesQueryWrapper);
|
||||
|
||||
if (salesList == null || salesList.isEmpty()) {
|
||||
// 如果没有找到对应的销售人员,返回空列表
|
||||
return List.of();
|
||||
}
|
||||
|
||||
// 如果找到多个销售人员,使用第一个的ID
|
||||
// 或者可以根据业务需求处理多个销售人员的情况
|
||||
finalSalesId = salesList.get(0).getId();
|
||||
}
|
||||
|
||||
// 如果最终没有salesId,返回空列表
|
||||
if (finalSalesId == null || finalSalesId.trim().isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
// 根据salesId查询统计数据
|
||||
queryWrapper.eq(AudioManagementStatistics::getSalesId, finalSalesId)
|
||||
.between(AudioManagementStatistics::getStatisticsDate, startDate, endDate)
|
||||
.orderByAsc(AudioManagementStatistics::getStatisticsDate);
|
||||
List<AudioManagementStatistics> statisticsList = list(queryWrapper);
|
||||
|
||||
// 在数据库层面聚合查询总录音时长和平均录音时长
|
||||
Map<String, Object> aggregateResult = baseMapper.getSalesAggregateStatistics(finalSalesId, startDate, endDate);
|
||||
|
||||
// 如果查询到聚合结果,将汇总统计信息设置到每条记录上
|
||||
if (aggregateResult != null && !aggregateResult.isEmpty() && !statisticsList.isEmpty()) {
|
||||
// 提取聚合结果
|
||||
Long totalDuration = null;
|
||||
Integer totalCount = null;
|
||||
BigDecimal avgDuration = null;
|
||||
String salesName = null;
|
||||
|
||||
// 获取总录音时长
|
||||
Object totalDurationObj = aggregateResult.get("total_duration");
|
||||
if (totalDurationObj != null) {
|
||||
totalDuration = Long.valueOf(totalDurationObj.toString());
|
||||
}
|
||||
|
||||
// 获取总录音数量
|
||||
Object totalCountObj = aggregateResult.get("total_count");
|
||||
if (totalCountObj != null) {
|
||||
totalCount = Integer.valueOf(totalCountObj.toString());
|
||||
}
|
||||
|
||||
// 获取平均录音时长
|
||||
Object avgDurationObj = aggregateResult.get("avg_duration");
|
||||
if (avgDurationObj != null) {
|
||||
avgDuration = new BigDecimal(avgDurationObj.toString());
|
||||
}
|
||||
|
||||
// 获取销售人员姓名
|
||||
Object salesNameObj = aggregateResult.get("sales_name");
|
||||
if (salesNameObj != null) {
|
||||
salesName = salesNameObj.toString();
|
||||
}
|
||||
|
||||
// 将聚合统计结果设置到每条记录上
|
||||
for (AudioManagementStatistics stat : statisticsList) {
|
||||
// 设置总录音时长(汇总)
|
||||
if (totalDuration != null) {
|
||||
stat.setSalesTotalDuration(totalDuration);
|
||||
}
|
||||
|
||||
// 设置总录音数量(汇总)
|
||||
if (totalCount != null) {
|
||||
stat.setSalesRecordingCount(totalCount);
|
||||
}
|
||||
|
||||
// 设置平均录音时长(汇总)
|
||||
if (avgDuration != null) {
|
||||
stat.setSalesAvgDuration(avgDuration);
|
||||
} 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<>();
|
||||
|
||||
Reference in New Issue
Block a user