|
|
@@ -1,12 +1,17 @@ |
|
|
|
package com.hz.pm.api.external; |
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.hz.pm.api.meeting.entity.config.WebProps; |
|
|
|
import com.ningdatech.basic.exception.BizException; |
|
|
|
import com.ningdatech.file.entity.File; |
|
|
|
import com.ningdatech.file.service.FileService; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* FilePreviewClient |
|
|
@@ -19,22 +24,32 @@ import org.springframework.stereotype.Component; |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class FilePreviewClient { |
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(FilePreviewClient.class); |
|
|
|
|
|
|
|
@Value("${mh.file-preview.host:http://ztzz2.hzswb.cn/yl}") |
|
|
|
private String mhFilePreviewUrl; |
|
|
|
|
|
|
|
private final FileService fileService; |
|
|
|
|
|
|
|
private static final String FILE_DOWN_NO_AUTH_URL = "/api/v1/file/preview/anonymous/down/"; |
|
|
|
|
|
|
|
//================================================================================================================== |
|
|
|
|
|
|
|
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) { |
|
|
|
String fileDownUrl = WebProps.apiUrl + FILE_DOWN_NO_AUTH_URL + fileId; |
|
|
|
File file = fileService.getById(fileId); |
|
|
|
if (file == null) { |
|
|
|
return StrUtil.EMPTY; |
|
|
|
return String.format(PREVIEW_PATH_FMT, mhFilePreviewUrl, fileDownUrl, file.getSuffix()); |
|
|
|
} |
|
|
|
|
|
|
|
public void downloadFile(Long fileId, HttpServletResponse response) { |
|
|
|
try { |
|
|
|
fileService.download(fileId, response); |
|
|
|
} catch (Exception e) { |
|
|
|
log.info("文件下载失败:{}", fileId, e); |
|
|
|
throw BizException.wrap("文件下载失败:%s", fileId); |
|
|
|
} |
|
|
|
String fileUrl = fileService.findUrlByFile(file); |
|
|
|
return String.format(PREVIEW_PATH_FMT, mhFilePreviewUrl, fileUrl, file.getSuffix()); |
|
|
|
} |
|
|
|
|
|
|
|
} |