chenyi 1 năm trước cách đây
mục cha
commit
95bcc63f04

+ 1 - 1
src/main/java/cn/cslg/pas/common/dto/PatentColumnDTO.java

@@ -307,7 +307,7 @@ public class PatentColumnDTO {
     /**
      * 发明人数量
      */
-    private Integer inventor_num;
+    private Integer inventorNum;
 
     /**
      * 代理机构

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

@@ -114,7 +114,12 @@ public class PatentStarController {
     @Operation(summary = "查询外部专利详情")
     @PostMapping("/queryExternalDetail")
     public Response queryExternalDetail(@RequestBody QueryExternalFamilyVO vo) throws Exception {
-        PatentColumnDTO dto = patentStarApiService.queryExternalDetail(vo);
+        PatentColumnDTO dto = null;
+        try {
+            dto = patentStarApiService.queryExternalDetail(vo);
+        } catch (IOException e) {
+            return Response.error(e.getMessage());
+        }
         return Response.success(dto);
     }
 

+ 13 - 75
src/main/java/cn/cslg/pas/service/common/NOSCacheService.java

@@ -6,13 +6,18 @@ import cn.cslg.pas.common.utils.StringUtils;
 import cn.cslg.pas.common.vo.NoCacheVO;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.hutool.core.util.IdUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 
+@RequiredArgsConstructor
+@Slf4j
 @Service
 public class NOSCacheService {
 
@@ -21,7 +26,7 @@ public class NOSCacheService {
 
     public NoCacheVO savaByList(PatentStarListDTO patentStarListDTO) {
         NoCacheVO cacheVO = new NoCacheVO();
-        String[] noArray = patentStarListDTO.getNumberQuery().split("[,,]|(\\r\\n)+|\\r+|\\n+");
+        String[] noArray = patentStarListDTO.getNumberQuery().split("\\s+|[,,]|(\\r\\n)+|\\r+|\\n+");
         cacheVO.setTotal((long) noArray.length);
         if (patentStarListDTO.getDBType().equals("CN")) {
             for (String s : noArray) {
@@ -63,85 +68,18 @@ public class NOSCacheService {
         Integer pageSize = patentStarListDTO.getRowCount();
         Long len = redisUtil.lLen(redisKey);
         List<String> ranges = redisUtil.lRange(redisKey, (long) (pageNum - 1) * pageSize, (long) pageNum * pageSize - 1);
-        String condition = "NO=(" + StringUtils.join(ranges, ",") +")";
+        String condition = "";
+        if (!CollectionUtils.isEmpty(ranges)) {
+            condition = "NO=(" + StringUtils.join(ranges, ",") +")";
+        } else {
+            condition = "NO=(0)";
+        }
         patentStarListDTO.setCurrentQuery(condition);
+        patentStarListDTO.setPageNum(1);
         NoCacheVO cacheVO = new NoCacheVO();
         cacheVO.setTotal(len);
         cacheVO.setList(ranges);
         cacheVO.setKey(patentStarListDTO.getRedisKey());
         return cacheVO;
     }
-
-    //处理NO并依照字符串形式存储条件到缓存中
-    public NoCacheVO saveByStr(PatentStarListDTO patentStarListDTO) {
-        NoCacheVO cacheVO = new NoCacheVO();
-        String[] noArray = patentStarListDTO.getNumberQuery().split("[,,]|(\\r\\n)+|\\r+|\\n+");
-        cacheVO.setTotal((long) noArray.length);
-        if (patentStarListDTO.getDBType().equals("CN")) {
-            for (String s : noArray) {
-                if (s.length() < 9) {
-                    throw new XiaoShiException("中国专利号码检索式错误,每一个号码长度请大于9");
-                }
-            }
-        } else {
-            for (String s : noArray) {
-                if (s.length() < 8) {
-                    throw new XiaoShiException("世界专利号码检索式错误,每一个号码长度请大于9");
-                }
-            }
-        }
-        String s = this.formatCondition(noArray, patentStarListDTO.getPageNum(), patentStarListDTO.getRowCount());
-        patentStarListDTO.setCurrentQuery(s);
-        cacheVO.setList(this.formatConditionList(s));
-
-        //存redis
-        String condition = StringUtils.join(noArray, ",");
-        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
-        String now = format.format(new Date());
-        String uuid = IdUtil.randomUUID();
-        String redisKey = uuid + "-" + now;
-        cacheVO.setKey(redisKey);
-        redisUtil.setEx(redisKey, condition, 24, TimeUnit.HOURS);
-        return cacheVO;
-    }
-
-    //根据缓存key取No条件并处理
-    public NoCacheVO getByStr(PatentStarListDTO patentStarListDTO) {
-        NoCacheVO cacheVO = new NoCacheVO();
-        String no = redisUtil.get(patentStarListDTO.getRedisKey());
-        String[] noArray = no.split("[,,]|(\\r\\n)+|\\r+|\\n+");
-        cacheVO.setTotal((long) noArray.length);
-        String s = this.formatCondition(noArray, patentStarListDTO.getPageNum(), patentStarListDTO.getRowCount());
-        patentStarListDTO.setCurrentQuery(s);
-        cacheVO.setKey(patentStarListDTO.getRedisKey());
-        cacheVO.setList(this.formatConditionList(s));
-        return cacheVO;
-    }
-
-    private List<String> formatConditionList(String condition) {
-        String s = condition.substring(condition.indexOf("=") + 1);
-        String s1 = s.replaceAll("[()]", "");
-        final String[] split = s1.split(",");
-        return new ArrayList<>(Arrays.asList(split));
-    }
-
-    private String formatCondition(String[] valueStrs, Integer pageNum, Integer pageSize) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("NO").append("=").append("(");
-        if (valueStrs.length > pageSize) {
-            for (int i = (pageNum - 1) * pageSize; i < (pageNum * pageSize); i++) {
-                String valueStr = valueStrs[i];
-                if (i != valueStrs.length - 1) {
-                    builder.append(valueStr).append(",");
-                } else {
-                    builder.append(valueStr);
-                }
-            }
-        } else {
-            String join = StringUtils.join(valueStrs, ",");
-            builder.append(join);
-        }
-
-        return builder.append(")").toString();
-    }
 }

+ 61 - 121
src/main/java/cn/cslg/pas/service/common/PatentStarApiService.java

@@ -67,7 +67,6 @@ import java.util.stream.Collectors;
 @RequiredArgsConstructor
 @Slf4j
 @Service
-
 public class PatentStarApiService {
     @Autowired
     private RetrieveRecordService retrieveRecordService;
@@ -114,8 +113,7 @@ public class PatentStarApiService {
 
         Map<String, Object> map = this.patentStarSearchApi(patentStarListDTO);
         if (map == null) {
-            ThrowException.throwXiaoShiException("检索失败,请检查检索式");
-//            throw new XiaoShiException("检索失败,请检查检索式");
+            throw new XiaoShiException("检索失败,请检查检索式");
         }
 
         //记录检索历史
@@ -150,111 +148,12 @@ public class PatentStarApiService {
         return records;
     }
 
-    private List<PatentColumnDTO> loadPatentList(List<PatentColumnDTO> columnDTOS, List<String> list, String dbType) {
-        if (CollectionUtils.isEmpty(list) || CollectionUtils.isEmpty(columnDTOS)) {
-            // 如果任一列表为空,直接返回原始columnDTOS或根据list生成新的DTO列表
-            return list.isEmpty() ? columnDTOS : createNewDTOs(list);
-        }
-
-        List<PatentColumnDTO> result = new ArrayList<>(columnDTOS.size());
-        Set<String> searchedNumbers = new HashSet<>(); // 用于跟踪已搜索的专利号
-
-        for (String patentNo : list) {
-            boolean found = false;
-            String formattedNo = dbType.equals("CN") ? PatentNoUtil.formatApNo(patentNo) : patentNo;
-
-            for (PatentColumnDTO columnDTO : columnDTOS) {
-                if (containsNumber(columnDTO, formattedNo)) {
-                    PatentColumnDTO dto = new PatentColumnDTO();
-                    BeanUtils.copyProperties(columnDTO,dto);
-                    dto.setSearchNo(patentNo);
-                    result.add(dto);
-                    searchedNumbers.add(patentNo); // 标记为已搜索
-                    found = true;
-                    break; // 找到匹配项后跳出内层循环
-                }
-            }
-
-            if (!found) {
-                // 如果没有在columnDTOS中找到匹配项,则创建一个新的DTO
-                PatentColumnDTO newDTO = new PatentColumnDTO();
-                newDTO.setPatentNo(patentNo);
-                newDTO.setSearchNo(patentNo);
-                newDTO.setIfSearch(false);
-                result.add(newDTO);
-            }
-        }
-
-        return result;
-    }
-
-    private boolean containsNumber(PatentColumnDTO dto, String number) {
-        return dto.getAppNo().contains(number) || dto.getPublicNo().contains(number)
-                || dto.getGrantNo().contains(number) || dto.getRowApplicationNo().contains(number);
-    }
-
-    private List<PatentColumnDTO> createNewDTOs(List<String> list) {
-        List<PatentColumnDTO> newDTOs = new ArrayList<>();
-        for (String s : list) {
-            PatentColumnDTO dto = new PatentColumnDTO();
-            dto.setPatentNo(s);
-            dto.setSearchNo(s);
-            dto.setIfSearch(false);
-            newDTOs.add(dto);
-        }
-        return newDTOs;
-    }
-
-    /*private List<PatentColumnDTO> loadPatentList(List<PatentColumnDTO> columnDTOS, List<String> list, String dbType) {
-        List<String> noList = new ArrayList<>(list);
-        if (CollectionUtils.isEmpty(list)) {
-            return columnDTOS;
-        }
-        List<PatentColumnDTO> patentColumnDTOS = new ArrayList<>();
-        if (CollectionUtils.isEmpty(columnDTOS)) {
-            list.forEach(i -> {
-                PatentColumnDTO columnDTO = new PatentColumnDTO();
-                columnDTO.setPatentNo(i);
-                columnDTO.setSearchNo(i);
-                columnDTO.setIfSearch(false);
-                patentColumnDTOS.add(columnDTO);
-            });
-            return patentColumnDTOS;
-        }
-        list.forEach(i -> {
-            for (PatentColumnDTO columnDTO : columnDTOS) {
-                if (dbType.equals("CN")) {
-                    String no = PatentNoUtil.formatApNo(i);
-                    if (columnDTO.getAppNo().contains(no) || columnDTO.getPublicNo().contains(no)
-                            || columnDTO.getGrantNo().contains(no) || columnDTO.getRowApplicationNo().contains(no)) {
-                        columnDTO.setSearchNo(i);
-                        patentColumnDTOS.add(columnDTO);
-                    }
-                } else {
-                    if (columnDTO.getAppNo().contains(i) || columnDTO.getPublicNo().contains(i)
-                            || columnDTO.getGrantNo().contains(i) || columnDTO.getRowApplicationNo().contains(i)) {
-                        columnDTO.setSearchNo(i);
-                        patentColumnDTOS.add(columnDTO);
-                    }
-                }
-            }
-        });
-        List<String> collect = patentColumnDTOS.stream().map(PatentColumnDTO::getSearchNo).collect(Collectors.toList());
-        for (String key : collect) {
-            noList.removeIf(j -> j.equals(key));
-        }
-        if (!CollectionUtils.isEmpty(noList)) {
-            for (String s : noList) {
-                PatentColumnDTO columnDTO = new PatentColumnDTO();
-                columnDTO.setPatentNo(s);
-                columnDTO.setSearchNo(s);
-                columnDTO.setIfSearch(false);
-                patentColumnDTOS.add(columnDTO);
-            }
-        }
-        return patentColumnDTOS;
-    }*/
-
+    /**
+     * 格式化条件后并请求外部接口
+     * @param PatentStarListDTO
+     * @return
+     * @throws IOException
+     */
     public Map<String, Object> patentStarSearchApi(PatentStarListDTO PatentStarListDTO) throws IOException {
         try {
             if (PatentStarListDTO.getFormed() == null || PatentStarListDTO.getFormed() == false) {
@@ -317,25 +216,66 @@ public class PatentStarApiService {
                 return reMap;
             }
         } catch (IOException e) {
-            e.printStackTrace();
-            return null;
-//            throw new XiaoShiException("外部接口检索超时");
+//            e.printStackTrace();
+//            return null;
+            throw new XiaoShiException("外部接口检索超时");
         }
         return null;
     }
 
-    private String formatCondition(String[] valueStrs, Integer pageNum, Integer pageSize) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("NO").append("=").append("(");
-        for (int i = (pageNum - 1) * pageSize; i < (pageNum * pageSize); i++) {
-            String valueStr = valueStrs[i];
-            if (i != (pageNum * pageSize) - 1) {
-                builder.append(valueStr).append(",");
-            } else {
-                builder.append(valueStr);
+    //封装patent column数据返回
+    private List<PatentColumnDTO> loadPatentList(List<PatentColumnDTO> columnDTOS, List<String> list, String dbType) {
+        if (CollectionUtils.isEmpty(list) || CollectionUtils.isEmpty(columnDTOS)) {
+            return list.isEmpty() ? columnDTOS : createNewDTOs(list);
+        }
+
+        List<PatentColumnDTO> result = new ArrayList<>(columnDTOS.size());
+        Set<String> searchedNumbers = new HashSet<>(); // 用于跟踪已搜索的专利号
+
+        for (String patentNo : list) {
+            boolean found = false;
+            String formattedNo = dbType.equals("CN") ? PatentNoUtil.formatApNo(patentNo) : patentNo;
+
+            for (PatentColumnDTO columnDTO : columnDTOS) {
+                if (containsNumber(columnDTO, formattedNo)) {
+                    PatentColumnDTO dto = new PatentColumnDTO();
+                    BeanUtils.copyProperties(columnDTO,dto);
+                    dto.setSearchNo(patentNo);
+                    result.add(dto);
+                    searchedNumbers.add(patentNo); // 标记为已搜索
+                    found = true;
+                    break; // 找到匹配项后跳出内层循环
+                }
+            }
+
+            if (!found) {
+                // 如果没有在columnDTOS中找到匹配项,则创建一个新的DTO
+                PatentColumnDTO newDTO = new PatentColumnDTO();
+                newDTO.setPatentNo(patentNo);
+                newDTO.setSearchNo(patentNo);
+                newDTO.setIfSearch(false);
+                result.add(newDTO);
             }
         }
-        return builder.append(")").toString();
+
+        return result;
+    }
+
+    private boolean containsNumber(PatentColumnDTO dto, String number) {
+        return dto.getAppNo().contains(number) || dto.getPublicNo().contains(number)
+                || dto.getGrantNo().contains(number) || dto.getRowApplicationNo().contains(number);
+    }
+
+    private List<PatentColumnDTO> createNewDTOs(List<String> list) {
+        List<PatentColumnDTO> newDTOs = new ArrayList<>();
+        for (String s : list) {
+            PatentColumnDTO dto = new PatentColumnDTO();
+            dto.setPatentNo(s);
+            dto.setSearchNo(s);
+            dto.setIfSearch(false);
+            newDTOs.add(dto);
+        }
+        return newDTOs;
     }
 
     public List<PatentStarListDTO> getSplitedConditions(PatentStarListDTO patentStarListDTO, int patentNum) throws IOException {