|
@@ -1,6 +1,5 @@
|
|
|
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.ReadExcelUtils;
|
|
@@ -8,52 +7,36 @@ import cn.cslg.pas.domain.PatentData;
|
|
|
import cn.cslg.pas.domain.Task;
|
|
|
import cn.cslg.pas.service.TaskService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import lombok.Data;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import org.apache.poi.ss.formula.functions.T;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Queue;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
-import java.util.concurrent.locks.Condition;
|
|
|
-import java.util.concurrent.locks.Lock;
|
|
|
-import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
|
|
/**
|
|
|
* 将专利信息存入队列或从队列取出
|
|
|
*
|
|
|
* @author 李仁杰
|
|
|
*/
|
|
|
+
|
|
|
@Service
|
|
|
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
public class PantentQueueService {
|
|
|
- @Autowired
|
|
|
- private ExcuteDataToVOService excuteDataToVOService;
|
|
|
- @Autowired
|
|
|
- private ExcuteUploadSettingService excuteUploadSettingService;
|
|
|
- @Autowired
|
|
|
- private MessageService messageService;
|
|
|
- @Autowired
|
|
|
- private TaskService taskService;
|
|
|
-
|
|
|
+ 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 Boolean flag = false;
|
|
|
private CountDownLatch patentLatch = new CountDownLatch(10);
|
|
|
private CountDownLatch taskLatch = new CountDownLatch(10);
|
|
|
- private static PantentQueueService pantentQueueService =new PantentQueueService();
|
|
|
- //构造函数
|
|
|
- private PantentQueueService(){
|
|
|
-
|
|
|
- }
|
|
|
- public static PantentQueueService getInstance(){
|
|
|
- return pantentQueueService;
|
|
|
- }
|
|
|
//将专利信息存入队列
|
|
|
public void addPatnetToQueue() {
|
|
|
try {
|
|
@@ -61,7 +44,6 @@ public class PantentQueueService {
|
|
|
if (taskQueueList.size() == 0) {
|
|
|
taskLatch.await();
|
|
|
}
|
|
|
-
|
|
|
//查找 taskQueueList 中有没有进行中的任务
|
|
|
long count = taskService.count(new LambdaQueryWrapper<Task>().in(Task::getId, taskQueueList).eq(Task::getStatus, 1));
|
|
|
//若没有,则取出第一个队列中的任务开始执行
|
|
@@ -81,7 +63,7 @@ public class PantentQueueService {
|
|
|
//检查文件合法性
|
|
|
Integer totalRow = ReadExcelUtils.textExcel(filePath);
|
|
|
//调用解析数据类,根据数据来源id(如1:智慧芽)解析数据源配置文件信息
|
|
|
- List<UploadSettingVO.Column> jsonData = excuteUploadSettingService.ExcuteUploadSetting(projectImportPatentVO.getSourceId());
|
|
|
+ List<UploadSettingVO.Column> jsonData = excuteUploadSettingService.ExcuteUploadSetting(1+"");
|
|
|
//遍历专利总数量,在循环中保存专利
|
|
|
for (int i = 1; i <= totalRow; i++) {
|
|
|
//解析读取一行专利
|
|
@@ -103,10 +85,8 @@ public class PantentQueueService {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
}
|
|
|
-
|
|
|
flag = true;
|
|
|
}
|
|
|
-
|
|
|
//将专利信息从队列取出
|
|
|
public void pushPantentToDb() throws InterruptedException {
|
|
|
try {
|
|
@@ -123,19 +103,15 @@ public class PantentQueueService {
|
|
|
System.out.println("出队列" + uploadParamsVO);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
} finally {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
public void setTaskQueueList(List<Integer> taskQueueList) {
|
|
|
- this.taskQueueList = taskQueueList;
|
|
|
+ this.taskQueueList.addAll(taskQueueList);
|
|
|
}
|
|
|
-
|
|
|
public void awakeTasktch(){
|
|
|
taskLatch.countDown();
|
|
|
|
|
|
}
|
|
|
-
|
|
|
}
|