fix(X-Pack): 设置动态访问路径后导出pdf失败 #12945
This commit is contained in:
parent
3f69c5393f
commit
d8eb9f12f3
@ -2,7 +2,11 @@ package io.dataease.commons.utils;
|
||||
|
||||
import io.dataease.commons.constants.AuthConstants;
|
||||
import io.dataease.plugins.common.util.SpringContextUtil;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -10,8 +14,18 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
@Component
|
||||
public class ServletUtils {
|
||||
|
||||
|
||||
@Getter
|
||||
private static String contextPath;
|
||||
|
||||
@Value("${server.servlet.context-path:#{null}}")
|
||||
public void setContextPath(String contextPath) {
|
||||
ServletUtils.contextPath = contextPath;
|
||||
}
|
||||
|
||||
public static HttpServletRequest request() {
|
||||
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = servletRequestAttributes.getRequest();
|
||||
@ -48,8 +62,7 @@ public class ServletUtils {
|
||||
}
|
||||
Environment environment = SpringContextUtil.getBean(Environment.class);
|
||||
Integer port = environment.getProperty("server.port", Integer.class);
|
||||
return "http://" + hostAddress + ":" + port;
|
||||
return "http://" + hostAddress + ":" + port + (StringUtils.isBlank(contextPath) ? "" : contextPath);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -30,8 +30,6 @@ public class IndexController {
|
||||
@Resource
|
||||
private PanelLinkService panelLinkService;
|
||||
|
||||
@Value("${server.servlet.context-path:#{null}}")
|
||||
private String contextPath;
|
||||
|
||||
@GetMapping(value = "/")
|
||||
public String index() {
|
||||
@ -56,6 +54,7 @@ public class IndexController {
|
||||
} else {
|
||||
url = panelLinkService.getUrlByUuid(index);
|
||||
}
|
||||
String contextPath = ServletUtils.getContextPath();
|
||||
if (StringUtils.isNotBlank(contextPath)) {
|
||||
url = contextPath + url;
|
||||
}
|
||||
@ -85,6 +84,7 @@ public class IndexController {
|
||||
@GetMapping("/tempMobileLink/{id}/{token}")
|
||||
public void tempMobileLink(@PathVariable("id") String id, @PathVariable("token") String token) {
|
||||
String url = "/#preview/" + id;
|
||||
String contextPath = ServletUtils.getContextPath();
|
||||
if (StringUtils.isNotBlank(contextPath)) {
|
||||
url = contextPath + url;
|
||||
}
|
||||
|
||||
@ -36,8 +36,7 @@ public class PanelLinkService {
|
||||
private static final String USERPARAM = "&user=";
|
||||
private static final String SHORT_URL_PREFIX = "/link/";
|
||||
|
||||
@Value("${server.servlet.context-path:#{null}}")
|
||||
private String contextPath;
|
||||
|
||||
|
||||
@Resource
|
||||
private PanelLinkMapper mapper;
|
||||
@ -281,6 +280,7 @@ public class PanelLinkService {
|
||||
List<PanelLinkMapping> mappings = panelLinkMappingMapper.selectByExample(example);
|
||||
PanelLinkMapping mapping = mappings.get(0);
|
||||
String uuid = mapping.getUuid();
|
||||
String contextPath = ServletUtils.getContextPath();
|
||||
return (StringUtils.isNotBlank(contextPath) ? contextPath : "") + SHORT_URL_PREFIX + (StringUtils.isBlank(uuid) ? mapping.getId() : uuid);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user