修改通话记录统计逻辑

master
wujingtao 2 years ago
parent fe1f0c406f
commit d0c32c9c35

@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @author wjt
@ -76,4 +77,9 @@ public class ReportController {
queryReportService.downloadMemberReport(response, beginTime, endTime, memberId);
}
@PostMapping("/report/turnOn")
@ApiOperation("统计接通过的线索")
public CommonResponse<Object> getTurnOnIds(@RequestBody List<Long> clueIds) {
return queryReportService.getTurnOnIds(clueIds);
}
}

@ -4,6 +4,7 @@ import com.baiye.http.CommonResponse;
import com.baiye.modules.report.entity.dto.StatisticalReportDTO;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @author wujingtao
@ -72,4 +73,11 @@ public interface QueryReportService {
* @return
*/
void downloadMemberReport(HttpServletResponse response, String beginTime, String endTime, Long memberId);
/**
* 线
* @param clueIds
* @return
*/
CommonResponse<Object> getTurnOnIds(List<Long> clueIds);
}

@ -30,7 +30,10 @@ import com.baiye.modules.system.repository.TaskRepository;
import com.baiye.modules.system.repository.UserRepository;
import com.baiye.modules.system.service.CompanyService;
import com.baiye.modules.telemarkting.dao.AllCallInfoRepository;
import com.baiye.modules.telemarkting.dao.CallClueRepository;
import com.baiye.modules.telemarkting.entity.AllCallInfo;
import com.baiye.modules.telemarkting.entity.CallClueInfo;
import com.baiye.timed.ReportSync;
import com.baiye.util.DateTimeUtil;
import com.baiye.util.ExportExcelUtil;
import com.baiye.util.SecurityUtils;
@ -60,6 +63,8 @@ public class QueryReportServiceImpl implements QueryReportService {
private final UserReportRepository userReportRepository;
private final SourceClueClient sourceClueClient;
private final UserRepository userRepository;
private final CallClueRepository callClueRepository;
private final ReportSync reportSync;
/**
*
@ -69,14 +74,13 @@ public class QueryReportServiceImpl implements QueryReportService {
@Override
public CommonResponse<Object> getReportByAll() {
Long companyId = SecurityUtils.getCompanyId();
String beginOfDay = DateUtil.beginOfDay(DateUtil.yesterday()).toString();
String endOfDay = DateUtil.endOfDay(DateUtil.yesterday()).toString();
List<TaskReport> list = taskReportRepository.queryAllByTimeAndCompanyId(beginOfDay, endOfDay, companyId);
String beginOfDay = DateUtil.beginOfDay(DateUtil.date()).toString();
String endOfDay = DateUtil.date().toString();
List<CallClueInfo> callClueInfos = callClueRepository.queryAllByTimeAndCompanyId(beginOfDay, endOfDay, companyId);
//对查询的数据进行处理
MemberInfoVO messageInfo = getAllTaskInfo(list);
MemberInfoVO messageInfo = getMessageInfo(beginOfDay, endOfDay, callClueInfos);
return CommonResponse.createBySuccess(messageInfo);
}
/**
* id
*
@ -89,6 +93,19 @@ public class QueryReportServiceImpl implements QueryReportService {
//对参数进行处理
StatisticalReportDTO condition = getStatisticalReportDTO(s);
List<TaskReport> taskReports = getTaskReport(condition.getBeginTime(), condition.getEndTime(), condition.getType(), condition.getIds());
// TODO: 2022/5/6 0006 这里将统计今日的数据
boolean betweenDays = DateTimeUtil.betweenByDay(DateUtil.date(), DateUtil.parseDate(condition.getEndTime()));
if (betweenDays) {
List<CallClueInfo> callClueInfos = callClueRepository.queryAllByTimeAndTaskId(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), condition.getIds());
List<TaskReport> list = reportSync.autoCountReportByTask(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), callClueInfos);
if (CollUtil.isEmpty(taskReports)) {
taskReports = list;
} else {
taskReports.addAll(list);
}
}
if (taskReports == null) {
return CommonResponse.createByErrorMessage("请检查时间类型是否错误");
}
@ -97,6 +114,8 @@ public class QueryReportServiceImpl implements QueryReportService {
taskReports.stream().collect(Collectors.groupingBy(TaskReport::getTaskId, Collectors.toList())).forEach(map::put);
Date begin = DateUtil.parseDate(condition.getBeginTime());
Date end = DateUtil.parseDate(condition.getEndTime());
//按月统计
if (s.getType() == DefaultNumberConstants.THREE_NUMBER) {
for (Long key : map.keySet()) {
@ -148,6 +167,19 @@ public class QueryReportServiceImpl implements QueryReportService {
StatisticalReportDTO condition = getStatisticalReportDTO(s);
List<TaskReport> taskReports = getTaskReport(condition.getBeginTime(), condition.getEndTime(), condition.getType(), condition.getIds());
List<TaskReport> list = new ArrayList<>();
// TODO: 2022/5/6 0006 这里将统计今日的数据
boolean betweenDays = DateTimeUtil.betweenByDay(DateUtil.date(), DateUtil.parseDate(condition.getEndTime()));
if (betweenDays) {
List<CallClueInfo> callClueInfos = callClueRepository.queryAllByTimeAndTaskId(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), condition.getIds());
List<TaskReport> lists = reportSync.autoCountReportByTask(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), callClueInfos);
if (CollUtil.isEmpty(taskReports)) {
taskReports = lists;
} else {
taskReports.addAll(lists);
}
}
if (taskReports != null && taskReports.size() > 0) {
//根据任务id合并
// TODO: 2022/3/18 0018 如果是动态任务,任务的总数是变动的。可能会有影响
@ -171,7 +203,7 @@ public class QueryReportServiceImpl implements QueryReportService {
}
/**
* 线
* 线
*
* @param response
* @param id
@ -260,6 +292,19 @@ public class QueryReportServiceImpl implements QueryReportService {
return CommonResponse.createByErrorMessage("未找到组信息");
}
List<UserReport> userReports = userReportRepository.queryAllByTimeAndTeamIds(beginTime, endTime, ids);
// TODO: 2022/5/6 0006 这里将统计今日的数据
boolean betweenDays = DateTimeUtil.betweenByDay(DateUtil.date(), DateUtil.parseDate(endTime));
if (betweenDays) {
List<CallClueInfo> callClueInfos = callClueRepository.queryAllByTimeAndTeamId(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), ids);
List<UserReport> list = reportSync.autoCountReportByUser(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), callClueInfos);
if (CollUtil.isEmpty(userReports)) {
userReports = list;
} else {
userReports.addAll(list);
}
}
Map<Long, UserReport> map = new HashMap<>();
//将一个组的数据合并
for (UserReport info : userReports) {
@ -297,6 +342,19 @@ public class QueryReportServiceImpl implements QueryReportService {
throw new BadRequestException(ResponseCode.USER_INFORMATION_ERROR.getDesc());
}
List<UserReport> userReports = userReportRepository.queryAllByTimeAndTeamIds(beginTime, endTime, ids);
// TODO: 2022/5/6 0006 这里将统计今日的数据
boolean betweenDays = DateTimeUtil.betweenByDay(DateUtil.date(), DateUtil.parseDate(endTime));
if (betweenDays) {
List<CallClueInfo> callClueInfos = callClueRepository.queryAllByTimeAndTeamId(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), ids);
List<UserReport> list = reportSync.autoCountReportByUser(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), callClueInfos);
if (CollUtil.isEmpty(userReports)) {
userReports = list;
} else {
userReports.addAll(list);
}
}
Map<Long, UserReport> map = new HashMap<>();
for (UserReport info : userReports) {
if (map.containsKey(info.getMemberId())) {
@ -324,20 +382,28 @@ public class QueryReportServiceImpl implements QueryReportService {
@Override
public CommonResponse<Object> getMemberReport(String beginTime, String endTime, Long memberId) {
String begin;
String end;
if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) {
begin = DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd");
end = DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd");
} else {
begin = DateUtil.format(DateUtil.parse(beginTime), "yyyy-MM-dd");
end = DateUtil.format(DateUtil.parse(endTime), "yyyy-MM-dd");
beginTime = DateUtil.today();
endTime = DateUtil.today();
}
if (memberId == null) {
log.error("成员id为空");
return CommonResponse.createByErrorMessage("成员id为空");
}
List<UserReport> userReports = userReportRepository.queryAllByTimeAndId(begin, end, memberId);
List<UserReport> userReports = userReportRepository.queryAllByTimeAndId(beginTime, endTime, memberId);
// TODO: 2022/5/6 0006 这里将统计今日的数据
boolean betweenDays = DateTimeUtil.betweenByDay(DateUtil.date(), DateUtil.parseDate(endTime));
if (betweenDays) {
List<CallClueInfo> callClueInfos = callClueRepository.queryAllByTimeAndMemberId(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), memberId);
List<UserReport> list = reportSync.autoCountReportByUser(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), callClueInfos);
if (CollUtil.isEmpty(userReports)) {
userReports = list;
} else {
userReports.addAll(list);
}
}
Map<Long, UserReport> map = new HashMap<>();
//合并同一个人的线索数据
for (UserReport info : userReports) {
@ -365,16 +431,24 @@ public class QueryReportServiceImpl implements QueryReportService {
@Override
public void downloadMemberReport(HttpServletResponse response, String beginTime, String endTime, Long memberId) {
String begin;
String end;
if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) {
begin = DateUtil.today();
end = DateUtil.today();
} else {
begin = DateUtil.format(DateUtil.parse(beginTime), "yyyy-MM-dd");
end = DateUtil.format(DateUtil.parse(endTime), "yyyy-MM-dd");
beginTime = DateUtil.today();
endTime = DateUtil.today();
}
List<UserReport> userReports = userReportRepository.queryAllByTimeAndId(beginTime, endTime, memberId);
// TODO: 2022/5/6 0006 这里将统计今日的数据
boolean betweenDays = DateTimeUtil.betweenByDay(DateUtil.date(), DateUtil.parseDate(endTime));
if (betweenDays) {
List<CallClueInfo> callClueInfos = callClueRepository.queryAllByTimeAndMemberId(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), memberId);
List<UserReport> list = reportSync.autoCountReportByUser(DateUtil.beginOfDay(DateUtil.date()).toString(), DateUtil.date().toString(), callClueInfos);
if (CollUtil.isEmpty(userReports)) {
userReports = list;
} else {
userReports.addAll(list);
}
}
List<UserReport> userReports = userReportRepository.queryAllByTimeAndId(begin, end, memberId);
List<MemberInfoVO> listResult = new ArrayList<>();
for (UserReport info : userReports) {
MemberInfoVO memberInfoVO = new MemberInfoVO();
@ -384,6 +458,15 @@ public class QueryReportServiceImpl implements QueryReportService {
ExportExcelUtil.downloadEasyExcel(response, MemberInfoVO.class, listResult);
}
@Override
public CommonResponse<Object> getTurnOnIds(List<Long> clueIds) {
List<Long> list = allCallInfoRepository.queryIdsByStatusAndClueId(clueIds, 2);
if (CollUtil.isNotEmpty(list)) {
list = list.stream().distinct().collect(Collectors.toList());
}
return CommonResponse.createBySuccess(list);
}
/**
*
*/
@ -566,6 +649,49 @@ public class QueryReportServiceImpl implements QueryReportService {
return memberInfoVO;
}
/**
* 线
*/
private MemberInfoVO getMessageInfo(String begin, String end, List<CallClueInfo> callClueInfos) {
int usrNum = 0;
int turnOnNum = 0;
double turnOnRate = 0.00;
long breatheTotalDuration = 0;
double breatheAverageDuration = 0;
if (CollUtil.isNotEmpty(callClueInfos)) {
//使用数
usrNum = callClueInfos.size();
for (CallClueInfo info : callClueInfos) {
//接通时才会有通话时长
long clueId = info.getClueId();
List<AllCallInfo> doubleCallInfo = allCallInfoRepository.queryAllByTime(begin, end, clueId);
//统计通话时长
int doubleClueTime = 0;
if (CollUtil.isNotEmpty(doubleCallInfo)) {
doubleClueTime = doubleCallInfo.stream().filter(item -> item.getStatus() == DefaultNumberConstants.TWO_NUMBER).collect(Collectors.toList()).stream().mapToInt(AllCallInfo::getDuration).sum();
if (doubleClueTime > 0) {
//有通话时长 说明电话打通
turnOnNum++;
}
}
breatheTotalDuration += doubleClueTime;
}
breatheAverageDuration = NumberUtil.div(breatheTotalDuration, callClueInfos.size(), 2);
}
if (usrNum != 0) {
//接通率=接通数/使用数
turnOnRate = NumberUtil.div(turnOnNum, usrNum, 2);
}
MemberInfoVO memberInfoVO = new MemberInfoVO();
memberInfoVO.setTurnOnNum(turnOnNum);
memberInfoVO.setTurnOnRate(turnOnRate);
memberInfoVO.setUsrNum(usrNum);
memberInfoVO.setBreatheAverageDuration(breatheAverageDuration);
memberInfoVO.setBreatheTotalDuration(breatheTotalDuration);
return memberInfoVO;
}
/**
*
*/

@ -71,4 +71,14 @@ public interface AllCallInfoRepository extends JpaRepository<AllCallInfo, Long>,
@Modifying
@Query(value = "delete from tb_call_info where member_id in ?1", nativeQuery = true)
int deleteByMemberId(List<Long> userIds);
/**
* 线idid
*
* @param clueIds
* @param status
* @return
*/
@Query(value = "select clue_id from tb_call_info where clue_id in ?1 and status = ?2", nativeQuery = true)
List<Long> queryIdsByStatusAndClueId(List<Long> clueIds, Integer status);
}

