Explorar el Código

增加文件预览地址获取接口

tags/24080901
WendyYang hace 9 meses
padre
commit
bd3f8c6300
Se han modificado 4 ficheros con 76 adiciones y 1 borrados
  1. +40
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/FilePreviewClient.java
  2. +34
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/controller/FilePreviewController.java
  3. +1
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/user/security/config/RedisSessionConfig.java
  4. +1
    -1
      hz-pm-api/src/main/java/com/hz/pm/api/user/security/handler/DefaultLoginFailureHandler.java

+ 40
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/FilePreviewClient.java Ver fichero

@@ -0,0 +1,40 @@
package com.hz.pm.api.external;

import cn.hutool.core.util.StrUtil;
import com.ningdatech.file.entity.File;
import com.ningdatech.file.service.FileService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
* <p>
* FilePreviewClient
* </p>
*
* @author WendyYang
* @since 09:27 2024/3/18
*/
@Component
@RequiredArgsConstructor
public class FilePreviewClient {

@Value("${mh.file-preview.host:http://ztzz2.hzswb.cn/yl}")
private String mhFilePreviewUrl;

private final FileService fileService;

//==================================================================================================================

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) {
File file = fileService.getById(fileId);
if (file == null) {
return StrUtil.EMPTY;
}
String fileUrl = fileService.findUrlByFile(file);
return String.format(PREVIEW_PATH_FMT, mhFilePreviewUrl, fileUrl, file.getSuffix());
}

}

+ 34
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/controller/FilePreviewController.java Ver fichero

@@ -0,0 +1,34 @@
package com.hz.pm.api.external.controller;

import com.hz.pm.api.external.FilePreviewClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
* FilePreviewController
* </p>
*
* @author WendyYang
* @since 10:01 2024/3/18
*/
@Api(tags = "文件预览外部服务")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/file/preview")
public class FilePreviewController {

private final FilePreviewClient filePreviewClient;

@ApiOperation("获取文件的预览地址")
@GetMapping("/getFilePreviewUrl/{fileId}")
public String getFilePreviewUrl(@PathVariable Long fileId) {
return filePreviewClient.getFilePreviewUrl(fileId);
}

}

+ 1
- 0
hz-pm-api/src/main/java/com/hz/pm/api/user/security/config/RedisSessionConfig.java Ver fichero

@@ -29,6 +29,7 @@ public class RedisSessionConfig {
DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
sessionIdResolver.setCookieSerializer(cookieSerializer);
// 设置到 sessionIdResolver 中
cookieSerializer.setCookiePath("/hzpm/");
cookieSerializer.setCookieName(BizConst.COOKIE_KEY);
cookieSerializer.setCookieMaxAge(SessionTimeConst.SESSION_TIME_SECONDS);
return sessionIdResolver;


+ 1
- 1
hz-pm-api/src/main/java/com/hz/pm/api/user/security/handler/DefaultLoginFailureHandler.java Ver fichero

@@ -27,7 +27,7 @@ public class DefaultLoginFailureHandler extends SimpleUrlAuthenticationFailureHa

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException, ServletException {
AuthenticationException exception) throws IOException {
response.setContentType("application/json;charset=UTF-8");
int errorCode;
String errorMsg;


Cargando…
Cancelar
Guardar