|
@@ -4,6 +4,7 @@ import cn.cslg.pas.common.core.base.IfConstant;
|
|
|
import cn.cslg.pas.common.dto.PatentColumnDTO;
|
|
|
import cn.cslg.pas.common.dto.PatentDTO;
|
|
|
//import cn.cslg.pas.common.dto.business.EsPatentFamilyDTO;
|
|
|
+import cn.cslg.pas.common.dto.PatentStarListDTO;
|
|
|
import cn.cslg.pas.common.dto.business.EsPatentFamilyDTO;
|
|
|
import cn.cslg.pas.common.model.request.MapRequest;
|
|
|
import cn.cslg.pas.common.model.request.OrderDTO;
|
|
@@ -12,10 +13,11 @@ import cn.cslg.pas.common.model.request.StringRequest;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.expressManager;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
|
+import cn.cslg.pas.common.vo.ChinaLeagalStatus;
|
|
|
import cn.cslg.pas.common.vo.PatentWithIdVO;
|
|
|
-import cn.cslg.pas.domain.es.FamilyPatent;
|
|
|
-import cn.cslg.pas.domain.es.Patent;
|
|
|
-import cn.cslg.pas.domain.es.PatentFamilyMessage;
|
|
|
+import cn.cslg.pas.common.vo.StarPatentVO;
|
|
|
+import cn.cslg.pas.domain.es.*;
|
|
|
+import cn.cslg.pas.service.common.PatentStarApiService;
|
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
import co.elastic.clients.elasticsearch._types.SortOrder;
|
|
@@ -24,6 +26,7 @@ import co.elastic.clients.elasticsearch.core.*;
|
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
|
import co.elastic.clients.elasticsearch.core.search.HitsMetadata;
|
|
|
import co.elastic.clients.elasticsearch.core.search.TotalHits;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -33,8 +36,10 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@Service
|
|
@@ -45,6 +50,9 @@ public class EsService {
|
|
|
|
|
|
@Autowired
|
|
|
private FormatQueryService formatQueryService;
|
|
|
+ @Autowired
|
|
|
+ private PatentStarApiService patentStarApiService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @param patent
|
|
@@ -175,7 +183,7 @@ public class EsService {
|
|
|
|
|
|
//分页
|
|
|
if (current > 0 && size > 0) {
|
|
|
- builder.from((current.intValue()-1)*size.intValue()).size(size.intValue());
|
|
|
+ builder.from((current.intValue() - 1) * size.intValue()).size(size.intValue());
|
|
|
}
|
|
|
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
@@ -289,6 +297,7 @@ public class EsService {
|
|
|
|
|
|
/**
|
|
|
* 查询是否存在专利
|
|
|
+ *
|
|
|
* @param parentId
|
|
|
* @param projectId
|
|
|
* @return
|
|
@@ -313,16 +322,21 @@ public class EsService {
|
|
|
|
|
|
/**
|
|
|
* 查询同族
|
|
|
+ *
|
|
|
* @param nos
|
|
|
* @param type
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public EsPatentFamilyDTO selectEsPatentFamily(List<String> nos, String type) throws IOException {
|
|
|
+ public EsPatentFamilyDTO addEsPatentFamily(List<String> nos, String type) throws IOException {
|
|
|
EsPatentFamilyDTO esDTO = new EsPatentFamilyDTO();
|
|
|
|
|
|
List<String> absentList = new ArrayList<>();
|
|
|
|
|
|
+ PatentFamilyMessage patentFamilyMessage = null;
|
|
|
+ String id = "";
|
|
|
+
|
|
|
+ //遍历,根据专利号查询同族
|
|
|
for (String no : nos) {
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
@@ -335,38 +349,95 @@ public class EsService {
|
|
|
Query q3 = QueryBuilders.term(t -> t.field("grant_no").value(no));
|
|
|
//类型
|
|
|
Query q4 = QueryBuilders.term(t -> t.field("family_type").value(type));
|
|
|
- Query bool = QueryBuilders.bool(i -> i.must(q4).should(q1, q2,q3));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q4).should(q1, q2, q3));
|
|
|
builder.query(bool);
|
|
|
SearchResponse<PatentFamilyMessage> response = client.search(builder.build(), PatentFamilyMessage.class);
|
|
|
long total = response.hits().total().value();
|
|
|
if (total > 0) {
|
|
|
List<FamilyPatent> list = new ArrayList<>();
|
|
|
List<Hit<PatentFamilyMessage>> hits = response.hits().hits();
|
|
|
- for (Hit<PatentFamilyMessage> hit : hits) {
|
|
|
- String id = hit.id();
|
|
|
- PatentFamilyMessage esMess = hit.source();
|
|
|
- list.addAll(esMess.getPatent());
|
|
|
- esDTO.setPatentFamilyId(id);
|
|
|
- }
|
|
|
- esDTO.setFamilyNum(list.size());
|
|
|
- } else {
|
|
|
- //获取不存在的号码
|
|
|
- absentList.add(no);
|
|
|
+ Hit<PatentFamilyMessage> hit = hits.get(0);
|
|
|
+ id = hit.id();
|
|
|
+ patentFamilyMessage = hit.source();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- //todo 判断是否全新/部分
|
|
|
- if (absentList.size() == nos.size()) {
|
|
|
|
|
|
- } else {
|
|
|
+ List<String> notInNos = new ArrayList<>();
|
|
|
+ //当查询到同族时
|
|
|
+ if (patentFamilyMessage != null) {
|
|
|
+ List<FamilyPatent> familyPatents = patentFamilyMessage.getPatent();
|
|
|
+ for (String no : nos) {
|
|
|
+ FamilyPatent familyPatent = familyPatents.stream()
|
|
|
+ .filter(item -> item.getAppNo().equals(no) || item.getPublicNo().equals(no) || item.getGrantNo().equals(no))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+ if (familyPatent == null) {
|
|
|
+ notInNos.add(no);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //当未查询到同族时
|
|
|
+ else {
|
|
|
+ patentFamilyMessage = new PatentFamilyMessage();
|
|
|
+ patentFamilyMessage.setFamilyType(type);
|
|
|
+ patentFamilyMessage.setPatent(new ArrayList<>());
|
|
|
+ notInNos.addAll(nos);
|
|
|
|
|
|
}
|
|
|
|
|
|
+ if (notInNos.size() > 0) {
|
|
|
+ //所有专利号的专利详情
|
|
|
+ List<StarPatentVO> starPatents = new ArrayList<>();
|
|
|
+
|
|
|
+ PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
|
|
|
+ List<PatentStarListDTO> patentStarListDtos = patentStarApiService.splitPatentNoByType(notInNos, patentStarListDTO);
|
|
|
+ while (patentStarListDtos.size() > 0) {
|
|
|
+ PatentStarListDTO patentStarListDTO1 = patentStarListDtos.remove(0);
|
|
|
+ patentStarListDTO1.setPageNum(1);
|
|
|
+ patentStarListDTO1.setRowCount(50);
|
|
|
+ Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDTO1);
|
|
|
+ if (resultMap == null || (Integer) resultMap.get("total") == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ starPatents.addAll((List<StarPatentVO>) resultMap.get("records"));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FamilyPatent> patents = new ArrayList<>();
|
|
|
+ starPatents.forEach(item -> {
|
|
|
+ FamilyPatent familyPatent = new FamilyPatent();
|
|
|
+ familyPatent.setAppNo(item.getApplicationNo());
|
|
|
+ familyPatent.setPublicNo(item.getPublicNo());
|
|
|
+ familyPatent.setGrantNo(item.getPublicAccreditNo());
|
|
|
+ patents.add(familyPatent);
|
|
|
+ });
|
|
|
+
|
|
|
+ patentFamilyMessage.getPatent().addAll(patents);
|
|
|
+
|
|
|
+
|
|
|
+ //当id不为null时
|
|
|
+ if (!id.equals("")) {
|
|
|
+
|
|
|
+ this.updatePatentFamily(patentFamilyMessage, id);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ id = this.addPatentFamily(patentFamilyMessage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ esDTO.setPatentFamilyId(id);
|
|
|
+ esDTO.setFamilyNum(patentFamilyMessage.getPatent().size());
|
|
|
return esDTO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加同族
|
|
|
+ *
|
|
|
* @param message
|
|
|
* @return
|
|
|
* @throws Exception
|
|
@@ -382,6 +453,7 @@ public class EsService {
|
|
|
|
|
|
/**
|
|
|
* 更新同族
|
|
|
+ *
|
|
|
* @param message
|
|
|
* @param id
|
|
|
* @return
|
|
@@ -400,7 +472,241 @@ public class EsService {
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新专利事务
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Integer updateLegalEvent(LegalEvent legalEvent, String id) {
|
|
|
+ UpdateRequest<LegalEvent, LegalEvent> req;
|
|
|
+ req = UpdateRequest.of(
|
|
|
+ b -> b.index("legal_event")
|
|
|
+ .id(id)
|
|
|
+ .doc(legalEvent)
|
|
|
+ );
|
|
|
+ try {
|
|
|
+ client.update(req, LegalEvent.class);
|
|
|
+ return 1;
|
|
|
+ } catch (IOException e) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加法律事务
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public String addLegalEvent(LegalEvent legalEvent) throws Exception {
|
|
|
+ IndexResponse indexResponse = client.index(i -> i
|
|
|
+ .index("legal_event")
|
|
|
+ .document(legalEvent)
|
|
|
+ );
|
|
|
+ return indexResponse.id();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新专利事务
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Integer updateQuotePatent(PatentQuoteMessage patentQuoteMessage, String id) {
|
|
|
+ UpdateRequest<PatentQuoteMessage, PatentQuoteMessage> req;
|
|
|
+ req = UpdateRequest.of(
|
|
|
+ b -> b.index("quote_patent")
|
|
|
+ .id(id)
|
|
|
+ .doc(patentQuoteMessage)
|
|
|
+ );
|
|
|
+ try {
|
|
|
+ client.update(req, PatentQuoteMessage.class);
|
|
|
+ return 1;
|
|
|
+ } catch (IOException e) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加法律事务
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public String addQuotePatent(PatentQuoteMessage patentQuoteMessage) throws Exception {
|
|
|
+ IndexResponse indexResponse = client.index(i -> i
|
|
|
+ .index("quote_patent")
|
|
|
+ .document(patentQuoteMessage)
|
|
|
+ );
|
|
|
+ return indexResponse.id();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String addEsQuotePatent(String no, List<String> nos) throws Exception {
|
|
|
+ StarPatentVO starPatentVO = patentStarApiService.getPatentByNo(no);
|
|
|
+ if (starPatentVO == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ QuotePatent quotePatent = this.reQuotePatent(starPatentVO);
|
|
|
+ PatentQuoteMessage patentQuoteMessage = null;
|
|
|
+ //根据申请号和
|
|
|
+ String id = "";
|
|
|
+ //根据专利号查询是否有引用信息
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("quote_patent");
|
|
|
+ //申请号
|
|
|
+ Query q1 = QueryBuilders.term(t -> t.field("patent.app_no").value(starPatentVO.getApplicationNo()));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1));
|
|
|
+ builder.query(bool);
|
|
|
+ SearchResponse<PatentQuoteMessage> response = client.search(builder.build(), PatentQuoteMessage.class);
|
|
|
+ long total = response.hits().total().value();
|
|
|
+ if (total > 0) {
|
|
|
+ patentQuoteMessage = response.hits().hits().get(0).source();
|
|
|
+ id = response.hits().hits().get(0).id();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<QuotePatent> quotePatents = new ArrayList<>();
|
|
|
+ if (patentQuoteMessage != null && patentQuoteMessage.getQuotedPatents() != null) {
|
|
|
+ quotePatents = patentQuoteMessage.getQuotedPatents();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String patentNo : nos) {
|
|
|
+ StarPatentVO starPatentVO1 = patentStarApiService.getPatentByNo(patentNo);
|
|
|
+ QuotePatent quotePatent1 = null;
|
|
|
+ if (quotePatents.size() > 0) {
|
|
|
+ quotePatent1 = quotePatents.stream()
|
|
|
+ .filter(item -> item.getAppNo().equals(starPatentVO1.getApplicationNo())).findFirst().orElse(null);
|
|
|
+ }
|
|
|
+ if (quotePatent1 == null) {
|
|
|
+ quotePatent1 = this.reQuotePatent(starPatentVO1);
|
|
|
+ quotePatents.add(quotePatent1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (patentQuoteMessage == null) {
|
|
|
+ if (quotePatents.size() != 0) {
|
|
|
+ patentQuoteMessage = new PatentQuoteMessage();
|
|
|
+ patentQuoteMessage.setPatent(quotePatent);
|
|
|
+ patentQuoteMessage.setQuotedPatents(quotePatents);
|
|
|
+ this.addQuotePatent(patentQuoteMessage);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ patentQuoteMessage.getQuotedPatents().addAll(quotePatents);
|
|
|
+ this.updateQuotePatent(patentQuoteMessage, id);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private QuotePatent reQuotePatent(StarPatentVO starPatentVO) {
|
|
|
+ QuotePatent quotePatent = new QuotePatent();
|
|
|
+
|
|
|
+ //装载申请人
|
|
|
+ if (starPatentVO.getApplicantStr() != null && !starPatentVO.getApplicantStr().equals("")) {
|
|
|
+ List<String> names = Arrays.asList(starPatentVO.getApplicantStr().split(";"));
|
|
|
+ List<PatentPerson> patentPeople = new ArrayList<>();
|
|
|
+ for (int i = 0; i < names.size(); i++) {
|
|
|
+ PatentPerson patentPerson = new PatentPerson();
|
|
|
+ patentPerson.setOrder(i + 1);
|
|
|
+ patentPerson.setType("1");
|
|
|
+ patentPerson.setName(names.get(i));
|
|
|
+ patentPeople.add(patentPerson);
|
|
|
+ }
|
|
|
+ quotePatent.setApplicant(patentPeople);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载权利人
|
|
|
+ if (starPatentVO.getCurrentApplicantStr() != null && !starPatentVO.getCurrentApplicantStr().equals("")) {
|
|
|
+ List<String> names = Arrays.asList(starPatentVO.getCurrentApplicantStr().split(";"));
|
|
|
+ List<PatentPerson> patentPeople = new ArrayList<>();
|
|
|
+ for (int i = 0; i < names.size(); i++) {
|
|
|
+ PatentPerson patentPerson = new PatentPerson();
|
|
|
+ patentPerson.setOrder(0);
|
|
|
+ patentPerson.setType("1");
|
|
|
+ patentPerson.setName(names.get(i));
|
|
|
+ patentPeople.add(patentPerson);
|
|
|
+ }
|
|
|
+ quotePatent.setRightHolder(patentPeople);
|
|
|
+ }
|
|
|
+ quotePatent.setAppNo(starPatentVO.getApplicationNo());
|
|
|
+ return quotePatent;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String addEsLegalEvent(String patentNo) {
|
|
|
+ LegalEvent legalEvent =null;
|
|
|
+ String id="";
|
|
|
+
|
|
|
+ //根据专利号查询
|
|
|
+ StarPatentVO starPatentVO = patentStarApiService.getPatentByNo(patentNo);
|
|
|
+ if (starPatentVO == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //根据专利号查询是否有引用信息
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("legal_event");
|
|
|
+ //申请号
|
|
|
+ Query q1 = QueryBuilders.term(t -> t.field("app_no").value(starPatentVO.getApplicationNo()));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1));
|
|
|
+ builder.query(bool);
|
|
|
+ SearchResponse<LegalEvent> response = null;
|
|
|
+ try {
|
|
|
+ response = client.search(builder.build(), LegalEvent.class);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ long total = response.hits().total().value();
|
|
|
+ if (total > 0) {
|
|
|
+ legalEvent = response.hits().hits().get(0).source();
|
|
|
+ id = response.hits().hits().get(0).id();
|
|
|
+ }
|
|
|
+
|
|
|
+ String cnLegalApiStr = patentStarApiService.getCnLegalApi(starPatentVO.getRowApplicationNo());
|
|
|
+ if (cnLegalApiStr != null && !cnLegalApiStr.equals("")) {
|
|
|
+ List<ChinaLeagalStatus> chinaLeagalStatuses = JSON.parseArray(cnLegalApiStr, ChinaLeagalStatus.class);
|
|
|
+ List<EventMessage> eventMessages = new ArrayList<>();
|
|
|
+ chinaLeagalStatuses.forEach(item -> {
|
|
|
+ EventMessage eventMessage = new EventMessage();
|
|
|
+ eventMessage.setEventDate(item.getLegalDate());
|
|
|
+ eventMessage.setCode(item.getLegalCode());
|
|
|
+ eventMessage.setDescription(item.getLegalStatusInfo());
|
|
|
+ eventMessages.add(eventMessage);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ if(legalEvent==null){
|
|
|
+ try {
|
|
|
+ legalEvent =new LegalEvent();
|
|
|
+ legalEvent.setAppNo(starPatentVO.getApplicationNo());
|
|
|
+ legalEvent.setEventMessages(eventMessages);
|
|
|
+ this.addLegalEvent(legalEvent);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ legalEvent.setAppNo(starPatentVO.getApplicationNo());
|
|
|
+ legalEvent.setEventMessages(eventMessages);
|
|
|
+ this.updateLegalEvent(legalEvent,id);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
|