@ -42,4 +42,48 @@ public interface CallClueRepository extends JpaRepository<CallClueInfo, Long>, J
@Modifying
@Query(value = "delete from CallClueInfo where companyId = ?1")
int deleteByCompanyId(Long companyId);
/**
*
*
* @param beginTime
* @param endTime
* @param companyId
* @return
*/
@Query(value = "select * from tb_call_clue where (create_time between ?1 and ?2) and company_id =?3", nativeQuery = true)
List<CallClueInfo> queryAllByTimeAndCompanyId(String beginTime, String endTime, Long companyId);
/**
* id线
*
* @param beginTime
* @param endTime
* @param ids
* @return
*/
@Query(value = "select * from tb_call_clue d where d.create_time >= ?1 and d.create_time< ?2 AND d.task_id in ?3", nativeQuery = true)
List<CallClueInfo> queryAllByTimeAndTaskId(String beginTime, String endTime, List<Long> ids);
/**
* id线
*
* @param beginTime
* @param endTime
* @param ids
* @return
*/
@Query(value = "select * from tb_call_clue d where d.create_time >= ?1 and d.create_time< ?2 AND d.team_id in ?3", nativeQuery = true)
List<CallClueInfo> queryAllByTimeAndTeamId(String beginTime, String endTime, List<Long> ids);
/**
* id线
*
* @param beginTime
* @param endTime
* @param id
* @return
*/
@Query(value = "select * from tb_call_clue d where d.create_time >= ?1 and d.create_time< ?2 AND d.member.id = ?3", nativeQuery = true)
List<CallClueInfo> queryAllByTimeAndMemberId(String beginTime, String endTime, Long id);
}

