1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150 |
- package cn.cslg.pas.service.upLoadPatent;
- import cn.cslg.pas.common.model.dto.PatentDTO;
- import cn.cslg.pas.common.model.dto.UploadFileDTO;
- import cn.cslg.pas.common.model.outApi.PatentStarListDto;
- import cn.cslg.pas.common.model.vo.KeyValueVO;
- import cn.cslg.pas.common.model.vo.UploadParamsVO;
- import cn.cslg.pas.common.model.vo.outApi.StarPatentVO;
- 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.getPatentStarPart.GetPatentStarPartService;
- import cn.cslg.pas.service.outApi.PatentStarApiService;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson2.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.fileupload.FileItem;
- import org.apache.commons.fileupload.disk.DiskFileItemFactory;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.web.multipart.MultipartFile;
- import org.springframework.web.multipart.commons.CommonsMultipartFile;
- import java.io.*;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- /**
- * 专利之星类型任务解析获取专利类
- *
- * @Author chenyu
- * @Date 2023/6/25
- */
- @Slf4j
- @RequiredArgsConstructor
- @Service
- public class ExcutePatentDataStar implements IExcutePatentData {
- private final PatentStarApiService patentStarApiService;
- private final FileUtils fileUtils;
- private final PantentQueueService pantentQueueService;
- private final UploadPatentBatchService uploadPatentBatchService;
- private final TaskService taskService;
- private final TaskConditionService taskConditionService;
- private final QuestionRecordService questionRecordService;
- private Integer pTaskId = 0;
- private Integer pTaskStatus = 0;
- /**
- * 解析获取专利数据
- *
- * @param task 任务
- */
- @Override
- public void startExcute(Task task) throws IOException {
- //若本次下载任务是超过一万条专利的全部下载任务
- int patentNum = 10000;
- if (task.getEndNumber() > patentNum) {
- try {
- Integer total = task.getTotal(); //任务专利总数量
- Integer successNum = task.getSuccessNum();
- 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(); //起止条数中不需要下载的专利号
- //如果完成数量大于0,则当前下载任务为暂停后的继续下载,则开始位置更新
- if (successNum > 0) {
- startNumber += successNum;
- }
- //获得返回的的多个检索式 patentStarListDtos
- List<PatentStarListDto> patentStarListDtos = patentStarApiService.getSplitedConditions(new PatentStarListDto()
- .setCurrentQuery(task.getConditions())
- .setOrderBy(orderBy)
- .setOrderByType(orderByType)
- .setDBType(dbType), 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++) {
- //调用一般检索接口,返回一批专利著录相关数据
- patentStarListDto
- .setPageNum(i)
- .setRowCount(50)
- .setFormed(true);
- 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");
- //第3层:遍历专利
- for (int j = 0; j < starPatents.size(); j++) {
- //若任务状态为已暂停,则结束本次任务的下载
- if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
- return;
- }
- //若生产的数量达到了总数,则结束本次任务的下载
- 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();
- uploadParamsVO.setPatent(new 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);
- }
- produceSuccessNum++; //计数,每生产完一个,生产完成数量++
- }
- }
- }
- } 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 successNum = task.getSuccessNum(); //成功条数(即上一次下载到的位置)
- String conditions = task.getConditions(); //检索式
- String orderBy = task.getOrderBy(); //排序字段
- String orderByType = task.getOrderByType(); //排序类型
- String dbType = task.getDBType(); //检索数据库类型
- List<String> cells = task.getConfigCells(); //下载字段
- Integer startNumber = task.getStartNumber(); //下载起始条数位置
- Integer endNumber = task.getEndNumber(); //下载终止条数位置
- List<String> isAddPatentNos = task.getIsAddPatentNos(); //需要额外下载的专利号
- List<String> isDeletePatentNos = task.getIsDeletePatentNos(); //起止条数中不需要下载的专利号
- //startToEndNum:起止条数中需要下载的专利总数量
- int startToEndNum = 0;
- if (endNumber > 0) {
- startToEndNum = endNumber - startNumber + 1;
- if (isDeletePatentNos != null && isDeletePatentNos.size() > 0) {
- startToEndNum = startToEndNum - isDeletePatentNos.size();
- }
- }
- //如果完成数量大于0,则当前下载任务为暂停后的继续下载,则开始位置更新
- if (successNum > 0) {
- if (startNumber == null) { //多个专利号导入任务没有startNumber这些值
- startNumber = 0;
- }
- startNumber += successNum;
- }
- //若有起止条数,并且完成条数在起止条数内(即起止条数中专利还没有下载完)
- if (endNumber > 0 && startNumber <= endNumber && successNum < startToEndNum) {
- Calculate calculate = calculateFromStartAndEndNumber(startNumber, endNumber);
- Integer startPage = calculate.getStartPage();
- Integer startNum = calculate.getStartNum();
- Integer endPage = calculate.getEndPage();
- Integer endNum = calculate.getEndNum();
- //根据计算出的起止页数,一页一页检索
- for (int i = startPage; i <= endPage; i++) {
- PatentStarListDto patentStarListDto = new PatentStarListDto()
- .setCurrentQuery(conditions)
- .setOrderBy(orderBy)
- .setOrderByType(orderByType)
- .setPageNum(i)
- .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++) {
- //若任务状态为已暂停,则结束生产
- if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
- return;
- }
- //若还没到开始页的开始位置,则跳过,不下载它
- if (i == startPage && j < startNum - 1) {
- continue;
- }
- //若到了结束页的结束位置
- if (i == endPage && j == endNum) {
- break;
- }
- //若当前遍历到的专利号是需要删除的专利,则跳过,不下载它
- if (isDeletePatentNos != null && isDeletePatentNos.size() > 0 && isDeletePatentNos.contains(starPatents.get(j).getApplicationNo())) {
- continue;
- }
- //将专利丢入各生产线程,进行生产和消费
- UploadParamsVO uploadParamsVO = new UploadParamsVO();
- uploadParamsVO.setPatent(new 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);
- }
- }
- }
- }
- //下载isAdd中的专利 / 下载多个专利号导入接口的专利 ↓
- if (isAddPatentNos != null && isAddPatentNos.size() > 0) {
- //判断isAdd中的多个专利号或申请号,即判断是检索页面手动勾选的多个专利下载/还是多个专利号导入的下载任务
- if (task.getIsAddType() != null && task.getIsAddType().equals(2)) {
- //若是多个专利号导入的下载
- String patentNoCondition = StringUtils.join(isAddPatentNos, " OR ");
- conditions = "AN=(" + patentNoCondition + ") OR PN=(" + patentNoCondition + ") OR GN=(" + patentNoCondition + ")";
- downLoadIsAddPatentNos(isAddPatentNos, task, orderBy, orderByType, dbType, cells, conditions);
- } else {
- //若是检索页面手动勾选的多个专利的下载
- downLoadIsAddPatentNos(isAddPatentNos, task, orderBy, orderByType, dbType, cells, null);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- //生产消费到一半时,发生错误异常,将任务状态置为完成
- task = taskService.getById(task.getId());
- if (task.getStatus().equals(1)) {
- task.setStatus(2);
- taskService.updateById(task);
- }
- }
- }
- /**
- * 装载著录方法
- *
- * @param starPatent 专利之星著录对象
- * @param uploadParamsVO 专利实体类对象
- */
- public void setPatentZhuLu(StarPatentVO starPatent, UploadParamsVO uploadParamsVO) throws IOException {
- String usedPatentNo;
- if (starPatent.getPublicNo() != null && !starPatent.getPublicNo().equals("")) {
- usedPatentNo = starPatent.getPublicNo();
- } else {
- usedPatentNo = starPatent.getPatentNo();
- }
- //以下 ↓装载的是调用"一般检索"接口返回的专利相关数据
- //装载专利类型
- Integer patentType = starPatent.getPatentType();
- if (patentType != null) {
- if (patentType.equals(2) || patentType.equals(9)) {
- uploadParamsVO.getPatent().setType(1); //实用新型
- } else if (patentType.equals(1) || patentType.equals(8)) {
- uploadParamsVO.getPatent().setType(2); //发明
- } else if (patentType.equals(3)) {
- uploadParamsVO.getPatent().setType(3); //外观设计
- }
- }
- //装载申请人地址
- if (starPatent.getApplicationAddress() != null && !starPatent.getApplicationAddress().equals("")) {
- ArrayList<String> patentApplicantOriginalAddresss = new ArrayList<>();
- patentApplicantOriginalAddresss.add(starPatent.getApplicationAddress());
- uploadParamsVO.setPatentApplicantOriginalAddress(patentApplicantOriginalAddresss);
- }
- //装载IPC分类号
- if (starPatent.getIpcListStr() != null && !starPatent.getIpcListStr().equals("")) {
- String[] ipcArr = starPatent.getIpcListStr().split(";");
- //装载主分类号
- //uploadParamsVO.setMainIpc(ipcArr[0]);
- uploadParamsVO.setMainIpc(starPatent.getMainIpc());
- uploadParamsVO.setIpcList(Arrays.asList(ipcArr));
- }
- //装载公告日(公开授权日)
- if (starPatent.getPublicAccreditDate() != null && !starPatent.getPublicAccreditDate().equals("")) {
- int timeStamp = stringDateToTimeStamp(starPatent.getPublicAccreditDate());
- uploadParamsVO.getPatent().setPublicAccreditDate(timeStamp);
- }
- //装载摘要
- if (starPatent.getAbstractStr() != null && !starPatent.getAbstractStr().equals("")) {
- uploadParamsVO.getPatent().setAbstractStr(starPatent.getAbstractStr());
- }
- //装载申请日
- if (starPatent.getApplicationDate() != null && !starPatent.getApplicationDate().equals("")) {
- int timeStamp = stringDateToTimeStamp(starPatent.getApplicationDate());
- uploadParamsVO.getPatent().setApplicationDate(timeStamp);
- }
- //装载发明人
- if (starPatent.getInventorStr() != null && !starPatent.getInventorStr().equals("")) {
- List<String> patentInventorNames = Arrays.asList(starPatent.getInventorStr().split(";"));
- ArrayList<PatentInventor> patentInventors = new ArrayList<>();
- for (String patentInventorName : patentInventorNames) {
- PatentInventor patentInventor = new PatentInventor();
- patentInventor.setName(patentInventorName);
- patentInventors.add(patentInventor);
- }
- uploadParamsVO.setPatentInventorList(patentInventors);
- }
- //装载专利号
- if (starPatent.getPatentNo() != null && !starPatent.getPatentNo().equals("")) {
- uploadParamsVO.getPatent().setPatentNo(starPatent.getPatentNo());
- }
- //装载授权号(公开授权日)
- if (starPatent.getPublicAccreditNo() != null && !starPatent.getPublicAccreditNo().equals("")) {
- uploadParamsVO.getPatent().setPublicAccreditNo(starPatent.getPublicAccreditNo());
- }
- //装载代理机构地址
- if (starPatent.getAgencyStr() != null && !starPatent.getAgencyStr().equals("")) {
- String agencyAddress;
- if (starPatent.getAgencyStr().contains(" ")) {
- agencyAddress = starPatent.getAgencyStr().substring(0, starPatent.getAgencyStr().lastIndexOf(" "));
- } else {
- agencyAddress = starPatent.getAgencyStr();
- }
- uploadParamsVO.getPatent().setAgencyId(agencyAddress);
- }
- //装载申请号
- if (starPatent.getApplicationNo() != null && !starPatent.getApplicationNo().equals("")) {
- uploadParamsVO.getPatent().setApplicationNo(starPatent.getApplicationNo());
- }
- //装载申请人
- if (starPatent.getApplicantStr() != null && !starPatent.getApplicantStr().equals("")) {
- uploadParamsVO.setPatentApplicantOriginalName(Arrays.asList(starPatent.getApplicantStr().split(";")));
- }
- //装载代理人
- if (starPatent.getAgentStr() != null && !starPatent.getAgentStr().equals("")) {
- List<String> patentAgents = Arrays.asList(starPatent.getAgentStr().split(";"));
- ArrayList<PatentAgent> patentAgentList = new ArrayList<>();
- for (String n : patentAgents) {
- PatentAgent patentAgent = new PatentAgent();
- patentAgent.setName(n);
- patentAgentList.add(patentAgent);
- }
- uploadParamsVO.setPatentAgentList(patentAgentList);
- }
- //装载公开日
- if (starPatent.getPublicDate() != null && !starPatent.getPublicDate().equals("")) {
- int timeStamp = stringDateToTimeStamp(starPatent.getPublicDate());
- uploadParamsVO.getPatent().setPublicDate(timeStamp);
- }
- //装载标题
- if (starPatent.getName() != null && !starPatent.getName().equals("")) {
- uploadParamsVO.getPatent().setName(starPatent.getName());
- }
- //装载权利人
- if (starPatent.getCurrentApplicantStr() != null && !starPatent.getCurrentApplicantStr().equals("")) {
- uploadParamsVO.setPatentApplicantCurrentName(Arrays.asList(starPatent.getCurrentApplicantStr().split(";")));
- }
- //装载法律状态(os_patent表status字段值)
- Integer status = starPatent.getLG();
- if (status != null) {
- //有效(有权)
- if (status == 1) {
- uploadParamsVO.getPatent().setSimpleStatus(3);
- //失效(无权)
- } else if (status == 2) {
- uploadParamsVO.getPatent().setSimpleStatus(2);
- //审中(审中)
- } else if (status == 3) {
- uploadParamsVO.getPatent().setSimpleStatus(1);
- }
- }
- //装载公开号
- if (starPatent.getPublicNo() != null && !starPatent.getPublicNo().equals("")) {
- uploadParamsVO.getPatent().setPublicNo(starPatent.getPublicNo());
- }
- if (starPatent.getSimpleStatus() != null && !starPatent.getSimpleStatus().equals("")) {
- uploadParamsVO.setPatentSimpleStatus(starPatent.getSimpleStatus());
- uploadParamsVO.setSimpleStatus(starPatent.getSimpleStatus());
- }
- //装载优先权
- if (starPatent.getPriorityNo() != null && !starPatent.getPriorityNo().equals("")) {
- uploadParamsVO.getPatent().setPriorityNo(starPatent.getPriorityNo());
- }
- //装载优先权日
- if (starPatent.getPriorityDate() != null && !starPatent.getPriorityDate().equals("")) {
- int timeStamp = stringDateToTimeStamp(starPatent.getPriorityDate());
- uploadParamsVO.getPatent().setPriorityDate(timeStamp);
- }
- //装载受理局
- if (starPatent.getBureau() != null && !starPatent.getBureau().equals("")) {
- uploadParamsVO.getPatent().setBureau(starPatent.getBureau());
- }
- String appNo;
- if (starPatent.getApplicationNo().contains(".")) {
- appNo = starPatent.getApplicationNo().substring(0, starPatent.getApplicationNo().lastIndexOf("."));
- } else {
- appNo = starPatent.getApplicationNo();
- }
- try {
- //以下 ↓装载的是调用"获得中国专利著录"接口返回的专利相关数据
- if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
- String chinaPatentZhuLuStr = patentStarApiService.getCnBibApi(appNo);
- if (chinaPatentZhuLuStr != null && !chinaPatentZhuLuStr.trim().equals("") && !chinaPatentZhuLuStr.equals("{}") && !chinaPatentZhuLuStr.contains("请求不合法")) {
- List<ChinaPatentZhuLu> chinaPatentZhuLus = JSON.parseArray(chinaPatentZhuLuStr, ChinaPatentZhuLu.class);
- ChinaPatentZhuLu chinaPatentZhuLu = chinaPatentZhuLus.get(0);
- //装载申请人地址
- if (uploadParamsVO.getPatentApplicantOriginalAddress() == null || uploadParamsVO.getPatentApplicantOriginalAddress().size() == 0) {
- if (chinaPatentZhuLu.getDZ() != null && !chinaPatentZhuLu.getDZ().equals("")) {
- List<String> patentApplicantOriginalAddresss = new ArrayList<>();
- if (chinaPatentZhuLu.getDZ().contains(" ")) {
- patentApplicantOriginalAddresss.add(chinaPatentZhuLu.getDZ().substring(chinaPatentZhuLu.getDZ().indexOf(" ") + 1));
- } else {
- patentApplicantOriginalAddresss.add(chinaPatentZhuLu.getDZ());
- }
- uploadParamsVO.setPatentApplicantOriginalAddress(patentApplicantOriginalAddresss);
- }
- }
- //装载代理人
- if (uploadParamsVO.getPatentAgentList() == null || uploadParamsVO.getPatentAgentList().size() == 0) {
- if (chinaPatentZhuLu.getAT() != null && !chinaPatentZhuLu.getAT().equals("")) {
- List<String> patentAgents = Arrays.asList(chinaPatentZhuLu.getAT().split(";"));
- ArrayList<PatentAgent> patentAgentList = new ArrayList<>();
- for (String n : patentAgents) {
- PatentAgent patentAgent = new PatentAgent();
- patentAgent.setName(n);
- patentAgentList.add(patentAgent);
- }
- uploadParamsVO.setPatentAgentList(patentAgentList);
- }
- }
- //装载代理机构地址
- if (uploadParamsVO.getPatent().getAgencyId() == null || uploadParamsVO.getPatent().getAgencyId().equals("")) {
- if (chinaPatentZhuLu.getAGN() != null && !chinaPatentZhuLu.getAGN().equals("")) {
- String agencyAddress;
- if (chinaPatentZhuLu.getAGN().contains(" ")) {
- agencyAddress = chinaPatentZhuLu.getAGN().substring(0, chinaPatentZhuLu.getAGN().lastIndexOf(" "));
- } else {
- agencyAddress = chinaPatentZhuLu.getAGN();
- }
- uploadParamsVO.getPatent().setAgencyId(agencyAddress);
- }
- }
- //装载发明人
- if (uploadParamsVO.getPatentInventorList() == null || uploadParamsVO.getPatentInventorList().size() == 0) {
- if (chinaPatentZhuLu.getIV() != null && !chinaPatentZhuLu.getIV().equals("")) {
- List<String> patentInventorNames = Arrays.asList(chinaPatentZhuLu.getIV().split(";"));
- ArrayList<PatentInventor> patentInventors = new ArrayList<>();
- for (String patentInventorName : patentInventorNames) {
- PatentInventor patentInventor = new PatentInventor();
- patentInventor.setName(patentInventorName);
- patentInventors.add(patentInventor);
- }
- uploadParamsVO.setPatentInventorList(patentInventors);
- }
- }
- //装载优先权号、优先权国家、优先权日
- if (uploadParamsVO.getPatent().getPriorityNo() == null || uploadParamsVO.getPatent().getPriorityNo().equals("")) {
- uploadParamsVO.getPatent().setPriorityNo(chinaPatentZhuLu.getPR());
- }
- }
- } else { //以下 ↓装载的是调用"获得世界专利著录"接口返回的专利相关数据
- String worldPatentZhuLuStr = patentStarApiService.getENBibApi(usedPatentNo);
- List<WorldPatentZhuLu> worldPatentZhuLus = JSON.parseArray(worldPatentZhuLuStr, WorldPatentZhuLu.class);
- WorldPatentZhuLu worldPatentZhuLu = worldPatentZhuLus.get(0);
- //装载公开号
- if (uploadParamsVO.getPatent().getPublicNo() == null || uploadParamsVO.getPatent().getPublicNo().equals("")) {
- uploadParamsVO.getPatent().setPatentNo(worldPatentZhuLu.getDocdbPubNo());
- }
- //装载申请号
- if (uploadParamsVO.getPatent().getApplicationNo() == null || uploadParamsVO.getPatent().getApplicationNo().equals("")) {
- uploadParamsVO.getPatent().setApplicationNo(worldPatentZhuLu.getEpoAppNo());
- }
- //装载申请日
- if (uploadParamsVO.getPatent().getApplicationDate() == null) {
- int timeStamp = stringDateToTimeStamp(worldPatentZhuLu.getAppDate());
- uploadParamsVO.getPatent().setApplicationDate(timeStamp);
- }
- //装载公开日
- if (uploadParamsVO.getPatent().getPublicDate() == null) {
- int timeStamp = stringDateToTimeStamp(worldPatentZhuLu.getPubDate());
- uploadParamsVO.getPatent().setPublicDate(timeStamp);
- }
- //装载IPC分类号
- if (uploadParamsVO.getIpcList() == null || uploadParamsVO.getIpcList().size() == 0) {
- String[] ipcArr = worldPatentZhuLu.getIpc().split(";");
- //装载主分类号
- if (uploadParamsVO.getMainIpc() == null || uploadParamsVO.getMainIpc().equals("")) {
- uploadParamsVO.setMainIpc(ipcArr[0]);
- }
- //装载IPC分类号
- uploadParamsVO.setIpcList(Arrays.asList(ipcArr));
- }
- //装载CPC分类号
- if (uploadParamsVO.getCpcList() == null || uploadParamsVO.getCpcList().size() == 0) {
- if (worldPatentZhuLu.getCpc() != null && !worldPatentZhuLu.getCpc().equals("")) {
- String[] cpcArr = worldPatentZhuLu.getCpc().split(";");
- uploadParamsVO.setCpcList(Arrays.asList(cpcArr));
- }
- }
- //装载申请人
- if (uploadParamsVO.getPatentApplicantOriginalName() == null || uploadParamsVO.getPatentApplicantOriginalName().size() == 0) {
- uploadParamsVO.setPatentApplicantOriginalName(Arrays.asList(worldPatentZhuLu.getPa().split(";")));
- }
- //装载发明人
- if (uploadParamsVO.getPatentInventorList() == null || uploadParamsVO.getPatentInventorList().size() == 0) {
- if (worldPatentZhuLu.getIv() != null && !worldPatentZhuLu.getIv().equals("")) {
- List<String> patentInventorNames = Arrays.asList(worldPatentZhuLu.getIv().split(";"));
- ArrayList<PatentInventor> patentInventors = new ArrayList<>();
- for (String patentInventorName : patentInventorNames) {
- PatentInventor patentInventor = new PatentInventor();
- patentInventor.setName(patentInventorName);
- patentInventors.add(patentInventor);
- }
- uploadParamsVO.setPatentInventorList(patentInventors);
- }
- }
- //装载优先权
- if (uploadParamsVO.getPatent().getPriorityNo() == null || uploadParamsVO.getPatent().getPriorityNo().equals("")) {
- uploadParamsVO.getPatent().setPriorityNo(worldPatentZhuLu.getPr());
- }
- //装载标题
- if (uploadParamsVO.getPatent().getName() == null || uploadParamsVO.getPatent().getName().equals("")) {
- uploadParamsVO.getPatent().setName(worldPatentZhuLu.getTitle());
- }
- //装载摘要
- if (uploadParamsVO.getPatent().getAbstractStr() == null || uploadParamsVO.getPatent().getAbstractStr().equals("")) {
- uploadParamsVO.getPatent().setAbstractStr(worldPatentZhuLu.getAbstract());
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- //以下 ↓装载的是调用"获得同族专利"接口返回的专利相关数据
- try {
- if (starPatent.getPatentNo() != null && !starPatent.getPatentNo().equals("")) {
- String familyPatentNoStr = patentStarApiService.getFamilyByPubNoApi(usedPatentNo);
- if (!familyPatentNoStr.equals("no data") && !familyPatentNoStr.equals("{}")) {
- FamilyPatentNo familyPatentNo = JSON.parseObject(familyPatentNoStr, FamilyPatentNo.class);
- List<String> familyPatentNos = Arrays.asList(familyPatentNo.getFamilyinfo().split(";"));
- uploadParamsVO.setSimpleFamily(familyPatentNos);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- //以下 ↓装载的是调用"获得中国专利法律状态"接口返回的专利相关数据
- try {
- if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
- PatentAffair patentAffair = new PatentAffair();
- String cnLegalApiStr = patentStarApiService.getCnLegalApi(appNo);
- if (!cnLegalApiStr.equals("")) {
- List<ChinaLeagalStatus> chinaLeagalStatuses = JSON.parseArray(cnLegalApiStr, ChinaLeagalStatus.class);
- if (chinaLeagalStatuses != null && chinaLeagalStatuses.size() > 0) {
- ArrayList<KeyValueVO> lst = new ArrayList<>();
- HashMap<Integer, String> nameMap = new HashMap<>();
- HashMap<Integer, String> contentMap = new HashMap<>();
- nameMap.put(0, "发生日期");
- nameMap.put(1, "法律状态");
- nameMap.put(2, "详细法律状态");
- nameMap.put(3, "详细信息");
- for (int i = 0; i < chinaLeagalStatuses.size(); i++) {
- if (i == 0) {
- patentAffair.setStatus(chinaLeagalStatuses.get(i).getLegalStatus());
- }
- contentMap.put(0, chinaLeagalStatuses.get(i).getLegalDate());
- contentMap.put(1, chinaLeagalStatuses.get(i).getLegalStatus());
- contentMap.put(2, chinaLeagalStatuses.get(i).getLegalStatusInfo());
- contentMap.put(3, chinaLeagalStatuses.get(i).getDETAIL());
- ArrayList<KeyValueVO.InpadocData> inpadocDatas = new ArrayList<>();
- for (int j = 0; j < 4; j++) {
- KeyValueVO.InpadocData inpadocData = new KeyValueVO.InpadocData();
- inpadocData.setName(nameMap.get(j));
- inpadocData.setContent(contentMap.get(j));
- inpadocDatas.add(inpadocData);
- }
- KeyValueVO keyValueVO = new KeyValueVO();
- keyValueVO.setInpadocData(inpadocDatas);
- lst.add(keyValueVO);
- }
- //装载事务表的status(公开|授权|驳回|权力转移。。。)
- String content = JSONObject.toJSONString(lst);
- patentAffair.setContent(content);
- uploadParamsVO.setPatentAffair(patentAffair);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 装载权要方法
- *
- * @param starPatent 专利之星著录对象
- * @param uploadParamsVO 专利实体类对象
- */
- public Boolean setPatentClaim(StarPatentVO starPatent, UploadParamsVO uploadParamsVO, PQueueData pQueueData) throws IOException {
- try {
- if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
- String applicationNo = starPatent.getApplicationNo() + "";
- String appNo;
- if (starPatent.getApplicationNo().contains(".")) {
- appNo = starPatent.getApplicationNo().substring(0, starPatent.getApplicationNo().lastIndexOf("."));
- } else {
- appNo = starPatent.getApplicationNo();
- }
- //根据申请号调用"获得中国专利全文文本"接口,获得包含各种xml标签的专利全文内容的长字符串 cnFullXmlStr
- String cnFullXmlStr = patentStarApiService.getCnFullXmlApi(appNo);
- //若没有取到全文文本即取不到权要,则将该专利检索专利之星接口次数+1,重新丢入权要生产队列,将当前申请号或专利号和备注信息记录到问题记录表,返回false
- if (cnFullXmlStr.equals("")) {
- if (pQueueData != null && pQueueData.getCallNum() < 2) {
- pQueueData.setCallNum(pQueueData.getCallNum() + 1);
- pantentQueueService.rightToPQueue(pQueueData);
- return false;
- }
- recordQuestionPatent(applicationNo, pQueueData.getTask().getId(), 2);
- return true;
- }
- //使用正则表达式拼接出权要原文
- String regex = "(?<=<claim id=.{1,110}>)[\\w\\W]+?(?=</claim>)";
- Pattern compile = Pattern.compile(regex);
- Matcher matcher = compile.matcher(cnFullXmlStr);
- StringBuilder builder = new StringBuilder();
- while (matcher.find()) {
- String macherGroup = matcher.group();
- String right = macherGroup.replaceAll("<!--.*?-->", "").trim();
- right = right.replaceAll("<.*?>", "").trim();
- right = right.replaceAll(" +", "");
- right = right.replace("\r\n", "").replace("\n", "");
- builder.append(right).append("\r\n");
- }
- String patentRightText = builder + "";
- //使用工具类去除字符串文本中的所有HTML格式标签
- patentRightText = RemoveHtmlTagsUtils.removeHtmlTags(patentRightText);
- patentRightText = patentRightText.trim();
- //装载权利要求原文
- PatentRight patentRight = new PatentRight();
- patentRight.setContent(patentRightText);
- uploadParamsVO.setPatentRight(patentRight);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return true;
- }
- return true;
- }
- /**
- * 装载说明书文本
- *
- * @param starPatent 专利之星著录对象
- * @param uploadParamsVO 专利实体类对象
- */
- public Boolean setPatentInstructionText(StarPatentVO starPatent, UploadParamsVO uploadParamsVO, PQueueData pQueueData) throws IOException {
- try {
- if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
- String applicationNo = starPatent.getApplicationNo() + "";
- String appNo;
- if (starPatent.getApplicationNo().contains(".")) {
- appNo = starPatent.getApplicationNo().substring(0, starPatent.getApplicationNo().lastIndexOf("."));
- } else {
- appNo = starPatent.getApplicationNo();
- }
- //根据申请号调用"获得中国专利全文文本"接口,获得包含各种xml标签的专利全文内容的长字符串 cnFullXmlStr
- String cnFullXmlStr = patentStarApiService.getCnFullXmlApi(appNo);
- //若没有取到全文文本,即取不到说明书文本,则将当前申请号或专利号和备注信息记录到问题记录表
- if (cnFullXmlStr.equals("")) {
- if (pQueueData != null && pQueueData.getCallNum() < 2) {
- pQueueData.setCallNum(pQueueData.getCallNum() + 1);
- pantentQueueService.rightToPQueue(pQueueData);
- return false;
- }
- recordQuestionPatent(applicationNo, pQueueData.getTask().getId(), 3);
- return true;
- }
- //使用正则表达式拼接出说明书文本全文
- String regex = "(?<=<description>)[\\w\\W]+?(?=</description>)";
- Pattern compile = Pattern.compile(regex);
- Matcher matcher = compile.matcher(cnFullXmlStr);
- String text = "";
- while (matcher.find()) {
- text = matcher.group();
- text = text.replaceAll("<invention-title[^>]*>.*?(\\n{0,}|\\s{0,}?)</invention-title>", "");
- text = text.replaceAll("<br/>", "");
- text = text.replaceAll("\\s", "");
- }
- //装载说明书文本全文
- PatentInstructionText patentInstructionText = new PatentInstructionText();
- patentInstructionText.setManual(text.trim());
- uploadParamsVO.setPatentInstructionText(patentInstructionText);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return true;
- }
- return true;
- }
- /**
- * 装载说明书pdf
- *
- * @param starPatent 专利之星著录对象
- * @param uploadParamsVO 专利实体类对象
- */
- public void setPatentInstructionPDF(StarPatentVO starPatent, UploadParamsVO uploadParamsVO, Task task) throws IOException {
- String usedPatentNo;
- if (starPatent.getPublicNo() != null && !starPatent.getPublicNo().equals("")) {
- usedPatentNo = starPatent.getPublicNo();
- } else {
- usedPatentNo = starPatent.getPatentNo();
- }
- try {
- String pdfUrl = "", pdfUrl1 = "", pdfUrl2 = "";
- if ((starPatent.getPatentNo() != null && !starPatent.getPatentNo().equals("")) || (starPatent.getApplicationNo() != null && !starPatent.getApplicationNo().equals(""))) {
- //先根据公开号判断国家,若没有公开号再根据申请号判断,调用"获得中国专利pdf"接口,获得1个或2个pdf的url地址
- if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
- String appNo = starPatent.getApplicationNo();
- if (appNo.contains(".")) {
- appNo = appNo.substring(0, appNo.lastIndexOf("."));
- }
- String pdfUrlStr = patentStarApiService.getCnPdfApi(appNo);
- //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
- if (pdfUrlStr.equals("")) {
- recordQuestionPatent(starPatent.getPatentNo(), task.getId(), 4);
- return;
- }
- if (pdfUrlStr.contains("|http")) { //若包含公开和授权两个pdf
- String[] pdfUrlArr = pdfUrlStr.split("\\|http");
- pdfUrl1 = pdfUrlArr[0].substring(pdfUrlArr[0].indexOf("http"), pdfUrlArr[0].indexOf("?"));
- pdfUrlArr[1] = "http" + pdfUrlArr[1];
- pdfUrl2 = pdfUrlArr[1].substring(pdfUrlArr[1].indexOf("http"), pdfUrlArr[1].indexOf("?"));
- UploadFileDTO fileDTO = downLoadPdf(pdfUrl1);
- UploadFileDTO fileDTO2 = downLoadPdf(pdfUrl2);
- if (pdfUrl1.contains("0A_CN_0.pdf")) {
- uploadParamsVO.setPdf1FileDTO(fileDTO);
- uploadParamsVO.setPdf2FileDTO(fileDTO2);
- } else {
- uploadParamsVO.setPdf1FileDTO(fileDTO2);
- uploadParamsVO.setPdf2FileDTO(fileDTO);
- }
- } else { //若只有一个
- pdfUrl1 = pdfUrlStr.substring(pdfUrlStr.indexOf("http"), pdfUrlStr.indexOf("?"));
- UploadFileDTO fileDTO = downLoadPdf(pdfUrl1);
- if (pdfUrl1.contains("0A_CN_0.pdf")) {
- uploadParamsVO.setPdf1FileDTO(fileDTO);
- } else {
- uploadParamsVO.setPdf2FileDTO(fileDTO);
- }
- }
- //根据专利号调用"获得世界专利pdf"接口,获得pdf的url地址
- } else {
- pdfUrl = patentStarApiService.getEnPdfApi(usedPatentNo);
- //若没有取到说明书pdf,则将当前申请号和备注信息存入问题记录表,并返回空对象
- if (pdfUrl.equals("") || pdfUrl.equals("{}")) {
- recordQuestionPatent(starPatent.getPatentNo(), task.getId(), 4);
- return;
- }
- UploadFileDTO fileDTO = downLoadPdf(pdfUrl);
- uploadParamsVO.setPdf1FileDTO(fileDTO);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 装载摘要附图
- *
- * @param starPatent 专利之星著录对象
- * @param uploadParamsVO 专利实体类对象
- */
- public void setPatentPicture(StarPatentVO starPatent, UploadParamsVO uploadParamsVO) throws IOException {
- try {
- //调用"获取中国专利摘要附图"接口
- String appNo = starPatent.getApplicationNo();
- if (appNo.contains(".")) {
- appNo = appNo.substring(0, appNo.lastIndexOf("."));
- }
- if ((starPatent.getPublicNo() != null && starPatent.getPublicNo().contains("CN")) || (starPatent.getPublicNo() == null && starPatent.getPatentNo().contains("CN"))) {
- String pictureUrl = patentStarApiService.getPictureApi(appNo);
- URL url = new URL(pictureUrl); //想要读取的url地址
- InputStream in = url.openStream();
- File file = File.createTempFile("new_url", ".jpg"); //创建文件
- OutputStream os = new FileOutputStream(file); //创建文件输出流
- int bytesRead;
- byte[] buffer = new byte[8192];
- int len = 8192;
- while ((bytesRead = in.read(buffer, 0, len)) != -1) {
- os.write(buffer, 0, bytesRead);
- }
- //关闭释放流
- os.close();
- in.close();
- DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
- FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
- buffer = new byte[8192];
- FileInputStream fis = new FileInputStream(file);
- OutputStream fos = item.getOutputStream();
- len = 8192;
- while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
- fos.write(buffer, 0, bytesRead);
- }
- //关闭释放流
- fos.close();
- fis.close();
- MultipartFile multipartFile = new CommonsMultipartFile(item);
- UploadFileDTO fileDTO = fileUtils.uploadFile(multipartFile);
- uploadParamsVO.setPictureFileDTO(fileDTO);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 下载指定多个专利号专利
- *
- * @param isAddPatentNos 起止条数以外,用户手动勾选的多个专利号
- */
- public void downLoadIsAddPatentNos(List<String> isAddPatentNos, Task task, String orderBy, String orderByType, String dbType, List<String> cells, String conditions) throws IOException {
- if (conditions == null) {
- conditions = "AN=(" + StringUtils.join(isAddPatentNos, " OR ") + ")";
- }
- int pageNum = 1;
- for (int i = 0; i < isAddPatentNos.size(); i += 50) {
- PatentStarListDto patentStarListDto = new PatentStarListDto()
- .setCurrentQuery(conditions)
- .setOrderBy(orderBy)
- .setOrderByType(orderByType)
- .setPageNum(pageNum++)
- .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 (StarPatentVO starPatent : starPatents) {
- //判断若任务状态为已暂停,则结束生产
- if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
- return;
- }
- try {
- UploadParamsVO uploadParamsVO = new UploadParamsVO();
- Patent patent = new Patent();
- uploadParamsVO.setPatent(patent);
- uploadParamsVO.getPatent().setPatentNo(starPatent.getPatentNo());
- uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
- PQueueData pQueueData = new PQueueData()
- .setTask(task)
- .setStarPatent(starPatent)
- .setUploadParamsVO(uploadParamsVO);
- //装载专利著录
- if (cells.contains("1")) {
- pantentQueueService.zhuluToPQueue(pQueueData);
- }
- //装载权要
- if (cells.contains("2")) {
- pantentQueueService.rightToPQueue(pQueueData);
- }
- //装载说明书文本
- if (cells.contains("3")) {
- pantentQueueService.instructionTextToPQueue(pQueueData);
- }
- //装载说明书pdf
- if (cells.contains("4")) {
- pantentQueueService.instructionPDFToPQueue(pQueueData);
- }
- //装载摘要附图
- if (cells.contains("6")) {
- pantentQueueService.imageToPQueue(pQueueData);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- public UploadFileDTO downLoadPdf(String pdfUrl) throws IOException {
- URL url = new URL(pdfUrl); //想要读取的url地址
- InputStream in = url.openStream();
- File file = File.createTempFile("new_url", ".pdf"); //创建文件
- OutputStream os = new FileOutputStream(file); //创建文件输出流
- int bytesRead;
- byte[] buffer = new byte[8192];
- int len = 8192;
- while ((bytesRead = in.read(buffer, 0, len)) != -1) {
- os.write(buffer, 0, bytesRead);
- }
- //关闭释放流
- os.close();
- in.close();
- DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
- FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
- buffer = new byte[8192];
- FileInputStream fis = new FileInputStream(file);
- OutputStream fos = item.getOutputStream();
- len = 8192;
- while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
- fos.write(buffer, 0, bytesRead);
- }
- //关闭释放流
- fos.close();
- fis.close();
- MultipartFile multipartFile = new CommonsMultipartFile(item);
- UploadFileDTO fileDTO = fileUtils.uploadFile(multipartFile);
- return fileDTO;
- }
- /**
- * 专利之星返回日期格式为字符串 yyyyMMdd,如 "20230713",本方法将其转成10位数字时间戳
- *
- * @param dateStr yyyyMMdd格式字符串日期
- * @return 返回10位数字时间戳
- */
- public int stringDateToTimeStamp(String dateStr) {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
- Date date;
- try {
- date = dateFormat.parse(dateStr);
- } catch (ParseException e) {
- //日期格式转换异常
- e.printStackTrace();
- return Integer.parseInt(dateStr);
- }
- long timeStamp = date.getTime() / 1000;
- 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;
- }
- /**
- * 记录没有数据的专利信息
- *
- * @param applicationNoOrPatentNo 公开号/申请号
- * @param taskId 任务id
- * @param cell 失败字段(1著录 2权要 3说明书文本 4说明书pdf 5摘要附图)
- */
- public void recordQuestionPatent(String applicationNoOrPatentNo, Integer taskId, int cell) {
- QuestionRecord questionRecord = new QuestionRecord()
- .setPatentNo(applicationNoOrPatentNo)
- .setCell(cell)
- .setTaskId(taskId)
- .setRemark("该申请号的该字段(2权要 3说明书文本 4说明书pdf)接口检索返回原始数据为空");
- List<QuestionRecord> questionRecords = questionRecordService.list(new LambdaQueryWrapper<QuestionRecord>().eq(QuestionRecord::getPatentNo, applicationNoOrPatentNo).eq(QuestionRecord::getCell, cell));
- if (questionRecords == null || questionRecords.size() == 0) {
- questionRecordService.save(questionRecord);
- }
- }
- public void setTaskStatus(Integer taskId, Integer taskStatus) {
- this.pTaskId = taskId;
- this.pTaskStatus = taskStatus;
- }
- public Integer getpTaskId() {
- return pTaskId;
- }
- public Integer getpTaskStatus() {
- return pTaskStatus;
- }
- }
|