|
@@ -1,6 +1,7 @@
|
|
|
package cn.cslg.pas.service.upLoadPatent;
|
|
|
|
|
|
import cn.cslg.pas.common.model.vo.ProjectImportPatentVO;
|
|
|
+import cn.cslg.pas.common.model.vo.SystemFile;
|
|
|
import cn.cslg.pas.common.model.vo.UploadParamsVO;
|
|
|
import cn.cslg.pas.common.model.vo.UploadSettingVO;
|
|
|
import cn.cslg.pas.common.utils.FileUtils;
|
|
@@ -8,12 +9,20 @@ 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.Task;
|
|
|
+import cn.cslg.pas.service.FileManagerService;
|
|
|
import cn.cslg.pas.service.TaskService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import okhttp3.ResponseBody;
|
|
|
+import org.apache.commons.compress.utils.IOUtils;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.core.io.InputStreamResource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -32,6 +41,9 @@ public class ExcutePatentDataExcel implements IExcutePatentData {
|
|
|
private final TaskService taskService;
|
|
|
private Integer pTaskId = 0;
|
|
|
private Integer pTaskStatus = 0;
|
|
|
+ private final FileManagerService fileManagerService;
|
|
|
+ @Value("${FileSource}")
|
|
|
+ private Integer fileSource;
|
|
|
|
|
|
/**
|
|
|
* 解析获取专利数据
|
|
@@ -42,8 +54,25 @@ public class ExcutePatentDataExcel implements IExcutePatentData {
|
|
|
@Override
|
|
|
public void startExcute(Task task) throws IOException {
|
|
|
try {
|
|
|
- //从任务中取出文件路径、总条数、成功条数、前台参数json
|
|
|
- String filePath = fileUtils.getPath(task.getUrl());
|
|
|
+ //调用文件系统获取文件信息接口,获得文件信息systemFile,并获得后缀名
|
|
|
+ ArrayList<Integer> fileIds = new ArrayList<>();
|
|
|
+ fileIds.add(task.getSystemFileId());
|
|
|
+ String res = fileManagerService.getSystemFileFromFMS(fileIds);
|
|
|
+ List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
|
|
|
+ SystemFile systemFile = systemFiles.get(0);
|
|
|
+ String suffix = systemFile.getFileName().substring(systemFile.getFileName().lastIndexOf("."));
|
|
|
+
|
|
|
+ //调用文件系统取出文件接口,获得文件流
|
|
|
+ byte[] bytes = fileManagerService.downloadSystemFileFromFMS(task.getSystemFileId());
|
|
|
+ //创建临时文件tempFile,并将文件读取到tempFile
|
|
|
+ File tempFile = File.createTempFile("temp", suffix);
|
|
|
+ try (
|
|
|
+ InputStream inputStream = new ByteArrayInputStream(bytes);
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(tempFile)
|
|
|
+ ) {
|
|
|
+ IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
|
|
|
+ }
|
|
|
+
|
|
|
Integer total = task.getTotal();
|
|
|
int lastIndex = task.getSuccessNum();
|
|
|
ProjectImportPatentVO projectImportPatentVO = JsonUtils.jsonToPojo(task.getPramJson(), ProjectImportPatentVO.class);
|
|
@@ -51,14 +80,14 @@ public class ExcutePatentDataExcel implements IExcutePatentData {
|
|
|
//解析数据源类,通过数据来源id(如1:智慧芽)解析数据源配置文件,获得数据源配置文件对象jsonData
|
|
|
List<UploadSettingVO.Column> jsonData = excuteUploadSettingService.ExcuteUploadSetting(projectImportPatentVO.getSourceId());
|
|
|
//解析Excel文件获得工作簿
|
|
|
- Sheet sheet = ReadExcelUtils.readExcel(filePath);
|
|
|
+ Sheet sheet = ReadExcelUtils.readExcel(tempFile);
|
|
|
//遍历专利总数量,在循环中将专利一个一个存入消费者专利队列
|
|
|
for (int i = lastIndex; i < total; i++) {
|
|
|
//判断若任务状态为已暂停,则结束生产
|
|
|
if (pTaskId.equals(task.getId()) && pTaskStatus == 4) {
|
|
|
return;
|
|
|
}
|
|
|
- PatentData patentData = ReadExcelUtils.readExcelOneRow(filePath, sheet, i + 1);
|
|
|
+ PatentData patentData = ReadExcelUtils.readExcelOneRow(tempFile, sheet, i + 1);
|
|
|
//调用装载数据类(根据数据源配置文件对象和专利源数据生成专利数据)
|
|
|
UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
|
|
|
//如果是中国专利,就将申请号作为专利号
|
|
@@ -69,6 +98,10 @@ public class ExcutePatentDataExcel implements IExcutePatentData {
|
|
|
//专利丢入消费者队列,并唤醒消费者线程
|
|
|
pantentQueueService.patentToQueue(task, uploadParamsVO);
|
|
|
}
|
|
|
+
|
|
|
+ //删除临时文件tempFile
|
|
|
+ new File(tempFile.getPath()).delete();
|
|
|
+
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
//生产消费到一半时,发生错误异常,将任务状态置为完成
|