Explorar el Código

20241119 外部检索专利时返回专利相似度信息

lwhhszx hace 10 meses
padre
commit
476271f1a7

+ 14 - 0
pom.xml

@@ -261,6 +261,20 @@
             <artifactId>alimt20181012</artifactId>
             <version>1.3.1</version>
         </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+            <version>2.1.6</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-registry-prometheus</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 1 - 0
src/main/java/cn/cslg/pas/common/core/base/RedisConf.java

@@ -26,4 +26,5 @@ public class RedisConf {
     public final static String PROJECT = "project";
     public final static String PRODUCT = "product";
     public final static String EVIDENCE_REASON = "evidence_reason";
+    public final static String GET_PATENT_SIMILAR_SCORE="get_patent_similar_score";
 }

+ 12 - 0
src/main/java/cn/cslg/pas/common/model/pythonModel/GetPatentSimilarScoreDTO.java

@@ -0,0 +1,12 @@
+package cn.cslg.pas.common.model.pythonModel;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class GetPatentSimilarScoreDTO {
+    private String text;
+    private Integer projectId;
+    private List<PatentScoreDTO> patentScoreDTOList;
+}

+ 11 - 0
src/main/java/cn/cslg/pas/common/model/pythonModel/GetPatentSimilarScoreVO.java

@@ -0,0 +1,11 @@
+package cn.cslg.pas.common.model.pythonModel;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class GetPatentSimilarScoreVO {
+    private String text;
+    private List<PatentScoreVO> patentScoreDTOList;
+}

+ 13 - 0
src/main/java/cn/cslg/pas/common/model/pythonModel/PatentScoreDTO.java

@@ -0,0 +1,13 @@
+package cn.cslg.pas.common.model.pythonModel;
+
+import lombok.Data;
+
+@Data
+public class PatentScoreDTO {
+    private String patentNo;
+    private String appNo;
+    private String rowApplicationNo;
+    private String abstractStr;
+    private String publicNo;
+    private String grantNo;
+}

+ 11 - 0
src/main/java/cn/cslg/pas/common/model/pythonModel/PatentScoreVO.java

@@ -0,0 +1,11 @@
+package cn.cslg.pas.common.model.pythonModel;
+
+import lombok.Data;
+
+@Data
+public class PatentScoreVO {
+    private String patentNo;
+    private String appNo;
+    private String abstractStr;
+    private Float score;
+}

+ 34 - 0
src/main/java/cn/cslg/pas/common/utils/MD5Util.java

@@ -0,0 +1,34 @@
+package cn.cslg.pas.common.utils;
+
+import org.springframework.stereotype.Component;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+@Component
+public class MD5Util {
+    public static String toMD5(String input) {
+        try {
+            // Create a MessageDigest instance for MD5
+            MessageDigest digest = MessageDigest.getInstance("MD5");
+            // Convert the input string to a byte array and update the digest
+            byte[] hash = digest.digest(input.getBytes(StandardCharsets.UTF_8));
+
+            // Convert the byte array to a hexadecimal string
+            StringBuilder hexString = new StringBuilder();
+
+            for (byte b : hash) {
+                // Convert the byte to an unsigned integer and then to a hexadecimal string
+                String hex = Integer.toHexString(0xff & b);
+                if (hex.length() == 1) hexString.append('0');
+                hexString.append(hex);
+            }
+
+            return hexString.toString();
+
+        } catch (NoSuchAlgorithmException e) {
+            throw new RuntimeException(e); // This shouldn't happen as MD5 is a standard algorithm
+        }
+    }
+}

+ 11 - 1
src/main/java/cn/cslg/pas/controller/outApi/PatentStarController.java

@@ -4,6 +4,8 @@ import cn.cslg.pas.common.core.base.Constants;
 import cn.cslg.pas.common.dto.*;
 import cn.cslg.pas.common.dto.business.SelectClaimDTO;
 import cn.cslg.pas.common.model.cronModel.Records;
+import cn.cslg.pas.common.model.pythonModel.GetPatentSimilarScoreDTO;
+import cn.cslg.pas.common.model.pythonModel.GetPatentSimilarScoreVO;
 import cn.cslg.pas.common.utils.Response;
 import cn.cslg.pas.common.vo.QueryExternalFamilyVO;
 import cn.cslg.pas.common.vo.business.PatentNoVO;
@@ -11,6 +13,7 @@ import cn.cslg.pas.common.vo.business.PatentNoVO;
 
 import cn.cslg.pas.domain.es.Text;
 import cn.cslg.pas.service.common.PatentStarApiService;
