xiexiang 1 年之前
父节点
当前提交
3994f8d27c

+ 18 - 3
src/main/java/cn/cslg/pas/common/utils/PatentNoUtil.java

@@ -3,11 +3,26 @@ package cn.cslg.pas.common.utils;
 import cn.cslg.pas.common.vo.OPS.PatentNoDetailVO;
 import org.springframework.stereotype.Component;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 @Component
 public class PatentNoUtil {
+
     public static PatentNoDetailVO getPatentNoDetail(String patentNo){
-        PatentNoDetailVO patentNoDetailVO=new PatentNoDetailVO();
-        //TODO
-        return patentNoDetailVO;
+        PatentNoDetailVO patentNoDetailVO = new PatentNoDetailVO();
+        Pattern PATENT_PATTERN = Pattern.compile("^([A-Za-z]{2})(\\d+)([A-Za-z\\d]+)$");
+        Matcher matcher = PATENT_PATTERN.matcher(patentNo);
+        if (matcher.find()) {
+            String country = matcher.group(1);
+            String num = matcher.group(2);
+            String cc = matcher.group(3);
+            patentNoDetailVO.setKind(cc);
+            patentNoDetailVO.setNumber(num);
+            patentNoDetailVO.setCc(country);
+            return patentNoDetailVO;
+        } else {
+            throw new IllegalArgumentException("Invalid patent number format: " + patentNo);
+        }
     }
 }

+ 15 - 0
src/main/java/cn/cslg/pas/common/vo/OPS/GetImagesInfoVO.java

@@ -0,0 +1,15 @@
+package cn.cslg.pas.common.vo.OPS;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @Author xiexiang
+ * @Date 2024/3/27
+ */
+@Data
+public class GetImagesInfoVO {
+    private PubReference pubReference;
+    private List<ImagesInfoVO> images;
+}

+ 19 - 0
src/main/java/cn/cslg/pas/common/vo/OPS/ImagesInfoVO.java

@@ -0,0 +1,19 @@
+package cn.cslg.pas.common.vo.OPS;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * OPS获取图片信息VO
+ * @Author xiexiang
+ * @Date 2024/3/27
+ */
+@Data
+public class ImagesInfoVO {
+    private String imageType;
+    private Integer numberOfPages;
+    private String urlLink;
+    private List<String> formatOptions;
+    private List<Section> sections;
+}

+ 18 - 0
src/main/java/cn/cslg/pas/common/vo/OPS/PubReference.java

@@ -0,0 +1,18 @@
+package cn.cslg.pas.common.vo.OPS;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @Author xiexiang
+ * @Date 2024/3/27
+ */
+@Data
+public class PubReference {
+    private String type;
+    private String country;
+    private String number;
+    private String kind;
+    private Date date;
+}

+ 13 - 0
src/main/java/cn/cslg/pas/common/vo/OPS/Section.java

@@ -0,0 +1,13 @@
+package cn.cslg.pas.common.vo.OPS;
+
+import lombok.Data;
+
+/**
+ * @Author xiexiang
+ * @Date 2024/3/27
+ */
+@Data
+public class Section {
+    private String name;
+    private Integer startPage;
+}

+ 75 - 4
src/main/java/cn/cslg/pas/service/importPatent/ImportSinglePatentService.java

@@ -1,16 +1,23 @@
 package cn.cslg.pas.service.importPatent;
 
 import cn.cslg.pas.common.core.IgnoreDTDEntityResolver;
+import cn.cslg.pas.common.dto.OPS.GetFuTuParamsDTO;
+import cn.cslg.pas.common.dto.OPS.PubNo;
 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.model.cronModel.Personnel;
 import cn.cslg.pas.common.model.cronModel.PersonnelVO;
+import cn.cslg.pas.common.model.cronModel.SystemFile;
 import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.utils.esDataForm.AddressSplitter;
 import cn.cslg.pas.common.utils.esDataForm.PatentClassifySplitter;
 import cn.cslg.pas.common.vo.*;
 import cn.cslg.pas.common.dto.OPS.GetClaimsInfoParamsDTO;
 import cn.cslg.pas.common.dto.OPS.GetDescriptionInfoParamsDTO;
+import cn.cslg.pas.common.vo.OPS.GetImagesInfoVO;
+import cn.cslg.pas.common.vo.OPS.ImagesInfoVO;
+import cn.cslg.pas.common.vo.OPS.PatentNoDetailVO;
 import cn.cslg.pas.domain.business.PatentClaim;
 import cn.cslg.pas.domain.business.ReportProject;
 import cn.cslg.pas.domain.es.*;
@@ -22,17 +29,20 @@ import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.common.OPSService;
 import cn.cslg.pas.service.common.PatentStarApiService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import lombok.RequiredArgsConstructor;
 import org.dom4j.Document;
 import org.dom4j.Element;
 import org.dom4j.XPath;
 import org.dom4j.io.SAXReader;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
 import java.util.*;
