@@ -1,12 +1,17 @@ | |||||
package com.hz.pm.api.external; | 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.entity.File; | ||||
import com.ningdatech.file.service.FileService; | import com.ningdatech.file.service.FileService; | ||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
import javax.servlet.http.HttpServletResponse; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
* FilePreviewClient | * FilePreviewClient | ||||
@@ -19,22 +24,32 @@ import org.springframework.stereotype.Component; | |||||
@RequiredArgsConstructor | @RequiredArgsConstructor | ||||
public class FilePreviewClient { | public class FilePreviewClient { | ||||
private static final Logger log = LoggerFactory.getLogger(FilePreviewClient.class); | |||||
@Value("${mh.file-preview.host:http://ztzz2.hzswb.cn/yl}") | @Value("${mh.file-preview.host:http://ztzz2.hzswb.cn/yl}") | ||||
private String mhFilePreviewUrl; | private String mhFilePreviewUrl; | ||||
private final FileService fileService; | 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"; | 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) { | public String getFilePreviewUrl(Long fileId) { | ||||
String fileDownUrl = WebProps.apiUrl + FILE_DOWN_NO_AUTH_URL + fileId; | |||||
File file = fileService.getById(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()); | |||||
} | } | ||||
} | } |
@@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.PathVariable; | |||||
import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
import javax.servlet.http.HttpServletResponse; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
* FilePreviewController | * FilePreviewController | ||||
@@ -31,4 +33,10 @@ public class FilePreviewController { | |||||
return filePreviewClient.getFilePreviewUrl(fileId); | return filePreviewClient.getFilePreviewUrl(fileId); | ||||
} | } | ||||
@ApiOperation("文件下载(不鉴权)") | |||||
@GetMapping("/anonymous/down/{fileId}") | |||||
public void anonymousFileDown(@PathVariable Long fileId, HttpServletResponse response) { | |||||
filePreviewClient.downloadFile(fileId, response); | |||||
} | |||||
} | } |
@@ -16,12 +16,18 @@ import org.springframework.stereotype.Component; | |||||
@Component | @Component | ||||
public class WebProps { | public class WebProps { | ||||
public static String apiHost; | |||||
public static String loginUrl; | |||||
public static String apiUrl; | |||||
@Value("${api-host:}") | |||||
private void setApiHost(String host) { | |||||
apiHost = host; | |||||
@Value("${web.login.url:}") | |||||
private void setLoginUrl(String url) { | |||||
loginUrl = url; | |||||
} | |||||
@Value("${web.api.url:}") | |||||
private void setApiUrl(String url) { | |||||
apiUrl = url; | |||||
} | } | ||||
} | } |
@@ -109,7 +109,7 @@ public class UserAuthController { | |||||
} | } | ||||
String authCode = authCodeLoginManage.generateAuthCode(targetUserId); | String authCode = authCodeLoginManage.generateAuthCode(targetUserId); | ||||
String urlParam = "?authCode=" + authCode; | String urlParam = "?authCode=" + authCode; | ||||
String path = WebProps.apiHost + request.getContextPath() + AUTH_CODE_LOGIN_PATH; | |||||
String path = WebProps.apiUrl + request.getContextPath() + AUTH_CODE_LOGIN_PATH; | |||||
response.sendRedirect(path + urlParam); | response.sendRedirect(path + urlParam); | ||||
} | } | ||||
@@ -210,4 +210,10 @@ reminder-task: | |||||
open: false | open: false | ||||
cron: 0 30 8 * * ? | cron: 0 30 8 * * ? | ||||
hz-pm: | hz-pm: | ||||
interfaceKey: hz_meeting_expert_info | |||||
interfaceKey: hz_meeting_expert_info | |||||
web: | |||||
login: | |||||
url: http://hzpm.ningdatech.com | |||||
api: | |||||
url: http://hzpm.ningdatech.com/hzpm |
@@ -178,7 +178,11 @@ login: | |||||
skip: false | skip: false | ||||
url: http://60.188.225.145/login | url: http://60.188.225.145/login | ||||
web: | web: | ||||
url: http://60.188.225.145 | |||||
login: | |||||
url: | |||||
api: | |||||
url: | |||||
mh: | mh: | ||||
sso: | sso: | ||||
client-id: ningda-74a5e5da-3bc3-414a-b9e6-004b7d87e310 | client-id: ningda-74a5e5da-3bc3-414a-b9e6-004b7d87e310 | ||||
@@ -8,6 +8,7 @@ security: | |||||
logout-url: /api/v1/user/auth/logout | logout-url: /api/v1/user/auth/logout | ||||
common-login-url: /api/v1/user/auth/common-login | common-login-url: /api/v1/user/auth/common-login | ||||
ignore-auth-urls: | ignore-auth-urls: | ||||
- /**/anonymous/** | |||||
- /v2/api-docs | - /v2/api-docs | ||||
- /swagger-ui.html | - /swagger-ui.html | ||||
- /webjars/** | - /webjars/** | ||||
@@ -43,6 +44,7 @@ security: | |||||
- /expert/ephemeral/*/registration | - /expert/ephemeral/*/registration | ||||
- /api/v1/mh/sync/** | - /api/v1/mh/sync/** | ||||
ignore-csrf-urls: | ignore-csrf-urls: | ||||
- /**/anonymous/** | |||||
- /api/v1/user/auth/** | - /api/v1/user/auth/** | ||||
- /v2/api-docs | - /v2/api-docs | ||||
- /swagger-ui.html | - /swagger-ui.html | ||||
@@ -8,6 +8,7 @@ security: | |||||
logout-url: /api/v1/user/auth/logout | logout-url: /api/v1/user/auth/logout | ||||
common-login-url: /api/v1/user/auth/common-login | common-login-url: /api/v1/user/auth/common-login | ||||
ignore-auth-urls: | ignore-auth-urls: | ||||
- /**/anonymous/** | |||||
- /v2/api-docs | - /v2/api-docs | ||||
- /swagger-ui.html | - /swagger-ui.html | ||||
- /webjars/** | - /webjars/** | ||||
@@ -43,6 +44,7 @@ security: | |||||
- /expert/ephemeral/*/registration | - /expert/ephemeral/*/registration | ||||
- /api/v1/mh/sync/** | - /api/v1/mh/sync/** | ||||
ignore-csrf-urls: | ignore-csrf-urls: | ||||
- /**/anonymous/** | |||||
- /api/v1/user/auth/** | - /api/v1/user/auth/** | ||||
- /v2/api-docs | - /v2/api-docs | ||||
- /swagger-ui.html | - /swagger-ui.html | ||||