|
@@ -9,8 +9,10 @@ import cn.cslg.pas.common.utils.FileUtils;
|
|
|
import cn.cslg.pas.common.utils.RemoveHtmlTagsUtils;
|
|
|
import cn.cslg.pas.common.utils.ThrowException;
|
|
|
import cn.cslg.pas.domain.*;
|
|
|
+import cn.cslg.pas.domain.asso.TaskCondition;
|
|
|
import cn.cslg.pas.service.TaskService;
|
|
|
import cn.cslg.pas.service.UploadPatentBatchService;
|
|
|
+import cn.cslg.pas.service.asso.TaskConditionService;
|
|
|
import cn.cslg.pas.service.outApi.PatentStarApiService;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
@@ -25,8 +27,6 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.net.URL;
|
|
|
-import java.sql.Timestamp;
|
|
|
-import java.text.DateFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
@@ -48,6 +48,7 @@ public class ExcutePatentDataStar implements IExcutePatentData {
|
|
|
private final PantentQueueService pantentQueueService;
|
|
|
private final UploadPatentBatchService uploadPatentBatchService;
|
|
|
private final TaskService taskService;
|
|
|
+ private final TaskConditionService taskConditionService;
|
|
|
private Integer pTaskId = 0;
|
|
|
private Integer pTaskStatus = 0;
|
|
|
|
|
@@ -58,8 +59,141 @@ public class ExcutePatentDataStar implements IExcutePatentData {
|
|
|
*/
|
|
|
@Override
|
|
|
public void startExcute(Task task) throws IOException {
|
|
|
+
|
|
|
+ //若本次下载任务是超过一万条专利的全部下载任务
|
|
|
+ if (task.getEndNumber() == 50) {
|
|
|
+ try {
|
|
|
+ Integer total = task.getTotal();
|
|
|
+ String orderBy = task.getOrderBy(); //排序字段
|
|
|
+ String orderByType = task.getOrderByType(); //排序类型
|
|
|
+ String dbType = task.getDBType(); //检索数据库类型
|
|
|
+ List<String> cells = task.getConfigCells(); //下载字段
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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())
|
|
|
+ .setOrderBy(orderBy)
|
|
|
+ .setOrderByType(orderByType)
|
|
|
+ .setPageNum(i + 1)
|
|
|
+ .setRowCount(50)
|
|
|
+ .setDBType(dbType);
|
|
|
+ //调用一般接口返回一批专利著录相关数据
|
|
|
+ Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
|
|
|
+ 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++) {
|
|
|
+ //若任务状态为已暂停,则将当前三层循环的位置信息保存入任务条件表,并结束本次任务的下载
|
|
|
+ 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)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //若当前遍历到的专利号是需要删除的专利,则跳过,不下载它
|
|
|
+ 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.getPatent().setPatentNo(starPatents.get(j).getPatentNo());
|
|
|
+ uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
|
|
|
+
|
|
|
+ PQueueData pQueueData = new PQueueData()
|
|
|
+ .setTask(task)
|
|
|
+ .setStarPatent(starPatents.get(j))
|
|
|
+ .setUploadParamsVO(uploadParamsVO);
|
|
|
+
|
|
|
+ //专利丢入著录生产者队列,并唤醒著录生产者线程
|
|
|
+ if (cells.contains("1")) {
|
|
|
+ pantentQueueService.zhuluToPQueue(pQueueData);
|
|
|
+ }
|
|
|
+ //专利丢入权要生产者队列,并唤醒权要生产者线程
|
|
|
+ if (cells.contains("2")) {
|
|
|
+ pantentQueueService.rightToPQueue(pQueueData);
|
|
|
+ }
|
|
|
+ //专利丢入说明书文本生产者队列,并唤醒说明书文本生产者线程
|
|
|
+ if (cells.contains("3")) {
|
|
|
+ pantentQueueService.instructionTextToPQueue(pQueueData);
|
|
|
+ }
|
|
|
+ //专利丢入说明书pdf生产者队列,并唤醒说明书pdf生产者线程
|
|
|
+ if (cells.contains("4")) {
|
|
|
+ pantentQueueService.instructionPDFToPQueue(pQueueData);
|
|
|
+ }
|
|
|
+ //专利丢入摘要附图生产者队列,并唤醒摘要附图生产者线程
|
|
|
+ if (cells.contains("6")) {
|
|
|
+ pantentQueueService.imageToPQueue(pQueueData);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //生产消费到一半时,发生错误异常,将任务状态置为完成
|
|
|
+ task = taskService.getById(task.getId());
|
|
|
+ if (task.getStatus().equals(1)) {
|
|
|
+ task.setStatus(2);
|
|
|
+ taskService.updateById(task);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ excuteLessThan10000(task);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void excuteLessThan10000(Task task) {
|
|
|
try {
|
|
|
- Integer total = task.getTotal(); //总条数
|
|
|
Integer successNum = task.getSuccessNum(); //成功条数(即上一次下载到的位置)
|
|
|
String conditions = task.getConditions(); //检索式
|
|
|
String orderBy = task.getOrderBy(); //排序字段
|
|
@@ -70,7 +204,6 @@ 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) {
|
|
@@ -87,24 +220,11 @@ public class ExcutePatentDataStar implements IExcutePatentData {
|
|
|
|
|
|
//若有起止条数,并且完成条数在起止条数内(即起止条数的专利还没有下载完)
|
|
|
if (endNumber > 0 && startNumber <= endNumber && successNum < startToEndNum) {
|
|
|
- int startPage; //检索开始页数
|
|
|
- int startNum; //检索开始页数的开始专利位置
|
|
|
- int endPage; //检索结束页数
|
|
|
- int endNum; //检索结束页数的结束专利位置
|
|
|
- if (startNumber % 50 != 0) {
|
|
|
- startPage = startNumber / 50 + 1;
|
|
|
- startNum = startNumber % 50;
|
|
|
- } else {
|
|
|
- startPage = startNumber / 50;
|
|
|
- startNum = 50;
|
|
|
- }
|
|
|
- if (endNumber % 50 != 0) {
|
|
|
- endPage = endNumber / 50 + 1;
|
|
|
- endNum = endNumber % 50;
|
|
|
- } else {
|
|
|
- endPage = endNumber / 50;
|
|
|
- endNum = 50;
|
|
|
- }
|
|
|
+ Calculate calculate = calculateFromStartAndEndNumber(startNumber, endNumber);
|
|
|
+ Integer startPage = calculate.getStartPage();
|
|
|
+ Integer startNum = calculate.getStartNum();
|
|
|
+ Integer endPage = calculate.getEndPage();
|
|
|
+ Integer endNum = calculate.getEndNum();
|
|
|
|
|
|
//根据计算出的起止页数,一页一页检索
|
|
|
int pageNum = startPage;
|
|
@@ -179,7 +299,7 @@ public class ExcutePatentDataStar implements IExcutePatentData {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //若是暂停后继续的任务,若 successNum > startToEndNum,即上一次执行不仅下载完了起止条数中的专利,还下载了isAdd中的部分专利
|
|
|
+ //若是暂停后继续的任务,若 successNum > startToEndNum,即上一次已经下载完了起止条数中的专利,还下载了isAdd中的部分专利
|
|
|
int fromIndex = 0;
|
|
|
if (successNum > 0 && successNum > startToEndNum) {
|
|
|
fromIndex = successNum - startToEndNum;
|
|
@@ -208,8 +328,6 @@ public class ExcutePatentDataStar implements IExcutePatentData {
|
|
|
taskService.updateById(task);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -677,6 +795,42 @@ public class ExcutePatentDataStar implements IExcutePatentData {
|
|
|
return (int) timeStamp;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据起止条数计算开始页数、开始页数的开始位置、结束页数、结束页数的结束位置
|
|
|
+ *
|
|
|
+ * @param startNumber 起始条数
|
|
|
+ * @param endNumber 终止条数
|
|
|
+ * @return 返回计算结果对象(开始页数、开始页数的开始位置、结束页数、结束页数的结束位置)
|
|
|
+ */
|
|
|
+ public Calculate calculateFromStartAndEndNumber(Integer startNumber, Integer endNumber) {
|
|
|
+ int startPage; //检索开始页数
|
|
|
+ int startNum; //检索开始页数的开始专利位置
|
|
|
+ int endPage; //检索结束页数
|
|
|
+ int endNum; //检索结束页数的结束专利位置
|
|
|
+ if (startNumber % 50 != 0) {
|
|
|
+ startPage = startNumber / 50 + 1;
|
|
|
+ startNum = startNumber % 50;
|
|
|
+ } else {
|
|
|
+ startPage = startNumber / 50;
|
|
|
+ startNum = 50;
|
|
|
+ }
|
|
|
+ if (endNumber % 50 != 0) {
|
|
|
+ endPage = endNumber / 50 + 1;
|
|
|
+ endNum = endNumber % 50;
|
|
|
+ } else {
|
|
|
+ endPage = endNumber / 50;
|
|
|
+ endNum = 50;
|
|
|
+ }
|
|
|
+
|
|
|
+ Calculate calculate = new Calculate()
|
|
|
+ .setStartPage(startPage)
|
|
|
+ .setStartNum(startNum)
|
|
|
+ .setEndPage(endPage)
|
|
|
+ .setEndNum(endNum);
|
|
|
+
|
|
|
+ return calculate;
|
|
|
+ }
|
|
|
+
|
|
|
public void setTaskStatus(Integer taskId, Integer taskStatus) {
|
|
|
this.pTaskId = taskId;
|
|
|
this.pTaskStatus = taskStatus;
|