|
@@ -8,10 +8,13 @@ import cn.cslg.pas.domain.es.Patent;
|
|
import cn.cslg.pas.domain.es.PatentJoin;
|
|
import cn.cslg.pas.domain.es.PatentJoin;
|
|
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;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.query_dsl.IdsQuery;
|
|
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.DeleteRequest;
|
|
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.UpdateRequest;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -20,6 +23,7 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -58,21 +62,45 @@ public class EsProductPatentService {
|
|
public List<Integer> delProductPatent(EsProductPatentVO vo) throws Exception {
|
|
public List<Integer> delProductPatent(EsProductPatentVO vo) throws Exception {
|
|
List<Integer> ids = new ArrayList<>();
|
|
List<Integer> ids = new ArrayList<>();
|
|
List<Integer> productIds = vo.getProductIds();
|
|
List<Integer> productIds = vo.getProductIds();
|
|
|
|
+ List<String> patentNos = vo.getPatentNos();
|
|
for (Integer productId : productIds) {
|
|
for (Integer productId : productIds) {
|
|
- SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
- //设置查询索引
|
|
|
|
- builder.index("patent");
|
|
|
|
- Query q = QueryBuilders.term(n -> n.field("product_id").value(productId));
|
|
|
|
- Query query = QueryBuilders.hasChild(i -> i.type("product").query(q));
|
|
|
|
- builder.query(query);
|
|
|
|
- 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();
|
|
|
|
|
|
+ List<String> productIdList = new ArrayList<>();
|
|
|
|
+ for (String patentNo : patentNos) {
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ //设置查询索引
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ Query q = QueryBuilders.term(n -> n.field("product_id").value(productId));
|
|
|
|
+ //申请号
|
|
|
|
+ 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 bool = QueryBuilders.bool(i -> i.should(q1, q2, q3));
|
|
|
|
+ Query query = QueryBuilders.hasParent(parent -> parent.parentType("patent").query(bool));
|
|
|
|
+ Query bool1 = QueryBuilders.bool(i -> i.must(q, query));
|
|
|
|
+ builder.query(bool1);
|
|
|
|
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
|
+ String id = hit.id();
|
|
|
|
+ productIdList.add(id);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
return ids;
|
|
return ids;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public Integer delProduct(String id) {
|
|
|
|
+ DeleteRequest request = DeleteRequest.of(i -> i.index("patent").id(id));
|
|
|
|
+ try {
|
|
|
|
+ client.delete(request);
|
|
|
|
+ return 1;
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|