feat 修改了一些搜索模块

This commit is contained in:
yinglong zhang
2021-06-29 09:07:06 +08:00
parent 26a5022c03
commit 4533960ef9
25 changed files with 512 additions and 46 deletions
@@ -50,7 +50,6 @@ public class ElasticsearchConfig {
if (client != null) {
client.close();
}
}*/
@@ -1,9 +1,12 @@
package com.adc.da.search.config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@Data
@ConfigurationProperties(prefix = "elasticsearch")
public class ElasticsearchProperties {
private String clustername;
@@ -11,35 +14,4 @@ public class ElasticsearchProperties {
private Integer port;
private Integer poolSize;
public String getClustername() {
return clustername;
}
public void setClustername(String clustername) {
this.clustername = clustername;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
public Integer getPoolSize() {
return poolSize;
}
public void setPoolSize(Integer poolSize) {
this.poolSize = poolSize;
}
}
@@ -7,6 +7,7 @@ import com.adc.da.excel.poi.excel.entity.enums.ExcelType;
import com.adc.da.http.PageInfo;
import com.adc.da.person.service.IPersonCollectEOService;
import com.adc.da.search.dto.*;
import com.adc.da.search.entity.CommonSearchInfoEO;
import com.adc.da.search.entity.SarAdvanceSearchVO;
import com.adc.da.search.entity.SeniorSearchInfoEO;
import com.adc.da.search.service.ElasticsearchService;
@@ -14,6 +15,8 @@ import com.adc.da.search.service.SearchCenterService;
import com.adc.da.exception.AdcDaBaseException;
import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result;
import com.adc.da.slrs.tsDictionaryType.entity.TsSearchMenu;
import com.adc.da.slrs.tsDictionaryType.service.ITsDicTypeService;
import com.adc.da.util.IOUtils;
import com.alibaba.fastjson.JSONObject;
@@ -23,10 +26,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.elasticsearch.client.transport.TransportClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -52,6 +52,15 @@ public class SearchCenterController extends BaseController<Map<String, Object>>
@Autowired
private ElasticsearchService elasticsearchService;
@Autowired
private ITsDicTypeService iTsDictypeService;
@ApiOperation("获取筛选条件")
@PostMapping("/getMenu")
public ResponseMessage<List<TsSearchMenu>> getSearchMenu(){
return Result.success(iTsDictypeService.getSearchMenu());
}
/**
*
* @param searchInfoEO
@@ -98,6 +107,14 @@ public class SearchCenterController extends BaseController<Map<String, Object>>
}
}
@ApiOperation("根据多个key去查询")
@PostMapping("/searchByKey")
public void searchByKey(@RequestBody CommonSearchInfoEO commonSearchInfoEO){
searchCenterService.searchByKey(commonSearchInfoEO);
}
@ApiOperation(value = "|SearchCenter|查询用于导出数据")
@PostMapping(value="/searchIdToImport")
public ResponseMessage<String []> searchIdToImport(SeniorSearchInfoEO searchInfoEO){
@@ -0,0 +1,13 @@
package com.adc.da.search.entity;
import lombok.Data;
import java.util.List;
@Data
public class BasicSearchEntity {
private String key;
private String sign;
private String value;
private List<String> values;
}
@@ -0,0 +1,22 @@
package com.adc.da.search.entity;
import lombok.Data;
import java.util.List;
@Data
public class CommonSearchInfoEO {
private List<BasicSearchEntity> searchEntities;
private String searchType;
private String searchIndex;
private String searchBox;
private Integer currents;
private Integer size;
}
@@ -1,5 +1,6 @@
package com.adc.da.search.service;
import com.adc.da.search.entity.CommonSearchInfoEO;
import com.adc.da.search.entity.SeniorSearchInfoEO;
import org.elasticsearch.action.search.SearchResponse;
@@ -27,4 +28,6 @@ public interface SearchCenterService {
List<Map<String, Object>> searchSarBykeyAndHighLightNumber(SeniorSearchInfoEO searchInfoEO) throws Exception;
void searchByKey(CommonSearchInfoEO commonSearchInfoEO);
}
@@ -1,11 +1,10 @@
package com.adc.da.search.service.impl;
import com.adc.da.person.dao.PersonSearchEODao;
import com.adc.da.search.entity.SarAdvanceSearchVO;
import com.adc.da.search.entity.SearchListDto;
import com.adc.da.search.entity.SeniorSearchInfoEO;
import com.adc.da.search.entity.*;
import com.adc.da.search.service.SearchCenterService;
import com.alibaba.fastjson.JSONArray;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.search.SearchRequestBuilder;
@@ -40,6 +39,7 @@ import java.text.SimpleDateFormat;
import java.util.*;
@Component
@Slf4j
public class SearchCenterServiceImpl implements SearchCenterService {
private final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(SearchCenterServiceImpl.class);
@@ -1246,6 +1246,36 @@ public class SearchCenterServiceImpl implements SearchCenterService {
searchInfoEO.getPager().setRowCount((int) response.getHits().getTotalHits());
return result;
}
@Override
public void searchByKey(CommonSearchInfoEO commonSearchInfoEO) {
//写个假的根据字段查询
SearchRequestBuilder searchRequestBuilder;
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
BoolQueryBuilder boolQueryShould = QueryBuilders.boolQuery();
BoolQueryBuilder boolQueryMust = QueryBuilders.boolQuery();
for (BasicSearchEntity entity: commonSearchInfoEO.getSearchEntities()) {
if(entity.getKey()!=null&&entity.getValue()!=null&&(entity.getSign()==null||entity.getSign().equals("=")))boolQueryMust.must(QueryBuilders.wildcardQuery(entity.getKey(),"*"+entity.getValue()+"*"));
}
searchRequestBuilder=client.prepareSearch(commonSearchInfoEO.getSearchIndex())
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setFrom((commonSearchInfoEO.getCurrents()-1)*commonSearchInfoEO.getSize())
.setSize(commonSearchInfoEO.getSize());
boolQueryBuilder.must(QueryBuilders.matchQuery("validFlag", 0));
boolQueryBuilder.must(boolQueryMust);
boolQueryShould.should(boolQueryShould);
searchRequestBuilder.setQuery(boolQueryBuilder);
// 获取查询到的结果
SearchResponse response = searchRequestBuilder.get();
log.info(response.getHits().toString());
}
}