chendayu %!s(int64=2) %!d(string=hai) anos
pai
achega
2da8dee5ec

+ 39 - 11
PAS/src/main/java/cn/cslg/pas/common/core/CreateTaskThread.java

@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Component;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -27,28 +28,55 @@ public class CreateTaskThread implements InitializingBean {
 
     private final TaskService taskService;
     private final PantentQueueService pantentQueueService;
+
     @Override
     public void afterPropertiesSet() throws Exception {
         //初始化任务列表数据(taskQueueList)
         //查找任务状态为0(队列中)和1(进行中)的任务
         List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().in(Task::getStatus, new ArrayList<>(Arrays.asList(0, 1))));
-        List<Integer> taskIds = tasks.stream().map(Task::getId).collect(Collectors.toList());
-        //将任务ids存入 taskQueueList
-        pantentQueueService.queueAddTask(taskIds);
-        //一个线程执行解析专利并入队列
-        Thread thread1 = new Thread(() -> {
+        if (tasks.size() > 0) {
+            List<Integer> taskIds = tasks.stream().map(Task::getId).collect(Collectors.toList());
+            //将任务ids存入 taskQueueList
+            pantentQueueService.queueAddTask(taskIds);
+        }
+
+        //一个线程执行生产者
+        Thread threadProducer = new Thread(() -> {
             pantentQueueService.addPatnetToQueue();
         });
-       thread1.start();
-        //一个线程执行保存专利并出队列
-        Thread thread2 = new Thread(() -> {
+        threadProducer.start();
+
+        //一个线程执行消费者1(将专利信息从队列取出,摘要附图和著录项目入库)
+        Thread threadConsumer1 = new Thread(() -> {
+            try {
+                pantentQueueService.pushPatentImageZhuluToDB();
+            } catch (InterruptedException | IOException e) {
+                e.printStackTrace();
+            }
+        });
+        threadConsumer1.start();
+
+        //一个线程执行消费者2(将专利信息从队列取出,说明书和权要入库)
+        Thread threadConsumer2 = new Thread(() -> {
             try {
-                pantentQueueService.pushPantentToDb();
-            } catch (InterruptedException e) {
+                pantentQueueService.pushPatentRightInstructionTextToDB();
+            } catch (InterruptedException | IOException e) {
                 e.printStackTrace();
             }
         });
-        thread2.start();
+        threadConsumer2.start();
+
+        //一个线程执行消费者3(将专利信息从队列取出,与专利关联的数据入库)
+        Thread threadConsumer3 = new Thread(() -> {
+            try {
+                pantentQueueService.pushPatentAssoToDB();
+            } catch (InterruptedException | IOException e) {
+                e.printStackTrace();
+            }
+        });
+        threadConsumer3.start();
+
+
     }
 
 }

+ 3 - 0
PAS/src/main/java/cn/cslg/pas/common/model/vo/ProjectImportPatentVO.java

@@ -5,6 +5,9 @@ import lombok.experimental.Accessors;
 
 import java.util.List;
 
+/**
+ * 前台参数实体类
+ */
 @Accessors(chain = true)
 @Data
 public class ProjectImportPatentVO {

+ 29 - 30
PAS/src/main/java/cn/cslg/pas/common/utils/ReadExcelUtils.java

@@ -82,7 +82,7 @@ public class ReadExcelUtils {
      * @param row      行数
      * @return 返回装载专利数据(专利内容数据 + 摘要附图)的对象
      */
-    public static PatentData readExcelOneRow(String filePath, Integer row) {
+    public static PatentData readExcelOneRow(String filePath, Sheet sheet, int row) throws IOException {
         //返回最终结果的对象
         PatentData patentData = new PatentData();
         //装载专利数据(除了摘要附图)的map:(key:表头如 "公开(公告)号"  value:表头对应内容如 "CN1307082B")
@@ -90,6 +90,32 @@ public class ReadExcelUtils {
         //装载摘要附图的对象
         PictureData pictureData = null;
 
+        //开始装载专利数据
+        Row firstRow = sheet.getRow(0);
+        Row needRow = sheet.getRow(row);
+        //读取第一行的时候会多读一列
+        int firstColumns = firstRow.getLastCellNum() - 0;
+        for (int i = 0; i < firstColumns; i++) {
+            map.put(firstRow.getCell(i) + "", needRow.getCell(i) + "");
+        }
+
+        //开始装载专利摘要附图(判断用07还是03的方法获取图片)
+        if (filePath.endsWith(".xls") || filePath.endsWith(".XLS")) {
+            pictureData = getPictures1((HSSFSheet) sheet, row);
+        } else if (filePath.endsWith(".xlsx") || filePath.endsWith(".XLSX")) {
+            pictureData = getPictures2((XSSFSheet) sheet, row);
+        }
+
+        //返回结果对象装载结果
+        patentData.setMap(map);
+        patentData.setPictureData(pictureData);
+
+        return patentData;
+    }
+
+    public static Sheet readExcel(String filePath) {
+        Sheet sheet = null;
+
         File file = new File(filePath);
         try {
             InputStream inputStream = new FileInputStream(file);
@@ -103,39 +129,12 @@ public class ReadExcelUtils {
             }
 
             //读取第几个sheet
-            Sheet sheet = workbook.getSheetAt(0);
-            //读取总行数
-            int rows = sheet.getPhysicalNumberOfRows();
-            if (rows <= row) {
-                ThrowException.throwXiaoShiException("row超出Excel文档中数量");
-            }
-
-            //开始装载专利数据
-            Row firstRow = sheet.getRow(0);
-            Row needRow = sheet.getRow(row);
-            //读取第一行的时候会多读一列
-            int firstColumns = firstRow.getLastCellNum() - 0;
-            for (int i = 0; i < firstColumns; i++) {
-                map.put(firstRow.getCell(i) + "", needRow.getCell(i) + "");
-            }
-
-            //开始装载专利摘要附图(判断用07还是03的方法获取图片)
-            if (filePath.endsWith(".xls") || filePath.endsWith(".XLS")) {
-                pictureData = getPictures1((HSSFSheet) sheet, row);
-            } else if (filePath.endsWith(".xlsx") || filePath.endsWith(".XLSX")) {
-                pictureData = getPictures2((XSSFSheet) sheet, row);
-            }
-            workbook.close();
-
-            //返回结果对象装载结果
-            patentData.setMap(map);
-            patentData.setPictureData(pictureData);
-
+            sheet = workbook.getSheetAt(0);
         } catch (IOException e) {
             e.printStackTrace();
         }
 
-        return patentData;
+        return sheet;
     }
 
     /**

+ 28 - 0
PAS/src/main/java/cn/cslg/pas/domain/QueueData.java

@@ -0,0 +1,28 @@
+package cn.cslg.pas.domain;
+
+import cn.cslg.pas.common.model.vo.ProjectImportPatentVO;
+import cn.cslg.pas.common.model.vo.UploadParamsVO;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+/**
+ * 队列实体类,存放专利实体类和前台参数实体类
+ *
+ * @Author chenyu
+ * @Date 2023/6/5
+ */
+@Accessors(chain = true)
+@Data
+public class QueueData implements Serializable {
+    /**
+     * 专利实体类
+     */
+    private UploadParamsVO uploadParamsVO;
+    /**
+     * 前台参数实体类
+     */
+    private ProjectImportPatentVO projectImportPatentVO;
+
+}

+ 15 - 4
PAS/src/main/java/cn/cslg/pas/domain/Task.java

@@ -20,6 +20,7 @@ public class Task extends BaseEntity<Task> {
     /**
      * 任务类型 1.上传,2导出
      */
+    @TableField("type")
     private Integer type;
 
     /**
@@ -79,17 +80,17 @@ public class Task extends BaseEntity<Task> {
      * 成功条数
      */
     @TableField("success_num")
-    private Long successNum;
+    private Integer successNum;
     /**
      * 失败条数
      */
     @TableField("default_num")
-    private Long defaultNum;
+    private Integer defaultNum;
     /**
-     *
+     * 前台参数json格式
      */
     @TableField("pram_json")
-    private Long pram_json;
+    private String pramJson;
     /**
      * 导入详细excel连接
      */
@@ -98,6 +99,10 @@ public class Task extends BaseEntity<Task> {
 
     @TableField("product_id")
     private Integer productId;
+    /**
+     * Excel文件原名称
+     */
+    @TableField("old_name")
     private String oldName;
 
     @TableField(exist = false)
@@ -105,4 +110,10 @@ public class Task extends BaseEntity<Task> {
 
     @TableField(exist = false)
     private String projectName;
+    /**
+     * 上一次的位置(代表保存到第几个专利)
+     */
+    @TableField(exist = false)
+    private Integer lastIndex;
+
 }

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

@@ -3,17 +3,15 @@ package cn.cslg.pas.service;
 import cn.cslg.pas.common.core.base.Constants;
 import cn.cslg.pas.common.model.dto.ClientDTO;
 import cn.cslg.pas.common.model.vo.ProductVO;
+import cn.cslg.pas.common.model.vo.ProjectImportPatentVO;
 import cn.cslg.pas.common.model.vo.ProjectVO;
+import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
-import cn.cslg.pas.common.utils.StringUtils;
 import cn.cslg.pas.domain.Project;
 import cn.cslg.pas.domain.SystemDict;
 import cn.cslg.pas.domain.Task;
 import cn.cslg.pas.common.model.vo.TaskVO;
 import cn.cslg.pas.mapper.TaskMapper;
-import cn.cslg.pas.common.utils.DateUtils;
-import cn.cslg.pas.common.utils.FileUtils;
-import cn.cslg.pas.common.utils.Response;
 import cn.cslg.pas.common.model.dto.UploadFileDTO;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.io.FileUtil;
@@ -27,6 +25,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -94,6 +93,56 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> {
         return task.getId();
     }
 
+    /**
+     * 新增导入专利任务
+     *
+     * @param fileDTO Excel文件
+     * @param json    前台参数
+     * @return 返回任务id
+     */
+    public Integer addTask2(UploadFileDTO fileDTO, Integer total, String json) {
+        //将前台参数json格式转换为实体类(从中取出专题库id存入任务表)
+        ProjectImportPatentVO projectImportPatentVO = JsonUtils.jsonToPojo(json, ProjectImportPatentVO.class);
+
+        //创建任务表实体类,准备装载数据 ↓
+        Task task = new Task();
+
+        //任务开始时间
+        task.setStartTime(DateUtils.getDateTime());
+        //任务状态(0.队列中 1.进行中 2.成功 3.失败)
+        task.setStatus(0);
+        if (projectImportPatentVO.getProjectId() != null) {
+            //专题库id
+            task.setProjectId(projectImportPatentVO.getProjectId());
+        }
+        //文件名称
+        task.setFileName(fileDTO.getFileName());
+        //文件路径
+        task.setUrl(fileDTO.getPath());
+        //文件的专利总数量
+        task.setTotal(total);
+        //文件大小
+        task.setFileSize(fileDTO.getFileSize());
+        //任务类型 (1.上传 2导出)
+        task.setType(1);
+        //导入导出字段数量
+        task.setFieldNum(0);
+        //创建人id
+        task.setCreateBy(loginUtils.getId());
+        //文件原始名称
+        task.setOldName(fileDTO.getName());
+        //成功条数
+        task.setSuccessNum(0);
+        //失败条数
+        task.setDefaultNum(0);
+        //前台参数json格式
+        task.setPramJson(json);
+
+        //数据入任务表
+        task.insert();
+        return task.getId();
+    }
+
     public Task edit(Integer id, Integer status) {
         Task task = this.getById(id);
         task.setStatus(status);

+ 1 - 1
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/MessageService.java

@@ -33,7 +33,7 @@ public class MessageService {
                 .setTaskId(task.getId())
                 .setProjectId(task.getProjectId())
                 .setComplete(false)
-                .setIndex(i - 1)
+                .setIndex(i)
                 .setTaskType(Constants.TASK_IMPORT_PATENT)
                 .setPercentage(percentage)
                 .setFileName("")

+ 195 - 57
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/PantentQueueService.java

@@ -1,24 +1,35 @@
 package cn.cslg.pas.service.upLoadPatent;
 
+import cn.cslg.pas.common.model.dto.UploadFileDTO;
+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.ExcelUtils;
+import cn.cslg.pas.common.utils.FileUtils;
+import cn.cslg.pas.common.utils.JsonUtils;
 import cn.cslg.pas.common.utils.ReadExcelUtils;
 import cn.cslg.pas.domain.PatentData;
+import cn.cslg.pas.domain.QueueData;
 import cn.cslg.pas.domain.Task;
 import cn.cslg.pas.service.TaskService;
+import cn.cslg.pas.service.UploadPatentBatchService;
+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.apache.poi.ss.usermodel.PictureData;
+import org.apache.poi.ss.usermodel.Sheet;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
+import java.io.IOException;
+import java.util.*;
 import java.util.concurrent.CountDownLatch;
 
+import static org.apache.poi.ss.usermodel.TableStyleType.totalRow;
+
 /**
  * 将专利信息存入队列或从队列取出
  *
@@ -30,90 +41,217 @@ import java.util.concurrent.CountDownLatch;
 public class PantentQueueService {
     private final ExcuteDataToVOService excuteDataToVOService;
     private final ExcuteUploadSettingService excuteUploadSettingService;
-    private final  MessageService messageService;
-    private final  TaskService taskService;
-    private Queue<UploadParamsVO> queue = new LinkedList<>();
-    private  List<Integer> taskQueueList = new ArrayList<>();
+    private final UploadPatentToDBService uploadPatentToDBService;
+    private final UploadPatentBatchService uploadPatentBatchService;
+    private final FileUtils fileUtils;
+    private final MessageService messageService;
+    private final TaskService taskService;
+    private Queue<QueueData> patentImageZhuluQueue = new LinkedList<>();
+    private Queue<QueueData> patentRightInstructionTextQueue = new LinkedList<>();
+    private Queue<QueueData> patentAssoQueue = new LinkedList<>();
+    private List<Integer> taskQueueList = new ArrayList<>();
     private Boolean flag = false;
-    private CountDownLatch patentLatch = new CountDownLatch(1);
     private CountDownLatch taskLatch = new CountDownLatch(1);
+    private CountDownLatch patentImageZhuluLatch = new CountDownLatch(1);
+    private CountDownLatch patentRightInstructionTextLatch = new CountDownLatch(1);
+    private CountDownLatch patentAssoLatch = new CountDownLatch(1);
+
     //将专利信息存入队列
     public void addPatnetToQueue() {
+        Task task = null;
         try {
-         while (true){
-            //检查任务队列
-            if (taskQueueList.size() == 0) {
-                taskLatch.await();
-            }
-            //查找 taskQueueList 中有没有进行中的任务
-            long count = taskService.count(new LambdaQueryWrapper<Task>().in(Task::getId, taskQueueList).eq(Task::getStatus, 1));
-            //若没有,则取出第一个队列中的任务开始执行
-            Task task = null;
-            if (count == 0) {
+            while (true) {
+                //检查任务队列
+                if (taskQueueList.size() == 0) {
+                    taskLatch.await();
+                }
+
+                //1.从taskQueueList中取出第一个taskId,并将其从taskQueueList中删除
                 task = taskService.getById(taskQueueList.get(0));
-                //任务队列去除该任务
                 taskQueueList.remove(0);
-                //修改该任务状态,改为进行中
-                Task currentTask = new Task();
-                currentTask.setId(task.getId());
-                currentTask.setStatus(1);
-                taskService.updateById(currentTask);
-            }
-            //获得文件路径
-            String filePath = task.getUrl();
-            //检查文件合法性
-            Integer totalRow = ReadExcelUtils.textExcel(filePath);
-            //调用解析数据类,根据数据来源id(如1:智慧芽)解析数据源配置文件信息
-            List<UploadSettingVO.Column> jsonData = excuteUploadSettingService.ExcuteUploadSetting(1 + "");
-            //遍历专利总数量,在循环中保存专利
-            for (int i = 1; i <= totalRow; i++) {
-                //解析读取一行专利
-                PatentData patentData = ReadExcelUtils.readExcelOneRow(filePath, i);
-                //调用装载数据类,专利数据转换为VO对象
-                UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
-                //一个专利加入队列
-                queue.add(uploadParamsVO);
-                //通知消费者线程
-                patentLatch.countDown();
-                //Websocket发送message:通过WebSocket 在每一次循环结束后 向前端发送完成进度
-                Long percentage = totalRow == 0 ? 0 : Math.round((totalRow.equals(i) ? (i * 1D) : (i + 1D)) / totalRow * 100D);
-                messageService.sendWebsocketMessage(task, totalRow, i, percentage);
+                //获得Excel文件路径
+                String filePath = task.getUrl();  //相对路径
+                filePath = fileUtils.getPath(filePath);  //绝对路径
+
+                //List<List<Object>> rowList = new ArrayList<>();
+                //List<Map<Object, Object>> mapList = new ArrayList<>();
+                //解析Excel获取所有行数据 rowList
+                //ExcelUtil.readBySax(filePath, -1, (sheetIndex, rowIndex, row) -> rowList.add(row));
+                //遍历 rowList,将第一行即表头作为key,其余行即专利内容作为value添加进map集合 mapList
+                //for (int i = 1; i < rowList.size(); i++) {
+                //    mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i)));
+                //}
+                //解析Excel获取所有摘要附图
+                //Map<String, PictureData> pictureDataMap = ExcelUtils.getDataFromExcel(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);
+                int total = sheet.getPhysicalNumberOfRows() - 1;
+
+                //遍历专利总数量,在循环中保存专利
+                for (int i = lastIndex; i < total; i++) {
+                    //解析读取一行专利
+                    //PatentData patentData = ReadExcelUtils.readExcelOneRow(filePath, i);
+                    //PatentData patentData = new PatentData()
+                    //        .setMap(mapList.get(i))
+                    //        .setPictureData(pictureDataMap.get(String.valueOf(i + 1)));
+                    PatentData patentData = ReadExcelUtils.readExcelOneRow(filePath, sheet, i);
+                    //patentData.setPictureData(pictureDataMap.get(String.valueOf(i + 1)));
+                    //调用装载数据类,专利数据转换为VO对象
+                    UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
+
+                    //保存专利基础数据(专利表"os_patent")
+                    uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
+
+                    //专利分别加入三个消费者队列
+                    QueueData queueData = new QueueData()
+                            .setUploadParamsVO(uploadParamsVO)
+                            .setProjectImportPatentVO(projectImportPatentVO);
+                    patentImageZhuluQueue.add(queueData);
+                    patentRightInstructionTextQueue.add(queueData);
+                    patentAssoQueue.add(queueData);
+
+                    //通知消费者线程(三个消费者:保存摘要附图和著录、保存说明书和权要、保存专题库关联专利数据)
+                    //保存摘要附图和著录消费者
+                    patentImageZhuluLatch.countDown();
+                    //保存说明书和权要消费者
+                    patentRightInstructionTextLatch.countDown();
+                    //保存专题库关联专利数据消费者
+                    patentAssoLatch.countDown();
+
+                    //任务表更新数据
+                    //上一次的位置(保存到第几个专利)
+                    task.setLastIndex(i);
+                    //成功条数
+                    task.setSuccessNum(i);
+                    //失败条数
+                    task.setDefaultNum(total - i);
+                    taskService.updateById(task);
+
+                    //Websocket发送message:通过WebSocket 在每一次循环结束后 向前端发送完成进度
+                    Long percentage = total == 0 ? 0 : Math.round((total == i ? (i * 1D) : (i + 1D)) / total * 100D);
+                    messageService.sendWebsocketMessage(task, total, i, percentage);
+                }
+                //全部循环结束后,发送进度
+                Long percentage = 100L;
+                messageService.sendWebsocketMessage(task, total, total, percentage);
+
+                //任务表更新数据
+                task.setStatus(2);
+                taskService.updateById(task);
             }
-            //全部循环结束后,发送进度
-            Long percentage = 100L;
-            messageService.sendWebsocketMessage(task, totalRow, totalRow, percentage);
-        }
+
         } catch (Exception e) {
             e.printStackTrace();
+            //修改任务状态为失败
+            task.setStatus(3);
+            taskService.updateById(task);
         } finally {
         }
         flag = true;
     }
-    //将专利信息从队列取出
-    public void pushPantentToDb() throws InterruptedException {
+
+    /**
+     * 将专利信息从队列取出,摘要附图和著录项目入库
+     */
+    public void pushPatentImageZhuluToDB() throws InterruptedException, IOException {
         try {
             while (true) {
-                if (queue.isEmpty()) {
+                if (patentImageZhuluQueue.isEmpty()) {
                     if (flag) {
                         System.out.println("退出循环");
                         return;
                     } else {
-                        patentLatch.await();
+                        patentImageZhuluLatch.await();
                     }
                 } else {
-                    UploadParamsVO uploadParamsVO = queue.remove();
-                    System.out.println("出队列" + uploadParamsVO);
+                    System.out.println("开始保存摘要附图和著录项目");
+                    QueueData queueData = patentImageZhuluQueue.remove();
+                    //摘要附图入库
+                    uploadPatentToDBService.uploadPatentImage(queueData.getUploadParamsVO());
+                    //著录项目入库
+                    uploadPatentToDBService.uploadPatentZhulu(queueData.getUploadParamsVO());
+                    System.out.println("出队列");
                 }
             }
         } finally {
 
         }
     }
+
+    /**
+     * 将专利信息从队列取出,说明书和权要入库
+     */
+    public void pushPatentRightInstructionTextToDB() throws InterruptedException, IOException {
+        try {
+            while (true) {
+                if (patentRightInstructionTextQueue.isEmpty()) {
+                    if (flag) {
+                        System.out.println("退出循环");
+                        return;
+                    } else {
+                        patentRightInstructionTextLatch.await();
+                    }
+                } else {
+                    System.out.println("开始保存说明书和权要");
+                    QueueData queueData = patentRightInstructionTextQueue.remove();
+                    //说明书入库
+                    uploadPatentToDBService.uploadPatentInstructionText(queueData.getUploadParamsVO());
+                    //权要入库
+                    uploadPatentToDBService.uploadPatentRight(queueData.getUploadParamsVO());
+
+                    System.out.println("出队列");
+                }
+            }
+        } finally {
+
+        }
+    }
+
+    /**
+     * 将专利信息从队列取出,与专利关联的数据入库
+     */
+    public void pushPatentAssoToDB() throws InterruptedException, IOException {
+        try {
+            while (true) {
+                if (patentAssoQueue.isEmpty()) {
+                    if (flag) {
+                        System.out.println("退出循环");
+                        return;
+                    } else {
+                        patentAssoLatch.await();
+                    }
+                } else {
+                    System.out.println("开始保存与专利关联的数据");
+                    QueueData queueData = patentAssoQueue.remove();
+                    //专题库与专利关联入库
+                    uploadPatentToDBService.uploadAssoThemaPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
+                    //自定义字段标引与专利关联入库
+                    uploadPatentToDBService.uploadAssoFieldPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
+                    //文件夹与专利关联入库
+                    uploadPatentToDBService.uploadAssoPorPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
+
+                    System.out.println("出队列");
+                }
+            }
+        } finally {
+
+        }
+    }
+
     public void queueAddTask(List<Integer> taskQueueList) {
         this.taskQueueList.addAll(taskQueueList);
     }
-    public void awakeTasktch(){
-       this.taskLatch.countDown();
+
+    public void awakeTasktch() {
+        this.taskLatch.countDown();
 
     }
 }

+ 10 - 23
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/UploadPatentToDBService.java

@@ -48,46 +48,33 @@ public class UploadPatentToDBService {
      * @param projectImportPatentVO 专题库专利关联数据实体类(专题库id、数据来源id、自定义字段、文件夹)
      */
     public void uploadPatentToDB(UploadParamsVO uploadParamsVO, ProjectImportPatentVO projectImportPatentVO) throws IOException {
-        //基础数据入库(取专利id)
-        uploadPatentBase(uploadParamsVO);
         //摘要附图入库
-        uploadPatentImage(uploadParamsVO, uploadParamsVO.getPictureData());
+        //uploadPatentImage(uploadParamsVO, uploadParamsVO.getPictureData());
         //著录项目入库
-        uploadPatentZhulu(uploadParamsVO);
+        //uploadPatentZhulu(uploadParamsVO);
         //说明书文本入库
-        uploadPatentInstructionText(uploadParamsVO);
+        //uploadPatentInstructionText(uploadParamsVO);
         //权要入库
-        uploadPatentRight(uploadParamsVO);
+        //uploadPatentRight(uploadParamsVO);
         //专题库与专利关联入库
-        uploadAssoThemaPat(uploadParamsVO, projectImportPatentVO);
+        //uploadAssoThemaPat(uploadParamsVO, projectImportPatentVO);
         //自定义字段标引与专利关联入库
-        uploadAssoFieldPat(uploadParamsVO, projectImportPatentVO);
+        //uploadAssoFieldPat(uploadParamsVO, projectImportPatentVO);
         //文件夹与专利关联入库
-        uploadAssoPorPat(uploadParamsVO, projectImportPatentVO);
+        //uploadAssoPorPat(uploadParamsVO, projectImportPatentVO);
 
     }
 
     /**
-     * 基础数据入库
-     *
-     * @param uploadParamsVO 专利内容实体类对象
-     */
-    public void uploadPatentBase(UploadParamsVO uploadParamsVO) {
-        //保存专利基础数据(专利表"os_patent")
-        uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
-    }
-
-    /**
      * 摘要附图入库
      *
      * @param uploadParamsVO 专利内容实体类对象
-     * @param pictureData    摘要附图
      */
-    public void uploadPatentImage(UploadParamsVO uploadParamsVO, PictureData pictureData) throws IOException {
+    public void uploadPatentImage(UploadParamsVO uploadParamsVO) throws IOException {
         //摘要附图数据装配及入库(摘要附图表"os_patent_img")
         if (uploadParamsVO.getPatent() != null) {
-            if (uploadParamsVO.getPatent().getId() != null && pictureData != null) {
-                uploadParamsVO.getPatent().setAbstractPath(patentImageService.updatePatentImage(uploadParamsVO.getPatent().getId(), pictureData));
+            if (uploadParamsVO.getPatent().getId() != null && uploadParamsVO.getPictureData() != null) {
+                uploadParamsVO.getPatent().setAbstractPath(patentImageService.updatePatentImage(uploadParamsVO.getPatent().getId(), uploadParamsVO.getPictureData()));
             }
         }
     }

+ 3 - 2
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/UploadTaskService.java

@@ -35,7 +35,7 @@ public class UploadTaskService {
     /**
      * 添加导入任务
      */
-    public void addTask(MultipartFile file, ProjectImportPatentVO projectImportPatentVO) throws IOException {
+    public void addTask(MultipartFile file, String json) throws IOException {
         //将包含多件专利的Excel文件上传至本地,并返回文件对象fileDTO
         UploadFileDTO fileDTO = fileUtils.uploadFile(file);
         //获得文件路径
@@ -43,7 +43,8 @@ public class UploadTaskService {
         //获取专利总数量
         Integer total = ReadExcelUtils.textExcel(filePath);
         //新增任务(专利导入导出任务表)
-        Integer taskId = taskService.add(fileDTO, projectImportPatentVO.getProjectId(), null, total, 1, 0, file.getOriginalFilename());
+        //Integer taskId = taskService.add(fileDTO, projectImportPatentVO.getProjectId(), null, total, 1, 0, file.getOriginalFilename());
+        Integer taskId = taskService.addTask2(fileDTO, total, json);
         pantentQueueService.queueAddTask(Arrays.asList(taskId));
         pantentQueueService.awakeTasktch();
     }