文档库--搜索中心
This commit is contained in:
+32
-16
@@ -352,22 +352,6 @@ public class JeroElasticsearchTemplate {
|
||||
*/
|
||||
public boolean delete(String indexName, String typeName, String dataId) {
|
||||
String url = this.getBaseUrl(indexName, typeName).append("/").append(dataId).toString();
|
||||
/* 返回结果(仅供参考)
|
||||
{
|
||||
"_index": "es_demo",
|
||||
"_type": "docs",
|
||||
"_id": "001",
|
||||
"_version": 3,
|
||||
"result": "deleted",
|
||||
"_shards": {
|
||||
"total": 1,
|
||||
"successful": 1,
|
||||
"failed": 0
|
||||
},
|
||||
"_seq_no": 28,
|
||||
"_primary_term": 18
|
||||
}
|
||||
*/
|
||||
try {
|
||||
return "deleted".equals(RestUtil.delete(url).getString("result"));
|
||||
} catch (org.springframework.web.client.HttpClientErrorException ex) {
|
||||
@@ -395,6 +379,19 @@ public class JeroElasticsearchTemplate {
|
||||
log.info("url:" + url + " ,return res: \n" + res.toJSONString());
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* 查询数据
|
||||
* <p>
|
||||
* 请求地址:POST http://{baseUrl}/{indexName}/{typeName}/_search
|
||||
*/
|
||||
public JSONObject search(String indexName, String typeName,JSONObject variables, JSONObject queryObject) {
|
||||
String url = this.getBaseUrl(indexName, typeName).append("/_search").toString();
|
||||
|
||||
log.info("url:" + url + " ,search: " + queryObject.toJSONString());
|
||||
JSONObject res = RestUtil.post(url,variables, queryObject);
|
||||
log.info("url:" + url + " ,return res: \n" + res.toJSONString());
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _source (源滤波器)指定返回的字段,传null返回所有字段
|
||||
@@ -413,6 +410,25 @@ public class JeroElasticsearchTemplate {
|
||||
json.put("size", size);
|
||||
return json;
|
||||
}
|
||||
/**
|
||||
* @param _source (源滤波器)指定返回的字段,传null返回所有字段
|
||||
* @param query
|
||||
* @param sort 排序字段
|
||||
* @param from 从第几条数据开始
|
||||
* @param size 返回条目数
|
||||
* @return { "query": query }
|
||||
*/
|
||||
public JSONObject buildQuery(List<String> _source, JSONObject query,String sort, int from, int size) {
|
||||
JSONObject json = new JSONObject();
|
||||
if (_source != null) {
|
||||
json.put("_source", _source);
|
||||
}
|
||||
json.put("query", query);
|
||||
json.put("from", from);
|
||||
json.put("size", size);
|
||||
// json.put("sort", sort);
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return { "bool" : { "must": must, "must_not": mustNot, "should": should } }
|
||||
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
package com.jero.config.safeFilter.cors;
|
||||
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 设置响应信息
|
||||
*/
|
||||
@WebFilter(urlPatterns = {"/verifyCode/**"})
|
||||
public class CorsFilter implements Filter {
|
||||
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(CorsFilter.class);
|
||||
|
||||
private int size = 0;
|
||||
|
||||
private String origin;
|
||||
|
||||
private String notFilter;
|
||||
|
||||
public CorsFilter(String origin, String notFilter) {
|
||||
this.origin = origin;
|
||||
this.notFilter = notFilter;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
|
||||
final String origin = ((HttpServletRequest) request).getHeader("Origin");
|
||||
//请求头与系统的origin不通则咔嚓
|
||||
// if (Objects.nonNull(origin) || this.origin.contains(origin)){
|
||||
// return;
|
||||
// }
|
||||
if (Objects.nonNull(origin) && !this.origin.contains(origin)){
|
||||
return;
|
||||
}
|
||||
//获取请求路径
|
||||
String url = req.getRequestURL().toString();
|
||||
String[] interfaceNameArr = notFilter.split(",");
|
||||
if (!isMSBrowser(req)){
|
||||
for (String name : interfaceNameArr) {
|
||||
//如果包含,不需要判断Origin是否合法
|
||||
if(url.contains(name)){
|
||||
responseInfo(request, response, chain);
|
||||
// return;
|
||||
}
|
||||
}
|
||||
}
|
||||
responseInfo(request, response, chain);
|
||||
}
|
||||
public boolean isMSBrowser(HttpServletRequest request) {
|
||||
String[] IEBrowserSignals = {"MSIE", "Trident"};
|
||||
String userAgent = request.getHeader("User-Agent");
|
||||
for (String signal : IEBrowserSignals) {
|
||||
if (userAgent.contains(signal)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private void responseInfo(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
// HttpServletResponse httpServletResponse = (HttpServletResponse) response;
|
||||
// httpServletResponse.setHeader("Access-Control-Allow-Origin", origin);
|
||||
// httpServletResponse.addHeader("Access-Control-Allow-Headers", "Authorization");
|
||||
// httpServletResponse.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
// httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, HEAD, OPTIONS, PUT, DELETE");
|
||||
// httpServletResponse.setHeader("Access-Control-Max-Age", "3600");
|
||||
// httpServletResponse.setHeader("Content-Security-Policy", "upgrade-insecure-requests;connect-src *");
|
||||
// httpServletResponse.setHeader("X-Content-Type-Options", "nosniff");
|
||||
// httpServletResponse.setHeader("X-XSS-Protection", "1;mode=block");
|
||||
// httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin, Accept, x-auth-token, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, authorization");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
}
|
||||
-126
@@ -1,126 +0,0 @@
|
||||
package com.jero.config.safeFilter.csrf;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* CsrfFilter
|
||||
*/
|
||||
public class CsrfFilter implements Filter {
|
||||
|
||||
public CsrfFilter(String csrfList) {
|
||||
this.csrfList = csrfList;
|
||||
}
|
||||
|
||||
/**
|
||||
* LOGGER
|
||||
*/
|
||||
private static final Log LOGGER = LogFactory.getLog(CsrfFilter.class);
|
||||
|
||||
/**
|
||||
* 从配置文件读取的csrf白名单字符串
|
||||
*/
|
||||
private final String csrfList;
|
||||
|
||||
/**
|
||||
* 白名单
|
||||
*/
|
||||
private List<String> whiteUrls;
|
||||
|
||||
/**
|
||||
* size
|
||||
*/
|
||||
private int size = 0;
|
||||
|
||||
/**
|
||||
* 读取文件
|
||||
*
|
||||
* @param filterConfig
|
||||
*/
|
||||
public void init(FilterConfig filterConfig) {
|
||||
// 读取文件
|
||||
String path = CsrfFilter.class.getResource("/").getFile();
|
||||
// whiteUrls = FileUtil.readAsStringList(path + "csrfWhite.txt");
|
||||
whiteUrls = Arrays.asList(csrfList.split(","));
|
||||
size = whiteUrls.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param request
|
||||
* @param response
|
||||
* @param chain
|
||||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
// try {
|
||||
HttpServletRequest req = (HttpServletRequest) request;
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
// 获取请求url地址
|
||||
String url = req.getRequestURL().toString();
|
||||
String referurl = req.getHeader("Referer");
|
||||
if (isWhiteReq(referurl)) {
|
||||
chain.doFilter(request, response);
|
||||
} else {
|
||||
req.getRequestDispatcher("/").forward(req, res);
|
||||
// 记录跨站请求日志
|
||||
String log = "";
|
||||
String date = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
|
||||
String clientIp = RequestUtils.getClientIp(req);
|
||||
|
||||
log = "跨站请求---->>>" + clientIp + "||" + date + "||" + referurl + "||" + url;
|
||||
LOGGER.warn(log);
|
||||
}
|
||||
|
||||
// } catch (Exception e) {
|
||||
// LOGGER.error("doFilter", e);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是白名单
|
||||
*/
|
||||
private boolean isWhiteReq(String referUrl) {
|
||||
if (referUrl == null || "".equals(referUrl) || size == 0) {
|
||||
return true;
|
||||
} else {
|
||||
String refHost = "";
|
||||
referUrl = referUrl.toLowerCase();
|
||||
if (referUrl.startsWith("http://")) {
|
||||
refHost = referUrl.substring(7);
|
||||
} else if (referUrl.startsWith("https://")) {
|
||||
refHost = referUrl.substring(8);
|
||||
}
|
||||
|
||||
for (String urlTemp : whiteUrls) {
|
||||
if (refHost.contains(urlTemp.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* destroy
|
||||
*/
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.jero.config.safeFilter.csrf;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class RequestUtils {
|
||||
|
||||
public static final String LOGIN_USER = "LOGIN_USER";
|
||||
public static final String LOGIN_USER_ID = "LOGIN_USER_ID";
|
||||
public static final String LOGIN_ROLE_ID = "LOGIN_ROLE_ID";
|
||||
|
||||
/**
|
||||
* 获取客户端IP地址
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static String getClientIp(HttpServletRequest request) {
|
||||
String remoteAddr = "";
|
||||
if (request != null) {
|
||||
remoteAddr = request.getHeader("X-FORWARDED-FOR");
|
||||
if (StringUtils.isEmpty(remoteAddr)) {
|
||||
remoteAddr = request.getRemoteAddr();
|
||||
}
|
||||
}
|
||||
return remoteAddr;
|
||||
}
|
||||
|
||||
public static String getLoginUserId(HttpServletRequest request) {
|
||||
return (String) request.getSession().getAttribute(LOGIN_USER_ID);
|
||||
}
|
||||
|
||||
public static String getLoginRoleId(HttpServletRequest request) {
|
||||
return (String) request.getSession().getAttribute(LOGIN_ROLE_ID);
|
||||
}
|
||||
|
||||
}
|
||||
+15
-3
@@ -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());
|
||||
}
|
||||
|
||||
+77
@@ -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);
|
||||
}
|
||||
}
|
||||
+185
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+21
@@ -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);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user