fix(项目报告): 定时任务发送的报告图像内容国际化优化
定时任务发送的报告图像内容根据创建用户所选择的语言而进行国际化优化
This commit is contained in:
parent
6cdc67b339
commit
75c6378c6c
|
@ -250,7 +250,7 @@ public class ReportStatisticsService {
|
||||||
return reportStatisticsMapper.selectByExample(example);
|
return reportStatisticsMapper.selectByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getImageContentById(ReportStatisticsWithBLOBs reportRecordId) {
|
public String getImageContentById(ReportStatisticsWithBLOBs reportRecordId, String language) {
|
||||||
ChromeUtils chromeUtils = ChromeUtils.getInstance();
|
ChromeUtils chromeUtils = ChromeUtils.getInstance();
|
||||||
HeadlessRequest headlessRequest = new HeadlessRequest();
|
HeadlessRequest headlessRequest = new HeadlessRequest();
|
||||||
BaseSystemConfigDTO baseInfo = CommonBeanFactory.getBean(SystemParameterService.class).getBaseInfo();
|
BaseSystemConfigDTO baseInfo = CommonBeanFactory.getBean(SystemParameterService.class).getBaseInfo();
|
||||||
|
@ -264,7 +264,7 @@ public class ReportStatisticsService {
|
||||||
platformUrl += "/echartPic?shareId=" + reportRecordId.getId();
|
platformUrl += "/echartPic?shareId=" + reportRecordId.getId();
|
||||||
headlessRequest.setUrl(platformUrl);
|
headlessRequest.setUrl(platformUrl);
|
||||||
headlessRequest.setRemoteDriverUrl(remoteDriverUrl);
|
headlessRequest.setRemoteDriverUrl(remoteDriverUrl);
|
||||||
String imageData = chromeUtils.getImageInfo(headlessRequest);
|
String imageData = chromeUtils.getImageInfo(headlessRequest, language);
|
||||||
return imageData;
|
return imageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ChromeUtils {
|
public class ChromeUtils {
|
||||||
private static ChromeUtils chromeUtils = new ChromeUtils();
|
private static ChromeUtils chromeUtils = new ChromeUtils();
|
||||||
|
@ -21,24 +23,26 @@ public class ChromeUtils {
|
||||||
return chromeUtils;
|
return chromeUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized WebDriver genWebDriver(HeadlessRequest headlessRequest) {
|
private synchronized WebDriver genWebDriver(HeadlessRequest headlessRequest, String language) {
|
||||||
if (headlessRequest.isEmpty()) {
|
if (headlessRequest.isEmpty()) {
|
||||||
LogUtil.error("Headless request is null! " + JSON.toJSONString(headlessRequest));
|
LogUtil.error("Headless request is null! " + JSON.toJSONString(headlessRequest));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//初始化一个chrome浏览器实例driver
|
//初始化一个chrome浏览器实例driver
|
||||||
ChromeOptions options = new ChromeOptions();
|
ChromeOptions options = new ChromeOptions();
|
||||||
options.addArguments("headless");
|
|
||||||
options.addArguments("no-sandbox");
|
if (StringUtils.isEmpty(language)) {
|
||||||
options.addArguments("disable-gpu");
|
language = "zh-cn";
|
||||||
options.addArguments("disable-features=NetworkService");
|
}
|
||||||
options.addArguments("ignore-certificate-errors");
|
if (StringUtils.equalsAnyIgnoreCase(language, "zh-cn")) {
|
||||||
options.addArguments("silent-launch");
|
Map<String, Object> optionMap = new HashMap<>();
|
||||||
options.addArguments("disable-application-cache");
|
optionMap.put("intl.accept_languages", "zh-CN,en,en_US");
|
||||||
options.addArguments("disable-web-security");
|
options.setExperimentalOption("prefs", optionMap);
|
||||||
options.addArguments("no-proxy-server");
|
} else if (StringUtils.equalsAnyIgnoreCase(language, "zh_tw")) {
|
||||||
options.addArguments("disable-dev-shm-usage");
|
Map<String, Object> optionMap = new HashMap<>();
|
||||||
options.addArguments("lang=zh_CN.UTF-8");
|
optionMap.put("intl.accept_languages", "zh-TW,en,en_US");
|
||||||
|
options.setExperimentalOption("prefs", optionMap);
|
||||||
|
}
|
||||||
|
|
||||||
WebDriver driver = null;
|
WebDriver driver = null;
|
||||||
try {
|
try {
|
||||||
|
@ -55,8 +59,8 @@ public class ChromeUtils {
|
||||||
return driver;
|
return driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String getImageInfo(HeadlessRequest request) {
|
public synchronized String getImageInfo(HeadlessRequest request, String langurage) {
|
||||||
WebDriver driver = this.genWebDriver(request);
|
WebDriver driver = this.genWebDriver(request, langurage);
|
||||||
String files = null;
|
String files = null;
|
||||||
if (driver != null) {
|
if (driver != null) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit a618ef0fb1ae45790e0c7de9805c8ff17c9df5be
|
Subproject commit fcc6073110adde4f6a67833046a7346721602fd0
|
Loading…
Reference in New Issue