Переглянути джерело

fix:

1. 文件预览修改;
tags/24112201
WendyYang 1 місяць тому
джерело
коміт
e24ead95fd
4 змінених файлів з 68 додано та 10 видалено
  1. +43
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/common/enumeration/FileOrigin.java
  2. +23
    -7
      hz-pm-api/src/main/java/com/hz/pm/api/external/FilePreviewClient.java
  3. +1
    -1
      hz-pm-api/src/main/java/com/hz/pm/api/external/controller/FilePreviewController.java
  4. +1
    -2
      hz-pm-api/src/main/java/com/hz/pm/api/external/controller/MhApiController.java

+ 43
- 0
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;

/**
* <p>
* FileOrigin
* </p>
*
* @author WendyYang
* @since 21:11 2024/11/18
*/
@Getter
@AllArgsConstructor
public enum FileOrigin {

MH("信产文件", 1),

OSS("OSS存储文件", 2);

private final String val;
private final Integer code;


public static String getVal(Integer code) {
return optGet(code).flatMap(t -> Optional.of(t.val)).orElse(StrUtil.EMPTY);
}

public static Optional<FileOrigin> 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));
}

}

+ 23
- 7
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;

/**
* <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) {


+ 1
- 1
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);
}



+ 1
- 2
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<MhDictDTO> 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) {


Завантаження…
Відмінити
Зберегти