@@ -61,6 +71,8 @@ public class ImportSinglePatentService {
     private LoginUtils loginUtils;
     @Autowired
     private OPSService opsService;
+    @Autowired
+    private PatentNoUtil patentNoUtil;
 
     public StarPatentVO getPatentFromWeb(String patentNo) {
         StarPatentVO starPatentVO = null;
@@ -870,17 +882,76 @@ public class ImportSinglePatentService {
      * @throws Exception
      */
     public void loadClaimFromOPS(UploadPatentWebDTO uploadPatentWebDTO) throws Exception {
+        Patent patent = uploadPatentWebDTO.getPatent();
         //从ops获取权利要求
         GetClaimsInfoParamsDTO getClaimsInfoParamsDTO = new GetClaimsInfoParamsDTO();
-        opsService.getClaimsInfo(getClaimsInfoParamsDTO);
+        PatentNoDetailVO patentNoDetailVO = patentNoUtil.getPatentNoDetail(patent.getPatentNo());
+        BeanUtils.copyProperties(patentNoDetailVO, getClaimsInfoParamsDTO);
+        String res = opsService.getClaimsInfo(getClaimsInfoParamsDTO);
+        JSONObject jsonObject = JSONObject.parseObject(res);
+        Text text = new Text();
+        text.setLanguage(getClaimsInfoParamsDTO.getCc());
+        text.setTextContent(jsonObject.getString("data"));
+        text.setIfOrigin(true);
+        patent.setClaim(Arrays.asList(text));
     }
 
     /**
      * 从OPS装载说明书
      * @throws Exception
      */
-    private void  loadFullTextFromOPS(UploadPatentWebDTO uploadPatentWebDTO) throws Exception{
-        GetDescriptionInfoParamsDTO getDescriptionInfoParamsDTO =new GetDescriptionInfoParamsDTO();
-        opsService.getDescriptionInfo(getDescriptionInfoParamsDTO);
+    private void loadFullTextFromOPS(UploadPatentWebDTO uploadPatentWebDTO) throws Exception{
+        Patent patent = uploadPatentWebDTO.getPatent();
+        GetDescriptionInfoParamsDTO getDescriptionInfoParamsDTO = new GetDescriptionInfoParamsDTO();
+        PatentNoDetailVO patentNoDetailVO = patentNoUtil.getPatentNoDetail(patent.getPatentNo());
+        BeanUtils.copyProperties(patentNoDetailVO, getDescriptionInfoParamsDTO);
+        String res = opsService.getDescriptionInfo(getDescriptionInfoParamsDTO);
+        JSONObject jsonObject = JSONObject.parseObject(res);
+        Text text = new Text();
+        text.setIfOrigin(true);
+        text.setTextContent(jsonObject.getString("data"));
+        text.setLanguage(getDescriptionInfoParamsDTO.getCc());
+        patent.setPublicFullText(Arrays.asList(text));
+    }
+
+    public byte[] getImages(String publicNo) throws IOException {
+        PatentNoDetailVO patentNoDetailVO = patentNoUtil.getPatentNoDetail(publicNo);
+        PubNo pubNo = new PubNo();
+        pubNo.setCountry(patentNoDetailVO.getCc());
+        pubNo.setNumber(patentNoDetailVO.getNumber());
+        pubNo.setKind(patentNoDetailVO.getKind());
+        String res = opsService.getImagesInfo(pubNo);
+        JSONObject jsonObject = JSONObject.parseObject(res);
+        String imageInfo = jsonObject.getString("data");
+        // 删除第一个 `[`
+        if (imageInfo.startsWith("[")) {
+            imageInfo = imageInfo.substring(1);
+        }
+        // 删除最后一个 `]`
+        if (imageInfo.endsWith("]")) {
+            imageInfo = imageInfo.substring(0, imageInfo.length() - 1);
+        }
+        GetImagesInfoVO getImagesInfoVO = JSONObject.parseObject(imageInfo, GetImagesInfoVO.class);
+        List<ImagesInfoVO> images = getImagesInfoVO.getImages();
+        if (!images.isEmpty()) {
+            ImagesInfoVO infoVO = images.stream().filter(item -> item.getImageType().equals("FirstPageClipping")).findFirst().orElse(null);
+            if (infoVO != null) {
+                GetFuTuParamsDTO getFuTuParamsDTO = new GetFuTuParamsDTO();
+                getFuTuParamsDTO.setPage(1);
+                getFuTuParamsDTO.setType("image/png");
+                getFuTuParamsDTO.setLink(infoVO.getUrlLink());
+                byte[] buffer = opsService.getPatentFile(getFuTuParamsDTO);
+                if (buffer != null) {
+                    return buffer;
+                } else {
+                    return null;
+                }
+            } else {
+                return null;
+            }
+        } else {
+            return null;
+        }
     }
+
 }