+import cn.cslg.pas.service.common.PythonApiService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
@@ -29,7 +32,7 @@ import java.util.Map;
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class PatentStarController {
     private final PatentStarApiService patentStarApiService;
-
+    private final PythonApiService pythonApiService;
     @PostMapping("/select")
     @Operation(summary = "一般检索接口")
     public Response select(@RequestBody PatentStarListDTO patentStarListDto) throws IOException {
@@ -164,4 +167,11 @@ public class PatentStarController {
         ExternalLegalInfoDTO infoDTO = patentStarApiService.getLegalStatus(appNo);
         return Response.success(infoDTO);
     }
+
+    @PostMapping("/getPatentSimilarMess")
+    @Operation(summary = "获取专利相似度信息")
+    public Response getLegalStatus(@RequestBody GetPatentSimilarScoreDTO getPatentSimilarScoreDTO) throws ParseException {
+        GetPatentSimilarScoreVO getPatentSimilarScoreVO= pythonApiService.getPatentSimilarMess(getPatentSimilarScoreDTO);
+        return Response.success(getPatentSimilarScoreVO);
+    }
 }

+ 12 - 1
src/main/java/cn/cslg/pas/service/business/TechnicalCaseService.java

@@ -114,7 +114,7 @@ public class TechnicalCaseService extends ServiceImpl<TechnicalCaseMapper, Techn
 
             //保存es
             EditInventionPointVO pointVO = this.selectTechnicalCasePatent(technicalCase.getProjectId());
-            if (!StringUtils.equals(vo.getInventionPoint(),pointVO.getInventionPoint())) {
+            if (!StringUtils.equals(vo.getInventionPoint(), pointVO.getInventionPoint())) {
                 TechnicalCasePatent casePatent = new TechnicalCasePatent();
 //            casePatent.setProjectId(vo.getProjectId());
                 casePatent.setInventionPoint(vo.getInventionPoint());
@@ -297,4 +297,15 @@ public class TechnicalCaseService extends ServiceImpl<TechnicalCaseMapper, Techn
             throw new XiaoShiException("删除发明点失败");
         }
     }
+
+    public TechnicalCase getByProjectId(Integer projectId) {
+        LambdaQueryWrapper<TechnicalCase> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(TechnicalCase::getProjectId, projectId);
+        TechnicalCase technicalCase = this.getOne(queryWrapper, false);
+        if (technicalCase == null) {
+            technicalCase = new TechnicalCase();
+        }
+        return technicalCase;
+    }
+
 }

+ 147 - 0
src/main/java/cn/cslg/pas/service/common/PythonApiService.java

