Procházet zdrojové kódy

Merge remote-tracking branch 'origin/dev2' into dev2

lwhhszx před 2 roky
rodič
revize
c56a60e08b

+ 64 - 75
PAS/src/main/java/cn/cslg/pas/common/core/CreateTaskThread.java

@@ -31,81 +31,70 @@ public class CreateTaskThread implements InitializingBean {
 
     @Override
     public void afterPropertiesSet() throws Exception {
-//        //初始化任务队列
-//        //查找任务状态为0(队列中)和1(进行中)的任务
-//        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().in(Task::getStatus, new ArrayList<>(Arrays.asList(0, 1))));
-//        if (tasks.size() > 0) {
-//            //过滤出任务ids
-//            List<Integer> taskIds = tasks.stream().map(Task::getId).collect(Collectors.toList());
-//            //过滤出进行中的任务的id
-//            List<Task> doingTasks = tasks.stream().filter(item -> item.getStatus() == 1).collect(Collectors.toList());
-//            List<Integer> doingTaskIds = doingTasks.stream().map(Task::getId).collect(Collectors.toList());
-//            if (doingTaskIds.size() > 0) {
-//                //先将进行中的任务(项目重启后进行中的任务仅会有1个)的id先存入任务队列,再将其余存入
-//                pantentQueueService.queueAddTask(Arrays.asList(doingTaskIds.get(0)));
-//                taskIds.removeAll(doingTaskIds);
-//            }
-//            pantentQueueService.queueAddTask(taskIds);
-//        }
-//
-//        //生产者线程
-//        Thread threadProducer = new Thread(pantentQueueService::addPatnetToQueue);
-//        threadProducer.start();
-//
-//
-//        //消费者1线程(摘要附图)
-//        Thread threadConsumer1 = new Thread(() -> {
-//            try {
-//                pantentQueueService.pushPatentImageToDB();
-//            } catch (InterruptedException | IOException e) {
-//                e.printStackTrace();
-//            }
-//        });
-//        threadConsumer1.start();
-//
-//
-//        //消费者2线程(著录项目)
-//        Thread threadConsumer2 = new Thread(() -> {
-//            try {
-//                pantentQueueService.pushPatentZhuLuToDB();
-//            } catch (InterruptedException | IOException e) {
-//                e.printStackTrace();
-//            }
-//        });
-//        threadConsumer2.start();
-//
-//
-//        //消费者3线程(权利要求)
-//        Thread threadConsumer3 = new Thread(() -> {
-//            try {
-//                pantentQueueService.pushPatentRightToDB();
-//            } catch (InterruptedException | IOException e) {
-//                e.printStackTrace();
-//            }
-//        });
-//        threadConsumer3.start();
-//
-//
-//        //消费者4线程(说明书文本消费者)
-//        Thread threadConsumer4 = new Thread(() -> {
-//            try {
-//                pantentQueueService.pushPatentInstructionTextToDB();
-//            } catch (InterruptedException | IOException e) {
-//                e.printStackTrace();
-//            }
-//        });
-//        threadConsumer4.start();
-//
-//
-//        //消费者5线程(与专利关联数据消费者)
-//        Thread threadConsumer5 = new Thread(() -> {
-//            try {
-//                pantentQueueService.pushPatentAssoToDB();
-//            } catch (InterruptedException | IOException e) {
-//                e.printStackTrace();
-//            }
-//        });
-//        threadConsumer5.start();
+        //初始化任务队列
+        //查找任务状态为0(队列中)和1(进行中)的任务
+        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().in(Task::getStatus, new ArrayList<>(Arrays.asList(0, 1))));
+        if (tasks.size() > 0) {
+            //过滤出任务ids
+            List<Integer> taskIds = tasks.stream().map(Task::getId).collect(Collectors.toList());
+            //过滤出进行中的任务的id
+            List<Task> doingTasks = tasks.stream().filter(item -> item.getStatus() == 1).collect(Collectors.toList());
+            List<Integer> doingTaskIds = doingTasks.stream().map(Task::getId).collect(Collectors.toList());
+            if (doingTaskIds.size() > 0) {
+                //先将进行中的任务(项目重启后进行中的任务仅会有1个)的id先存入任务队列,再将其余存入
+                pantentQueueService.taskQueueAddTask(Arrays.asList(doingTaskIds.get(0)));
+                taskIds.removeAll(doingTaskIds);
+            }
+            pantentQueueService.taskQueueAddTask(taskIds);
+        }
+
+        //生产者线程
+        Thread threadProducer = new Thread(pantentQueueService::addPatnetToQueue);
+        threadProducer.start();
+
+
+        //消费者1线程(摘要附图)
+        Thread threadConsumer1 = new Thread(() -> {
+            try {
+                pantentQueueService.pushPatentImageToDB();
+            } catch (InterruptedException | IOException e) {
+                e.printStackTrace();
+            }
+        });
+        threadConsumer1.start();
+
+
+        //消费者2线程(著录项目)
+        Thread threadConsumer2 = new Thread(() -> {
+            try {
+                pantentQueueService.pushPatentZhuLuToDB();
+            } catch (InterruptedException | IOException e) {
+                e.printStackTrace();
+            }
+        });
+        threadConsumer2.start();
+
+
+        //消费者3线程(权利要求)
+        Thread threadConsumer3 = new Thread(() -> {
+            try {
+                pantentQueueService.pushPatentRightToDB();
+            } catch (InterruptedException | IOException e) {
+                e.printStackTrace();
+            }
+        });
+        threadConsumer3.start();
+
+
+        //消费者4线程(说明书文本消费者)
+        Thread threadConsumer4 = new Thread(() -> {
+            try {
+                pantentQueueService.pushPatentInstructionTextToDB();
+            } catch (InterruptedException | IOException e) {
+                e.printStackTrace();
+            }
+        });
+        threadConsumer4.start();
 
     }
 

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

