|
@@ -19,7 +19,6 @@ import cn.cslg.pas.service.business.CommonService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
-import co.elastic.clients.elasticsearch._types.query_dsl.IdsQuery;
|
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
@@ -37,6 +36,7 @@ import java.io.IOException;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -160,6 +160,21 @@ public class EsCountService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (countVOS.size() == 1) {
|
|
|
|
+ EsCountVO countVO = countVOS.get(0);
|
|
|
|
+ String field = countVO.getField();
|
|
|
|
+ String valueOne = countVO.getValueOne();
|
|
|
|
+ String valueTwo = countVO.getValueTwo();
|
|
|
|
+ if (StringUtils.isNotEmpty(valueOne) && StringUtils.isEmpty(valueTwo)) {
|
|
|
|
+ String filterCondition = field + " = " + valueOne;
|
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
|
+ searchCondition = filterCondition + " AND " + searchCondition;
|
|
|
|
+ } else {
|
|
|
|
+ searchCondition = filterCondition;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if (!CollectionUtils.isEmpty(customFields)) {
|
|
if (!CollectionUtils.isEmpty(customFields)) {
|
|
searchCondition = esService.parseCustomField(customFields,projectId,taskId);
|
|
searchCondition = esService.parseCustomField(customFields,projectId,taskId);
|
|
}
|
|
}
|
|
@@ -527,32 +542,43 @@ public class EsCountService {
|
|
EsCountDTO esCountDTO, String firstName,
|
|
EsCountDTO esCountDTO, String firstName,
|
|
Map<String, List<EsCountDetailDTO>> map,List<String> values) {
|
|
Map<String, List<EsCountDetailDTO>> map,List<String> values) {
|
|
List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
|
|
+ long otherNum = 0l;
|
|
|
|
+ List<StringTermsBucket> list = agg.sterms().buckets().array();
|
|
|
|
+ for (StringTermsBucket bucket : list) {
|
|
|
|
+ EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
|
+ dto.setField(field);
|
|
|
|
+ Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
|
|
+ String value = bucket.key().stringValue();
|
|
|
|
+ if (StringUtils.isNotEmpty(value)) {
|
|
|
|
+ dto.setName(value);
|
|
|
|
+ dto.setNumber(bucket.docCount());
|
|
|
|
+ dto.setTopN(topN);
|
|
|
|
+ dto.setFirstName(firstName);
|
|
|
|
+ if (aggregate != null) {
|
|
|
|
+ dto.setNumber(aggregate.filter().docCount());
|
|
|
|
+ }
|
|
|
|
+ if (dto.getNumber() > 0) {
|
|
|
|
+ countDetailDTOS.add(dto);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ otherNum += 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (countDetailDTOS.size() > topN) {
|
|
|
|
+ countDetailDTOS.remove(countDetailDTOS.size() - 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
countDTO.setField(field);
|
|
countDTO.setField(field);
|
|
countDTO.setName("其他");
|
|
countDTO.setName("其他");
|
|
countDTO.setTopN(topN);
|
|
countDTO.setTopN(topN);
|
|
Long count = agg.sterms().sumOtherDocCount();
|
|
Long count = agg.sterms().sumOtherDocCount();
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
- countDTO.setNumber(count);
|
|
|
|
|
|
+ countDTO.setNumber(count + otherNum);
|
|
detailDTOS.add(countDTO);
|
|
detailDTOS.add(countDTO);
|
|
}
|
|
}
|
|
-
|
|
|
|
- List<StringTermsBucket> list = agg.sterms().buckets().array();
|
|
|
|
- list.forEach(bucket -> {
|
|
|
|
- EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
|
- dto.setField(field);
|
|
|
|
- Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
|
|
- dto.setName(bucket.key().stringValue());
|
|
|
|
- dto.setNumber(bucket.docCount());
|
|
|
|
- dto.setTopN(topN);
|
|
|
|
- dto.setFirstName(firstName);
|
|
|
|
- if (aggregate != null) {
|
|
|
|
- dto.setNumber(aggregate.filter().docCount());
|
|
|
|
- }
|
|
|
|
- if (dto.getNumber() > 0) {
|
|
|
|
- countDetailDTOS.add(dto);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ esCountDTO.setRemainingNum(count);
|
|
|
|
|
|
List<String> strs = new ArrayList<>();
|
|
List<String> strs = new ArrayList<>();
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
@@ -837,7 +863,9 @@ public class EsCountService {
|
|
public void getDateCountDTOS(Aggregate agg, String field, Integer topN, String format, List<EsCountDetailDTO> detailDTOS,
|
|
public void getDateCountDTOS(Aggregate agg, String field, Integer topN, String format, List<EsCountDetailDTO> detailDTOS,
|
|
EsCountDTO esCountDTO, String valueOne, String valueTwo) throws ParseException {
|
|
EsCountDTO esCountDTO, String valueOne, String valueTwo) throws ParseException {
|
|
List<DateHistogramBucket> list = agg.dateHistogram().buckets().array();
|
|
List<DateHistogramBucket> list = agg.dateHistogram().buckets().array();
|
|
- esCountDTO.setAllNumber(Long.valueOf(String.valueOf(list.size())));
|
|
|
|
|
|
+ long all = Long.valueOf(String.valueOf(list.size()));
|
|
|
|
+ esCountDTO.setAllNumber(all);
|
|
|
|
+
|
|
List<EsCountDetailDTO> esCountDetailDTOS = new ArrayList<>();
|
|
List<EsCountDetailDTO> esCountDetailDTOS = new ArrayList<>();
|
|
if (StringUtils.isNotEmpty(format) && format.equals("半年")) {
|
|
if (StringUtils.isNotEmpty(format) && format.equals("半年")) {
|
|
List<EsCountDetailDTO> detailDTOList = new ArrayList<>();
|
|
List<EsCountDetailDTO> detailDTOList = new ArrayList<>();
|
|
@@ -940,23 +968,21 @@ public class EsCountService {
|
|
}
|
|
}
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(esCountDetailDTOS)) {
|
|
if (!CollectionUtils.isEmpty(esCountDetailDTOS)) {
|
|
|
|
+ if (StringUtils.isNotEmpty(valueOne) || StringUtils.isNotEmpty(valueTwo)) {
|
|
|
|
+ all = Long.valueOf(String.valueOf(esCountDetailDTOS.size()));
|
|
|
|
+ }
|
|
|
|
+ long num = Long.valueOf(String.valueOf(topN));
|
|
|
|
+ long finalNum = all - num;
|
|
|
|
+ if (finalNum > 0) {
|
|
|
|
+ esCountDTO.setRemainingNum(finalNum);
|
|
|
|
+ } else {
|
|
|
|
+ esCountDTO.setRemainingNum(0l);
|
|
|
|
+ }
|
|
|
|
+
|
|
List<EsCountDetailDTO> collect = esCountDetailDTOS.stream()
|
|
List<EsCountDetailDTO> collect = esCountDetailDTOS.stream()
|
|
.sorted(Comparator.comparing(EsCountDetailDTO::getName).reversed()).limit(topN).collect(Collectors.toList());
|
|
.sorted(Comparator.comparing(EsCountDetailDTO::getName).reversed()).limit(topN).collect(Collectors.toList());
|
|
detailDTOS.addAll(collect);
|
|
detailDTOS.addAll(collect);
|
|
}
|
|
}
|
|
-
|
|
|
|
-// EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
|
-// countDTO.setField(field);
|
|
|
|
-// countDTO.setName("其他");
|
|
|
|
-// if (list.size() > topN) {
|
|
|
|
-// int sum = list.size() - topN;
|
|
|
|
-// countDTO.setNumber(Long.valueOf(String.valueOf(sum)));
|
|
|
|
-//
|
|
|
|
-// } else {
|
|
|
|
-// countDTO.setNumber(0L);
|
|
|
|
-// }
|
|
|
|
-// countDTO.setTopN(topN);
|
|
|
|
-// detailDTOS.add(countDTO);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1035,18 +1061,9 @@ public class EsCountService {
|
|
Map<String, List<EsCountDetailDTO>> map, List<String> values) {
|
|
Map<String, List<EsCountDetailDTO>> map, List<String> values) {
|
|
Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
- EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
|
- countDTO.setField(field);
|
|
|
|
- countDTO.setName("其他");
|
|
|
|
- countDTO.setTopN(topN);
|
|
|
|
- Long count = termsAgg.sterms().sumOtherDocCount();
|
|
|
|
- if (count > 0) {
|
|
|
|
- countDTO.setNumber(count);
|
|
|
|
- countDetailDTOS.add(countDTO);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ long otherNum = 0l;
|
|
List<StringTermsBucket> list = termsAgg.sterms().buckets().array();
|
|
List<StringTermsBucket> list = termsAgg.sterms().buckets().array();
|
|
- list.forEach(bucket -> {
|
|
|
|
|
|
+ for (StringTermsBucket bucket : list) {
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
dto.setField(field);
|
|
dto.setField(field);
|
|
Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
@@ -1062,11 +1079,25 @@ public class EsCountService {
|
|
if (dto.getNumber() > 0) {
|
|
if (dto.getNumber() > 0) {
|
|
countDetailDTOS.add(dto);
|
|
countDetailDTOS.add(dto);
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ otherNum += 1;
|
|
}
|
|
}
|
|
-// if (dto.getNumber() > 0) {
|
|
|
|
-// detailDTOS.add(dto);
|
|
|
|
-// }
|
|
|
|
- });
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (countDetailDTOS.size() > topN) {
|
|
|
|
+ countDetailDTOS.remove(countDetailDTOS.size() - 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
|
+ countDTO.setField(field);
|
|
|
|
+ countDTO.setName("其他");
|
|
|
|
+ countDTO.setTopN(topN);
|
|
|
|
+ Long count = termsAgg.sterms().sumOtherDocCount();
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ countDTO.setNumber(count + otherNum);
|
|
|
|
+ countDetailDTOS.add(countDTO);
|
|
|
|
+ }
|
|
|
|
+ esCountDTO.setRemainingNum(count);
|
|
|
|
|
|
List<String> strs = new ArrayList<>();
|
|
List<String> strs = new ArrayList<>();
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
if (!CollectionUtils.isEmpty(values)) {
|