|
@@ -3,12 +3,14 @@ package cn.cslg.pas.service.business.es;
|
|
|
import cn.cslg.pas.common.dto.business.EsCountDTO;
|
|
|
import cn.cslg.pas.common.dto.business.EsCountDetailDTO;
|
|
|
import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
|
|
|
+import cn.cslg.pas.common.dto.es.EsDateRangeDTO;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.expressManager;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
|
import cn.cslg.pas.common.vo.EsConfigVO;
|
|
|
import cn.cslg.pas.common.vo.business.EsAllCountVO;
|
|
|
import cn.cslg.pas.common.vo.business.EsCountVO;
|
|
|
+import cn.cslg.pas.common.vo.es.EsDateRangeVO;
|
|
|
import cn.cslg.pas.domain.es.Patent;
|
|
|
import cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory.EsCountAnalysisBuilderFactory;
|
|
|
import cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory.IEsCountAnalysisBuilder;
|
|
@@ -56,13 +58,53 @@ public class EsCountService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public EsCountDTO esCountAnalysis(EsAllCountVO vo) throws Exception {
|
|
|
+ List<EsCountVO> countVOS = vo.getCountVOS();
|
|
|
String searchCondition = vo.getCondition();
|
|
|
List<EsCustomFieldValueDTO> customFields = vo.getCustomFields();
|
|
|
+ Integer taskId = vo.getTaskId();
|
|
|
+ Integer projectId = vo.getProjectId();
|
|
|
+ EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
+ List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
|
+ if (countVOS.size() > 1) {
|
|
|
+ EsCountVO countVO = countVOS.get(0);
|
|
|
+ List<String> values = countVO.getValues();
|
|
|
+ List<EsCountVO> esCountVOS = new ArrayList<>();
|
|
|
+ esCountVOS.add(countVOS.get(1));
|
|
|
+ if (StringUtils.isNotEmpty(countVO.getFieldId())) {
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ for (String value : values) {
|
|
|
+ EsCustomFieldValueDTO valueDTO = new EsCustomFieldValueDTO();
|
|
|
+ valueDTO.setFieldId(countVO.getFieldId());
|
|
|
+ valueDTO.setFieldValue(Arrays.asList(value));
|
|
|
+ customFields.add(valueDTO);
|
|
|
+ this.getReturnData(searchCondition, customFields, taskId, projectId, esCountVOS, detailDTOS, esCountDTO,value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ for (String value : values) {
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
+ searchCondition = countVO.getField() + " = " + value + " AND " + searchCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = countVO.getField() + " = " + value;
|
|
|
+ }
|
|
|
+ this.getReturnData(searchCondition, customFields, taskId, projectId, esCountVOS, detailDTOS, esCountDTO,value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.getReturnData(searchCondition, customFields, taskId, projectId, countVOS, detailDTOS, esCountDTO,"");
|
|
|
+ }
|
|
|
+ esCountDTO.setDetailDTOS(detailDTOS);
|
|
|
+ return esCountDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getReturnData(String searchCondition,List<EsCustomFieldValueDTO> customFields,Integer taskId,
|
|
|
+ Integer projectId,List<EsCountVO> countVOS,List<EsCountDetailDTO> detailDTOS,
|
|
|
+ EsCountDTO esCountDTO,String firstName) throws Exception {
|
|
|
if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
searchCondition = esService.parseCustomField(customFields);
|
|
|
}
|
|
|
- Integer taskId = vo.getTaskId();
|
|
|
- Integer projectId = vo.getProjectId();
|
|
|
+
|
|
|
searchCondition = this.getCondition(searchCondition, taskId, projectId);
|
|
|
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
@@ -78,9 +120,6 @@ public class EsCountService {
|
|
|
query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
}
|
|
|
|
|
|
- EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
- List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
|
- List<EsCountVO> countVOS = vo.getCountVOS();
|
|
|
for (EsCountVO countVO : countVOS) {
|
|
|
String field = countVO.getField();
|
|
|
Integer topN = countVO.getTopN();
|
|
@@ -113,7 +152,6 @@ public class EsCountService {
|
|
|
if (dateList.contains(field)) {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
try {
|
|
|
this.getDateCountDTOS(filtersAgg, field, topN, format, detailDTOS, esCountDTO);
|
|
@@ -123,16 +161,14 @@ public class EsCountService {
|
|
|
});
|
|
|
} else {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getDateAnalysisDTOS(filtersAgg, field, topN, detailDTOS,esCountDTO);
|
|
|
+ this.getDateAnalysisDTOS(filtersAgg, field, topN, detailDTOS,esCountDTO,firstName);
|
|
|
});
|
|
|
}
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getNestedCountDTOS(filtersAgg, field,topN, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(filtersAgg, field,topN, detailDTOS,firstName);
|
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
|
esCountDTO.setAllNumber(filtersAgg.nested().docCount());
|
|
|
}
|
|
@@ -141,16 +177,14 @@ public class EsCountService {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
Integer finalFieldType = fieldType;
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
this.getChildCountDTOS(filtersAgg, field, finalFieldType, topN,detailDTOS,esCountDTO);
|
|
|
});
|
|
|
} else {
|
|
|
Integer finalFieldType1 = fieldType;
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getChildAnalysisDTOS(filtersAgg, field, finalFieldType1, topN,detailDTOS, esCountDTO);
|
|
|
+ this.getChildAnalysisDTOS(filtersAgg, field, finalFieldType1, topN,detailDTOS, esCountDTO,firstName);
|
|
|
});
|
|
|
}
|
|
|
} else if (numberList.contains(field)) {
|
|
@@ -158,16 +192,14 @@ public class EsCountService {
|
|
|
|
|
|
} else {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getNumberAnalysisDTOS(filtersAgg, field,topN, detailDTOS);
|
|
|
+ this.getNumberAnalysisDTOS(filtersAgg, field,topN, detailDTOS,firstName);
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
-// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getTermCountDTOS(filtersAgg, field, topN,detailDTOS);
|
|
|
+ this.getTermCountDTOS(filtersAgg, field, topN,detailDTOS,firstName);
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
@@ -178,10 +210,10 @@ public class EsCountService {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
this.getDateCountDTOS(agg, field, topN,format, detailDTOS,esCountDTO);
|
|
|
} else {
|
|
|
- this.getDateAnalysisDTOS(agg, field, topN, detailDTOS,esCountDTO);
|
|
|
+ this.getDateAnalysisDTOS(agg, field, topN, detailDTOS,esCountDTO,firstName);
|
|
|
}
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
- this.getNestedCountDTOS(agg, field,topN, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(agg, field,topN, detailDTOS,firstName);
|
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
|
esCountDTO.setAllNumber(agg.nested().docCount());
|
|
|
}
|
|
@@ -189,18 +221,54 @@ public class EsCountService {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
this.getChildCountDTOS(agg, field, fieldType,topN, detailDTOS, esCountDTO);
|
|
|
} else {
|
|
|
- this.getChildAnalysisDTOS(agg, field, fieldType,topN, detailDTOS, esCountDTO);
|
|
|
+ this.getChildAnalysisDTOS(agg, field, fieldType,topN, detailDTOS, esCountDTO,firstName);
|
|
|
}
|
|
|
} else if (numberList.contains(field)) {
|
|
|
- this.getNumberAnalysisDTOS(agg, field,topN, detailDTOS);
|
|
|
+ this.getNumberAnalysisDTOS(agg, field,topN, detailDTOS,firstName);
|
|
|
} else {
|
|
|
- this.getTermCountDTOS(agg, field,topN, detailDTOS);
|
|
|
+ this.getTermCountDTOS(agg, field,topN, detailDTOS,firstName);
|
|
|
}
|
|
|
}
|
|
|
+ esCountDTO.setCondition(searchCondition);
|
|
|
}
|
|
|
- esCountDTO.setDetailDTOS(detailDTOS);
|
|
|
- esCountDTO.setCondition(searchCondition);
|
|
|
- return esCountDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public EsDateRangeDTO getFieldRange(EsDateRangeVO rangeVO) throws Exception {
|
|
|
+ String searchCondition = rangeVO.getCondition();
|
|
|
+ String field = rangeVO.getField();
|
|
|
+ List<EsCustomFieldValueDTO> customFields = rangeVO.getCustomFields();
|
|
|
+ if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
+ searchCondition = esService.parseCustomField(customFields);
|
|
|
+ }
|
|
|
+ Integer taskId = rangeVO.getTaskId();
|
|
|
+ Integer projectId = rangeVO.getProjectId();
|
|
|
+ searchCondition = this.getCondition(searchCondition, taskId, projectId);
|
|
|
+
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+ //设置查询索引
|
|
|
+ Query query = null;
|
|
|
+ if (StringUtils.isNotEmpty(searchCondition)) {
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
|
+ //格式化检索式
|
|
|
+ //3. 从es中检索数据
|
|
|
+ query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
+ }
|
|
|
+ switch (field) {
|
|
|
+
|
|
|
+ }
|
|
|
+ Aggregation finalAggregation = null;
|
|
|
+ Query finalQuery = query;
|
|
|
+ Aggregation filtersAgg = new Aggregation.Builder().filters(new FiltersAggregation.Builder()
|
|
|
+ .filters(i -> i.array(Arrays.asList(finalQuery))).build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filters_agg", finalAggregation);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("Agg", filtersAgg);
|
|
|
+ EsDateRangeDTO rangeDTO = new EsDateRangeDTO();
|
|
|
+ return rangeDTO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -302,7 +370,7 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getTermCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getTermCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,String firstName) {
|
|
|
EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
countDTO.setField(field);
|
|
|
countDTO.setName("其他");
|
|
@@ -317,6 +385,7 @@ public class EsCountService {
|
|
|
dto.setName(bucket.key().stringValue());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
dto.setTopN(topN);
|
|
|
+ dto.setFirstName(firstName);
|
|
|
if (aggregate != null) {
|
|
|
dto.setNumber(aggregate.filter().docCount());
|
|
|
}
|
|
@@ -377,8 +446,8 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getChildAnalysisDTOS(Aggregate agg, String field,Integer fieldType,Integer topN,
|
|
|
- List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
+ public void getChildAnalysisDTOS(Aggregate agg, String field, Integer fieldType, Integer topN,
|
|
|
+ List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO, String firstName) {
|
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
|
list.forEach(bucket -> {
|
|
@@ -390,6 +459,7 @@ public class EsCountService {
|
|
|
dto.setField(field);
|
|
|
dto.setName(termsBucket.key().stringValue());
|
|
|
dto.setNumber(termsBucket.docCount());
|
|
|
+ dto.setFirstName(firstName);
|
|
|
dto.setTopN(topN);
|
|
|
if (dto.getNumber() > 0) {
|
|
|
detailDTOS.add(dto);
|
|
@@ -416,7 +486,7 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getNumberAnalysisDTOS(Aggregate agg, String field,Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getNumberAnalysisDTOS(Aggregate agg, String field,Integer topN, List<EsCountDetailDTO> detailDTOS,String firstName) {
|
|
|
List<RangeBucket> list = agg.range().buckets().array();
|
|
|
for (RangeBucket bucket : list) {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
@@ -424,6 +494,7 @@ public class EsCountService {
|
|
|
dto.setName(bucket.key());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
dto.setTopN(topN);
|
|
|
+ dto.setFirstName(firstName);
|
|
|
if (dto.getNumber() > 0) {
|
|
|
detailDTOS.add(dto);
|
|
|
}
|
|
@@ -533,11 +604,12 @@ public class EsCountService {
|
|
|
* @param topN
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getDateAnalysisDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,EsCountDTO esCountDTO) {
|
|
|
+ public void getDateAnalysisDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO, String firstName) {
|
|
|
List<RangeBucket> list1 = agg.dateRange().buckets().array();
|
|
|
List<EsCountDetailDTO> esCountDetailDTOS = new ArrayList<>();
|
|
|
for (RangeBucket bucket : list1) {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
+ dto.setFirstName(firstName);
|
|
|
dto.setField(field);
|
|
|
dto.setName(bucket.key());
|
|
|
dto.setNumber(bucket.docCount());
|
|
@@ -560,7 +632,7 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getNestedCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getNestedCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS, String firstName) {
|
|
|
Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
countDTO.setField(field);
|
|
@@ -576,6 +648,7 @@ public class EsCountService {
|
|
|
dto.setName(bucket.key().stringValue());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
dto.setTopN(topN);
|
|
|
+ dto.setFirstName(firstName);
|
|
|
if (aggregate != null) {
|
|
|
dto.setNumber(aggregate.filter().docCount());
|
|
|
}
|
|
@@ -585,5 +658,4 @@ public class EsCountService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|