|
@@ -8,15 +8,16 @@ import cn.cslg.pas.common.utils.parseQueryToTree.expressManager;
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
import cn.cslg.pas.common.vo.EsConfigVO;
|
|
import cn.cslg.pas.common.vo.EsConfigVO;
|
|
|
|
+import cn.cslg.pas.common.vo.FieldValueVO;
|
|
import cn.cslg.pas.common.vo.PatentWithIdVO;
|
|
import cn.cslg.pas.common.vo.PatentWithIdVO;
|
|
-import cn.cslg.pas.common.vo.es.EsCustomFieldBatchVO;
|
|
|
|
-import cn.cslg.pas.common.vo.es.FieldHistoryVO;
|
|
|
|
-import cn.cslg.pas.common.vo.es.QueryESCustomFieldVO;
|
|
|
|
|
|
+import cn.cslg.pas.common.vo.es.*;
|
|
import cn.cslg.pas.domain.business.CustomField;
|
|
import cn.cslg.pas.domain.business.CustomField;
|
|
|
|
+import cn.cslg.pas.domain.business.CustomOption;
|
|
import cn.cslg.pas.domain.business.TreeNode;
|
|
import cn.cslg.pas.domain.business.TreeNode;
|
|
import cn.cslg.pas.domain.es.*;
|
|
import cn.cslg.pas.domain.es.*;
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
|
|
+import cn.cslg.pas.service.business.CustomOptionService;
|
|
import cn.cslg.pas.service.business.TreeNodeService;
|
|
import cn.cslg.pas.service.business.TreeNodeService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
@@ -54,7 +55,7 @@ public class EsCustomFieldService {
|
|
private final ElasticsearchClient client;
|
|
private final ElasticsearchClient client;
|
|
private final EsService esService;
|
|
private final EsService esService;
|
|
private final TreeNodeService treeNodeService;
|
|
private final TreeNodeService treeNodeService;
|
|
-
|
|
|
|
|
|
+ private final CustomOptionService customOptionService;
|
|
@Autowired
|
|
@Autowired
|
|
private FormatQueryService formatQueryService;
|
|
private FormatQueryService formatQueryService;
|
|
|
|
|
|
@@ -271,6 +272,7 @@ public class EsCustomFieldService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 批量添加自定义栏位值
|
|
* 批量添加自定义栏位值
|
|
|
|
+ *
|
|
* @param vo
|
|
* @param vo
|
|
* @return
|
|
* @return
|
|
* @throws Exception
|
|
* @throws Exception
|
|
@@ -292,7 +294,7 @@ public class EsCustomFieldService {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
- } else if (startNum >= 1 && endNum > 0){
|
|
|
|
|
|
+ } else if (startNum >= 1 && endNum > 0) {
|
|
List<String> patentNos = this.getPatentNos(vo);
|
|
List<String> patentNos = this.getPatentNos(vo);
|
|
for (String patentNo : patentNos) {
|
|
for (String patentNo : patentNos) {
|
|
for (EsCustomFieldDTO fieldDTO : fieldDTOS) {
|
|
for (EsCustomFieldDTO fieldDTO : fieldDTOS) {
|
|
@@ -307,6 +309,7 @@ public class EsCustomFieldService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取专利号列表
|
|
* 获取专利号列表
|
|
|
|
+ *
|
|
* @param vo
|
|
* @param vo
|
|
* @return
|
|
* @return
|
|
* @throws Exception
|
|
* @throws Exception
|
|
@@ -383,7 +386,7 @@ public class EsCustomFieldService {
|
|
|
|
|
|
int number = endNum - startNum;
|
|
int number = endNum - startNum;
|
|
if (startNum > 0 && endNum > startNum) {
|
|
if (startNum > 0 && endNum > startNum) {
|
|
- builder.from(startNum-1).size(number);
|
|
|
|
|
|
+ builder.from(startNum - 1).size(number);
|
|
}
|
|
}
|
|
|
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
@@ -617,6 +620,7 @@ public class EsCustomFieldService {
|
|
return esCustomFieldHistoryHit;
|
|
return esCustomFieldHistoryHit;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
public PatentWithIdVO getPatentLabel(AddPatentLabelDTO addPatentLabelDTO) throws Exception {
|
|
public PatentWithIdVO getPatentLabel(AddPatentLabelDTO addPatentLabelDTO) throws Exception {
|
|
PatentWithIdVO patentWithIdVO = new PatentWithIdVO();
|
|
PatentWithIdVO patentWithIdVO = new PatentWithIdVO();
|
|
Integer projectId = addPatentLabelDTO.getProjectId();
|
|
Integer projectId = addPatentLabelDTO.getProjectId();
|
|
@@ -644,7 +648,7 @@ public class EsCustomFieldService {
|
|
Query q3 = QueryBuilders.hasParent(t -> t.parentType("patent").query(parentQ));
|
|
Query q3 = QueryBuilders.hasParent(t -> t.parentType("patent").query(parentQ));
|
|
|
|
|
|
Query bool = null;
|
|
Query bool = null;
|
|
- bool = QueryBuilders.bool(i -> i.must(q1, q3, q4));
|
|
|
|
|
|
+ bool = QueryBuilders.bool(i -> i.must(q1, q3, q4));
|
|
|
|
|
|
|
|
|
|
builder.query(bool);
|
|
builder.query(bool);
|
|
@@ -662,4 +666,204 @@ public class EsCustomFieldService {
|
|
return patentWithIdVO;
|
|
return patentWithIdVO;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public List<ESCustomField> getPatentCustomFields(String projectId, String patentId) {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q1 = QueryBuilders.term(t -> t.field("project_id").value(projectId));
|
|
|
|
+ Query q2 = QueryBuilders.parentId(parent -> parent.type("patent").id(patentId));
|
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q2));
|
|
|
|
+ try {
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ hits.forEach(item -> {
|
|
|
|
+ });
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询自定义栏位和值
|
|
|
|
+ *
|
|
|
|
+ * @param esQueryPatentFieldsDTO
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public List<EsPatentFieldsVO> getPatentFields(EsQueryPatentFieldsDTO esQueryPatentFieldsDTO) throws Exception {
|
|
|
|
+ List<EsPatentFieldsVO> esPatentFieldsVOS = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ Integer projectId = esQueryPatentFieldsDTO.getProjectId();
|
|
|
|
+ List<String> patentNos = esQueryPatentFieldsDTO.getPatentNos();
|
|
|
|
+ List<InnerFields> innerFields = esQueryPatentFieldsDTO.getInnerFields();
|
|
|
|
+
|
|
|
|
+ for (String patentNo : patentNos) {
|
|
|
|
+ EsPatentFieldsVO esPatentFieldsVO = new EsPatentFieldsVO();
|
|
|
|
+ esPatentFieldsVO.setPatentNo(patentNo);
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ builder.sort(sortOptionsBuilder -> sortOptionsBuilder
|
|
|
|
+ .field(fieldSortBuilder -> fieldSortBuilder
|
|
|
|
+ .field("custom_field.create_time").order(SortOrder.Desc)));
|
|
|
|
+ Query queries = this.getQueries(patentNo, innerFields, projectId);
|
|
|
|
+ builder.size(999);
|
|
|
|
+ builder.query(queries);
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+ long total = response.hits().total().value();
|
|
|
|
+ List<ESCustomField> esCustomFields = new ArrayList<>();
|
|
|
|
+ List<InnerPatentFieldsVO> innerPatentFieldsVOS = new ArrayList<>();
|
|
|
|
+ if (total > 0) {
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ ESCustomField esCustomField = patent.getESCustomField();
|
|
|
|
+ ESCustomField esCustomField1 = esCustomFields.stream()
|
|
|
|
+ .filter(item -> item.getField().equals(esCustomField.getField()) && item.getFieldType().equals(esCustomField.getFieldType()))
|
|
|
|
+ .findFirst().orElse(null);
|
|
|
|
+
|
|
|
|
+ if (esCustomField1 == null) {
|
|
|
|
+ esCustomFields.add(esCustomField);
|
|
|
|
+ InnerPatentFieldsVO innerPatentFieldsVO = new InnerPatentFieldsVO();
|
|
|
|
+ innerPatentFieldsVO.setField(esCustomField.getField());
|
|
|
|
+ innerPatentFieldsVO.setFieldType(esCustomField.getFieldType());
|
|
|
|
+ List<FieldValueVO> fieldValueVOS = this.getCustomFieldValues(esCustomField.getFieldType(), esCustomField.getFieldValue());
|
|
|
|
+ innerPatentFieldsVO.setFieldValueVOS(fieldValueVOS);
|
|
|
|
+ innerPatentFieldsVOS.add(innerPatentFieldsVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ esPatentFieldsVO.setInnerClassFields(innerPatentFieldsVOS);
|
|
|
|
+ esPatentFieldsVOS.add(esPatentFieldsVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return esPatentFieldsVOS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Query getQueries(String patentNo, List<InnerFields> innerFields, Integer projectId) {
|
|
|
|
+
|
|
|
|
+ Query parentQ1 = QueryBuilders.term(t -> t.field("app_no.keyword").value(patentNo));
|
|
|
|
+
|
|
|
|
+ //公开号
|
|
|
|
+ Query parentQ2 = QueryBuilders.term(t -> t.field("public_no.keyword").value(patentNo));
|
|
|
|
+
|
|
|
|
+ //授权号
|
|
|
|
+ Query parentQ3 = QueryBuilders.term(t -> t.field("grant_no.keyword").value(patentNo));
|
|
|
|
+
|
|
|
|
+ Query parentQ = QueryBuilders.bool(i -> i.should(parentQ1, parentQ2, parentQ3));
|
|
|
|
+ Query patentQ1 = QueryBuilders.hasParent(t -> t.parentType("patent").query(parentQ));
|
|
|
|
+ List<Query> queries = new ArrayList<>();
|
|
|
|
+ for (InnerFields innerField : innerFields) {
|
|
|
|
+ String filedId = innerField.getFieldId();
|
|
|
|
+ Integer fieldType = innerField.getFieldType();
|
|
|
|
+ Query q1 = QueryBuilders.term(t -> t.field("custom_field.project_id").value(projectId));
|
|
|
|
+ Query q2 = QueryBuilders.term((t -> t.field("custom_field.field").value(filedId)));
|
|
|
|
+ Query q3 = QueryBuilders.term(t -> t.field("custom_field.field_type").value(fieldType));
|
|
|
|
+
|
|
|
|
+ Query fQ = QueryBuilders.bool(i -> i.must(q1, q2, q3));
|
|
|
|
+ queries.add(fQ);
|
|
|
|
+ }
|
|
|
|
+ Query query = QueryBuilders.bool(i -> i.should(queries));
|
|
|
|
+ Query query1 = QueryBuilders.bool(i -> i.must(query, patentQ1));
|
|
|
|
+ return query1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获得自定义字段的值
|
|
|
|
+ *
|
|
|
|
+ * @param type
|
|
|
|
+ * @param value
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<FieldValueVO> getCustomFieldValues(Integer type, List<String> value) {
|
|
|
|
+ List<FieldValueVO> fieldValueVOS = new ArrayList<>();
|
|
|
|
+ switch (type) {
|
|
|
|
+ case 0:
|
|
|
|
+ case 1:
|
|
|
|
+ case 2:
|
|
|
|
+ value.forEach(item -> {
|
|
|
|
+ FieldValueVO fieldValueVO = new FieldValueVO();
|
|
|
|
+ fieldValueVO.setValue(item);
|
|
|
|
+ fieldValueVOS.add(fieldValueVO);
|
|
|
|
+ });
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ case 4:
|
|
|
|
+ case 5:
|
|
|
|
+ if (value != null && value.size() > 0) {
|
|
|
|
+ List<Integer> ids = FormatUtil.StringTOIntegerList(value);
|
|
|
|
+ LambdaQueryWrapper<CustomOption> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.in(CustomOption::getId, ids);
|
|
|
|
+ List<CustomOption> customOptions = customOptionService.list(queryWrapper);
|
|
|
|
+ customOptions.forEach(item -> {
|
|
|
|
+ FieldValueVO fieldValueVO = new FieldValueVO();
|
|
|
|
+ fieldValueVO.setValueId(item.getId());
|
|
|
|
+ fieldValueVO.setValue(item.getName());
|
|
|
|
+ fieldValueVOS.add(fieldValueVO);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 6:
|
|
|
|
+ case 7:
|
|
|
|
+ case 8:
|
|
|
|
+
|
|
|
|
+ case 9:
|
|
|
|
+ if (value != null && value.size() > 0) {
|
|
|
|
+ List<Integer> ids = FormatUtil.StringTOIntegerList(value);
|
|
|
|
+ LambdaQueryWrapper<TreeNode> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.in(TreeNode::getId, ids);
|
|
|
|
+ List<TreeNode> treeNodes = treeNodeService.list(queryWrapper);
|
|
|
|
+ treeNodes.forEach(item -> {
|
|
|
|
+ FieldValueVO fieldValueVO = new FieldValueVO();
|
|
|
|
+ fieldValueVO.setValueId(item.getId());
|
|
|
|
+ fieldValueVO.setValue(item.getName());
|
|
|
|
+ fieldValueVO.setPath(item.getPath());
|
|
|
|
+ fieldValueVOS.add(fieldValueVO);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ return fieldValueVOS;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<PatentWithIdVO> getEsCustomFields(String filedId, Integer type, Integer projectId) {
|
|
|
|
+ List<PatentWithIdVO> patentWithIdVOS = new ArrayList<>();
|
|
|
|
+ Query q1 = QueryBuilders.term(t -> t.field("custom_field.project_id").value(projectId));
|
|
|
|
+ Query q2 = QueryBuilders.term((t -> t.field("custom_field.field").value(filedId)));
|
|
|
|
+ Query q3 = QueryBuilders.term(t -> t.field("custom_field.field_type").value(type));
|
|
|
|
+
|
|
|
|
+ Query fQ = QueryBuilders.bool(i -> i.must(q1, q2, q3));
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ builder.size(999);
|
|
|
|
+ builder.query(fQ);
|
|
|
|
+ builder.sort(sortOptionsBuilder -> sortOptionsBuilder
|
|
|
|
+ .field(fieldSortBuilder -> fieldSortBuilder
|
|
|
|
+ .field("custom_field.create_time").order(SortOrder.Desc)));
|
|
|
|
+ try {
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+ long total = response.hits().total().value();
|
|
|
|
+ if (total > 0) {
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ PatentWithIdVO patentWithIdVO = new PatentWithIdVO();
|
|
|
|
+ patentWithIdVO.setPatent(hit.source());
|
|
|
|
+ patentWithIdVO.setId(hit.id());
|
|
|
|
+ PatentWithIdVO patentWithIdVO1 = patentWithIdVOS.stream().filter(item -> item.getPatent().getPatentJoin().getParent().equals(hit.source().getPatentJoin().getParent())).findFirst().orElse(null);
|
|
|
|
+ if (patentWithIdVO1 == null) {
|
|
|
|
+ patentWithIdVOS.add(patentWithIdVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return patentWithIdVOS;
|
|
|
|
+ }
|
|
}
|
|
}
|