修改呼叫统计的方式

master
wujingtao 3 years ago
parent 4e083e754b
commit 7b98a4f84d

@ -11,5 +11,7 @@ public class ResSourceLabel {
private Long clueId;
private String remark;
private String nid;
private String remark;
}

@ -2,7 +2,7 @@ package com.baiye.modules.report.api;
import com.baiye.http.CommonResponse;
import com.baiye.modules.report.entity.dto.StatisticalReportDTO;
import com.baiye.modules.report.service.ReportService;
import com.baiye.modules.report.service.QueryReportService;
import com.baiye.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -21,69 +21,59 @@ import javax.servlet.http.HttpServletResponse;
@Slf4j
@Api(tags = "获取统计信息")
public class ReportController {
@Resource
private ReportService reportService;
private QueryReportService queryReportService;
@GetMapping("/report/all")
@ApiOperation("按任务分组的统计信息")
@ApiOperation("所有任务的统计信息")
public CommonResponse<Object> getReportByAll() {
return reportService.getReportByAll();
return queryReportService.getReportByAll();
}
@PostMapping("/report/task")
@ApiOperation("按任务的统计信息")
public CommonResponse<Object> getReportByTask(@RequestBody StatisticalReportDTO s) {
Long companyId = SecurityUtils.getCompanyId();
s.setCompanyId(companyId);
return reportService.getReportByTask(s);
s.setCompanyId(SecurityUtils.getCompanyId());
return queryReportService.getReportByTask(s);
}
@PostMapping("/download/task")
@ApiOperation("导出任务统计信息")
public void downloadTaskReport(HttpServletResponse response, @RequestBody StatisticalReportDTO statisticalReportDTO) {
Long companyId = SecurityUtils.getCompanyId();
statisticalReportDTO.setCompanyId(companyId);
reportService.downloadTaskReport(response, statisticalReportDTO);
public void downloadTaskReport(HttpServletResponse response, @RequestBody StatisticalReportDTO s) {
s.setCompanyId(SecurityUtils.getCompanyId());
queryReportService.downloadTaskReport(response, s);
}
@GetMapping("/download/single/task")
@ApiOperation("导出单个任务的线索统计信息")
public void downloadTaskReport(HttpServletResponse response, Long id) {
reportService.downloadSingleTaskReport(response, id);
}
@GetMapping("/report/single/task")
@ApiOperation("查单个任务的线索统计信息")
public CommonResponse<Object> reportTaskReport(Long id) {
return reportService.reportSingleTaskReport(id);
queryReportService.downloadSingleTaskReport(response, id);
}
@PostMapping("/report/organize")
@ApiOperation("按组的统计信息")
public CommonResponse<Object> getReportByOrganize(@RequestBody StatisticalReportDTO s) {
Long companyId = SecurityUtils.getCompanyId();
s.setCompanyId(companyId);
return reportService.getReportByOrganize(s);
return queryReportService.getReportByOrganize(s);
}
@PostMapping("/download/organize")
@ApiOperation("导出组成员统计信息")
public void downloadOrganizeReport(HttpServletResponse response, @RequestBody StatisticalReportDTO s) {
Long companyId = SecurityUtils.getCompanyId();
s.setCompanyId(companyId);
reportService.downloadOrganizeReport(response, s);
queryReportService.downloadOrganizeReport(response, s);
}
@GetMapping("/report/member")
@ApiOperation("获取单个成员统计信息")
public CommonResponse<Object> getMemberReport(String beginTime, String endTime, Long memberId) {
return reportService.getMemberReport(beginTime, endTime, memberId);
return queryReportService.getMemberReport(beginTime, endTime, memberId);
}
@GetMapping("/download/member")
@ApiOperation("导出单个成员统计信息")
public void downloadMemberReport(HttpServletResponse response, String beginTime, String endTime, Long memberId) {
reportService.downloadMemberReport(response, beginTime, endTime, memberId);
queryReportService.downloadMemberReport(response, beginTime, endTime, memberId);
}
}

@ -0,0 +1,39 @@
package com.baiye.modules.report.dao;
import com.baiye.modules.report.entity.TaskReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author wujingtao
* @date 2022/03/14
*/
@Repository
public interface TaskReportRepository extends JpaRepository<TaskReport, Long>, JpaSpecificationExecutor<TaskReport> {
/**
* id
*
* @param beginTime
* @param endTime
* @param ids
* @return
*/
@Query(value = "select * from tb_report_task where (create_time between ?1 and ?2) and (coalesce (?3,null) is null or task_id in (?3))", nativeQuery = true)
List<TaskReport> queryAllByTimeAndTaskIds(String beginTime, String endTime, List<Long> ids);
/**
*
*
* @param beginTime
* @param endTime
* @param companyId
* @return
*/
@Query(value = "select * from tb_report_task where (create_time between ?1 and ?2) and company_id =?3", nativeQuery = true)
List<TaskReport> queryAllByTimeAndCompanyId(String beginTime, String endTime, Long companyId);
}

@ -0,0 +1,39 @@
package com.baiye.modules.report.dao;
import com.baiye.modules.report.entity.UserReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author wujingtao
* @date 2022/03/15
*/
@Repository
public interface UserReportRepository extends JpaRepository<UserReport, Long>, JpaSpecificationExecutor<UserReport> {
/**
*
*
* @param beginTime
* @param endTime
* @param id
* @return
*/
@Query(value = "select * from tb_report_user d where (d.create_time between ?1 and ?2) and d.member_id = ?3", nativeQuery = true)
List<UserReport> queryAllByTimeAndId(String beginTime, String endTime, Long id);
/**
* id
*
* @param beginTime
* @param endTime
* @param ids
* @return
*/
@Query(value = "select * from tb_report_user where (create_time between ?1 and ?2) and (coalesce (?3,null) is null or organize_id in (?3))", nativeQuery = true)
List<UserReport> queryAllByTimeAndTeamIds(String beginTime, String endTime, List<Long> ids);
}

@ -0,0 +1,74 @@
package com.baiye.modules.report.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
* @author wujingtao
* @date 2022/03/15
*/
@Getter
@Setter
@Entity
@Table(name = "tb_report_user")
@EntityListeners(AuditingEntityListener.class)
@AllArgsConstructor
public class UserReport implements Serializable {
private static final long serialVersionUID = -166471922413278727L;
@Id
@ApiModelProperty(value = "主键id自动递增")
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@LastModifiedDate
@Column(name = "create_time")
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "组id")
@Column(name = "organize_id")
private Long organizeId;
@ApiModelProperty(value = "组名称")
@Column(name = "organize_name")
private String organizeName;
@ApiModelProperty(value = "人员id")
@Column(name = "member_id")
private Long memberId;
@ApiModelProperty(value = "人员名称")
@Column(name = "member_name")
private String memberName;
@ApiModelProperty(value = "使用量")
@Column(name = "usr_num")
private Integer usrNum;
@ApiModelProperty(value = "接通量")
@Column(name = "turn_on_num")
private Integer turnOnNum;
@ApiModelProperty(value = "接通率")
@Column(name = "turn_on_rate")
private Double turnOnRate;
@ApiModelProperty(value = "外呼总时长")
@Column(name = "breathe_total_duration")
private Long breatheTotalDuration;
@ApiModelProperty(value = "外呼平均时长")
@Column(name = "breathe_average_duration")
private Double breatheAverageDuration;
@ApiModelProperty(value = "所属公司")
@Column(name = "company_id")
private Long companyId;
public UserReport() {
}
}

