zero 1 vuosi sitten
vanhempi
commit
b7f82bc0f8

+ 5 - 3
src/main/java/cn/cslg/pas/controller/FeatureController.java

@@ -7,6 +7,7 @@ import cn.cslg.pas.common.dto.invalidDTO.QueryClaimSplitHistoryDTO;
 import cn.cslg.pas.common.dto.invalidDTO.UpdateFeatureDTO;
 import cn.cslg.pas.common.model.cronModel.Records;
 import cn.cslg.pas.common.utils.Response;
+import cn.cslg.pas.common.vo.PatentRightTree;
 import cn.cslg.pas.common.vo.business.SplitVO;
 import cn.cslg.pas.domain.business.ReportProject;
 import cn.cslg.pas.exception.XiaoShiException;
@@ -94,13 +95,14 @@ public class FeatureController {
     @Operation(summary = "查询权要树")
     @GetMapping("/getPatentRightTree")
     public Response getPatentRightTree(String patentNo,String appNo) throws Exception {
+        Records records = new Records();
         try {
-            Records records = new Records();
-            records.setData(featureService.getPatentRightTree(patentNo,appNo));
-            return Response.success(records);
+            List<PatentRightTree> list = featureService.getPatentRightTree(patentNo, appNo);
+            records.setData(list);
         } catch (Exception e) {
             return Response.error(e.getMessage());
         }
+        return Response.success(records);
 
     }
 

+ 19 - 1
src/main/java/cn/cslg/pas/service/business/FeatureService.java

@@ -32,6 +32,7 @@ import co.elastic.clients.elasticsearch.core.SearchRequest;
 import co.elastic.clients.elasticsearch.core.SearchResponse;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -287,6 +288,23 @@ public class FeatureService extends ServiceImpl<FeatureMapper, Feature> {
     public List<PatentRightTree> getPatentRightTree(String patentNo, String appNo) {
         try {
             List<RePatentClaim> patentRights = this.getRightListByNo(patentNo, appNo);
+            Long total = translateService.getTranslateByPatentNo(patentNo);
+            if (total < 1) {
+                PatentColumnDTO columnDTO = translateService.getPatentByPatentNo(patentNo);
+                List<Text> claim = columnDTO.getClaim();
+                if (!CollectionUtils.isEmpty(claim)) {
+                    Text text = claim.get(0);
+                    for (RePatentClaim rePatentClaim : patentRights) {
+                        if (rePatentClaim.getContent().contains("&nbsp;")) {
+                            String replace = rePatentClaim.getContent().replace("&nbsp;", " ");
+                            rePatentClaim.setContent(replace);
+                        }
+                        //原文
+                        translateService.loadingTranslate(patentNo, "3", text.getLanguage(), true,
+                                rePatentClaim.getSort(), rePatentClaim.getParentSort(), rePatentClaim.getContent());
+                    }
+                }
+            }
 
             List<PatentRightTree> treeNodeList = new ArrayList<>();
             //装载权要原文
@@ -325,7 +343,7 @@ public class FeatureService extends ServiceImpl<FeatureMapper, Feature> {
             return treeNodeList;
 
         } catch (Exception e) {
-            throw new XiaoShiException("系统错误");
+            throw new XiaoShiException(e.getMessage());
         }
     }
 

+ 74 - 7
src/main/java/cn/cslg/pas/service/common/TranslateService.java

@@ -16,6 +16,7 @@ import cn.cslg.pas.domain.es.Text;
 import cn.cslg.pas.exception.XiaoShiException;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.InlineScript;
+import co.elastic.clients.elasticsearch._types.Refresh;
 import co.elastic.clients.elasticsearch._types.Script;
 import co.elastic.clients.elasticsearch._types.query_dsl.Query;
 import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
@@ -37,6 +38,8 @@ import org.springframework.util.CollectionUtils;
 
 import java.io.IOException;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 @Service
@@ -147,7 +150,7 @@ public class TranslateService {
         IndexResponse indexResponse = client.index(i -> i
                 .index("translate")
                 //传入user对象
-                .document(translate)
+                .document(translate).refresh(Refresh.True)
         );
         return indexResponse.id();
     }
@@ -177,7 +180,7 @@ public class TranslateService {
             i += 1;
         }
         //译文
-        String translateContent = this.getTranslateContent(textContent);
+        String translateContent = this.getLimitTranslateContent(textContent);
         String s1 = this.loadingTranslate(patentNo, patentField, "CN", false, 0, "-1", translateContent);
         if (StringUtils.isNotEmpty(s1)) {
             i += 1;
@@ -417,10 +420,7 @@ public class TranslateService {
             for (EsTranslateDTO translateDTO : translateDTOS) {
                 Content content = translateDTO.getContent();
                 String textContent = content.getTextContent();
-                if (textContent.contains("\r\n")) {
-                    textContent = textContent.replaceAll("\r\n", "");
-                }
-                String translateContent = this.getTranslateContent(textContent);
+                String translateContent = this.getLimitTranslateContent(textContent);
                 String s = this.loadingTranslate(translateDTO.getPatentNo(), translateDTO.getPatentField(), "CN", false,
                         content.getOrder(), content.getParentSort(), translateContent);
                 if (StringUtils.isNotEmpty(s)) {
@@ -443,6 +443,47 @@ public class TranslateService {
         return translateVOS;
     }
 
+    //判断文本翻译是否超出限制5000
+    public String getLimitTranslateContent(String content) throws Exception {
+        /*if (content.length() > 5000) {
+            String s = content.substring(0, 5000);
+            int i = s.lastIndexOf(",") + 1;
+            String s1 = s.substring(0, i);
+            str = str + this.getTranslateContent(s1);
+            String s2 = s.substring(i);
+            String s3 = this.getLimitTranslateContent(s2);
+            str = str + s3;
+        } else {
+            str = this.getTranslateContent(content);
+        }*/
+        String str = "";
+        String regex = "(?<!\\d)\\.(?!\\d)|[;。;]";
+        String regex1 = "(?<!\\d)\\.(?!\\d)";
+        Pattern pattern = Pattern.compile(regex);
+        Pattern pattern1 = Pattern.compile(regex1);
+        while (content.length() > 5000) {
+            String s2 = content.substring(0, 5000);
+            Matcher matcher = pattern.matcher(s2);
+            Matcher matcher1 = pattern1.matcher(s2);
+            int lastIndex = -1;
+            while (matcher.find()) {
+                lastIndex = matcher.end() - 1; // matcher.end() 返回的是匹配项之后的索引,所以减1得到最后一个字符的索引
+            }
+            if (lastIndex == -1) {
+                while (matcher1.find()) {
+                    lastIndex = matcher1.end() - 1; // matcher.end() 返回的是匹配项之后的索引,所以减1得到最后一个字符的索引
+                }
+            }
+            String s = content.substring(0, lastIndex + 1);
+            String translateContent = this.getTranslateContent(s);
+            str = str + translateContent;
+            content = content.substring(lastIndex + 1);
+        }
+        String translateContent = this.getTranslateContent(content);
+        str = str + translateContent;
+        return str;
+    }
+
     /**
      * 根据文本获取翻译内容
      *
@@ -450,7 +491,7 @@ public class TranslateService {
      * @return
      */
     public TranslateVO getTranslateByText(TranslateDTO vo) throws Exception {
-        String translateContent = this.getTranslateContent(vo.getContent());
+        String translateContent = this.getLimitTranslateContent(vo.getContent());
         TranslateVO translateVO = new TranslateVO();
         translateVO.setOriginalContent(vo.getContent());
         translateVO.setTranslationContent(translateContent);
@@ -481,6 +522,7 @@ public class TranslateService {
         return explainTextVOS;
     }
 
+    //根据专利号和序号查询是否已有翻译
     public List<String> getTranslateOrder(String patentNo, Integer sort) throws IOException {
         List<String> list = new ArrayList<>();
         SearchRequest.Builder builder = new SearchRequest.Builder();
@@ -505,4 +547,29 @@ public class TranslateService {
         }
         return list;
     }
+
+    //根据专利号和序号查询是否已有翻译
+    public Long getTranslateByPatentNo(String patentNo) throws IOException {
+        List<String> list = new ArrayList<>();
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("translate");
+        Query q1 = QueryBuilders.term(t -> t.field("patent_no").value(patentNo));
+        Query q2 = QueryBuilders.term(t -> t.field("patent_field").value("3"));
+        Query q3 = QueryBuilders.term(t -> t.field("if_origin").value(true));
+        Query bool = QueryBuilders.bool(i -> i.must(q1, q2, q3));
+        builder.query(bool);
+        builder.size(1000);
+        builder.trackTotalHits(i -> i.enabled(true));
+        SearchResponse<PatentTranslate> response = client.search(builder.build(), PatentTranslate.class);
+//        List<Hit<PatentTranslate>> hits = response.hits().hits();
+//        for (Hit<PatentTranslate> hit : hits) {
+//            PatentTranslate source = hit.source();
+//            String content = source.getContent().getTextContent();
+//            if (StringUtils.isNotEmpty(content)) {
+//                list.add(content);
+//            }
+//        }
+        return response.hits().total().value();
+    }
 }

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 32 - 5
src/test/java/cn/cslg/pas/service/EventServiceTests.java