Parcourir la source

Merge remote-tracking branch 'origin/master'

lwhhszx il y a 1 an
Parent
commit
0b39d4ea0b

+ 44 - 0
src/main/java/cn/cslg/pas/common/utils/esUtils/GetPatentNoUtils.java

@@ -0,0 +1,44 @@
+package cn.cslg.pas.common.utils.esUtils;
+
+import org.springframework.stereotype.Component;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 获取专利号
+ */
+@Component
+public class GetPatentNoUtils {
+    /**
+     * 返回专利号
+     * @param var
+     * @return
+     */
+    public String getPatentNo(String var) {
+        int fixedLength = 13;
+        int fixedLength1 = 15;
+        String fixedSymbol = ".";
+
+        String s = "";
+        if (var == null) {
+            return s;
+        }
+
+        if (var.length() == fixedLength || var.length() == fixedLength1) {
+            String frontPart = var.substring(0, var.length() - 1);
+            String afterPart = var.substring(var.length() - 1);
+            var = frontPart + fixedSymbol + afterPart;
+        }
+        //使用正则表达式匹配前两位是否为字母
+        Pattern pattern = Pattern.compile("^[a-zA-Z]{2}");
+        Matcher matcher = pattern.matcher(var);
+        boolean flag = matcher.find();
+        if (!flag) {
+            s = "CN" + var;
+        } else {
+            s = var;
+        }
+        return s;
+    }
+}

+ 1 - 1
src/main/java/cn/cslg/pas/controller/CompareLiteratureController.java

@@ -84,7 +84,7 @@ public class CompareLiteratureController {
     }
 
 
-    @Operation(summary = "批量添加或编辑")
+    @Operation(summary = "批量删除对比文献")
     @PostMapping("/deleteCompareLiterature")
     public Response deleteCompareLiterature(@RequestBody List<Integer> ids) throws Exception {
         try {

+ 6 - 8
src/main/java/cn/cslg/pas/factorys/EsBuilderFactory/WildcardQueryBuilder.java

@@ -23,15 +23,13 @@ public class WildcardQueryBuilder implements IQueryBuilder{
         String str = "*";
         String s = "";
         if (list.contains(field)) {
-            if (value.contains(".")) {
-                s = str.concat(value.toUpperCase(Locale.ROOT)).concat("*");
+            if (value.length() == 13 || value.length() == 15) {
+                String frontPart = value.substring(0, value.length() - 1);
+                String afterPart = value.substring(value.length() - 1);
+                String s1 = frontPart + "." + afterPart;
+                s = str.concat(s1.toUpperCase(Locale.ROOT)).concat("*");
             } else {
-                if (value.length() > 10) {
-                    String substring = value.substring(0, value.length() - 1);
-                    s = str.concat(substring.toUpperCase(Locale.ROOT)).concat("*");
-                } else {
-                    s = str.concat(value.toUpperCase(Locale.ROOT)).concat("*");
-                }
+                s = str.concat(value.toUpperCase(Locale.ROOT)).concat("*");
             }
         } else {
             s = str.concat(value).concat("*");

+ 18 - 1
src/main/java/cn/cslg/pas/service/business/CompareLiteratureService.java

@@ -34,7 +34,11 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
+import java.io.IOException;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Date;
@@ -70,6 +74,8 @@ public class CompareLiteratureService extends ServiceImpl<CompareLiteratureMappe
     private EsService esService;
     @Autowired
     private MessageService messageService;
+    @Autowired
+    private CompareLiteratureMapper compareLiteratureMapper;
 
     //添加专利对比文献
     public Integer addPatentCompareLiterature(Patent patent, Integer projectId, String createId) {
@@ -520,10 +526,21 @@ public class CompareLiteratureService extends ServiceImpl<CompareLiteratureMappe
         return null;
     }
 
-    public Boolean deleteCompareLiterature(List<Integer> ids) {
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
+    public Boolean deleteCompareLiterature(List<Integer> ids) throws IOException {
         if (ids == null || ids.size() <= 0) {
             throw new XiaoShiException("请选择对比文献");
         }
+        List<CompareLiterature> literatures = compareLiteratureMapper.selectBatchIds(ids);
+        if (!CollectionUtils.isEmpty(literatures)) {
+            List<CompareLiterature> literatureList = literatures.stream().filter(i -> i.getType().equals(0)).collect(Collectors.toList());
+            for (CompareLiterature literature : literatureList) {
+                Integer number = esService.getPatent(literature.getLiteratureNo(), literature.getProjectId());
+                if (number < 1) {
+                    throw new XiaoShiException("删除失败");
+                }
+            }
+        }
         return this.removeBatchByIds(ids);
 
     }

+ 32 - 0
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -1338,6 +1338,38 @@ public class EsService {
         return list;
     }
 
+    public Integer getPatent(String patentNo, Integer projectId) throws IOException {
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("patent");
+        Query query = QueryBuilders.term(i -> i.field("project_id").value(projectId));
+        Query q = QueryBuilders.term(i -> i.field("patent_no.keyword").value(patentNo));
+        Query query1 = QueryBuilders.hasParent(i -> i.parentType("patent").query(q));
+        Query bool = QueryBuilders.bool(i -> i.must(query, query1));
+        builder.query(bool);
+        //解除最大条数限制
+        builder.trackTotalHits(i -> i.enabled(true));
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        List<Hit<Patent>> hits = response.hits().hits();
+        List<String> list = new ArrayList<>();
+        for (Hit<Patent> hit : hits) {
+            String id = hit.id();
+            list.add(id);
+        }
+        return this.deleteByIds(list);
+    }
+
+    public Integer deleteByIds(List<String> ids) {
+        Query query = QueryBuilders.ids(n -> n.values(ids));
+        DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index("patent").query(query));
+        try {
+            client.deleteByQuery(request);
+            return 1;
+        } catch (IOException e) {
+            throw new XiaoShiException("删除失败");
+        }
+    }
+
 }