From ca9baeb8c3e22aa292dabae3bf9f27aaf0022bb2 Mon Sep 17 00:00:00 2001 From: shizhendong Date: Thu, 12 Oct 2023 14:36:57 +0800 Subject: fix: NEZ-3216 指定 chrome 二进制文件目录 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dashboard/service/impl/VisualServiceImpl.java | 50 ++++++++++------------ 1 file 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 @@ -646,6 +646,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 * @@ -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 templateDataParam = MapUtil.builder() .put("paragraphList", paragraphList) .map(); -- cgit v1.2.3