zero 9 ヶ月 前
コミット
dd623b5fa8

+ 26 - 1
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -134,7 +134,32 @@ public class EsService {
         return patentWithIdVO;
     }
 
-
+    /**
+     * 根据专利号获取专利id
+     *
+     * @param patentNo
+     * @return
+     * @throws Exception
+     */
+    public PatentWithIdVO importPatentQueryByPatentNo(String patentNo) throws Exception {
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("patent");
+        PatentWithIdVO patentWithIdVO = null;
+        String id = null;
+        Query query = QueryBuilders.term(t -> t.field("patent_no.keyword").value(patentNo));
+        builder.query(query);
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        List<Hit<Patent>> hits = response.hits().hits();
+        if (hits != null && hits.size() > 0) {
+            id = hits.get(0).id();
+            Patent patent = hits.get(0).source();
+            patentWithIdVO = new PatentWithIdVO();
+            patentWithIdVO.setPatent(patent);
+            patentWithIdVO.setId(id);
+        }
+        return patentWithIdVO;
+    }
     /**
      * Es检索
      *

+ 50 - 1
src/main/java/cn/cslg/pas/service/common/PatentStarApiService.java

@@ -888,7 +888,12 @@ public class PatentStarApiService {
         //遍历初始集合
         for (String str : originalList) {
             if (str.startsWith("CN")) {
-                cnStrings.add(str);
+                if (str.length() == 12 && str.contains(".")) {
+                    String cnNumber = this.formatCnNumber(str);
+                    cnStrings.add(cnNumber);
+                } else {
+                    cnStrings.add(str);
+                }
                 cnCount++;
                 if (cnCount >= 100) {
                     cnStrings = new ArrayList<>();
@@ -931,6 +936,50 @@ public class PatentStarApiService {
         return patentStarListDTOS;
     }
 
+    public String formatCnNumber(String str) {
+        StringBuilder builder = new StringBuilder();
+        builder.append(str, 0, 2);
+        String sub = str.substring(2, 3);
+        if (sub.equals("9")) {
+            builder.append("19");
+        } else if (sub.equals("0")) {
+            builder.append("20");
+        }
+        builder.append(str, 2, 5);
+        builder.append("00");
+        builder.append(str, 5, str.indexOf("."));
+        String s = builder.toString();
+        String s1 = s.substring(2);
+        char c = this.calculateChecksum(s1);
+        builder.append(".").append(c);
+        return builder.toString();
+    }
+
+    public char calculateChecksum(String input) {
+        int sum = 0;
+        int[] weights = {2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5};
+
+        // 遍历字符串中的每个字符,并计算乘积之和
+        for (int i = 0; i < input.length(); i++) {
+            char digit = input.charAt(i);
+            int num = Character.getNumericValue(digit);
+            sum += num * weights[i];
+        }
+
+        // 计算总和除以11的余数
+        int remainder = sum % 11;
+
+        // 根据余数确定校验位
+        char checksum;
+        if (remainder < 10) {
+            checksum = (char) ('0' + remainder);
+        } else {
+            checksum = 'X';
+        }
+
+        return checksum;
+    }
+
     public StarPatentVO getPatentByNo(String patentNo) {
         StarPatentVO starPatentVO = null;
         String condition = "AN=(" + patentNo + ") OR PN=(" + patentNo + ") OR GN=(" + patentNo + ") OR ANO=(" + patentNo + ")";

+ 19 - 6
src/main/java/cn/cslg/pas/service/importPatent/GetCataloguingFromWebThread.java

@@ -20,6 +20,7 @@ import co.elastic.clients.elasticsearch.core.UpdateRequest;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Configurable;
@@ -68,17 +69,18 @@ public class GetCataloguingFromWebThread extends Thread {
                 StarPatentVO starPatentVO = uploadPatentWebDTO.getStarPatentVO();
                 String patentZhuLuStr = "";
                 patentStarApiService = applicationContext.getBean(PatentStarApiService.class);
+                String number = this.getNumber(starPatentVO.getGN(), starPatentVO.getPN(), starPatentVO.getAN());
                 WebVOTransformService webVOTransformService = applicationContext.getBean(WebVOTransformService.class);
-                if (starPatentVO.getAN().startsWith("CN")) {
+                if (number.startsWith("CN")) {
                     patentZhuLuStr = patentStarApiService.getCnBibApi(uploadPatentWebDTO.getStarPatentVO().getANO());
                 } else {
                     patentZhuLuStr = patentStarApiService.getENBibApi(uploadPatentWebDTO.getStarPatentVO().getPN());
                 }
-                    if (starPatentVO.getAN().startsWith("CN")) {
-                        webVOTransformService.loadCNPatent(patentZhuLuStr, uploadPatentWebDTO);
-                    } else {
-                        webVOTransformService.loadWorldPatent(patentZhuLuStr, uploadPatentWebDTO);
-                    }
+                if (number.startsWith("CN")) {
+                    webVOTransformService.loadCNPatent(patentZhuLuStr, uploadPatentWebDTO);
+                } else {
+                    webVOTransformService.loadWorldPatent(patentZhuLuStr, uploadPatentWebDTO);
+                }
 
 
                 EsService esService = applicationContext.getBean(EsService.class);
@@ -137,6 +139,17 @@ public class GetCataloguingFromWebThread extends Thread {
         this.sendDone();
     }
 
+    public String getNumber(String grantNo, String publicNo, String appNo) {
+        String res = "";
+        if (StringUtils.isNotEmpty(grantNo)) {
+            res = grantNo;
+        } else if (StringUtils.isNotEmpty(publicNo)) {
+            res = publicNo;
+        } else {
+            res = appNo;
+        }
+        return res;
+    }
 
     public GetCataloguingFromWebThread(TaskThread taskThread, ImportFromWebToEsService importFromWebToEsService) {
         this.importTaskAMVO = taskThread.getImportTaskAMVO();

+ 1 - 1
src/main/java/cn/cslg/pas/service/importPatent/SavePatentToEsThread.java

@@ -61,7 +61,7 @@ public class SavePatentToEsThread extends Thread {
             try {
                 //根据专利号查询专利
                 EsService esService = applicationContext.getBean(EsService.class);
-                PatentWithIdVO patentWithIdVO = esService.getIdByPatentNo(patent.getPatentNo());
+                PatentWithIdVO patentWithIdVO = esService.importPatentQueryByPatentNo(patent.getPatentNo());
                 String patentId = null;
                 // 若查出专利则更新
                 Patent orgPatent = null;