|
|
@@ -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; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
@@ -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<MhFileInfoDTO> 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) { |
|
|
|