@ -64,8 +64,6 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
private SourceClueClient sourceClueClient;
@Resource
private ExtensionNumberRepository extensionNumberRepository;
@Resource
private WebSocketServer webSocketServer;
@Override
public CommonResponse<String> doubleCallReq(TelephoneCallReqDTO doubleCallReq, Long companyId) {

@ -61,13 +61,15 @@ public class ReportSync {
return;
}
//按任务统计
autoCountReportByTask(beginOfDay, endOfDay, callClueInfos);
List<TaskReport> taskList = autoCountReportByTask(beginOfDay, endOfDay, callClueInfos);
taskReportRepository.saveAll(taskList);
//按人员统计
autoCountReportByUser(beginOfDay, endOfDay, callClueInfos);
List<UserReport> userList = autoCountReportByUser(beginOfDay, endOfDay, callClueInfos);
userReportRepository.saveAll(userList);
log.info("++++++++++++++++++++++countReport Sync end time {} ++++++++++++++++", DateUtil.now());
}
private void autoCountReportByTask(String beginOfDay, String endOfDay, List<CallClueInfo> callClueInfos) {
public List<TaskReport> autoCountReportByTask(String beginOfDay, String endOfDay, List<CallClueInfo> callClueInfos) {
HashMap<Long, List<CallClueInfo>> map = new HashMap<>();
//根据任务id分组
callClueInfos.stream().collect(Collectors.groupingBy(CallClueInfo::getTaskId, Collectors.toList())).forEach(map::put);
@ -75,7 +77,7 @@ public class ReportSync {
for (Long key : map.keySet()) {
Task taskInfo = taskRepository.findByIsDistributionAndId(DefaultNumberConstants.ONE_NUMBER, key);
if (ObjectUtil.isNull(taskInfo)) {
log.info("任务定时统计时,未找到该任务 id:{}", key);
log.info("任务统计时,未找到该任务 id:{}", key);
continue;
}
int totalNum = taskInfo.getTotalNumber();
@ -93,6 +95,7 @@ public class ReportSync {
}
//计算
TaskReport countInfo = JSONUtil.toBean(getCountInfo(beginOfDay, endOfDay, map.get(key)), TaskReport.class);
//如果
countInfo.setTaskId(key);
countInfo.setTaskName(taskName);
countInfo.setTotalNum(totalNum);
@ -101,10 +104,10 @@ public class ReportSync {
countInfo.setCompanyId(map.get(key).get(0).getCompanyId());
list.add(countInfo);
}
taskReportRepository.saveAll(list);
return list;
}
private void autoCountReportByUser(String beginOfDay, String endOfDay, List<CallClueInfo> callClueInfos) {
public List<UserReport> autoCountReportByUser(String beginOfDay, String endOfDay, List<CallClueInfo> callClueInfos) {
HashMap<Long, List<CallClueInfo>> map = new HashMap<>();
//根据人员id分组
callClueInfos.stream().collect(Collectors.groupingBy(CallClueInfo::getMemberId, Collectors.toList())).forEach(map::put);
@ -131,7 +134,7 @@ public class ReportSync {
userReport.setCreateTime(DateUtil.date());
list.add(userReport);
}
userReportRepository.saveAll(list);
return list;
}
private JSONObject getCountInfo(String beginOfDay, String endOfDay, List<CallClueInfo> callClueInfos) {

Loading…
Cancel
Save