|
@@ -0,0 +1,78 @@
|
|
|
+package cn.cslg.pas.service.business.es;
|
|
|
+
|
|
|
+
|
|
|
+import cn.cslg.pas.common.dto.business.SelectClaimDTO;
|
|
|
+import cn.cslg.pas.common.vo.PatentWithIdVO;
|
|
|
+import cn.cslg.pas.common.vo.es.EsProductPatentVO;
|
|
|
+import cn.cslg.pas.domain.es.Patent;
|
|
|
+import cn.cslg.pas.domain.es.PatentJoin;
|
|
|
+import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
+import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
+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;
|
|
|
+import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
|
+import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
+public class EsProductPatentService {
|
|
|
+ private final ElasticsearchClient client;
|
|
|
+ private final FormatQueryService formatQueryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EsService esService;
|
|
|
+
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
+ public List<Integer> addProductPatent(EsProductPatentVO vo) throws Exception {
|
|
|
+ List<Integer> ids = new ArrayList<>();
|
|
|
+ List<String> patentNos = vo.getPatentNos();
|
|
|
+ for (String patentNo : patentNos) {
|
|
|
+ PatentWithIdVO patentWithIdVO = esService.getIdByPatentNo(patentNo);
|
|
|
+ String id = patentWithIdVO.getId();
|
|
|
+ Patent patent = new Patent();
|
|
|
+ PatentJoin patentJoin = new PatentJoin();
|
|
|
+ patentJoin.setParent(id);
|
|
|
+ patentJoin.setName("product");
|
|
|
+ patent.setPatentJoin(patentJoin);
|
|
|
+ List<Integer> productIds = vo.getProductIds();
|
|
|
+ for (Integer productId : productIds) {
|
|
|
+ patent.setProductId(productId);
|
|
|
+ esService.addChildPatent(patent, id);
|
|
|
+ ids.add(productId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
+ public List<Integer> delProductPatent(EsProductPatentVO vo) throws Exception {
|
|
|
+ List<Integer> ids = new ArrayList<>();
|
|
|
+ List<Integer> productIds = vo.getProductIds();
|
|
|
+ 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();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+}
|