|
@@ -3,30 +3,37 @@ package cn.cslg.pas.service.importPatent;
|
|
|
import cn.cslg.pas.common.model.cronModel.SystemFile;
|
|
|
import cn.cslg.pas.common.utils.ReadExcelUtils;
|
|
|
import cn.cslg.pas.common.vo.ImportTaskAMVO;
|
|
|
+import cn.cslg.pas.common.vo.PatentData;
|
|
|
+import cn.cslg.pas.common.vo.UploadParamsVO;
|
|
|
import cn.cslg.pas.common.vo.UploadSettingVO;
|
|
|
import cn.cslg.pas.domain.es.Patent;
|
|
|
+import cn.cslg.pas.service.common.ExcuteDataToVOService;
|
|
|
import cn.cslg.pas.service.common.ExcuteUploadSettingService;
|
|
|
import cn.cslg.pas.service.common.FileManagerService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
+import org.apache.commons.compress.utils.IOUtils;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Configurable;
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
-public class GetPatentFromExcelThread extends Thread{
|
|
|
- private ImportTaskAMVO importTaskAMVO;
|
|
|
- @Autowired
|
|
|
- private FileManagerService fileManagerService;
|
|
|
+@Configurable
|
|
|
+public class GetPatentFromExcelThread extends Thread {
|
|
|
+ private ImportTaskAMVO importTaskAMVO;
|
|
|
+ private ApplicationContext applicationContext;
|
|
|
+ private SavePatentToEsThread savePatentToEsThread;
|
|
|
+
|
|
|
|
|
|
- @Autowired
|
|
|
- private ExcuteUploadSettingService excuteUploadSettingService;
|
|
|
- private SavePatentToEsThread savePatentToEsThread;
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
+ FileManagerService fileManagerService = applicationContext.getBean(FileManagerService.class);
|
|
|
|
|
|
String res = fileManagerService.getSystemFileFromFMS(Arrays.asList(importTaskAMVO.getFileGuid()));
|
|
|
List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
|
|
@@ -35,49 +42,55 @@ public class GetPatentFromExcelThread extends Thread{
|
|
|
//调用文件系统取出文件接口,获得文件流
|
|
|
byte[] bytes = fileManagerService.downloadSystemFileFromFMS(importTaskAMVO.getFileGuid());
|
|
|
//创建临时文件tempFile,并将文件读取到tempFile
|
|
|
- File tempFile = File.createTempFile(systemFile.getFileName()+"temp", suffix);
|
|
|
+ File tempFile = File.createTempFile(systemFile.getFileName() + "temp", suffix);
|
|
|
+ try (
|
|
|
+ InputStream inputStream = new ByteArrayInputStream(bytes);
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(tempFile)
|
|
|
+ ) {
|
|
|
+ IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
|
|
|
+ }
|
|
|
Integer total = importTaskAMVO.getAllNum();
|
|
|
Integer lastIndex = importTaskAMVO.getSuccessNum();
|
|
|
Integer sourceId = importTaskAMVO.getSourceId();
|
|
|
//解析数据源类,通过数据来源id(如1:智慧芽)解析数据源配置文件,获得数据源配置文件对象jsonData
|
|
|
+ ExcuteDataToVOService excuteDataToVOService =applicationContext.getBean(ExcuteDataToVOService.class);
|
|
|
+ ExcuteUploadSettingService excuteUploadSettingService =applicationContext.getBean(ExcuteUploadSettingService.class);
|
|
|
List<UploadSettingVO.Column> jsonData = excuteUploadSettingService.ExcuteUploadSetting(sourceId.toString());
|
|
|
//解析Excel文件获得工作簿
|
|
|
Sheet sheet = ReadExcelUtils.readExcel(tempFile);
|
|
|
//遍历专利总数量,在循环中将专利一个一个存入消费者专利队列
|
|
|
-// for (int i = lastIndex; i < total; i++) {
|
|
|
-// //判断若任务状态为已暂停,则结束生产
|
|
|
-// if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// PatentData patentData = ReadExcelUtils.readExcelOneRow(tempFile, sheet, i + 1);
|
|
|
-// //调用装载数据类(根据数据源配置文件对象和专利源数据生成专利数据)
|
|
|
-// UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
|
|
|
-// //如果是中国专利,就将申请号作为专利号
|
|
|
-// if (uploadParamsVO.getPatent().getPatentNo().contains("CN")) {
|
|
|
-// uploadParamsVO.getPatent().setPatentNo(uploadParamsVO.getPatent().getApplicationNo()); //将申请号设为专利号patentNo
|
|
|
-// }
|
|
|
-//
|
|
|
-// //专利丢入消费者队列,并唤醒消费者线程
|
|
|
-// pantentQueueService.patentToQueue(task, uploadParamsVO);
|
|
|
-// }
|
|
|
+ for (int i = lastIndex; i < total; i++) {
|
|
|
+
|
|
|
+ PatentData patentData = ReadExcelUtils.readExcelOneRow(tempFile, sheet, i + 1);
|
|
|
+ //调用装载数据类(根据数据源配置文件对象和专利源数据生成专利数据)
|
|
|
+ UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
|
|
|
+
|
|
|
|
|
|
+ //专利丢入消费者队列,并唤醒消费者线程
|
|
|
+ savePatentToEsThread.awakeTask(uploadParamsVO.getPatent());
|
|
|
+ }
|
|
|
+ savePatentToEsThread.setIfProductAll(true);
|
|
|
//删除临时文件tempFile
|
|
|
new File(tempFile.getPath()).delete();
|
|
|
- for(int i =0;i<10;i++)
|
|
|
- {
|
|
|
- Thread.sleep(5000);
|
|
|
- Patent patent =new Patent();
|
|
|
- patent.setPatentNo("CN"+i+"task"+importTaskAMVO.getId());
|
|
|
- System.out.println("task"+importTaskAMVO.getId()+"getPatent"+i);
|
|
|
- savePatentToEsThread.awakeTask(patent);
|
|
|
- }
|
|
|
-savePatentToEsThread.setIfProductAll(true);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- public GetPatentFromExcelThread(ImportTaskAMVO importTaskAMVO,SavePatentToEsThread savePatentToEsThread){
|
|
|
- this.importTaskAMVO =importTaskAMVO;
|
|
|
- this.savePatentToEsThread =savePatentToEsThread;
|
|
|
+
|
|
|
+ public GetPatentFromExcelThread(ImportTaskAMVO importTaskAMVO, SavePatentToEsThread savePatentToEsThread,ApplicationContext applicationContext) {
|
|
|
+ this.importTaskAMVO = importTaskAMVO;
|
|
|
+ this.savePatentToEsThread = savePatentToEsThread;
|
|
|
+ this.applicationContext= applicationContext;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void loadPatent(Patent patent) {
|
|
|
+ //如果是中国专利,就将申请号作为专利号
|
|
|
+ if (patent.getPatentNo().contains("CN")) {
|
|
|
+ patent.setPatentNo(patent.getAppNo()); //将申请号设为专利号patentNo
|
|
|
+ }
|
|
|
+
|
|
|
+ //装载权利要求
|
|
|
+
|
|
|
}
|
|
|
}
|