|
@@ -1,11 +1,17 @@
|
|
package com.example.xiaoshiweixinback.service.importPatent;
|
|
package com.example.xiaoshiweixinback.service.importPatent;
|
|
|
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.InlineScript;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.Script;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
|
|
+import co.elastic.clients.elasticsearch.core.search.FieldCollapse;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
|
|
+import co.elastic.clients.json.JsonData;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.example.xiaoshiweixinback.business.common.base.Records;
|
|
import com.example.xiaoshiweixinback.business.common.base.Records;
|
|
import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
@@ -14,15 +20,19 @@ import com.example.xiaoshiweixinback.business.utils.BeanUtil;
|
|
import com.example.xiaoshiweixinback.business.utils.CacheUtil;
|
|
import com.example.xiaoshiweixinback.business.utils.CacheUtil;
|
|
import com.example.xiaoshiweixinback.business.utils.LoginUtils;
|
|
import com.example.xiaoshiweixinback.business.utils.LoginUtils;
|
|
import com.example.xiaoshiweixinback.business.utils.ToolUtil;
|
|
import com.example.xiaoshiweixinback.business.utils.ToolUtil;
|
|
|
|
+import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.expressManager;
|
|
|
|
+import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.operateNode;
|
|
|
|
+import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.treeNode;
|
|
import com.example.xiaoshiweixinback.domain.AssoPersonProduct;
|
|
import com.example.xiaoshiweixinback.domain.AssoPersonProduct;
|
|
import com.example.xiaoshiweixinback.domain.es.*;
|
|
import com.example.xiaoshiweixinback.domain.es.*;
|
|
-import com.example.xiaoshiweixinback.entity.dto.patent.CollectPatentDTO;
|
|
|
|
-import com.example.xiaoshiweixinback.entity.dto.patent.DelCollectPatentDTO;
|
|
|
|
-import com.example.xiaoshiweixinback.entity.dto.patent.PatentColumnDTO;
|
|
|
|
-import com.example.xiaoshiweixinback.entity.dto.patent.SelectCollectPatentDTO;
|
|
|
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPictureNoDTO;
|
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.patent.*;
|
|
import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPatentVectorVo;
|
|
import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo;
|
|
import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo;
|
|
import com.example.xiaoshiweixinback.mapper.AssoPersonProductMapper;
|
|
import com.example.xiaoshiweixinback.mapper.AssoPersonProductMapper;
|
|
|
|
+import com.example.xiaoshiweixinback.service.common.FileManagerService;
|
|
|
|
+import com.example.xiaoshiweixinback.service.common.GetVectorService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -32,8 +42,10 @@ import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -52,8 +64,22 @@ public class EsPatentService {
|
|
@Autowired
|
|
@Autowired
|
|
private AssoPersonProductMapper assoPersonProductMapper;
|
|
private AssoPersonProductMapper assoPersonProductMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private EsDenseVectorService esDenseVectorService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private FileManagerService fileManagerService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private GetVectorService getVectorService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private FormatQueryService formatQueryService;
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 收藏专利
|
|
* 收藏专利
|
|
|
|
+ *
|
|
* @param patentDTO
|
|
* @param patentDTO
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@@ -101,6 +127,7 @@ public class EsPatentService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询收藏专利
|
|
* 查询收藏专利
|
|
|
|
+ *
|
|
* @param dto
|
|
* @param dto
|
|
* @return
|
|
* @return
|
|
* @throws IOException
|
|
* @throws IOException
|
|
@@ -143,6 +170,7 @@ public class EsPatentService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 删除收藏专利
|
|
* 删除收藏专利
|
|
|
|
+ *
|
|
* @param patentDTO
|
|
* @param patentDTO
|
|
* @return
|
|
* @return
|
|
* @throws IOException
|
|
* @throws IOException
|
|
@@ -152,7 +180,7 @@ public class EsPatentService {
|
|
List<String> patentNos = patentDTO.getPatentNos();
|
|
List<String> patentNos = patentDTO.getPatentNos();
|
|
List<String> patentIds = new ArrayList<>();
|
|
List<String> patentIds = new ArrayList<>();
|
|
for (String patentNo : patentNos) {
|
|
for (String patentNo : patentNos) {
|
|
- List<String> list = this.selectPatentId(patentNo, assoPersonProductId);
|
|
|
|
|
|
+ List<String> list = this.selectChildPatentId(patentNo, assoPersonProductId);
|
|
patentIds.addAll(list);
|
|
patentIds.addAll(list);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -168,14 +196,14 @@ public class EsPatentService {
|
|
}
|
|
}
|
|
|
|
|
|
//根据专利号、assoPersonProductId查询相关专利id
|
|
//根据专利号、assoPersonProductId查询相关专利id
|
|
- public List<String> selectPatentId(String patentNo,Integer assoPersonProductId) throws IOException {
|
|
|
|
|
|
+ public List<String> selectChildPatentId(String patentNo, Integer assoPersonProductId) throws IOException {
|
|
List<String> list = new ArrayList<>();
|
|
List<String> list = new ArrayList<>();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
//设置查询索引
|
|
//设置查询索引
|
|
builder.index("wxpatent");
|
|
builder.index("wxpatent");
|
|
- Query query = QueryBuilders.term(i -> i.field("product_id").value(assoPersonProductId));
|
|
|
|
- Query q = QueryBuilders.hasChild(i -> i.type("product").query(query));
|
|
|
|
- Query q1 = QueryBuilders.term(i -> i.field("patent_no.keyword").value(patentNo));
|
|
|
|
|
|
+ Query q = QueryBuilders.term(i -> i.field("product_id").value(assoPersonProductId));
|
|
|
|
+ Query query = QueryBuilders.term(i -> i.field("patent_no.keyword").value(patentNo));
|
|
|
|
+ Query q1 = QueryBuilders.hasParent(i -> i.parentType("patent").query(query));
|
|
Query bool = QueryBuilders.bool(i -> i.must(q, q1));
|
|
Query bool = QueryBuilders.bool(i -> i.must(q, q1));
|
|
builder.query(bool);
|
|
builder.query(bool);
|
|
//解除最大条数限制
|
|
//解除最大条数限制
|
|
@@ -226,6 +254,7 @@ public class EsPatentService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 根据专利号获取专利id
|
|
* 根据专利号获取专利id
|
|
|
|
+ *
|
|
* @param patentNo
|
|
* @param patentNo
|
|
* @return
|
|
* @return
|
|
* @throws IOException
|
|
* @throws IOException
|
|
@@ -248,6 +277,7 @@ public class EsPatentService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 判断该专利是否已经被收藏
|
|
* 判断该专利是否已经被收藏
|
|
|
|
+ *
|
|
* @param personProductId
|
|
* @param personProductId
|
|
* @return
|
|
* @return
|
|
* @throws IOException
|
|
* @throws IOException
|
|
@@ -269,4 +299,118 @@ public class EsPatentService {
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //-------------------查询相关专利信息-----------
|
|
|
|
+ public List<PatentColumnDTO> selectPatent(SelectPatentDTO patentDTO, File file) throws Exception {
|
|
|
|
+ List<PatentColumnDTO> columnDTOS = new ArrayList<>();
|
|
|
|
+ //根据条件获取图片专利里的数据信息,如appNo
|
|
|
|
+ List<EsPatentVectorVo> vectorVos = this.selectPicturePatent(patentDTO, file);
|
|
|
|
+ if (!CollectionUtils.isEmpty(vectorVos)) {
|
|
|
|
+ for (EsPatentVectorVo vectorVo : vectorVos) {
|
|
|
|
+ String appNo = vectorVo.getAppNo();
|
|
|
|
+ //获取专利的多张摘要附图
|
|
|
|
+ EsPictureNoDTO esPictureNoDTO = new EsPictureNoDTO();
|
|
|
|
+ esPictureNoDTO.setAppNo(appNo);
|
|
|
|
+ List<EsPictureNoVo> noVos = esDenseVectorService.getPictureByNo(esPictureNoDTO);
|
|
|
|
+ List<String> guids = noVos.stream().map(EsPictureNoVo::getGuid).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //根据专利申请号appNo获取专利信息
|
|
|
|
+ PatentColumnDTO columnDTO = this.selectPatentByAppNo(appNo);
|
|
|
|
+ columnDTO.setPictureGuids(guids);
|
|
|
|
+ columnDTOS.add(columnDTO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return columnDTOS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<EsPatentVectorVo> selectPicturePatent(SelectPatentDTO patentDTO, File file) throws Exception {
|
|
|
|
+ Boolean ifAllExport = patentDTO.getIfAllExport();
|
|
|
|
+ Integer limitNum = patentDTO.getLimitNum();
|
|
|
|
+
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent_vector");
|
|
|
|
+ Query q = null;
|
|
|
|
+ String condition = esDenseVectorService.appendCondition(patentDTO.getProductId(), patentDTO.getKey());
|
|
|
|
+ if (StringUtils.isNotEmpty(condition)) {
|
|
|
|
+ //1. 解析检索条件
|
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
|
+ //2. 从es中检索数据
|
|
|
|
+ q = formatQueryService.EsQueryToQuery((operateNode) tree, "patentVector", null);
|
|
|
|
+ }
|
|
|
|
+ //获取图片向量
|
|
|
|
+ List<Float> imageList = new ArrayList<>();
|
|
|
|
+ List<String> stringList = new ArrayList<>();
|
|
|
|
+ if (file != null && file.exists() && file.length() != 0) {
|
|
|
|
+ stringList = getVectorService.getVectorByFile(file);
|
|
|
|
+ } else if (StringUtils.isNotEmpty(patentDTO.getDescription())) {
|
|
|
|
+ stringList = getVectorService.getVectorByText(patentDTO.getDescription());
|
|
|
|
+ }
|
|
|
|
+ stringList.forEach(item -> {
|
|
|
|
+ Float a = Float.parseFloat(item);
|
|
|
|
+ imageList.add(a);
|
|
|
|
+ });
|
|
|
|
+ if (!CollectionUtils.isEmpty(imageList)) {
|
|
|
|
+ String source = "cosineSimilarity(params.queryVector, 'my_vector') + 1.0";
|
|
|
|
+ InlineScript inlineScript = InlineScript.of(i -> i.lang("painless").params("queryVector", JsonData.of(imageList)).source(source));
|
|
|
|
+ Script script = Script.of(i -> i.inline(inlineScript));
|
|
|
|
+ Query query = null;
|
|
|
|
+ if (q != null) {
|
|
|
|
+ Query finalQ = q;
|
|
|
|
+ query = QueryBuilders.scriptScore(i -> i.script(script)
|
|
|
|
+ .query(finalQ));
|
|
|
|
+ } else {
|
|
|
|
+ query = QueryBuilders.scriptScore(i -> i.script(script)
|
|
|
|
+ .query(org.springframework.data.elasticsearch.client.elc.QueryBuilders.matchAllQueryAsQuery()));
|
|
|
|
+ }
|
|
|
|
+ builder.query(query);
|
|
|
|
+ } else {
|
|
|
|
+ builder.query(q);
|
|
|
|
+ }
|
|
|
|
+ //根据申请号去重
|
|
|
|
+ FieldCollapse collapse = FieldCollapse.of(i -> i.field("app_no"));
|
|
|
|
+ builder.collapse(collapse);
|
|
|
|
+ //分页
|
|
|
|
+ if (Boolean.TRUE.equals(ifAllExport)) {
|
|
|
|
+ builder.from(0).size(999999);
|
|
|
|
+ } else {
|
|
|
|
+ builder.size(limitNum);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //解除最大条数限制
|
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
|
+ SearchResponse<PatentVector> response = client.search(builder.build(), PatentVector.class);
|
|
|
|
+ List<Hit<PatentVector>> hits = response.hits().hits();
|
|
|
|
+ List<EsPatentVectorVo> vectorVos = new ArrayList<>();
|
|
|
|
+ Double fixedScore = 1.7d;
|
|
|
|
+ for (Hit<PatentVector> hit : hits) {
|
|
|
|
+ Double score = hit.score();
|
|
|
|
+ if (score > fixedScore) {
|
|
|
|
+ PatentVector vector = hit.source();
|
|
|
|
+ EsPatentVectorVo vectorVo = new EsPatentVectorVo();
|
|
|
|
+ BeanUtil.copy(vector, vectorVo);
|
|
|
|
+ vectorVos.add(vectorVo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return vectorVos;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public PatentColumnDTO selectPatentByAppNo(String appNo) throws IOException {
|
|
|
|
+ PatentColumnDTO columnDTO = new PatentColumnDTO();
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("wxpatent");
|
|
|
|
+ Query q = QueryBuilders.term(i -> i.field("app_no.keyword").value(appNo));
|
|
|
|
+ builder.query(q);
|
|
|
|
+ builder.size(10);
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ Patent patent = hit.source();
|
|
|
|
+ columnDTO = this.getPatentColumnDTO(patent, null, null);
|
|
|
|
+ }
|
|
|
|
+ return columnDTO;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|