Pārlūkot izejas kodu

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

chendayu 2 gadi atpakaļ
vecāks
revīzija
d18a67dc08

+ 4 - 0
PAS/src/main/java/cn/cslg/pas/common/model/vo/QueryTaskVO.java

@@ -100,6 +100,10 @@ public class QueryTaskVO implements Serializable {
      * Excel文件地址
      */
     private String url;
+    /**
+     * 文件id
+     */
+    private String fileId;
 
     //以上若是网站导入的任务,则以下为关联任务条件表数据;以上若是Excel导入的任务,则以下都是null
     /**

+ 15 - 4
PAS/src/main/java/cn/cslg/pas/common/utils/ReadExcelUtils.java

@@ -26,7 +26,7 @@ public class ReadExcelUtils {
      * @param tempFile 临时文件
      * @return 返回文件总行数
      */
-    public static Integer textExcel(File tempFile) throws IOException {
+    public static Integer textExcel(File tempFile, String sourceId) throws IOException {
         //判断文件是否存在
         if (!tempFile.exists() || tempFile.getPath().trim().equals("")) {
             //删除临时文件tempFile
@@ -66,9 +66,20 @@ public class ReadExcelUtils {
         Row firstRow = sheet.getRow(0);
         boolean flag1 = false;  //是否有 "公开(公告)号"
         boolean flag2 = false;  //是否有 "申请号"
-        //遍历第一行单元格抬头
+        //遍历第一行单元格抬头,检查合法性
+        String title = "", source = "";
+        if (sourceId.equals("1")) {
+            source = "智慧芽";
+            title = "公开(公告)号";
+        } else if (sourceId.equals("2")) {
+            source = "合享";
+            title = "公开(公告)号";
+        } else {
+            source = "Patentics";
+            title = "公开号";
+        }
         for (Cell cell : firstRow) {
-            if (cell.getStringCellValue().equals("公开(公告)号")) {
+            if (cell.getStringCellValue().equals(title)) {
                 flag1 = true;
             }
             if (cell.getStringCellValue().equals("申请号")) {
@@ -79,7 +90,7 @@ public class ReadExcelUtils {
             //删除临时文件tempFile
             fis.close();
             new File(tempFile.getPath()).delete();
-            ThrowException.throwXiaoShiException("文件内容格式不正确,第一行抬头必须有【公开(公告)号】和【申请号】");
+            ThrowException.throwXiaoShiException("文件内容格式不正确,您选择【" + source + "】来源,Excel第一行抬头必须有【" + title + "】和【申请号】");
         }
 
         //关闭流

+ 4 - 1
PAS/src/main/java/cn/cslg/pas/service/upLoadPatent/UploadTaskService.java

@@ -4,6 +4,7 @@ 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.ProjectImportPatentVO;
 import cn.cslg.pas.common.model.vo.SystemFile;
 import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
@@ -73,7 +74,9 @@ public class UploadTaskService {
         }
 
         //检查文件tempFile合法性并获取专利总数量
-        Integer total = ReadExcelUtils.textExcel(tempFile);
+        ProjectImportPatentVO projectImportPatentVO = JsonUtils.jsonToPojo(json, ProjectImportPatentVO.class);  //将前台参数json格式转换为实体类
+        String sourceId = projectImportPatentVO.getSourceId();
+        Integer total = ReadExcelUtils.textExcel(tempFile, sourceId);
 
         //删除临时文件tempFile
         new File(tempFile.getPath()).delete();

+ 2 - 1
PAS/src/main/resources/mapper/TaskMapper.xml

@@ -46,7 +46,7 @@
         tas.success_num tas_success_num,
         tas.true_success_num tas_true_success_num, tas.default_num tas_default_num, tas.pram_json tas_pram_json,
         tas.task_condition_id tas_task_condition_id, tas.create_time tas_create_time,
-        tas.task_type tas_task_type, tas.downexcel tas_downexcel,
+        tas.task_type tas_task_type, tas.downexcel tas_downexcel, tas.system_file_id tas_system_file_id,
         con.id, con.task_id, con.task_type, con.task_type2, con.conditions,
         con.crons, con.config_cells, con.config_id, con.task_name, con.total,
         con.orderby, con.orderby_type, con.db_type, con.start_number, con.end_number,
@@ -132,6 +132,7 @@
         <result column="tas_task_type" property="taskType"/>
         <result column="tas_endtime" property="modifiedTime"/>
         <result column="tas_downexcel" property="url"/>
+        <result column="tas_system_file_id" property="fileId"/>
         <result column="conditions" property="conditions"/>
         <result column="crons" property="crons"/>
         <result column="config_cells" property="configCells"/>