Jelajahi Sumber

Merge remote-tracking branch 'origin/master'

lwhhszx 1 tahun lalu
induk
melakukan
7c016311aa

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

@@ -10,6 +10,7 @@ public class EsCountDTO {
     //总数
     private Long allNumber;
     private String condition;
+    private Long remainingNum;
     private List<EsCountDetailDTO> detailDTOS;
     //多维分析返回数据
     private Map<String, List<EsCountDetailDTO>> analyseMap;

+ 1 - 0
src/main/java/cn/cslg/pas/controller/ReferencesController.java

@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
 import java.util.List;
 
 /**
+ * 报告文档
  * @Author xiexiang
  * @Date 2023/12/19
  */

+ 2 - 1
src/main/java/cn/cslg/pas/factorys/EsCountAnalyseBuilderFactory/ChildNestedAnalyseBuilder.java

@@ -35,7 +35,7 @@ public class ChildNestedAnalyseBuilder implements IEsCountAnalysisBuilder{
             Query query = QueryBuilders.wildcard(i -> i.field(field).value(s));
             Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(query,q1)));
             terms = new Aggregation.Builder().terms(new TermsAggregation.Builder()
-                    .field(field).size(100).build())
+                    .field(field).size(topN).build())
                     .aggregations(new HashMap() {{
                         put("filter_agg", filter);
                     }}).build();
@@ -47,6 +47,7 @@ public class ChildNestedAnalyseBuilder implements IEsCountAnalysisBuilder{
                         put("filter_agg", filter);
                     }}).build();
         } else {
+            topN = topN + 1;
             Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(q1)));
             terms = new Aggregation.Builder().terms(new TermsAggregation.Builder()
                     .field(field).size(topN).build())

+ 2 - 1
src/main/java/cn/cslg/pas/factorys/EsCountAnalyseBuilderFactory/NestedCountAnalysisBuilder.java

@@ -38,13 +38,14 @@ public class NestedCountAnalysisBuilder implements IEsCountAnalysisBuilder {
             Query query = QueryBuilders.wildcard(i -> i.field(field).value(s));
             Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(query)));
             terms = new Aggregation.Builder().terms(new TermsAggregation.Builder()
-                    .field(field).size(100).build())
+                    .field(field).size(topN).build())
                     .aggregations(new HashMap() {{
                         put("filter_agg", filter);
                     }}).build();
         } else if (!CollectionUtils.isEmpty(values)) {
             terms = AggregationBuilders.terms(i -> i.field(field).include(j -> j.terms(values)).size(topN));
         } else {
+            topN = topN + 1;
             terms = AggregationBuilders.terms(j -> j.field(field).size(topN));
         }
         Aggregation finalTerms = terms;

+ 2 - 1
src/main/java/cn/cslg/pas/factorys/EsCountAnalyseBuilderFactory/TermsCountAnalysisBuilder.java

@@ -37,13 +37,14 @@ public class TermsCountAnalysisBuilder implements IEsCountAnalysisBuilder {
             Query query = QueryBuilders.wildcard(i -> i.field(field).value(s));
             Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(query)));
             aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
-                    .field(field).size(100).build())
+                    .field(field).size(topN).build())
                     .aggregations(new HashMap() {{
                         put("filter_agg", filter);
                     }}).build();
         } else if (!CollectionUtils.isEmpty(values)) {
             aggregation = AggregationBuilders.terms(i -> i.field(field).include(j -> j.terms(values)).size(topN));
         } else {
+            topN = topN + 1;
             aggregation = AggregationBuilders.terms(i -> i.field(field).size(topN));
         }
         return aggregation;

+ 83 - 43
src/main/java/cn/cslg/pas/service/business/InvalidRecordService.java

@@ -71,6 +71,12 @@ public class InvalidRecordService extends ServiceImpl<InvalidRecordMapper, Inval
     @Autowired
     private AssoProjectFileService assoProjectFileService;
 