@@ -541,8 +541,10 @@ public class ProjectService extends ServiceImpl<ProjectMapper, Project> {
         projectUserService.deleteByProjectId(id);
         projectFileService.deleteByProjectId(id);
         patentApplicantMergeLinkService.deleteByProjectId(id);
-        //陈宇 ↓ 删除专题库id关联产品id关联架构id(asso_structure_patent表)数据
+        //陈宇 ↓ 删除专题库产品架构标引表(asso_structure_patent)数据
         assoStructurePatentMapper.deleteByProjectId(id);
+        //陈宇 ↓ 删除任务表(os_task)数据
+        taskService.remove(new LambdaQueryWrapper<Task>().eq(Task::getProjectId, id));
         return Response.success();
     }
 

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

@@ -15,6 +15,8 @@ import cn.cslg.pas.common.model.vo.TaskVO;
 import cn.cslg.pas.domain.asso.AssoOsTaskQrtzTask;
 import cn.cslg.pas.mapper.TaskMapper;
 import cn.cslg.pas.common.model.dto.UploadFileDTO;
+import cn.cslg.pas.service.upLoadPatent.ExcutePatentDataExcel;
+import cn.cslg.pas.service.upLoadPatent.PantentQueueService;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.io.FileUtil;
 import com.alibaba.fastjson.JSON;
@@ -53,6 +55,8 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
     private final LoginUtils loginUtils;
     private final RequestService requestService;
     private final OutInterfaceService outInterfaceService;
+    private final PantentQueueService pantentQueueService;
+    private final ExcutePatentDataExcel excutePatentDataExcel;
 
     public String getFileUrl(Integer id) {
         Task task = this.getById(id);
@@ -296,24 +300,24 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
     public void pauseTask(Integer taskId) {
         log.info("开始处理【暂停任务】的业务,参数为:taskId={}", taskId);
 
-        //1.检查尝试暂停的任务是否存在,若不存在则暂停失败,提示用户 "暂停失败,当前任务已不存在,请尝试刷新页面"
+        //1.检查尝试暂停的任务是否存在,若不存在则提示用户 "暂停失败,当前任务已不存在,请尝试刷新页面"
         log.info("检查尝试暂停的任务是否存在");
         Task task = this.getById(taskId);
         if (task == null) {
             ThrowException.throwXiaoShiException("暂停失败,当前任务已不存在,请尝试刷新页面");
             return;
         }
-        //2.检查尝试暂停的任务是否已处于暂停状态,若是则暂停失败,提示用户 "暂停失败,当前任务已处于暂停状态,请尝试刷新页面"
+        //2.检查尝试暂停的任务是否已处于暂停状态,若是则提示用户 "暂停失败,当前任务已处于暂停状态,请尝试刷新页面"
         if (task.getStatus().equals(4)) {
             ThrowException.throwXiaoShiException("暂停失败,当前任务已处于暂停状态,请尝试刷新页面");
         }
 
-        //3.检查尝试暂停的任务是否处于进行中状态,若不是则暂停失败,提示用户 "暂停失败,当前任务已结束或未开始,请尝试刷新页面"
+        //3.检查尝试暂停的任务是否处于进行中状态,若不是则提示用户 "暂停失败,当前任务已结束或未开始,请尝试刷新页面"
         if (!task.getStatus().equals(1)) {
             ThrowException.throwXiaoShiException("暂停失败,当前任务已结束或未开始,请尝试刷新页面");
         }
 
-        //4.暂停任务
+        //4.任务表将任务状态修改为4暂停
         Task updateTask = new Task();
         updateTask.setId(taskId);
         updateTask.setStatus(4);
@@ -323,6 +327,16 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
             ThrowException.throwXiaoShiException("暂停失败,服务器忙请稍后再试");
         }
 
+        //5.将生产者生产专利类中的公共任务状态改为暂停
+        excutePatentDataExcel.setTaskStatus(4);
+        try {
+            Thread.sleep(2000);
+        } catch (InterruptedException e) {
+            ThrowException.throwXiaoShiException("暂停失败,未知错误");
+        }
+        //6.将消费者的专利队列中所有该任务的专利剔除
+        pantentQueueService.consumerQueueDeleteTasks(taskId);
+
         log.info("暂停任务成功");
 
     }
@@ -336,7 +350,7 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
     public void continueTask(Integer taskId) {
         log.info("开始处理【继续任务】的业务,参数为:taskId={}", taskId);
 
-        //1.检查尝试继续的任务是否存在,若不存在则继续失败,提示用户 "继续失败,当前任务已不存在,请尝试刷新页面"
+        //1.检查尝试继续的任务是否存在,若不存在则提示用户 "继续失败,当前任务已不存在,请尝试刷新页面"
         log.info("检查尝试继续的任务是否存在");
         Task task = this.getById(taskId);
         if (task == null) {
@@ -344,7 +358,7 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
             return;
         }
 
-        //2.检查尝试继续的任务是否处于暂停状态,若不是则继续失败,提示用户 "继续失败,当前任务未暂停,请尝试刷新页面"
+        //2.检查尝试继续的任务是否处于暂停状态,若不是则提示用户 "继续失败,当前任务未暂停,请尝试刷新页面"
         if (!task.getStatus().equals(4)) {
             ThrowException.throwXiaoShiException("继续失败,当前任务未暂停,请尝试刷新页面");
         }
@@ -359,6 +373,10 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
             ThrowException.throwXiaoShiException("继续失败,服务器忙请稍后再试");
         }
 
+        //4.将当前任务添加进生产者任务队列进行排队,并唤醒生产者线程
+        pantentQueueService.taskQueueAddTask(new ArrayList<>(Arrays.asList(taskId)));
+        pantentQueueService.awakeTasktch();
+
         log.info("继续任务成功");
 
     }

+ 0 - 2
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/ExcuteDataToVOService.java

@@ -1,9 +1,7 @@
 package cn.cslg.pas.service.upLoadPatent;
 
