chendayu 2 years ago
parent
commit
884a20be4e

+ 0 - 4
PAS/src/main/java/cn/cslg/pas/common/model/outApi/PatentStarListDto.java

@@ -4,10 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 import lombok.Data;
 import lombok.experimental.Accessors;
 import org.joda.time.DateTime;
-import reactor.util.annotation.NonNull;
-
-import javax.validation.constraints.NotNull;
-import java.util.Date;
 
 /**
  * 专利之星检索dto类

+ 17 - 20
PAS/src/main/java/cn/cslg/pas/service/outApi/PatentStarApiService.java

@@ -4,30 +4,28 @@ import cn.cslg.pas.common.model.PersonnelVO;
 import cn.cslg.pas.common.model.outApi.PatentStarDto;
 import cn.cslg.pas.common.model.outApi.PatentStarListDto;
 import cn.cslg.pas.common.model.vo.outApi.StarPatentVO;
-import cn.cslg.pas.common.utils.*;
+import cn.cslg.pas.common.utils.CacheUtils;
+import cn.cslg.pas.common.utils.DateUtils2;
+import cn.cslg.pas.common.utils.FormatUtil;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
+import cn.cslg.pas.common.utils.ThrowException;
 import cn.cslg.pas.domain.*;
 import cn.cslg.pas.service.upLoadPatent.RetrieveRecordService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import io.swagger.v3.oas.models.security.SecurityScheme;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import okhttp3.FormBody;
 import okhttp3.OkHttpClient;
 import okhttp3.Request;
 import okhttp3.Response;
-
 import org.joda.time.DateTime;
-import org.joda.time.Days;
-import org.joda.time.Months;
 import org.joda.time.format.DateTimeFormat;
 import org.joda.time.format.DateTimeFormatter;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
-import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
@@ -287,10 +285,10 @@ public class PatentStarApiService {
 
     public Map<String, Object> patentStarSearchApi(PatentStarListDto patentStarListDto) throws IOException {
         try {
-if(patentStarListDto.getFormed()==null||patentStarListDto.getFormed()==false) {
-    String formQuery = patentStarListDto.getCurrentQuery();
-    patentStarListDto.setCurrentQuery(PatentStarApiService.formatQuery(formQuery));
-}
+            if (patentStarListDto.getFormed() == null || patentStarListDto.getFormed() == false) {
+                String formQuery = patentStarListDto.getCurrentQuery();
+                patentStarListDto.setCurrentQuery(PatentStarApiService.formatQuery(formQuery));
+            }
         } catch (Exception e) {
             return null;
         }
@@ -344,7 +342,7 @@ if(patentStarListDto.getFormed()==null||patentStarListDto.getFormed()==false) {
         return null;
     }
 
-    public List<PatentStarListDto> test(PatentStarListDto patentStarListDto) throws IOException {
+    public List<PatentStarListDto> getSplitedConditions(PatentStarListDto patentStarListDto, int patentNum) throws IOException {
         DateTime nowDate = new DateTime();
         DateTime date = DateUtils2.formStrToDateTime("2000-01-01");
         //超过1万的列表
@@ -363,7 +361,7 @@ if(patentStarListDto.getFormed()==null||patentStarListDto.getFormed()==false) {
             Integer total1 = Integer.parseInt(map1.get("total").toString());
             dto.setTotal(total1);
             patentStarListDto.setFormed(true);
-            if (total1 > 10000) {
+            if (total1 > patentNum) {
                 DateTime startTime1 = dto.getStartTime();
                 DateTime endTime1 = dto.getEndTime();
                 List<DateTime> dateTimes = DateUtils2.formStrToDateTime(startTime1, endTime1);
@@ -379,8 +377,7 @@ if(patentStarListDto.getFormed()==null||patentStarListDto.getFormed()==false) {
                 this.setConditions(dto2);
                 patentStarListDtos.add(dto1);
                 patentStarListDtos.add(dto2);
-            }
-            else{
+            } else if (total1 != 0) {
                 reDtos.add(dto);
             }
 
@@ -391,12 +388,12 @@ if(patentStarListDto.getFormed()==null||patentStarListDto.getFormed()==false) {
 
     public void setConditions(PatentStarListDto patentStarListDto) {
         DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd");
-        String startStr =formatter.print(patentStarListDto.getStartTime());
-        String endStr =formatter.print(patentStarListDto.getEndTime());
-        String cond = "*(" + startStr+ ">" + endStr + "/" + "AD)";
-        Integer len =patentStarListDto.getOrginCondition().length();
-        StringBuilder stringBuilder =new StringBuilder(patentStarListDto.getOrginCondition());
-        stringBuilder.insert(len-1,cond);
+        String startStr = formatter.print(patentStarListDto.getStartTime());
+        String endStr = formatter.print(patentStarListDto.getEndTime());
+        String cond = "*(" + startStr + ">" + endStr + "/" + "AD)";
+        Integer len = patentStarListDto.getOrginCondition().length();
+        StringBuilder stringBuilder = new StringBuilder(patentStarListDto.getOrginCondition());
+        stringBuilder.insert(len - 1, cond);
         patentStarListDto.setCurrentQuery(stringBuilder.toString());
     }
 

+ 66 - 63
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/ExcutePatentDataStar.java

@@ -61,9 +61,11 @@ public class ExcutePatentDataStar implements IExcutePatentData {
     public void startExcute(Task task) throws IOException {
 
         //若本次下载任务是超过一万条专利的全部下载任务
-        if (task.getEndNumber() == 50) {
+        int patentNum = 300;
+        if (task.getEndNumber() > patentNum) {
             try {
-                Integer total = task.getTotal();
+                Integer total = task.getTotal();  //任务专利总数量
+                Integer successNum = task.getSuccessNum();
                 String orderBy = task.getOrderBy();  //排序字段
                 String orderByType = task.getOrderByType();  //排序类型
                 String dbType = task.getDBType();  //检索数据库类型
@@ -71,76 +73,74 @@ public class ExcutePatentDataStar implements IExcutePatentData {
                 Integer startNumber = task.getStartNumber();  //下载起始条数位置
                 List<String> isDeletePatentNos = task.getIsDeletePatentNos();  //起止条数中不需要下载的专利号
 
-                //多个检索式
-                ArrayList<MultipleCondition> multipleConditions = new ArrayList<>();
-                multipleConditions.add(new MultipleCondition().setConditions("AD=20230511 AND TI=(计算机 OR 手机)").setTotal(26));
-                multipleConditions.add(new MultipleCondition().setConditions("AD=20230512 AND TI=(计算机 OR 手机)").setTotal(15));
-                multipleConditions.add(new MultipleCondition().setConditions("AD=20230531 AND TI=(计算机 OR 手机)").setTotal(16));
-
-                //第一层遍历多个检索式,第二层遍历每个检索式检索出的检索页数,第三层遍历每页专利
-                int lastH, lastI, lastJ;
-                //若本次下载是暂停后继续,则取出上一次遍历位置信息
-                if (task.getContinueLastInformation() != null && !task.getContinueLastInformation().equals("")) {
-                    String[] lastIndexArr = task.getContinueLastInformation().split("\\|");
-                    lastH = Integer.parseInt(lastIndexArr[0]);
-                    lastI = Integer.parseInt(lastIndexArr[1]);
-                    lastJ = Integer.parseInt(lastIndexArr[2]);
-                } else {
-                    lastH = 0;
-                    lastI = 0;
-                    lastJ = 0;
+                //如果完成数量大于0,则当前下载任务为暂停后的继续下载,则开始位置更新
+                if (successNum > 0) {
+                    startNumber += successNum;
                 }
 
-                for (int h = lastH; h < multipleConditions.size(); h++) {
-                    Calculate calculate = calculateFromStartAndEndNumber(1, multipleConditions.get(h).getTotal());
-                    //根据计算出的起止页数,一页一页检索
-                    for (int i = lastI; i <= calculate.getEndPage(); i++) {
-                        PatentStarListDto patentStarListDto = new PatentStarListDto()
-                                .setCurrentQuery(multipleConditions.get(h).getConditions())
+                //获得返回的的多个检索式 patentStarListDtos
+                List<PatentStarListDto> patentStarListDtos = patentStarApiService.getSplitedConditions(new PatentStarListDto().setCurrentQuery(task.getConditions()), patentNum);
+
+                int produceSuccessNum = 0;
+                int countForStart = 0;  //定义变量countForStart,记录检索式的专利总数量(目的是找出下载开始位置专利所属的那个检索式)
+                //第1层:遍历多个检索式
+                for (PatentStarListDto patentStarListDto : patentStarListDtos) {
+                    //还没有到开始位置,则跳过,继续判断下一个检索式
+                    countForStart += patentStarListDto.getTotal();
+                    if (countForStart < startNumber) {
+                        continue;
+                    }
+
+                    //至此,即找到了当前检索式即为要下载的专利开始位置所属的检索式,重新计算开始位置startNumber(即要下载的专利的开始位置,对应了当前检索式中该专利位置)
+                    startNumber = startNumber - (countForStart - patentStarListDto.getTotal());
+                    //第一个检索式下载完成后,从第二个检索式开始 startNumber都是从1开始下载
+                    if (startNumber < 0) {
+                        startNumber = 1;
+                    }
+                    //调用方法,入参为开始位置和结束位置(即当前检索式最后一个专利的位置,即当前检索式的专利总数量total),获得开始页数、结束页数、开始页数的开始位置、结束页数的结束位置
+                    Calculate calculate = calculateFromStartAndEndNumber(startNumber, patentStarListDto.getTotal());
+                    Integer startPage = calculate.getStartPage();
+                    Integer startNum = calculate.getStartNum();
+                    Integer endPage = calculate.getEndPage();
+
+                    //第2层:遍历检索页数
+                    for (Integer i = startPage; i <= endPage; i++) {
+                        //调用一般检索接口,返回一批专利著录相关数据
+                        Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(new PatentStarListDto()
+                                .setCurrentQuery(patentStarListDto.getCurrentQuery())
                                 .setOrderBy(orderBy)
                                 .setOrderByType(orderByType)
-                                .setPageNum(i + 1)
+                                .setPageNum(i)
                                 .setRowCount(50)
-                                .setDBType(dbType);
-                        //调用一般接口返回一批专利著录相关数据
-                        Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
+                                .setDBType(dbType)
+                                .setFormed(true));
                         if (resultMap == null || (Integer) resultMap.get("total") == 0) {
                             ThrowException.throwXiaoShiException("未检索到相关专利");
                         }
 
                         List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
-                        //遍历这一页的专利
-                        for (int j = lastJ; j < starPatents.size(); j++) {
-                            //若任务状态为已暂停,则将当前三层循环的位置信息保存入任务条件表,并结束本次任务的下载
+                        //第3层:遍历专利
+                        for (int j = 0; j < starPatents.size(); j++) {
+                            //若任务状态为已暂停,则结束本次任务的下载
                             if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
-                                TaskCondition taskCondition = new TaskCondition()
-                                        .setId(task.getTaskConditionId())
-                                        .setContinueLastInformation(h + "|" + i + "|" + j);
-                                taskConditionService.updateById(taskCondition);
                                 return;
                             }
-
-                            //判断若本任务是第一次下载,并且刚检索到第一页专利
-                            if (h == 0 && i == 0) {
-                                //如果还没走到需要下载的专利开始位置startNumber,则跳过
-                                if (j < startNumber - 1) {
-                                    continue;
-                                }
-                            }
-
-                            //查询当前任务完成专利数量,判断若达到total,则结束
-                            if (taskService.getById(task.getId()).getSuccessNum().equals(total)) {
+                            //若生产的数量达到了总数,则结束本次任务的下载
+                            if (produceSuccessNum == total) {
                                 return;
                             }
-
-                            //若当前遍历到的专利号是需要删除的专利,则跳过,不下载它
+                            //如果还没到要下载的专利的开始位置,则跳过,继续判断下一个专利
+                            if (i.equals(startPage) && j < startNum - 1) {
+                                continue;
+                            }
+                            //如果当前遍历到的专利号是需要删除的专利,则跳过,不下载它
                             if (isDeletePatentNos != null && isDeletePatentNos.size() > 0 && isDeletePatentNos.contains(starPatents.get(j).getApplicationNo())) {
                                 continue;
                             }
 
+                            //将专利丢入各生产线程,进行生产和消费
                             UploadParamsVO uploadParamsVO = new UploadParamsVO();
-                            Patent patent = new Patent();
-                            uploadParamsVO.setPatent(patent);
+                            uploadParamsVO.setPatent(new Patent());
                             uploadParamsVO.getPatent().setPatentNo(starPatents.get(j).getPatentNo());
                             uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
 
@@ -170,6 +170,8 @@ public class ExcutePatentDataStar implements IExcutePatentData {
                                 pantentQueueService.imageToPQueue(pQueueData);
                             }
 
+                            produceSuccessNum++;  //计数,每生产完一个,生产完成数量++
+
                         }
                     }
 
@@ -204,6 +206,7 @@ public class ExcutePatentDataStar implements IExcutePatentData {
             Integer endNumber = task.getEndNumber();  //下载终止条数位置
             List<String> isAddPatentNos = task.getIsAddPatentNos();  //需要额外下载的专利号
             List<String> isDeletePatentNos = task.getIsDeletePatentNos();  //起止条数中不需要下载的专利号
+
             //startToEndNum:起止条数中需要下载的专利总数量
             int startToEndNum = 0;
             if (endNumber > 0) {
@@ -213,12 +216,12 @@ public class ExcutePatentDataStar implements IExcutePatentData {
                 }
             }
 
-            //若有完成条数,即表示此次任务为暂停后的继续执行,则将起始条数 startNumber重置为成功条数 + 1
+            //如果完成数量大于0,则当前下载任务为暂停后的继续下载,则开始位置更新
             if (successNum > 0) {
-                startNumber = successNum + 1;
+                startNumber += successNum;
             }
 
-            //若有起止条数,并且完成条数在起止条数内(即起止条数专利还没有下载完)
+            //若有起止条数,并且完成条数在起止条数内(即起止条数专利还没有下载完)
             if (endNumber > 0 && startNumber <= endNumber && successNum < startToEndNum) {
                 Calculate calculate = calculateFromStartAndEndNumber(startNumber, endNumber);
                 Integer startPage = calculate.getStartPage();
@@ -227,13 +230,12 @@ public class ExcutePatentDataStar implements IExcutePatentData {
                 Integer endNum = calculate.getEndNum();
 
                 //根据计算出的起止页数,一页一页检索
-                int pageNum = startPage;
                 for (int i = startPage; i <= endPage; i++) {
                     PatentStarListDto patentStarListDto = new PatentStarListDto()
                             .setCurrentQuery(conditions)
                             .setOrderBy(orderBy)
                             .setOrderByType(orderByType)
-                            .setPageNum(pageNum++)
+                            .setPageNum(i)
                             .setRowCount(50)
                             .setDBType(dbType);
                     //调用一般接口返回一批专利著录相关数据
@@ -262,9 +264,9 @@ public class ExcutePatentDataStar implements IExcutePatentData {
                             continue;
                         }
 
+                        //将专利丢入各生产线程,进行生产和消费
                         UploadParamsVO uploadParamsVO = new UploadParamsVO();
-                        Patent patent = new Patent();
-                        uploadParamsVO.setPatent(patent);
+                        uploadParamsVO.setPatent(new Patent());
                         uploadParamsVO.getPatent().setPatentNo(starPatents.get(j).getPatentNo());
                         uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
 
@@ -299,16 +301,17 @@ public class ExcutePatentDataStar implements IExcutePatentData {
                 }
             }
 
-            //若是暂停后继续的任务,若 successNum > startToEndNum,即上一次已经下载完了起止条数中的专利,还下载了isAdd中的部分专利
+            //若是暂停后继续的任务,若 successNum > startToEndNum,即已经下载完了起止条数中的专利
             int fromIndex = 0;
             if (successNum > 0 && successNum > startToEndNum) {
                 fromIndex = successNum - startToEndNum;
             }
             //下载isAdd中的专利 / 下载多个专利号导入接口的专利 ↓
             if (isAddPatentNos != null && isAddPatentNos.size() > 0) {
-                //fromIndex > 0 表示上一次执行的下载已经下载了isAdd中的部分专利,此次需要下载剩余专利
-                if (fromIndex > 0) {
-                    isAddPatentNos = isAddPatentNos.subList(fromIndex, isAddPatentNos.size() - 1);
+                if (fromIndex > 0 && fromIndex < isAddPatentNos.size() - 1) {
+                    isAddPatentNos = isAddPatentNos.subList(fromIndex, isAddPatentNos.size());
+                } else if (fromIndex == isAddPatentNos.size() - 1) {
+                    isAddPatentNos = Arrays.asList(isAddPatentNos.get(isAddPatentNos.size() - 1));
                 }
                 //若是检索页面网站导入,则isAddPatentNos是前台传的多个申请号,即包含"."
                 if (isAddPatentNos.get(0).contains(".")) {

+ 3 - 1
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/PantentQueueService.java

@@ -480,7 +480,9 @@ public class PantentQueueService {
                 if (patentInstructionPDFQueueList.size() > 0) {
                     queueData = patentInstructionPDFQueueList.remove(0);
                     //说明书pdf入库
-                    patentInstructionService.edit(queueData.getUploadParamsVO().getPatent().getPatentNo(), queueData.getUploadParamsVO().getFileDTO());
+                    if (queueData.getUploadParamsVO().getFileDTO() != null) {
+                        patentInstructionService.edit(queueData.getUploadParamsVO().getPatent().getPatentNo(), queueData.getUploadParamsVO().getFileDTO());
+                    }
 
                     sendMessage(queueData);
                 } else {