Kaynağa Gözat

替换分析系统中涉及Excel导入专利和读取Excel下载专利的代码(文件的上传和读取代码替换为使用文件管理系统

chendayu 2 yıl önce
ebeveyn
işleme
87a39af8bb

+ 36 - 21
PAS/src/main/java/cn/cslg/pas/common/utils/ReadExcelUtils.java

@@ -23,31 +23,32 @@ public class ReadExcelUtils {
     /**
      * 检测Excel文件合法性
      *
-     * @param filePath 文件路径
+     * @param tempFile 临时文件
      * @return 返回文件总行数
      */
-    public static Integer textExcel(String filePath) throws IOException {
+    public static Integer textExcel(File tempFile) throws IOException {
         //判断文件是否存在
-        if (filePath == null || filePath.equals("")) {
-            ThrowException.throwXiaoShiException("文件上传失败,服务器忙请稍后再试!");
-        }
-        File file = new File(filePath);
-        if (!file.exists()) {
+        if (!tempFile.exists() || tempFile.getPath().trim().equals("")) {
+            //删除临时文件tempFile
+            new File(tempFile.getPath()).delete();
             ThrowException.throwXiaoShiException("文件上传失败,服务器忙请稍后再试!");
         }
 
         // 检测是否为excel文件
-        if (!filePath.endsWith(".xls") && !filePath.endsWith(".xlsx") && !filePath.endsWith(".XLS") && !filePath.endsWith(".XLSX")) {
+        String suffix = tempFile.getPath().substring(tempFile.getPath().lastIndexOf("."));
+        if (!suffix.equals(".xls") && !suffix.equals(".xlsx") && !suffix.equals(".XLS") && !suffix.equals(".XLSX")) {
+            //删除临时文件tempFile
+            new File(tempFile.getPath()).delete();
             ThrowException.throwXiaoShiException("文件格式错误,请上传Excel文件!");
         }
 
-        InputStream fis = new FileInputStream(file);
+        InputStream fis = new FileInputStream(tempFile);
         //使用poi框架解析处理Excel文件
         Workbook workbook = null;
         //区分不同版本Excel,使用各自对应的工具类
-        if (filePath.endsWith(".xls") || filePath.endsWith(".XLS")) {
+        if (suffix.equals(".xls") || suffix.equals(".XLS")) {
             workbook = new HSSFWorkbook(fis);
-        } else if (filePath.endsWith(".xlsx") || filePath.endsWith(".XLSX")) {
+        } else if (suffix.equals(".xlsx") || suffix.equals(".XLSX")) {
             workbook = new XSSFWorkbook(fis);
         }
         //读取第几个sheet
@@ -55,6 +56,9 @@ public class ReadExcelUtils {
         //读取总行数
         int rows = sheet.getPhysicalNumberOfRows();
         if (rows <= 1) {
+            //删除临时文件tempFile
+            fis.close();
+            new File(tempFile.getPath()).delete();
             ThrowException.throwXiaoShiException("文件内容格式不正确,请检查总行数是否有专利内容");
         }
 
@@ -72,9 +76,15 @@ public class ReadExcelUtils {
             }
         }
         if (!flag1 || !flag2) {
+            //删除临时文件tempFile
+            fis.close();
+            new File(tempFile.getPath()).delete();
             ThrowException.throwXiaoShiException("文件内容格式不正确,第一行抬头必须有【公开(公告)号】和【申请号】");
         }
 
+        //关闭流
+        fis.close();
+
         //返回文件总行数-1(即专利总数量)
         return rows - 1;
     }
@@ -82,12 +92,12 @@ public class ReadExcelUtils {
     /**
      * 获取一行专利的全部数据(专利内容数据 + 摘要附图)
      *
-     * @param filePath Excel文件路径
+     * @param tempFile Excel临时文件
      * @param row      行数
      * @return 返回装载专利数据(专利内容数据 + 摘要附图)的对象
      */
-    public static PatentData readExcelOneRow(String filePath, Sheet sheet, int row) throws IOException {
-        //返回最终结果的对象
+    public static PatentData readExcelOneRow(File tempFile, Sheet sheet, int row) throws IOException {
+        //创建返回最终结果的对象 patentData
         PatentData patentData = new PatentData();
         //装载专利数据(除了摘要附图)的map:(key:表头如 "公开(公告)号"  value:表头对应内容如 "CN1307082B")
         Map<Object, Object> map = new HashMap<>();
@@ -104,9 +114,10 @@ public class ReadExcelUtils {
         }
 
         //开始装载专利摘要附图(判断用07还是03的方法获取图片)
-        if (filePath.endsWith(".xls") || filePath.endsWith(".XLS")) {
+        String suffix = tempFile.getName().substring(tempFile.getName().lastIndexOf("."));
+        if (suffix.equals(".xls") || suffix.equals(".XLS")) {
             pictureData = getPictures1((HSSFSheet) sheet, row);
-        } else if (filePath.endsWith(".xlsx") || filePath.endsWith(".XLSX")) {
+        } else if (suffix.equals(".xlsx") || suffix.equals(".XLSX")) {
             pictureData = getPictures2((XSSFSheet) sheet, row);
         }
 
@@ -117,23 +128,27 @@ public class ReadExcelUtils {
         return patentData;
     }
 
-    public static Sheet readExcel(String filePath) {
+    public static Sheet readExcel(File tempFile) {
         Sheet sheet = null;
 
-        File file = new File(filePath);
         try {
-            InputStream inputStream = new FileInputStream(file);
+            InputStream inputStream = new FileInputStream(tempFile);
             //POI可以处理Excel文件
             Workbook workbook = null;
             //当文件以.xls结尾时
-            if (filePath.endsWith(".xls") || filePath.endsWith(".XLS")) {
+            String suffix = tempFile.getName().substring(tempFile.getName().lastIndexOf("."));
+            if (suffix.equals(".xls") || suffix.equals(".XLS")) {
                 workbook = new HSSFWorkbook(inputStream);
-            } else if (filePath.endsWith(".xlsx") || filePath.endsWith(".XLSX")) {
+            } else if (suffix.equals(".xlsx") || suffix.equals(".XLSX")) {
                 workbook = new XSSFWorkbook(inputStream);
             }
 
             //读取第几个sheet
             sheet = workbook.getSheetAt(0);
+
+            //关闭流
+            inputStream.close();
+
         } catch (IOException e) {
             e.printStackTrace();
         }

+ 2 - 4
PAS/src/main/java/cn/cslg/pas/controller/ProjectImportController.java

@@ -11,15 +11,13 @@ import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
 import cn.cslg.pas.common.utils.auth.checkAuth;
 import cn.cslg.pas.exception.XiaoShiException;
-import cn.cslg.pas.service.ProjectImportService;
-import cn.cslg.pas.service.ProjectImportStatusService;
-import cn.cslg.pas.service.ProjectService;
-import cn.cslg.pas.service.UploadPatentBatchService;
+import cn.cslg.pas.service.*;
 import cn.cslg.pas.service.upLoadPatent.UploadTaskService;
 import cn.dev33.satoken.stp.StpUtil;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.bind.annotation.*;

+ 28 - 6
PAS/src/main/java/cn/cslg/pas/service/FileManagerService.java

@@ -16,10 +16,12 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.TimeUnit;
+
 import static cn.hutool.core.io.FileUtil.getMimeType;
 
 /**
  * Okhttp调用FMS上传文件接口
+ *
  * @Author xiexiang
  * @Date 2023/8/10
  */
@@ -40,19 +42,19 @@ public class FileManagerService {
 
     public String uploadFile(List<MultipartFile> multipartFiles, Integer sourceId) throws IOException {
         List<File> files = new ArrayList<>();
-        for(MultipartFile multipartFile:multipartFiles){
+        for (MultipartFile multipartFile : multipartFiles) {
             File file = new File(multipartFile.getOriginalFilename());
-            FileCopyUtils.copy(multipartFile.getBytes(),file);
+            FileCopyUtils.copy(multipartFile.getBytes(), file);
             files.add(file);
         }
         MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder()
                 .setType(MultipartBody.FORM);
-        for(File file:files){
+        for (File file : files) {
             //根据文件名获取文件的MIME类型
             String mimeType = getMimeType(file.getPath());
-            multipartBodyBuilder.addFormDataPart("files",file.getName(),RequestBody.create(MediaType.parse(mimeType), file));
+            multipartBodyBuilder.addFormDataPart("files", file.getName(), RequestBody.create(MediaType.parse(mimeType), file));
         }
-        RequestBody requestBody =multipartBodyBuilder
+        RequestBody requestBody = multipartBodyBuilder
                 .addFormDataPart("sourceId", String.valueOf(sourceId))
                 .build();
         OkHttpClient okHttpClient = new OkHttpClient.Builder()
@@ -68,7 +70,26 @@ public class FileManagerService {
     }
 
     /**
-     * 调用文件系统查询接口
+     * 调用文件系统取出文件接口(获得文件流)
+     *
+     * @param fieldId 文件id
+     */
+    public byte[] downloadSystemFileFromFMS(Integer fieldId) throws IOException {
+        OkHttpClient okHttpClient = new OkHttpClient.Builder()
+                .connectTimeout(60, TimeUnit.SECONDS)
+                .writeTimeout(60, TimeUnit.SECONDS)
+                .readTimeout(60, TimeUnit.SECONDS)
+                .build();
+        Request request = new Request.Builder()
+                .url(FMSUrl + "/fileManager/downloadSystemFile?fileId=" + fieldId)
+                .get()
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).bytes();
+    }
+
+    /**
+     * 调用文件系统获取文件信息接口
+     *
      * @return
      * @throws IOException
      */
@@ -89,6 +110,7 @@ public class FileManagerService {
 
     /**
      * 调用文件系统删除接口
+     *
      * @return
      * @throws IOException
      */

+ 11 - 7
PAS/src/main/java/cn/cslg/pas/service/TaskService.java

@@ -7,6 +7,7 @@ import cn.cslg.pas.common.model.dto.TaskAddNewDTO;
 
 import cn.cslg.pas.common.model.dto.QueryTaskDTO;
 import cn.cslg.pas.common.model.vo.*;
+import cn.cslg.pas.common.model.vo.SystemFile;
 import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
 
@@ -116,11 +117,11 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
     /**
      * 新增导入专利任务
      *
-     * @param fileDTO Excel文件
-     * @param json    前台参数
+     * @param systemFile Excel文件对象
+     * @param json       前台参数
      * @return 返回任务id
      */
-    public Integer addTask2(UploadFileDTO fileDTO, Integer total, String json) {
+    public Integer addTask2(SystemFile systemFile, Integer total, String json) {
         //将前台参数json格式转换为实体类(从中取出专题库id存入任务表)
         ProjectImportPatentVO projectImportPatentVO = JsonUtils.jsonToPojo(json, ProjectImportPatentVO.class);
 
@@ -142,13 +143,13 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
             task.setProductId(projectImportPatentVO.getProductId());
         }
         //文件名称
-        task.setFileName(fileDTO.getFileName());
+        task.setFileName(systemFile.getFileName());
         //文件路径
-        task.setUrl(fileDTO.getPath());
+        task.setUrl(systemFile.getFilePath());
         //文件的专利总数量
         task.setTotal(total);
         //文件大小
-        task.setFileSize(fileDTO.getFileSize());
+        task.setFileSize(Long.valueOf(systemFile.getFileLength()));
         //任务类型 (1.上传 2导出)
         task.setType(1);
         //导入导出字段数量
@@ -156,7 +157,7 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
         //创建人id
         task.setCreateBy(loginUtils.getId());
         //文件原始名称
-        task.setOldName(fileDTO.getName());
+        task.setOldName(systemFile.getOriginalName());
         //成功条数
         task.setSuccessNum(0);
         //失败条数
@@ -165,7 +166,10 @@ public class TaskService extends ServiceImpl<TaskMapper, Task> implements ITaskS
         task.setPramJson(json);
         //任务类型1(0普通任务 1定时任务)
         task.setTaskType(0);
+        //是否作为对比文件
         task.setAsCompare(projectImportPatentVO.getAsCompare());
+        //文件id
+        task.setSystemFileId(systemFile.getId());
         //数据入任务表
         task.insert();
         return task.getId();

+ 38 - 5
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/ExcutePatentDataExcel.java

@@ -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();
             //生产消费到一半时,发生错误异常,将任务状态置为完成

+ 44 - 12
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/UploadTaskService.java

@@ -4,25 +4,28 @@ import cn.cslg.pas.common.model.PersonnelVO;
 import cn.cslg.pas.common.model.dto.TaskAddNewDTO;
 import cn.cslg.pas.common.model.dto.UploadFileDTO;
 import cn.cslg.pas.common.model.outApi.PatentStarListDto;
+import cn.cslg.pas.common.model.vo.SystemFile;
 import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
 import cn.cslg.pas.domain.Project;
 import cn.cslg.pas.domain.SerachBiblioData;
 import cn.cslg.pas.domain.WebLoginConfig;
 import cn.cslg.pas.domain.asso.TaskCondition;
-import cn.cslg.pas.service.PatentService;
-import cn.cslg.pas.service.ProjectService;
-import cn.cslg.pas.service.TaskService;
-import cn.cslg.pas.service.WebLoginConfigService;
+import cn.cslg.pas.service.*;
 import cn.cslg.pas.service.asso.TaskConditionService;
 import cn.cslg.pas.service.outApi.PatentStarApiService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.compress.utils.IOUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.IOException;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -49,6 +52,9 @@ public class UploadTaskService {
     private final PatentStarApiService patentStarApiService;
     private final ProjectService projectService;
     private final PatentService patentService;
+    private final FileManagerService fileManagerService;
+    @Value("${FileSource}")
+    private Integer fileSource;
 
     /**
      * 新增Excel导入任务
@@ -57,14 +63,40 @@ public class UploadTaskService {
      * @param json 前台参数(与专题库关联信息、自定义字段、文件夹等)
      */
     public void addExcelTask(MultipartFile file, String json) throws IOException {
-        //将包含多件专利的Excel文件上传至本地,并返回文件对象fileDTO
-        UploadFileDTO fileDTO = fileUtils.uploadFile(file);
-        //获得文件路径(绝对路径)
-        String filePath = fileUtils.getPath(fileDTO.getPath());
-        //检查文件合法性并获取专利总数量
-        Integer total = ReadExcelUtils.textExcel(filePath);
+        String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
+
+        //创建临时文件tempFile,并将file读取到tempFile
+        File tempFile = File.createTempFile("temp", suffix);
+        try (InputStream inputStream = file.getInputStream();
+             FileOutputStream outputStream = new FileOutputStream(tempFile)) {
+            IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
+        }
+
+        //检查文件tempFile合法性并获取专利总数量
+        Integer total = ReadExcelUtils.textExcel(tempFile);
+
+        //删除临时文件tempFile
+        new File(tempFile.getPath()).delete();
+
+        //将文件file上传至服务器,并返回文件fileId
+        ArrayList<MultipartFile> files = new ArrayList<>();
+        files.add(file);
+        String res = fileManagerService.uploadFile(files, fileSource);
+        JSONObject jsonObject = JSONObject.parseObject(res);
+        List<Integer> fileIds = JSONArray.parseArray(jsonObject.get("data").toString(), Integer.class);
+        if (fileIds == null || fileIds.size() == 0) {
+            ThrowException.throwXiaoShiException("服务器忙请稍后再试!");
+        }
+        //获得文件信息systemFile
+        res = fileManagerService.getSystemFileFromFMS(fileIds);
+        List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
+        if (systemFiles == null || systemFiles.size() == 0) {
+            ThrowException.throwXiaoShiException("服务器忙请稍后再试!");
+        }
+        SystemFile systemFile = systemFiles.get(0);
+
         //新增任务(专利导入导出任务表)
-        Integer taskId = taskService.addTask2(fileDTO, total, json);
+        Integer taskId = taskService.addTask2(systemFile, total, json);
         //任务存入生产者任务队列并唤醒生产者线程
         pantentQueueService.taskQueueListAddTask(Arrays.asList(taskId));
         pantentQueueService.awakeTasktch();

+ 15 - 7
PAS/src/test/java/cn/cslg/pas/service/TextExcelTests.java

@@ -6,6 +6,8 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 
+import java.io.File;
+
 /**
  * 检测文件合法性方法单元测试
  *
@@ -22,10 +24,11 @@ public class TextExcelTests {
      */
     @Test
     void addNotFoundFileTask() {
-        filePath = "文件丢失或不存在路径";
+        filePath = "文件丢失或不存在路径.xlsx";
+        File file = new File(filePath);
 
         try {
-            ReadExcelUtils.textExcel(filePath);
+            ReadExcelUtils.textExcel(file);
 
         } catch (Exception e) {
             Assertions.assertEquals("文件上传失败,服务器忙请稍后再试!", e.getMessage(), "测试用例1不通过");
@@ -38,9 +41,10 @@ public class TextExcelTests {
     @Test
     void addNotExcelTask() {
         filePath = ".\\单元测试用例专用文件\\FTO风险排查报告用户操作手册.pptx";
+        File file = new File(filePath);
 
         try {
-            ReadExcelUtils.textExcel(filePath);
+            ReadExcelUtils.textExcel(file);
 
         } catch (Exception e) {
             Assertions.assertEquals("文件格式错误,请上传Excel文件!", e.getMessage(), "测试用例2不通过");
@@ -53,9 +57,10 @@ public class TextExcelTests {
     @Test
     void addRowLessThan1ExcelTask() {
         filePath = ".\\单元测试用例专用文件\\1件CN专利 - 单元格行数不大于1.XLSX";
+        File file = new File(filePath);
 
         try {
-            ReadExcelUtils.textExcel(filePath);
+            ReadExcelUtils.textExcel(file);
 
         } catch (Exception e) {
             Assertions.assertEquals("文件内容格式不正确,请检查总行数是否有专利内容", e.getMessage(), "测试用例3不通过");
@@ -68,9 +73,10 @@ public class TextExcelTests {
     @Test
     void addFalseTitleExcelTask() {
         filePath = ".\\单元测试用例专用文件\\1件CN专利 - 抬头没有申请号.XLSX";
+        File file = new File(filePath);
 
         try {
-            ReadExcelUtils.textExcel(filePath);
+            ReadExcelUtils.textExcel(file);
 
         } catch (Exception e) {
             Assertions.assertEquals("文件内容格式不正确,第一行抬头必须有【公开(公告)号】和【申请号】", e.getMessage(), "测试用例4不通过");
@@ -84,9 +90,10 @@ public class TextExcelTests {
     @Test
     void addFalseTitleExcelTask2() {
         filePath = ".\\单元测试用例专用文件\\1件CN专利 - 抬头没有公开公告号.XLSX";
+        File file = new File(filePath);
 
         try {
-            ReadExcelUtils.textExcel(filePath);
+            ReadExcelUtils.textExcel(file);
 
         } catch (Exception e) {
             Assertions.assertEquals("文件内容格式不正确,第一行抬头必须有【公开(公告)号】和【申请号】", e.getMessage(), "测试用例5不通过");
@@ -100,9 +107,10 @@ public class TextExcelTests {
     @Test
     void addExcelTask() {
         filePath = ".\\单元测试用例专用文件\\1件CN专利.XLSX";
+        File file = new File(filePath);
 
         try {
-            ReadExcelUtils.textExcel(filePath);
+            ReadExcelUtils.textExcel(file);
 
         } catch (Exception e) {
             Assertions.assertEquals("文件内容格式不正确,第一行抬头必须有【公开(公告)号】和【申请号】", e.getMessage(), "测试用例5不通过");