Bläddra i källkod

fixed 二维分析

zero 1 år sedan
förälder
incheckning
bba0f8aece

+ 3 - 0
src/main/java/cn/cslg/pas/common/dto/business/EsCountDTO.java

@@ -3,6 +3,7 @@ package cn.cslg.pas.common.dto.business;
 import lombok.Data;
 
 import java.util.List;
+import java.util.Map;
 
 @Data
 public class EsCountDTO {
@@ -10,4 +11,6 @@ public class EsCountDTO {
     private Long allNumber;
     private String condition;
     private List<EsCountDetailDTO> detailDTOS;
+    //多维分析返回数据
+    private Map<String, List<EsCountDetailDTO>> analyseMap;
 }

+ 274 - 71
src/main/java/cn/cslg/pas/service/business/es/EsCountService.java

@@ -38,7 +38,7 @@ import java.util.stream.Collectors;
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class EsCountService {
     private final List<String> childList = Arrays.asList("field");
-    private final List<String> nestedList = Arrays.asList("PA", "IN", "PE", "SAT", "MAT", "SRH", "MRH","MIN");
+    private final List<String> nestedList = Arrays.asList("PA", "IN", "PE", "SAT", "MAT", "SRH", "MRH", "MIN");
     private final List<String> dateList = Arrays.asList("PD", "AD", "GD");
     private final List<String> numberList = Arrays.asList("QPN", "QDPN", "SFN", "IFN", "PFN");
 
@@ -53,6 +53,7 @@ public class EsCountService {
 
     /**
      * 聚合统计
+     *
      * @param vo
      * @return
      * @throws Exception
@@ -64,6 +65,7 @@ public class EsCountService {
         Integer taskId = vo.getTaskId();
         Integer projectId = vo.getProjectId();
         EsCountDTO esCountDTO = new EsCountDTO();
+        HashMap<String, List<EsCountDetailDTO>> map = new HashMap<>();
         List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
         if (countVOS.size() > 1) {
             EsCountVO countVO = countVOS.get(0);
@@ -77,30 +79,30 @@ public class EsCountService {
                         valueDTO.setFieldId(countVO.getFieldId());
                         valueDTO.setFieldValue(Arrays.asList(value));
                         customFields.add(valueDTO);
-                        this.getReturnData(searchCondition, customFields, taskId, projectId, esCountVOS, detailDTOS, esCountDTO,value);
+                        this.getReturnData(searchCondition, customFields, taskId, projectId, esCountVOS, detailDTOS, esCountDTO, value, map);
                     }
                 }
-
             } else {
                 for (String value : values) {
+                    String condition = countVO.getField() + " = " + value;
                     if (searchCondition != null && !"".equals(searchCondition.trim())) {
-                        searchCondition = countVO.getField() + " = " + value + " AND " + searchCondition;
+                        searchCondition = condition + " AND " + searchCondition;
                     } else {
-                        searchCondition = countVO.getField() + " = " + value;
+                        searchCondition = condition;
                     }
-                    this.getReturnData(searchCondition, customFields, taskId, projectId, esCountVOS, detailDTOS, esCountDTO,value);
+                    this.getReturnData(searchCondition, customFields, taskId, projectId, esCountVOS, detailDTOS, esCountDTO, value, map);
                 }
             }
         } else {
-            this.getReturnData(searchCondition, customFields, taskId, projectId, countVOS, detailDTOS, esCountDTO,"");
+            this.getReturnData(searchCondition, customFields, taskId, projectId, countVOS, detailDTOS, esCountDTO, "", map);
         }
         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 {
+    public void getReturnData(String searchCondition, List<EsCustomFieldValueDTO> customFields, Integer taskId,
+                              Integer projectId, List<EsCountVO> countVOS, List<EsCountDetailDTO> detailDTOS,
+                              EsCountDTO esCountDTO, String firstName, Map<String, List<EsCountDetailDTO>> map) throws Exception {
         if (!CollectionUtils.isEmpty(customFields)) {
             searchCondition = esService.parseCustomField(customFields);
         }
@@ -162,13 +164,13 @@ public class EsCountService {
                         } else {
                             filtersBuckets.forEach(filtersBucket -> {
                                 Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
-                                this.getDateAnalysisDTOS(filtersAgg, field, topN, detailDTOS,esCountDTO,firstName);
+                                this.getDateAnalysisDTOS(filtersAgg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
                             });
                         }
                     } else if (nestedList.contains(field)) {
                         filtersBuckets.forEach(filtersBucket -> {
                             Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
-                            this.getNestedCountDTOS(filtersAgg, field,topN, detailDTOS,firstName);
+                            this.getNestedCountDTOS(filtersAgg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
                             if (!CollectionUtils.isEmpty(values)) {
                                 esCountDTO.setAllNumber(filtersAgg.nested().docCount());
                             }
@@ -178,13 +180,14 @@ public class EsCountService {
                             Integer finalFieldType = fieldType;
                             filtersBuckets.forEach(filtersBucket -> {
                                 Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
-                                this.getChildCountDTOS(filtersAgg, field, finalFieldType, topN,detailDTOS,esCountDTO);
+                                this.getChildCountDTOS(filtersAgg, field, finalFieldType, topN, detailDTOS, esCountDTO);
                             });
                         } else {
                             Integer finalFieldType1 = fieldType;
                             filtersBuckets.forEach(filtersBucket -> {
                                 Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
-                                this.getChildAnalysisDTOS(filtersAgg, field, finalFieldType1, topN,detailDTOS, esCountDTO,firstName);
+                                this.getChildAnalysisDTOS(filtersAgg, field, finalFieldType1, topN,
+                                        detailDTOS, esCountDTO, firstName, map,values);
                             });
                         }
                     } else if (numberList.contains(field)) {
@@ -193,13 +196,13 @@ public class EsCountService {
                         } else {
                             filtersBuckets.forEach(filtersBucket -> {
                                 Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
-                                this.getNumberAnalysisDTOS(filtersAgg, field,topN, detailDTOS,firstName);
+                                this.getNumberAnalysisDTOS(filtersAgg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
                             });
                         }
                     } else {
                         filtersBuckets.forEach(filtersBucket -> {
                             Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
-                            this.getTermCountDTOS(filtersAgg, field, topN,detailDTOS,firstName);
+                            this.getTermCountDTOS(filtersAgg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
                         });
                     }
                 } else {
@@ -208,28 +211,30 @@ public class EsCountService {
             } else {
                 if (dateList.contains(field)) {
                     if (CollectionUtils.isEmpty(values)) {
-                        this.getDateCountDTOS(agg, field, topN,format, detailDTOS,esCountDTO);
+                        this.getDateCountDTOS(agg, field, topN, format, detailDTOS, esCountDTO);
                     } else {
-                        this.getDateAnalysisDTOS(agg, field, topN, detailDTOS,esCountDTO,firstName);
+                        this.getDateAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
                     }
                 } else if (nestedList.contains(field)) {
-                    this.getNestedCountDTOS(agg, field,topN, detailDTOS,firstName);
+                    this.getNestedCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
                     if (!CollectionUtils.isEmpty(values)) {
                         esCountDTO.setAllNumber(agg.nested().docCount());
                     }
                 } else if (childList.contains(field)) {
                     if (CollectionUtils.isEmpty(values)) {
-                        this.getChildCountDTOS(agg, field, fieldType,topN, detailDTOS, esCountDTO);
+                        this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO);
                     } else {
-                        this.getChildAnalysisDTOS(agg, field, fieldType,topN, detailDTOS, esCountDTO,firstName);
+                        this.getChildAnalysisDTOS(agg, field, fieldType, topN,
+                                detailDTOS, esCountDTO, firstName, map,values);
                     }
                 } else if (numberList.contains(field)) {
-                    this.getNumberAnalysisDTOS(agg, field,topN, detailDTOS,firstName);
+                    this.getNumberAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
                 } else {
-                    this.getTermCountDTOS(agg, field,topN, detailDTOS,firstName);
+                    this.getTermCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map,values);
                 }
             }
             esCountDTO.setCondition(searchCondition);
+            esCountDTO.setAnalyseMap(map);
         }
     }
 
@@ -317,6 +322,7 @@ public class EsCountService {
 
     /**
      * 查询共用Aggregation
+     *
      * @param countVO
      * @return
      * @throws Exception
@@ -414,7 +420,10 @@ public class EsCountService {
      * @param field
      * @param detailDTOS
      */
-    public void getTermCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,String firstName) {
+    public void getTermCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,
+                                 EsCountDTO esCountDTO, String firstName,
+                                 Map<String, List<EsCountDetailDTO>> map,List<String> values) {
+        List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
         EsCountDetailDTO countDTO = new EsCountDetailDTO();
         countDTO.setField(field);
         countDTO.setName("其他");
@@ -434,9 +443,44 @@ public class EsCountService {
                 dto.setNumber(aggregate.filter().docCount());
             }
             if (dto.getNumber() > 0) {
-                detailDTOS.add(dto);
+                countDetailDTOS.add(dto);
             }
         });
+
+        List<String> strs = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(values)) {
+            strs.addAll(values);
+        }
+        if (StringUtils.isNotEmpty(firstName)) {
+            countDetailDTOS.removeIf(dto -> dto.getName().equals("其他"));
+            if (countDetailDTOS.size() != values.size()) {
+                for (EsCountDetailDTO detailDTO : countDetailDTOS) {
+                    strs.removeIf(i -> i.equals(detailDTO.getName()));
+                }
+                for (String value : strs) {
+                    EsCountDetailDTO detailDTO = new EsCountDetailDTO();
+                    detailDTO.setName(value);
+                    detailDTO.setFirstName(firstName);
+                    detailDTO.setField(field);
+                    detailDTO.setNumber(0L);
+                    detailDTO.setTopN(topN);
+                    countDetailDTOS.add(detailDTO);
+                }
+            } else if (countDetailDTOS.isEmpty()) {
+                for (String value : values) {
+                    EsCountDetailDTO detailDTO = new EsCountDetailDTO();
+                    detailDTO.setName(value);
+                    detailDTO.setFirstName(firstName);
+                    detailDTO.setField(field);
+                    detailDTO.setNumber(0L);
+                    detailDTO.setTopN(topN);
+                    countDetailDTOS.add(detailDTO);
+                }
+            }
+            map.put(firstName, countDetailDTOS);
+        } else {
+            detailDTOS.addAll(countDetailDTOS);
+        }
     }
 
     /**
@@ -446,7 +490,7 @@ public class EsCountService {
      * @param field
      * @param detailDTOS
      */
