chendayu %!s(int64=2) %!d(string=hai) anos
pai
achega
c642c09b54

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

@@ -4,7 +4,9 @@ import cn.cslg.report.common.core.base.Constants;
 import cn.cslg.report.common.utils.DateUtils;
 import cn.cslg.report.common.utils.FileUtils;
 
+import cn.cslg.report.service.OutInterfaceService;
 import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson2.JSONObject;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
@@ -25,11 +27,27 @@ import java.net.URLEncoder;
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class DownloadController {
     private final FileUtils fileUtils;
+    private final OutInterfaceService outInterfaceService;
 
     @GetMapping("downloadFile")
     @Operation(summary = "下载文件")
-    public ResponseEntity<FileSystemResource> downloadSystemFile2(String url) throws IOException {
+    public ResponseEntity<FileSystemResource> downloadSystemFile2(String url, String taskId) throws IOException {
         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();
         String fileName = DateUtils.getNowTimeFormat(DateUtils.YYYYMMDDHHMMSS) + "." + FileUtil.extName(file.getName());
         headers.add("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));

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

@@ -646,4 +646,37 @@ public class OutInterfaceService {
         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();
+    }
+
+
 }