@@ -0,0 +1,147 @@
+package cn.cslg.pas.service.common;
+
+import cn.cslg.pas.common.core.base.RedisConf;
+import cn.cslg.pas.common.model.pythonModel.GetPatentSimilarScoreDTO;
+import cn.cslg.pas.common.model.pythonModel.GetPatentSimilarScoreVO;
+import cn.cslg.pas.common.model.pythonModel.PatentScoreDTO;
+import cn.cslg.pas.common.model.pythonModel.PatentScoreVO;
+import cn.cslg.pas.common.utils.LoginUtils;
+import cn.cslg.pas.common.utils.MD5Util;
+import cn.cslg.pas.common.utils.RedisUtil;
+import cn.cslg.pas.common.utils.StringUtils;
+import cn.cslg.pas.common.vo.StarPatentVO;
+import cn.cslg.pas.domain.business.TechnicalCase;
+import cn.cslg.pas.exception.ExceptionEnum;
+import cn.cslg.pas.exception.XiaoShiException;
+import cn.cslg.pas.service.business.TechnicalCaseService;
+import cn.cslg.pas.service.importPatent.WebVOTransformService;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.google.gson.Gson;
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
+@Service
+public class PythonApiService {
+    @Value("${PythonUrl}")
+    private String PythonUrl;
+    @Autowired
+    private RedisUtil redisUtil;
+    @Autowired
+    private PatentStarApiService patentStarApiService;
+    @Autowired
+    private WebVOTransformService webVOTransformService;
+    @Autowired
+    private TechnicalCaseService technicalCaseService;
+
+    public GetPatentSimilarScoreVO getPatentSimilarScore(GetPatentSimilarScoreDTO getPatentSimilarScoreDTO) {
+        GetPatentSimilarScoreVO getPatentSimilarScoreVo = new GetPatentSimilarScoreVO();
+        try {
+            OkHttpClient okHttpClient = new OkHttpClient();
+            String param = new Gson().toJson(getPatentSimilarScoreDTO);
+            RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
+            Request request = new Request.Builder()
+                    .url(PythonUrl + "/getPatentSimilarScore")
+                    .post(requestBody)
+                    .build();
+            String reStr = Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+            getPatentSimilarScoreVo = JSONObject.parseObject(reStr, GetPatentSimilarScoreVO.class);
+
+        } catch (Exception e) {
+     e.printStackTrace();
+            throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "获取专利相似度失败");
+        }
+        return getPatentSimilarScoreVo;
+
+
+    }
+
+    public GetPatentSimilarScoreVO getPatentSimilarMess(GetPatentSimilarScoreDTO getPatentSimilarScoreDTO) {
+        GetPatentSimilarScoreVO getPatentSimilarScoreVO = new GetPatentSimilarScoreVO();
+        Integer projectId = getPatentSimilarScoreDTO.getProjectId();
+        TechnicalCase technicalCase = technicalCaseService.getByProjectId(projectId);
+        String text = technicalCase.getInventionPoint();
+        if (text == null || text.trim().equals("")) {
+            return getPatentSimilarScoreVO;
+        }
+        List<PatentScoreVO> donePatentScoreVo = new ArrayList<>();
+        List<PatentScoreDTO> waitTOGetDTOs = new ArrayList<>();
+        String code =  MD5Util.toMD5(text);
+        List<PatentScoreDTO> patentScoreDTOList = getPatentSimilarScoreDTO.getPatentScoreDTOList();
+        patentScoreDTOList.forEach(item -> {
+
+            String json = redisUtil.get(RedisConf.GET_PATENT_SIMILAR_SCORE + ":" + item.getPatentNo()+":"+code);
+
+            if (!StringUtils.isEmpty(json)) {
+                PatentScoreVO patentScoreVO = JSONObject.parseObject(json, PatentScoreVO.class);
+                donePatentScoreVo.add(patentScoreVO);
+            } else {
+                waitTOGetDTOs.add(item);
+
+            }
+        });
+
+        List<PatentScoreVO> patentScoreVOS = this.getPatentScore(waitTOGetDTOs, text);
+        donePatentScoreVo.addAll(patentScoreVOS);
+
+        getPatentSimilarScoreVO.setText(text);
+        getPatentSimilarScoreVO.setPatentScoreDTOList(donePatentScoreVo);
+        return getPatentSimilarScoreVO;
+    }
+
+
+    public List<PatentScoreVO> getPatentScore(List<PatentScoreDTO> waitTOGetDTOs, String text) {
+        String code =  MD5Util.toMD5(text);
+        List<PatentScoreVO> patentScoreVOS = new ArrayList<>();
+        if (waitTOGetDTOs.size() > 0) {
+            this.formatPatentScoreVO(waitTOGetDTOs);
+            GetPatentSimilarScoreDTO getSearchScoreDTO = new GetPatentSimilarScoreDTO();
+            getSearchScoreDTO.setText(text);
+            getSearchScoreDTO.setPatentScoreDTOList(waitTOGetDTOs);
+            GetPatentSimilarScoreVO getPatentSimilarScoreVO = this.getPatentSimilarScore(getSearchScoreDTO);
+            patentScoreVOS = getPatentSimilarScoreVO.getPatentScoreDTOList();
+            patentScoreVOS.forEach(item -> {
+                String jsons = JSONObject.toJSONString(item);
+                redisUtil.setEx(RedisConf.GET_PATENT_SIMILAR_SCORE + ":" + item.getPatentNo()+":"+code, jsons, 1l, TimeUnit.DAYS);
+            });
+        }
+
+        return patentScoreVOS;
+    }
+
+    public List<PatentScoreDTO> formatPatentScoreVO(List<PatentScoreDTO> waitTOGetDTOs) {
+        waitTOGetDTOs.forEach(item -> {
+            String rowAppNo = item.getRowApplicationNo();
+            String patentNo = item.getPatentNo();
+            String publicNo =item.getPublicNo();
+            if (patentNo.startsWith("CN")) {
+                String patentZhuLuStr = patentStarApiService.getCnBibApi(rowAppNo);
+                if (patentZhuLuStr != null && !patentZhuLuStr.trim().equals("") && !patentZhuLuStr.equals("{}") && !patentZhuLuStr.contains("请求不合法")) {
+                    List<StarPatentVO> chinaPatentZhuLus = JSON.parseArray(patentZhuLuStr, StarPatentVO.class);
+                    StarPatentVO chinaPatentZhuLu = chinaPatentZhuLus.get(0);
+                    item.setAbstractStr(chinaPatentZhuLu.getAB());
+
+                }
+            } else {
+                String patentZhuLuStr = patentStarApiService.getENBibApi(publicNo);
+                if (patentZhuLuStr != null && !patentZhuLuStr.trim().equals("") && !patentZhuLuStr.equals("{}") && !patentZhuLuStr.contains("请求不合法")) {
+                    List<StarPatentVO> worldPatentZhuLus = JSON.parseArray(patentZhuLuStr, StarPatentVO.class);
+                    StarPatentVO worldPatentZhuLu = worldPatentZhuLus.get(0);
+                    item.setAbstractStr(worldPatentZhuLu.getAB());
+                }
+            }
+        });
+
+        return waitTOGetDTOs;
+    }
+}

