文档库--搜索中心

This commit is contained in:
zhn
2022-03-15 13:51:59 +08:00
parent 5092a992aa
commit 4df94f312f
8 changed files with 330 additions and 282 deletions
@@ -266,7 +266,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
* 查询条件
* @param flag
* @param cut
* @param searchFlag 搜索中心标识(searchFlag=search时查询的是搜索中心的查询条件)
* @param searchFlag 搜索中心标识 searchFlag = 0时,查询下拉,树形,日期等字段 type = 1时,查询输入框字段
* @return
*/
@Override
@@ -274,8 +274,20 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList(flag);
if (fieldList.size() != 0) {
//过滤出搜索条件()
if("search".equals(searchFlag)){
fieldList = fieldList.stream().filter(e -> YesOrNoEnum.YES.getValue().equals(String.valueOf(e.getIsShowSearch()))).collect(Collectors.toList());
if(StringUtils.isNotBlank(searchFlag)){
if("1".equals(searchFlag)){
//搜索中心输入框
fieldList = fieldList.stream()
.filter(e -> YesOrNoEnum.YES.getValue().equals(String.valueOf(e.getIsShowSearch()))
&& (FieldTypeEnum.TEXT_STRING.getValue().equals(e.getFieldShowType()) || FieldTypeEnum.TEXT_NUMBER.getValue().equals(e.getFieldShowType())))
.collect(Collectors.toList());
}else{
//搜索中心下拉,树形,日期等字段
fieldList = fieldList.stream()
.filter(e -> YesOrNoEnum.YES.getValue().equals(String.valueOf(e.getIsShowSearch()))
&& (!FieldTypeEnum.TEXT_STRING.getValue().equals(e.getFieldShowType()) || !FieldTypeEnum.TEXT_NUMBER.getValue().equals(e.getFieldShowType())))
.collect(Collectors.toList());
}
}else{
fieldList = fieldList.stream().filter(e -> YesOrNoEnum.YES.getValue().equals(String.valueOf(e.getIsQuery()))).collect(Collectors.toList());
}
@@ -0,0 +1,77 @@
package com.jero.modules.searchcenter.controller;
import com.alibaba.fastjson.JSONObject;
import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog;
import com.jero.modules.searchcenter.service.impl.DocumentSearchServiceImpl;
import com.jero.modules.searchcenter.service.impl.IDocumentSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @description
* @date 2022/3/14 9:56
* @auth zhn
*/
@Api(tags="搜索中心")
@RestController
@RequestMapping("/search")
@Slf4j
public class DocumentSearchController {
@Autowired
private IDocumentSearchService iDocumentSearchService;
/**
* 列表查询条件 标识传 1-->用于查询文档库字段属性
* @param flag 标识传 1-->用于查询文档库字段属性
* @param cut 中英文切换
* @param searchFlag 搜索中心标识 searchFlag = 0时,查询下拉,树形,日期等字段 type = 1时,查询输入框字段
* @return
*/
@AutoLog(value = "文档库信息表-查询条件")
@ApiOperation(value="文档库信息表-查询条件", notes="文档库信息表-查询条件")
@GetMapping(value = "/queryCondition")
public Result<List<Map<String,Object>>> queryCondition(@RequestParam(name="flag",required=true) String flag,
@RequestParam(name="cut",required=true) String cut,
@RequestParam(name="searchFlag",required=true) String searchFlag) {
List<Map<String,Object>> list = iDocumentSearchService.queryCondition(flag,cut,searchFlag);
return Result.OK(list);
}
/**
* 列表表头
* @param flag 标识传 1-->用于查询文档库字段属性
* @return
*/
@AutoLog(value = "文档库信息表-列表表头")
@ApiOperation(value="文档库信息表-列表表头", notes="文档库信息表-列表表头")
@GetMapping(value = "/getHeader")
public Result<List<Map<String,Object>>> getHeader(@RequestParam(name="flag",required=true) String flag,
@RequestParam(name="cut",required=true) String cut,
@RequestParam(name="searchFlag",required=true) String searchFla) {
List<Map<String,Object>> list = iDocumentSearchService.getHeader(flag,cut,searchFla);
return Result.OK(list);
}
@ApiOperation(value="列表查询", notes="列表查询")
@GetMapping(value = "/getInfoList")
public Result<?> getInfoList(@RequestParam(name="indexName",required=true) String indexName,
@RequestParam(name="typeName",required=true) String typeName,
@RequestParam(name="map",required=false) Map<String,Object> map) {
map =new HashMap<>();
// map.put("_source","serial_number");
// map.put("_source","implement_time");
JSONObject infoList = iDocumentSearchService.getInfoList(indexName, typeName, map);
return Result.OK(infoList);
}
}
@@ -0,0 +1,185 @@
package com.jero.modules.searchcenter.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jero.common.constant.enums.ModuleEnum;
import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.es.JeroElasticsearchTemplate;
import com.jero.common.es.QueryStringBuilder;
import com.jero.generater.modules.online.cgform.entity.OnlCgformField;
import com.jero.generater.modules.online.cgform.service.impl.OnlCgformFieldServiceImpl;
import com.jero.modules.document.enums.FieldTypeEnum;
import com.jero.modules.document.service.IBussDocumentLibraryEOService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* @description
* @date 2022/3/14 10:03
* @auth zhn
*/
@Component
public class DocumentSearchServiceImpl implements IDocumentSearchService {
@Autowired
private IBussDocumentLibraryEOService iBussDocumentLibraryEOService;
@Autowired
private JeroElasticsearchTemplate jeroElasticsearchTemplate;
@Autowired
private OnlCgformFieldServiceImpl onlCgformFieldService;
@Override
public List<Map<String, Object>> queryCondition(String flag, String cut,String searchFlag) {
List<Map<String, Object>> mapList = iBussDocumentLibraryEOService.queryCondition(flag, cut, searchFlag);
//type = 0时,查询下拉,树形,日期等字段 type = 1时,查询输入框字段
return mapList;
}
@Override
public List<Map<String, Object>> getHeader(String flag, String cut,String searchFlag) {
List<Map<String, Object>> header = iBussDocumentLibraryEOService.getHeader(flag, cut, searchFlag);
return header;
}
@Override
public JSONObject getInfoList(String indexName, String typeName, Map<String,Object> map) {
//文档库所有的字段
List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList(ModuleEnum.DOCUMENT_LIBRARY.getValue());
//需要查询的列表字段
List<OnlCgformField> hearOnlCgformFieldList = fieldList.stream()
.filter(e -> YesOrNoEnum.YES.getValue().equals(e.getIsShowSearch())).collect(Collectors.toList());
// List<String> sourceList = new ArrayList<>();
List<String> sourceList = hearOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
//输入框字段
List<OnlCgformField> inputOnlCgformFieldList = fieldList.stream()
.filter(e -> FieldTypeEnum.TEXT_STRING.getValue().equals(e.getFieldShowType())
|| FieldTypeEnum.TEXT_NUMBER.getValue().equals(e.getFieldShowType()))
.collect(Collectors.toList());
List<String> inputFieldList = inputOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldEnName).collect(Collectors.toList());
//下拉,树形,日期等字段
List<OnlCgformField> 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<String> otherFieldList = otherOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldEnName).collect(Collectors.toList());
Map<String,Object> inputMap = new HashMap<>();//条件内容为输入框的
Map<String,Object> otherMap = new HashMap<>();//条件内容为下拉,日期,树形
//区分输入框和下拉,树形,日期等字段
if(ObjectUtils.isNotEmpty(map)){
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if(inputFieldList.contains(key)){
inputMap.put(key,value);
}
if(otherFieldList.contains(key)){
otherMap.put(key,value);
}
}
}
JSONArray should = new JSONArray();
//封装输入框查询条件
if(ObjectUtils.isNotEmpty(inputMap)){
Map<String,Object> queryMap = new HashMap<>();
for (Map.Entry<String, Object> entry : inputMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
Map<String,Object> queryMapTemp = new HashMap<>();
queryMapTemp.put(key,value);
queryMap.put("match",queryMapTemp);
}
}
//封装下拉,树形,日期查询条件
JSONArray must = new JSONArray();
if(ObjectUtils.isNotEmpty(otherMap)){
for (Map.Entry<String, Object> entry : otherMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
Map<String,Object> queryMap = new HashMap<>();
Map<String,Object> queryMapTemp = new HashMap<>();
queryMapTemp.put(key,value);
queryMap.put("match",queryMapTemp);
must.add(queryMap);
}
}
indexName = "documentLibrary";
typeName = "document";
// String json = JSON.toJSONString(map);//map转String
// JSONObject queryObject = JSON.parseObject(json);
JSONObject search = null;
try {
//查询所有字段
//封装查询条件
// JSONObject jsonObject = jeroElasticsearchTemplate.buildQueryString( "serial_number","*55*");
// JSONObject jsonObject = jeroElasticsearchTemplate.buildQueryString( "555");
// JSONArray must = new JSONArray();
// must.add("555");
// JSONArray mustNot = new JSONArray();
// mustNot.add("555");
Map<String,Object> queryMap = new HashMap<>();
Map<String,Object> queryMap2 = new HashMap<>();
queryMap2.put("serial_number","555");
// queryMap2.put("title","13");
queryMap.put("match_phrase",queryMap2);
Map<String,Object> queryMap3 = new HashMap<>();
Map<String,Object> queryMap4 = new HashMap<>();
queryMap4.put("title","载货汽车定型试验");
// queryMap2.put("title","13");
queryMap3.put("match",queryMap4);
Map<String,Object> queryMap5 = new HashMap<>();
Map<String,Object> queryMap6 = new HashMap<>();
queryMap6.put("issue_time","2022-03-10");
// queryMap2.put("title","13");
queryMap5.put("match",queryMap6);
should.add(queryMap);
should.add(queryMap3);
// should.add(queryMap5);
must.add(queryMap);
// must.add(queryMap3);
// should.add(queryMap5);
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(must, null, null);
//封装分页和字段值
// sourceList.add("serial_number");
// sourceList.add("title");
JSONObject serial_number = jeroElasticsearchTemplate.buildQuery(sourceList, jsonObject,"issue_time", 0,10);
//
//数据查询
search = jeroElasticsearchTemplate.search(indexName, typeName, serial_number);
// search = jeroElasticsearchTemplate.search(indexName, typeName, new JSONObject());
} catch (Exception e) {
e.printStackTrace();
}
return search;
}
}
@@ -0,0 +1,21 @@
package com.jero.modules.searchcenter.service.impl;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
import java.util.Map;
/**
* @description
* @date 2022/3/14 10:03
* @auth zhn
*/
public interface IDocumentSearchService {
List<Map<String, Object>> queryCondition(String flag, String cut,String searchFlag);
List<Map<String, Object>> getHeader(String flag, String cut,String searchFla);
JSONObject getInfoList(String indexName, String typeName, Map<String,Object> map);
}