@ -62,7 +62,7 @@ public class MemberInfoVO {
*
*/
@ExcelProperty(value = "外呼总时长(秒)", index = 6)
private Integer breatheTotalDuration;
private Long breatheTotalDuration;
/**
*

@ -6,11 +6,10 @@ import com.baiye.modules.report.entity.dto.StatisticalReportDTO;
import javax.servlet.http.HttpServletResponse;
/**
* @author wjt
* @date 2021/12/10
* @author wujingtao
* @date 2022/03/16
*/
public interface ReportService {
public interface QueryReportService {
/**
*
*
@ -37,8 +36,6 @@ public interface ReportService {
void downloadSingleTaskReport(HttpServletResponse response, Long id);
CommonResponse<Object> reportSingleTaskReport(Long id);
/**
*
*
@ -75,5 +72,4 @@ public interface ReportService {
* @return
*/
void downloadMemberReport(HttpServletResponse response, String beginTime, String endTime, Long memberId);
}

@ -0,0 +1,579 @@
package com.baiye.modules.report.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.exception.BadRequestException;
import com.baiye.feign.SourceClueClient;
import com.baiye.http.CommonResponse;
import com.baiye.model.enums.ResponseCode;
import com.baiye.model.vo.ResSourceLabel;
import com.baiye.modules.report.dao.TaskReportRepository;
import com.baiye.modules.report.dao.UserReportRepository;
import com.baiye.modules.report.entity.TaskReport;
import com.baiye.modules.report.entity.UserReport;
import com.baiye.modules.report.entity.dto.StatisticalReportDTO;
import com.baiye.modules.report.entity.dto.UploadTaskDTO;
import com.baiye.modules.report.entity.vo.MemberInfoVO;
import com.baiye.modules.report.service.QueryReportService;
import com.baiye.modules.system.domain.Organize;
import com.baiye.modules.system.domain.Task;
import com.baiye.modules.system.domain.User;
import com.baiye.modules.system.repository.OrganizeRepository;
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.entity.AllCallInfo;
import com.baiye.util.DateTimeUtil;
import com.baiye.util.ExportExcelUtil;
import com.baiye.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author wujingtao
* @date 2022/03/14
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class QueryReportServiceImpl implements QueryReportService {
private final CompanyService companyService;
private final TaskRepository taskRepository;
private final AllCallInfoRepository allCallInfoRepository;
private final TaskReportRepository taskReportRepository;
private final OrganizeRepository organizeRepository;
private final UserReportRepository userReportRepository;
private final SourceClueClient sourceClueClient;
private final UserRepository userRepository;
/**
*
*
* @return
*/
@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);
//对查询的数据进行处理
MemberInfoVO messageInfo = getAllTaskInfo(list);
return CommonResponse.createBySuccess(messageInfo);
}
/**
* id
*
* @param s
* @return
*/
@Override
public CommonResponse<Object> getReportByTask(StatisticalReportDTO s) {
List<Map<String, Object>> listResult = new ArrayList<>();
//对参数进行处理
StatisticalReportDTO condition = getStatisticalReportDTO(s);
List<TaskReport> taskReports = getTaskReport(condition.getBeginTime(), condition.getEndTime(), condition.getType(), condition.getIds());
if (taskReports == null) {
return CommonResponse.createByErrorMessage("请检查时间类型是否错误");
}
Map<Long, List<TaskReport>> map = new HashMap<>();
//对查询的所有统计信息 按任务id分组
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()) {
Map<String, Object> mapResult = new HashMap<>(2);
List<Map<String, Object>> list = new ArrayList<>();
List<TaskReport> taskReport = map.get(key);
//按时间分组
List<TaskReport> collect = taskReport.stream().filter(c -> DateTimeUtil.betweenByMonth(c.getCreateTime(), begin)).collect(Collectors.toList());
List<TaskReport> collect1 = taskReport.stream().filter(c -> DateTimeUtil.betweenByMonth(c.getCreateTime(), end)).collect(Collectors.toList());
getMapByTime(begin, collect, list);
getMapByTime(end, collect1, list);
mapResult.put("data", list);
mapResult.put("taskName", taskReport.get(0).getTaskName());
listResult.add(mapResult);
}
}
//按天统计
if (s.getType() == DefaultNumberConstants.TWO_NUMBER) {
int betweenDay = (int) DateUtil.between(begin, end, DateUnit.DAY);
for (Long key : map.keySet()) {
List<Map<String, Object>> timeList = new ArrayList<>();
HashMap<String, Object> resultMap = new HashMap<>(2);
for (int i = 0; i <= betweenDay; i++) {
HashMap<String, Object> dateMap = new HashMap<>(2);
Date dateTime = DateUtil.offsetDay(begin, i);
//按时间分组
List<TaskReport> collect = map.get(key).stream().filter(c -> DateTimeUtil.betweenByDay(dateTime, c.getCreateTime())).collect(Collectors.toList());
dateMap.put("createTime", DateTimeUtil.getTimeType(dateTime, condition.getType()));
double usrRate = 0.0;
if (collect.size() > 0) {
//只会有一条数据
TaskReport taskReport = collect.get(0);
usrRate = NumberUtil.div(taskReport.getUsrNum(), taskReport.getTotalNum(), 2).doubleValue();
}
dateMap.put("usrRate", usrRate);
timeList.add(dateMap);
}
resultMap.put("data", timeList);
resultMap.put("taskName", map.get(key).get(0).getTaskName());
listResult.add(resultMap);
}
}
return CommonResponse.createBySuccess(listResult);
}
@Override
public void downloadTaskReport(HttpServletResponse response, StatisticalReportDTO s) {
StatisticalReportDTO condition = getStatisticalReportDTO(s);
List<TaskReport> taskReports = getTaskReport(condition.getBeginTime(), condition.getEndTime(), condition.getType(), condition.getIds());
List<TaskReport> list = new ArrayList<>();
if (taskReports != null && taskReports.size() > 0) {
//根据任务id合并
// TODO: 2022/3/18 0018 如果是动态任务,任务的总数是变动的。可能会有影响
taskReports.parallelStream().collect(Collectors.groupingBy(TaskReport::getTaskId, Collectors.toList())).forEach(
(id, transfer) -> {
transfer.stream().reduce((a, b) -> new TaskReport(a.getId(), null, a.getTaskId(), a.getTaskName(), a.getTotalNum(),
a.getUsrNum() + b.getUsrNum(), a.getTurnOnNum() + b.getTurnOnNum(), a.getTurnOnRate() + b.getTurnOnRate(), a.getBreatheTotalDuration() + b.getBreatheTotalDuration(), a.getBreatheAverageDuration() + b.getBreatheAverageDuration(),
a.getLabel(), a.getCompanyId()
)).ifPresent(list::add);
}
);
}
List<UploadTaskDTO> listResult = new ArrayList<>();
for (TaskReport info : list) {
UploadTaskDTO uploadTaskDTO = new UploadTaskDTO();
BeanUtil.copyProperties(info, uploadTaskDTO);
uploadTaskDTO.setCreateTime(condition.getBeginTime() + "至" + condition.getEndTime());
listResult.add(uploadTaskDTO);
}
ExportExcelUtil.downloadEasyExcel(response, UploadTaskDTO.class, listResult);
}
/**
* 线
*
* @param response
* @param id
*/
@Override
public void downloadSingleTaskReport(HttpServletResponse response, Long id) {
List<AllCallInfo> allCallInfos = allCallInfoRepository.selectClueByTaskId(id);
//以线索id分组
Map<Long, List<AllCallInfo>> map = new HashMap<>(16);
allCallInfos.stream().collect(Collectors.groupingBy(AllCallInfo::getClueId, Collectors.toList())).forEach(map::put);
//提取线索id
List<Long> clueIds = allCallInfos.stream().map(AllCallInfo::getClueId).collect(Collectors.toList());
//获取线索信息
List<ResSourceLabel> clueInfos = sourceClueClient.findSourceLabel(clueIds).getBody();
Map<Long, ResSourceLabel> clueMap = new HashMap<>();
if (CollUtil.isNotEmpty(clueInfos) && clueInfos != null) {
for (ResSourceLabel r : clueInfos) {
clueMap.put(r.getClueId(), r);
}
}
//获取任务的基础标签
String taskName = "";
List<String> baseLabel = new ArrayList<>();
Task taskInfo = taskRepository.findByIsDistributionAndId(DefaultNumberConstants.ONE_NUMBER, id);
if (ObjectUtil.isNull(taskInfo)) {
log.error("未找到符合的任务");
// throw new BadRequestException("未找到符合的任务");
} else {
taskName = taskInfo.getTaskName();
//任务标签
baseLabel = taskInfo.getBaseLabel();
}
Collections.sort(baseLabel);
List<LinkedList<Object>> linkedLists = new ArrayList<>();
for (Long key : map.keySet()) {
List<AllCallInfo> list = map.get(key);
//获取线索名
String clueName = null;
List<String> label = new ArrayList<>();
String remark = null;
String nid = null;
if (clueMap.containsKey(key)) {
ResSourceLabel resSourceLabel = clueMap.get(key);
clueName = resSourceLabel.getName();
remark = resSourceLabel.getRemark();
nid = resSourceLabel.getNid();
label = JSONUtil.toList(JSONUtil.parseArray(resSourceLabel.getSourceLabel()), String.class);
}
//计算
LinkedList<Object> linkedList = getDownLoadTaskInfo(clueName, nid, list);
linkedList.add(remark);
for (String l : baseLabel) {
if (label.size() > 0 && label.contains(l)) {
linkedList.add("√");
} else {
linkedList.add("");
}
}
linkedLists.add(linkedList);
}
ExportExcelUtil.dynamicHeadWrite(response, linkedLists, baseLabel, taskName);
}
/**
*
*
* @param s
* @return
*/
@Override
public CommonResponse<Object> getReportByOrganize(StatisticalReportDTO s) {
String beginTime = s.getBeginTime();
String endTime = s.getEndTime();
if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) {
beginTime = DateTimeUtil.getBeginTimeByDay(DateUtil.today());
endTime = DateTimeUtil.getEndTimeByDay(DateUtil.today());
}
List<Long> ids = s.getIds();
if (ids == null || ids.size() == 0) {
ids = getOrganizedIds();
}
if (ids.size() == 0) {
return CommonResponse.createByErrorMessage("未找到组信息");
}
List<UserReport> userReports = userReportRepository.queryAllByTimeAndTeamIds(beginTime, endTime, ids);
Map<Long, UserReport> map = new HashMap<>();
//将一个组的数据合并
for (UserReport info : userReports) {
if (map.containsKey(info.getOrganizeId())) {
UserReport userReport = map.get(info.getOrganizeId());
userReport.setUsrNum(userReport.getUsrNum() + info.getUsrNum());
userReport.setTurnOnNum(userReport.getTurnOnNum() + info.getTurnOnNum());
userReport.setTurnOnRate(userReport.getTurnOnRate() + info.getTurnOnRate());
userReport.setBreatheTotalDuration(userReport.getBreatheTotalDuration() + info.getBreatheTotalDuration());
userReport.setBreatheAverageDuration(userReport.getBreatheAverageDuration() + info.getBreatheAverageDuration());
map.put(info.getOrganizeId(), userReport);
} else {
info.setMemberId(null);
info.setMemberName(null);
map.put(info.getOrganizeId(), info);
}
}
return CommonResponse.createBySuccess(map.values());
}
@Override
public void downloadOrganizeReport(HttpServletResponse response, StatisticalReportDTO s) {
String beginTime = s.getBeginTime();
String endTime = s.getEndTime();
if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) {
beginTime = DateTimeUtil.getBeginTimeByDay(DateUtil.today());
endTime = DateTimeUtil.getEndTimeByDay(DateUtil.today());
}
List<Long> ids = s.getIds();
if (s.getIds() == null || s.getIds().size() == 0) {
ids = getOrganizedIds();
}
if (ids.size() == 0) {
log.error("未找到组信息");
throw new BadRequestException(ResponseCode.USER_INFORMATION_ERROR.getDesc());
}
List<UserReport> userReports = userReportRepository.queryAllByTimeAndTeamIds(beginTime, endTime, ids);
Map<Long, UserReport> map = new HashMap<>();
for (UserReport info : userReports) {
if (map.containsKey(info.getMemberId())) {
UserReport userReport = map.get(info.getMemberId());
userReport.setUsrNum(userReport.getUsrNum() + info.getUsrNum());
userReport.setTurnOnNum(userReport.getTurnOnNum() + info.getTurnOnNum());
userReport.setTurnOnRate(userReport.getTurnOnRate() + info.getTurnOnRate());
userReport.setBreatheTotalDuration(userReport.getBreatheTotalDuration() + info.getBreatheTotalDuration());
userReport.setBreatheAverageDuration(userReport.getBreatheAverageDuration() + info.getBreatheAverageDuration());
map.put(info.getMemberId(), userReport);
} else {
map.put(info.getMemberId(), info);
}
}
List<MemberInfoVO> values = new ArrayList<>();
for (UserReport value : map.values()) {
MemberInfoVO v = new MemberInfoVO();
BeanUtil.copyProperties(value, v);
values.add(v);
}
HashMap<String, List<MemberInfoVO>> mapByTeam = new HashMap<>(8);
values.stream().collect(Collectors.groupingBy(MemberInfoVO::getOrganizeName, Collectors.toList())).forEach(mapByTeam::put);
ExportExcelUtil.exportPackByDate(response, mapByTeam, "小组统计");
}
@Override
public CommonResponse<Object> getMemberReport(String beginTime, String endTime, Long memberId) {
String begin;
String end;
if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) {
begin = DateUtil.beginOfDay(DateUtil.yesterday()).toString();
end = DateUtil.endOfDay(DateUtil.yesterday()).toString();
} else {
begin = DateTimeUtil.getBeginTimeByDay(beginTime);
end = DateTimeUtil.getEndTimeByDay(endTime);
}
if (memberId == null) {
log.error("成员id为空");
return CommonResponse.createByErrorMessage("成员id为空");
}
List<UserReport> userReports = userReportRepository.queryAllByTimeAndId(begin, end, memberId);
Map<Long, UserReport> map = new HashMap<>();
//合并同一个人的线索数据
for (UserReport info : userReports) {
if (map.containsKey(info.getMemberId())) {
UserReport userReport = map.get(info.getMemberId());
userReport.setUsrNum(userReport.getUsrNum() + info.getUsrNum());
userReport.setTurnOnNum(userReport.getTurnOnNum() + info.getTurnOnNum());
userReport.setTurnOnRate(userReport.getTurnOnRate() + info.getTurnOnRate());
userReport.setBreatheTotalDuration(userReport.getBreatheTotalDuration() + info.getBreatheTotalDuration());
userReport.setBreatheAverageDuration(userReport.getBreatheAverageDuration() + info.getBreatheAverageDuration());
map.put(info.getMemberId(), userReport);
} else {
map.put(info.getMemberId(), info);
}
}
MemberInfoVO memberInfoVO = new MemberInfoVO();
for (UserReport value : map.values()) {
if (ObjectUtil.isNotNull(value)) {
BeanUtil.copyProperties(value, memberInfoVO);
break;
}
}
return CommonResponse.createBySuccess(memberInfoVO);
}
@Override
public void downloadMemberReport(HttpServletResponse response, String beginTime, String endTime, Long memberId) {
String begin;
String end;
if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) {
begin = DateTimeUtil.getBeginTimeByDay(DateUtil.today());
end = DateTimeUtil.getEndTimeByDay(DateUtil.today());
} else {
begin = DateTimeUtil.getBeginTimeByDay(beginTime);
end = DateTimeUtil.getEndTimeByDay(endTime);
}
List<UserReport> userReports = userReportRepository.queryAllByTimeAndId(begin, end, memberId);
List<MemberInfoVO> listResult = new ArrayList<>();
for (UserReport info : userReports) {
MemberInfoVO memberInfoVO = new MemberInfoVO();
BeanUtil.copyProperties(info, memberInfoVO);
listResult.add(memberInfoVO);
}
ExportExcelUtil.downloadEasyExcel(response, MemberInfoVO.class, listResult);
}
/**
*
*/
private StatisticalReportDTO getStatisticalReportDTO(StatisticalReportDTO s) {
List<Long> ids = s.getIds();
Long userId = companyService.findById(s.getCompanyId()).getUserId();
s.setUserId(userId);
if (CollUtil.isEmpty(ids)) {
ids = new ArrayList<>();
//获取公司下5个任务id
getTaskId(ids, userId);
s.setIds(ids);
}
String beginTime = s.getBeginTime();
String endTime = s.getEndTime();
Integer type;
if (StrUtil.isBlank(beginTime) && StrUtil.isBlank(endTime)) {
endTime = DateUtil.today();
beginTime = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -6), "yyyy-MM-dd");
type = 2;
s.setBeginTime(beginTime);
s.setEndTime(endTime);
s.setType(type);
}
return s;
}
/**
* 5
*/
private void getTaskId(List<Long> ids, Long userId) {
List<Task> allByIsAndIsDistribution = taskRepository.findAllByIsAndIsDistributionAndId(DefaultNumberConstants.ONE_NUMBER, ids, userId);
if (CollUtil.isNotEmpty(allByIsAndIsDistribution)) {
int flag = 0;
for (int i = allByIsAndIsDistribution.size() - 1; i >= 0; i--) {
if (flag == 5) {
break;
}
flag += 1;
ids.add(allByIsAndIsDistribution.get(i).getId());
}
}
}
private List<Long> getOrganizedIds() {
List<Organize> allByCreateBy = organizeRepository.findAllByCreateBy(SecurityUtils.getCurrentUserId());
List<Long> ids = new ArrayList<>();
if (CollUtil.isNotEmpty(allByCreateBy)) {
int flag = 0;
for (int i = allByCreateBy.size() - 1; i >= 0; i--) {
if (flag == 5) {
break;
}
flag += 1;
ids.add(allByCreateBy.get(i).getId());
}
}
return ids;
}
/**
*
*/
private List<TaskReport> getTaskReport(String beginTime, String endTime, Integer type, List<Long> ids) {
List<TaskReport> taskReports = new ArrayList<>();
String begin;
String end;
if (CollUtil.isEmpty(ids)) {
return taskReports;
}
switch (type) {
case 2:
begin = DateTimeUtil.getBeginTimeByDay(beginTime);
end = DateTimeUtil.getEndTimeByDay(endTime);
taskReports = taskReportRepository.queryAllByTimeAndTaskIds(begin, end, ids);
break;
case 3:
int monthEnd = DateUtil.parse(endTime).month();
int monthBegin = DateUtil.parse(beginTime).month();
if (monthEnd - monthBegin > 1) {
log.error("---------接受参数类型为月。时间范围超出2个月 ");
return null;
}
begin = DateTimeUtil.getBeginTimeByMonth(beginTime);
end = DateTimeUtil.getEndTimeByMonth(endTime);
taskReports = taskReportRepository.queryAllByTimeAndTaskIds(begin, end, ids);
break;
default:
break;
}
return taskReports;
}
/**
*
*
* @param time
* @param collect
* @param list
*/
private void getMapByTime(Date time, List<TaskReport> collect, List<Map<String, Object>> list) {
Map<String, Object> mapByUsrRate = new HashMap<>(2);
double usrRate = 0;
for (TaskReport info : collect) {
int usrNum = info.getUsrNum();
long totalNum = info.getTotalNum();
usrRate += NumberUtil.div(usrNum, totalNum, 2);
}
mapByUsrRate.put("createTime", DateUtil.format(time, "yyyy-MM"));
mapByUsrRate.put("usrRate", usrRate);
list.add(mapByUsrRate);
}
private LinkedList<Object> getDownLoadTaskInfo(String clueName, String nid, List<AllCallInfo> list) {
int usrNum = list.size();
//接通数
int turnOnNum = 0;
//外呼总时长
int breatheTotalDuration = 0;
double breatheAverageDuration = 0;
double turnOnRate = 0;
for (AllCallInfo info : list) {
//接通
if (info.getStatus() == DefaultNumberConstants.TWO_NUMBER) {
turnOnNum++;
breatheTotalDuration += info.getDuration();
}
}
long memberId;
String userName = null;
if (list.size() > 0) {
memberId = list.get(0).getMemberId();
userName = getMember(memberId).getUsername();
}
if (usrNum != 0) {
//接通率
turnOnRate = NumberUtil.div(turnOnNum, usrNum, 2);
if (turnOnNum != 0) {
//平均时长
breatheAverageDuration = NumberUtil.div(breatheTotalDuration, turnOnNum, 2);
}
}
LinkedList<Object> linkedList = new LinkedList<>();
linkedList.add(clueName);
linkedList.add(userName);
linkedList.add(nid);
linkedList.add(usrNum);
linkedList.add(turnOnNum);
linkedList.add(turnOnRate);
linkedList.add(breatheTotalDuration);
linkedList.add(breatheAverageDuration);
return linkedList;
}
/**
*
*
* @param taskReports
* @return
*/
private MemberInfoVO getAllTaskInfo(List<TaskReport> taskReports) {
int usrNum = 0;
int turnOnNum = 0;
long breatheTotalDuration = 0;
double breatheAverageDuration = 0;
for (TaskReport info : taskReports) {
usrNum += info.getUsrNum();
turnOnNum += info.getTurnOnNum();
breatheTotalDuration += info.getBreatheTotalDuration();
breatheAverageDuration += info.getBreatheAverageDuration();
}
MemberInfoVO memberInfoVO = new MemberInfoVO();
memberInfoVO.setTurnOnNum(turnOnNum);
if (usrNum != 0) {
memberInfoVO.setTurnOnRate(NumberUtil.div(turnOnNum, usrNum, 2));
} else {
memberInfoVO.setTurnOnRate(0.0);
}
memberInfoVO.setUsrNum(usrNum);
memberInfoVO.setBreatheAverageDuration(breatheAverageDuration);
memberInfoVO.setBreatheTotalDuration(breatheTotalDuration);
return memberInfoVO;
}
/**
*
*/
@Cacheable(value = "user", key = "'user:' + #p0")
public User getMember(Long id) {
return userRepository.findUserById(id);
}
}

