Ver código fonte

专利号导入完成导入中国和外国专利号,完成超过一千个专利号的导入,完成暂停继续功能

chendayu 2 anos atrás
pai
commit
97115068f1

+ 2 - 2
PAS/src/main/java/cn/cslg/pas/common/model/dto/TaskAddNewDTO.java

@@ -66,11 +66,11 @@ public class TaskAddNewDTO {
      */
     private Integer productId;
     /**
-     * 任务类型2(3.欧专局导入 4.专利之星导入 5.专利号导入)
+     * 任务类型(1.Excel导入 2.导出 3.欧专局导入 4.专利之星导入 5.专利号导入 6.合并导出pdf首页
      */
     private Integer taskType2;
     /**
-     * 任务类型1 (0普通任务 1定时任务)
+     * 任务类型 (0普通任务 1定时任务)
      */
     private Integer taskType;
     /**

+ 1 - 1
PAS/src/main/java/cn/cslg/pas/common/model/vo/ProjectImportVO.java

@@ -14,7 +14,7 @@ public class ProjectImportVO extends BaseVO {
     /**
      * 多个专利号,以 ",|," 分隔
      */
-    @Schema(description = "专利号")
+    @Schema(description = "以,|,分隔的多个专利号")
     private String patentNo;
     /**
      * 专题库id

+ 6 - 1
PAS/src/main/java/cn/cslg/pas/controller/ProjectImportController.java

@@ -17,6 +17,7 @@ import cn.dev33.satoken.stp.StpUtil;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.scheduling.annotation.Async;
@@ -35,6 +36,7 @@ import java.util.List;
  * @author 王岩
  * @since 2021-12-24
  */
+@Slf4j
 @Tag(name = "专题库导入")
 @RestController
 @RequestMapping(Constants.API_VERSION_V2 + "/project/import")
@@ -118,8 +120,9 @@ public class ProjectImportController {
     }
 
     @PostMapping("/importByNos")
-    @Operation(summary = "根据专利号导入专利到专题库或报告或产品")
+    @Operation(summary = "专利号导入专利")
     public String importByNos(@RequestBody ProjectImportVO patentDTO) throws IOException {
+        log.info("开始处理【专利号导入专利】的请求,请求参数为:{}", patentDTO);
         TaskAddNewDTO taskAddNewDTO = new TaskAddNewDTO()
                 .setProjectId(patentDTO.getProjectId())
                 .setReportId(patentDTO.getReportId())
@@ -129,4 +132,6 @@ public class ProjectImportController {
         uploadTaskService.addPatentNoTask(taskAddNewDTO);
         return Response.success();
     }
+
+
 }

+ 2 - 2
PAS/src/main/java/cn/cslg/pas/controller/TaskController.java

@@ -41,9 +41,9 @@ public class TaskController {
     private final JobService jobService;
 
     @PostMapping("/addTask")
-    @Operation(summary = "新增网站导入任务")
+    @Operation(summary = "检索导入专利")
     public String add(@RequestBody TaskAddNewDTO taskAddNewDTO) throws IOException, SchedulerException {
-        log.info("开始处理【新增网站导入专利任务】的请求,请求参数为:{}", taskAddNewDTO);
+        log.info("开始处理【检索导入专利】的请求,请求参数为:{}", taskAddNewDTO);
 
         TaskCondition taskCondition = new TaskCondition();
         //新增欧专局网站导入任务

+ 1 - 1
PAS/src/main/java/cn/cslg/pas/domain/asso/TaskCondition.java

@@ -36,7 +36,7 @@ public class TaskCondition implements Serializable {
     @TableField(value = "task_type")
     private Integer taskType;
     /**
-     * 任务类型2(3.EPO欧专局导入 4.专利之星导入)
+     * 任务类型2(4.专利之星导入 5.专利号导入)
      */
     @TableField(value = "task_type2")
     private Integer taskType2;

+ 8 - 8
PAS/src/main/java/cn/cslg/pas/service/TaskService.java

@@ -61,8 +61,8 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
     private final OutInterfaceService outInterfaceService;
     private final PantentQueueService pantentQueueService;
     private final ExcutePatentDataExcel excutePatentDataExcel;
-    //private final ExcutePatentDataEpo excutePatentDataEpo;
     private final ExcutePatentDataStar excutePatentDataStar;
+    private final ExcutePatentDataPatentNo excutePatentDataPatentNo;
     private final TaskConditionService taskConditionService;
     private final ProjectService projectService;
     private final ReportService reportService;
@@ -189,7 +189,7 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
         //task.setStartTime(DateUtils.getDateTime());
         //任务状态(0.队列中 1.进行中 2.成功 3.失败)
         task.setStatus(0);
-        //判断当前导入专利任务是与专题库关联还是与报告关联
+        //与专题库/报告/产品关联(导入专题库/报告/产品)
         if (taskAddNewDTO.getProjectId() != null && taskAddNewDTO.getReportId() == null) {
             //专题库id
             task.setProjectId(taskAddNewDTO.getProjectId());
@@ -601,14 +601,14 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
         //将检索生产专利时的公共任务状态改为暂停(若还在检索生产,则会结束)
         if (task.getType() == 1) {  //Excel导入
             excutePatentDataExcel.setTaskStatus(taskId, 4);
-        } else if (task.getType() == 3) {  //欧专局
-            //excutePatentDataEpo.setTaskStatus(taskId, 4);
-        } else if (task.getType() == 4) {  //专利之星
+        } else if (task.getType() == 4) {  //专利之星检索导入
             excutePatentDataStar.setTaskStatus(taskId, 4);
+        } else if (task.getType() == 5) {  //专利号导入
+            excutePatentDataPatentNo.setTaskStatus(taskId, 4);
         }
 
         //若是网站导入任务,则还要将专利各部分装载线程队列中该任务元素清空
-        if (task.getType().equals(3) || task.getType().equals(4)) {
+        if (task.getType().equals(4) || task.getType().equals(5)) {
             //等上半秒(上述代码虽然使得生产暂停,但是生产暂停前正在存入生产队列的过程中,等2秒使得这些放入消费者队列后再清空消费者)
             pantentQueueService.setQueueRemoveTasks(taskId);
         }
@@ -661,10 +661,10 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
         //将生产者生产专利类中的公共任务状态从暂停改为0
         if (task.getType().equals(1) && excutePatentDataExcel.getpTaskId().equals(task.getId())) {
             excutePatentDataExcel.setTaskStatus(taskId, 0);
-//        } else if (task.getType().equals(3) && excutePatentDataEpo.getpTaskId().equals(task.getId())) {
-//            excutePatentDataEpo.setTaskStatus(taskId, 0);
         } else if (task.getType().equals(4) && excutePatentDataStar.getpTaskId().equals(task.getId())) {
             excutePatentDataStar.setTaskStatus(taskId, 0);
+        } else if (task.getType().equals(5) && excutePatentDataPatentNo.getpTaskId().equals(task.getId())) {
+            excutePatentDataPatentNo.setTaskStatus(taskId, 0);
         }
 
         pantentQueueService.awakeTasktch();

+ 0 - 592
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/ExcutePatentDataEpo.java

@@ -1,592 +0,0 @@
-//package cn.cslg.pas.service.upLoadPatent;
-//
-//import cn.cslg.pas.common.model.PatentCell;
-//import cn.cslg.pas.common.model.dto.*;
-//import cn.cslg.pas.common.model.vo.UploadParamsVO;
-//import cn.cslg.pas.common.utils.FileUtils;
-//import cn.cslg.pas.common.utils.StringUtils;
-//import cn.cslg.pas.common.utils.ThrowException;
-//import cn.cslg.pas.domain.*;
-//import cn.cslg.pas.domain.asso.TaskCondition;
-//import cn.cslg.pas.exception.XiaoShiException;
-//import cn.cslg.pas.service.*;
-//import cn.cslg.pas.service.asso.TaskConditionService;
-//import com.alibaba.fastjson.JSONObject;
-//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-//import com.spire.pdf.FileFormat;
-//import com.spire.pdf.PdfDocument;
-//import com.spire.pdf.PdfDocumentBase;
-//import lombok.RequiredArgsConstructor;
-//import lombok.extern.slf4j.Slf4j;
-//import org.apache.commons.fileupload.FileItem;
-//import org.apache.commons.fileupload.disk.DiskFileItemFactory;
-//import org.springframework.beans.BeanUtils;
-//import org.springframework.stereotype.Service;
-//import org.springframework.web.multipart.MultipartFile;
-//import org.springframework.web.multipart.commons.CommonsMultipartFile;
-//
-//import java.io.*;
-//import java.text.SimpleDateFormat;
-//import java.util.ArrayList;
-//import java.util.Arrays;
-//import java.util.Date;
-//import java.util.List;
-//
-///**
-// * Epo类型任务解析获取专利类
-// *
-// * @Author chenyu
-// * @Date 2023/6/16
-// */
-//@Slf4j
-//@RequiredArgsConstructor
-//@Service
-//public class ExcutePatentDataEpo implements IExcutePatentData {
-//    private final FileUtils fileUtils;
-//    private final PantentQueueService pantentQueueService;
-//    private final TaskConditionService taskConditionService;
-//    private final OutInterfaceService outInterfaceService;
-//    private final PatentInstructionService patentInstructionService;
-//    private final PatentAgencyService patentAgencyService;
-//    private final PatentAffairService patentAffairService;
-//    private final ProjectPatentLinkService projectPatentLinkService;
-//    private final PatentService patentService;
-//    private final PatentImageService patentImageService;
-//    private Integer pTaskId = 0;
-//    private Integer pTaskStatus = 0;
-//
-//    /**
-//     * 解析获取专利数据
-//     *
-//     * @param task 任务
-//     */
-//    @Override
-//    public void startExcute(Task task) throws IOException {
-//        //从任务关联网站导入任务表中取出当前任务
-//        List<TaskCondition> taskConditions = taskConditionService.list(new LambdaQueryWrapper<TaskCondition>().eq(TaskCondition::getTaskId, task.getId()));
-//        TaskCondition taskCondition = taskConditions.get(0);
-//
-//        //从任务数据中获取下载字段、检索式
-//        String cellsStr = taskCondition.getConfigCells();
-//        List<String> cells = Arrays.asList(cellsStr.split(","));
-//        String conditions = taskCondition.getConditions();
-//
-//        //定义每次检索的专利数量(每次检索50件)
-//        int size = 50;
-//
-//        //获得专利总数量
-//        Integer count = task.getTotal();
-//
-//        //1.根据专利总数量count遍历检索专利
-//        for (int i = 1; i <= count; i += size) {
-//            //根据检索式conditions、专利开始数i、专利最后数i + size - 1检索专利著录信息
-//            SerachBiblioData serachBiblioData = getSerachBiblioData(conditions, i, i + size - 1);
-//            //获取检索结果中的所有专利著录信息
-//            if (serachBiblioData == null || serachBiblioData.getTotals() == 0) {
-//                continue;
-//            }
-//            List<PatentZhuLu> patents = serachBiblioData.getPatents();
-//            //2.遍历专利
-//            for (PatentZhuLu patent : patents) {
-//                //判断若任务状态为已暂停,则结束生产
-//                if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
-//                    return;
-//                }
-//                PatentCell patentCell = new PatentCell();
-//                patentCell.setProjectId(task.getProjectId());
-//                PubNo pubNO = new PubNo();
-//                //装载专利著录
-//                if (cells.contains("1")) {
-//                    setPatentZhuLu(patentCell, patent, pubNO);
-//                }
-//                //装载权要
-//                if (cells.contains("2")) {
-//                    setPatentClaim(patentCell, pubNO);
-//                }
-//                //装载说明书文本
-//                if (cells.contains("3")) {
-//                    setPatentInstructionText(patentCell, pubNO);
-//                }
-//
-//                //以下代码是在准备一会要调用拿取各种附图的接口所需的参数(FullDocument->说明书pdf、Drawing->其他附图、FirstPageClipping->摘要附图)
-//                String fullDocumentLink = "", fullDocumentType = "", drawingLink = "", drawingType = "", firstPageClippingLink = "", firstPageClippingType = "";
-//                Integer fullDocumentPage = 0, drawingPage = 0, firstPageClippingPage = 0;
-//                //根据当前专利号调用接口获取一会调用拿取各种附图的接口的参数
-//                try {
-//                    ImageInfo imageInfo = getImage(pubNO);
-//                    for (Image image : imageInfo.getImages()) {
-//                        //如果附件类型是说明书
-//                        if (image.getImageType().equals("FullDocument")) {
-//                            fullDocumentLink = image.getUrlLink();
-//                            fullDocumentPage = image.getNumberOfPages();
-//                            for (String formatOption : image.getFormatOptions()) {
-//                                if (formatOption.contains("pdf")) {
-//                                    fullDocumentType = formatOption;
-//                                }
-//                            }
-//                        }
-//                        //如果附件类型是其他附件
-//                        if (image.getImageType().equals("Drawing")) {
-//                            drawingLink = image.getUrlLink();
-//                            drawingPage = image.getNumberOfPages();
-//                            for (String formatOption : image.getFormatOptions()) {
-//                                if (formatOption.contains("tiff")) {
-//                                    drawingType = formatOption;
-//                                }
-//                            }
-//                        }
-//                        //如果附件类型是摘要附图
-//                        if (image.getImageType().equals("FirstPageClipping")) {
-//                            firstPageClippingLink = image.getUrlLink();
-//                            firstPageClippingPage = image.getNumberOfPages();
-//                            for (String formatOption : image.getFormatOptions()) {
-//                                if (formatOption.contains("jpeg")) {
-//                                    firstPageClippingType = formatOption;
-//                                }
-//                            }
-//                        }
-//                    }
-//
-//                    //装载说明书pdf
-//                    if (cells.contains("4")) {
-//                        setFuJian(fullDocumentLink, fullDocumentPage, fullDocumentType, patentCell, ".pdf");
-//                    }
-//                    //装载摘要附图
-//                    if (cells.contains("6")) {
-//                        setFuJian(firstPageClippingLink, firstPageClippingPage, firstPageClippingType, patentCell, ".jpeg");
-//                    }
-//                    //装载其他附图
-//                    if (cells.contains("7")) {
-//                        setFuJian(drawingLink, drawingPage, drawingType, patentCell, ".tiff");
-//                    }
-//
-//                    //先将部分入库,再将其余扔给消费者来入库(消费者方更改任务状态发送进度通知)
-//                    if (patentCell.getPatentNo() != null) {
-//                        UploadParamsVO uploadParamsVO = new UploadParamsVO();
-//                        Patent patent2 = new Patent();
-//                        //设置专利号
-//                        patent2.setPatentNo(patentCell.getPatentNo());
-//                        //设置摘要
-//                        patent2.setAbstractStr(patentCell.getAbstrText());
-//                        //设置标题
-//                        patent2.setName(patentCell.getTitle());
-//                        //设置公开日
-//                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
-//                        if (patentCell.getPubilcDate() != null) {
-//                            Date date = simpleDateFormat.parse(patentCell.getPubilcDate());
-//                            Integer ts = (int) date.getTime();
-//                            patent2.setPublicDate(ts);
-//                        }
-//                        //设置申请号
-//                        patent2.setApplicationNo(patentCell.getApplicationNo());
-//                        //设置申请日
-//                        if (patentCell.getApplicationDate() != null) {
-//                            Date date = simpleDateFormat.parse(patentCell.getApplicationDate());
-//                            Integer ts = (int) date.getTime();
-//                            patent2.setApplicationDate(ts);
-//                        }
-//                        //设置摘要附图
-//                        patent2.setAbstractPath(patentCell.getPicUrl());
-//                        //设置pdf文档
-//                        if (patentCell.getPdf() != null) {
-//                            patentInstructionService.edit(patentCell.getPatentNo(), patentCell.getPdf());
-//                        }
-//                        //设置公开号
-//                        patent2.setPublicNo(patentCell.getPublicNo());
-//                        uploadParamsVO.setSimpleStatus(patentCell.getStatue());
-//                        uploadParamsVO.setPatent(patent2);
-//                        getOneOrInsertOne(uploadParamsVO);
-//                        //摘要附图上传专利附图表"os_patent_img"根据专利id删除该专利的摘要图片数据,以免上传重复
-//                        patentImageService.deleteByPatentIdAndStatus(uploadParamsVO.getPatent().getId(), 1);
-//                        PatentImage patentImage = new PatentImage();
-//                        patentImage.setStatus(1);
-//                        patentImage.setPatentId(uploadParamsVO.getPatent().getId());
-//                        patentImage.setUrl(patentCell.getPicUrl());
-//                        patentImage.setFileName(patentCell.getFileName());
-//                        //摘要附图数据入库
-//                        patentImage.insert();
-//
-//                        if (patentCell.getAgency() != null && !patentCell.getAgency().equals("")) {
-//                            uploadParamsVO.getPatent().setAgencyId(patentAgencyService.getAgencyStringIdByName(patentCell.getAgency()));
-//                        }
-//                        uploadParamsVO.setPatentRight(new PatentRight());
-//                        uploadParamsVO.getPatentRight().setContent(StringUtils.join(patentCell.getRights(), ""));
-//                        uploadParamsVO.setSelfContent(patentCell.getMainRignt());
-//                        uploadParamsVO.setPatentInstructionText(new PatentInstructionText());
-//                        uploadParamsVO.getPatentInstructionText().setManual(patentCell.getPatentInstructionText());
-//                        //发明人
-//                        List<String> inventors = patentCell.getInventors();
-//                        if (inventors != null && inventors.size() > 0) {
-//                            ArrayList<PatentInventor> patentInventors = new ArrayList<>();
-//                            for (String inventor : inventors) {
-//                                PatentInventor patentInventor = new PatentInventor();
-//                                patentInventor.setName(inventor);
-//                                patentInventors.add(patentInventor);
-//                            }
-//                            uploadParamsVO.setPatentInventorList(patentInventors);
-//                        }
-//                        uploadParamsVO.setPatentApplicantCurrentName(patentCell.getApplicationCurrents());
-//                        uploadParamsVO.setPatentApplicantOriginalName(patentCell.getApplicationPersons());
-//                        uploadParamsVO.setPatentApplicantOriginalAddress(patentCell.getApplicationAddress());
-//                        uploadParamsVO.setIpcList(patentCell.getIpc());
-//                        uploadParamsVO.setMainIpc(patentCell.getMainIpc());
-//                        //代理人
-//                        List<String> agencyPersons = patentCell.getAgencyPersons();
-//                        if (agencyPersons != null && agencyPersons.size() > 0) {
-//                            ArrayList<PatentAgent> patentAgents = new ArrayList<>();
-//                            for (String agencyPerson : agencyPersons) {
-//                                PatentAgent patentAgent = new PatentAgent();
-//                                patentAgent.setName(agencyPerson);
-//                                patentAgents.add(patentAgent);
-//                            }
-//                            uploadParamsVO.setPatentAgentList(patentAgents);
-//                        }
-//                        //事务信息 OS_PATENT_AFFAIR
-//                        if (patentCell.getPatentAffairs() != null && patentCell.getPatentAffairs().size() > 0) {
-//                            patentAffairService.updatePatientAffairs(patentCell.getPatentAffairs(), uploadParamsVO.getPatent().getId());
-//                        }
-//                        //当专题库id不为null时添加专利到专题库
-//                        if (patentCell.getProjectId() != null) {
-//                            projectPatentLinkService.updateProjectPatent(patentCell.getProjectId(), uploadParamsVO.getPatent().getId());
-//                        }
-//                        pantentQueueService.patentToQueue(task, uploadParamsVO);
-//                    }
-//
-//                } catch (XiaoShiException e) {
-//                    //虽然拿不到所有附图,但已经拿到了专利著录,能拿到啥是啥
-//                    log.info(e.getMessage());
-//                } catch (Exception e) {
-//
-//                }
-//
-//            }
-//        }
-//
-//    }
-//
-//    //调用外部接口获取一批专利著录信息
-//    public SerachBiblioData getSerachBiblioData(String conditions, Integer start, Integer size) throws IOException {
-//        GetSearchBiblioParamsDTO getSearchBiblioParamsDTO = new GetSearchBiblioParamsDTO()
-//                .setQuery(conditions)
-//                .setStart(start)
-//                .setEnd(size);
-//        String res = outInterfaceService.getSearchBiblio(getSearchBiblioParamsDTO);
-//        if (res == null || res.equals("")) {
-//            return null;
-//        }
-//        JSONObject jsonObject = JSONObject.parseObject(res);
-//        if (!jsonObject.get("status").toString().equals("200")) {
-//            //若发生类似400、500等异常(杰哥处理)
-//            return null;
-//        }
-//        //返回检索结果data
-//        return JSONObject.parseObject(jsonObject.get("data").toString(), SerachBiblioData.class);
-//    }
-//
-//    /**
-//     * 装载著录方法
-//     *
-//     * @param patentCell 实体类对象
-//     * @param patent     专利对象
-//     * @param pubNo      公开号对象
-//     */
-//    private void setPatentZhuLu(PatentCell patentCell, PatentZhuLu patent, PubNo pubNo) {
-//        //装载申请号
-//        for (AppNo appNo : patent.getAppNos()) {
-//            if (appNo.getType().equals("docdb")) {
-//                patentCell.setApplicationNo(appNo.getCountry() + appNo.getNumber() + appNo.getKind());
-//            }
-//        }
-//        //装载申请日
-//        patentCell.setApplicationDate(patent.getAppDate());
-//        //装载国家/省市
-//        patentCell.setCountry(patent.getAppCountry());
-//        //装载公开号
-//        for (PubNo n : patent.getPubNos()) {
-//            if (n.getType().equals("docdb")) {
-//                BeanUtils.copyProperties(n, pubNo);
-//                patentCell.setPublicNo(n.getCountry() + n.getNumber() + n.getKind());
-//            }
-//        }
-//        //装载专利号
-//        patentCell.setPatentNo(patentCell.getPublicNo());
-//        //装载公开日
-//        patentCell.setPubilcDate(patent.getPubDate());
-//        //装载授权公告号(未找到)
-//        //装载授权公告日(未找到)
-//        //装载主分类号
-//        List<String> ipCs = patent.getIpCs();
-//        List<String> cpCs = patent.getCpCs();
-//        ipCs.addAll(cpCs);
-//        if (ipCs != null && ipCs.size() > 0) {
-//            patentCell.setMainIpc(ipCs.get(0));
-//        }
-//        //装载分类号
-//        if (ipCs != null && ipCs.size() > 0) {
-//            patentCell.setIpc(ipCs);
-//        }
-//        //装载申请人
-//        ArrayList<String> applicationPersons = new ArrayList<>();
-//        for (Application application : patent.getApplications()) {
-//            if (application.getOriginalName().contains("(标:)")) {
-//                application.setOriginalName(application.getOriginalName().substring(0, application.getOriginalName().indexOf("(标:)")));
-//            }
-//            applicationPersons.add(application.getOriginalName());
-//        }
-//        patentCell.setApplicationPersons(applicationPersons);
-//
-//        //装载申请人地址(未找到)
-//        //装载发明人
-//        ArrayList<String> inventors = new ArrayList<>();
-//        for (Inventor inventor : patent.getInventors()) {
-//            inventors.add(inventor.getOriginalName());
-//        }
-//        patentCell.setInventors(inventors);
-//        //装载当前权利人(未找到)
-//        //装载代理人(未找到)
-//        //装载代理机构(未找到)
-//        //装载范畴分类(未找到)
-//        //装载当前状态(未找到)
-//        //装载同族号
-//        patentCell.setFamilyId(patent.getFamilyId());
-//        //装载著录标题
-//        String olTitle = patent.getOlTitle();
-//        String enTitle = patent.getEnTitle();
-//        if (olTitle == null) {
-//            patentCell.setTitle(enTitle);
-//        } else {
-//            patentCell.setTitle(olTitle);
-//        }
-//        //装载摘要
-//        String olAbstract = patent.getOlAbstract();
-//        String enAbstract = patent.getEnAbstract();
-//        if (olAbstract == null) {
-//            patentCell.setAbstrText(enAbstract);
-//        } else {
-//            patentCell.setAbstrText(olAbstract);
-//        }
-//        //装载优先权号、优先权国家、优先权日
-//        ArrayList<Priority> priorities = new ArrayList<>();
-//        List<Priorityy> priorties = patent.getPriorties();
-//        for (Priorityy priorty : priorties) {
-//            for (PriorityNumber number : priorty.getNumbers()) {
-//                if (number.getType().equals("epodoc")) {
-//                    Priority priority = new Priority()
-//                            .setPriorityNo(number.getNumber().substring(2))
-//                            .setPriorityCountry(number.getNumber().substring(0, 2))
-//                            .setPriorityDate(priorty.getDate());
-//                    priorities.add(priority);
-//                }
-//            }
-//        }
-//        patentCell.setPriorities(priorities);
-//    }
-//
-//    /**
-//     * 装载权要方法
-//     *
-//     * @param patentCell 实体类对象
-//     * @param pubNo      公开号对象
-//     */
-//    private void setPatentClaim(PatentCell patentCell, PubNo pubNo) throws IOException {
-//        GetClaimsInfoParamsDTO getClaimsInfoParamsDTO = new GetClaimsInfoParamsDTO()
-//                .setCc(pubNo.getCountry())
-//                .setNumber(pubNo.getNumber())
-//                .setKind(pubNo.getKind());
-//        String res = outInterfaceService.getClaimsInfo(getClaimsInfoParamsDTO);
-//        JSONObject jsonObject = JSONObject.parseObject(res);
-//        if (!jsonObject.get("status").toString().equals("200")) {
-//            //若发生类似400、500等异常(杰哥处理)
-//            //ThrowException.throwXiaoShiException("权要接口无法检索该国家专利");
-//            log.info("权要接口无法检索该国家专利");
-//            return;
-//        }
-//        //拿到检索结果(未格式化的含有页面等标签的权要)并格式化权要
-//        //String unformatRight = JSONObject.parseObject(jsonObject.get("data").toString(), String.class);
-//        ArrayList<String> unformatRights = JSONObject.parseObject(jsonObject.get("data").toString(), ArrayList.class);
-//        //String[] rightArr = unformatRight.split("\n");
-//        //ArrayList<String> rights = new ArrayList<>(Arrays.asList(rightArr));
-//        patentCell.setRights(unformatRights);
-//    }
-//
-//    /**
-//     * 装载说明书方法
-//     *
-//     * @param patentCell 实体类对象
-//     * @param pubNo      公开号对象
-//     */
-//    private void setPatentInstructionText(PatentCell patentCell, PubNo pubNo) throws IOException {
-//        GetDescriptionInfoParamsDTO getDescriptionInfoParamsDTO = new GetDescriptionInfoParamsDTO()
-//                .setCc(pubNo.getCountry())
-//                .setNumber(pubNo.getNumber())
-//                .setKind(pubNo.getKind());
-//        String res = outInterfaceService.getDescriptionInfo(getDescriptionInfoParamsDTO);
-//        JSONObject jsonObject = JSONObject.parseObject(res);
-//        if (!jsonObject.get("status").toString().equals("200")) {
-//            //若发生类似400、500等异常(杰哥处理)
-//            //ThrowException.throwXiaoShiException("说明书接口无法检索该国家专利");
-//            log.info("说明书接口无法检索该国家专利");
-//            return;
-//        }
-//        //拿到检索结果(未格式化的含有页面等标签的说明书)
-//        //String unformatInstructionText = JSONObject.parseObject(jsonObject.get("data").toString(), String.class);
-//        List<String> unformatInstructionText = JSONObject.parseObject(jsonObject.get("data").toString(), List.class);
-//        StringBuilder builder = new StringBuilder();
-//        for (String n : unformatInstructionText) {
-//            builder.append(n);
-//        }
-////        String regex = "<p>(.+?)</p>";
-////        Matcher matcher = Pattern.compile(regex).matcher(unformatInstructionText);
-////        if (matcher.find()) {
-////            patentCell.setPatentInstructionText(matcher.group());
-////        }
-//        patentCell.setPatentInstructionText(builder + "");
-//    }
-//
-//    /**
-//     * 获取Image信息方法(从信息中获取三种附图的检索参数)
-//     *
-//     * @param pubNo 公开号对象
-//     */
-//    private ImageInfo getImage(PubNo pubNo) throws IOException {
-//        String res = outInterfaceService.getImagesInfo(pubNo);
-//        JSONObject jsonObject = JSONObject.parseObject(res);
-//        if (!jsonObject.get("status").toString().equals("200")) {
-//            //若发生类似400、500等异常(杰哥处理)
-//            ThrowException.throwXiaoShiException("Image信息接口无法检索该国家专利");
-//        }
-//        //拿到检索结果(未格式化的含有页面等标签的说明书)
-//        String unFormatData = jsonObject.get("data").toString();
-//        String data = unFormatData.substring(unFormatData.indexOf("[") + 1, unFormatData.lastIndexOf("]"));
-//        ImageInfo imageInfo = JSONObject.parseObject(data, ImageInfo.class);
-//        return imageInfo;
-//    }
-//
-//    /**
-//     * 装载说明书附件pdf方法
-//     *
-//     * @param link       附件链接
-//     * @param page       附件页数
-//     * @param type       附件类型
-//     * @param patentCell 实体类对象
-//     */
-//    private void setFuJian(String link, Integer page, String type, PatentCell patentCell, String FuJianSuffix) throws Exception {
-//        //合并说明书pdf文档时所需的读取流数组
-//        InputStream[] streams = new InputStream[page];
-//        //其他附图url数组
-//        ArrayList<String> otherUrls = new ArrayList<>();
-//        //遍历附件页数
-//        for (int i = 1; i <= page; i++) {
-//            GetFuTuParamsDTO getFuTuParamsDTO = new GetFuTuParamsDTO()
-//                    .setLink(link)
-//                    .setPage(i)
-//                    .setType(type);
-//            byte[] buffer = outInterfaceService.getPatentFile(getFuTuParamsDTO);
-//            InputStream inputStream = new ByteArrayInputStream(buffer);
-//            streams[i - 1] = inputStream;
-//            //如果不是说明书pdf
-//            if (!FuJianSuffix.equals(".pdf")) {
-//                File file = File.createTempFile("new_url", FuJianSuffix);
-//                FileOutputStream out = new FileOutputStream(file);
-//                out.write(buffer);
-//                out.close();
-//                streams[i - 1] = new FileInputStream(file);
-//                DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
-//                FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
-//                int bytesRead = 0;
-//                buffer = new byte[8192];
-//                try {
-//                    FileInputStream fis = new FileInputStream(file);
-//                    OutputStream os = item.getOutputStream();
-//                    int len = 8192;
-//                    while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
-//                        os.write(buffer, 0, bytesRead);
-//                    }
-//                    os.close();
-//                    fis.close();
-//                } catch (IOException e) {
-//                    e.printStackTrace();
-//                }
-//                MultipartFile multipartFile = new CommonsMultipartFile(item);
-//                UploadFileDTO fileDTO = fileUtils.uploadFile(multipartFile);
-//                //如果是摘要附图
-//                if (FuJianSuffix.equals(".jpeg")) {
-//                    patentCell.setPicUrl(fileDTO.getPath());
-//                    patentCell.setFileName(fileDTO.getFileName());
-//                }
-//                //如果是其他附图
-//                if (FuJianSuffix.equals(".tiff")) {
-//                    otherUrls.add(fileDTO.getPath());
-//                }
-//            }
-//        }
-//
-//        //如果是说明书pdf
-//        if (FuJianSuffix.equals(".pdf")) {
-//            //合并说明书多个pdf文件
-//            PdfDocumentBase doc = PdfDocument.mergeFiles(streams);
-//            //保存结果文件
-//            doc.save("merge.pdf", FileFormat.PDF);
-//            doc.close();
-//
-//            //手动将合并后的pdf文件转成MultipartFile,上传文件并获取path装载到patentCell
-//            File file = new File("merge.pdf");
-//            DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(16, null);
-//            FileItem item = diskFileItemFactory.createItem(file.getName(), "text/plain", true, file.getName());
-//            int bytesRead = 0;
-//            byte[] buffer = new byte[8192];
-//            try {
-//                FileInputStream fis = new FileInputStream(file);
-//                OutputStream os = item.getOutputStream();
-//                int len = 8192;
-//                while ((bytesRead = fis.read(buffer, 0, len)) != -1) {
-//                    os.write(buffer, 0, bytesRead);
-//                }
-//                os.close();
-//                fis.close();
-//            } catch (IOException e) {
-//                e.printStackTrace();
-//            }
-//            MultipartFile multipartFile = new CommonsMultipartFile(item);
-//            UploadFileDTO fileDTO = fileUtils.uploadFile(multipartFile);
-//            patentCell.setPdf(fileDTO);
-//        } else if (FuJianSuffix.equals(".tiff")) {
-//            patentCell.setOtherUrls(otherUrls);
-//        }
-//
-//    }
-//
-//    /**
-//     * @param uploadParamsVO 全局类
-//     * @date 2022-7-11
-//     * @name 工具方法
-//     * @description 查询数据是否存在 如果存在 返回该条数据 如果不存在 新增一条数据
-//     */
-//    public void getOneOrInsertOne(UploadParamsVO uploadParamsVO) {
-//        if (uploadParamsVO.getPatent() != null) {
-//            uploadParamsVO.getPatent().setPatentNo(uploadParamsVO.getPatent().getPatentNo().trim());
-//            //用专利号查询该条数据是否存在
-//            Patent patent = patentService.getByPatentNo(uploadParamsVO.getPatent().getPatentNo());
-//            //如果不存在就新增一条
-//            if (patent == null) {
-//                uploadParamsVO.getPatent().insert();
-//            } else {
-//                uploadParamsVO.getPatent().setId(patent.getId());
-//            }
-//        }
-//    }
-//
-//    public void setTaskStatus(Integer taskId, Integer taskStatus) {
-//        this.pTaskId = taskId;
-//        this.pTaskStatus = taskStatus;
-//    }
-//
-//    public Integer getpTaskId() {
-//        return pTaskId;
-//    }
-//
-//    public Integer getpTaskStatus() {
-//        return pTaskStatus;
-//    }
-//
-//}

+ 178 - 0
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/ExcutePatentDataPatentNo.java

@@ -0,0 +1,178 @@
+package cn.cslg.pas.service.upLoadPatent;
+
+import cn.cslg.pas.common.model.outApi.PatentStarListDto;
+import cn.cslg.pas.common.model.vo.UploadParamsVO;
+import cn.cslg.pas.common.model.vo.outApi.StarPatentVO;
+import cn.cslg.pas.common.utils.ThrowException;
+import cn.cslg.pas.domain.PQueueData;
+import cn.cslg.pas.domain.Patent;
+import cn.cslg.pas.domain.Task;
+import cn.cslg.pas.service.TaskService;
+import cn.cslg.pas.service.UploadPatentBatchService;
+import cn.cslg.pas.service.outApi.PatentStarApiService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 专利号导入任务开始执行导入专利
+ *
+ * @author chenyu
+ * @date 2023/9/12
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class ExcutePatentDataPatentNo implements IExcutePatentData {
+    private final PatentStarApiService patentStarApiService;
+    private final PantentQueueService pantentQueueService;
+    private final UploadPatentBatchService uploadPatentBatchService;
+    private final TaskService taskService;
+    private Integer pTaskId = 0;
+    private Integer pTaskStatus = 0;
+
+    @Override
+    public void startExcute(Task task) throws IOException {
+        try {
+            String orderBy = task.getOrderBy();
+            String orderByType = task.getOrderByType();
+            List<String> isAddPatentNos = task.getIsAddPatentNos();
+
+            List<String> cNPatentNos = isAddPatentNos.stream().filter(patentNo -> patentNo.contains("CN")).collect(Collectors.toList());  //所有中国专利号
+            List<String> wDPatentNos = isAddPatentNos.stream().filter(patentNo -> !patentNo.contains("CN")).collect(Collectors.toList());  //所有外国专利号
+
+            PatentStarListDto patentStarListDto = new PatentStarListDto()
+                    .setOrderBy(orderBy)
+                    .setOrderByType(orderByType)
+                    .setRowCount(50);
+
+            if (cNPatentNos.size() > 0) {
+                for (int i = 0; i < cNPatentNos.size(); i += 1000) {
+                    List<String> cNPatentNos0;
+                    try {
+                        cNPatentNos0 = cNPatentNos.subList(i, i + 1000);
+                    } catch (IndexOutOfBoundsException e) {
+                        int leftNum = cNPatentNos.size() % 1000;
+                        cNPatentNos0 = cNPatentNos.subList(i, i + leftNum);
+                    }
+                    String join = StringUtils.join(cNPatentNos0, " OR ");
+                    String condition = "AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")";
+                    int pageNum = 1;
+                    for (int j = 0; j < cNPatentNos0.size(); j += 50) {
+                        patentStarListDto
+                                .setCurrentQuery(condition)
+                                .setPageNum(pageNum++)
+                                .setDBType("CN");
+                        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");
+                        boolean isPause = extracted(task, starPatents);
+                        if (isPause) {
+                            return;
+                        }
+                    }
+                }
+            }
+
+            if (wDPatentNos.size() > 0) {
+                for (int i = 0; i < wDPatentNos.size(); i += 1000) {
+                    List<String> wDPatentNos0;
+                    try {
+                        wDPatentNos0 = wDPatentNos.subList(i, i + 1000);
+                    } catch (IndexOutOfBoundsException e) {
+                        int leftNum = wDPatentNos.size() % 1000;
+                        wDPatentNos0 = wDPatentNos.subList(i, i + leftNum);
+                    }
+                    String join = StringUtils.join(wDPatentNos0, " OR ");
+                    String condition = "PN=(" + join + ")";
+                    int pageNum = 1;
+                    for (int j = 0; j < wDPatentNos0.size(); j += 50) {
+                        patentStarListDto
+                                .setCurrentQuery(condition)
+                                .setPageNum(pageNum++)
+                                .setDBType("WD");
+                        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");
+                        boolean isPause = extracted(task, starPatents);
+                        if (isPause) {
+                            return;
+                        }
+                    }
+                }
+            }
+
+        } catch (IOException e) {
+            e.printStackTrace();
+            //生产消费到一半时,发生错误异常,将任务状态置为完成
+            task = taskService.getById(task.getId());
+            if (task.getStatus().equals(1)) {
+                task.setStatus(2);
+                taskService.updateById(task);
+            }
+        }
+
+
+    }
+
+    private boolean extracted(Task task, List<StarPatentVO> starPatents) {
+        //遍历所有专利
+        for (StarPatentVO starPatent : starPatents) {
+            //判断若任务状态为已暂停,则结束生产
+            if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
+                return true;
+            }
+
+            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);
+            //装载专利著录
+            pantentQueueService.zhuluToPQueue(pQueueData);
+            //装载权要
+            pantentQueueService.rightToPQueue(pQueueData);
+            //装载说明书文本
+            pantentQueueService.instructionTextToPQueue(pQueueData);
+            //装载说明书pdf
+            pantentQueueService.instructionPDFToPQueue(pQueueData);
+            //装载摘要附图
+            pantentQueueService.imageToPQueue(pQueueData);
+
+        }
+        return false;
+    }
+
+    public void setTaskStatus(Integer taskId, Integer taskStatus) {
+        this.pTaskId = taskId;
+        this.pTaskStatus = taskStatus;
+    }
+
+    public Integer getpTaskId() {
+        return pTaskId;
+    }
+
+    public Integer getpTaskStatus() {
+        return pTaskStatus;
+    }
+
+
+}

+ 16 - 27
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/ExcutePatentDataStar.java

@@ -34,12 +34,13 @@ 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
+ * @author chenyu
+ * @date 2023/6/25
  */
 @Slf4j
 @RequiredArgsConstructor
@@ -50,25 +51,18 @@ public class ExcutePatentDataStar implements IExcutePatentData {
     private final PantentQueueService pantentQueueService;
     private final UploadPatentBatchService uploadPatentBatchService;
     private final TaskService taskService;
-    private final TaskConditionService taskConditionService;
     private final QuestionRecordService questionRecordService;
-    private final PatentService patentService;
-    private final UploadPatentToDBService uploadPatentToDBService;
-    private final OutInterfaceService outInterfaceService;
     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) {
+        if (task.getEndNumber() <= patentNum) {
+            excuteLessThan10000(task);
+        } else {
             try {
                 Integer total = task.getTotal();  //任务专利总数量
                 Integer successNum = task.getSuccessNum();
@@ -195,12 +189,8 @@ public class ExcutePatentDataStar implements IExcutePatentData {
                     taskService.updateById(task);
                 }
             }
-
-        } else {
-            excuteLessThan10000(task);
         }
 
-
     }
 
     private void excuteLessThan10000(Task task) {
@@ -313,15 +303,10 @@ public class ExcutePatentDataStar implements IExcutePatentData {
                 }
             }
 
-            //下载 isAdd中的专利/多个专利号导入的专利
+            //下载 isAdd中的专利
             if (isAddPatentNos != null && isAddPatentNos.size() > 0) {
                 String patentNoCondition = StringUtils.join(isAddPatentNos, " OR ");
-
-                if (task.getIsAddType() != null && task.getIsAddType().equals(2)) {  //若是多个专利号导入的下载
-                    conditions = "AN=(" + patentNoCondition + ") OR PN=(" + patentNoCondition + ") OR GN=(" + patentNoCondition + ")";
-                } else {  //若是检索页面手动勾选的多个专利的下载
-                    conditions = "AN=(" + patentNoCondition + ")";
-                }
+                conditions = "AN=(" + patentNoCondition + ")";
                 downLoadIsAddPatentNos(isAddPatentNos, task, orderBy, orderByType, dbType, cells, conditions);
             }
 
@@ -920,9 +905,7 @@ public class ExcutePatentDataStar implements IExcutePatentData {
     }
 
     /**
-     * 下载指定多个专利号专利
-     *
-     * @param isAddPatentNos 起止条数以外,用户手动勾选的多个专利号
+     * 检索页面手动勾选的专利下载
      */
     public void downLoadIsAddPatentNos(List<String> isAddPatentNos, Task task, String orderBy, String orderByType, String dbType, List<String> cells, String conditions) throws IOException {
         int pageNum = 1;
@@ -982,6 +965,12 @@ public class ExcutePatentDataStar implements IExcutePatentData {
 
                 } catch (Exception e) {
                     e.printStackTrace();
+                    //生产消费到一半时,发生错误异常,将任务状态置为完成
+                    task = taskService.getById(task.getId());
+                    if (task.getStatus().equals(1)) {
+                        task.setStatus(2);
+                        taskService.updateById(task);
+                    }
                 }
 
             }

+ 11 - 17
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/PantentQueueService.java

@@ -45,13 +45,12 @@ public class PantentQueueService {
     private final TaskService taskService;
     private final TaskConditionService taskConditionService;
     private final ExcutePatentDataExcel excutePatentDataExcel;
-    //private final ExcutePatentDataEpo excutePatentDataEpo;
     private final ExcutePatentDataStar excutePatentDataStar;
+    private final ExcutePatentDataPatentNo excutePatentDataPatentNo;
     private final PatentInstructionService patentInstructionService;
     private final OutInterfaceService outInterfaceService;
     private final QuestionRecordService questionRecordService;
     private final AssoProductPatentService assoProductPatentService;
-    private final QuestionRecordMapper questionRecordMapper;
     private final List<Integer> taskQueueList = new ArrayList<>();
     private final List<PQueueData> setPatentImageQueueList = new ArrayList<>();
     private final List<PQueueData> setPatentZhuluQueueList = new ArrayList<>();
@@ -104,13 +103,13 @@ public class PantentQueueService {
                 if (taskQueueList.size() > 0) {
                     //从任务队列中取出第一个task任务,同时将其从任务队列中剔除
                     task = taskService.getById(taskQueueList.remove(0));
-                    //判断任务状态,若不存在或已完成或已暂停或已取消,则跳过继续取下一个任务
+                    //判断任务状态,若不存在/已完成/已暂停/已取消,则跳过继续取下一个任务
                     if (task == null || task.getStatus().equals(2) || task.getStatus().equals(4) || task.getStatus().equals(5)) {
                         continue;
                     }
 
                     //若是网站导入任务,则将网站导入相关信息存入task对象中(方便生产与消费时使用)
-                    if (task.getType().equals(3) || task.getType().equals(4) || task.getType().equals(5)) {
+                    if (task.getType().equals(4) || task.getType().equals(5)) {
                         TaskCondition taskCondition = taskConditionService.getById(task.getTaskConditionId());
                         List<String> configCells = Arrays.asList(taskCondition.getConfigCells().split(","));
                         task.setConfigCellsNum(configCells.size());
@@ -127,8 +126,6 @@ public class PantentQueueService {
                             task.setIsDeletePatentNos(Arrays.asList(taskCondition.getIsDeletePatentNos().split(",")));
                         }
                         task.setConditions(taskCondition.getConditions());
-                        task.setContinueLastInformation(taskCondition.getContinueLastInformation());
-                        task.setIsAddType(taskCondition.getIsAddType());
                     }
 
                     //TODO 调用工厂方法,工厂方法会根据任务类型创建并返回对应的生产专利方法的对象
@@ -559,7 +556,7 @@ public class PantentQueueService {
             String currentPatent = task.getId() + "|" + queueData.getUploadParamsVO().getPatent().getId();
             Integer num = patentIdMap.get(currentPatent);
             int needNum = 3;  //临界默认设为4(即Excel导入任务默认使用5个消费者)
-            if (task.getType().equals(3) || task.getType().equals(4) || task.getType().equals(5)) {  //若是网站导入任务,则临界默认设为下载字段类型数量 - 1
+            if (task.getType().equals(4) || task.getType().equals(5)) {  //若是网站导入任务,则临界默认设为下载字段类型数量 - 1
                 needNum = task.getConfigCellsNum() - 1;
             }
             if (num == null && needNum > 0) {
@@ -579,8 +576,7 @@ public class PantentQueueService {
                 if (queueData.getTask().getProjectId() != null && !queueData.getTask().getProjectId().equals(0)) {
                     //与专题库关联入库
                     uploadPatentToDBService.uploadAssoThemaPat(queueData.getUploadParamsVO(), queueData.getTask().getProjectId());
-                }
-                else if (queueData.getTask().getReportId() != null && !queueData.getTask().getReportId().equals(0)) {
+                } else if (queueData.getTask().getReportId() != null && !queueData.getTask().getReportId().equals(0)) {
                     //与报告关联入库(调用报告系统接口)
                     ImportTaskPatent importTaskPatent = new ImportTaskPatent();
                     importTaskPatent.setImportTaskId(queueData.getTask().getId());
@@ -592,7 +588,7 @@ public class PantentQueueService {
                     } catch (IOException e) {
                         e.printStackTrace();
                     }
-                } else if (queueData.getTask().getProductId() != null) {
+                } else if (queueData.getTask().getProductId() != null && !queueData.getTask().getProductId().equals(0)) {
                     //与产品关联入库(调用报告系统接口)
                     List<AssoProductPatent> assoProductPatents = assoProductPatentService.list(new LambdaQueryWrapper<AssoProductPatent>().eq(AssoProductPatent::getProductId, queueData.getTask().getProductId()).eq(AssoProductPatent::getPatentNo, queueData.getUploadParamsVO().getPatent().getPatentNo()));
                     if (assoProductPatents == null || assoProductPatents.size() == 0) {
@@ -603,7 +599,6 @@ public class PantentQueueService {
                     }
                 }
 
-
                 //任务表更新 完成条数+1
                 task.setSuccessNum(task.getSuccessNum() + 1);
                 //根据专利号查询专利是否有导入失败记录
@@ -627,6 +622,8 @@ public class PantentQueueService {
                     ArrayList<String> updateIsAddPatentNos = new ArrayList<>(task.getIsAddPatentNos());
                     updateIsAddPatentNos.removeIf(item -> item.equals(queueData.getUploadParamsVO().getPatent().getPatentNo()));
                     updateIsAddPatentNos.removeIf(item -> item.equals(queueData.getUploadParamsVO().getPatent().getApplicationNo()));
+                    updateIsAddPatentNos.removeIf(item -> item.equals(queueData.getUploadParamsVO().getPatent().getPublicNo()));
+                    updateIsAddPatentNos.removeIf(item -> item.equals(queueData.getUploadParamsVO().getPatent().getPublicAccreditNo()));
 
                     TaskCondition taskCondition = new TaskCondition()
                             .setId(task.getTaskConditionId())
@@ -851,16 +848,13 @@ public class PantentQueueService {
         switch (task.getType()) {
             case 1:  //Excel导入专利
                 return excutePatentDataExcel;
-//            case 3:  //欧专局网站导入
-//                return excutePatentDataEpo;
-            case 4:  //专利之星网站导入
-                return excutePatentDataStar;
-            case 5:  //专利号导入(也是专利之星方式)
+            case 4:  //检索导入
                 return excutePatentDataStar;
+            case 5:  //专利号导入
+                return excutePatentDataPatentNo;
             default:
                 return null;
         }
-
     }
 
     /**

+ 182 - 99
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/UploadTaskService.java

@@ -1,36 +1,36 @@
 package cn.cslg.pas.service.upLoadPatent;
 
-import cn.cslg.pas.common.model.PersonnelVO;
 import cn.cslg.pas.common.model.dto.TaskAddNewDTO;
-import cn.cslg.pas.common.model.dto.UploadFileDTO;
 import cn.cslg.pas.common.model.outApi.PatentStarListDto;
 import cn.cslg.pas.common.model.vo.ProjectImportPatentVO;
 import cn.cslg.pas.common.model.vo.SystemFile;
 import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
+import cn.cslg.pas.domain.Product;
 import cn.cslg.pas.domain.Project;
-import cn.cslg.pas.domain.SerachBiblioData;
-import cn.cslg.pas.domain.WebLoginConfig;
 import cn.cslg.pas.domain.asso.TaskCondition;
 import cn.cslg.pas.service.*;
 import cn.cslg.pas.service.asso.TaskConditionService;
+import cn.cslg.pas.service.impl.ProductServiceImpl;
 import cn.cslg.pas.service.outApi.PatentStarApiService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.compress.utils.IOUtils;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 导入专利任务的业务层
@@ -52,6 +52,7 @@ public class UploadTaskService {
     private final WebLoginConfigService webLoginConfigService;
     private final PatentStarApiService patentStarApiService;
     private final ProjectService projectService;
+    private final ProductServiceImpl productService;
     private final PatentService patentService;
     private final FileManagerService fileManagerService;
 
@@ -104,14 +105,14 @@ public class UploadTaskService {
     }
 
     /**
-     * 新增专利之星导入任务
+     * 新增检索导入专利任务
      *
      * @param taskAddNewDTO 前台参数(检索信息conditions、专题库id、下载字段configCells等)
      */
     public TaskCondition addPatentStarTask(TaskAddNewDTO taskAddNewDTO) throws IOException {
-        log.info("开始处理【新增专利之星下载接口导入专利】的业务,参数为:{}", taskAddNewDTO);
+        log.info("开始处理【检索导入专利】的业务,参数为:{}", taskAddNewDTO);
 
-        //检查任务合法性1(检查是否有下载字段)
+        //检查任务合法性1(检查是否有选择下载字段)
         List<String> cells = taskAddNewDTO.getConfigCells();
         if (cells == null || cells.size() == 0) {
             ThrowException.throwXiaoShiException("请选择至少一个需要下载的字段");
@@ -125,7 +126,17 @@ public class UploadTaskService {
             }
         }
 
-        //检查任务合法性3(根据检索式进行一次检索看是否能检索出专利)
+        //检查任务合法性3(检查产品是否存在)
+        if (taskAddNewDTO.getProductId() != null) {
+            Product product = productService.getById(taskAddNewDTO.getProductId());
+            if (product == null) {
+                ThrowException.throwXiaoShiException("该产品已不存在,请尝试刷新页面");
+            }
+        }
+
+        //TODO 检查任务合法性4(检查报告是否存在)
+
+        //检查任务合法性5(尝试检索式能否检索出专利)
         PatentStarListDto patentStarListDto = new PatentStarListDto()
                 .setCurrentQuery(taskAddNewDTO.getConditions())
                 .setOrderBy(taskAddNewDTO.getOrderBy())
@@ -139,24 +150,19 @@ public class UploadTaskService {
         }
 
         //计算要下载的专利总数量
-        Integer total;
+        int total;
         if (taskAddNewDTO.getEndNumber() > 0) {
             total = taskAddNewDTO.getEndNumber() - taskAddNewDTO.getStartNumber() + 1;
-            if (taskAddNewDTO.getIsDeletePatentNos() != null) {
+            if (taskAddNewDTO.getIsDeletePatentNos() != null && taskAddNewDTO.getIsDeletePatentNos().size() > 0) {
                 total = total - taskAddNewDTO.getIsDeletePatentNos().size();
             }
-            if (taskAddNewDTO.getIsAddPatentNos() != null) {
+            if (taskAddNewDTO.getIsAddPatentNos() != null && taskAddNewDTO.getIsAddPatentNos().size() > 0) {
                 total = total + taskAddNewDTO.getIsAddPatentNos().size();
             }
         } else {
             total = taskAddNewDTO.getIsAddPatentNos().size();
         }
 
-        //如果是多个专利号导入,总数量改为实际检索到的数量
-        if (taskAddNewDTO.getTaskType2().equals(5)) {
-            total = (Integer) resultMap.get("total");
-        }
-
         //任务条件表("task_condition")新增数据
         TaskCondition taskCondition = new TaskCondition();
         taskCondition
@@ -200,58 +206,10 @@ public class UploadTaskService {
     }
 
     /**
-     * 新增Epo网站导入任务
-     *
-     * @param taskAddNewDTO 前台参数(检索信息conditions、专题库id、下载字段configCells等)
+     * 新增专利号导入任务
      */
-//    public TaskCondition addEpoTask(TaskAddNewDTO taskAddNewDTO) throws IOException {
-//        Integer webId = taskAddNewDTO.getConfigId();
-//        PersonnelVO personnelVO = cacheUtils.getLoginUserPersonnel(loginUtils.getId());
-//        //根据网站id获得配置
-//        WebLoginConfig webLoginConfig = webLoginConfigService.getLoginConfig(webId, personnelVO.getTenantId());
-//        if (webLoginConfig == null) {
-//            ThrowException.throwXiaoShiException("未配置网站登录信息");
-//        }
-//
-//        //检查任务合法性(检查当前检索式能否检索出专利)
-//        //根据检索式conditions检索一件专利著录信息
-//        SerachBiblioData serachBiblioData = excutePatentDataEpo.getSerachBiblioData(taskAddNewDTO.getConditions(), 1, 1);
-//        if (serachBiblioData == null || serachBiblioData.getTotals() == 0) {
-//            ThrowException.throwXiaoShiException("根据检索信息未检索到相关专利,请尝试更换检索信息");
-//        }
-//        //任务与任务条件关联表新增数据
-//        TaskCondition taskCondition = new TaskCondition();
-//        taskCondition
-//                .setTaskType(taskAddNewDTO.getTaskType())
-//                .setConditions(taskAddNewDTO.getConditions())
-//                .setCrons(taskAddNewDTO.getCrons())
-//                .setConfigId(taskAddNewDTO.getConfigId())
-//                .setTaskName(taskAddNewDTO.getTaskName())
-//                .setTotal(serachBiblioData.getTotals());
-//        List<String> cells = taskAddNewDTO.getConfigCells();
-//        if (cells == null) {
-//            taskCondition.setConfigCells("");
-//        } else {
-//            taskCondition.setConfigCells(String.join(",", cells));
-//        }
-//        taskConditionService.save(taskCondition);
-//
-//        //任务表新增任务
-//        Integer taskId = taskService.addTask3(taskAddNewDTO, serachBiblioData.getTotals(), taskCondition);
-//
-//        //任务与任务条件关联表更新数据
-//        taskCondition.setTaskId(taskId);
-//        taskConditionService.updateById(taskCondition);
-//
-//        //任务存入生产者任务队列并唤醒生产者线程
-//        pantentQueueService.taskQueueListAddTask(Arrays.asList(taskId));
-//        pantentQueueService.awakeTasktch();
-//
-//        return taskCondition;
-//    }
-
     public void addPatentNoTask(TaskAddNewDTO taskAddNewDTO) throws IOException {
-        log.info("开始处理【根据专利号导入专利】的业务,参数为:{}", taskAddNewDTO);
+        log.info("开始处理【专利号导入专利】的业务,业务参数为:{}", taskAddNewDTO);
 
         //检查合法性
         if (taskAddNewDTO == null || taskAddNewDTO.getConditions() == null || taskAddNewDTO.getConditions().trim().equals("")) {
@@ -259,48 +217,173 @@ public class UploadTaskService {
             return;
         }
 
-        String isAddPatentNosStr = taskAddNewDTO.getConditions();
+        String patentNoStr = taskAddNewDTO.getConditions();
+        patentNoStr = patentNoStr.replaceAll(" +", "");  //去掉所有空格
+        List<String> patentNos = Arrays.asList(patentNoStr.split("[,|,]"));  //生成专利号集合
+
+        //检查合法性,若用户输入的多个专利号总长度超过24,但拆分后专利号集合只有一个元素(即只有一个专利号),则表示用户输入的格式不正确
+        if (patentNoStr.length() > 24 && patentNos.size() == 1) {
+            ThrowException.throwXiaoShiException("请按照格式要求正确输入专利号");
+        }
 
-        //根据专利号生成检索式
-        String condition = this.setPatentNosToCondition(taskAddNewDTO.getConditions());
         taskAddNewDTO
-                .setProjectId(taskAddNewDTO.getProjectId())
-                .setReportId(taskAddNewDTO.getReportId())
-                .setProductId(taskAddNewDTO.getProductId())
-                .setConditions(condition)
+                .setConditions(patentNoStr.replaceAll("[,|,]", "|"))
                 .setEndNumber(0)
-                .setIsAddPatentNos(Arrays.asList(isAddPatentNosStr.split("[,|,]")))
-                .setDBType("CN")
+                .setIsAddPatentNos(patentNos)
+                .setDBType("CN/WD")
                 .setOrderBy("AD")
                 .setOrderByType("DESC")
                 .setConfigCells(Arrays.asList("1", "2", "3", "4", "6"))
                 .setConfigId(2)
-                .setTaskName("多个专利号导入方式任务")
+                .setTaskName("专利号导入任务")
                 .setTaskType(0)
-                .setTaskType2(5)
-                .setIsAddType(2)
-        ;
-
-        //根据下载的网站类型新增任务
-        if (taskAddNewDTO.getTaskType2().equals(3)) {
-            //this.addEpoTask(taskAddNewDTO);
-        } else if (taskAddNewDTO.getTaskType2().equals(4) || taskAddNewDTO.getTaskType2().equals(5)) {
-            this.addPatentStarTask(taskAddNewDTO);
+                .setTaskType2(5);
+
+        //检查任务合法性1(检查是否有选择下载字段)
+        List<String> cells = taskAddNewDTO.getConfigCells();
+        if (cells == null || cells.size() == 0) {
+            ThrowException.throwXiaoShiException("请选择至少一个需要下载的字段");
         }
 
-    }
+        //检查任务合法性2(检查专题库是否存在)
+        if (taskAddNewDTO.getProjectId() != null) {
+            Project project = projectService.getById(taskAddNewDTO.getProjectId());
+            if (project == null) {
+                ThrowException.throwXiaoShiException("该专题库已不存在,请尝试刷新页面");
+            }
+        }
+
+        //检查任务合法性3(检查产品是否存在)
+        if (taskAddNewDTO.getProductId() != null) {
+            Product product = productService.getById(taskAddNewDTO.getProductId());
+            if (product == null) {
+                ThrowException.throwXiaoShiException("该产品已不存在,请尝试刷新页面");
+            }
+        }
+
+        //TODO 检查任务合法性4(检查报告是否存在)
+
+        //检查任务合法性5(尝试检索式能否检索出专利)
+        Map<String, Object> resultMap = null;
+        PatentStarListDto patentStarListDto = new PatentStarListDto()
+                .setOrderBy(taskAddNewDTO.getOrderBy())
+                .setOrderByType(taskAddNewDTO.getOrderByType())
+                .setPageNum(1)
+                .setRowCount(10);
+        //中国专利检索中国库
+        List<String> cNPatentNos = taskAddNewDTO.getIsAddPatentNos().stream().filter(patentNo -> patentNo.contains("CN")).collect(Collectors.toList());
+        if (cNPatentNos.size() > 0) {
+            List<String> cNPatentNos0;
+            try {
+                cNPatentNos0 = cNPatentNos.subList(0, 1000);
+            } catch (IndexOutOfBoundsException e) {
+                int leftNum = cNPatentNos.size() % 1000;
+                cNPatentNos0 = cNPatentNos.subList(0, leftNum);
+            }
+            String join = StringUtils.join(cNPatentNos0, " OR ");
+            patentStarListDto
+                    .setCurrentQuery("AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")")
+                    .setDBType("CN");
+            resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
+        }
+        //外国专利检索外国库
+        List<String> wDPatentNos = taskAddNewDTO.getIsAddPatentNos().stream().filter(patentNo -> !patentNo.contains("CN")).collect(Collectors.toList());
+        if (wDPatentNos.size() > 0 && (resultMap == null || (Integer) resultMap.get("total") == 0)) {
+            List<String> wDPatentNos0;
+            try {
+                wDPatentNos0 = wDPatentNos.subList(0, 1000);
+            } catch (IndexOutOfBoundsException e) {
+                int leftNum = wDPatentNos.size() % 1000;
+                wDPatentNos0 = wDPatentNos.subList(0, leftNum);
+            }
+            String join = StringUtils.join(wDPatentNos0, " OR ");
+            patentStarListDto
+                    .setCurrentQuery("PN=(" + join + ")")
+                    .setDBType("WD");
+            resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
+        }
+        if (resultMap == null || (Integer) resultMap.get("total") == 0) {
+            ThrowException.throwXiaoShiException("该检索信息未检索出相关专利");
+        }
 
-    public String setPatentNosToCondition(String patentNosStr) {
-        String[] patentNosArr = patentNosStr.split("[,|,]");
-        ArrayList<String> patentNos = new ArrayList<>(Arrays.asList(patentNosArr));
-        //判断若用户输入的多个专利号字符长度超过了一个专利号长度,而拆分后专利号集合只有一个元素,则定义为用户输入的格式不正确
-        if (patentNosStr.length() > 24 && patentNos.size() == 1) {
-            ThrowException.throwXiaoShiException("请按照格式要求正确输入专利号(注意:不允许出现空格)");
+        //计算要下载的专利总数量
+        Integer total = 0;
+        //检索到的中国专利数量
+        if (cNPatentNos.size() > 0) {
+            for (int i = 0; i < cNPatentNos.size(); i += 1000) {
+                List<String> cNPatentNos0;
+                try {
+                    cNPatentNos0 = cNPatentNos.subList(i, i + 1000);
+                } catch (IndexOutOfBoundsException e) {
+                    int leftNum = cNPatentNos.size() % 1000;
+                    cNPatentNos0 = cNPatentNos.subList(i, i + leftNum);
+                }
+                String join = StringUtils.join(cNPatentNos0, " OR ");
+                patentStarListDto
+                        .setCurrentQuery("AN=(" + join + ") OR PN=(" + join + ") OR GN=(" + join + ")")
+                        .setDBType("CN");
+                resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
+                if (resultMap != null && (Integer) resultMap.get("total") > 0) {
+                    total += (Integer) resultMap.get("total");
+                }
+            }
         }
-        //将本系统不包含的专利拼接成条件
-        String patentNoCondition = StringUtils.join(patentNos, " OR ");
-        String conditions = "AN=(" + patentNoCondition + ") OR PN=(" + patentNoCondition + ") OR GN=(" + patentNoCondition + ")";
-        return conditions;
+        //检索到的外国专利数量
+        if (wDPatentNos.size() > 0) {
+            for (int i = 0; i < wDPatentNos.size(); i += 1000) {
+                List<String> wDPatentNos0;
+                try {
+                    wDPatentNos0 = wDPatentNos.subList(i, i + 1000);
+                } catch (IndexOutOfBoundsException e) {
+                    int leftNum = wDPatentNos.size() % 1000;
+                    wDPatentNos0 = wDPatentNos.subList(i, i + leftNum);
+                }
+                String join = StringUtils.join(wDPatentNos0, " OR ");
+                patentStarListDto
+                        .setCurrentQuery("PN=(" + join + ")")
+                        .setDBType("WD");
+                resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
+                if (resultMap != null && (Integer) resultMap.get("total") > 0) {
+                    total += (Integer) resultMap.get("total");
+                }
+            }
+        }
+
+        //任务条件表("task_condition")新增数据
+        TaskCondition taskCondition = new TaskCondition();
+        taskCondition
+                .setTaskType(taskAddNewDTO.getTaskType())
+                .setTaskType2(taskAddNewDTO.getTaskType2())
+                .setConditions(taskAddNewDTO.getConditions())
+                .setCrons(taskAddNewDTO.getCrons())
+                .setConfigId(taskAddNewDTO.getConfigId())
+                .setTaskName(taskAddNewDTO.getTaskName())
+                .setTotal(total)
+                .setOrderBy(taskAddNewDTO.getOrderBy())
+                .setOrderByType(taskAddNewDTO.getOrderByType())
+                .setDBType(taskAddNewDTO.getDBType())
+                .setStartNumber(taskAddNewDTO.getStartNumber())
+                .setEndNumber(taskAddNewDTO.getEndNumber())
+                .setIsAddType(taskAddNewDTO.getIsAddType())
+                .setConfigCells(String.join(",", cells));
+        taskCondition.setIsAddPatentNos(StringUtils.join(taskAddNewDTO.getIsAddPatentNos(), ","));
+
+        log.info("任务条件表新增数据");
+        taskConditionService.save(taskCondition);
+
+        //任务表新增任务
+        Integer taskId = taskService.addTask3(taskAddNewDTO, total, taskCondition);
+
+        //任务条件表(task_condition)更新数据(普通任务)
+        if (taskAddNewDTO.getTaskType().equals(0)) {
+            taskCondition.setTaskId(taskId);
+            taskConditionService.updateById(taskCondition);
+        }
+
+        //任务存入生产者任务队列并唤醒生产者线程
+        pantentQueueService.taskQueueListAddTask(Arrays.asList(taskId));
+        pantentQueueService.awakeTasktch();
+
     }
 
 }

+ 1 - 1
PAS/src/test/java/cn/cslg/pas/service/PatentRightServiceTests.java

@@ -21,7 +21,7 @@ public class PatentRightServiceTests {
      */
     @Test
     void queryPatentRightTree() {
-        List<TreeNode> treeNodes = patentRightService.queryPatentRightTree(184872);
+        List<TreeNode> treeNodes = patentRightService.queryPatentRightTree("");
     }
 
 }