|
@@ -19,10 +19,12 @@ import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
|
import cn.cslg.pas.common.vo.ContentVO;
|
|
|
import cn.cslg.pas.common.vo.EsConfigVO;
|
|
|
import cn.cslg.pas.common.vo.PatentPageMessageVO;
|
|
|
+import cn.cslg.pas.common.vo.PatentWithIdVO;
|
|
|
import cn.cslg.pas.common.vo.business.PatentKinDetailVO;
|
|
|
import cn.cslg.pas.common.vo.business.PatentKinVO;
|
|
|
import cn.cslg.pas.common.vo.business.PatentNoVO;
|
|
|
import cn.cslg.pas.common.vo.business.SelectProductVO;
|
|
|
+import cn.cslg.pas.common.vo.es.EsPatentCommonVO;
|
|
|
import cn.cslg.pas.domain.es.*;
|
|
|
import cn.cslg.pas.mapper.ProductCategoryMapper;
|
|
|
import cn.cslg.pas.mapper.ProductMapper;
|
|
@@ -34,6 +36,8 @@ import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
import co.elastic.clients.elasticsearch._types.SortOptions;
|
|
|
import co.elastic.clients.elasticsearch._types.SortOrder;
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.StringTermsBucket;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
|
import co.elastic.clients.elasticsearch.core.DeleteResponse;
|
|
@@ -81,6 +85,7 @@ public class EsPatentService {
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private EsService esService;
|
|
|
+
|
|
|
/**
|
|
|
* 根据专利号查询专利详情
|
|
|
*
|
|
@@ -98,7 +103,7 @@ public class EsPatentService {
|
|
|
Query q2 = QueryBuilders.term(t -> t.field("public_no.keyword").value(vo.getPatentNo()));
|
|
|
//授权号
|
|
|
Query q3 = QueryBuilders.term(t -> t.field("grant_no.keyword").value(vo.getPatentNo()));
|
|
|
- Query query = QueryBuilders.bool(i -> i.should(q1,q2,q3));
|
|
|
+ Query query = QueryBuilders.bool(i -> i.should(q1, q2, q3));
|
|
|
builder.query(query);
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
@@ -129,14 +134,14 @@ public class EsPatentService {
|
|
|
builder.index("legal_event");
|
|
|
List<Query> queries = new ArrayList<>();
|
|
|
|
|
|
- Query q1 = QueryBuilders.term(i -> i.field("app_no").value(patentNo));
|
|
|
- queries.add(q1);
|
|
|
+ Query q1 = QueryBuilders.term(i -> i.field("app_no").value(patentNo));
|
|
|
+ queries.add(q1);
|
|
|
|
|
|
- Query q2 = QueryBuilders.term(i -> i.field("public_no").value(patentNo));
|
|
|
- queries.add(q2);
|
|
|
+ Query q2 = QueryBuilders.term(i -> i.field("public_no").value(patentNo));
|
|
|
+ queries.add(q2);
|
|
|
|
|
|
- Query q3 = QueryBuilders.term(i -> i.field("grant_no").value(patentNo));
|
|
|
- queries.add(q3);
|
|
|
+ Query q3 = QueryBuilders.term(i -> i.field("grant_no").value(patentNo));
|
|
|
+ queries.add(q3);
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(queries)) {
|
|
|
Query query = QueryBuilders.bool(i -> i.should(queries));
|
|
@@ -290,14 +295,14 @@ public class EsPatentService {
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(systemFiles)) {
|
|
|
SystemFile systemFile1 = systemFiles.stream().filter(item -> item.getGuid().equals(pdfFormat1)).findFirst().orElse(null);
|
|
|
- SystemFile systemFile2 = systemFiles.stream().filter(item->item.getGuid().equals(pdfFormat2)).findFirst().orElse(null);
|
|
|
- if(systemFile1!=null) {
|
|
|
+ SystemFile systemFile2 = systemFiles.stream().filter(item -> item.getGuid().equals(pdfFormat2)).findFirst().orElse(null);
|
|
|
+ if (systemFile1 != null) {
|
|
|
InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
|
|
|
dto.setPdfGuid(pdfFormat1);
|
|
|
dto.setType(0);
|
|
|
list.add(dto);
|
|
|
}
|
|
|
- if(systemFile2!=null) {
|
|
|
+ if (systemFile2 != null) {
|
|
|
InnerPatentPdfDTO dto = new InnerPatentPdfDTO();
|
|
|
dto.setPdfGuid(pdfFormat2);
|
|
|
dto.setType(1);
|
|
@@ -351,8 +356,8 @@ public class EsPatentService {
|
|
|
Query q3 = QueryBuilders.term(t -> t.field("patent.grant_no").value(no));
|
|
|
//同族类型
|
|
|
Query q4 = QueryBuilders.term(t -> t.field("family_type").value(type));
|
|
|
- Query q =QueryBuilders.bool(i->i.should(q1,q2,q3));
|
|
|
- Query bool = QueryBuilders.bool(i -> i.must(q4,q));
|
|
|
+ Query q = QueryBuilders.bool(i -> i.should(q1, q2, q3));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q4, q));
|
|
|
builder.query(bool);
|
|
|
//分页
|
|
|
if (pageNum > 0 && pageSize > 0) {
|
|
@@ -581,56 +586,42 @@ public class EsPatentService {
|
|
|
|
|
|
Long current = queryRequest.getCurrent();
|
|
|
Long size = queryRequest.getSize();
|
|
|
- SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
- //设置查询索引
|
|
|
- builder.index("patent");
|
|
|
- Query q = this.getQuery(queryRequest);
|
|
|
- //4. 返回数据
|
|
|
- builder.query(q);
|
|
|
- //排序
|
|
|
- List<OrderDTO> dtoList = queryRequest.getOrderDTOList();
|
|
|
- if (!CollectionUtils.isEmpty(dtoList)) {
|
|
|
- String json = CommonService.readJsonFile("patent.json");
|
|
|
- List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
- for (OrderDTO orderDTO : dtoList) {
|
|
|
- EsConfigVO configVO = esConfigVOS.stream().filter(item -> item.getField().equals(orderDTO.getOrderBy())).findFirst().orElse(null);
|
|
|
- if (configVO != null) {
|
|
|
- if (orderDTO.getOrderType().equals(IfConstant.NO)) {
|
|
|
- builder.sort(sortOptionsBuilder -> sortOptionsBuilder
|
|
|
- .field(fieldSortBuilder -> fieldSortBuilder
|
|
|
- .field(configVO.getEsField()).order(SortOrder.Asc)));
|
|
|
- } else {
|
|
|
- builder.sort(sortOptionsBuilder -> sortOptionsBuilder
|
|
|
- .field(fieldSortBuilder -> fieldSortBuilder
|
|
|
- .field(configVO.getEsField()).order(SortOrder.Desc)));
|
|
|
- }
|
|
|
- }
|
|
|
+ EsPatentCommonVO esPatentCommonVO = esService.tranPatentRequestToComVO(queryRequest);
|
|
|
+
|
|
|
+ Records records = new Records();
|
|
|
+ if (esPatentCommonVO.getEsField() == null || esPatentCommonVO.getEsField().equals("")) {
|
|
|
+ SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
+ PatentPageMessageVO patentPageMessageVO = new PatentPageMessageVO();
|
|
|
+ patentPageMessageVO.setPatentNo(hit.source().getPatentNo());
|
|
|
+ patentPageMessageVOS.add(patentPageMessageVO);
|
|
|
}
|
|
|
+ records.setTotal(response.hits().total().value());
|
|
|
} else {
|
|
|
- builder.sort(sortOptionsBuilder -> sortOptionsBuilder
|
|
|
- .field(fieldSortBuilder -> fieldSortBuilder
|
|
|
- .field("patent_no.keyword").order(SortOrder.Desc)));
|
|
|
- }
|
|
|
- //分页
|
|
|
- if (current > 0 && size > 0) {
|
|
|
- builder.from(current.intValue() - 1).size(size.intValue());
|
|
|
- }
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
- List<Hit<Patent>> hits = response.hits().hits();
|
|
|
- for (Hit<Patent> hit : hits) {
|
|
|
- PatentPageMessageVO patentPageMessageVO = new PatentPageMessageVO();
|
|
|
- patentPageMessageVO.setPatentNo(hit.source().getPatentNo());
|
|
|
- patentPageMessageVOS.add(patentPageMessageVO);
|
|
|
+ SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ Aggregate statsAgg = response.aggregations().get("statsBucket");
|
|
|
+ Long total = statsAgg.statsBucket().count();
|
|
|
+ records.setTotal(total);
|
|
|
+ Aggregate agg = response.aggregations().get("Agg");
|
|
|
+ List<StringTermsBucket> termsBuckets = agg.sterms().buckets().array();
|
|
|
+
|
|
|
+ for (StringTermsBucket termsBucket : termsBuckets) {
|
|
|
+ PatentPageMessageVO patentPageMessageVO = new PatentPageMessageVO();
|
|
|
+ String key = termsBucket.key().stringValue();
|
|
|
+ PatentWithIdVO patentWithIdVO = esService.getPatentColumnDTOByGroup2(key, esPatentCommonVO.getProjectId(), esPatentCommonVO.getEsField());
|
|
|
+ patentPageMessageVO.setPatentNo(patentWithIdVO.getPatent().getPatentNo());
|
|
|
+ patentPageMessageVOS.add(patentPageMessageVO);
|
|
|
+ }
|
|
|
}
|
|
|
- Records records = new Records();
|
|
|
- records.setTotal(response.hits().total().value());
|
|
|
records.setSize(size);
|
|
|
records.setCurrent(current);
|
|
|
records.setData(patentPageMessageVOS);
|
|
|
return records;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 检索上一页下一页信息
|
|
|
*
|
|
@@ -640,8 +631,8 @@ public class EsPatentService {
|
|
|
public List<Patent> getPatentsWithNotNo(QueryRequest queryRequest, List<String> patentNos) throws Exception {
|
|
|
List<Patent> patentList = new ArrayList<>();
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
- Long current =queryRequest.getCurrent();
|
|
|
- Long size =queryRequest.getSize();
|
|
|
+ Long current = queryRequest.getCurrent();
|
|
|
+ Long size = queryRequest.getSize();
|
|
|
//设置查询索引
|
|
|
builder.index("patent");
|
|
|
Query q = this.getQuery(queryRequest);
|
|
@@ -695,7 +686,7 @@ public class EsPatentService {
|
|
|
public Query getQuery(QueryRequest queryRequest) throws Exception {
|
|
|
String searchCondition = "";
|
|
|
Integer projectId = queryRequest.getProjectId();
|
|
|
- Integer taskId =queryRequest.getTaskId();
|
|
|
+ Integer taskId = queryRequest.getTaskId();
|
|
|
//判断表达式
|
|
|
if (queryRequest instanceof StringRequest) {
|
|
|
searchCondition = ((StringRequest) queryRequest).getSearchQuery();
|
|
@@ -718,8 +709,7 @@ public class EsPatentService {
|
|
|
} else {
|
|
|
searchCondition = "taskId = " + taskId;
|
|
|
}
|
|
|
- }
|
|
|
- else if (projectId != null) {
|
|
|
+ } else if (projectId != null) {
|
|
|
if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
searchCondition = "projectId = " + projectId + " AND " + searchCondition;
|
|
|
} else {
|
|
@@ -739,12 +729,12 @@ public class EsPatentService {
|
|
|
treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
|
//格式化检索式
|
|
|
//3. 从es中检索数据
|
|
|
- Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent",null);
|
|
|
+ Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent", null);
|
|
|
|
|
|
return q;
|
|
|
}
|
|
|
|
|
|
- private List<Query> getNoNotInQuery(List<String> patentNos) {
|
|
|
+ public List<Query> getNoNotInQuery(List<String> patentNos) {
|
|
|
List<Query> queryList = new ArrayList<>();
|
|
|
for (String patentNo : patentNos) {
|
|
|
Query q1 = QueryBuilders.term(t -> t.field("patent_no.keyword").value(patentNo));
|
|
@@ -753,6 +743,37 @@ public class EsPatentService {
|
|
|
return queryList;
|
|
|
}
|
|
|
|
|
|
+ public Query getEntireNotInQuery(EsPatentCommonVO commonVO) throws Exception {
|
|
|
+ Integer projectId = commonVO.getProjectId();
|
|
|
+ Integer productId = commonVO.getProductId();
|
|
|
+ Integer taskId = commonVO.getTaskId();
|
|
|
+ String searchCondition = commonVO.getSearchCondition();
|
|
|
+ String productFrom = commonVO.getProductFrom();
|
|
|
+ List<String> isAdd = commonVO.getIsAdd();
|
|
|
+ List<String> isDelete = commonVO.getIsDelete();
|
|
|
+ List<EsCustomFieldValueDTO> customFields = commonVO.getCustomFields();
|
|
|
+ if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
+ String customFieldCondition = esService.parseCustomField(customFields, projectId, taskId);
|
|
|
+ if (StringUtils.isNotEmpty(searchCondition)) {
|
|
|
+ searchCondition = searchCondition + " AND " + customFieldCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = customFieldCondition;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String condition = esService.appendIdsCondition(searchCondition, taskId, productFrom, projectId, productId);
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
+ //3. 从es中检索数据
|
|
|
+ Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent", projectId);
|
|
|
+ Query reQuery = null;
|
|
|
+ if (isDelete != null && isDelete.size() > 0) {
|
|
|
+ List<Query> notInQuery = this.getNoNotInQuery(isDelete);
|
|
|
+ reQuery = QueryBuilders.bool(i -> i.must(q).mustNot(notInQuery));
|
|
|
+ } else {
|
|
|
+ reQuery = QueryBuilders.bool(i -> i.must(q));
|
|
|
+ }
|
|
|
+ return reQuery;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 根据id查询
|
|
@@ -782,84 +803,42 @@ public class EsPatentService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public List<PatentNoWithIdVO> getPatentIdsWithNotNo(QueryRequest queryRequest, List<String> patentNos,Long startNum,Long endNum) throws Exception {
|
|
|
- List<PatentNoWithIdVO> patentWithIdVOS=new ArrayList<>();
|
|
|
- SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
- Long current =queryRequest.getCurrent();
|
|
|
- Long size =queryRequest.getSize();
|
|
|
- String groupField = queryRequest.getGroupField();
|
|
|
+ public List<PatentNoWithIdVO> getPatentIdsWithNotNo(QueryRequest queryRequest, List<String> patentNos, Long startNum, Long endNum) throws Exception {
|
|
|
+ List<PatentNoWithIdVO> patentWithIdVOS = new ArrayList<>();
|
|
|
|
|
|
- //设置查询索引
|
|
|
- builder.index("patent");
|
|
|
- Query q = this.getQuery(queryRequest);
|
|
|
+ EsPatentCommonVO esPatentCommonVO = esService.tranPatentRequestToComVO(queryRequest);
|
|
|
+ esPatentCommonVO.setIsDelete(patentNos);
|
|
|
|
|
|
- Query reQuery = null;
|
|
|
- if (patentNos != null && patentNos.size() > 0) {
|
|
|
- List<Query> notInQuery = this.getNoNotInQuery(patentNos);
|
|
|
- reQuery = QueryBuilders.bool(i -> i.must(q).mustNot(notInQuery));
|
|
|
- } else {
|
|
|
- reQuery = QueryBuilders.bool(i -> i.must(q));
|
|
|
- }
|
|
|
- //4. 返回数据
|
|
|
- builder.query(reQuery);
|
|
|
- if (startNum > 0 && endNum>0) {
|
|
|
- builder.from(startNum.intValue()-1).size((endNum.intValue()-startNum.intValue())+1);
|
|
|
- }
|
|
|
- List<String> reSources = this.rePatentSource();
|
|
|
- builder.source(sourceOptionsBuilder -> sourceOptionsBuilder
|
|
|
- .filter(fieldSourceBuilder -> fieldSourceBuilder
|
|
|
- .includes(reSources)));
|
|
|
-
|
|
|
- //判断同族分组
|
|
|
- String str = "";
|
|
|
- if (StringUtils.isNotEmpty(groupField)) {
|
|
|
- switch (groupField) {
|
|
|
- case "simpleFamilyId":
|
|
|
- str = "simple_family_id";
|
|
|
- break;
|
|
|
- case "inpadocFamilyId":
|
|
|
- str = "inpadoc_family_id";
|
|
|
- break;
|
|
|
- case "patsnapFamilyId":
|
|
|
- str = "patsnap_family_id";
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- List<SortOptions> optionsList = new ArrayList<>();
|
|
|
- List<OrderDTO> dtoList = queryRequest.getOrderDTOList();
|
|
|
- if (!CollectionUtils.isEmpty(dtoList)) {
|
|
|
- String json = CommonService.readJsonFile("patent.json");
|
|
|
- List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
- for (OrderDTO orderDTO : dtoList) {
|
|
|
- EsConfigVO configVO = esConfigVOS.stream().filter(item -> item.getField().equals(orderDTO.getOrderBy())).findFirst().orElse(null);
|
|
|
- if (configVO != null) {
|
|
|
- if (orderDTO.getOrderType().equals(IfConstant.NO)) {
|
|
|
- SortOptions sortOptions = SortOptions.of(i -> i.field(j -> j.field(configVO.getEsField()).order(SortOrder.Asc).missing(-1)));
|
|
|
- optionsList.add(sortOptions);
|
|
|
- } else {
|
|
|
- SortOptions sortOptions = SortOptions.of(i -> i.field(j -> j.field(configVO.getEsField()).order(SortOrder.Desc).missing(-1)));
|
|
|
- optionsList.add(sortOptions);
|
|
|
- }
|
|
|
- }
|
|
|
+ if (esPatentCommonVO.getEsField() == null || esPatentCommonVO.getEsField().equals("")) {
|
|
|
+ SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
|
|
|
+ if (startNum > 0 && endNum > 0) {
|
|
|
+ builder.from(startNum.intValue() - 1).size((endNum.intValue() - startNum.intValue()) + 1);
|
|
|
}
|
|
|
- } else {
|
|
|
- SortOptions sortOptions = SortOptions.of(i -> i.field(j -> j.field("patent_no.keyword").order(SortOrder.Desc).missing(-1)));
|
|
|
- optionsList.add(sortOptions);
|
|
|
- }
|
|
|
- builder.sort(optionsList);
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
- List<Hit<Patent>> hits = response.hits().hits();
|
|
|
- for (Hit<Patent> hit : hits) {
|
|
|
- if (hits != null && hits.size() > 0) {
|
|
|
- PatentNoWithIdVO patentWithIdVO =new PatentNoWithIdVO();
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
+ PatentNoWithIdVO patentWithIdVO = new PatentNoWithIdVO();
|
|
|
patentWithIdVO.setId(hit.id());
|
|
|
patentWithIdVO.setPatentNo(hit.source().getPatentNo());
|
|
|
patentWithIdVOS.add(patentWithIdVO);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
|
|
|
+ if (startNum > 0 && endNum > 0) {
|
|
|
+ builder.from(startNum.intValue() - 1).size((endNum.intValue() - startNum.intValue()) + 1);
|
|
|
+ }
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ Aggregate agg = response.aggregations().get("Agg");
|
|
|
+ List<StringTermsBucket> termsBuckets = agg.sterms().buckets().array();
|
|
|
+
|
|
|
+ for (StringTermsBucket termsBucket : termsBuckets) {
|
|
|
+ String key = termsBucket.key().stringValue();
|
|
|
+ PatentWithIdVO patentWithIdVO = esService.getPatentColumnDTOByGroup2(key, esPatentCommonVO.getProjectId(), esPatentCommonVO.getEsField());
|
|
|
+ PatentNoWithIdVO patentNoWithIdVO = new PatentNoWithIdVO();
|
|
|
+ patentNoWithIdVO.setId(patentWithIdVO.getId());
|
|
|
+ patentNoWithIdVO.setPatentNo(patentWithIdVO.getPatent().getPatentNo());
|
|
|
+ patentWithIdVOS.add(patentNoWithIdVO);
|
|
|
+ }
|
|
|
}
|
|
|
return patentWithIdVOS;
|
|
|
}
|