+ 2 - 21
src/main/java/cn/cslg/pas/service/importPatent/ImportSinglePatentService.java

@@ -182,26 +182,7 @@ public class ImportSinglePatentService {
     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, "");
-                }
+                String reClaim = webVOTransformService.getClaimFromWeb(cnFullXmlStr);
                 //装载权利要求原文
                 Text text = new Text();
                 text.setLanguage(patent.getAppCountry());
@@ -625,7 +606,7 @@ public class ImportSinglePatentService {
             if (patentWithIdVO != null) {
                 return patentWithIdVO;
             } else {
-                Patent patent =new Patent();
+                Patent patent = new Patent();
                 patent.setPatentNo(patentNo);
                 PatentJoin patentJoin = new PatentJoin();
                 patentJoin.setName("patent");

+ 30 - 32
src/main/java/cn/cslg/pas/service/importPatent/WebVOTransformService.java

@@ -121,11 +121,11 @@ public class WebVOTransformService {
 
         //装载IPC分类号
         if (patent.getPatentType() != null && patent.getPatentType().equals("3")) {
-            this.loadPatentLoc(patent,starPatentVO.getIC());
-            this.loadPatentMainLoc(patent,starPatentVO.getMC());
+            this.loadPatentLoc(patent, starPatentVO.getIC());
+            this.loadPatentMainLoc(patent, starPatentVO.getMC());
         } else {
             this.loadPatentIPC(patent, starPatentVO.getIC());
-            this.loadPatentMainIPC(patent,starPatentVO.getMC());
+            this.loadPatentMainIPC(patent, starPatentVO.getMC());
         }
         //装载公告日
         this.loadGrantDate(patent, starPatentVO.getPD(), starPatentVO.getGD());
@@ -860,35 +860,7 @@ public class WebVOTransformService {
     public void loadClaim(Patent patent, String cnFullXmlStr, Integer taskId) {
         try {
             if (cnFullXmlStr != null && cnFullXmlStr != "") {
-                SAXReader reader = new SAXReader();
-                reader.setEntityResolver(new IgnoreDTDEntityResolver());
-                Reader stringReader = new StringReader(cnFullXmlStr);
-                Document document = reader.read(stringReader);
-                XPath xpathRoot = document.createXPath("//business:Claim");
-                List<Element> claimElements = (List<Element>) xpathRoot.selectNodes(document);
-
-                List<String> reClaims = new ArrayList<>();
-                for (Element element : claimElements) {
-                    List<Element> elements = element.elements("claim-text");
-
-                    if (elements.size() == 0) {
-                        elements = element.elements("ClaimText");
-                    }
-                    StringBuilder stringBuilder = new StringBuilder();
-
-                    elements.forEach(item -> {
-                        String claim = item.getText();
-                        stringBuilder.append(claim);
-                    });
-                    reClaims.add(stringBuilder.toString());
-
-                }
-
-                String reClaim = "";
-                if (reClaims.size() != 0) {
-                    reClaim = cn.cslg.pas.common.utils.StringUtils.join(reClaims, "@##");
-                }
-                System.out.println(reClaim);
+                String reClaim = this.getClaimFromWeb(cnFullXmlStr);
                 //装载权利要求原文
                 Text text = new Text();
                 text.setLanguage("CN");
@@ -1122,4 +1094,30 @@ public class WebVOTransformService {
         }
     }
 
+
+    public String getClaimFromWeb(String cnFullXmlStr) throws Exception {
+        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, "@##");
+        }
+        System.out.println(reClaim);
+        return reClaim;
+    }
 }

+ 12 - 3
src/main/resources/application-dev.yml

@@ -60,13 +60,14 @@ spring:
     job-store-type: memory
     #初始化表结构
 
-authorUrl: http://localhost:8880
-PCSUrl: http://localhost:8880
+authorUrl: http://localhost:8871
+PCSUrl: http://localhost:8871
 #OPSUrl: http://192.168.2.24:5001
 OPSUrl: http://139.224.24.90:5001
 PASUrl: http://localhost:8879
 FMSUrl: http://localhost:8803
 WDUrl: http://1.116.113.26:81
+PythonUrl: http://localhost:8001
 FileSource: 1
 ES:
   patentVector: patent_vector
@@ -74,4 +75,12 @@ ES:
   config: 192.168.2.24
 WDSYS:
   account: caiyangl
-  password: Lqftiu807005
+  password: Lqftiu807005
+management:
+  endpoints:
+    web:
+      exposure:
+        include: "*"
+  endpoint:
+    health:
+      show-details: always

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 49 - 0
src/test/java/cn/cslg/pas/getSimilarTest.java