@ -1,705 +0,0 @@
package com.baiye.modules.report.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.feign.SourceClueClient;
import com.baiye.http.CommonResponse;
import com.baiye.model.vo.ResSourceLabel;
import com.baiye.modules.report.entity.dto.StatisticalReportDTO;
import com.baiye.modules.report.entity.dto.UploadTaskDTO;
import com.baiye.modules.report.entity.vo.MemberInfoVO;
import com.baiye.modules.report.service.ReportService;
import com.baiye.modules.system.domain.Organize;
import com.baiye.modules.system.domain.Task;
import com.baiye.modules.system.domain.User;
import com.baiye.modules.system.repository.OrganizeRepository;
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.util.DateTimeUtil;
import com.baiye.util.ExportExcelUtil;
import com.baiye.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author wjt
* @date 2021/12/10
*/
@Service
@Slf4j
public class ReportServiceImpl implements ReportService {
@Resource
private CallClueRepository callClueRepository;
@Resource
private AllCallInfoRepository allCallInfoRepository;
@Resource
private TaskRepository taskRepository;
@Resource
private OrganizeRepository organizeRepository;
@Resource
private UserRepository userRepository;
@Resource
private SourceClueClient sourceClueClient;
@Resource
private CompanyService companyService;
@Override
public CommonResponse<Object> getReportByAll() {
Long companyId = SecurityUtils.getCompanyId();
List<CallClueInfo> all = callClueRepository.selectByDay(DateTimeUtil.getBeginTimeByDay(DateUtil.today()), DateTimeUtil.getEndTimeByDay(DateUtil.today()), companyId);
MemberInfoVO messageInfo = getMessageInfo(DateTimeUtil.getBeginTimeByDay(DateUtil.today()), DateTimeUtil.getEndTimeByDay(DateUtil.today()), all);
return CommonResponse.createBySuccess(messageInfo);
}
@Override
public CommonResponse<Object> getReportByTask(StatisticalReportDTO s) {
StatisticalReportDTO dto = getStatisticalReportDTO(s);
List<CallClueInfo> callClueInfos = getCallClueInfos(dto.getBeginTime(), dto.getEndTime(), dto.getType(), dto.getIds());
if (callClueInfos == null) {
return CommonResponse.createByErrorMessage("请检查时间类型是否错误");
}
//以任务分组
List<HashMap<String, Object>> mapByTask = getMapByTask(dto, getGroupTask(dto.getIds(), callClueInfos));
return CommonResponse.createBySuccess(mapByTask);
}
@Override
public void downloadTaskReport(HttpServletResponse response, StatisticalReportDTO s) {
StatisticalReportDTO dto = getStatisticalReportDTO(s);
List<CallClueInfo> callClueInfos = getCallClueInfos(dto.getBeginTime(), dto.getEndTime(), dto.getType(), dto.getIds());
List<UploadTaskDTO> mapByTaskUpload = getMapByTaskUpload(dto, getGroupTask(dto.getIds(), callClueInfos));
ExportExcelUtil.downloadEasyExcel(response, UploadTaskDTO.class, mapByTaskUpload);
}
@Override
public void downloadSingleTaskReport(HttpServletResponse response, Long id) {
List<AllCallInfo> allCallInfos = allCallInfoRepository.selectClueByTaskId(id);
//以线索id分组
Map<Long, List<AllCallInfo>> map = new HashMap<>(16);
allCallInfos.stream().collect(Collectors.groupingBy(AllCallInfo::getClueId, Collectors.toList())).forEach(map::put);
//提取线索id
List<Long> clueIds = allCallInfos.stream().map(AllCallInfo::getClueId).collect(Collectors.toList());
//获取线索信息
List<ResSourceLabel> clueInfos = sourceClueClient.findSourceLabel(clueIds).getBody();
Map<Long, ResSourceLabel> clueMap = new HashMap<>();
if (CollUtil.isNotEmpty(clueInfos) && clueInfos != null) {
for (ResSourceLabel r : clueInfos) {
clueMap.put(r.getClueId(), r);
}
}
//获取任务的基础标签
String taskName = "";
List<String> baseLabel = new ArrayList<>();
Task taskInfo = taskRepository.findByIsDistributionAndId(DefaultNumberConstants.ONE_NUMBER, id);
if (ObjectUtil.isNull(taskInfo)) {
log.error("未找到符合的任务");
// throw new BadRequestException("未找到符合的任务");
} else {
taskName = taskInfo.getTaskName();
//任务标签
baseLabel = taskInfo.getBaseLabel();
}
Collections.sort(baseLabel);
List<LinkedList<Object>> linkedLists = new ArrayList<>();
for (Long key : map.keySet()) {
List<AllCallInfo> list = map.get(key);
//获取线索名
String clueName = null;
List<String> label = new ArrayList<>();
String remark = null;
if (clueMap.containsKey(key)) {
ResSourceLabel resSourceLabel = clueMap.get(key);
clueName = resSourceLabel.getName();
remark = resSourceLabel.getRemark();
label = JSONUtil.toList(JSONUtil.parseArray(resSourceLabel.getSourceLabel()), String.class);
}
LinkedList<Object> linkedList = getDownLoadTaskInfo(clueName, list);
linkedList.add(remark);
for (String l : baseLabel) {
if (label.size() > 0 && label.contains(l)) {
linkedList.add("√");
} else {
linkedList.add("");
}
}
linkedLists.add(linkedList);
}
ExportExcelUtil.dynamicHeadWrite(response, linkedLists, baseLabel, taskName);
}
@Override
public CommonResponse<Object> reportSingleTaskReport(Long id) {
List<MemberInfoVO> listVo = new ArrayList<>();
List<AllCallInfo> allCallInfos = allCallInfoRepository.selectClueByTaskId(id);
//以线索id分组
Map<Long, List<AllCallInfo>> map = new HashMap<>(16);
allCallInfos.stream().collect(Collectors.groupingBy(AllCallInfo::getClueId, Collectors.toList())).forEach(map::put);
//提取线索id
List<Long> clueIds = allCallInfos.stream().map(AllCallInfo::getClueId).collect(Collectors.toList());
//获取线索信息
List<ResSourceLabel> clueInfos = sourceClueClient.findSourceLabel(clueIds).getBody();
Map<Long, ResSourceLabel> clueMap = new HashMap<>();
if (CollUtil.isNotEmpty(clueInfos) && clueInfos != null) {
for (ResSourceLabel r : clueInfos) {
clueMap.put(r.getClueId(), r);
}
}
for (AllCallInfo info : allCallInfos) {
String clueName = "";
if (clueMap.containsKey(info.getClueId())) {
ResSourceLabel resSourceLabel = clueMap.get(info.getClueId());
clueName = resSourceLabel.getName();
}
MemberInfoVO reportTaskInfo = getReportTaskInfo(info.getClueId(), clueName, map.get(info.getClueId()));
listVo.add(reportTaskInfo);
}
return CommonResponse.createBySuccess(listVo);
}
private MemberInfoVO getReportTaskInfo(Long clueId, String clueName, List<AllCallInfo> list) {
int usrNum = list.size();
//接通数
int turnOnNum = 0;
//外呼总时长
int breatheTotalDuration = 0;
double breatheAverageDuration = 0;
double turnOnRate = 0;
for (AllCallInfo info : list) {
//接通
if (info.getStatus() == DefaultNumberConstants.TWO_NUMBER) {
turnOnNum++;
breatheTotalDuration += info.getDuration();
}
}
if (usrNum != 0) {
//接通率
turnOnRate = NumberUtil.div(turnOnNum, usrNum, 2);
if (turnOnNum != 0) {
//平均时长
breatheAverageDuration = NumberUtil.div(breatheTotalDuration, turnOnNum, 2);
}
}
MemberInfoVO memberInfoVO = new MemberInfoVO();
memberInfoVO.setClueId(clueId);
memberInfoVO.setClueName(clueName);
memberInfoVO.setUsrNum(usrNum);
memberInfoVO.setTurnOnNum(turnOnNum);
memberInfoVO.setTurnOnRate(turnOnRate);
memberInfoVO.setBreatheTotalDuration(breatheTotalDuration);
memberInfoVO.setBreatheAverageDuration(breatheAverageDuration);
return memberInfoVO;
}
private LinkedList<Object> getDownLoadTaskInfo(String clueName, List<AllCallInfo> list) {
int usrNum = list.size();
//接通数
int turnOnNum = 0;
//外呼总时长
int breatheTotalDuration = 0;
double breatheAverageDuration = 0;
double turnOnRate = 0;
for (AllCallInfo info : list) {
//接通
if (info.getStatus() == DefaultNumberConstants.TWO_NUMBER) {
turnOnNum++;
breatheTotalDuration += info.getDuration();
}
}
long memberId;
String userName = null;
if (list.size() > 0) {
memberId = list.get(0).getMemberId();
userName = getMember(memberId).getUsername();
}
if (usrNum != 0) {
//接通率
turnOnRate = NumberUtil.div(turnOnNum, usrNum, 2);
if (turnOnNum != 0) {
//平均时长
breatheAverageDuration = NumberUtil.div(breatheTotalDuration, turnOnNum, 2);
}
}
LinkedList<Object> linkedList = new LinkedList<>();
linkedList.add(clueName);
linkedList.add(userName);
linkedList.add(usrNum);
linkedList.add(turnOnNum);
linkedList.add(turnOnRate);
linkedList.add(breatheTotalDuration);
linkedList.add(breatheAverageDuration);
return linkedList;
}
@Override
public CommonResponse<Object> getReportByOrganize(StatisticalReportDTO s) {
String beginTime = s.getBeginTime();
String endTime = s.getEndTime();
if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) {
beginTime = DateTimeUtil.getBeginTimeByDay(DateUtil.today());
endTime = DateTimeUtil.getEndTimeByDay(DateUtil.today());
} else {
beginTime = DateTimeUtil.getBeginTimeByDay(beginTime);
endTime = DateTimeUtil.getEndTimeByDay(endTime);
}
//按时间和组id查询拨打线索记录
List<CallClueInfo> callClueInfos = callClueRepository.selectAllByTimeAndTeamId(beginTime, endTime, s.getIds(), s.getCompanyId());
Map<Long, List<CallClueInfo>> map = new HashMap<>(16);
callClueInfos.stream().collect(Collectors.groupingBy(CallClueInfo::getTeamId, Collectors.toList())).forEach(map::put);
List<MemberInfoVO> memberInfoVos = new ArrayList<>();
for (long key : map.keySet()) {
List<CallClueInfo> list = map.get(key);
String organizationName = null;
if (CollUtil.isNotEmpty(list)) {
Long organizeId = list.get(0).getTeamId();
Organize organizeById = getOrganize(organizeId);
if (ObjectUtil.isNotNull(organizeById)) {
organizationName = organizeById.getOrganizeName();
}
}
MemberInfoVO messageInfo = getMessageInfo(beginTime, endTime, list);
messageInfo.setOrganizeName(organizationName);
memberInfoVos.add(messageInfo);
}
return CommonResponse.createBySuccess(memberInfoVos);
}
@Override
public void downloadOrganizeReport(HttpServletResponse response, StatisticalReportDTO s) {
String beginTime = s.getBeginTime();
String endTime = s.getEndTime();
if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) {
beginTime = DateTimeUtil.getBeginTimeByDay(DateUtil.today());
endTime = DateTimeUtil.getEndTimeByDay(DateUtil.today());
} else {
beginTime = DateTimeUtil.getBeginTimeByDay(beginTime);
endTime = DateTimeUtil.getEndTimeByDay(endTime);
}
//按时间和组id查询拨打线索记录
List<CallClueInfo> callClueInfos = callClueRepository.selectAllByTimeAndTeamId(beginTime, endTime, s.getIds(), s.getCompanyId());
//按人分组
Map<Long, List<CallClueInfo>> mapByMember = new HashMap<>(16);
callClueInfos.stream().collect(Collectors.groupingBy(CallClueInfo::getMemberId, Collectors.toList())).forEach(mapByMember::put);
List<MemberInfoVO> memberInfoVos = new ArrayList<>();
for (long key : mapByMember.keySet()) {
//每个人的数据
List<CallClueInfo> list = mapByMember.get(key);
User userById = getMember(key);
String userName = null;
if (ObjectUtil.isNotNull(userById)) {
userName = userById.getUsername();
}
String organizationName = null;
if (CollUtil.isNotEmpty(list)) {
Long organizeId = list.get(0).getTeamId();
Organize organizeById = getOrganize(organizeId);
if (ObjectUtil.isNotNull(organizeById)) {
organizationName = organizeById.getOrganizeName();
}
}
MemberInfoVO messageInfo = getMessageInfo(beginTime, endTime, list);
messageInfo.setOrganizeName(organizationName);
messageInfo.setMemberName(userName);
messageInfo.setCreateTime(beginTime + "至" + endTime);
memberInfoVos.add(messageInfo);
}
HashMap<String, List<MemberInfoVO>> mapByTeam = new HashMap<>(8);
memberInfoVos.stream().collect(Collectors.groupingBy(MemberInfoVO::getOrganizeName, Collectors.toList())).forEach(mapByTeam::put);
ExportExcelUtil.exportPackByDate(response, mapByTeam, "小组统计");
}
@Override
public CommonResponse<Object> getMemberReport(String beginTime, String endTime, Long memberId) {
String begin;
String end;
if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) {
begin = DateTimeUtil.getBeginTimeByDay(DateUtil.today());
end = DateTimeUtil.getEndTimeByDay(DateUtil.today());
} else {
begin = DateTimeUtil.getBeginTimeByDay(beginTime);
end = DateTimeUtil.getEndTimeByDay(endTime);
}
if (memberId == null) {
log.error("成员id为空");
return CommonResponse.createByErrorMessage("成员id为空");
}
List<CallClueInfo> callClueInfos = callClueRepository.selectAllByTimeAndMemberId(begin, end, memberId);
MemberInfoVO messageInfo = getMessageInfo(begin, end, callClueInfos);
messageInfo.setMemberId(memberId);
return CommonResponse.createBySuccess(messageInfo);
}
@Override
public void downloadMemberReport(HttpServletResponse response, String beginTime, String endTime, Long memberId) {
String begin;
String end;
if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) {
begin = DateTimeUtil.getBeginTimeByDay(DateUtil.today());
end = DateTimeUtil.getEndTimeByDay(DateUtil.today());
} else {
begin = DateTimeUtil.getBeginTimeByDay(beginTime);
end = DateTimeUtil.getEndTimeByDay(endTime);
}
if (memberId == null) {
log.error("成员id为空");
return;
}
List<CallClueInfo> callClueInfos = callClueRepository.selectAllByTimeAndMemberId(begin, end, memberId);
if (CollUtil.isEmpty(callClueInfos)) {
return;
}
User userById = getMember(memberId);
String userName = null;
if (ObjectUtil.isNotNull(userById)) {
userName = userById.getUsername();
}
String organizationName = null;
Long organizeId = callClueInfos.get(0).getTeamId();
Organize organizeById = getOrganize(organizeId);
if (ObjectUtil.isNotNull(organizeById)) {
organizationName = organizeById.getOrganizeName();
}
//按时间分组
HashMap<String, List<CallClueInfo>> clues = getGroupByTime(begin, end, callClueInfos, 2);
List<MemberInfoVO> list = new ArrayList<>();
for (String key : clues.keySet()) {
List<CallClueInfo> clueInfos = clues.get(key);
if (CollUtil.isEmpty(clueInfos)) {
continue;
}
MemberInfoVO messageInfo = getMessageInfo(begin, end, clueInfos);
messageInfo.setMemberName(userName);
messageInfo.setOrganizeName(organizationName);
messageInfo.setCreateTime(key);
list.add(messageInfo);
}
ExportExcelUtil.downloadEasyExcel(response, MemberInfoVO.class, list);
}
/**
*
*/
private StatisticalReportDTO getStatisticalReportDTO(StatisticalReportDTO s) {
List<Long> ids = s.getIds();
Long userId = companyService.findById(s.getCompanyId()).getUserId();
s.setUserId(userId);
if (CollUtil.isEmpty(ids)) {
ids = new ArrayList<>();
getTaskId(ids, userId);
s.setIds(ids);
}
String beginTime = s.getBeginTime();
String endTime = s.getEndTime();
Integer type;
if (StrUtil.isBlank(beginTime) && StrUtil.isBlank(endTime)) {
endTime = DateUtil.today();
beginTime = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -7), "yyyy-MM-dd");
type = 2;
s.setBeginTime(beginTime);
s.setEndTime(endTime);
s.setType(type);
}
return s;
}
/**
*
*/
private List<CallClueInfo> getCallClueInfos(String beginTime, String endTime, Integer type, List<Long> ids) {
List<CallClueInfo> callClueInfos = new ArrayList<>();
String begin;
String end;
switch (type) {
case 2:
begin = DateTimeUtil.getBeginTimeByDay(beginTime);
end = DateTimeUtil.getEndTimeByDay(endTime);
callClueInfos = callClueRepository.selectAllByTimeAndTaskId(begin, end, ids);
break;
case 3:
int monthEnd = DateUtil.parse(endTime).month();
int monthBegin = DateUtil.parse(beginTime).month();
if (monthEnd - monthBegin > 1) {
log.error("---------接受参数类型为月。时间范围超出2个月 ");
return null;
}
begin = DateTimeUtil.getBeginTimeByMonth(beginTime);
end = DateTimeUtil.getEndTimeByMonth(endTime);
callClueInfos = callClueRepository.selectAllByTimeAndTaskId(begin, end, ids);
break;
case 1:
int betweenHour = (int) DateUtil.between(DateUtil.parse(beginTime), DateUtil.parse(endTime), DateUnit.HOUR);
if (betweenHour > 48) {
log.error("---------接受参数类型为小时。时间范围超出48小时 ");
return null;
}
begin = DateTimeUtil.getBeginTimeByHour(beginTime);
end = DateTimeUtil.getEndTimeByHour(endTime);
callClueInfos = callClueRepository.selectAllByTimeAndTaskId(begin, end, ids);
break;
default:
break;
}
return callClueInfos;
}
/**
* idkey
*/
private HashMap<Long, List<CallClueInfo>> getGroupTask(List<Long> ids, List<CallClueInfo> callClueInfos) {
HashMap<Long, List<CallClueInfo>> map = new HashMap<>();
for (long id : ids) {
List<CallClueInfo> collect = callClueInfos.stream().filter(c -> c.getTaskId() != null && c.getTaskId() == id).collect(Collectors.toList());
if (CollUtil.isEmpty(collect)) {
map.put(id, new ArrayList<>());
} else {
map.put(id, collect);
}
}
return map;
}
/**
* key
*/
private HashMap<String, List<CallClueInfo>> getGroupByTime(String beginTime, String endTime, List<CallClueInfo> callClueInfos, Integer type) {
Date begin = DateUtil.parse(beginTime);
Date end = DateUtil.parse(endTime);
HashMap<String, List<CallClueInfo>> map = new HashMap<>();
switch (type) {
case 2:
int betweenDay = (int) DateUtil.between(begin, end, DateUnit.DAY);
for (int i = 0; i <= betweenDay; i++) {
Date dateTime = DateUtil.offsetDay(begin, i);
List<CallClueInfo> collect = callClueInfos.stream().filter(c -> DateTimeUtil.betweenByDay(dateTime, c.getCreateTime())).collect(Collectors.toList());
map.put(DateTimeUtil.getTimeType(dateTime, type), collect);
}
break;
case 3:
List<CallClueInfo> collect = callClueInfos.stream().filter(c -> DateTimeUtil.betweenByMonth(c.getCreateTime(), begin)).collect(Collectors.toList());
List<CallClueInfo> collect1 = callClueInfos.stream().filter(c -> DateTimeUtil.betweenByMonth(c.getCreateTime(), end)).collect(Collectors.toList());
map.put(DateTimeUtil.getTimeType(begin, type), collect);
map.put(DateTimeUtil.getTimeType(end, type), collect1);
break;
case 1:
int betweenHour = (int) DateUtil.between(begin, end, DateUnit.HOUR);
for (int i = 0; i <= betweenHour; i++) {
Date dateTime = DateUtil.offsetHour(begin, i);
List<CallClueInfo> collectByHour = callClueInfos.stream().filter(c ->
DateTimeUtil.betweenByHour(dateTime, c.getCreateTime())
).collect(Collectors.toList());
map.put(DateTimeUtil.getTimeType(dateTime, type), collectByHour);
}
break;
default:
return map;
}
return map;
}
/**
* 5
*/
private void getTaskId(List<Long> ids, Long userId) {
List<Task> allByIsAndIsDistribution = taskRepository.findAllByIsAndIsDistributionAndId(DefaultNumberConstants.ONE_NUMBER, ids, userId);
if (CollUtil.isNotEmpty(allByIsAndIsDistribution)) {
int flag = 0;
for (int i = allByIsAndIsDistribution.size() - 1; i >= 0; i--) {
if (flag == 5) {
break;
}
flag += 1;
ids.add(allByIsAndIsDistribution.get(i).getId());
}
}
}
/**
* 使
*/
private List<HashMap<String, Object>> getMapByTask(StatisticalReportDTO s, Map<Long, List<CallClueInfo>> mapByTask) {
List<HashMap<String, Object>> listMap = new ArrayList<>();
List<Task> tasks = taskRepository.findAllByIsAndIsDistributionAndId(DefaultNumberConstants.ONE_NUMBER, s.getIds(), s.getUserId());
//按id分组
Map<Long, Task> taskInfos = new HashMap<>(8);
for (Task info : tasks) {
taskInfos.put(info.getId(), info);
}
for (Long key : mapByTask.keySet()) {
HashMap<String, Object> mapVo = new HashMap<String, Object>(16);
//按时间分
HashMap<String, List<CallClueInfo>> mapByTime = getGroupByTime(s.getBeginTime(), s.getEndTime(), mapByTask.get(key), s.getType());
int total = taskInfos.get(key).getTotalNumber();
String taskName = taskInfos.get(key).getTaskName();
double usrRate = 0;
ArrayList list = new ArrayList();
for (String keyId : mapByTime.keySet()) {
Map<String, Object> mapByUsrRate = new HashMap<>();
//使用数
long count = mapByTime.get(keyId).stream().filter(c -> c.getStatus() != 0).count();
if (total != 0) {
//使用率
usrRate = NumberUtil.div(count, total, 2);
}
mapByUsrRate.put("usrRate", usrRate);
mapByUsrRate.put("createTime", keyId);
list.add(mapByUsrRate);
}
list.sort(new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
String time1 = (String) o1.get("createTime");
String time2 = (String) o2.get("createTime");
return time1.compareTo(time2);
}
});
mapVo.put("taskName", taskName);
mapVo.put("data", list);
listMap.add(mapVo);
}
return listMap;
}
/**
*
*/
private List<UploadTaskDTO> getMapByTaskUpload(StatisticalReportDTO s, Map<Long, List<CallClueInfo>> mapByTask) {
List<UploadTaskDTO> list = new ArrayList<>();
List<Task> tasks = taskRepository.findAllByIsAndIsDistributionAndId(DefaultNumberConstants.ONE_NUMBER, s.getIds(), s.getUserId());
//按id分组
Map<Long, Task> taskInfos = new HashMap<>(8);
for (Task info : tasks) {
taskInfos.put(info.getId(), info);
}
for (Long key : mapByTask.keySet()) {
Task task = taskInfos.get(key);
String taskName = task.getTaskName();
List<String> baseLabel = task.getBaseLabel();
StringBuilder label = new StringBuilder();
if (baseLabel.size() > 0) {
for (int i = 0; i < baseLabel.size(); i++) {
if (i == baseLabel.size() - 1) {
label.append(baseLabel.get(i));
} else {
label.append(baseLabel.get(i)).append(",");
}
}
}
List<CallClueInfo> clueInfos = mapByTask.get(key);
if (CollUtil.isEmpty(clueInfos)) {
continue;
}
MemberInfoVO messageInfo = getMessageInfo(s.getBeginTime(), s.getEndTime(), clueInfos);
UploadTaskDTO upload = new UploadTaskDTO();
BeanUtil.copyProperties(messageInfo, upload);
upload.setTaskName(taskName);
upload.setLabel(label.toString());
upload.setCreateTime(s.getBeginTime() + "至" + s.getEndTime());
list.add(upload);
}
return list;
}
/**
* 线
*/
private MemberInfoVO getMessageInfo(String begin, String end, List<CallClueInfo> callClueInfos) {
int usrNum = 0;
int turnOnNum = 0;
double turnOnRate = 0.00;
int breatheTotalDuration = 0;
double breatheAverageDuration = 0;
if (CollUtil.isNotEmpty(callClueInfos)) {
//使用数
usrNum = callClueInfos.size();
for (CallClueInfo info : callClueInfos) {
//接通时才会有通话时长
long clueId = info.getClueId();
List<AllCallInfo> doubleCallInfo = allCallInfoRepository.selectAllByTimeAndClueId(begin, end, clueId);
//统计通话时长
int doubleClueTime = 0;
if (CollUtil.isNotEmpty(doubleCallInfo)) {
// for (AllCallInfo ai : doubleCallInfo) {
// if (ai.getStatus() == DefaultNumberConstants.TWO_NUMBER) {
// doubleClueTime += ai.getDuration();
// }
// }
// doubleClueTime = doubleCallInfo.stream().mapToInt(AllCallInfo::getDuration).sum();
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;
}
/**
*
*/
@Cacheable(value = "organize", key = "'organize:' + #p0")
public Organize getOrganize(Long id) {
return organizeRepository.findOrganizeById(id);
}
/**
*
*/
@Cacheable(value = "user", key = "'user:' + #p0")
public User getMember(Long id) {
return userRepository.findUserById(id);
}
}

@ -6,6 +6,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Set;
/**
@ -26,5 +28,7 @@ public interface OrganizeRepository extends JpaRepository<Organize, Long>, JpaSp
@Query(value = "select t from Organize t where t.id =?1")
Organize findOrganizeById(Long id);
List<Organize> findAllByCreateBy(Long id);
Set<Organize> findByCreateBy(Long currentUserId);
}

@ -1,6 +1,8 @@
package com.baiye.modules.system.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.baiye.exception.BadRequestException;
import com.baiye.feign.SourceClueClient;
import com.baiye.modules.system.domain.OrganizeUser;
import com.baiye.modules.system.domain.Task;
@ -8,7 +10,12 @@ import com.baiye.modules.system.domain.User;
import com.baiye.modules.system.repository.*;
import com.baiye.modules.system.service.CompanyService;
import com.baiye.modules.system.service.InternalUseService;
import com.baiye.modules.telemarkting.dao.AllCallInfoRepository;
import com.baiye.modules.telemarkting.dao.CallClueRepository;
import com.baiye.modules.telemarkting.dao.ExtensionNumberRepository;
import com.baiye.modules.telemarkting.dao.ExtensionUserRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -20,6 +27,7 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@Slf4j
public class InternalUseServiceImpl implements InternalUseService {
private final UserRepository userRepository;
@ -29,6 +37,10 @@ public class InternalUseServiceImpl implements InternalUseService {
private final TaskRepository taskRepository;
private final TaskOrganizeRepository taskOrganizeRepository;
private final SourceClueClient sourceClueClient;
private final CallClueRepository callClueRepository;
private final AllCallInfoRepository allCallInfoRepository;
private final ExtensionNumberRepository extensionNumberRepository;
private final ExtensionUserRepository extensionUserRepository;
@Override
@Transactional(rollbackFor = Exception.class)
@ -36,7 +48,10 @@ public class InternalUseServiceImpl implements InternalUseService {
List<User> userList = userRepository.findByCompanyId(companyId);
userRepository.deleteByCompanyId(companyId);
companyService.deleteCompanyByCompanyId(companyId);
//删除资源呼叫记录
callClueRepository.deleteByCompanyId(companyId);
//删除分机号
extensionNumberRepository.deleteByCompanyId(companyId);
//删除组关系、任务、资源
List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList());
delCompanyAll(userIds);
@ -44,7 +59,7 @@ public class InternalUseServiceImpl implements InternalUseService {
@Transactional(rollbackFor = Exception.class)
public void delCompanyAll(List<Long> userIds){
public void delCompanyAll(List<Long> userIds) {
List<OrganizeUser> organizeUserList = new ArrayList<>();
Set<Long> taskIds = new HashSet<>();
//1、删除组-用户关系
@ -54,7 +69,7 @@ public class InternalUseServiceImpl implements InternalUseService {
organizeUserRepository.deleteByUserId(userId);
//3、查询所有涉及的任务id
List<Task> taskList = taskRepository.findByCreateBy(userId);
if (CollUtil.isNotEmpty(taskList)){
if (CollUtil.isNotEmpty(taskList)) {
taskIds = taskList.stream().map(Task::getId).collect(Collectors.toSet());
}
}
@ -68,7 +83,7 @@ public class InternalUseServiceImpl implements InternalUseService {
}
//4、删除任务和任务-组关系表
if (CollUtil.isNotEmpty(taskIds)){
if (CollUtil.isNotEmpty(taskIds)) {
for (Long taskId : taskIds) {
taskRepository.deleteById(taskId);
taskOrganizeRepository.deleteByTaskId(taskId);
@ -76,6 +91,16 @@ public class InternalUseServiceImpl implements InternalUseService {
}
//5、删除资源、资源记录、资源任务关联表
sourceClueClient.delClueAll(taskIds);
try {
sourceClueClient.delClueAll(taskIds);
} catch (Exception e) {
log.error("Method 【delCompanyAll】 error{},time:{} ", e.getMessage(), DateUtil.now());
throw new BadRequestException("删除资源、资源记录、资源任务关联表错误");
}
//6、删除人员的拨打记录
allCallInfoRepository.deleteByMemberId(userIds);
//7、删除人员和分机号绑定关系
extensionUserRepository.deleteByMemberId(userIds);
}
}

@ -6,10 +6,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@ -26,17 +24,13 @@ public class ExtensionNumberController {
private final ExtensionNumberService extensionNumberService;
@GetMapping("/add/extension")
@PostMapping("/add/extension")
@ApiOperation("导入分机号和外显号")
public CommonResponse<String> addNumbers(@RequestParam("minNumber") Integer minNumber,
@RequestParam("maxNumber") Integer maxNumber,
public CommonResponse<String> addNumbers(@RequestParam(value = "file") MultipartFile file,
@RequestParam("display") Long display,
@RequestParam("companyId") Long companyId
)
{
extensionNumberService.addNumbers(minNumber, maxNumber, display,companyId);
return CommonResponse.createBySuccess();
) {
return extensionNumberService.addNumbers(file, display, companyId);
}
@GetMapping("/get/extension")

@ -1,11 +1,13 @@
package com.baiye.modules.telemarkting.api;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.exception.BadRequestException;
import com.baiye.http.CommonResponse;
import com.baiye.model.dto.UserDto;
import com.baiye.model.enums.ResponseCode;
import com.baiye.modules.system.domain.Company;
import com.baiye.modules.system.domain.Organize;
@ -39,19 +41,22 @@ public class TelephoneCallController {
private final CompanyService companyService;
@PostMapping("/telephone/req")
@ApiOperation("拨打电话")
public CommonResponse<String> doubleCallReq(@Validated @RequestBody TelephoneCallReqDTO telephoneCallReqDTO) {
if (ObjectUtil.isEmpty(telephoneCallReqDTO)) {
return CommonResponse.createByError();
}
//判断账号是否到期
UserDto userDto = JSONUtil.toBean(SecurityUtils.getUser(), UserDto.class);
if (ObjectUtil.isNull(userDto) || userDto.getExpirationTime() == null || DateUtil.compare(userDto.getExpirationTime(), DateUtil.date()) < 0) {
return CommonResponse.createByErrorMessage("您的账号已到期,请续费后使用");
}
Long companyId = SecurityUtils.getCompanyId();
if (companyId != null && telephoneCallReqDTO.getTeamId() != null) {
Organize organize = organizeService.findByOrganizeId(telephoneCallReqDTO.getTeamId());
Company byId = companyService.findById(SecurityUtils.getCompanyId());
if (organize != null && byId != null) {
if (organize.getCallMode() != null) {
switch (organize.getCallMode()) {
case DefaultNumberConstants.ZERO_NUMBER:
@ -65,7 +70,7 @@ public class TelephoneCallController {
telephoneCallReqDTO.setXGroup(byId.getXGroup());
return telephoneCallService.axbDialNumber(telephoneCallReqDTO, companyId);
case DefaultNumberConstants.ONE_NUMBER:
return telephoneCallService.rollCallReq(telephoneCallReqDTO,companyId);
return telephoneCallService.rollCallReq(telephoneCallReqDTO, companyId);
default:
return CommonResponse.createByErrorMessage("未配置呼叫");
}

@ -24,16 +24,6 @@ public interface AllCallInfoRepository extends JpaRepository<AllCallInfo, Long>,
*/
AllCallInfo findBySessionId(String sessionId);
/**
*
*
* @param beginTime
* @param endTime
* @param id
* @return
*/
@Query(value = "select * from tb_call_info d where (d.create_time between ?1 and ?2) and d.clue_id = ?3", nativeQuery = true)
List<AllCallInfo> selectAllByTimeAndClueId(String beginTime, String endTime, Long id);
@Modifying
@Query(value = "update AllCallInfo d set d.status =?1 where d.sessionId = ?2")
@ -45,10 +35,11 @@ public interface AllCallInfoRepository extends JpaRepository<AllCallInfo, Long>,
* @param clueId
* @param memberId
* @param status
* @param recordFlag
* @return
*/
@Query(value = "select d from AllCallInfo d where d.clueId=?1 and d.memberId=?2 and d.status=?3")
List<AllCallInfo> findByClueIdAndMemberId(Long clueId, Long memberId, Integer status);
@Query(value = "select d from AllCallInfo d where d.clueId=?1 and d.memberId=?2 and d.status=?3 and d.recordFlag=?4")
List<AllCallInfo> findByClueIdAndMemberId(Long clueId, Long memberId, Integer status, Integer recordFlag);
/**
@ -60,4 +51,24 @@ public interface AllCallInfoRepository extends JpaRepository<AllCallInfo, Long>,
@Query(value = "select i.* from tb_call_info i left join tb_call_clue c on i.clue_id = c.clue_id where c.task_id = ?1", nativeQuery = true)
List<AllCallInfo> selectClueByTaskId(Long id);
/**
*
*
* @param beginTime
* @param endTime
* @param id
* @return
*/
@Query(value = "select * from tb_call_info d where d.create_time>=?1 and d.create_time<?2 and d.clue_id = ?3", nativeQuery = true)
List<AllCallInfo> queryAllByTime(String beginTime, String endTime, Long id);
/**
* id
*
* @param userIds
* @return
*/
@Modifying
@Query(value = "delete from tb_call_info where member_id in ?1", nativeQuery = true)
int deleteByMemberId(List<Long> userIds);
}

@ -17,48 +17,29 @@ import java.util.List;
public interface CallClueRepository extends JpaRepository<CallClueInfo, Long>, JpaSpecificationExecutor<CallClueInfo> {
/**
* 线
*
* @param beginTime
* @param endTime
* @return
* id
*/
@Query(value = "select * from tb_call_clue d where (d.create_time between ?1 and ?2) AND d.company_id = ?3", nativeQuery = true)
List<CallClueInfo> selectByDay(String beginTime, String endTime, Long companyId);
@Modifying
@Query(value = "update CallClueInfo c set c.status =?1 where c.clueId = ?2")
void updateByStatus(Integer status, Long clueId);
/**
*
* 线
*
* @param beginTime
* @param endTime
* @param id
* @return
*/
@Query(value = "select * from tb_call_clue d where (d.create_time between ?1 and ?2) and d.member_id = ?3", nativeQuery = true)
List<CallClueInfo> selectAllByTimeAndMemberId(String beginTime, String endTime, Long id);
@Query(value = "select * from tb_call_clue d where d.create_time >= ?1 and d.create_time< ?2", nativeQuery = true)
List<CallClueInfo> queryAllByTime(String beginTime, String endTime);
/**
* id
* id
*
* @param beginTime
* @param endTime
* @param id
* @param companyId
* @return
*/
@Query(value = "select * from tb_call_clue d where (d.create_time between ?1 and ?2) and (coalesce (?3,null) is null or d.team_id in (?3)) and d.company_id = ?4", nativeQuery = true)
List<CallClueInfo> selectAllByTimeAndTeamId(String beginTime, String endTime, List<Long> id, Long companyId);
/**
* id
*/
@Query(value = "select * from tb_call_clue d where (d.create_time between ?1 and ?2) and (coalesce (?3,null) is null or d.task_id in (?3))", nativeQuery = true)
List<CallClueInfo> selectAllByTimeAndTaskId(String beginTime, String endTime, List<Long> id);
/**
* id
*/
@Modifying
@Query(value = "update CallClueInfo c set c.status =?1 where c.clueId = ?2")
void updateByStatus(Integer status, Long clueId);
@Query(value = "delete from CallClueInfo where companyId = ?1")
int deleteByCompanyId(Long companyId);
}

@ -35,4 +35,13 @@ public interface ExtensionNumberRepository extends JpaRepository<ExtensionNumber
@Modifying
@Query(value = "update ExtensionNumber c set c.status =?1 where c.number in ?2")
void updateByNumber(Integer status, List<Integer> number);
/**
* id
* @param companyId
* @return
*/
@Modifying
@Query(value = "delete from ExtensionNumber where companyId = ?1")
int deleteByCompanyId(Long companyId);
}

