chendayu 2 years ago
parent
commit
781b78a283

+ 101 - 0
RMS/src/main/java/cn/cslg/report/common/model/vo/TaskFromPASVO.java

@@ -0,0 +1,101 @@
+package cn.cslg.report.common.model.vo;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 装载分析系统返回的任务对象
+ *
+ * @Author chenyu
+ * @Date 2023/7/31
+ */
+@Accessors(chain = true)
+@Data
+public class TaskFromPASVO implements Serializable {
+    /**
+     * 任务类型 1.Excel导入 2.导出 3.EPO欧专局导入 4.专利之星导入
+     */
+    private Integer type;
+    /**
+     * 创建人
+     */
+    private Integer createBy;
+    /**
+     * 开始时间
+     */
+    private Integer startTime;
+    /**
+     * 专题库id
+     */
+    private Integer projectId;
+    /**
+     * 报告id
+     */
+    private Integer reportId;
+    /**
+     * 导入导出字段数量
+     */
+    private Integer fieldNum;
+    /**
+     * 专利数量
+     */
+    private Integer total;
+    /**
+     * 完成时间
+     */
+    private Integer endTime;
+    /**
+     * 任务状态(0.队列中 1.进行中 2.已完成 4.已暂停 5.已取消)
+     */
+    private Integer status;
+    /**
+     * 文件名
+     */
+    private String fileName;
+    /**
+     * 文件大小
+     */
+    private Long fileSize;
+    /**
+     * 完成条数(非成功条数)
+     */
+    private Integer successNum;
+    /**
+     * 成功条数
+     */
+    private Integer trueSuccessNum;
+    /**
+     * 失败条数
+     */
+    private Integer defaultNum;
+    /**
+     * 自定义字段文件夹信息json格式
+     */
+    private String pramJson;
+    /**
+     * 导入详细excel连接
+     */
+    private String url;
+    private Integer productId;
+    /**
+     * Excel文件原名称
+     */
+    private String oldName;
+    /**
+     * 所属任务条件id
+     */
+    private Integer taskConditionId;
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+    /**
+     * 任务类型1(0普通任务 1定时任务)
+     */
+    private Integer taskType;
+
+}

+ 24 - 1
RMS/src/main/java/cn/cslg/report/controller/DownloadController.java

@@ -1,10 +1,16 @@
 package cn.cslg.report.controller;
 package cn.cslg.report.controller;
 
 
 import cn.cslg.report.common.core.base.Constants;
 import cn.cslg.report.common.core.base.Constants;
+import cn.cslg.report.common.model.vo.TaskFromPASVO;
 import cn.cslg.report.common.utils.DateUtils;
 import cn.cslg.report.common.utils.DateUtils;
 import cn.cslg.report.common.utils.FileUtils;
 import cn.cslg.report.common.utils.FileUtils;
 
 
+import cn.cslg.report.entity.Task;
+import cn.cslg.report.service.OutInterfaceService;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSON;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
@@ -18,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
 import java.net.URLEncoder;
 import java.net.URLEncoder;
+import java.util.List;
 
 
 @Tag(name = "下载")
 @Tag(name = "下载")
 @RestController
 @RestController
@@ -25,11 +32,27 @@ import java.net.URLEncoder;
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class DownloadController {
 public class DownloadController {
     private final FileUtils fileUtils;
     private final FileUtils fileUtils;
+    private final OutInterfaceService outInterfaceService;
 
 
     @GetMapping("downloadFile")
     @GetMapping("downloadFile")
     @Operation(summary = "下载文件")
     @Operation(summary = "下载文件")
-    public ResponseEntity<FileSystemResource> downloadSystemFile2(String url) throws IOException {
+    public ResponseEntity<FileSystemResource> downloadSystemFile2(String url, Integer taskId) throws IOException {
         File file = new File(fileUtils.getSystemPath() + url);
         File file = new File(fileUtils.getSystemPath() + url);
+        if (!file.exists()) {
+            if (taskId != null) {
+                //根据任务id,调用分析系统查询任务接口,获得任务对象
+                //String json = outInterfaceService.getTask(taskId);
+                //JSONObject jsonObject = JSONObject.parseObject(json);
+                //TaskFromPASVO task = JSONObject.parseObject(jsonObject.get("data").toString(), TaskFromPASVO.class);
+                //判断若该任务是与报告关联,则调用分析系统的下载接口(目前是为了下载Excel)
+                //if (task.getReportId() != null) {
+                String json2 = outInterfaceService.getDownLoadFile(url);
+                JSONObject jsonObject2 = JSONObject.parseObject(json2);
+                String path = jsonObject2.get("data").toString();
+                file = new File(path);
+                //}
+            }
+        }
         HttpHeaders headers = new HttpHeaders();
         HttpHeaders headers = new HttpHeaders();
         String fileName = DateUtils.getNowTimeFormat(DateUtils.YYYYMMDDHHMMSS) + "." + FileUtil.extName(file.getName());
         String fileName = DateUtils.getNowTimeFormat(DateUtils.YYYYMMDDHHMMSS) + "." + FileUtil.extName(file.getName());
         headers.add("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
         headers.add("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));

+ 31 - 0
RMS/src/main/java/cn/cslg/report/service/OutInterfaceService.java

@@ -645,4 +645,35 @@ public class OutInterfaceService {
         return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
         return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
     }
     }
 
 
+    /**
+     * 调用分析系统根据任务id查询任务接口
+     *
+     * @param taskId 任务id
+     * @return 返回任务
+     */
+    public String getTask(Integer taskId) throws IOException {
+        OkHttpClient okHttpClient = new OkHttpClient();
+        Request request = new Request.Builder()
+                .url(PASUrl + "/api/v2/task/queryTaskById?taskId=" + taskId)
+                .get()
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
+    /**
+     * 调用分析系统下载接口
+     *
+     * @param url url相对路径
+     * @return 返回ResponseEntity
+     */
+    public String getDownLoadFile(String url) throws IOException {
+        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), url);
+        OkHttpClient okHttpClient = new OkHttpClient();
+        Request request = new Request.Builder()
+                .url(PASUrl + "/api/v2/common/downloadPartUrlFile")
+                .post(requestBody)
+                .build();
+        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
+    }
+
 }
 }