-import cn.cslg.pas.common.model.vo.ProjectImportPatentVO;
 import cn.cslg.pas.common.model.vo.UploadParamsVO;
 import cn.cslg.pas.common.model.vo.UploadSettingVO;
-import cn.cslg.pas.common.utils.FileUtils;
 import cn.cslg.pas.common.utils.UploadPatentBatchUtil;
 import cn.cslg.pas.domain.PatentData;
 import org.apache.poi.ss.usermodel.PictureData;

+ 10 - 0
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/ExcutePatentDataExcel.java

@@ -28,6 +28,7 @@ public class ExcutePatentDataExcel implements IExcutePatentData {
     private final ExcuteUploadSettingService excuteUploadSettingService;
     private final ExcuteDataToVOService excuteDataToVOService;
     private final PantentQueueService pantentQueueService;
+    private Integer taskStatus;
 
     /**
      * 解析获取专利数据
@@ -50,7 +51,12 @@ public class ExcutePatentDataExcel implements IExcutePatentData {
         //解析Excel文件获得工作簿
         Sheet sheet = ReadExcelUtils.readExcel(filePath);
         //遍历专利总数量,在循环中将专利一个一个存入消费者专利队列
+        taskStatus = 0;
         for (int i = lastIndex; i < total; i++) {
+            //判断若任务状态为暂停(4),则不再生产该任务的专利
+            if (taskStatus == 4) {
+                return;
+            }
             PatentData patentData = ReadExcelUtils.readExcelOneRow(filePath, sheet, i + 1);
             //调用装载数据类(根据数据源配置文件对象和专利源数据生成专利数据)
             UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
@@ -60,4 +66,8 @@ public class ExcutePatentDataExcel implements IExcutePatentData {
         }
     }
 
+    public void setTaskStatus(Integer taskStatus) {
+        this.taskStatus = taskStatus;
+    }
+
 }

+ 0 - 702
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/ExcuteTaskToPatentService.java

@@ -1,702 +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.ProjectImportPatentVO;
-import cn.cslg.pas.common.model.vo.UploadParamsVO;
-import cn.cslg.pas.common.model.vo.UploadSettingVO;
-import cn.cslg.pas.common.utils.*;
-import cn.cslg.pas.domain.*;
-import cn.cslg.pas.domain.asso.AssoOsTaskQrtzTask;
-import cn.cslg.pas.exception.XiaoShiException;
-import cn.cslg.pas.service.*;
-import cn.cslg.pas.service.asso.AssoOsTaskQrtzTaskService;
-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.apache.poi.ss.usermodel.Sheet;
-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;
-
-/**
- * 根据不同类型任务生成专利入消费者队列的业务层
- *
- * @Author chenyu
- * @Date 2023/6/12
- */
-@Slf4j
-@Service
-@RequiredArgsConstructor
-public class ExcuteTaskToPatentService implements Serializable {
-    private final FileUtils fileUtils;
-    private final ExcuteUploadSettingService excuteUploadSettingService;
-    private final ExcuteDataToVOService excuteDataToVOService;
-    private final PantentQueueService pantentQueueService;
-    private final AssoOsTaskQrtzTaskService assoOsTaskQrtzTaskService;
-    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 TaskService taskService;
-
-    //TODO 工厂类
-    public void taskToPatentQueue(Task task) throws IOException {
-        //Excel导入任务
-        if (task.getType() == 1) {
-            excelTaskToPatentQueue(task);
-            //EPO网站导入任务
-        } else if (task.getType() == 3) {
-            epoTaskToPatentQueue(task);
-        }
-
-    }
-
-    /**
-     * Excel导入专利
-     *
-     * @param task Excel导入专利任务
-     */
-    public void excelTaskToPatentQueue(Task task) throws IOException {
-        //从任务中取出文件路径、总条数、成功条数、前台参数json
-        String filePath = task.getUrl();  //相对路径
-        filePath = fileUtils.getPath(filePath);  //绝对路径
-        Integer total = task.getTotal();
-
-        int lastIndex = task.getSuccessNum();
-        String json = task.getPramJson();
-        ProjectImportPatentVO projectImportPatentVO = JsonUtils.jsonToPojo(json, ProjectImportPatentVO.class);
-        //解析数据源类,通过数据来源id(如1:智慧芽)解析数据源配置文件,获得数据源配置文件对象jsonData
-        List<UploadSettingVO.Column> jsonData = excuteUploadSettingService.ExcuteUploadSetting(projectImportPatentVO.getSourceId());
-        //解析Excel文件获得工作簿
-        Sheet sheet = ReadExcelUtils.readExcel(filePath);
-        //遍历专利总数量,在循环中保存专利
-        for (int i = lastIndex; i < total; i++) {
-            PatentData patentData = ReadExcelUtils.readExcelOneRow(filePath, sheet, i + 1);
-            //调用装载数据类,专利数据转换为VO对象
-            UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
-
-            //专利入消费者队列,并唤醒消费者执行专利入库
-            //patentToQueueAwakeConsumer(uploadParamsVO, projectImportPatentVO);
-            pantentQueueService.patentToQueue(task, uploadParamsVO, projectImportPatentVO);
-        }
-    }
-
-    /**
-     * EPO网站导入专利
-     *
-     * @param task EPO网站导入专利
-     */
-    public void epoTaskToPatentQueue(Task task) throws IOException {
-        Integer taskId = task.getId();
-        List<AssoOsTaskQrtzTask> assoOsTaskQrtzTasks = assoOsTaskQrtzTaskService.list(new LambdaQueryWrapper<AssoOsTaskQrtzTask>().eq(AssoOsTaskQrtzTask::getTaskId, taskId));
-        AssoOsTaskQrtzTask assoOsTaskQrtzTask = assoOsTaskQrtzTasks.get(0);
-
-        Integer successNum = task.getSuccessNum();
-
-        //从任务关联网站导入任务对象中取出下载字段、检索信息
-        String cellsStr = assoOsTaskQrtzTask.getConfigCells();
-        List<String> cells = Arrays.asList(cellsStr.split(","));
-        String conditions = assoOsTaskQrtzTask.getConditions();
-
-        //定义每次检索的专利数量(每次检索50件)
-        int size = 50;
-
-        //获得专利总数量
-        Integer count = task.getTotal();
-
-        //计算进度值
-//        double percentage = count == 0 ? 0 : (count.equals(successNum) ? (successNum * 1D) : (successNum + 1D) / count * 100D);
-//        percentage = MathUtils.saveTwoDecimal(percentage);
-        //1.根据专利总数量count遍历检索专利
-        for (int i = 1; i <= count; i += size) {
-            //查看任务状态
-//            QrtzTaskDetail qrtzTaskDetail1 = qrTaskDetailService.getById(webQueryDTO.getTaskId());
-//            if (qrtzTaskDetail1.getTaskDetailState().equals(7)) {
-//                qrtzTaskDetail1.setTaskDetailState(5);
-//                qrtzTaskDetail1.setSuccessNum(successNum);
-//                qrtzTaskDetail1.setTaskProcess(percentage);
-//                qrtzTaskDetail1.updateById();
-//                WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
-//                        .setId(webQueryDTO.getTaskId())
-//                        .setProjectId(task.getProjectId())
-//                        .setComplete(false)
-//                        .setIndex(successNum)
-//                        .setTaskDetailState(5)
-//                        .setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "null");
-//                return null;
-//            } else if (qrtzTaskDetail1.getTaskDetailState().equals(8)) {
-//                qrtzTaskDetail1.setTaskDetailState(6);
-//                qrtzTaskDetail1.setSuccessNum(successNum);
-//                qrtzTaskDetail1.setTaskProcess(percentage);
-//                qrtzTaskDetail1.updateById();
-//                WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
-//                        .setId(webQueryDTO.getTaskId())
-//                        .setProjectId(task.getProjectId())
-//                        .setComplete(false)
-//                        .setIndex(successNum)
-//                        .setTaskDetailState(6)
-//                        .setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "null");
-//                return null;
-//            }
-            //根据检索式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) {
-                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) {
-//                        String res = outInterfaceService.importPatents(patentCell);
-//                        JSONObject jsonObject = JSONObject.parseObject(res);
-//                        if (jsonObject.get("code").toString().equals("500")) {
-//                            //舍弃这个专利,继续下一个专利
-//                            continue;
-//                        }
-                        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);
-                        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, null);
-                    }
-
-//                    QrtzTaskDetail qrtzTaskDetail11 = qrTaskDetailService.getById(qrtzTaskDetail.getId());
-//                    percentage = count == 0 ? 0 : (count.equals(successNum) ? (successNum * 1D) : (successNum + 1D) / count * 100D);
-//                    percentage = MathUtils.saveTwoDecimal(percentage);
-//                    WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
-//                            .setId(webQueryDTO.getTaskId())
-//                            .setProjectId(task.getProjectId())
-//                            .setComplete(false)
-//                            .setIndex(successNum)
-//                            .setPercentage(percentage)
-//                            .setTaskDetailState(qrtzTaskDetail11.getTaskDetailState())
-//                            .setFileName("")
-//                            .setUrl("")
-//                            .setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "null");
-                } catch (XiaoShiException e) {
-                    //虽然拿不到所有附图,但已经拿到了专利著录,能拿到啥是啥
-                    log.info(e.getMessage());
-                } catch (Exception e) {
-//                    qrtzTaskDetail.setTaskDetailState(3);
-//                    qrtzTaskDetail.setSuccessNum(successNum);
-//                    qrtzTaskDetail.setDefaultNum(qrtzTaskDetail.getAllNum() - successNum);
-//                    qrtzTaskDetail.setFailure("拉取节点失败");
-//                    qrtzTaskDetail.setEndTime(new Date());
-//                    qrtzTaskDetail.updateById();
-//                    if (qrtzTask.getTaskType() == 1) {
-//                        qrtzTask.setTaskState(4);
-//                    } else {
-//                        qrtzTask.setTaskState(3);
-//                    }
-//                    qrtzTask.updateById();
-//                    WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
-//                            .setId(webQueryDTO.getTaskId())
-//                            .setProjectId(task.getProjectId())
-//                            .setComplete(true)
-//                            .setIndex(successNum)
-//                            .setPercentage(100D)
-//                            .setTaskDetailState(qrtzTaskDetail.getTaskDetailState())
-//                            .setFileName("")
-//                            .setUrl("")
-//                            .setTotal(successNum), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "");
-                }
-
-            }
-        }
-//        WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
-//                .setId(webQueryDTO.getTaskId())
-//                .setProjectId(task.getProjectId())
-//                .setComplete(true)
-//                .setIndex(count)
-//                .setPercentage(100D)
-//                .setTaskDetailState(qrtzTaskDetail.getTaskDetailState())
-//                .setFileName("")
-//                .setUrl("")
-//                .setTotal(count), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), "");
-//        //任务执行情况状态设为成功,任务条件状态设为已完成(若是任务条件是定时任务则设为等待下一次执行)
-//        qrtzTaskDetail.setTaskDetailState(2);
-//        qrtzTaskDetail.setSuccessNum(successNum);
-//        qrtzTaskDetail.setDefaultNum(qrtzTaskDetail.getAllNum() - successNum);
-//        qrtzTaskDetail.setTaskProcess(100);
-//        qrtzTaskDetail.setEndTime(new Date());
-//        qrtzTaskDetail.updateById();
-//        if (qrtzTask.getTaskType() == 1) {
-//            qrtzTask.setTaskState(4);
-//        } else {
-//            qrtzTask.setTaskState(2);
-//        }
-//        qrtzTask.updateById();
-//        return patentCells;
-    }
-
-    //调用接口获取一批专利著录信息
-    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());
-                }
-                //如果是其他附图
-                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());
-            }
-        }
-    }
-
-}