@ -3,6 +3,7 @@ package com.baiye.modules.telemarkting.dao;
import com.baiye.modules.telemarkting.entity.ExtensionUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@ -21,4 +22,14 @@ public interface ExtensionUserRepository extends JpaRepository<ExtensionUser, Lo
void deleteByOrganizeId(Long organizeId);
List<ExtensionUser> findByAndOrganizeId(Long organizationId);
/**
* id
*
* @param userIds
* @return
*/
@Modifying
@Query(value = "delete from tb_extension_user where member_id in ?1", nativeQuery = true)
int deleteByMemberId(List<Long> userIds);
}

@ -13,7 +13,6 @@ import com.baiye.modules.telemarkting.entity.dto.TelephoneCallReqDTO;
import com.baiye.modules.telemarkting.entity.dto.TelephoneCallStopDTO;
import com.baiye.modules.telemarkting.entity.dto.TelephoneCallSystemDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@ -49,21 +48,30 @@ public class DoubleCallReq {
doubleCallSystemDTO.setCdrUrl(cdrUrl);
doubleCallSystemDTO.setStatusUrl(statusUrl);
log.info("请求对象:{}", JSONUtil.toJsonPrettyStr(doubleCallSystemDTO));
HttpResponse httpResponse = sendCallReq(JSONUtil.toJsonPrettyStr(doubleCallSystemDTO), reqUrl);
if (httpResponse.isOk()) {
DoubleCallResponse doubleCallResponse = JSONUtil
.toBean(httpResponse.body(), DoubleCallResponse.class);
if (String.valueOf
(DefaultNumberConstants.ZERO_NUMBER)
.equals(doubleCallResponse.getResult())) {
return doubleCallResponse.getSessionId();
//设置重试机制
int count = 0;
int flag = 3;
while (count <= flag) {
try {
HttpResponse httpResponse = sendCallReq(JSONUtil.toJsonPrettyStr(doubleCallSystemDTO), reqUrl);
log.info("返回值:{}", httpResponse);
DoubleCallResponse doubleCallResponse = JSONUtil.toBean(httpResponse.body(), DoubleCallResponse.class);
if (String.valueOf(DefaultNumberConstants.ZERO_NUMBER).equals(doubleCallResponse.getResult())) {
return doubleCallResponse.getSessionId();
} else {
count++;
log.error("请求失败,response==={}", doubleCallResponse.getReason());
Thread.sleep(5000);
}
} catch (Exception e) {
log.error("method【reqTask】 double_call error {}", e.getMessage());
e.printStackTrace();
}
throw new BadRequestException
(StringUtils.isNotBlank(doubleCallResponse.getReason()) ?
doubleCallResponse.getReason()
: ResponseCode.CALL_ERROR.getDesc());
}
throw new BadRequestException(ResponseCode.CALL_ERROR.getDesc());
}
public Boolean stopReq(TelephoneCallStopDTO telephoneCallStopDTO) {

@ -14,7 +14,6 @@ import com.baiye.model.enums.ResponseCode;
import com.baiye.modules.telemarkting.entity.dto.RollCallSystemDTO;
import com.baiye.modules.telemarkting.entity.dto.TelephoneCallReqDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@ -58,20 +57,29 @@ public class RollCallReq {
rollCallSystemDTO.setDisplay_caller(String.valueOf(doubleCallReq.getDisplay()));
log.info("请求对象:{}", BeanUtil.beanToMap(rollCallSystemDTO));
String httpResponse = sendCallReq(BeanUtil.beanToMap(rollCallSystemDTO), reqUrl, authorization);
log.info("返回值为 {}", httpResponse);
RollCallResponse doubleCallResponse = JSONUtil
.toBean(httpResponse, RollCallResponse.class);
if (String.valueOf
(DefaultNumberConstants.ZERO_NUMBER)
.equals(doubleCallResponse.getResult())) {
return doubleCallResponse.getReqid();
//设置重试机制
int count = 0;
int flag = 3;
while (count <= flag) {
try {
String httpResponse = sendCallReq(BeanUtil.beanToMap(rollCallSystemDTO), reqUrl, authorization);
log.info("返回值为 {}", httpResponse);
RollCallResponse doubleCallResponse = JSONUtil.toBean(httpResponse, RollCallResponse.class);
if (String.valueOf
(DefaultNumberConstants.ZERO_NUMBER)
.equals(doubleCallResponse.getResult())) {
return doubleCallResponse.getReqid();
} else {
count++;
log.error("请求失败,response==={}", doubleCallResponse.getReason());
Thread.sleep(5000);
}
} catch (Exception e) {
log.error("method【reqTask】 roll_call error {}", e.getMessage());
e.printStackTrace();
}
}
throw new BadRequestException
(StringUtils.isNotBlank(doubleCallResponse.getReason()) ?
doubleCallResponse.getReason()
: ResponseCode.CALL_ERROR.getDesc());
throw new BadRequestException(ResponseCode.CALL_ERROR.getDesc());
}
private String sendCallReq(Map<String, Object> json, String url, String authorization) {

@ -3,18 +3,21 @@ package com.baiye.modules.telemarkting.service;
import com.baiye.http.CommonResponse;
import com.baiye.modules.telemarkting.entity.ExtensionNumber;
import org.springframework.web.multipart.MultipartFile;
/**
* @author wujingtao
* @date 2022/02/14
*/
public interface ExtensionNumberService {
void addNumbers(Integer minNumber, Integer maxNumber, Long display, Long companyId);
CommonResponse<String> addNumbers(MultipartFile file, Long display, Long companyId);
ExtensionNumber getExtension(Long memberId);
/**
*
*
* @param organizeId
* @param memberId
* @return
@ -23,6 +26,7 @@ public interface ExtensionNumberService {
/**
*
*
* @param organizeId
*/
void unbindExtension(Long organizeId);

@ -1,6 +1,8 @@
package com.baiye.modules.telemarkting.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.exception.BadRequestException;
import com.baiye.http.CommonResponse;
@ -16,10 +18,12 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@ -37,10 +41,31 @@ public class ExtensionNumberServiceImpl implements ExtensionNumberService {
private UserRepository userRepository;
@Override
public void addNumbers(Integer minNumber, Integer maxNumber, Long display, Long companyId) {
List<ExtensionNumber> numbers = getNumbers(minNumber, maxNumber, display, companyId);
extensionNumberRepository.saveAll(numbers);
public CommonResponse<String> addNumbers(MultipartFile file, Long display, Long companyId) {
List<ExtensionNumber> list = new ArrayList<>();
try {
int lastIndexOf = Objects.requireNonNull(file.getOriginalFilename()).lastIndexOf(".");
String nameFormat = file.getOriginalFilename().substring(lastIndexOf + 1);
if ("xlsx".equals(nameFormat) || "xls".equals(nameFormat)) {
ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
List<List<Object>> read = reader.read(0, reader.getRowCount());
for (List<Object> objects : read) {
String number = String.valueOf(objects.get(0));
ExtensionNumber extensionNumber = new ExtensionNumber();
extensionNumber.setNumber(Integer.valueOf(number));
extensionNumber.setDisplay(display);
extensionNumber.setCompanyId(companyId);
list.add(extensionNumber);
}
}
} catch (Exception e) {
log.error("读取文件错误:{}", e.getMessage());
return CommonResponse.createByErrorMessage("读取文件错误");
}
if (list.size() > 0) {
extensionNumberRepository.saveAll(list);
}
return CommonResponse.createBySuccess();
}
@Override
@ -91,17 +116,4 @@ public class ExtensionNumberServiceImpl implements ExtensionNumberService {
extensionUserRepository.deleteByOrganizeId(organizeId);
}
}
private List<ExtensionNumber> getNumbers(Integer minNumber, Integer maxNumber, Long display, Long companyId) {
List<ExtensionNumber> list = new ArrayList<>();
for (int i = minNumber; i <= maxNumber; i++) {
ExtensionNumber extensionNumber = new ExtensionNumber();
extensionNumber.setNumber(i);
extensionNumber.setDisplay(display);
extensionNumber.setCompanyId(companyId);
list.add(extensionNumber);
}
return list;
}
}

@ -2,13 +2,18 @@ package com.baiye.modules.telemarkting.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.exception.BadRequestException;
import com.baiye.feign.SourceClueClient;
import com.baiye.http.CommonResponse;
import com.baiye.model.dto.SendWebSocketDTO;
import com.baiye.model.enums.CallStatusEnum;
import com.baiye.modules.system.domain.Clue;
import com.baiye.modules.telemarkting.dao.AllCallInfoRepository;
@ -23,6 +28,8 @@ import com.baiye.modules.telemarkting.httpRequest.AxbRequest;
import com.baiye.modules.telemarkting.httpRequest.DoubleCallReq;
import com.baiye.modules.telemarkting.httpRequest.RollCallReq;
import com.baiye.modules.telemarkting.service.TelephoneCallService;
import com.baiye.socket.WebSocketServer;
import com.baiye.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@ -57,12 +64,21 @@ 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) {
String requestId = RandomUtil.randomString(10);
doubleCallReq.setRequestId(requestId);
Clue body = sourceClueClient.queryDetails(Long.parseLong(doubleCallReq.getUserData())).getBody();
Clue body;
try {
body = sourceClueClient.queryDetails(Long.parseLong(doubleCallReq.getUserData())).getBody();
} catch (Exception e) {
log.error("Method 【doubleCallReq】 query Clue details error{},time:{} ", e.getMessage(), DateUtil.now());
throw new BadRequestException("查询线索详情错误");
}
if (ObjectUtil.isNull(body) || StrUtil.isEmpty(body.getNid())) {
return CommonResponse.createByErrorMessage("未获取到号码");
}
@ -133,7 +149,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
log.error("参数不能为空clueId:{} ,memberId:{}", clueId, memberId);
return CommonResponse.createByErrorMessage("参数不能为空");
}
List<AllCallInfo> calls = allCallInfoRepository.findByClueIdAndMemberId(clueId, memberId, DefaultNumberConstants.TWO_NUMBER);
List<AllCallInfo> calls = allCallInfoRepository.findByClueIdAndMemberId(clueId, memberId, DefaultNumberConstants.TWO_NUMBER, DefaultNumberConstants.ONE_NUMBER);
List<CallRecordsVO> list = new ArrayList<>();
if (CollUtil.isNotEmpty(calls)) {
for (AllCallInfo info : calls) {
@ -149,7 +165,14 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
@Override
public CommonResponse<String> axbDialNumber(TelephoneCallReqDTO doubleCallReq, Long companyId) {
long originalNumber = Long.parseLong(doubleCallReq.getUserData());
ResponseEntity<Clue> body = sourceClueClient.queryDetails(originalNumber);
ResponseEntity<Clue> body;
try {
body = sourceClueClient.queryDetails(originalNumber);
} catch (Exception e) {
log.error("Method 【axbDialNumber】 query Clue details error{},time:{} ", e.getMessage(), DateUtil.now());
throw new BadRequestException("查询线索详情错误");
}
if (ObjectUtil.isNotNull(body) && ObjectUtil.isNotNull(body.getBody())) {
String nid = Objects.requireNonNull(body.getBody()).getNid();
String randomString = RandomUtil.randomString(DefaultNumberConstants.TEN_NUMBER);
@ -195,7 +218,13 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
telephoneCallReqDTO.setDisplay(extensionNumber.getDisplay());
}
//获取线索号
Clue body = sourceClueClient.queryDetails(Long.parseLong(telephoneCallReqDTO.getUserData())).getBody();
Clue body;
try {
body = sourceClueClient.queryDetails(Long.parseLong(telephoneCallReqDTO.getUserData())).getBody();
} catch (Exception e) {
log.error("Method 【rollCallReq】query clue error{},time:{} ", e.getMessage(), DateUtil.now());
throw new BadRequestException("查询线索错误");
}
if (ObjectUtil.isNull(body) || StrUtil.isEmpty(body.getNid())) {
log.error("未获取到号码");
return CommonResponse.createByErrorMessage("未获取到号码");
@ -248,6 +277,24 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
allCallInfo.setRecordFlag(DefaultNumberConstants.ONE_NUMBER);
allCallInfo.setRecordFileDownloadUrl(rollCallBackDTO.getRecord_file_url());
} else {
// if (StrUtil.isBlank(rollCallBackDTO.getCallee_answer_time())) {
// JSONObject object = new JSONObject();
// object.putOpt("code", 500);
// object.putOpt("type", "rollCall_reason");
// if (StrUtil.isBlank(rollCallBackDTO.getCallee_start_time()) || StrUtil.isBlank(rollCallBackDTO.getCallee_ring_time())) {
// log.error("呼叫未送达,session: {}",sessionId);
// object.putOpt("message", "呼叫未送达");
// } else {
// object.putOpt("message", "通话未接听");
// }
// // TODO: 2022/2/28 0028 发送websocket
// webSocketServer.sendMessage(JSONUtil.toJsonStr(object), SecurityUtils.getCurrentUserId());
// } else {
// callClueRepository.updateByStatus(DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueId());
// allCallInfo.setStatus(DefaultNumberConstants.TWO_NUMBER);
// allCallInfo.setDuration(Integer.valueOf(rollCallBackDTO.getDuration()));
// }
//拨打线索号的回调
if (StrUtil.isNotBlank(rollCallBackDTO.getCallee_answer_time())) {
//表示接通
@ -255,6 +302,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
allCallInfo.setStatus(DefaultNumberConstants.TWO_NUMBER);
allCallInfo.setDuration(Integer.valueOf(rollCallBackDTO.getDuration()));
}
}
allCallInfoRepository.save(allCallInfo);
}

@ -0,0 +1,173 @@
package com.baiye.timed;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baiye.constant.DefaultNumberConstants;
import com.baiye.modules.report.dao.TaskReportRepository;
import com.baiye.modules.report.dao.UserReportRepository;
import com.baiye.modules.report.entity.TaskReport;
import com.baiye.modules.report.entity.UserReport;
import com.baiye.modules.system.domain.Organize;
import com.baiye.modules.system.domain.Task;
import com.baiye.modules.system.domain.User;
import com.baiye.modules.system.repository.OrganizeRepository;
import com.baiye.modules.system.repository.TaskRepository;
import com.baiye.modules.system.repository.UserRepository;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author wujingtao
* @date 2022/03/14
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class ReportSync {
private final CallClueRepository callClueRepository;
private final TaskRepository taskRepository;
private final AllCallInfoRepository allCallInfoRepository;
private final OrganizeRepository organizeRepository;
private final TaskReportRepository taskReportRepository;
private final UserRepository userRepository;
private final UserReportRepository userReportRepository;
/**
* 23
*/
@Scheduled(cron = "0 0 23 * * ? ")
public void countReport() {
String beginOfDay = DateUtil.formatDateTime(DateUtil.yesterday());
String endOfDay = DateUtil.formatDateTime(DateUtil.date());
//查询今天的线索情况
List<CallClueInfo> callClueInfos = callClueRepository.queryAllByTime(beginOfDay, endOfDay);
if (CollUtil.isEmpty(callClueInfos)) {
return;
}
//按任务统计
autoCountReportByTask(beginOfDay, endOfDay, callClueInfos);
//按人员统计
autoCountReportByUser(beginOfDay, endOfDay, callClueInfos);
}
private void 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);
List<TaskReport> list = new ArrayList<>();
for (Long key : map.keySet()) {
Task taskInfo = taskRepository.findByIsDistributionAndId(DefaultNumberConstants.ONE_NUMBER, key);
if (ObjectUtil.isNull(taskInfo)) {
log.info("任务定时统计时,未找到该任务 id:{}", key);
continue;
}
int totalNum = taskInfo.getTotalNumber();
String taskName = taskInfo.getTaskName();
List<String> baseLabel = taskInfo.getBaseLabel();
StringBuilder label = new StringBuilder();
if (baseLabel.size() > 0) {
for (int i = 0; i < baseLabel.size(); i++) {
if (i == baseLabel.size() - 1) {
label.append(baseLabel.get(i));
} else {
label.append(baseLabel.get(i)).append(",");
}
}
}
//计算
TaskReport countInfo = JSONUtil.toBean(getCountInfo(beginOfDay, endOfDay, map.get(key)), TaskReport.class);
countInfo.setTaskId(key);
countInfo.setTaskName(taskName);
countInfo.setTotalNum(totalNum);
countInfo.setLabel(label.toString());
countInfo.setCreateTime(DateUtil.date());
countInfo.setCompanyId(map.get(key).get(0).getCompanyId());
list.add(countInfo);
}
taskReportRepository.saveAll(list);
}
private void 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);
List<UserReport> list = new ArrayList<>();
for (Long key : map.keySet()) {
Organize organize = organizeRepository.findOrganize(key);
User userById = userRepository.findUserById(key);
Long organizationId = null;
String organizeName = null;
if (ObjectUtil.isNotNull(organize)) {
organizationId = organize.getId();
organizeName = organize.getOrganizeName();
}
String userName = null;
if (ObjectUtil.isNotNull(userById)) {
userName = userById.getUsername();
}
UserReport userReport = JSONUtil.toBean(getCountInfo(beginOfDay, endOfDay, map.get(key)), UserReport.class);
userReport.setOrganizeId(organizationId);
userReport.setOrganizeName(organizeName);
userReport.setMemberId(key);
userReport.setMemberName(userName);
userReport.setCompanyId(map.get(key).get(0).getCompanyId());
userReport.setCreateTime(DateUtil.date());
list.add(userReport);
}
userReportRepository.saveAll(list);
}
private JSONObject getCountInfo(String beginOfDay, String endOfDay, List<CallClueInfo> callClueInfos) {
JSONObject object = new JSONObject();
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(beginOfDay, endOfDay, 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);
}
object.putOpt("turnOnNum", turnOnNum);
object.putOpt("turnOnRate", turnOnRate);
object.putOpt("usrNum", usrNum);
object.putOpt("breatheAverageDuration", breatheAverageDuration);
object.putOpt("breatheTotalDuration", breatheTotalDuration);
return object;
}
}

@ -103,6 +103,8 @@ public class ExportExcelUtil {
head0.add("线索名称");
List<String> head1 = new ArrayList<>();
head1.add("跟进人");
List<String> head8 = new ArrayList<>();
head8.add("手机号");
List<String> head2 = new ArrayList<>();
head2.add("外呼次数");
List<String> head3 = new ArrayList<>();
@ -117,6 +119,7 @@ public class ExportExcelUtil {
head7.add("备注");
headList.add(head0);
headList.add(head1);
headList.add(head8);
headList.add(head2);
headList.add(head3);
headList.add(head4);

@ -1,8 +1,11 @@
package com.baiye.module.dao;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baiye.exception.BadRequestException;
import com.baiye.feign.OrganizeClient;
import com.baiye.model.dto.ClueDto;
import com.baiye.model.dto.ClueQueryCriteria;
@ -149,15 +152,23 @@ public class ClueJpa {
String nid = AESUtils.decrypt(phone, secret);
String key = "task:encryption:" + taskId;
String str = String.valueOf(redisUtils.get(key));
if (str.equals("null") || StringUtils.isBlank(str)) {
if ("null".equals(str) || StringUtils.isBlank(str)) {
ClueDto clueDtoClient = new ClueDto();
clueDtoClient.setTaskId(taskId.longValue());
clueDtoClient.setIsRedis(1);
Map<String, List<String>> body = organizeClient.getLabel(clueDtoClient).getBody();
str = body.get("taskIsEncryption").get(0);
Map<String, List<String>> body;
try {
body = organizeClient.getLabel(clueDtoClient).getBody();
} catch (Exception e) {
log.error("Method【getTradeInfo】An error occurred ,error:{},time:{}", e.getMessage(), DateUtil.now());
throw new BadRequestException("获取加密信息错误");
}
if (body != null && body.containsKey("taskIsEncryption")) {
str = body.get("taskIsEncryption").get(0);
}
}
//str此次任务是否加密线索手机号 0:不加密 1:加密
if (str.equals("0")) {
if ("0".equals(str)) {
clueDto.setNid(nid);
} else {
StringBuilder stringBuilder = new StringBuilder(nid);
@ -184,7 +195,7 @@ public class ClueJpa {
public List<ResSourceLabel> findSourceLabel(List<Long> clueIds) {
StringBuilder sql = new StringBuilder();
sql.append("select tcm.source_label as sourceLabel, clue_id as clueId,tc.name as name,tcm.remark as remark from tb_clue_middle tcm LEFT JOIN tb_clue tc on tcm.clue_id = tc.id where 1=1 ");
sql.append("select tcm.source_label as sourceLabel, clue_id as clueId,tc.name as name,tcm.remark as remark,tc.nid as nid from tb_clue_middle tcm LEFT JOIN tb_clue tc on tcm.clue_id = tc.id where 1=1 ");
if (clueIds != null && clueIds.size() > 0) {
sql.append("AND tcm.clue_id IN (:clueIds) ");
}
@ -203,6 +214,9 @@ public class ClueJpa {
BigInteger clueId = (BigInteger) row.get("clueId");
resSourceLabel.setClueId(clueId.longValue());
resSourceLabel.setRemark((String) row.get("remark"));
String phone = (String) row.get("nid");
String nid = StrUtil.isBlank(phone) ? null : AESUtils.decrypt(phone, secret);
resSourceLabel.setNid(nid);
list.add(resSourceLabel);
}
return list;

@ -1,6 +1,7 @@
package com.baiye.module.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
@ -332,7 +333,12 @@ public class ClueServiceImpl implements ClueService {
Long userId = baseExcelVo.getUserId();
Integer taskNum = clueMiddleRepository.findTaskNum(taskId);
if (taskNum == null || taskNum == 0) {
taskClient.sendErrMessage("导入资源合规条数0条,请检查文件重新导入", userId);
try {
taskClient.sendErrMessage("导入资源合规条数0条,请检查文件重新导入", userId);
} catch (Exception e) {
log.error("Method【saveTask】An error occurred ,error:{},time:{}", e.getMessage(), DateUtil.now());
throw new BadRequestException("发送websocket失败");
}
throw new BadRequestException("导入资源合规条数为0条,请检查文件重新导入");
}
int lastIndexOf = oneFileName.lastIndexOf(".");
@ -345,6 +351,12 @@ public class ClueServiceImpl implements ClueService {
task.setTotalNumber(taskNum);
task.setTaskType(DefaultNumberConstants.ZERO_NUMBER);
taskClient.saveTask(task);
try {
taskClient.saveTask(task);
} catch (Exception e) {
log.error("Method【saveTask】An error occurred ,error:{},time:{}", e.getMessage(), DateUtil.now());
throw new BadRequestException("创建任务失败");
}
}
@Override

Loading…
Cancel
Save