package cn.cslg.pas.service.business.es; import cn.cslg.pas.domain.es.LegalEvent; import cn.cslg.pas.domain.es.PatentQuoteMessage; import cn.cslg.pas.domain.es.QuotePatent; import cn.cslg.pas.exception.XiaoShiException; 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.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.*; import java.util.stream.Collectors; @Service @RequiredArgsConstructor(onConstructor_ = {@Lazy}) public class EsLegalEventService { private final ElasticsearchClient client; //根据专利号查询同族专利号 public List getEsQutePatentByNos(String patentNo) throws Exception { SearchRequest.Builder builder = new SearchRequest.Builder(); //设置查询索引 builder.index("legal_event"); Query q1 = QueryBuilders.term(t -> t.field("app_no").value(patentNo)); //公开号 Query q2 = QueryBuilders.term(t -> t.field("public_no").value(patentNo)); //授权号 Query q3 = QueryBuilders.term(t -> t.field("grant_no").value(patentNo)); Query query = QueryBuilders.bool(i -> i.should(q1, q2, q3)); builder.query(query); SearchResponse response = client.search(builder.build(), LegalEvent.class); List> hits = response.hits().hits(); List legalEvents = new ArrayList<>(); if (hits.size() <= 0) { return legalEvents; } hits.forEach(item -> { legalEvents.add(item.source()); }); return legalEvents; } public List getStrLegalEvent(String patentNo) { List stringList = new ArrayList<>(); try { List legalEvents = this.getEsQutePatentByNos(patentNo); legalEvents = legalEvents.stream().sorted(Comparator.comparing(LegalEvent::getEventDate)).collect(Collectors.toList()); legalEvents.forEach(item -> { stringList.add(item.getName()); }); } catch (Exception e) { throw new XiaoShiException("获得事务错误"); } return stringList; } }