dataease-dm/backend/src/main/java/io/dataease/controller/IndexController.java

95 lines
3.2 KiB
Java
Raw Normal View History

2021-02-20 10:07:25 +08:00
package io.dataease.controller;
2021-12-07 11:26:58 +08:00
import io.dataease.commons.exception.DEException;
2021-08-11 14:58:29 +08:00
import io.dataease.commons.license.DefaultLicenseService;
import io.dataease.commons.license.F2CLicenseResponse;
import io.dataease.commons.utils.CodingUtil;
2021-12-07 11:26:58 +08:00
import io.dataease.commons.utils.LogUtil;
2021-11-11 16:56:54 +08:00
import io.dataease.commons.utils.ServletUtils;
import io.dataease.service.panel.PanelLinkService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpRequest;
2021-02-20 10:07:25 +08:00
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
2021-11-11 16:56:54 +08:00
import org.springframework.web.bind.annotation.PathVariable;
2021-02-20 10:07:25 +08:00
import org.springframework.web.bind.annotation.RequestMapping;
2021-08-11 14:58:29 +08:00
import javax.annotation.Resource;
2021-11-11 16:56:54 +08:00
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
2021-11-11 16:56:54 +08:00
import javax.servlet.http.HttpServletResponse;
2021-12-06 11:04:55 +08:00
import java.io.IOException;
2021-08-11 14:58:29 +08:00
2021-02-20 10:07:25 +08:00
@Controller
@RequestMapping
public class IndexController {
2021-12-18 22:35:59 +08:00
private static final int FOR_EVER = 3600 * 24 * 30 * 12 * 10; // 10 years in second
2021-08-11 14:58:29 +08:00
@Resource
private DefaultLicenseService defaultLicenseService;
2021-11-11 16:56:54 +08:00
@Resource
private PanelLinkService panelLinkService;
2021-02-20 10:07:25 +08:00
@GetMapping(value = "/")
public String index() {
return "index.html";
}
@GetMapping(value = "/login")
public String login() {
2021-03-25 18:58:05 +08:00
return "index.html";
}
2021-08-11 14:58:29 +08:00
@GetMapping("/deApi")
public String deApi() {
F2CLicenseResponse f2CLicenseResponse = defaultLicenseService.validateLicense();
switch (f2CLicenseResponse.getStatus()) {
case valid:
return "doc.html";
default:
2022-02-24 17:25:59 +08:00
// return "nolic.html";
return "doc.html";
2021-08-11 14:58:29 +08:00
}
2021-11-11 16:56:54 +08:00
}
2021-11-26 11:38:25 +08:00
@GetMapping("/link/{index}")
public void link(@PathVariable(value = "index", required = true) String index) {
String url;
if (CodingUtil.isNumeric(index)) {
url = panelLinkService.getUrlByIndex(Long.parseLong(index));
2022-02-16 16:10:39 +08:00
} else {
url = panelLinkService.getUrlByUuid(index);
}
2021-11-11 16:56:54 +08:00
HttpServletResponse response = ServletUtils.response();
2021-12-06 11:04:55 +08:00
try {
// TODO 增加仪表板外部参数
HttpServletRequest request = ServletUtils.request();
String attachParams = request.getParameter("attachParams");
if(StringUtils.isNotEmpty(attachParams)){
url = url+"&attachParams="+attachParams;
}
2021-12-06 11:04:55 +08:00
response.sendRedirect(url);
} catch (IOException e) {
2021-12-07 11:26:58 +08:00
LogUtil.error(e.getMessage());
DEException.throwException(e);
2021-12-06 11:04:55 +08:00
}
2021-08-11 14:58:29 +08:00
}
2021-12-18 22:35:59 +08:00
@GetMapping("/tempMobileLink/{id}/{token}")
public void tempMobileLink(@PathVariable("id") String id, @PathVariable("token") String token) {
2021-12-20 14:42:19 +08:00
String url = "/#preview/" + id;
2021-12-18 22:35:59 +08:00
HttpServletResponse response = ServletUtils.response();
Cookie cookie = new Cookie("Authorization", token);
cookie.setPath("/");
cookie.setMaxAge(FOR_EVER);
response.addCookie(cookie);
try {
response.sendRedirect(url);
} catch (IOException e) {
LogUtil.error(e.getMessage());
DEException.throwException(e);
}
}
2021-03-25 18:58:05 +08:00
2021-02-20 10:07:25 +08:00
}