|
|
@@ -8,12 +8,18 @@ import com.ruoyi.common.utils.DateUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 外呼记录Service业务层处理
|
|
|
@@ -204,4 +210,58 @@ public class CcOutboundCdrServiceImpl implements ICcOutboundCdrService
|
|
|
public List<CcOutboundCdr> selectCcOutboundCdrByIds(List<String> ids) {
|
|
|
return ccOutboundCdrMapper.selectCcOutboundCdrByIds(ids);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CcOutboundCdr> selectMergedCcOutboundCdrByUuids(List<String> uuids) {
|
|
|
+ if (CollectionUtils.isEmpty(uuids)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<String> distinctUuids = uuids.stream()
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (distinctUuids.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<CcOutboundCdr> list = ccOutboundCdrMapper.selectCcOutboundCdrByUuids(distinctUuids);
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ Map<String, List<CcOutboundCdr>> grouped = list.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(item -> StringUtils.isNotBlank(item.getUuid()))
|
|
|
+ .collect(Collectors.groupingBy(CcOutboundCdr::getUuid, LinkedHashMap::new, Collectors.toList()));
|
|
|
+
|
|
|
+ List<CcOutboundCdr> merged = new ArrayList<>(grouped.size());
|
|
|
+ for (List<CcOutboundCdr> segments : grouped.values()) {
|
|
|
+ merged.add(mergeReconnectSegments(segments));
|
|
|
+ }
|
|
|
+ return merged;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 断线重连多段合并:end_time 倒序后,取最晚一条为底;
|
|
|
+ * start_time、answered_time 取最早一条;time_len、time_len_valid 全部分段累加。
|
|
|
+ */
|
|
|
+ private CcOutboundCdr mergeReconnectSegments(List<CcOutboundCdr> segments) {
|
|
|
+ if (segments.size() == 1) {
|
|
|
+ return segments.get(0);
|
|
|
+ }
|
|
|
+ List<CcOutboundCdr> ordered = segments.stream()
|
|
|
+ .sorted(Comparator.comparing(CcOutboundCdr::getEndTime, Comparator.nullsLast(Long::compareTo)).reversed())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ CcOutboundCdr latest = ordered.get(0);
|
|
|
+ CcOutboundCdr earliest = ordered.get(ordered.size() - 1);
|
|
|
+ latest.setStartTime(earliest.getStartTime());
|
|
|
+ latest.setAnsweredTime(earliest.getAnsweredTime());
|
|
|
+ long timeLenSum = 0L;
|
|
|
+ long timeLenValidSum = 0L;
|
|
|
+ for (CcOutboundCdr item : ordered) {
|
|
|
+ timeLenSum += item.getTimeLen() == null ? 0L : item.getTimeLen();
|
|
|
+ timeLenValidSum += item.getTimeLenValid() == null ? 0L : item.getTimeLenValid();
|
|
|
+ }
|
|
|
+ latest.setTimeLen(timeLenSum);
|
|
|
+ latest.setTimeLenValid(timeLenValidSum);
|
|
|
+ return latest;
|
|
|
+ }
|
|
|
}
|