@@ -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()); | |||||
} | |||||
} |
@@ -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); | |||||
} | |||||
} |
@@ -29,6 +29,7 @@ public class RedisSessionConfig { | |||||
DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer(); | DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer(); | ||||
sessionIdResolver.setCookieSerializer(cookieSerializer); | sessionIdResolver.setCookieSerializer(cookieSerializer); | ||||
// 设置到 sessionIdResolver 中 | // 设置到 sessionIdResolver 中 | ||||
cookieSerializer.setCookiePath("/hzpm/"); | |||||
cookieSerializer.setCookieName(BizConst.COOKIE_KEY); | cookieSerializer.setCookieName(BizConst.COOKIE_KEY); | ||||
cookieSerializer.setCookieMaxAge(SessionTimeConst.SESSION_TIME_SECONDS); | cookieSerializer.setCookieMaxAge(SessionTimeConst.SESSION_TIME_SECONDS); | ||||
return sessionIdResolver; | return sessionIdResolver; | ||||
@@ -27,7 +27,7 @@ public class DefaultLoginFailureHandler extends SimpleUrlAuthenticationFailureHa | |||||
@Override | @Override | ||||
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, | ||||
AuthenticationException exception) throws IOException, ServletException { | |||||
AuthenticationException exception) throws IOException { | |||||
response.setContentType("application/json;charset=UTF-8"); | response.setContentType("application/json;charset=UTF-8"); | ||||
int errorCode; | int errorCode; | ||||
String errorMsg; | String errorMsg; | ||||