|
@@ -1,8 +1,12 @@
|
|
|
package cn.cslg.pas.service.importPatent;
|
|
|
|
|
|
+import cn.cslg.pas.common.core.IgnoreDTDEntityResolver;
|
|
|
import cn.cslg.pas.common.dto.PatentStarListDTO;
|
|
|
import cn.cslg.pas.common.dto.UploadPatentWebDTO;
|
|
|
+import cn.cslg.pas.common.dto.es.RefreshPatentDTO;
|
|
|
import cn.cslg.pas.common.utils.DateUtils;
|
|
|
+import cn.cslg.pas.common.utils.FileUtils;
|
|
|
+import cn.cslg.pas.common.utils.FormatUtil;
|
|
|
import cn.cslg.pas.common.utils.esDataForm.AddressSplitter;
|
|
|
import cn.cslg.pas.common.utils.esDataForm.PatentClassifySplitter;
|
|
|
import cn.cslg.pas.common.vo.ChinaPatentZhuLu;
|
|
@@ -10,14 +14,25 @@ import cn.cslg.pas.common.vo.PatentWithIdVO;
|
|
|
import cn.cslg.pas.common.vo.StarPatentVO;
|
|
|
import cn.cslg.pas.common.vo.WorldPatentZhuLu;
|
|
|
import cn.cslg.pas.domain.es.*;
|
|
|
+import cn.cslg.pas.exception.XiaoShiException;
|
|
|
import cn.cslg.pas.service.business.es.EsService;
|
|
|
+import cn.cslg.pas.service.common.FileManagerService;
|
|
|
import cn.cslg.pas.service.common.PatentStarApiService;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.experimental.Accessors;
|
|
|
+import org.dom4j.Document;
|
|
|
+import org.dom4j.Element;
|
|
|
+import org.dom4j.XPath;
|
|
|
+import org.dom4j.io.SAXReader;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.Reader;
|
|
|
+import java.io.StringReader;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
@@ -28,6 +43,8 @@ public class ImportSinglePatentService {
|
|
|
|
|
|
@Autowired
|
|
|
private EsService esService;
|
|
|
+ @Autowired
|
|
|
+ private FileManagerService fileManagerService;
|
|
|
|
|
|
public StarPatentVO getPatentFromWeb(String patentNo) {
|
|
|
StarPatentVO starPatentVO = null;
|
|
@@ -85,6 +102,12 @@ public class ImportSinglePatentService {
|
|
|
return patent;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获得专利著录信息
|
|
|
+ *
|
|
|
+ * @param starPatentVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public Patent getPatentCataloguingFromWeb(StarPatentVO starPatentVO) {
|
|
|
String patentZhuLuStr = "";
|
|
|
if (starPatentVO.getApplicationNo().startsWith("CN")) {
|
|
@@ -215,15 +238,12 @@ public class ImportSinglePatentService {
|
|
|
patent.setGrantNo(starPatentVO.getPublicAccreditNo());
|
|
|
}
|
|
|
|
|
|
- if(patent.getAppNo().startsWith("CN")){
|
|
|
+ if (patent.getAppNo().startsWith("CN")) {
|
|
|
patent.setPatentNo(patent.getAppNo());
|
|
|
- }
|
|
|
- else {
|
|
|
- if(patent.getPublicNo()!=null){
|
|
|
+ } else {
|
|
|
+ if (patent.getPublicNo() != null) {
|
|
|
patent.setPatentNo(patent.getPublicNo());
|
|
|
- }
|
|
|
- else if(patent.getGrantNo()!=null)
|
|
|
- {
|
|
|
+ } else if (patent.getGrantNo() != null) {
|
|
|
patent.setPatentNo(patent.getGrantNo());
|
|
|
}
|
|
|
}
|
|
@@ -280,8 +300,7 @@ public class ImportSinglePatentService {
|
|
|
patentPeople.add(patentPerson);
|
|
|
}
|
|
|
patent.setRightHolder(patentPeople);
|
|
|
- }
|
|
|
- else if(patent.getApplicant()!=null){
|
|
|
+ } else if (patent.getApplicant() != null) {
|
|
|
patent.setRightHolder(patent.getApplicant());
|
|
|
}
|
|
|
|
|
@@ -372,7 +391,12 @@ public class ImportSinglePatentService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 装载世界专利
|
|
|
+ /**
|
|
|
+ * 装载世界专利著录
|
|
|
+ *
|
|
|
+ * @param worldPatentZhuLuStr
|
|
|
+ * @param patent
|
|
|
+ */
|
|
|
private void loadWorldPatent(String worldPatentZhuLuStr, Patent patent) {
|
|
|
String country = "";
|
|
|
List<WorldPatentZhuLu> worldPatentZhuLus = JSON.parseArray(worldPatentZhuLuStr, WorldPatentZhuLu.class);
|
|
@@ -438,9 +462,9 @@ public class ImportSinglePatentService {
|
|
|
patentPeople.add(patentPerson);
|
|
|
}
|
|
|
patent.setApplicant(patentPeople);
|
|
|
-if(patent.getRightHolder()==null||patent.getRightHolder().size()==0){
|
|
|
- patent.setRightHolder(patent.getApplicant());
|
|
|
-}
|
|
|
+ if (patent.getRightHolder() == null || patent.getRightHolder().size() == 0) {
|
|
|
+ patent.setRightHolder(patent.getApplicant());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -489,4 +513,236 @@ if(patent.getRightHolder()==null||patent.getRightHolder().size()==0){
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public void getFullXmlStr(Patent patent, StarPatentVO starPatentVO, List<Integer> contents) throws Exception {
|
|
|
+ String cnFullXmlStr = patentStarApiService.getCnFullXmlApi(starPatentVO.getRowApplicationNo());
|
|
|
+ if (contents.contains(3)) {
|
|
|
+ this.loadClaim(patent, cnFullXmlStr);
|
|
|
+ }
|
|
|
+ if (contents.contains(2)) {
|
|
|
+ this.loadFullText(patent, cnFullXmlStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载权利要求
|
|
|
+ private void loadClaim(Patent patent, String cnFullXmlStr) {
|
|
|
+ try {
|
|
|
+ if (cnFullXmlStr != null && cnFullXmlStr != "") {
|
|
|
+ SAXReader reader = new SAXReader();
|
|
|
+ reader.setEntityResolver(new IgnoreDTDEntityResolver());
|
|
|
+ Reader stringReader = new StringReader(cnFullXmlStr);
|
|
|
+ Document document = reader.read(stringReader);
|
|
|
+ XPath xpath = document.createXPath("//claim-text");
|
|
|
+ List<Element> element = (List<Element>) xpath.selectNodes(document);
|
|
|
+ if (element.size() == 0) {
|
|
|
+ xpath = document.createXPath("//business:ClaimText");
|
|
|
+ element = (List<Element>) xpath.selectNodes(document);
|
|
|
+ }
|
|
|
+ List<String> reClaims = new ArrayList<>();
|
|
|
+ element.forEach(item -> {
|
|
|
+ String claim = item.getText();
|
|
|
+ claim = claim.replaceAll("\r\n|\r|\n|\t| ", "");
|
|
|
+ reClaims.add(claim);
|
|
|
+
|
|
|
+ });
|
|
|
+ String reClaim = "";
|
|
|
+ if (reClaims.size() != 0) {
|
|
|
+ reClaim = cn.cslg.pas.common.utils.StringUtils.join(reClaims, "");
|
|
|
+ }
|
|
|
+ //装载权利要求原文
|
|
|
+ Text text = new Text();
|
|
|
+ text.setLanguage(patent.getAppCountry());
|
|
|
+ text.setTextContent(reClaim);
|
|
|
+ text.setIfOrigin(true);
|
|
|
+ patent.setClaim(Arrays.asList(text));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载说明书文档
|
|
|
+ private void loadFullText(Patent patent, String cnFullXmlStr) {
|
|
|
+ try {
|
|
|
+ //若没有取到全文文本,即取不到说明书文本,则将当前申请号或专利号和备注信息记录到问题记录表
|
|
|
+ if (cnFullXmlStr.equals("")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ SAXReader reader = new SAXReader();
|
|
|
+ reader.setEntityResolver(new IgnoreDTDEntityResolver());
|
|
|
+ Reader stringReader = new StringReader(cnFullXmlStr);
|
|
|
+ Document document = reader.read(stringReader);
|
|
|
+ XPath xpath = document.createXPath("//description//p");
|
|
|
+ List<Element> elements = (List<Element>) xpath.selectNodes(document);
|
|
|
+ if (elements.size() == 0) {
|
|
|
+ xpath = document.createXPath("//business:Description//base:Paragraphs");
|
|
|
+ elements = (List<Element>) xpath.selectNodes(document);
|
|
|
+ }
|
|
|
+ List<String> fullTexts = new ArrayList<>();
|
|
|
+ Integer count = 1;
|
|
|
+ for (Element item : elements) {
|
|
|
+ String fullText = item.getText().replaceAll("<br/>", "");
|
|
|
+ if (!fullText.trim().equals("技术领域")
|
|
|
+ && !fullText.trim().equals("发明内容")
|
|
|
+ && !fullText.trim().equals("附图说明")
|
|
|
+ && !fullText.trim().equals("具体实施方式")
|
|
|
+ && !fullText.trim().equals("背景技术")
|
|
|
+ && !fullText.trim().equals("实用新型内容")) {
|
|
|
+ String formattedNum = String.format("%04d", count);
|
|
|
+ fullText = "[" + formattedNum + "]" + fullText;
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ fullText = fullText.replaceAll("\r\n|\r|\n| ", "");
|
|
|
+ fullTexts.add(fullText);
|
|
|
+ }
|
|
|
+ String fullText = "";
|
|
|
+ if (fullTexts.size() != 0) {
|
|
|
+ fullText = cn.cslg.pas.common.utils.StringUtils.join(fullTexts, "");
|
|
|
+ }
|
|
|
+ Text text = new Text();
|
|
|
+ text.setIfOrigin(true);
|
|
|
+ text.setTextContent(fullText);
|
|
|
+ text.setLanguage(patent.getAppCountry());
|
|
|
+ patent.setPublicFullText(Arrays.asList(text));
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getPDFFromWeb(StarPatentVO starPatentVO) throws Exception {
|
|
|
+
|
|
|
+ String usedPatentNo;
|
|
|
+ if (starPatentVO.getPublicNo() != null && !starPatentVO.getPublicNo().equals("")) {
|
|
|
+ usedPatentNo = starPatentVO.getPublicNo();
|
|
|
+ } else {
|
|
|
+ usedPatentNo = starPatentVO.getPublicAccreditNo();
|
|
|
+ }
|
|
|
+
|
|
|
+ String pdfUrl = "", pdfUrl1 = "", pdfUrl2 = "";
|
|
|
+ //先根据公开号判断国家,若没有公开号再根据申请号判断,调用"获得中国专利pdf"接口,获得1个或2个pdf的url地址
|
|
|
+ if ((starPatentVO.getPublicNo() != null && starPatentVO.getPublicNo().contains("CN")) || (starPatentVO.getPublicNo() == null && starPatentVO.getPatentNo().contains("CN"))||(starPatentVO.getPublicAccreditNo() != null &&starPatentVO.getPublicAccreditNo().contains("CN")) ) {
|
|
|
+
|
|
|
+ String pdfUrlStr = patentStarApiService.getCnPdfApi(starPatentVO.getRowApplicationNo());
|
|
|
+
|
|
|
+ //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
|
|
|
+ if (!pdfUrlStr.equals("")) {
|
|
|
+// recordQuestionPatent(starPatent.getApplicationNo(), task.getId(), 4);
|
|
|
+
|
|
|
+
|
|
|
+ if (pdfUrlStr.contains("|http")) { //若包含公开和授权两个pdf
|
|
|
+ String[] pdfUrlArr = pdfUrlStr.split("\\|http");
|
|
|
+ pdfUrl1 = pdfUrlArr[0].substring(pdfUrlArr[0].indexOf("http"), pdfUrlArr[0].indexOf("?"));
|
|
|
+ pdfUrlArr[1] = "http" + pdfUrlArr[1];
|
|
|
+ pdfUrl2 = pdfUrlArr[1].substring(pdfUrlArr[1].indexOf("http"), pdfUrlArr[1].indexOf("?"));
|
|
|
+
|
|
|
+
|
|
|
+ if (pdfUrl1.contains("0A_CN_0.pdf")) {
|
|
|
+ String guid1 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 0);
|
|
|
+ File file1 = FileUtils.getFileByUrl(pdfUrl1);
|
|
|
+ fileManagerService.uploadFileWithGuid(file1, guid1);
|
|
|
+ String guid2 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 1);
|
|
|
+ File file2 = FileUtils.getFileByUrl(pdfUrl2);
|
|
|
+ fileManagerService.uploadFileWithGuid(file2, guid2);
|
|
|
+ } else {
|
|
|
+ String guid1 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 1);
|
|
|
+ File file1 = FileUtils.getFileByUrl(pdfUrl1);
|
|
|
+ fileManagerService.uploadFileWithGuid(file1, guid1);
|
|
|
+ String guid2 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 0);
|
|
|
+ File file2 = FileUtils.getFileByUrl(pdfUrl2);
|
|
|
+ fileManagerService.uploadFileWithGuid(file2, guid2);
|
|
|
+ }
|
|
|
+ } else { //若只有一个
|
|
|
+ pdfUrl1 = pdfUrlStr.substring(pdfUrlStr.indexOf("http"), pdfUrlStr.indexOf("?"));
|
|
|
+ if (pdfUrl1.contains("0A_CN_0.pdf")) {
|
|
|
+ String guid1 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 0);
|
|
|
+ File file1 = FileUtils.getFileByUrl(pdfUrl1);
|
|
|
+ fileManagerService.uploadFileWithGuid(file1, guid1);
|
|
|
+ } else {
|
|
|
+ String guid1 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 1);
|
|
|
+ File file1 = FileUtils.getFileByUrl(pdfUrl1);
|
|
|
+ fileManagerService.uploadFileWithGuid(file1, guid1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //根据专利号调用"获得世界专利pdf"接口,获得pdf的url地址
|
|
|
+ } else {
|
|
|
+ pdfUrl = patentStarApiService.getEnPdfApi(usedPatentNo);
|
|
|
+ //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
|
|
|
+// if (pdfUrl.equals("") || pdfUrl.equals("{}")) {
|
|
|
+// recordQuestionPatent(starPatent.getApplicationNo(), task.getId(), 4);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+ String guid1 = FormatUtil.getPDFFormat(starPatentVO.getApplicationNo(), 0);
|
|
|
+ File file1 = FileUtils.getFileByUrl(pdfUrl);
|
|
|
+ fileManagerService.uploadFileWithGuid(file1, guid1);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getPictureFromWeb(StarPatentVO starPatentVO) throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+ String pictureUrl = patentStarApiService.getPictureApi(starPatentVO.getRowApplicationNo());
|
|
|
+ if (pictureUrl != null && pictureUrl != "{}") {
|
|
|
+ File file = FileUtils.getPictureFileByUrl(pictureUrl);
|
|
|
+ String guid = FormatUtil.getPictureFormat(starPatentVO.getApplicationNo());
|
|
|
+ fileManagerService.uploadFileWithGuid(file, guid);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新专利信息
|
|
|
+ *
|
|
|
+ * @param refreshPatentDTO
|
|
|
+ */
|
|
|
+ public Boolean refreshPatent(RefreshPatentDTO refreshPatentDTO) throws Exception {
|
|
|
+ String patentNo = refreshPatentDTO.getPatentNo();
|
|
|
+ List<Integer> contents = refreshPatentDTO.getRefreshContent();
|
|
|
+ if (patentNo == null) {
|
|
|
+ throw new XiaoShiException("请输入专利号");
|
|
|
+ }
|
|
|
+ if (contents == null || contents.size() == 0) {
|
|
|
+ throw new XiaoShiException("请选择导入内容");
|
|
|
+ }
|
|
|
+
|
|
|
+ PatentWithIdVO patentWithIdVO = esService.getIdByPatentNo(patentNo);
|
|
|
+ if (patentWithIdVO == null) {
|
|
|
+ throw new XiaoShiException("专利不存在");
|
|
|
+ }
|
|
|
+ StarPatentVO starPatentVO = this.getPatentFromWeb(patentNo);
|
|
|
+ if (starPatentVO == null) {
|
|
|
+ throw new XiaoShiException("未检索到专利");
|
|
|
+ }
|
|
|
+
|
|
|
+ Patent patent = new Patent();
|
|
|
+ //装载基本信息
|
|
|
+ if (contents.contains(1)) {
|
|
|
+ patent = this.getPatentCataloguingFromWeb(starPatentVO);
|
|
|
+ }
|
|
|
+ //装载权利要求
|
|
|
+ if (contents.contains(2) || contents.contains(3)) {
|
|
|
+ this.getFullXmlStr(patent, starPatentVO, contents);
|
|
|
+ }
|
|
|
+ //装载图片
|
|
|
+ if (contents.contains(4)) {
|
|
|
+ this.getPictureFromWeb(starPatentVO);
|
|
|
+ }
|
|
|
+ //装载pdf
|
|
|
+ if (contents.contains(5)) {
|
|
|
+ this.getPDFFromWeb(starPatentVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!ObjectUtils.isEmpty(patent)) {
|
|
|
+ esService.updatePatentShouldWait(patent, patentWithIdVO.getId());
|
|
|
+
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|