|
@@ -3,8 +3,9 @@ package com.example.xiaoshiweixinback.service.importPatent;
|
|
|
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.SortOptions;
|
|
|
+import co.elastic.clients.elasticsearch._types.SortOrder;
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
@@ -12,6 +13,7 @@ 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.json.JsonData;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.example.xiaoshiweixinback.business.common.base.Records;
|
|
|
import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
@@ -27,6 +29,9 @@ import com.example.xiaoshiweixinback.domain.AssoPersonProduct;
|
|
|
import com.example.xiaoshiweixinback.domain.es.*;
|
|
|
import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPictureNoDTO;
|
|
|
import com.example.xiaoshiweixinback.entity.dto.patent.*;
|
|
|
+import com.example.xiaoshiweixinback.entity.patent.MapRequest;
|
|
|
+import com.example.xiaoshiweixinback.entity.patent.QueryRequest;
|
|
|
+import com.example.xiaoshiweixinback.entity.patent.StringRequest;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPatentVectorVo;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo;
|
|
@@ -45,13 +50,13 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
+
|
|
|
+
|
|
|
public class EsPatentService {
|
|
|
|
|
|
private final ElasticsearchClient client;
|
|
@@ -78,9 +83,10 @@ public class EsPatentService {
|
|
|
private FormatQueryService formatQueryService;
|
|
|
|
|
|
@Value("${ES.patentVector}")
|
|
|
- private String patentVectorName;
|
|
|
+ private String patentVectorName;
|
|
|
@Value("${ES.patent}")
|
|
|
private String patentMapName;
|
|
|
+
|
|
|
/**
|
|
|
* 收藏专利
|
|
|
*
|
|
@@ -93,9 +99,12 @@ public class EsPatentService {
|
|
|
Integer productId = patentDTO.getProductId();
|
|
|
//获取用户
|
|
|
PersonnelVO personnelVO = cacheUtils.getLoginUser(LoginUtils.getToken());
|
|
|
+
|
|
|
+
|
|
|
if (ToolUtil.isEmpty(personnelVO)) {
|
|
|
throw new BusinessException(ExceptionEnum.THE_GET_INFORMATION_TOKEN_INVALID);
|
|
|
}
|
|
|
+
|
|
|
String uuid = personnelVO.getUuid();
|
|
|
//获取人员产品关联表id
|
|
|
AssoPersonProduct assoPersonProduct = assoPersonProductMapper.selectOne(new LambdaQueryWrapper<AssoPersonProduct>()
|
|
@@ -332,6 +341,7 @@ public class EsPatentService {
|
|
|
|
|
|
/**
|
|
|
* 查询专利(用于导出专利数据)
|
|
|
+ *
|
|
|
* @param patentDTO
|
|
|
* @param file
|
|
|
* @return
|
|
@@ -377,6 +387,7 @@ public class EsPatentService {
|
|
|
|
|
|
/**
|
|
|
* 获取图片专利里的信息
|
|
|
+ *
|
|
|
* @param patentDTO
|
|
|
* @param file
|
|
|
* @return
|
|
@@ -456,6 +467,7 @@ public class EsPatentService {
|
|
|
|
|
|
/**
|
|
|
* 根据申请号查询专利信息
|
|
|
+ *
|
|
|
* @param appNo
|
|
|
* @return
|
|
|
* @throws IOException
|
|
@@ -477,4 +489,83 @@ public class EsPatentService {
|
|
|
return columnDTO;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Es检索
|
|
|
+ *
|
|
|
+ * @param queryRequest 检索条件
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public PatentDTO esSearch(QueryRequest queryRequest) throws Exception {
|
|
|
+ PatentDTO dto = new PatentDTO();
|
|
|
+ String searchCondition = "";
|
|
|
+ Integer projectId = queryRequest.getProjectId();
|
|
|
+ Long current = queryRequest.getCurrent();
|
|
|
+ Long size = queryRequest.getSize();
|
|
|
+
|
|
|
+ //判断表达式
|
|
|
+ if (queryRequest instanceof StringRequest) {
|
|
|
+ searchCondition = ((StringRequest) queryRequest).getSearchQuery();
|
|
|
+ } else if (queryRequest instanceof MapRequest) {
|
|
|
+ Map<String, Object> map = ((MapRequest) queryRequest).getSearchQuery();
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ for (String key : map.keySet()) {
|
|
|
+ Object value = map.get(key);
|
|
|
+ if (!"".contentEquals(stringBuilder)) {
|
|
|
+ stringBuilder = stringBuilder.append(" AND ").append(key).append("=").append(value);
|
|
|
+ } else {
|
|
|
+ stringBuilder = stringBuilder.append(key).append("=").append(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ searchCondition = stringBuilder.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ String condition = searchCondition;
|
|
|
+
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("wxpatent");
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
+ //3. 从es中检索数据
|
|
|
+ Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent", projectId);
|
|
|
+ builder.query(q);
|
|
|
+
|
|
|
+ //排序
|
|
|
+// List<SortOptions> optionsList = new ArrayList<>();
|
|
|
+//
|
|
|
+// SortOptions sortOptions = SortOptions.of(i -> i.field(j -> j.field("public_date").order(SortOrder.Desc).missing(-1)));
|
|
|
+// optionsList.add(sortOptions);
|
|
|
+//
|
|
|
+// builder.sort(optionsList);
|
|
|
+
|
|
|
+// //分页
|
|
|
+// if (current != null && size != null && current > 0 && size > 0) {
|
|
|
+// builder.from((current.intValue() - 1) * size.intValue()).size(size.intValue());
|
|
|
+// } else {
|
|
|
+// builder.from(1).size(99999);
|
|
|
+// }
|
|
|
+
|
|
|
+ //解除最大条数限制
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ List<PatentColumnDTO> list = new ArrayList<>();
|
|
|
+ long total = 0L;
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
+ total = response.hits().total().value();
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
+// String id = hit.id();
|
|
|
+// Patent esMess = hit.source();
|
|
|
+// PatentColumnDTO columnDTO = this.getPatentColumnDTO(esMess, projectId, id);
|
|
|
+// list.add(columnDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ dto.setTotal(total);
|
|
|
+ dto.setPatents(list);
|
|
|
+ dto.setPageNum(current);
|
|
|
+ dto.setPageSize(size);
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
}
|