|
@@ -37,6 +37,7 @@ import cn.cslg.pas.service.common.FileManagerService;
|
|
|
import cn.cslg.pas.service.permissions.PermissionService;
|
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
+import co.elastic.clients.elasticsearch._types.ElasticsearchException;
|
|
|
import co.elastic.clients.elasticsearch._types.SortOptions;
|
|
|
import co.elastic.clients.elasticsearch._types.SortOrder;
|
|
|
import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
|
|
@@ -61,6 +62,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.text.ParseException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -108,11 +110,16 @@ public class EsPatentService {
|
|
|
Query q3 = QueryBuilders.term(t -> t.field("grant_no.keyword").value(vo.getPatentNo()));
|
|
|
Query query = QueryBuilders.bool(i -> i.should(q1, q2, q3));
|
|
|
builder.query(query);
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
|
Patent esMess = hit.source();
|
|
|
- dto = esService.getPatentColumnDTO(esMess, vo.getProjectId(), hit.id());
|
|
|
+ dto = esService.getPatentColumnDTO(esMess, vo.getProjectId(), hit.id(), "");
|
|
|
//格式化权利要求
|
|
|
List<Text> claims = dto.getClaim();
|
|
|
if (claims != null && claims.size() > 0) {
|
|
@@ -149,7 +156,12 @@ public class EsPatentService {
|
|
|
if (!CollectionUtils.isEmpty(queries)) {
|
|
|
Query query = QueryBuilders.bool(i -> i.should(queries));
|
|
|
builder.query(query);
|
|
|
- SearchResponse<LegalEvent> response = client.search(builder.build(), LegalEvent.class);
|
|
|
+ SearchResponse<LegalEvent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), LegalEvent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<LegalEvent>> hits = response.hits().hits();
|
|
|
for (Hit<LegalEvent> hit : hits) {
|
|
|
LegalEvent event = hit.source();
|
|
@@ -199,7 +211,12 @@ public class EsPatentService {
|
|
|
Query query = QueryBuilders.hasParent(i -> i.parentType("patent").query(ids));
|
|
|
Query q = QueryBuilders.bool(i -> i.must(nested, query));
|
|
|
builder.query(q);
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
List<PatentMergePerson> list = new ArrayList<>();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
@@ -228,7 +245,12 @@ public class EsPatentService {
|
|
|
Query query = QueryBuilders.hasParent(i -> i.parentType("patent").query(ids));
|
|
|
Query q = QueryBuilders.bool(i -> i.must(nested, query));
|
|
|
builder.query(q);
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
List<PatentMergePerson> list = new ArrayList<>();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
@@ -257,7 +279,12 @@ public class EsPatentService {
|
|
|
Query query = QueryBuilders.hasParent(i -> i.parentType("patent").query(ids));
|
|
|
Query q = QueryBuilders.bool(i -> i.must(nested, query));
|
|
|
builder.query(q);
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
List<PatentMergePerson> list = new ArrayList<>();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
@@ -366,7 +393,12 @@ public class EsPatentService {
|
|
|
if (pageNum > 0 && pageSize > 0) {
|
|
|
builder.from((pageNum - 1) * pageSize).size(pageSize);
|
|
|
}
|
|
|
- SearchResponse<PatentFamilyMessage> response = client.search(builder.build(), PatentFamilyMessage.class);
|
|
|
+ SearchResponse<PatentFamilyMessage> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), PatentFamilyMessage.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<PatentFamilyMessage>> hits = response.hits().hits();
|
|
|
List<PatentKinDTO> kinDTOS = new ArrayList<>();
|
|
|
for (Hit<PatentFamilyMessage> hit : hits) {
|
|
@@ -453,7 +485,12 @@ public class EsPatentService {
|
|
|
// if (pageNum > 0 && pageSize > 0) {
|
|
|
// builder.from((pageNum - 1) * pageSize).size(pageSize);
|
|
|
// }
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
|
PatentKinDTO kinDTO = new PatentKinDTO();
|
|
@@ -503,7 +540,12 @@ public class EsPatentService {
|
|
|
Query bool1 = QueryBuilders.bool(i -> i.must(q, query));
|
|
|
builder.query(bool1);
|
|
|
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
|
Patent patent = hit.source();
|
|
@@ -525,7 +567,7 @@ public class EsPatentService {
|
|
|
*/
|
|
|
public List<Patent> getPatentsByNo(List<String> patentNos, Boolean ifGetAll, Long current, Long size) throws Exception {
|
|
|
List<Patent> patentList = new ArrayList<>();
|
|
|
- if(patentNos==null||patentNos.size()==0){
|
|
|
+ if (patentNos == null || patentNos.size() == 0) {
|
|
|
return patentList;
|
|
|
}
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
@@ -554,7 +596,12 @@ public class EsPatentService {
|
|
|
} else {
|
|
|
builder.from(0).size(10000);
|
|
|
}
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
if (hits != null && hits.size() > 0) {
|
|
|
hits.forEach(item -> {
|
|
@@ -566,6 +613,56 @@ public class EsPatentService {
|
|
|
return patentList;
|
|
|
}
|
|
|
|
|
|
+ public List<PatentColumnDTO> getPatentsByNo1(List<String> patentNos, Boolean ifGetAll, Long current, Long size, Integer projectId) throws Exception {
|
|
|
+ List<PatentColumnDTO> patentList = new ArrayList<>();
|
|
|
+ if (patentNos == null || patentNos.size() == 0) {
|
|
|
+ return patentList;
|
|
|
+ }
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+ List<Query> querys = new ArrayList<>();
|
|
|
+ for (String patentNo : patentNos) {
|
|
|
+ Query q1 = QueryBuilders.term(t -> t.field("app_no.keyword").value(patentNo));
|
|
|
+ //公开号
|
|
|
+ Query q2 = QueryBuilders.term(t -> t.field("public_no.keyword").value(patentNo));
|
|
|
+ //授权号
|
|
|
+ Query q3 = QueryBuilders.term(t -> t.field("grant_no.keyword").value(patentNo));
|
|
|
+ Query query = QueryBuilders.bool(i -> i.should(q1, q2, q3));
|
|
|
+ querys.add(query);
|
|
|
+ }
|
|
|
+ Query finalQuery = QueryBuilders.bool((i -> i.should(querys)));
|
|
|
+ builder.query(finalQuery);
|
|
|
+ if (!ifGetAll) {
|
|
|
+ List<String> reSources = this.rePatentSource();
|
|
|
+ builder.source(sourceOptionsBuilder -> sourceOptionsBuilder
|
|
|
+ .filter(fieldSourceBuilder -> fieldSourceBuilder
|
|
|
+ .includes(reSources)));
|
|
|
+ }
|
|
|
+ if (current != null && size != null && current > 0 && size > 0) {
|
|
|
+ builder.from((current.intValue() - 1) * size.intValue()).size(size.intValue());
|
|
|
+ } else {
|
|
|
+ builder.from(0).size(10000);
|
|
|
+ }
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
+ if (hits != null && hits.size() > 0) {
|
|
|
+ hits.forEach(item -> {
|
|
|
+ Patent patent = item.source();
|
|
|
+ String id = item.id();
|
|
|
+ PatentColumnDTO columnDTO = esService.getPatentColumnDTO(patent, projectId, id, "1");
|
|
|
+ patentList.add(columnDTO);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return patentList;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private List<String> rePatentSource() {
|
|
|
List<String> rePatentSource = new ArrayList<>();
|
|
@@ -601,7 +698,12 @@ public class EsPatentService {
|
|
|
esPatentCommonVO.setSize(null);
|
|
|
SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
|
|
|
Records records = new Records();
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
|
PatentPageMessageVO patentPageMessageVO = new PatentPageMessageVO();
|
|
@@ -655,7 +757,12 @@ public class EsPatentService {
|
|
|
.filter(fieldSourceBuilder -> fieldSourceBuilder
|
|
|
.includes(reSources)));
|
|
|
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
|
if (hits != null && hits.size() > 0) {
|
|
@@ -679,7 +786,12 @@ public class EsPatentService {
|
|
|
builder.source(sourceOptionsBuilder -> sourceOptionsBuilder
|
|
|
.filter(fieldSourceBuilder -> fieldSourceBuilder
|
|
|
.includes(reSources)));
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
return response.hits().total().value();
|
|
|
}
|
|
|
|
|
@@ -763,17 +875,16 @@ public class EsPatentService {
|
|
|
}
|
|
|
String condition = esService.appendIdsCondition(searchCondition, taskId, productFrom, projectId, productId);
|
|
|
|
|
|
- Query q =null;
|
|
|
- if(condition==null||condition.trim().equals("")){
|
|
|
- q =QueryBuilders.exists(i->i.field("patent_no"));
|
|
|
- }
|
|
|
- else {
|
|
|
- //1. 解析检索条件
|
|
|
- treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
- //3. 从es中检索数据
|
|
|
- q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent", projectId);
|
|
|
+ Query q = null;
|
|
|
+ if (StringUtils.isEmpty(condition)) {
|
|
|
+ q = QueryBuilders.exists(i -> i.field("patent_no"));
|
|
|
+ } else {
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
+ //3. 从es中检索数据
|
|
|
+ q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent", projectId);
|
|
|
}
|
|
|
- Query finalQ=q;
|
|
|
+ Query finalQ = q;
|
|
|
Query reQuery = null;
|
|
|
if (patentNos != null && patentNos.size() > 0) {
|
|
|
List<Query> notInQuery = this.getNoNotInQuery(patentNos);
|
|
@@ -797,7 +908,12 @@ public class EsPatentService {
|
|
|
builder.index("patent");
|
|
|
Query q = QueryBuilders.ids(i -> i.values(ids));
|
|
|
builder.query(q);
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
long total = response.hits().total().value();
|
|
|
if (total > 0) {
|
|
|
patents = response.hits().hits();
|
|
@@ -820,7 +936,12 @@ public class EsPatentService {
|
|
|
esPatentCommonVO.setStartNum(startNum);
|
|
|
esPatentCommonVO.setEndNum(endNum);
|
|
|
SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
|
if ((patentNos == null || patentNos.size() == 0) || (!patentNos.contains(hit.source().getPatentNo()))) {
|
|
@@ -865,7 +986,12 @@ public class EsPatentService {
|
|
|
FieldCollapse collapse = FieldCollapse.of(i -> i.field("project_id"));
|
|
|
builder.collapse(collapse);
|
|
|
builder.trackTotalHits(i -> i.enabled(true));
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), Patent.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "ES检索失败");
|
|
|
+ }
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
if (hits != null && hits.size() > 0) {
|
|
|
hits.forEach(item -> {
|
|
@@ -879,16 +1005,15 @@ public class EsPatentService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
public PatentNoWithIdVO addPatentToProject(PatentNoWithIdVO patentWithIdVO, Integer projectId) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
String patentId = patentWithIdVO.getId();
|
|
|
- if(patentId==null){
|
|
|
+ if (patentId == null) {
|
|
|
PatentWithIdVO patentWithIdVO1 = esService.getIdByPatentNo(patentWithIdVO.getPatentNo());
|
|
|
- patentId =patentWithIdVO1.getId();
|
|
|
+ patentId = patentWithIdVO1.getId();
|
|
|
}
|
|
|
Boolean ifInproject = esService.searchPatent(patentId, projectId);
|
|
|
if (!ifInproject) {
|
|
@@ -911,6 +1036,7 @@ public class EsPatentService {
|
|
|
/**
|
|
|
* lrj
|
|
|
* 为导入专利向量建立的方法,不具有普遍性,其他功能勿用
|
|
|
+ *
|
|
|
* @param queryRequest
|
|
|
* @return
|
|
|
* @throws Exception
|
|
@@ -933,15 +1059,14 @@ public class EsPatentService {
|
|
|
.includes(reSources)));
|
|
|
//解除最大条数限制
|
|
|
builder.trackTotalHits(i -> i.enabled(true));
|
|
|
- Query query =null;
|
|
|
- if(projectId!=null) {
|
|
|
- query= QueryBuilders.hasChild(child -> child.type("project")
|
|
|
+ Query query = null;
|
|
|
+ if (projectId != null) {
|
|
|
+ query = QueryBuilders.hasChild(child -> child.type("project")
|
|
|
.query(org.springframework.data.elasticsearch.client.elc.QueryBuilders.matchQueryAsQuery("project_id", projectId.toString(), null, null)));
|
|
|
+ } else {
|
|
|
+ query = QueryBuilders.exists(i -> i.field("patent_no"));
|
|
|
}
|
|
|
- else {
|
|
|
- query=QueryBuilders.exists(i->i.field("patent_no"));
|
|
|
- }
|
|
|
- SearchResponse<Patent> response = null;
|
|
|
+ SearchResponse<Patent> response = null;
|
|
|
builder.query(query);
|
|
|
|
|
|
if (current > 0 && size > 0) {
|
|
@@ -952,18 +1077,18 @@ public class EsPatentService {
|
|
|
try {
|
|
|
response = client.search(builder.build(), Patent.class);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- throw new XiaoShiException("检索错误,请检查检索式");
|
|
|
+// e.printStackTrace();
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "检索错误,请检查检索式");
|
|
|
}
|
|
|
List<PatentColumnDTO> list = new ArrayList<>();
|
|
|
List<Hit<Patent>> hits = response.hits().hits();
|
|
|
long total = 0L;
|
|
|
- total = response.hits().total().value();
|
|
|
+ total = response.hits().total().value();
|
|
|
for (Hit<Patent> hit : hits) {
|
|
|
String id = hit.id();
|
|
|
Patent esMess = hit.source();
|
|
|
PatentColumnDTO columnDTO = new PatentColumnDTO();
|
|
|
- BeanUtils.copyProperties(esMess,columnDTO);
|
|
|
+ BeanUtils.copyProperties(esMess, columnDTO);
|
|
|
columnDTO.setPatentId(id);
|
|
|
list.add(columnDTO);
|
|
|
}
|