-    public void getChildCountDTOS(Aggregate agg, String field,Integer fieldType, Integer topN,
+    public void getChildCountDTOS(Aggregate agg, String field, Integer fieldType, Integer topN,
                                   List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
         esCountDTO.setAllNumber(agg.children().docCount());
         Aggregate childAgg = agg.children().aggregations().get("childAgg");
@@ -491,7 +535,9 @@ public class EsCountService {
      * @param detailDTOS
      */
     public void getChildAnalysisDTOS(Aggregate agg, String field, Integer fieldType, Integer topN,
-                                     List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO, String firstName) {
+                                     List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO,
+                                     String firstName, Map<String, List<EsCountDetailDTO>> map,List<String> values) {
+        List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
         Aggregate childAgg = agg.children().aggregations().get("childAgg");
         List<StringTermsBucket> list = childAgg.sterms().buckets().array();
         list.forEach(bucket -> {
@@ -505,22 +551,70 @@ public class EsCountService {
                 dto.setNumber(termsBucket.docCount());
                 dto.setFirstName(firstName);
                 dto.setTopN(topN);
-                if (dto.getNumber() > 0) {
-                    detailDTOS.add(dto);
-                    if (fieldType == null || fieldType != 6) {
-                        Long docCount = aggregate.sterms().sumOtherDocCount();
-                        EsCountDetailDTO detail = new EsCountDetailDTO();
-                        detail.setField(field);
-                        detail.setName("未选择");
-                        detail.setNumber(docCount);
-                        detail.setTopN(topN);
-                        if (!detailDTOS.contains(detail)) {
-                            detailDTOS.add(detail);
-                        }
+                countDetailDTOS.add(dto);
+                if (fieldType == null || fieldType != 6) {
+                    Long docCount = aggregate.sterms().sumOtherDocCount();
+                    EsCountDetailDTO detail = new EsCountDetailDTO();
+                    detail.setField(field);
+                    detail.setName("未选择");
+                    detail.setNumber(docCount);
+                    detail.setTopN(topN);
+                    if (!countDetailDTOS.contains(detail)) {
+                        countDetailDTOS.add(detail);
                     }
                 }
+//                if (dto.getNumber() > 0) {
+//                    detailDTOS.add(dto);
+//                    if (fieldType == null || fieldType != 6) {
+//                        Long docCount = aggregate.sterms().sumOtherDocCount();
+//                        EsCountDetailDTO detail = new EsCountDetailDTO();
+//                        detail.setField(field);
+//                        detail.setName("未选择");
+//                        detail.setNumber(docCount);
+//                        detail.setTopN(topN);
+//                        if (!detailDTOS.contains(detail)) {
+//                            detailDTOS.add(detail);
+//                        }
+//                    }
+//                }
             });
         });
+
+        List<String> strs = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(values)) {
+            strs.addAll(values);
+        }
+        if (StringUtils.isNotEmpty(firstName)) {
+            countDetailDTOS.removeIf(dto -> dto.getName().equals("其他"));
+            if (countDetailDTOS.size() != values.size()) {
+                for (EsCountDetailDTO detailDTO : countDetailDTOS) {
+                    strs.removeIf(i -> i.equals(detailDTO.getName()));
+                }
+                for (String value : strs) {
+                    EsCountDetailDTO detailDTO = new EsCountDetailDTO();
+                    detailDTO.setName(value);
+                    detailDTO.setFirstName(firstName);
+                    detailDTO.setField(field);
+                    detailDTO.setNumber(0L);
+                    detailDTO.setTopN(topN);
+                    countDetailDTOS.add(detailDTO);
+                }
+            } else if (countDetailDTOS.isEmpty()) {
+                for (String value : values) {
+                    EsCountDetailDTO detailDTO = new EsCountDetailDTO();
+                    detailDTO.setName(value);
+                    detailDTO.setFirstName(firstName);
+                    detailDTO.setField(field);
+                    detailDTO.setNumber(0L);
+                    detailDTO.setTopN(topN);
+                    countDetailDTOS.add(detailDTO);
+                }
+            }
+            map.put(firstName, countDetailDTOS);
+        } else {
+            detailDTOS.addAll(countDetailDTOS);
+        }
+
     }
 
     /**
@@ -530,7 +624,10 @@ public class EsCountService {
      * @param field
      * @param detailDTOS
      */
-    public void getNumberAnalysisDTOS(Aggregate agg, String field,Integer topN, List<EsCountDetailDTO> detailDTOS,String firstName) {
+    public void getNumberAnalysisDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,
+                                      EsCountDTO esCountDTO, String firstName,
+                                      Map<String, List<EsCountDetailDTO>> map,List<String> values) {
+        List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
         List<RangeBucket> list = agg.range().buckets().array();
         for (RangeBucket bucket : list) {
             EsCountDetailDTO dto = new EsCountDetailDTO();
@@ -539,9 +636,45 @@ public class EsCountService {
             dto.setNumber(bucket.docCount());
             dto.setTopN(topN);
             dto.setFirstName(firstName);
-            if (dto.getNumber() > 0) {
-                detailDTOS.add(dto);
+            countDetailDTOS.add(dto);
+//            if (dto.getNumber() > 0) {
+//                detailDTOS.add(dto);
+//            }
+        }
+
+        List<String> strs = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(values)) {
+            strs.addAll(values);
+        }
+        if (StringUtils.isNotEmpty(firstName)) {
+            countDetailDTOS.removeIf(dto -> dto.getName().equals("其他"));
+            if (countDetailDTOS.size() != values.size()) {
+                for (EsCountDetailDTO detailDTO : countDetailDTOS) {
+                    strs.removeIf(i -> i.equals(detailDTO.getName()));
+                }
+                for (String value : strs) {
+                    EsCountDetailDTO detailDTO = new EsCountDetailDTO();
+                    detailDTO.setName(value);
+                    detailDTO.setFirstName(firstName);
+                    detailDTO.setField(field);
+                    detailDTO.setNumber(0L);
+                    detailDTO.setTopN(topN);
+                    countDetailDTOS.add(detailDTO);
+                }
+            } else if (countDetailDTOS.isEmpty()) {
+                for (String value : values) {
+                    EsCountDetailDTO detailDTO = new EsCountDetailDTO();
+                    detailDTO.setName(value);
+                    detailDTO.setFirstName(firstName);
+                    detailDTO.setField(field);
+                    detailDTO.setNumber(0L);
+                    detailDTO.setTopN(topN);
+                    countDetailDTOS.add(detailDTO);
+                }
             }
+            map.put(firstName, countDetailDTOS);
+        } else {
+            detailDTOS.addAll(countDetailDTOS);
         }
     }
 
@@ -588,7 +721,7 @@ public class EsCountService {
                         h1Count += histogramBucket.docCount();
                         dto.setNumber(h1Count);
                     }
-                    if (month.after(halfYearDate)){
+                    if (month.after(halfYearDate)) {
                         h2Count += histogramBucket.docCount();
                         dto2.setNumber(h2Count);
                     }
@@ -633,9 +766,7 @@ public class EsCountService {
                 if (aggregate != null) {
                     dto.setNumber(aggregate.filter().docCount());
                 }
-                if (dto.getNumber() > 0) {
-                    esCountDetailDTOS.add(dto);
-                }
+                esCountDetailDTOS.add(dto);
             }
         } else {
             list.forEach(bucket -> {
@@ -648,9 +779,7 @@ public class EsCountService {
                 if (aggregate != null) {
                     dto.setNumber(aggregate.filter().docCount());
                 }
-                if (dto.getNumber() > 0) {
-                    esCountDetailDTOS.add(dto);
-                }
+                esCountDetailDTOS.add(dto);
             });
         }
 
@@ -660,18 +789,18 @@ public class EsCountService {
             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);
+//        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);
     }
 
     /**
@@ -682,7 +811,9 @@ public class EsCountService {
      * @param topN
      * @param detailDTOS
      */
-    public void getDateAnalysisDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO, String firstName) {
+    public void getDateAnalysisDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,
+                                    EsCountDTO esCountDTO, String firstName,
+                                    Map<String, List<EsCountDetailDTO>> map,List<String> values) {
         List<RangeBucket> list1 = agg.dateRange().buckets().array();
         List<EsCountDetailDTO> esCountDetailDTOS = new ArrayList<>();
         for (RangeBucket bucket : list1) {
@@ -692,14 +823,47 @@ public class EsCountService {
             dto.setName(bucket.key());
             dto.setNumber(bucket.docCount());
             dto.setTopN(topN);
-            if (dto.getNumber() > 0) {
-                esCountDetailDTOS.add(dto);
-            }
+            esCountDetailDTOS.add(dto);
         }
         if (!CollectionUtils.isEmpty(esCountDetailDTOS)) {
             List<EsCountDetailDTO> collect = esCountDetailDTOS.stream()
                     .sorted(Comparator.comparing(EsCountDetailDTO::getName).reversed()).limit(topN).collect(Collectors.toList());
-            detailDTOS.addAll(collect);
+
+            List<String> strs = new ArrayList<>();
+            if (!CollectionUtils.isEmpty(values)) {
+                strs.addAll(values);
+            }
+            if (StringUtils.isNotEmpty(firstName)) {
+                collect.removeIf(dto -> dto.getName().equals("其他"));
+                if (collect.size() != values.size()) {
+                    for (EsCountDetailDTO detailDTO : collect) {
+                        strs.removeIf(i -> i.equals(detailDTO.getName()));
+                    }
+                    for (String value : strs) {
+                        EsCountDetailDTO detailDTO = new EsCountDetailDTO();
+                        detailDTO.setName(value);
+                        detailDTO.setFirstName(firstName);
+                        detailDTO.setField(field);
+                        detailDTO.setNumber(0L);
+                        detailDTO.setTopN(topN);
+                        collect.add(detailDTO);
+                    }
+                } else if (collect.isEmpty()) {
+                    for (String value : values) {
+                        EsCountDetailDTO detailDTO = new EsCountDetailDTO();
+                        detailDTO.setName(value);
+                        detailDTO.setFirstName(firstName);
+                        detailDTO.setField(field);
+                        detailDTO.setNumber(0L);
+                        detailDTO.setTopN(topN);
+                        collect.add(detailDTO);
+                    }
+                }
+                map.put(firstName, collect);
+            } else {
+                detailDTOS.addAll(collect);
+            }
+
         }
     }
 
@@ -710,14 +874,17 @@ public class EsCountService {
      * @param field
      * @param detailDTOS
      */
-    public void getNestedCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS, String firstName) {
+    public void getNestedCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,
+                                   EsCountDTO esCountDTO, String firstName,
+                                   Map<String, List<EsCountDetailDTO>> map, List<String> values) {
         Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
+        List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
         EsCountDetailDTO countDTO = new EsCountDetailDTO();
         countDTO.setField(field);
         countDTO.setName("其他");
         countDTO.setNumber(termsAgg.sterms().sumOtherDocCount());
         countDTO.setTopN(topN);
-        detailDTOS.add(countDTO);
+        countDetailDTOS.add(countDTO);
         List<StringTermsBucket> list = termsAgg.sterms().buckets().array();
         list.forEach(bucket -> {
             EsCountDetailDTO dto = new EsCountDetailDTO();
@@ -730,10 +897,46 @@ public class EsCountService {
             if (aggregate != null) {
                 dto.setNumber(aggregate.filter().docCount());
             }
-            if (dto.getNumber() > 0) {
-                detailDTOS.add(dto);
-            }
+            countDetailDTOS.add(dto);
+//            if (dto.getNumber() > 0) {
+//                detailDTOS.add(dto);
+//            }
         });
+
+        List<String> strs = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(values)) {
+            strs.addAll(values);
+        }
+        if (StringUtils.isNotEmpty(firstName)) {
+            countDetailDTOS.removeIf(dto -> dto.getName().equals("其他"));
+            if (countDetailDTOS.size() != values.size()) {
+                for (EsCountDetailDTO detailDTO : countDetailDTOS) {
+                    strs.removeIf(i -> i.equals(detailDTO.getName()));
+                }
+                for (String value : strs) {
+                    EsCountDetailDTO detailDTO = new EsCountDetailDTO();
+                    detailDTO.setName(value);
+                    detailDTO.setFirstName(firstName);
+                    detailDTO.setField(field);
+                    detailDTO.setNumber(0L);
+                    detailDTO.setTopN(topN);
+                    countDetailDTOS.add(detailDTO);
+                }
+            } else if (countDetailDTOS.isEmpty()) {
+                for (String value : values) {
+                    EsCountDetailDTO detailDTO = new EsCountDetailDTO();
+                    detailDTO.setName(value);
+                    detailDTO.setFirstName(firstName);
+                    detailDTO.setField(field);
+                    detailDTO.setNumber(0L);
+                    detailDTO.setTopN(topN);
+                    countDetailDTOS.add(detailDTO);
+                }
+            }
+            map.put(firstName, countDetailDTOS);
+        } else {
+            detailDTOS.addAll(countDetailDTOS);
+        }
     }
 
 }