diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/common/enumeration/FileOrigin.java b/hz-pm-api/src/main/java/com/hz/pm/api/common/enumeration/FileOrigin.java
new file mode 100644
index 0000000..dc12ed8
--- /dev/null
+++ b/hz-pm-api/src/main/java/com/hz/pm/api/common/enumeration/FileOrigin.java
@@ -0,0 +1,43 @@
+package com.hz.pm.api.common.enumeration;
+
+import cn.hutool.core.util.StrUtil;
+import com.ningdatech.basic.exception.BizException;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+/**
+ *
optGet(Integer code) {
+ return Arrays.stream(values()).filter(item -> item.code.equals(code)).findFirst();
+ }
+
+ public static FileOrigin getNoNull(Integer code) {
+ return optGet(code).orElseThrow(() -> BizException.wrap("文件来源无效:%s", code));
+ }
+
+}
diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/FilePreviewClient.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/FilePreviewClient.java
index d20b7d5..57fd9ad 100644
--- a/hz-pm-api/src/main/java/com/hz/pm/api/external/FilePreviewClient.java
+++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/FilePreviewClient.java
@@ -1,6 +1,7 @@
package com.hz.pm.api.external;
-import cn.hutool.http.useragent.UserAgentUtil;
+import cn.hutool.core.util.NumberUtil;
+import com.hz.pm.api.external.model.dto.MhFileInfoDTO;
import com.hz.pm.api.meeting.entity.config.WebProps;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.file.entity.File;
@@ -13,6 +14,7 @@ import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.util.List;
/**
*
@@ -35,26 +37,40 @@ public class FilePreviewClient {
private String mhFilePreviewPrivateUrl;
private final FileService fileService;
+ private final MhFileClient mhFileClient;
private static final String FILE_DOWN_NO_AUTH_URL = "/api/v1/file/preview/anonymous/down/";
+ private static final String MH_DOWN_FILE_URL = "/api/v1/mh/anonymous/file/download/";
+
+
//==================================================================================================================
private static final String PREVIEW_PATH_FMT = "%s/public/risen/core/resrc/view/pdf_view.html.do?strMap.remote_url=%s&strMap.ext=%s";
- public String getFilePreviewUrl(Long fileId, HttpServletRequest request) {
+ public String getFilePreviewUrl(String fileId, HttpServletRequest request) {
String serverName = request.getServerName();
log.info("serverName:{}", serverName);
+ StringBuilder fileDownUrl = new StringBuilder();
if (serverName.contains("weixin") || serverName.contains("10.54.38.13")) {
// 浙政钉访问需要转换为互联网可访问的地址
- String fileDownUrl = WebProps.zzdApiUrl + FILE_DOWN_NO_AUTH_URL + fileId;
- File file = fileService.getById(fileId);
- return String.format(PREVIEW_PATH_FMT, mhFilePreviewPublicUrl, fileDownUrl, file.getSuffix());
+ fileDownUrl.append(WebProps.zzdApiUrl);
+ } else {
+ fileDownUrl.append(WebProps.apiUrl);
+ }
+ String fileSuffix;
+ // 信产文件ID为字符串、当前系统文件ID为数字
+ if (!NumberUtil.isLong(fileId)) {
+ List fileInfos = mhFileClient.listFileInfo(fileId);
+ MhFileInfoDTO mhFileInfo = fileInfos.get(0);
+ fileSuffix = mhFileInfo.getFileSuffix();
+ fileDownUrl.append(MH_DOWN_FILE_URL).append(fileId);
} else {
- String fileDownUrl = WebProps.apiUrl + FILE_DOWN_NO_AUTH_URL + fileId;
+ fileDownUrl.append(FILE_DOWN_NO_AUTH_URL).append(fileId);
File file = fileService.getById(fileId);
- return String.format(PREVIEW_PATH_FMT, mhFilePreviewPrivateUrl, fileDownUrl, file.getSuffix());
+ fileSuffix = file.getSuffix();
}
+ return String.format(PREVIEW_PATH_FMT, mhFilePreviewPrivateUrl, fileDownUrl, fileSuffix);
}
public void downloadFile(Long fileId, HttpServletResponse response) {
diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/controller/FilePreviewController.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/controller/FilePreviewController.java
index a3d9883..c9fb6b5 100644
--- a/hz-pm-api/src/main/java/com/hz/pm/api/external/controller/FilePreviewController.java
+++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/controller/FilePreviewController.java
@@ -30,7 +30,7 @@ public class FilePreviewController {
@ApiOperation("获取文件的预览地址")
@GetMapping("/getFilePreviewUrl/{fileId}")
- public String getFilePreviewUrl(@PathVariable Long fileId, HttpServletRequest request) {
+ public String getFilePreviewUrl(@PathVariable String fileId, HttpServletRequest request) {
return filePreviewClient.getFilePreviewUrl(fileId, request);
}
diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/controller/MhApiController.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/controller/MhApiController.java
index 7cadc89..bcda037 100644
--- a/hz-pm-api/src/main/java/com/hz/pm/api/external/controller/MhApiController.java
+++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/controller/MhApiController.java
@@ -32,14 +32,13 @@ public class MhApiController {
private final MhApiClient mhApiClient;
private final MhFileClient mhFileClient;
-
@GetMapping("/dict/listByType/{dictType}")
@ApiOperation("根据字典类型获取字典信息")
public List dictListByType(@PathVariable MhDictType dictType) {
return mhApiClient.dictListByType(dictType);
}
- @GetMapping("/file/download/{fileId}")
+ @GetMapping({"/anonymous/file/download/{fileId}", "/file/download/{fileId}"})
@WebLog("下载信创平台文件")
@ApiOperation("下载信创平台文件")
public void download(@PathVariable String fileId, HttpServletResponse response) {