From bd3f8c6300fbbd424ece15847cad2029c1645ae1 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Mon, 18 Mar 2024 10:30:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E5=9C=B0=E5=9D=80=E8=8E=B7=E5=8F=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hz/pm/api/external/FilePreviewClient.java | 40 ++++++++++++++++++++++ .../external/controller/FilePreviewController.java | 34 ++++++++++++++++++ .../user/security/config/RedisSessionConfig.java | 1 + .../handler/DefaultLoginFailureHandler.java | 2 +- 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 hz-pm-api/src/main/java/com/hz/pm/api/external/FilePreviewClient.java create mode 100644 hz-pm-api/src/main/java/com/hz/pm/api/external/controller/FilePreviewController.java 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 new file mode 100644 index 0000000..b70670d --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/FilePreviewClient.java @@ -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; + +/** + *

+ * FilePreviewClient + *

+ * + * @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()); + } + +} 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 new file mode 100644 index 0000000..7b09165 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/controller/FilePreviewController.java @@ -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; + +/** + *

+ * FilePreviewController + *

+ * + * @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); + } + +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/user/security/config/RedisSessionConfig.java b/hz-pm-api/src/main/java/com/hz/pm/api/user/security/config/RedisSessionConfig.java index 2d55c5b..69a057b 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/user/security/config/RedisSessionConfig.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/user/security/config/RedisSessionConfig.java @@ -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; diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/user/security/handler/DefaultLoginFailureHandler.java b/hz-pm-api/src/main/java/com/hz/pm/api/user/security/handler/DefaultLoginFailureHandler.java index 6f8c4f2..be03526 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/user/security/handler/DefaultLoginFailureHandler.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/user/security/handler/DefaultLoginFailureHandler.java @@ -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;