diff options
| author | shizhendong <[email protected]> | 2023-10-12 14:36:57 +0800 |
|---|---|---|
| committer | shizhendong <[email protected]> | 2023-10-12 14:36:57 +0800 |
| commit | ca9baeb8c3e22aa292dabae3bf9f27aaf0022bb2 (patch) | |
| tree | 8b659bdffc362393fdf3ad3974aa2413ae662e5d | |
| parent | 16bde6e0603c2e0b5e0a1866fead4a07fa531d3b (diff) | |
fix: NEZ-3216 指定 chrome 二进制文件目录rel-23.10.02
| -rw-r--r-- | nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualServiceImpl.java | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualServiceImpl.java index bb0ac1db..58c91a4e 100644 --- a/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualServiceImpl.java +++ b/nz-admin/src/main/java/com/nis/modules/dashboard/service/impl/VisualServiceImpl.java @@ -647,6 +647,26 @@ public class VisualServiceImpl implements VisualService { } /** + * create chrome driver + * + * @return + */ + private ChromeDriver createChromeDriver() { + final var chromeOptions = new ChromeOptions(); + chromeOptions.addArguments( + "--headless", + "--disable-cache", + "--disable-dev-shm-usage", + "--no-sandbox", + "--window-size=1920x1080" + ); + chromeOptions.setBinary("./lib/chrome-linux64/chrome"); + + ChromeDriver chromeDriver = new ChromeDriver(chromeOptions); + return chromeDriver; + } + + /** * html to pdf * * @param taskId @@ -658,22 +678,12 @@ public class VisualServiceImpl implements VisualService { StopWatch sw = new StopWatch(); sw.start(); - ChromeDriver driver = null; + ChromeDriver driver = this.createChromeDriver(); File tempFile = null; try { tempFile = Tool.FileUtil.file(Tool.StrUtil.concat(true, Constant.TEMP_PATH, File.separator, taskId, ".html")); FileUtil.writeUtf8String(htmlContent, tempFile); - ChromeOptions opt = new ChromeOptions(); - opt.addArguments( - "--headless", - "--disable-cache", - "--disable-dev-shm-usage", - "--no-sandbox", - "--window-size=1920x1080" - ); - - driver = new ChromeDriver(opt); driver.resetInputState(); driver.get("file://" + tempFile.getAbsolutePath()); @@ -716,22 +726,12 @@ public class VisualServiceImpl implements VisualService { StopWatch sw = new StopWatch(); sw.start(); - ChromeDriver driver = null; + ChromeDriver driver = this.createChromeDriver(); File tempFile = null; try { tempFile = Tool.FileUtil.file(Tool.StrUtil.concat(true, Constant.TEMP_PATH, File.separator, taskId, ".html")); FileUtil.writeUtf8String(htmlContent, tempFile); - ChromeOptions opt = new ChromeOptions(); - opt.addArguments( - "--headless", - "--disable-cache", - "--disable-dev-shm-usage", - "--no-sandbox", - "--window-size=1920x1080" - ); - - driver = new ChromeDriver(opt); driver.resetInputState(); driver.get("file://" + tempFile.getAbsolutePath()); @@ -783,12 +783,6 @@ public class VisualServiceImpl implements VisualService { paragraphList.add(tempNodeMap); } - // 按照 chart.Y 排序 - paragraphList.sort(Comparator.comparing(m -> { - VisualChart tempChartForSort = MapUtil.get(m, "chart", VisualChart.class); - return tempChartForSort.getY() == null ? -2D : tempChartForSort.getY(); - })); - Map<Object, Object> templateDataParam = MapUtil.builder() .put("paragraphList", paragraphList) .map(); |
