|
@@ -1,10 +1,8 @@
|
|
package cn.cslg.pas.service.upLoadPatent;
|
|
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.ProjectImportPatentVO;
|
|
import cn.cslg.pas.common.model.vo.UploadParamsVO;
|
|
import cn.cslg.pas.common.model.vo.UploadParamsVO;
|
|
import cn.cslg.pas.common.model.vo.UploadSettingVO;
|
|
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.FileUtils;
|
|
import cn.cslg.pas.common.utils.JsonUtils;
|
|
import cn.cslg.pas.common.utils.JsonUtils;
|
|
import cn.cslg.pas.common.utils.ReadExcelUtils;
|
|
import cn.cslg.pas.common.utils.ReadExcelUtils;
|
|
@@ -13,29 +11,20 @@ import cn.cslg.pas.domain.QueueData;
|
|
import cn.cslg.pas.domain.Task;
|
|
import cn.cslg.pas.domain.Task;
|
|
import cn.cslg.pas.service.TaskService;
|
|
import cn.cslg.pas.service.TaskService;
|
|
import cn.cslg.pas.service.UploadPatentBatchService;
|
|
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 lombok.RequiredArgsConstructor;
|
|
-import org.apache.poi.ss.usermodel.PictureData;
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
-import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
-import java.util.concurrent.CountDownLatch;
|
|
|
|
-
|
|
|
|
-import static org.apache.poi.ss.usermodel.TableStyleType.totalRow;
|
|
|
|
|
|
+import java.util.concurrent.locks.Condition;
|
|
|
|
+import java.util.concurrent.locks.Lock;
|
|
|
|
+import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 将专利信息存入队列或从队列取出
|
|
* 将专利信息存入队列或从队列取出
|
|
- *
|
|
|
|
- * @author 李仁杰
|
|
|
|
*/
|
|
*/
|
|
-
|
|
|
|
@Service
|
|
@Service
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
public class PantentQueueService {
|
|
public class PantentQueueService {
|
|
@@ -51,65 +40,50 @@ public class PantentQueueService {
|
|
private Queue<QueueData> patentAssoQueue = new LinkedList<>();
|
|
private Queue<QueueData> patentAssoQueue = new LinkedList<>();
|
|
private List<Integer> taskQueueList = new ArrayList<>();
|
|
private List<Integer> taskQueueList = new ArrayList<>();
|
|
private Boolean flag = false;
|
|
private Boolean flag = false;
|
|
- private CountDownLatch taskLatch = new CountDownLatch(1);
|
|
|
|
- private CountDownLatch patentImageZhuluLatch = new CountDownLatch(1);
|
|
|
|
- private CountDownLatch patentRightInstructionTextLatch = new CountDownLatch(1);
|
|
|
|
- private CountDownLatch patentAssoLatch = new CountDownLatch(1);
|
|
|
|
|
|
+ private Lock taskLock = new ReentrantLock();
|
|
|
|
+ private Lock patentImageZhuluLock = new ReentrantLock();
|
|
|
|
+ private Lock patentRightInstructionTextLock = new ReentrantLock();
|
|
|
|
+ private Lock patentAssoLock = new ReentrantLock();
|
|
|
|
+ Condition taskCondition = taskLock.newCondition();
|
|
|
|
+ private Condition patentImageZhuluCondition = patentImageZhuluLock.newCondition();
|
|
|
|
+ private Condition patentRightInstructionTextCondition = patentRightInstructionTextLock.newCondition();
|
|
|
|
+ private Condition patentAssoCondition = patentAssoLock.newCondition();
|
|
|
|
+ private HashMap<Integer, Integer> patentIdMap = new HashMap<>();
|
|
|
|
+ private Task task = null;
|
|
|
|
+ private Integer patentFinishNum = 0;
|
|
|
|
|
|
//将专利信息存入队列
|
|
//将专利信息存入队列
|
|
public void addPatnetToQueue() {
|
|
public void addPatnetToQueue() {
|
|
- Task task = null;
|
|
|
|
try {
|
|
try {
|
|
while (true) {
|
|
while (true) {
|
|
//检查任务队列
|
|
//检查任务队列
|
|
if (taskQueueList.size() == 0) {
|
|
if (taskQueueList.size() == 0) {
|
|
- taskLatch.await();
|
|
|
|
|
|
+ taskLock.lock();
|
|
|
|
+ taskCondition.await();
|
|
}
|
|
}
|
|
-
|
|
|
|
- //1.从taskQueueList中取出第一个taskId,并将其从taskQueueList中删除
|
|
|
|
|
|
+ //1.从taskQueueList中取出第一个task,并将其从taskQueueList中删除
|
|
task = taskService.getById(taskQueueList.get(0));
|
|
task = taskService.getById(taskQueueList.get(0));
|
|
taskQueueList.remove(0);
|
|
taskQueueList.remove(0);
|
|
- //获得Excel文件路径
|
|
|
|
|
|
+ //从任务数据中取出文件路径、总条数、成功条数、前台参数json
|
|
String filePath = task.getUrl(); //相对路径
|
|
String filePath = task.getUrl(); //相对路径
|
|
filePath = fileUtils.getPath(filePath); //绝对路径
|
|
filePath = fileUtils.getPath(filePath); //绝对路径
|
|
|
|
+ Integer total = task.getTotal();
|
|
|
|
+ patentIdMap.put(0, total);
|
|
|
|
|
|
- //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();
|
|
int lastIndex = task.getSuccessNum();
|
|
String json = task.getPramJson();
|
|
String json = task.getPramJson();
|
|
ProjectImportPatentVO projectImportPatentVO = JsonUtils.jsonToPojo(json, ProjectImportPatentVO.class);
|
|
ProjectImportPatentVO projectImportPatentVO = JsonUtils.jsonToPojo(json, ProjectImportPatentVO.class);
|
|
//解析数据源类,通过数据来源id(如1:智慧芽)解析数据源配置文件,获得数据源配置文件对象jsonData
|
|
//解析数据源类,通过数据来源id(如1:智慧芽)解析数据源配置文件,获得数据源配置文件对象jsonData
|
|
List<UploadSettingVO.Column> jsonData = excuteUploadSettingService.ExcuteUploadSetting(projectImportPatentVO.getSourceId());
|
|
List<UploadSettingVO.Column> jsonData = excuteUploadSettingService.ExcuteUploadSetting(projectImportPatentVO.getSourceId());
|
|
-
|
|
|
|
- //解析Excel文件获得工作簿,并取出工作簿总行数作为专利数量
|
|
|
|
|
|
+ //解析Excel文件获得工作簿
|
|
Sheet sheet = ReadExcelUtils.readExcel(filePath);
|
|
Sheet sheet = ReadExcelUtils.readExcel(filePath);
|
|
- int total = sheet.getPhysicalNumberOfRows() - 1;
|
|
|
|
-
|
|
|
|
//遍历专利总数量,在循环中保存专利
|
|
//遍历专利总数量,在循环中保存专利
|
|
for (int i = lastIndex; i < total; i++) {
|
|
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)));
|
|
|
|
|
|
+ PatentData patentData = ReadExcelUtils.readExcelOneRow(filePath, sheet, i + 1);
|
|
//调用装载数据类,专利数据转换为VO对象
|
|
//调用装载数据类,专利数据转换为VO对象
|
|
UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
|
|
UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
|
|
-
|
|
|
|
//保存专利基础数据(专利表"os_patent")
|
|
//保存专利基础数据(专利表"os_patent")
|
|
uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
|
|
uploadPatentBatchService.getOneOrInsertOne(uploadParamsVO);
|
|
-
|
|
|
|
//专利分别加入三个消费者队列
|
|
//专利分别加入三个消费者队列
|
|
QueueData queueData = new QueueData()
|
|
QueueData queueData = new QueueData()
|
|
.setUploadParamsVO(uploadParamsVO)
|
|
.setUploadParamsVO(uploadParamsVO)
|
|
@@ -117,31 +91,25 @@ public class PantentQueueService {
|
|
patentImageZhuluQueue.add(queueData);
|
|
patentImageZhuluQueue.add(queueData);
|
|
patentRightInstructionTextQueue.add(queueData);
|
|
patentRightInstructionTextQueue.add(queueData);
|
|
patentAssoQueue.add(queueData);
|
|
patentAssoQueue.add(queueData);
|
|
-
|
|
|
|
//通知消费者线程(三个消费者:保存摘要附图和著录、保存说明书和权要、保存专题库关联专利数据)
|
|
//通知消费者线程(三个消费者:保存摘要附图和著录、保存说明书和权要、保存专题库关联专利数据)
|
|
//保存摘要附图和著录消费者
|
|
//保存摘要附图和著录消费者
|
|
- patentImageZhuluLatch.countDown();
|
|
|
|
|
|
+ //patentImageZhuluLatch.countDown();
|
|
|
|
+ patentImageZhuluLock.lock();
|
|
|
|
+ patentImageZhuluCondition.signalAll();
|
|
|
|
+ patentImageZhuluLock.unlock();
|
|
//保存说明书和权要消费者
|
|
//保存说明书和权要消费者
|
|
- patentRightInstructionTextLatch.countDown();
|
|
|
|
|
|
+ //patentRightInstructionTextLatch.countDown();
|
|
|
|
+ patentRightInstructionTextLock.lock();
|
|
|
|
+ patentRightInstructionTextCondition.signalAll();
|
|
|
|
+ patentRightInstructionTextLock.unlock();
|
|
//保存专题库关联专利数据消费者
|
|
//保存专题库关联专利数据消费者
|
|
- patentAssoLatch.countDown();
|
|
|
|
|
|
+ //patentAssoLatch.countDown();
|
|
|
|
+ patentAssoLock.lock();
|
|
|
|
+ patentAssoCondition.signalAll();
|
|
|
|
+ patentAssoLock.unlock();
|
|
|
|
|
|
- //任务表更新数据
|
|
|
|
- //上一次的位置(保存到第几个专利)
|
|
|
|
- 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);
|
|
task.setStatus(2);
|
|
@@ -166,20 +134,23 @@ public class PantentQueueService {
|
|
while (true) {
|
|
while (true) {
|
|
if (patentImageZhuluQueue.isEmpty()) {
|
|
if (patentImageZhuluQueue.isEmpty()) {
|
|
if (flag) {
|
|
if (flag) {
|
|
- System.out.println("退出循环");
|
|
|
|
|
|
+ System.out.println("所有专利的摘要附图和著录项目全部完成,退出循环");
|
|
return;
|
|
return;
|
|
} else {
|
|
} else {
|
|
- patentImageZhuluLatch.await();
|
|
|
|
|
|
+ patentImageZhuluLock.lock();
|
|
|
|
+ patentImageZhuluCondition.await();
|
|
|
|
+ patentImageZhuluLock.unlock();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- System.out.println("开始保存摘要附图和著录项目");
|
|
|
|
QueueData queueData = patentImageZhuluQueue.remove();
|
|
QueueData queueData = patentImageZhuluQueue.remove();
|
|
//摘要附图入库
|
|
//摘要附图入库
|
|
uploadPatentToDBService.uploadPatentImage(queueData.getUploadParamsVO());
|
|
uploadPatentToDBService.uploadPatentImage(queueData.getUploadParamsVO());
|
|
//著录项目入库
|
|
//著录项目入库
|
|
uploadPatentToDBService.uploadPatentZhulu(queueData.getUploadParamsVO());
|
|
uploadPatentToDBService.uploadPatentZhulu(queueData.getUploadParamsVO());
|
|
- System.out.println("出队列");
|
|
|
|
|
|
+ //Websocket发送message:通过WebSocket 在每一次循环结束后 向前端发送完成进度
|
|
|
|
+ sendMessage(queueData, patentIdMap.get(0), task);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
} finally {
|
|
} finally {
|
|
|
|
|
|
@@ -194,20 +165,21 @@ public class PantentQueueService {
|
|
while (true) {
|
|
while (true) {
|
|
if (patentRightInstructionTextQueue.isEmpty()) {
|
|
if (patentRightInstructionTextQueue.isEmpty()) {
|
|
if (flag) {
|
|
if (flag) {
|
|
- System.out.println("退出循环");
|
|
|
|
|
|
+ System.out.println("所有专利的说明书和权要全部完成,退出循环");
|
|
return;
|
|
return;
|
|
} else {
|
|
} else {
|
|
- patentRightInstructionTextLatch.await();
|
|
|
|
|
|
+ patentRightInstructionTextLock.lock();
|
|
|
|
+ patentRightInstructionTextCondition.await();
|
|
|
|
+ patentRightInstructionTextLock.unlock();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- System.out.println("开始保存说明书和权要");
|
|
|
|
QueueData queueData = patentRightInstructionTextQueue.remove();
|
|
QueueData queueData = patentRightInstructionTextQueue.remove();
|
|
//说明书入库
|
|
//说明书入库
|
|
uploadPatentToDBService.uploadPatentInstructionText(queueData.getUploadParamsVO());
|
|
uploadPatentToDBService.uploadPatentInstructionText(queueData.getUploadParamsVO());
|
|
//权要入库
|
|
//权要入库
|
|
uploadPatentToDBService.uploadPatentRight(queueData.getUploadParamsVO());
|
|
uploadPatentToDBService.uploadPatentRight(queueData.getUploadParamsVO());
|
|
-
|
|
|
|
- System.out.println("出队列");
|
|
|
|
|
|
+ //Websocket发送message:通过WebSocket 在每一次循环结束后 向前端发送完成进度
|
|
|
|
+ sendMessage(queueData, patentIdMap.get(0), task);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} finally {
|
|
} finally {
|
|
@@ -223,13 +195,14 @@ public class PantentQueueService {
|
|
while (true) {
|
|
while (true) {
|
|
if (patentAssoQueue.isEmpty()) {
|
|
if (patentAssoQueue.isEmpty()) {
|
|
if (flag) {
|
|
if (flag) {
|
|
- System.out.println("退出循环");
|
|
|
|
|
|
+ System.out.println("所有专利的与专利关联的数据全部完成,退出循环");
|
|
return;
|
|
return;
|
|
} else {
|
|
} else {
|
|
- patentAssoLatch.await();
|
|
|
|
|
|
+ patentAssoLock.lock();
|
|
|
|
+ patentAssoCondition.await();
|
|
|
|
+ patentAssoLock.unlock();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- System.out.println("开始保存与专利关联的数据");
|
|
|
|
QueueData queueData = patentAssoQueue.remove();
|
|
QueueData queueData = patentAssoQueue.remove();
|
|
//专题库与专利关联入库
|
|
//专题库与专利关联入库
|
|
uploadPatentToDBService.uploadAssoThemaPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
|
|
uploadPatentToDBService.uploadAssoThemaPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
|
|
@@ -237,8 +210,8 @@ public class PantentQueueService {
|
|
uploadPatentToDBService.uploadAssoFieldPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
|
|
uploadPatentToDBService.uploadAssoFieldPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
|
|
//文件夹与专利关联入库
|
|
//文件夹与专利关联入库
|
|
uploadPatentToDBService.uploadAssoPorPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
|
|
uploadPatentToDBService.uploadAssoPorPat(queueData.getUploadParamsVO(), queueData.getProjectImportPatentVO());
|
|
-
|
|
|
|
- System.out.println("出队列");
|
|
|
|
|
|
+ //Websocket发送message:通过WebSocket 在每一次循环结束后 向前端发送完成进度
|
|
|
|
+ sendMessage(queueData, patentIdMap.get(0), task);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} finally {
|
|
} finally {
|
|
@@ -246,12 +219,45 @@ public class PantentQueueService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void sendMessage(QueueData queueData, Integer total, Task task) {
|
|
|
|
+ //每完成一个专利,通过计算,发送进度
|
|
|
|
+ synchronized ("啊啊啊") {
|
|
|
|
+ Integer currentPatentId = queueData.getUploadParamsVO().getPatent().getId();
|
|
|
|
+ Integer num = patentIdMap.get(currentPatentId);
|
|
|
|
+ if (num == null) {
|
|
|
|
+ patentIdMap.put(currentPatentId, 1);
|
|
|
|
+ } else if (num == 1) {
|
|
|
|
+ patentIdMap.put(currentPatentId, 2);
|
|
|
|
+ } else {
|
|
|
|
+ //num达到3了就从patentIdMap中删除
|
|
|
|
+ patentIdMap.remove(currentPatentId);
|
|
|
|
+ long percentage = Math.round((patentFinishNum + 1D) / total * 100D);
|
|
|
|
+ if (patentFinishNum.equals(total)) {
|
|
|
|
+ percentage = 100L;
|
|
|
|
+ }
|
|
|
|
+ patentFinishNum++;
|
|
|
|
+ messageService.sendWebsocketMessage(task, total, patentFinishNum, percentage);
|
|
|
|
+
|
|
|
|
+//任务表更新数据 ↓
|
|
|
|
+ //成功条数
|
|
|
|
+ task.setSuccessNum(patentFinishNum);
|
|
|
|
+ //失败条数
|
|
|
|
+ task.setDefaultNum(total - task.getSuccessNum());
|
|
|
|
+ taskService.updateById(task);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
public void queueAddTask(List<Integer> taskQueueList) {
|
|
public void queueAddTask(List<Integer> taskQueueList) {
|
|
this.taskQueueList.addAll(taskQueueList);
|
|
this.taskQueueList.addAll(taskQueueList);
|
|
}
|
|
}
|
|
|
|
|
|
public void awakeTasktch() {
|
|
public void awakeTasktch() {
|
|
- this.taskLatch.countDown();
|
|
|
|
|
|
+ taskLock.lock();
|
|
|
|
+ taskCondition.signalAll();
|
|
|
|
+ taskLock.unlock();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|