+    @Autowired
+    private InvalidDecisionFileService invalidDecisionFileService;
+
+    @Autowired
+    private AssoReportAffairFileService assoReportAffairFileService;
+
     /**
      * 新增or更新
      * @param invalidRecordDTO
@@ -143,6 +149,16 @@ public class InvalidRecordService extends ServiceImpl<InvalidRecordMapper, Inval
                 InvalidRecordVO invalidRecordVO = new InvalidRecordVO();
                 BeanUtils.copyProperties(item, invalidRecordVO);
                 invalidRecordVO.setIfAdd(true);
+
+                LambdaQueryWrapper<AssoOtherPatentInfoFile> queryWrapper1 = new LambdaQueryWrapper<>();
+                queryWrapper1.eq(AssoOtherPatentInfoFile::getOtherPatentInfoId, invalidRecordVO.getId())
+                        .eq(AssoOtherPatentInfoFile::getType, 6);
+                List<AssoOtherPatentInfoFile> assoOtherPatentInfoFiles = assoOtherPatentInfoFileService.list(queryWrapper1);
+                if (!assoOtherPatentInfoFiles.isEmpty()) {
+                    List<String> fileGuids = assoOtherPatentInfoFiles.stream().map(AssoOtherPatentInfoFile::getFileGuid).collect(Collectors.toList());
+                    invalidRecordVO.setFileGuids(fileGuids);
+                }
+
                 invalidRecordVOS.add(invalidRecordVO);
             });
         }
@@ -179,21 +195,14 @@ public class InvalidRecordService extends ServiceImpl<InvalidRecordMapper, Inval
             if (personnel != null) {
                 invalidRecordVO.setCreateName(personnel.getPersonnelName());
             }
-            LambdaQueryWrapper<AssoOtherPatentInfoFile> queryWrapper = new LambdaQueryWrapper<>();
-            queryWrapper.eq(AssoOtherPatentInfoFile::getOtherPatentInfoId, invalidRecordVO.getId())
-                    .eq(AssoOtherPatentInfoFile::getType, 6);
-            List<AssoOtherPatentInfoFile> assoOtherPatentInfoFiles = assoOtherPatentInfoFileService.list(queryWrapper);
-            if (!assoOtherPatentInfoFiles.isEmpty()) {
-                List<String> fileGuids = assoOtherPatentInfoFiles.stream().map(AssoOtherPatentInfoFile::getFileGuid).collect(Collectors.toList());
-                invalidRecordVO.setFileGuids(fileGuids);
-                List<SystemFile> systemFiles = new ArrayList<>();
-                if (fileGuids.size() != 0) {
-                    String res = fileManagerService.getSystemFileFromFMS(fileGuids);
-                    systemFiles = JSONObject.parseArray(res, SystemFile.class);
-                }
-                if (!systemFiles.isEmpty()) {
-                    invalidRecordVO.setSystemFileList(systemFiles);
-                }
+            List<String> fileGuids = invalidRecordVO.getFileGuids();
+            List<SystemFile> systemFiles = new ArrayList<>();
+            if (fileGuids.size() != 0) {
+                String res = fileManagerService.getSystemFileFromFMS(fileGuids);
+                systemFiles = JSONObject.parseArray(res, SystemFile.class);
+            }
+            if (!systemFiles.isEmpty()) {
+                invalidRecordVO.setSystemFileList(systemFiles);
             }
         }
     }
@@ -225,32 +234,13 @@ public class InvalidRecordService extends ServiceImpl<InvalidRecordMapper, Inval
             reportProjects.forEach(item -> {
                 Project project = projectService.getById(item.getProjectId());
                 Integer type = item.getReportType();
-                //报告类型为稳定性分析和第三方意见  查询无效请求书
-                if (type.equals(1) || type.equals(2)) {
-                    InvalidRecordVO invalidRecordVO = new InvalidRecordVO();
-                    invalidRecordVO.setInvalidCaseNum(item.getCaseNumber());
-                    invalidRecordVO.setPatentNo(patentNo);
-                    Integer affairType = 1;
-                    Date time = this.loadInvalidTime(affairType, item);
-                    invalidRecordVO.setInvalidTime(time);
-                    invalidRecordVO.setCreateId(project.getCreateId());
-                    invalidRecordVO.setCreateTime(project.getCreateTime());
-                    List<String> fileGuids = this.loadFileGuids(item.getProjectId());
-                    invalidRecordVO.setFileGuids(fileGuids);
-                    invalidRecordVO.setIfAdd(false);
-                    //带出报告信息
-                    ReportVO reportVO = new ReportVO();
-                    BeanUtils.copyProperties(item, reportVO);
-                    Integer projectId = item.getProjectId();
-                    Project reportProject = projectService.getById(projectId);
-                    reportVO.setReportName(reportProject.getName());
-                    invalidRecordVO.setReportVO(reportVO);
-                    finalVOS.add(invalidRecordVO);
-                } else if (type.equals(7)) {
-                    //报告类型为官方无效  查询行政判决诉讼书
+                if (type.equals(7)) {
+                    //报告类型为官方无效
                     InvalidRecordVO invalidRecordVO = new InvalidRecordVO();
                     invalidRecordVO.setInvalidCaseNum(item.getCaseNumber());
+                    invalidRecordVO.setInvalidApplicant(item.getInvalidApplication());
                     invalidRecordVO.setPatentNo(patentNo);
+                    //无效请求书
                     Integer affairType = 1;
                     Date invalidTime = this.loadInvalidTime(affairType, item);
                     invalidRecordVO.setInvalidTime(invalidTime);
@@ -262,6 +252,10 @@ public class InvalidRecordService extends ServiceImpl<InvalidRecordMapper, Inval
                     List<String> fileGuids = this.loadFileGuids(item.getProjectId());
                     invalidRecordVO.setFileGuids(fileGuids);
                     invalidRecordVO.setIfAdd(false);
+                    //装载结果  先查询行政判决诉讼书
+                    Integer resultType = 5;
+                    String result = this.loadResult(resultType, item);
+                    invalidRecordVO.setResult(result);
                     //带出报告信息
                     ReportVO reportVO = new ReportVO();
                     BeanUtils.copyProperties(item, reportVO);
@@ -290,13 +284,59 @@ public class InvalidRecordService extends ServiceImpl<InvalidRecordMapper, Inval
         }
     }
 
+    public String loadResult(Integer type, ReportProject reportProject){
+        LambdaQueryWrapper<ReportAffair> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(ReportAffair::getAffairType, type)
+                .eq(ReportAffair::getProjectId, reportProject.getProjectId())
+                .orderByDesc(ReportAffair::getCreateTime)
+                .last("LIMIT 1");
+        ReportAffair reportAffair = reportAffairService.getOne(queryWrapper, false);
+        if (reportAffair != null) {
+            return reportAffair.getDescription();
+        } else {
+            Integer affairType = 3;
+            LambdaQueryWrapper<ReportAffair> queryWrapper1 = new LambdaQueryWrapper<>();
+            queryWrapper1.eq(ReportAffair::getAffairType, affairType)
+                    .eq(ReportAffair::getProjectId, reportProject.getProjectId())
+                    .orderByDesc(ReportAffair::getCreateTime)
+                    .last("LIMIT 1");
+            ReportAffair reportAffair1 = reportAffairService.getOne(queryWrapper, false);
+            if (reportAffair1 != null) {
+                Integer reportAffairId2 = reportAffair1.getId();
+                LambdaQueryWrapper<InvalidDecisionFile> queryWrapper2 = new LambdaQueryWrapper<>();
+                queryWrapper2.eq(InvalidDecisionFile::getReportAffairId, reportAffairId2);
+                InvalidDecisionFile invalidDecisionFile = invalidDecisionFileService.getOne(queryWrapper2, false);
+                if (invalidDecisionFile != null) {
+                    return invalidDecisionFile.getDecisionKey();
+                } else {
+                    return null;
+                }
+            } else {
+                return null;
+            }
+        }
+    }
+
+
     public List<String> loadFileGuids(Integer projectId){
         List<String> fileGuids = new ArrayList<>();
-        LambdaQueryWrapper<AssoProjectFile> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(AssoProjectFile::getProjectId, projectId);
-        List<AssoProjectFile> assoProjectFiles = assoProjectFileService.list(queryWrapper);
-        if (!assoProjectFiles.isEmpty()) {
-            fileGuids = assoProjectFiles.stream().map(AssoProjectFile::getFileGuid).collect(Collectors.toList());
+//        LambdaQueryWrapper<AssoProjectFile> queryWrapper = new LambdaQueryWrapper<>();
+//        queryWrapper.eq(AssoProjectFile::getProjectId, projectId);
+//        List<AssoProjectFile> assoProjectFiles = assoProjectFileService.list(queryWrapper);
+//        if (!assoProjectFiles.isEmpty()) {
+//            fileGuids = assoProjectFiles.stream().map(AssoProjectFile::getFileGuid).collect(Collectors.toList());
+//        }
+        LambdaQueryWrapper<ReportAffair> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(ReportAffair::getProjectId, projectId);
+        List<ReportAffair> reportAffairs = reportAffairService.list(queryWrapper);
+        if (!reportAffairs.isEmpty()) {
+            List<Integer> reportAffairIds = reportAffairs.stream().map(ReportAffair::getId).collect(Collectors.toList());
+            LambdaQueryWrapper<AssoReportAffairFile> queryWrapper1 = new LambdaQueryWrapper<>();
+            queryWrapper1.in(AssoReportAffairFile::getReportAffairId, reportAffairIds);
+            List<AssoReportAffairFile> assoReportAffairFiles = assoReportAffairFileService.list(queryWrapper1);
+            if (!assoReportAffairFiles.isEmpty()) {
+                fileGuids = assoReportAffairFiles.stream().map(AssoReportAffairFile::getFileGuid).collect(Collectors.toList());
+            }
         }
         return fileGuids;
     }

+ 25 - 18
src/main/java/cn/cslg/pas/service/business/MergePersonService.java

@@ -669,7 +669,7 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
         builder.index("patent");
-        Query mustQ = QueryBuilders.hasChild(i -> i.type("project").query(j -> j.term(n -> n.field("project_id").value(projectId))));
+//        Query mustQ = QueryBuilders.hasChild(i -> i.type("project").query(j -> j.term(n -> n.field("project_id").value(projectId))));
         if (!CollectionUtils.isEmpty(conditionList)) {
             for (String name : conditionList) {
                 List<Query> queries = new ArrayList<>();
@@ -696,15 +696,15 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
                     Query childQ = QueryBuilders.hasChild(i -> i.type("merge_inventor").query(query));
                     queries.add(childQ);
                 }
-                Query bool = QueryBuilders.bool(i -> i.must(mustQ).should(queries));
-//                builder.size(99);
+                Query bool = QueryBuilders.bool(i -> i.should(queries));
                 builder.query(bool);
                 //分页
                 if (pageNum > 0 && pageSize > 0) {
                     builder.from((pageNum.intValue() - 1) * pageSize.intValue()).size(pageSize.intValue());
                 }
-                builder.trackTotalHits(i -> i.enabled(true));
+//                builder.trackTotalHits(i -> i.enabled(true));
                 SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+                total = response.hits().total().value();
                 List<Hit<Patent>> hits = response.hits().hits();
                 Map<String, Patent> map = new HashMap<>();
                 for (Hit<Patent> hit : hits) {
@@ -895,8 +895,10 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
                 }
             }
 
-            List<GetAllPersonDTO> collect = personList.stream().sorted(Comparator.comparing(GetAllPersonDTO::getName)).collect(Collectors.toList());
-            personDTOList.addAll(collect);
+            List<GetAllPersonDTO> collect = personList.stream().filter(i -> !StringUtils.isEmpty(i.getName())).collect(Collectors.toList());
+            List<GetAllPersonDTO> list = collect.stream().sorted(Comparator.comparing(GetAllPersonDTO::getName)).collect(Collectors.toList());
+
+            personDTOList.addAll(list);
         }
 
 //        List<GetAllPersonDTO> collect = personDTOList.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
@@ -1103,13 +1105,18 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
                         Map<String, List<PatentMergePerson>> inventorMap = this.getChildMergePerson(id, projectId, "merge_inventor");
                         if (!CollectionUtils.isEmpty(inventorMap)) {
                             for (String inventorId : inventorMap.keySet()) {
-                                if (CollectionUtils.isEmpty(nameDatas)) {
-                                    this.delSingleMerge(inventorId, type, name);
-                                }
+//                                if (CollectionUtils.isEmpty(nameDatas)) {
+//                                    this.delSingleMerge(inventorId, type, name);
+//                                }
 
                                 ArrayList<PatentMergePerson> inventorMergeList = new ArrayList<>(mergePersonList);
                                 List<PatentMergePerson> inventorList = inventorMap.get(inventorId);
                                 inventorMergeList.addAll(inventorList);
+                                if (CollectionUtils.isEmpty(nameDatas)) {
+                                    if (!CollectionUtils.isEmpty(inventorMergeList)) {
+                                        inventorMergeList.removeIf(inventor -> inventor.getName().equals(name));
+                                    }
+                                }
                                 //添加子文档
                                 Patent newPatent = new Patent();
                                 PatentJoin patentJoin = new PatentJoin();
@@ -1214,13 +1221,13 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
                             Map<String, List<PatentMergePerson>> appMap = this.getChildMergePerson(id, projectId, "merge_applicant");
                             if (!CollectionUtils.isEmpty(appMap)) {
                                 for (String appId : appMap.keySet()) {
-                                    if (StringUtils.isNotEmpty(name)) {
-                                        this.delSingleMerge(appId, type, name);
-                                    }
 
                                     List<PatentMergePerson> appMergeList = new ArrayList<>(mergePersonList);
                                     List<PatentMergePerson> appList = appMap.get(appId);
                                     appMergeList.addAll(appList);
+                                    if (!CollectionUtils.isEmpty(appMergeList)) {
+                                        appMergeList.removeIf(app -> app.getName().equals(name));
+                                    }
                                     //添加子文档
                                     Patent newPatent = new Patent();
                                     PatentJoin patentJoin = new PatentJoin();
@@ -1243,13 +1250,13 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
                             Map<String, List<PatentMergePerson>> rightMap = this.getChildMergePerson(id, projectId, "merge_right_holder");
                             if (!CollectionUtils.isEmpty(rightMap)) {
                                 for (String rightId : rightMap.keySet()) {
-                                    if (StringUtils.isNotEmpty(name)) {
-                                        this.delSingleMerge(rightId, type, name);
-                                    }
 
                                     ArrayList<PatentMergePerson> rightMergeList = new ArrayList<>(mergePersonList);
                                     List<PatentMergePerson> rightList = rightMap.get(rightId);
                                     rightMergeList.addAll(rightList);
+                                    if (!CollectionUtils.isEmpty(rightMergeList)) {
+                                        rightMergeList.removeIf(right -> right.getName().equals(name));
+                                    }
                                     //添加子文档
                                     Patent newPatent = new Patent();
                                     PatentJoin patentJoin = new PatentJoin();
@@ -1270,13 +1277,13 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
                             Map<String, List<PatentMergePerson>> inventorMap = this.getChildMergePerson(id, projectId, "merge_inventor");
                             if (!CollectionUtils.isEmpty(inventorMap)) {
                                 for (String inventorId : inventorMap.keySet()) {
-                                    if (StringUtils.isNotEmpty(name)) {
-                                        this.delSingleMerge(inventorId, type, name);
-                                    }
 
                                     ArrayList<PatentMergePerson> inventorMergeList = new ArrayList<>(mergePersonList);
                                     List<PatentMergePerson> inventorList = inventorMap.get(inventorId);
                                     inventorMergeList.addAll(inventorList);
+                                    if (!CollectionUtils.isEmpty(inventorMergeList)) {
+                                        inventorMergeList.removeIf(inventor -> inventor.getName().equals(name));
+                                    }
                                     //添加子文档
                                     Patent newPatent = new Patent();
                                     PatentJoin patentJoin = new PatentJoin();

+ 79 - 48
src/main/java/cn/cslg/pas/service/business/es/EsCountService.java

@@ -19,7 +19,6 @@ import cn.cslg.pas.service.business.CommonService;
 import cn.cslg.pas.service.query.FormatQueryService;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
 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.QueryBuilders;
 import co.elastic.clients.elasticsearch.core.SearchRequest;
@@ -37,6 +36,7 @@ import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.stream.Collectors;
 
 @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)) {
             searchCondition = esService.parseCustomField(customFields,projectId,taskId);
         }
@@ -527,32 +542,43 @@ public class EsCountService {
                                  EsCountDTO esCountDTO, String firstName,
                                  Map<String, List<EsCountDetailDTO>> map,List<String> values) {
         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();
         countDTO.setField(field);
         countDTO.setName("其他");
         countDTO.setTopN(topN);
         Long count = agg.sterms().sumOtherDocCount();
         if (count > 0) {
-            countDTO.setNumber(count);
+            countDTO.setNumber(count + otherNum);
             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<>();
         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,
                                  EsCountDTO esCountDTO, String valueOne, String valueTwo) throws ParseException {
         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<>();
         if (StringUtils.isNotEmpty(format) && format.equals("半年")) {
             List<EsCountDetailDTO> detailDTOList = new ArrayList<>();
@@ -940,23 +968,21 @@ public class EsCountService {
         }
 
         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()
                     .sorted(Comparator.comparing(EsCountDetailDTO::getName).reversed()).limit(topN).collect(Collectors.toList());
             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) {
         Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
         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.forEach(bucket -> {
+        for (StringTermsBucket bucket : list) {
             EsCountDetailDTO dto = new EsCountDetailDTO();
             dto.setField(field);
             Aggregate aggregate = bucket.aggregations().get("filter_agg");
@@ -1062,11 +1079,25 @@ public class EsCountService {
                 if (dto.getNumber() > 0) {
                     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<>();
         if (!CollectionUtils.isEmpty(values)) {