From 1fd0df30de0a81f85b7438883fac92de6352a783 Mon Sep 17 00:00:00 2001 From: zhn <947514737@qq.com> Date: Sat, 2 Apr 2022 13:56:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2--=E6=97=B6=E9=97=B4=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=94=B9=E4=B8=BA=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DocumentSearchServiceImpl.java | 60 ++++++++++++++----- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/searchcenter/service/impl/DocumentSearchServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/searchcenter/service/impl/DocumentSearchServiceImpl.java index acfdf071d..d8a4a7f11 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/searchcenter/service/impl/DocumentSearchServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/searchcenter/service/impl/DocumentSearchServiceImpl.java @@ -104,7 +104,11 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { return header; } - + /** + * 文档库列表 + * @param map + * @return + */ @Override public IPage getInfoList(Map map) { boolean flagTemp = jeroElasticsearchTemplate.indexExists(SearchEnum.INDEX_NAME_DOCUMENT.getValue()); @@ -126,16 +130,21 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { .collect(Collectors.toList()); List inputFieldList = inputOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList()); inputFieldList.add("file_text"); - //下拉,树形,日期等字段 + + //下拉,树形,等字段 List otherOnlCgformFieldList = fieldList.stream() .filter(e -> FieldTypeEnum.PULL_SINGLE.getValue().equals(e.getFieldShowType())//下拉单选 || FieldTypeEnum.PULL_MORE.getValue().equals(e.getFieldShowType())//下拉多选 - || FieldTypeEnum.DATE_SINGLE.getValue().equals(e.getFieldShowType())//日期单选 - || FieldTypeEnum.DATE_MORE.getValue().equals(e.getFieldShowType())//日期多选 || FieldTypeEnum.TREE.getValue().equals(e.getFieldShowType()))//树形 .collect(Collectors.toList()); List otherFieldList = otherOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList()); + //日期字段 + List dateOnlCgformFieldList = fieldList.stream() + .filter(e -> FieldTypeEnum.DATE_SINGLE.getValue().equals(e.getFieldShowType()))//日期单选 + .collect(Collectors.toList()); + List dateFieldList = dateOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList()); + //过滤出下拉选 List onlCgformFieldList = fieldList.stream() .filter(e -> FieldTypeEnum.PULL_SINGLE.getValue().equals(e.getFieldShowType()) @@ -161,11 +170,11 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { JSONArray must = new JSONArray(); //处理首次查询条件 if (ObjectUtils.isNotEmpty(mapOne)) { - queryCondition(mapOne, inputFieldList, otherFieldList, must); + queryCondition(mapOne, inputFieldList, otherFieldList,dateFieldList, must); } //处理二次查询条件 if (ObjectUtils.isNotEmpty(mapTwo)) { - queryCondition(mapTwo, inputFieldList, otherFieldList, must); + queryCondition(mapTwo, inputFieldList, otherFieldList,dateFieldList, must); } //处理ids JSONArray should = new JSONArray(); @@ -179,7 +188,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { should.add(queryMap); } } - //列表 //封装查询条件 JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(must, null, should); //1. 封装分页和字段值 @@ -206,7 +214,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { } else { mapTemp.put("collectFlag", "0"); } - //处理订阅 LambdaQueryWrapper lambdaQueryWrapperTemp = new LambdaQueryWrapper<>(); lambdaQueryWrapperTemp.in(OnlCgformSubscribe::getDocumentId, mapTemp.get("id")); @@ -216,7 +223,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { } else { mapTemp.put("subscribeFlag", "0"); } - //格式化时间字段 solveTime(mapTemp); mapList.add(mapTemp); @@ -229,7 +235,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { if (fieldPullList.contains(entry.getKey())) { bussDocumentLibraryEOService.dictItem(sysDictItems, entry, (String) map.get("cut"), fieldList); } - //处理文件 if (FieldFileList.contains(entry.getKey())) { List fileInfos = iOSSFileService.getFileInfos((String) entry.getValue()); @@ -250,9 +255,11 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { } - private void queryCondition(Map mapOne, List inputFieldList, List otherFieldList, JSONArray must) { + private void queryCondition(Map mapOne, List inputFieldList, + List otherFieldList, List dateFieldList,JSONArray must) { Map inputMap = new HashMap<>();//条件内容为输入框的 Map otherMap = new HashMap<>();//条件内容为下拉,日期,树形 + Map dateMap = new HashMap<>();//条件内容为下拉,树形 //区分输入框和下拉,树形,日期等字段 if (ObjectUtils.isNotEmpty(mapOne)) { for (Map.Entry entry : mapOne.entrySet()) { @@ -265,6 +272,9 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { if (otherFieldList.contains(key)) { otherMap.put(key, value); } + if(dateFieldList.contains(key)){ + dateMap.put(key, value); + } } } @@ -284,7 +294,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { } } } - //封装下拉,树形,日期查询条件 + //封装下拉,树形查询条件 if (ObjectUtils.isNotEmpty(otherMap)) { for (Map.Entry entry : otherMap.entrySet()) { String key = entry.getKey(); @@ -300,8 +310,31 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { } } } + //封装时间类型字段查询(时间范围) + if (ObjectUtils.isNotEmpty(dateMap)) { + for (Map.Entry entry : dateMap.entrySet()) { + String key = entry.getKey(); + String value = (String) entry.getValue(); + Map queryMap = new HashMap<>(); + Map queryMapTemp = new HashMap<>(); + if (ObjectUtils.isNotEmpty(value)) { + Map map = new HashMap<>(); + map.put("gte", value.split(",")[0]); + map.put("lte", value.split(",")[1]); + map.put("format", "yyyy-MM-dd"); + queryMap.put(key, map); + queryMapTemp.put("range", queryMap); + must.add(queryMapTemp); + } + } + } } + /** + * 全文 + * @param searchVO + * @return + */ @Override public IPage getFullTextInfoList(SearchVO searchVO) { if(StringUtils.isBlank(searchVO.getSelectValue())){ @@ -321,7 +354,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { } String selectValue = searchVO.getSelectValue(); String selectValueTwo = searchVO.getSelectValueTwo(); - //不查询高亮字段 //1. 需要查询的字段 List fieldList = new ArrayList<>(); fieldList.add("module_type"); @@ -408,7 +440,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { JSONArray jsonArraySort = new JSONArray(); jsonArraySort.add(querySort); - //全部 //1. 条件,分页 JSONObject queryObject = jeroElasticsearchTemplate.buildQuery(null, jsonObject, @@ -435,7 +466,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { //二次搜索结果 List> mapListTwo = new ArrayList<>(); - List> listNew = new ArrayList<>(); for (Map stringObjectMap : list) { Map mapSource = (Map) stringObjectMap.get("_source"); if (StringUtils.isNotBlank(selectValueTwo)) {