+ 89 - 95
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/PantentQueueService.java

@@ -8,6 +8,7 @@ import cn.cslg.pas.domain.Task;
 import cn.cslg.pas.service.TaskService;
 import cn.cslg.pas.service.UploadPatentBatchService;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import lombok.Data;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -33,23 +34,20 @@ public class PantentQueueService {
     private final ExcutePatentDataEpo excutePatentDataEpo;
     private final List<Integer> taskQueueList = new ArrayList<>();
     private Boolean flag = false;
-    private final Queue<QueueData> patentImageQueue = new LinkedList<>();
-    private final Queue<QueueData> patentZhuluQueue = new LinkedList<>();
-    private final Queue<QueueData> patentRightQueue = new LinkedList<>();
-    private final Queue<QueueData> patentInstructionTextQueue = new LinkedList<>();
-    private final Queue<QueueData> patentAssoQueue = new LinkedList<>();
+    private final List<QueueData> patentImageQueueList = new ArrayList<>();
+    private final List<QueueData> patentZhuluQueueList = new ArrayList<>();
+    private final List<QueueData> patentRightQueueList = new ArrayList<>();
+    private final List<QueueData> patentInstructionTextQueueList = new ArrayList<>();
     private final Lock taskLock = new ReentrantLock();
     private final Lock patentImageLock = new ReentrantLock();
     private final Lock patentZhuluLock = new ReentrantLock();
     private final Lock patentRightLock = new ReentrantLock();
     private final Lock patentInstructionTextLock = new ReentrantLock();
-    private final Lock patentAssoLock = new ReentrantLock();
     private final Condition taskCondition = taskLock.newCondition();
     private final Condition patentImageCondition = patentImageLock.newCondition();
     private final Condition patentZhuluCondition = patentZhuluLock.newCondition();
     private final Condition patentRightCondition = patentRightLock.newCondition();
     private final Condition patentInstructionTextCondition = patentInstructionTextLock.newCondition();
-    private final Condition patentAssoCondition = patentAssoLock.newCondition();
     private final HashMap<String, Integer> patentIdMap = new HashMap<>();
 
     /**
@@ -68,14 +66,18 @@ public class PantentQueueService {
                 //线程被唤醒后 ↓
                 if (taskQueueList.size() > 0) {
                     //1.从任务队列中取出一个task任务
+                    //2.同时将其从任务队列中剔除
+                    //3.查询任务,判断任务不存在或状态为已暂停,则直接跳过进行下一个任务
                     task = taskService.getById(taskQueueList.get(0));
-                    //同时将其从任务队列中剔除
                     taskQueueList.remove(0);
+                    if (task == null || task.getStatus() == 4) {
+                        continue;
+                    }
 
-                    //TODO 调用工厂方法,将任务扔进去,工厂方法根据任务类型返回对应的生产专利方法对象
+                    //TODO 调用工厂方法并将任务扔进去,工厂方法会根据任务的类型创建并返回对应的生产专利方法的对象
                     //1.用工厂方法根据任务类型创建对应的获取专利数据的对象
                     IExcutePatentData excutePatentDataObject = createObject(task);
-                    //2.开始执行生产专利方法(解析任务生产专利并丢入消费者专利队列,唤醒消费者线程)
+                    //2.对象调用执行生产专利方法(解析任务生产专利并丢入消费者专利队列,唤醒消费者线程)
                     if (excutePatentDataObject != null) {
                         excutePatentDataObject.startExcute(task);
                     }
@@ -100,7 +102,7 @@ public class PantentQueueService {
     public void pushPatentImageToDB() throws InterruptedException, IOException {
         while (true) {
             try {
-                if (patentImageQueue.isEmpty()) {
+                if (patentImageQueueList.isEmpty()) {
                     if (flag) {
                         System.out.println("摘要附图全部完成,退出循环");
                         return;
@@ -110,11 +112,11 @@ public class PantentQueueService {
                         patentImageLock.unlock();
                     }
                 } else {
-                    QueueData queueData = patentImageQueue.remove();
+                    QueueData queueData = patentImageQueueList.remove(0);
                     //摘要附图入库
                     uploadPatentToDBService.uploadPatentImage(queueData.getUploadParamsVO());
                     //Websocket发送message:通过WebSocket 在每一次循环结束后 向前端发送完成进度
-                    sendMessage(queueData, queueData.getTask().getTotal(), queueData.getTask());
+                    sendMessage(queueData);
                 }
 
             } catch (Exception e) {
@@ -131,7 +133,7 @@ public class PantentQueueService {
     public void pushPatentZhuLuToDB() throws InterruptedException, IOException {
         while (true) {
             try {
-                if (patentZhuluQueue.isEmpty()) {
+                if (patentZhuluQueueList.isEmpty()) {
                     if (flag) {
                         System.out.println("著录项目全部完成,退出循环");
                         return;
@@ -141,11 +143,17 @@ public class PantentQueueService {
                         patentZhuluLock.unlock();
                     }
                 } else {
-                    QueueData queueData = patentZhuluQueue.remove();
+                    QueueData queueData = patentZhuluQueueList.remove(0);
                     //著录项目入库
                     uploadPatentToDBService.uploadPatentZhulu(queueData.getUploadParamsVO());
+                    //专题库与专利关联入库
+                    uploadPatentToDBService.uploadAssoThemaPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
+                    //自定义字段标引与专利关联入库
+                    uploadPatentToDBService.uploadAssoFieldPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
+                    //文件夹与专利关联入库
+                    uploadPatentToDBService.uploadAssoPorPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
                     //Websocket发送message:通过WebSocket 在每一次循环结束后 向前端发送完成进度
-                    sendMessage(queueData, queueData.getTask().getTotal(), queueData.getTask());
+                    sendMessage(queueData);
                 }
 
             } catch (Exception e) {
@@ -161,7 +169,7 @@ public class PantentQueueService {
     public void pushPatentRightToDB() throws InterruptedException, IOException {
         while (true) {
             try {
-                if (patentRightQueue.isEmpty()) {
+                if (patentRightQueueList.isEmpty()) {
                     if (flag) {
                         System.out.println("权利要求全部完成,退出循环");
                         return;
@@ -171,11 +179,11 @@ public class PantentQueueService {
                         patentRightLock.unlock();
                     }
                 } else {
-                    QueueData queueData = patentRightQueue.remove();
+                    QueueData queueData = patentRightQueueList.remove(0);
                     //权要文本入库
                     uploadPatentToDBService.uploadPatentRight(queueData.getUploadParamsVO());
                     //Websocket发送message:通过WebSocket 在每一次循环结束后 向前端发送完成进度
-                    sendMessage(queueData, queueData.getTask().getTotal(), queueData.getTask());
+                    sendMessage(queueData);
                 }
 
             } catch (Exception e) {
@@ -191,7 +199,7 @@ public class PantentQueueService {
     public void pushPatentInstructionTextToDB() throws InterruptedException, IOException {
         while (true) {
             try {
-                if (patentInstructionTextQueue.isEmpty()) {
+                if (patentInstructionTextQueueList.isEmpty()) {
                     if (flag) {
                         System.out.println("说明书文本全部完成,退出循环");
                         return;
@@ -201,45 +209,11 @@ public class PantentQueueService {
                         patentInstructionTextLock.unlock();
                     }
                 } else {
-                    QueueData queueData = patentInstructionTextQueue.remove();
+                    QueueData queueData = patentInstructionTextQueueList.remove(0);
                     //说明书文本入库
                     uploadPatentToDBService.uploadPatentInstructionText(queueData.getUploadParamsVO());
                     //Websocket发送message:通过WebSocket 在每一次循环结束后 向前端发送完成进度
-                    sendMessage(queueData, queueData.getTask().getTotal(), queueData.getTask());
-                }
-
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-
-        }
-    }
-
-    /**
-     * 消费者5:将专利从队列取出,与专利关联数据入库
-     */
-    public void pushPatentAssoToDB() throws InterruptedException, IOException {
-        while (true) {
-            try {
-                if (patentAssoQueue.isEmpty()) {
-                    if (flag) {
-                        System.out.println("与专利关联的数据全部完成,退出循环");
-                        return;
-                    } else {
-                        patentAssoLock.lock();
-                        patentAssoCondition.await();
-                        patentAssoLock.unlock();
-                    }
-                } else {
-                    QueueData queueData = patentAssoQueue.remove();
-                    //专题库与专利关联入库
-                    uploadPatentToDBService.uploadAssoThemaPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
-                    //自定义字段标引与专利关联入库
-                    uploadPatentToDBService.uploadAssoFieldPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
-                    //文件夹与专利关联入库
-                    uploadPatentToDBService.uploadAssoPorPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
-                    //Websocket发送message:通过WebSocket 在每一次循环结束后 向前端发送完成进度
-                    sendMessage(queueData, queueData.getTask().getTotal(), queueData.getTask());
+                    sendMessage(queueData);
                 }
 
             } catch (Exception e) {
@@ -249,54 +223,55 @@ public class PantentQueueService {
         }
     }
 
-    public void sendMessage(QueueData queueData, Integer total, Task task) {
+    public void sendMessage(QueueData queueData) {
         //每完成一个专利,通过计算,发送进度
         synchronized ("此为同步锁") {
-            //上一个任务的一个消费者结束,开始消费下一个任务的专利,即下一个任务的第一个消费者进来,将当前任务的状态改为4待进行
-//            if (task.getStatus() == 0) {
-//                task.setStatus(4);
-//                taskService.updateById(task);
-//            }
-            Integer currentPatentId = queueData.getUploadParamsVO().getPatent().getId();
-            Integer taskId = task.getId();
-            String currentPatent = taskId + "|" + currentPatentId;
+            //当前进行的任务
+            Task task = queueData.getTask();
+            //当前进行的任务的专利总数量
+            Integer total = task.getTotal();
+
+            //将任务id + "|" + 专利id,拼接成专利的标识(作为当前某一个消费者消费完的这个专利的数量标识)
+            String currentPatent = task.getId() + "|" + queueData.getUploadParamsVO().getPatent().getId();
             Integer num = patentIdMap.get(currentPatent);
             if (num == null) {
                 patentIdMap.put(currentPatent, 1);
-            } else if (num < 4) {
+            } else if (num < 3) {
                 patentIdMap.put(currentPatent, ++num);
             } else {
-                //下一个任务的第5个消费者进来(即表示上一个任务的5个消费者都结束了),就将这个任务的状态正式改为1进行中
+                /*
+                1)若是看当前任务,表示当前这个任务这个专利的4个消费者全都消费结束,即当前这个任务的这个专利已完成
+                2)若是看下一个任务,表示下一个任务的著录项目消费者终于第一次进来了(即表示上一个任务最慢的著录项目消费者也结束了即上一个任务完成了),就将这下一个任务的状态改为 1进行中
+                 */
                 if (task.getStatus() == 0) {
                     task.setStatus(1);
                     task.setStartTime(DateUtils.getDateTime());
                     taskService.updateById(task);
                 }
-                //num达到4了就从patentIdMap中删除
+                //num达到4了就在patentIdMap中将其删除
                 patentIdMap.remove(currentPatent);
                 long percentage = Math.round((task.getSuccessNum() + 1D) / total * 100D);
-                //当全部完成时
-                if (task.getSuccessNum().equals(total)) {
-                    percentage = 100L;
-                }
-                messageService.sendWebsocketMessage(task, total, task.getSuccessNum(), percentage);
-                //任务表更新数据
+                //任务表更新数据(这里只更新成功条数和失败条数,注意不能更新状态等其他信息)
                 task.setSuccessNum(task.getSuccessNum() + 1);
                 task.setDefaultNum(total - task.getSuccessNum());
-                taskService.updateById(task);
+                Task updateTask = new Task();
+                updateTask.setId(task.getId());
+                updateTask.setSuccessNum(task.getSuccessNum());
+                updateTask.setDefaultNum(total - task.getSuccessNum());
+                taskService.updateById(updateTask);
+
                 //当全部完成时
                 if (task.getSuccessNum().equals(total)) {
+                    percentage = 100L;
                     //设置任务状态为成功
                     task.setStatus(2);
                     //设置任务结束时间为当前时间
                     task.setEndTime(DateUtils.getDateTime());
                     taskService.updateById(task);
-//                    //判断若没有进行中的任务则唤醒生产者线程
-//                    List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getStatus, 1));
-//                    if (tasks == null || tasks.size() == 0) {
-//                        awakeTasktch();
-//                    }
                 }
+
+                messageService.sendWebsocketMessage(task, total, task.getSuccessNum(), percentage);
+
             }
         }
     }
@@ -305,44 +280,62 @@ public class PantentQueueService {
         //保存专利基础数据(专利表"os_patent")
         uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
 
-        //专利分别加入5个消费者队列
+
         QueueData queueData = new QueueData()
                 .setTask(task)
                 .setUploadParamsVO(uploadParamsVO)
                 .setProjectImportPatentVO(projectImportPatentVO);
-        patentImageQueue.add(queueData);
-        patentZhuluQueue.add(queueData);
-        patentRightQueue.add(queueData);
-        patentInstructionTextQueue.add(queueData);
-        patentAssoQueue.add(queueData);
+
+        //专利分别加入5个消费者队列
+        patentImageQueueList.add(queueData);
+        patentZhuluQueueList.add(queueData);
+        patentRightQueueList.add(queueData);
+        patentInstructionTextQueueList.add(queueData);
 
         //通知消费者线程(5个消费者:摘要附图、著录项目、权利要求文本、说明书文本、与专利关联数据)
-        //消费者1摘要附图
+        //1.摘要附图
         patentImageLock.lock();
         patentImageCondition.signalAll();
         patentImageLock.unlock();
-        //消费者2著录项目
+        //2.著录项目
         patentZhuluLock.lock();
         patentZhuluCondition.signalAll();
         patentZhuluLock.unlock();
-        //消费者3权利要求文本
+        //3.权利要求文本
         patentRightLock.lock();
         patentRightCondition.signalAll();
         patentRightLock.unlock();
-        //消费者4说明书文本
+        //4.说明书文本
         patentInstructionTextLock.lock();
         patentInstructionTextCondition.signalAll();
         patentInstructionTextLock.unlock();
-        //消费者5与专利关联数据
-        patentAssoLock.lock();
-        patentAssoCondition.signalAll();
-        patentAssoLock.unlock();
     }
 
-    public void queueAddTask(List<Integer> taskQueueList) {
+    /**
+     * 生产者任务队列新增任务ids
+     *
+     * @param taskQueueList 生产者任务队列
+     */
+    public void taskQueueAddTask(List<Integer> taskQueueList) {
         this.taskQueueList.addAll(taskQueueList);
     }
 
+    /**
+     * 消费者专利队列剔除指定任务的所有专利
+     *
+     * @param taskId 任务id
+     */
+    public void consumerQueueDeleteTasks(Integer taskId) {
+        this.patentImageQueueList.removeIf(queueData -> queueData.getTask().getId().equals(taskId));
+        this.patentZhuluQueueList.removeIf(queueData -> queueData.getTask().getId().equals(taskId));
+        this.patentRightQueueList.removeIf(queueData -> queueData.getTask().getId().equals(taskId));
+        this.patentInstructionTextQueueList.removeIf(queueData -> queueData.getTask().getId().equals(taskId));
+        this.patentIdMap.clear();
+    }
+
+    /**
+     * 唤醒生产者线程执
+     */
     public void awakeTasktch() {
         taskLock.lock();
         taskCondition.signalAll();
@@ -369,4 +362,5 @@ public class PantentQueueService {
 
     }
 
+
 }

+ 0 - 34
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/PatentToDbTaskJob.java

@@ -1,34 +0,0 @@
-package cn.cslg.pas.service.upLoadPatent;
-
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.quartz.DisallowConcurrentExecution;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
-import org.springframework.scheduling.quartz.QuartzJobBean;
-
-/**
- * 调度任务类
- */
-@Slf4j
-@DisallowConcurrentExecution
-@RequiredArgsConstructor
-public class PatentToDbTaskJob extends QuartzJobBean {
-
-    @Override
-    public void executeInternal(JobExecutionContext context) throws JobExecutionException {
-        //0.检查全部任务情况
-
-
-        //1.获得任务信息(检查进行中的任务,执行等待中的任务)
-
-
-        //2.根据不同的任务类型,选择不同方法上传任务
-        //2.1 Excel导入专利任务
-        //excuteTaskService.executeExcelTask();
-
-        //2.2 网站导入专利任务
-
-    }
-
-}

+ 2 - 5
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/TaskAddJob.java

@@ -39,11 +39,8 @@ public class TaskAddJob extends QuartzJobBean {
         task.setStatus(0);
         taskService.save(task);
         //任务存入生产者任务队列并唤醒生产者线程(判断若没有进行中的任务则唤醒)
-        pantentQueueService.queueAddTask(Arrays.asList(task.getId()));
-        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getStatus, 1));
-        if (tasks == null || tasks.size() == 0) {
-            pantentQueueService.awakeTasktch();
-        }
+        pantentQueueService.taskQueueAddTask(Arrays.asList(task.getId()));
+        pantentQueueService.awakeTasktch();
         logger.info("添加任务" + "信息是" + task);
     }
 

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 1209
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/UploadFromWebService.java


+ 0 - 30
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/UploadPatentToDBService.java

@@ -3,29 +3,17 @@ package cn.cslg.pas.service.upLoadPatent;
 import cn.cslg.pas.common.core.base.Constants;
 import cn.cslg.pas.common.model.vo.ProjectImportPatentVO;
 import cn.cslg.pas.common.model.vo.UploadParamsVO;
-import cn.cslg.pas.common.model.vo.UploadSettingVO;
-import cn.cslg.pas.common.utils.DateUtils;
-import cn.cslg.pas.common.utils.FileUtils;
-import cn.cslg.pas.common.utils.ReadExcelUtils;
-import cn.cslg.pas.common.utils.UploadPatentBatchUtil;
-import cn.cslg.pas.domain.PatentData;
 import cn.cslg.pas.domain.SystemDict;
 import cn.cslg.pas.service.PatentAgencyService;
 import cn.cslg.pas.service.PatentImageService;
 import cn.cslg.pas.service.SystemDictService;
 import cn.cslg.pas.service.UploadPatentBatchService;
-import cn.hutool.core.util.IdUtil;
 import lombok.RequiredArgsConstructor;
-import org.apache.poi.ss.usermodel.PictureData;
 import org.springframework.stereotype.Service;
 
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 /**
  * 保存专利及所有与之关联数据入库
@@ -55,24 +43,6 @@ public class UploadPatentToDBService {
         }
     }
 
-//    /**
-//     * 法律状态
-//     *
-//     * @param uploadParamsVO 专利内容
-//     */
-//    public void uploadLegalStatus(UploadParamsVO uploadParamsVO) {
-//        //保存法律状态(专利表"os_patent")
-//        if (uploadParamsVO.getPatent() != null) {
-//            List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.PATENT_SIMPLE_STATUS));
-//            Integer simpleStatus = Integer.parseInt(systemDictList.stream()
-//                    .filter(systemDict -> systemDict.getType().equals(Constants.PATENT_SIMPLE_STATUS) && systemDict.getLabel().equals(uploadParamsVO.getPatentSimpleStatus()))
-//                    .findFirst()
-//                    .orElse(new SystemDict()).getValue());
-//            uploadParamsVO.getPatent().setSimpleStatus(simpleStatus);
-//            uploadParamsVO.getPatent().updateById();
-//        }
-//    }
-
     /**
      * 著录项目
      *

+ 4 - 22
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/UploadTaskService.java

@@ -3,35 +3,25 @@ package cn.cslg.pas.service.upLoadPatent;
 import cn.cslg.pas.common.model.PersonnelVO;
 import cn.cslg.pas.common.model.dto.QrtzTaskAddNewDTO;
 import cn.cslg.pas.common.model.dto.UploadFileDTO;
-import cn.cslg.pas.common.model.vo.ProjectImportPatentVO;
 import cn.cslg.pas.common.utils.CacheUtils;
 import cn.cslg.pas.common.utils.FileUtils;
 import cn.cslg.pas.common.utils.ReadExcelUtils;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
 import cn.cslg.pas.common.utils.ThrowException;
 import cn.cslg.pas.domain.SerachBiblioData;
-import cn.cslg.pas.domain.Task;
 import cn.cslg.pas.domain.WebLoginConfig;
 import cn.cslg.pas.domain.asso.AssoOsTaskQrtzTask;
-import cn.cslg.pas.exception.XiaoShiException;
-import cn.cslg.pas.service.IAssoOsTaskQrtzTaskService;
 import cn.cslg.pas.service.TaskService;
 import cn.cslg.pas.service.WebLoginConfigService;
 import cn.cslg.pas.service.asso.AssoOsTaskQrtzTaskService;
-import cn.hutool.core.collection.IterUtil;
-import cn.hutool.poi.excel.ExcelUtil;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 
 /**
  * 导入专利任务的业务层
@@ -46,7 +36,7 @@ public class UploadTaskService {
     private final TaskService taskService;
     private final PantentQueueService pantentQueueService;
     private final AssoOsTaskQrtzTaskService assoOsTaskQrtzTaskService;
-    private final ExcuteTaskToPatentService excuteTaskToPatentService;
+    private final ExcutePatentDataEpo excutePatentDataEpo;
     private final CacheUtils cacheUtils;
     private final LoginUtils loginUtils;
     private final WebLoginConfigService webLoginConfigService;
@@ -67,7 +57,7 @@ public class UploadTaskService {
         //新增任务(专利导入导出任务表)
         Integer taskId = taskService.addTask2(fileDTO, total, json);
         //任务存入生产者任务队列并唤醒生产者线程
-        pantentQueueService.queueAddTask(Arrays.asList(taskId));
+        pantentQueueService.taskQueueAddTask(Arrays.asList(taskId));
         pantentQueueService.awakeTasktch();
     }
 
@@ -87,7 +77,7 @@ public class UploadTaskService {
 
         //检查任务合法性(检查当前检索式能否检索出专利)
         //根据检索式conditions检索一件专利著录信息
-        SerachBiblioData serachBiblioData = excuteTaskToPatentService.getSerachBiblioData(qrtzTaskAddNewDTO.getConditions(), 1, 1);
+        SerachBiblioData serachBiblioData = excutePatentDataEpo.getSerachBiblioData(qrtzTaskAddNewDTO.getConditions(), 1, 1);
         if (serachBiblioData == null || serachBiblioData.getTotals() == 0) {
             ThrowException.throwXiaoShiException("根据检索信息未检索到相关专利,请尝试更换检索信息");
         }
@@ -117,18 +107,10 @@ public class UploadTaskService {
         assoOsTaskQrtzTaskService.updateById(assoOsTaskQrtzTask);
 
         //任务存入生产者任务队列并唤醒生产者线程
-        pantentQueueService.queueAddTask(Arrays.asList(taskId));
+        pantentQueueService.taskQueueAddTask(Arrays.asList(taskId));
         pantentQueueService.awakeTasktch();
 
         return assoOsTaskQrtzTask;
     }
 
-    public void pauseTask() {
-
-    }
-
-    public void deleteTask() {
-    }
-
-
 }