|
@@ -3,21 +3,28 @@ package cn.cslg.pas.service.importPatent;
|
|
|
import cn.cslg.pas.common.dto.PatentStarListDTO;
|
|
|
import cn.cslg.pas.common.dto.UploadPatentWebDTO;
|
|
|
import cn.cslg.pas.common.model.cronModel.Calculate;
|
|
|
-import cn.cslg.pas.common.utils.DateUtils;
|
|
|
-import cn.cslg.pas.common.utils.MathUtils;
|
|
|
-import cn.cslg.pas.common.utils.ThrowException;
|
|
|
+import cn.cslg.pas.common.model.cronModel.SystemFile;
|
|
|
+import cn.cslg.pas.common.utils.*;
|
|
|
import cn.cslg.pas.common.vo.ImportTaskAMVO;
|
|
|
import cn.cslg.pas.common.vo.StarPatentVO;
|
|
|
import cn.cslg.pas.common.vo.UploadParamsVO;
|
|
|
import cn.cslg.pas.domain.es.Patent;
|
|
|
import cn.cslg.pas.factorys.PatentImportFactory.PatentImportImp;
|
|
|
+import cn.cslg.pas.service.common.FileManagerService;
|
|
|
import cn.cslg.pas.service.common.PatentStarApiService;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import org.apache.commons.compress.utils.IOUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -35,14 +42,20 @@ public class ImportFromWebToEsService implements PatentImportImp {
|
|
|
|
|
|
private GetCataloguingFromWebThread getCataloguingFromWebThread;
|
|
|
|
|
|
- private GetPDFfromWebThread getPDFfromWebThread;
|
|
|
- private GetPictureFromWebThread getPictureFromWebThread;
|
|
|
+ private GetPatentPDFFromWebThread getPatentPDFFromWebThread;
|
|
|
+ private GetPatentPictureFromWebThread getPatentPictureFromWebThread;
|
|
|
private GetRightAndFullTextFromWebThread getRightAndFullTextFromWebThread;
|
|
|
-
|
|
|
+ private ApplicationContext applicationContext;
|
|
|
@Override
|
|
|
public void startPatentThread() {
|
|
|
+ //装载专利信息的计数器
|
|
|
+ Integer addPatentCounter = 0;
|
|
|
//十进制转二进制
|
|
|
- String imContents = MathUtils.fun(2, importTaskAMVO.getImportContent());
|
|
|
+ String imContents="0000";
|
|
|
+ if(!importTaskAMVO.getImportContent().equals(0)){
|
|
|
+ imContents = MathUtils.fun(2, importTaskAMVO.getImportContent());
|
|
|
+ }
|
|
|
+
|
|
|
//下载字段
|
|
|
char[] importCells = imContents.toCharArray();
|
|
|
char ifCataloguing = importCells[0];
|
|
@@ -54,102 +67,153 @@ public class ImportFromWebToEsService implements PatentImportImp {
|
|
|
importTaskAMVO.setIfAddPicture(ifAddPicture);
|
|
|
importTaskAMVO.setIfAddFullText(ifFullText);
|
|
|
importTaskAMVO.setIfAddPDF(ifPdf);
|
|
|
+ importTaskAMVO.setShouldSaveCounter(0);
|
|
|
+ importTaskAMVO.setHaveSaveCounter(0);
|
|
|
int patentNum = 10000;
|
|
|
savePatentToEsThread = new SavePatentToEsThread(taskThread, taskThread.getApplicationContext());
|
|
|
+ savePatentToEsThread.start();
|
|
|
if (ifAddPicture == '1') {
|
|
|
- getPictureFromWebThread = new GetPictureFromWebThread(taskThread, this);
|
|
|
- getPictureFromWebThread.start();
|
|
|
+ getPatentPictureFromWebThread = new GetPatentPictureFromWebThread(taskThread, this);
|
|
|
+ getPatentPictureFromWebThread.start();
|
|
|
+ importTaskAMVO.setShouldSaveCounter(importTaskAMVO.getShouldSaveCounter() + 1);
|
|
|
}
|
|
|
if (ifFullText == '1') {
|
|
|
getRightAndFullTextFromWebThread = new GetRightAndFullTextFromWebThread(taskThread, this);
|
|
|
getRightAndFullTextFromWebThread.start();
|
|
|
+ addPatentCounter += 1;
|
|
|
}
|
|
|
if (ifPdf == '1') {
|
|
|
- getPDFfromWebThread = new GetPDFfromWebThread(taskThread, this);
|
|
|
- getPDFfromWebThread.start();
|
|
|
+ getPatentPDFFromWebThread = new GetPatentPDFFromWebThread(taskThread, this);
|
|
|
+ getPatentPDFFromWebThread.start();
|
|
|
+ importTaskAMVO.setShouldSaveCounter(importTaskAMVO.getShouldSaveCounter() + 1);
|
|
|
}
|
|
|
- if (importTaskAMVO.getEndNum() <= patentNum) {
|
|
|
- if (ifCataloguing == '1') {
|
|
|
- getCataloguingFromWebThread = new GetCataloguingFromWebThread(taskThread, this);
|
|
|
- getCataloguingFromWebThread.start();
|
|
|
- }
|
|
|
- excuteLessThan10000(importTaskAMVO);
|
|
|
- } else {
|
|
|
+
|
|
|
+ if (ifCataloguing == '1') {
|
|
|
+ getCataloguingFromWebThread = new GetCataloguingFromWebThread(taskThread, this);
|
|
|
+ getCataloguingFromWebThread.start();
|
|
|
+ addPatentCounter += 1;
|
|
|
}
|
|
|
|
|
|
- savePatentToEsThread.start();
|
|
|
+ if (ifCataloguing == '1' || ifFullText == '1') {
|
|
|
+ importTaskAMVO.setShouldSaveCounter(importTaskAMVO.getShouldSaveCounter() + 1);
|
|
|
+ }
|
|
|
+ excuteLessThan10000(importTaskAMVO,addPatentCounter);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void excuteLessThan10000(ImportTaskAMVO importTaskAMVO) {
|
|
|
+ private void excuteLessThan10000(ImportTaskAMVO importTaskAMVO,Integer addPatentCounter) {
|
|
|
try {
|
|
|
- Integer successNum = importTaskAMVO.getSuccessNum(); //成功条数(即上一次下载到的位置)
|
|
|
- String conditions = importTaskAMVO.getSearchCondition(); //检索式
|
|
|
String orderBy = importTaskAMVO.getOrderBy(); //排序字段
|
|
|
String orderByType = importTaskAMVO.getOrderByType(); //排序类型
|
|
|
String dbType = importTaskAMVO.getDbType(); //检索数据库类型
|
|
|
- Integer importContent = importTaskAMVO.getImportContent(); //下载字段
|
|
|
- Integer doneNum = 0;
|
|
|
+ Integer doneNum = importTaskAMVO.getDoneNum();
|
|
|
+ int patentNum = 10000;
|
|
|
+
|
|
|
+ //检索式
|
|
|
+ String conditions = importTaskAMVO.getSearchCondition();
|
|
|
+
|
|
|
+ //获得返回的的多个检索式 patentStarListDtos
|
|
|
+ List<PatentStarListDTO> patentStarListDtos = patentStarApiService.getSplitedConditions(new PatentStarListDTO()
|
|
|
+ .setCurrentQuery(conditions)
|
|
|
+ .setOrderBy(orderBy)
|
|
|
+ .setOrderByType(orderByType)
|
|
|
+ .setDBType(dbType), patentNum);
|
|
|
+
|
|
|
+ //当专利为专利号导入时
|
|
|
+ if (importTaskAMVO.getType().equals(2)) {
|
|
|
+ conditions = conditions.replaceAll(" +", ""); //去掉所有空格
|
|
|
+ List<String> patentNos = Arrays.asList(conditions.split("[,|,]")); //生成专利号集合
|
|
|
+ String join = StringUtils.join(patentNos, " OR ");
|
|
|
+ conditions = "AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")";
|
|
|
+ importTaskAMVO.setDbType("CN");
|
|
|
+ }
|
|
|
+
|
|
|
+ //当专利为专利号文件导入时
|
|
|
+ if (importTaskAMVO.getType().equals(3)) {
|
|
|
+ FileManagerService fileManagerService = applicationContext.getBean(FileManagerService.class);
|
|
|
+
|
|
|
+ String res = fileManagerService.getSystemFileFromFMS(Arrays.asList(importTaskAMVO.getFileGuid()));
|
|
|
+ List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
|
|
|
+ SystemFile systemFile = systemFiles.get(0);
|
|
|
+ String suffix = systemFile.getFileName().substring(systemFile.getFileName().lastIndexOf("."));
|
|
|
+ //调用文件系统取出文件接口,获得文件流
|
|
|
+ byte[] bytes = fileManagerService.downloadSystemFileFromFMS(importTaskAMVO.getFileGuid());
|
|
|
+ //创建临时文件tempFile,并将文件读取到tempFile
|
|
|
+ File tempFile = File.createTempFile(systemFile.getFileName() + "temp", suffix);
|
|
|
+ try (
|
|
|
+ InputStream inputStream = new ByteArrayInputStream(bytes);
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(tempFile)
|
|
|
+ ) {
|
|
|
+ IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
|
|
|
+ }
|
|
|
+ Sheet sheet = ReadExcelUtils.readExcel(tempFile);
|
|
|
+ List<String> patentNos = ReadExcelUtils.getPatentNoFromExcel(sheet);
|
|
|
+ String join = StringUtils.join(patentNos, " OR ");
|
|
|
+ conditions = "AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")";
|
|
|
+ }
|
|
|
+
|
|
|
char ifCataloguing = importTaskAMVO.getIfAddCatalogue();
|
|
|
char ifAddPicture = importTaskAMVO.getIfAddPicture();
|
|
|
char ifAddFullText = importTaskAMVO.getIfAddFullText();
|
|
|
char ifPdf = importTaskAMVO.getIfAddPDF();
|
|
|
- //十进制转二进制
|
|
|
- String imContents = MathUtils.fun(2, importContent);
|
|
|
//下载字段
|
|
|
- char[] importCells = imContents.toCharArray();
|
|
|
- Calculate calculate = DateUtils.calculateFromStartAndEndNumber(doneNum, importTaskAMVO.getAllNum(), 50);
|
|
|
- Integer startPage = calculate.getStartPage();
|
|
|
- Integer startNum = calculate.getStartNum();
|
|
|
- Integer endPage = calculate.getEndPage();
|
|
|
-
|
|
|
- //根据计算出的起止页数,一页一页检索
|
|
|
- for (int i = startPage; i <= endPage; i++) {
|
|
|
- PatentStarListDTO patentStarListDto = new PatentStarListDTO()
|
|
|
- .setCurrentQuery(conditions)
|
|
|
- .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 = 0; j < starPatents.size(); j++) {
|
|
|
- UploadPatentWebDTO uploadPatentWebDTO = new UploadPatentWebDTO();
|
|
|
- Patent patent = new Patent();
|
|
|
|
|
|
- //装载start
|
|
|
- uploadPatentWebDTO.setStarPatentVO(starPatents.get(i));
|
|
|
- uploadPatentWebDTO.setPatent(patent);
|
|
|
- uploadPatentWebDTO.setCounter(0);
|
|
|
|
|
|
- if (ifCataloguing == '1') {
|
|
|
- getCataloguingFromWebThread.awakeTask(uploadPatentWebDTO);
|
|
|
- uploadPatentWebDTO.setCounter(uploadPatentWebDTO.getCounter()+1);
|
|
|
- }
|
|
|
- if (ifAddPicture == '1') {
|
|
|
- getPictureFromWebThread.awakeTask(uploadPatentWebDTO);
|
|
|
- uploadPatentWebDTO.setCounter(uploadPatentWebDTO.getCounter()+1);
|
|
|
- }
|
|
|
- if (ifAddFullText == '1') {
|
|
|
- getRightAndFullTextFromWebThread.awakeTask(uploadPatentWebDTO);
|
|
|
- uploadPatentWebDTO.setCounter(uploadPatentWebDTO.getCounter()+1);
|
|
|
+ //已经跳过的数量
|
|
|
+ Integer overNum =0;
|
|
|
+ while (patentStarListDtos.size() > 0) {
|
|
|
+ PatentStarListDTO patentStarListDto = patentStarListDtos.remove(0);
|
|
|
+ Integer total=patentStarListDto.getTotal();
|
|
|
+ overNum+=total;
|
|
|
+ if(total<=doneNum){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Integer startNum =overNum-doneNum;
|
|
|
+ Calculate calculate = DateUtils.calculateFromStartAndEndNumber(startNum, total, 50);
|
|
|
+ Integer startPage = calculate.getStartPage();
|
|
|
+ Integer endPage = calculate.getEndPage();
|
|
|
+ for (int i = startPage; i <= endPage; i++) {
|
|
|
+ //调用一般接口返回一批专利著录相关数据
|
|
|
+ Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
|
|
|
+ if (resultMap == null || (Integer) resultMap.get("total") == 0) {
|
|
|
+ ThrowException.throwXiaoShiException("未检索到相关专利");
|
|
|
}
|
|
|
- if(ifPdf=='1'){
|
|
|
- getPDFfromWebThread.awakeTask(uploadPatentWebDTO);
|
|
|
- uploadPatentWebDTO.setCounter(uploadPatentWebDTO.getCounter()+1);
|
|
|
+
|
|
|
+ List<StarPatentVO> starPatents = (List<StarPatentVO>) resultMap.get("records");
|
|
|
+ //遍历这一页的专利
|
|
|
+ for (int j = 0; j < starPatents.size(); j++) {
|
|
|
+ if((i*50+j)<startNum){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ UploadPatentWebDTO uploadPatentWebDTO = new UploadPatentWebDTO();
|
|
|
+ Patent patent = new Patent();
|
|
|
+
|
|
|
+ //装载start
|
|
|
+ uploadPatentWebDTO.setStarPatentVO(starPatents.get(i));
|
|
|
+ uploadPatentWebDTO.setPatent(patent);
|
|
|
+ uploadPatentWebDTO.setCounter(0);
|
|
|
+ uploadPatentWebDTO.setTotalCounter(addPatentCounter);
|
|
|
+ uploadPatentWebDTO.setHaveSaveCounter(0);
|
|
|
+ if (ifCataloguing == '1') {
|
|
|
+ getCataloguingFromWebThread.awakeTask(uploadPatentWebDTO);
|
|
|
+ }
|
|
|
+ if (ifAddPicture == '1') {
|
|
|
+ getPatentPictureFromWebThread.awakeTask(uploadPatentWebDTO);
|
|
|
+ }
|
|
|
+ if (ifAddFullText == '1') {
|
|
|
+ getRightAndFullTextFromWebThread.awakeTask(uploadPatentWebDTO);
|
|
|
+ }
|
|
|
+ if (ifPdf == '1') {
|
|
|
+ getPatentPDFFromWebThread.awakeTask(uploadPatentWebDTO);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
+ }catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
//生产消费到一半时,发生错误异常,将任务状态置为完成
|
|
|
// task = taskService.getById(task.getId());
|
|
@@ -161,16 +225,16 @@ public class ImportFromWebToEsService implements PatentImportImp {
|
|
|
@Override
|
|
|
public void setTaskThread(TaskThread taskThread) {
|
|
|
this.taskThread = taskThread;
|
|
|
- ApplicationContext applicationContext = taskThread.getApplicationContext();
|
|
|
+ this.applicationContext = taskThread.getApplicationContext();
|
|
|
this.patentStarApiService = applicationContext.getBean(PatentStarApiService.class);
|
|
|
this.importTaskAMVO = taskThread.getImportTaskAMVO();
|
|
|
}
|
|
|
|
|
|
+ //加入es保存队列
|
|
|
public void savePatentToEs(UploadPatentWebDTO uploadPatentWebDTO) {
|
|
|
+
|
|
|
uploadPatentWebDTO.setCounter(uploadPatentWebDTO.getCounter() + 1);
|
|
|
if (uploadPatentWebDTO.getTotalCounter().equals(uploadPatentWebDTO.getCounter())) {
|
|
|
- uploadPatentWebDTO.setIfAddPatent(false);
|
|
|
- uploadPatentWebDTO.setIfAddPicture(false);
|
|
|
savePatentToEsThread.awakeTask(uploadPatentWebDTO);
|
|
|
}
|
|
|
}
|