Method for generating graphic report based on calling of server
Through direct communication with real browsers and Echarts' chart rendering, combined with Poi-tl's document processing, the compatibility and security risks of PhantomJS are solved, and efficient and reliable server-side call generation graphical reports are achieved, which improves users Experience and technical support.
Patent Information
- Application Number
- CN202410974064.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2044-07-19
AI Technical Summary
Existing server calls front-end page generation chart methods, such as PhantomJS, have compatibility issues, security risks and insufficient ecological support, making it difficult to achieve efficient and reliable timed reports.
Selenium communicates directly with real browsers, combined with Echarts and Poi-tl technology, the server calls the front-end page to generate graphical reports, and uses Selenium's page DOM probe technology to ensure normal return and resource management of chart file streams.
It avoids compatibility issues and security risks of PhantomJS, improves user experience, reduces the invasiveness of business code, and provides more complete ecological support and technical upgrade guarantees.
Smart Images

Figure CN118981576A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of computer processing technology and file processing, and in particular to a method and system for generating graphic reports by periodic calling at a server. Background Art
[0002] The production of various reports has always been a large part of the daily work of corporate employees. However, for report forms with fixed formats and strong objectivity, using software programs to automatically generate them is undoubtedly a more efficient solution.
[0003] The report generated by the above-mentioned program generally contains narrative text and functional charts. For functional charts, it is difficult to make charts with exquisite UI interface and complete functions based on the existing server-side technology and server-side technology positioning, so it is necessary to rely on front-end technology to realize the production of charts.
[0004] The front-end chart production can perfectly solve the above problems in terms of content, but it is difficult to achieve the same timed scheduling effect as the server in terms of process control, which goes against our original intention of automatically generating reports on a regular basis. This leads to the core of this application, how to make the server call the front-end page to generate report charts on a regular basis.
[0005] In the existing public technologies, PhantomJS technology is generally used to implement the above scenarios. PhantomJS is a headless WebKit script with its own JavaScript API. It has fast and native support for various web standards, including DOM processing, CSS selectors, JSON, Canvas and SVG. PhantomJS is simply a programmable headless browser. The so-called headless browser is actually a browser kernel, including js parsing engine, rendering engine, request processing, etc., but does not include a browser for displaying and user interaction pages. The usual practice is: introduce PhantomJS related libraries into the server program, after splicing the data required for the chart in the program, connect PhantomJS by calling the cmd command, and use the js script written in advance for data parsing to render the page, generate the chart, and then return the chart file to the server through the front-end technology.
[0006] Although PhantomJS has realized the need for the server to call the front-end page, it also has a fatal flaw: PhantomJS has announced that it will suspend maintenance in 2018. This is undoubtedly a huge security risk for production projects, and there are problems with technical support and ecological support in the later use process. In addition, the applicant has recently discovered during the use of PhantomJS that PhantomJS has compatibility issues with some of the more mainstream front-end technologies. For example, when using the html2canvas front-end screenshot tool to generate images, the js rendered on PhantomJS will produce blank images, and will not be recognized when inserted into Word.
[0007] In summary, in order to overcome the deficiencies of the prior art, a more efficient and reliable method and system for generating graphic reports based on server calls is needed. Summary of the invention
[0008] The purpose of the present invention is to overcome the deficiencies of the existing technology and provide a more efficient and reliable method and system for generating graphic reports based on server calls.
[0009] In order to solve the above technical problems, the technical solution of the present invention is a method for generating graphic reports based on server-side calls, and the specific implementation steps are as follows:
[0010] The steps are as follows: Step 1: Based on the Linux server, install a web browser on the server, such as mainstream ones such as Chrome, Firefox, etc., and install the system fonts required for graphic report rendering on the server.
[0011] Step 2: Front-end (network) coding to implement relevant functions of chart generation, including calling the server-side interface to obtain the data required for the chart when the page is initialized, using Echarts technology to complete the drawing of the chart, and after the page is loaded, calling the Echarts related API to convert the chart into a file stream back to the server, and providing a link entry for server-side access.
[0012] Step 3: Backend (data and logic processing) coding, introducing Selenium-related dependencies, and configuring the driver corresponding to the browser version installed on the remote server. The server calls the SDK provided by Selenium, uses the driver to communicate with the server browser, creates a server browser access process, and accesses the link provided in step 2 to complete the call to the front-end page.
[0013] Step 4: Configure the general template (.docx) of the report that the program needs to generate. Use anchor technology and open source technology Poi-tl to insert the chart file returned by the front end in step 3 into the corresponding position of the report and regenerate a new report (.docx).
[0014] Step 2: Based on the React client framework coding, introduce the Echarts open source library to implement functions such as rendering, monitoring, documenting, and sending back to the file server for graphic reports. The process is as follows:
[0015] 1) Use npm to import the React version of Echarts open source library
[0016] 2) Use the init method provided by Echarts to initialize the graphic report and generate rendering settings
[0017] 3) Use the rendering completion listener event provided by Echarts to monitor the rendering process
[0018] 4) After rendering is completed, use the getDataURL method provided by Echarts to complete the file of the report
[0019] 5) Call the service to upload the file interface and persist the graphic report on the file server
[0020] Step 3: Based on the Java server-side coding, Selenium WebDriver 3.x is referenced to implement the server-side application to control the behavior of the web browser, actively render the graphic report provided in step 2 in the web browser to generate the URL, and then trigger the graphic report produced in step 2 to persist in the server-side file server, and at the same time call a series of SKD methods provided by Selenium to complete the monitoring of page rendering completion, and disconnect the communication between the server-side application and the web browser. The main process is as follows:
[0021] 1) Use Maven dependency management to introduce Selenium WebDriver 3.x library packages into the server
[0022] 2) The server introduces the Selenium Manager driver that matches the local web browser version
[0023] 3) new ChromeDriver (ChromeOptions) completes the initialization of WebDriver, including driver location loading, web browser access settings, etc.
[0024] 4) Call the WebDriver.get() SDK method provided by WebDriver to establish communication between the server and the web browser, and automatically trigger the graphical report generation URL rendering
[0025] 5) Graphic report generation page renders the graphic report. After rendering, it is filed and persisted on the server file server
[0026] 6) Quit provided by WebDriver closes the communication between the server and the web browser and releases resources;
[0027] In step 3, in order to achieve the effect of reasonable allocation and utilization of server resources and rapid reversal of the entire server-side call to generate graphic reports, Selenium is used to provide a page DOM probe technology. The server continuously detects the successful DOM nodes agreed in advance with the front-end. If the detection is successful, it can accurately know that the current page chart file stream has been returned normally, and then the communication channel established between the current server and the web browser is closed to achieve server resource scheduling and allocation and the next step of reversing the overall process.
[0028] Specifically, the server and the client agree on two page-specific DOM nodes, namely: the number of graphic reports rendered on the page (imageSize) and the result collection (uploadDatas) returned by the graphic report calling the server file persistence interface. Use Selenium WebDriver 3.x components to establish communication between the server and the web browser, and schedule the triggering of the rendering of the graphic report generation page on the web browser. At this time, the graphic report generation page requests the server API data interface to obtain the business data required for the graphic report generation. According to the data structure returned by the server, the number of graphic reports generated on the current page (imageSize) is set. If the data acquisition fails, the imageSize is set to -1; when the echarts myChart.on('finished',function) event is used to monitor the completion of the rendering of a graphic report, myChart.getDataURL() is called to convert the graphic report into a Base64 file stream, and the server upload method is called to persist the graphic report data in the server file server, and the result returned by the upload method is recorded in the uploadDatas collection.
[0029] The server uses the WebDriverWait.until(callBack)SDK method provided by Selenium to detect the values of page imageSize and uploadDatas.size() every second. When the imageSize value is -1, it means that the rendering of this graphic report is abnormal. The WebDriver.quit()SDK method is called to disconnect the communication between the server application and the web browser, and record the failure record for subsequent retries. When it is detected that the imageSize and uploadDatas.size() values are equal, it means that the rendering of this batch of generated graphic reports is completed, and the communication between the server and the web browser is closed to release resources.
[0030] Use the scheduling platform to wake up the task of timing triggering the front-end page in the report generation service. Specifically, the server introduces Selenium-related dependencies and configures the driver corresponding to the browser version installed in the remote server. The server calls the SDK provided by the Selenium dependency package to communicate with the browser in the remote server, creates a browser access process, and the program automatically enters the URL provided by the front-end chart generation service to trigger the front-end page loading. The specific implementation is as follows:
[0031] 1) Install the Selenium library and introduce the WebDriver 3.x component (WebDriver is an API and protocol that defines a language-neutral interface for controlling the behavior of a web browser). In this case, Maven is used to reference the selenium-java jar package dependency to complete the installation;
[0032] 2) Download the driver corresponding to your local web browser from the official Selenium Manager website, and use System.setProperty("webdriver.chrome.driver",driverFile) to load the local driver;
[0033] 3) Use ChromeOptions to complete the necessary parameters for WebDriver to control the behavior of the web browser, and use newChromeDriver(ChromeOptions) to complete the initialization operation of WebDriver;
[0034] 4) Call the WebDriver.get() SDK method provided by WebDriver, create a server application to communicate with the web browser, create a browser access process, control the web browser to automatically input the graphic report generation URL provided in step 2, and then trigger the graphic report rendering process produced in step 2;
[0035] 5) The graphic report page uses echarts to render the graphic report and listens to the rendering completion event. After the rendering is completed, the report is converted into a file and the service file upload interface is called to persist the final generated graphic report in the server-side file server;
[0036] 6) Call the WebDriverWait and WebDriverWait.until(callBack) SDK methods provided by WebDriver to periodically detect the page DOM structure provided in step 2, and try to obtain the specific DOM nodes required by the server and client to complete page rendering. If detected, it means that the current page has been successfully rendered, and call the WebDriver.quit() SDK method to disconnect the server application from the web browser, completing the task of actively triggering the client network connection.
[0037] Beneficial effects: Compared with the existing technology, it has significant advantages:
[0038] (1) The present invention generally uses the web automation tool - Selenium to realize direct communication between the server and the browser, so that the front-end code runs directly on the real browser, instead of using PhantomJS to simulate browser behavior. The advantages of using Selenium-based scheduling of front-end pages are as follows: it can completely avoid the compatibility issues caused by the real browser and the headless browser simulated by PhantomJS, and because the final display of the user is simulated to a great extent, it also optimizes the user experience to a certain extent.
[0039] (2) Traditionally, PhantomJS is used to simulate browser behavior to request a specified URL. We can only perceive whether the request is successful and the page loading status from the HTTP response result. However, this situation is inaccurate. For example, in the demand for the server to call to generate a chart, it is necessary to grasp whether the chart file stream in the current page has been completely transmitted back to the server, record the return log, and close the browser process. If PhantomJS is used, it can only be perceived through the HTTP response code 500 when the page rendering reports an error. However, if the page rendering is normal, but the ajax return is abnormal, it cannot be perceived based on the HTTP request-response mode. Selenium provides a page DOM probe technology. This feature can be used to allow the server to continuously detect the successful DOM nodes agreed in advance with the front end. If the detection is successful, it can accurately know that the current page chart file stream has been returned normally, and the next step can be performed.
[0040] (3) Using Selenium to schedule the front-end page is less invasive than using PhantomJS to simulate browser behavior business code. You only need to introduce a Selenium dependency package to communicate directly with the browser, while PhantomJS needs to introduce a series of cmd command support dependencies, which greatly simplifies the server-side configuration.
[0041] (4) Compared with PhantomJS, Selenium has a more complete ecosystem, and subsequent technical support and upgrade iterations are more guaranteed. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 This is a system architecture diagram for generating graphic reports based on server calls in an embodiment of the present invention.
[0043] Figure 2 The present invention provides a flowchart of a method for generating a graphical report based on a server-side call in an embodiment of the present invention. DETAILED DESCRIPTION
[0044] Figure 1 This is a system architecture diagram for generating graphic reports based on server-side calls in an embodiment of the present invention. The system architecture includes three main modules, namely, a server-side report service module, a front-end chart service, and a scheduling platform.
[0045] The server-side report service module mainly includes three sub-modules: report data service, report generation service and report preview service.
[0046] The core functions of the reporting data service are mainly two:
[0047] a) Provide data support for front-end chart generation;
[0048] b) Provide data support for the report documents required for report generation services;
[0049] The report generation service has three core functions:
[0050] a) Provide an interface to store the chart file stream returned by the front end;
[0051] b) Call the report data service interface to obtain the data required for the report copy and fill in the corresponding copy position of the general template;
[0052] c) Fill the chart file stream returned by the front end into the corresponding position of the template and regenerate a new report
[0053] (.docx);
[0054] The core function of the report preview service is to provide an acquisition interface for front-end report preview;
[0055] The front-end chart service module mainly includes two sub-modules: chart generation service and report preview service.
[0056] The core function of the chart generation service is to realize the rendering, monitoring, file conversion, and file transmission of graphic reports based on the Echarts open source library.
[0057] The core function of the report preview service is to call the server-side report file acquisition interface to provide online preview of the report and customized selection of report modules. Among them, the online preview is mainly implemented based on the PDF preview plug-in provided by the web browser.
[0058] The core function of the scheduling platform module is to regularly invoke the report generation service and use Selenium technology to actively trigger the front-end page to complete a series of subsequent report generation actions.
[0059] Figure 2 The flowchart of the method for generating a graphic report based on a server-side call in an embodiment of the present invention is shown in the following specific steps:
[0060] Step 201: This step is a preparation step, which mainly includes the installation of the remote server browser and the installation of the fonts required for generating the chart. If the font is missing, it may cause a garbled font on the chart.
[0061] Step 202: Using the scheduling platform, wake up the task of timing triggering the front-end page in the report generation service. Specifically, the server introduces Selenium-related dependencies and configures the driver corresponding to the browser version installed in the remote server. The server calls the SDK provided by the Selenium dependency package to communicate with the browser in the remote server, creates a browser access process, and the program automatically enters the URL provided by the front-end chart generation service to trigger the front-end page loading.
[0062] The specific implementation is as follows:
[0063] 1) Install the Selenium library and introduce the WebDriver 3.x component (WebDriver is an API and protocol that defines a language-neutral interface for controlling the behavior of a web browser). In this case, Maven is used to reference the selenium-java jar package dependency to complete the installation;
[0064] 2) Download the driver corresponding to your local web browser from the official Selenium Manager website, and use System.setProperty("webdriver.chrome.driver",driverFile) to load the local driver;
[0065] 3) Use ChromeOptions to complete the necessary parameters for WebDriver to control the behavior of the web browser, and use newChromeDriver(ChromeOptions) to complete the initialization operation of WebDriver;
[0066] 4) Call the WebDriver.get() SDK method provided by WebDriver, create a server application to communicate with the web browser, create a browser access process, control the web browser to automatically input the graphic report generation URL provided in step 2, and then trigger the graphic report rendering process produced in step 2;
[0067] 5) The graphic report page uses echarts to render the graphic report and listens to the rendering completion event. After the rendering is completed, the report is converted into a file and the service file upload interface is called to persist the final generated graphic report in the server-side file server;
[0068] 6) Call the WebDriverWait and WebDriverWait.until(callBack) SDK methods provided by WebDriver to periodically detect the page DOM structure provided in step 2, and try to obtain the specific DOM nodes required by the server and client to complete page rendering. If detected, it means that the current page has been successfully rendered, and call the WebDriver.quit() SDK method to disconnect the server application from the web browser, completing the task of actively triggering the client network connection.
[0069] Step 203: The corresponding front-end chart generation page starts loading. First, the interface provided by the report data service is called to obtain the data required for the chart. The front-end uses the various API configurations provided by Echarts to render the chart on demand. After rendering, the save interface provided by the report generation service is called to return the chart file stream to the server. The specific implementation of the graphical report rendering based on JavaScript's open source visualization chart library Echarts is as follows:
[0070] 1) Use npm to import the React version of Echarts open source library, and import ECharts charts and components as needed to implement graphical report rendering
[0071] 2) Initialize Echarts through var myChart = echarts.init(document) and configure the rendering chart industry
[0072] Required topics
[0073] 3) The Web browser triggers the rendering of the graphic report. When the page is initialized, the server API data interface is called to obtain the business data required for the graphic report rendering, and the number of graphic reports rendered on the page (imageSize) is set synchronously;
[0074] 4) Use the myChart.on('finished', function) event to monitor when the graphic report is rendered.
[0075] 5) Use myChart.getDataURL() to convert the graphic report into a Base64 file stream to file the graphic report, making it easier to send the graphic report back to the server;
[0076] 6) Call the service file saving API interface to persist the graphic report in the server-side file server and record the upload results in the uploadDatas collection
[0077] Step 204: The operator prepares a general report template (.doxc) in advance, which mainly includes the general style and content of the report, and marks the data variables and chart positions with anchor points. The server-side report generation service calls the report data service interface to obtain the data required by the report text and fills it into the corresponding anchor points.
[0078] Step 205: The report generation service uses Poi-tl open source technology to fill the chart file generated by the front end in step 203 into the universal corresponding anchor point, and regenerates a new report (.docx), stores it in the file system, and waits for the front-end preview service to obtain it.
[0079] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations on the present invention. A person skilled in the art may change, modify, replace and modify the above embodiments within the scope of the present invention without departing from the principles and intent of the present invention.
Claims
1. A method for generating a graphical report based on a server call, characterized in that the steps are: as follows: Step 1: Based on the Linux server, install the web browser on the server and install the system fonts required for graphic report rendering on the server; Step 2: Front-end network coding to implement relevant functions of chart generation, including calling the server-side interface to obtain the data required for the chart when the page is initialized, using Echarts technology to complete the drawing of the chart, and after the page is loaded, calling Echarts related API to convert the chart into a file and stream it back to the server, and providing a link entry for server-side access; Step 3: Backend coding, introducing Selenium-related dependencies, and configuring the driver corresponding to the browser version installed on the remote server; the server calls the SDK provided by Selenium, uses the driver to communicate with the server browser, creates a server browser access process, and accesses the link provided in step 2 to complete the call to the front-end page; Step 4: Configure the general template (.docx) of the report that the program needs to generate. Use anchor technology and open source technology Poi-tl to insert the chart file returned by the front end in step 3 into the corresponding position of the report and regenerate a new report (.docx).
2. The method for generating a graphic report based on a server-side call according to claim 1, characterized in that: In step 2: Based on the React client framework coding, the Echarts open source library is introduced to realize the rendering, monitoring, file conversion of graphic reports, and transmission back to the file server; the process is as follows: (1) Use npm to import the React version of Echarts open source library (2) Use the init method provided by Echarts to complete the initialization of the graphic report and generate rendering settings (3) Use the rendering completion listener event provided by Echarts to monitor the rendering process (4) After rendering is completed, use the getDataURL method provided by Echarts to complete the file of the report (5) Call the service interrupt file upload interface to persist the graphic report on the file server Step 3: Based on the Java server-side coding, Selenium WebDriver 3.x is referenced to implement the server-side application to control the behavior of the web browser, actively render the graphic report provided in step 2 in the web browser to generate a URL, and then trigger the graphic report produced in step 2 to persist in the server-side file server, and at the same time call a series of SKD methods provided by Selenium to complete the monitoring of page rendering completion, and disconnect the communication between the server-side application and the web browser; The process is as follows: (1) Use Maven dependency management to introduce Selenium WebDriver 3.x library packages into the server (2) The server introduces the Selenium Manager driver that matches the local web browser version (3) new ChromeDriver (ChromeOptions) completes the initialization of WebDriver, including driver location loading, web browser access settings, etc. (4) Call the WebDriver.get() SDK method provided by WebDriver to establish communication between the server and the web browser, and automatically trigger the graphical report generation URL rendering (5) Graphic report generation page renders the graphic report. After rendering, it is filed and persisted on the server file server (6) Quit provided by WebDriver closes the communication between the server and the web browser and releases resources.
3. The method for generating graphic reports based on server-side calls according to claim 2, characterized in that: In step 3, in order to achieve the effect of reasonable allocation and utilization of server resources and rapid reversal of the entire server-side call generation graphic report process, Selenium is used to provide a page DOM probe technology. The server continuously detects the successful DOM nodes agreed with the front end in advance. If the detection is successful, it can accurately know that the current page chart file stream has been returned normally, and then the communication channel established between the current server and the web browser is closed to achieve the server resource scheduling allocation and the next step of the overall process reversal; The server and the client agree on two page-specific DOM nodes, namely: the number of graphic reports rendered on the page (imageSize) and the result set returned by the graphic report calling the server-side file persistence interface (uploadDatas); Use Selenium WebDriver 3.x components to establish communication between the server and the web browser, and schedule the triggering of the rendering of the graphic report generation page on the web browser; at this time, the graphic report generation page requests the server API data interface to obtain the business data required for the graphic report generation, and sets the number of graphic reports generated on the current page (imageSize) according to the data structure returned by the server. If the data acquisition fails, set imageSize to -1; when the echarts myChart.on('finished',function) event is used to monitor the completion of the rendering of a graphic report, myChart.getDataURL() is called to convert the graphic report into a Base64 file stream, and the server upload method is called to persist the graphic report data in the server file server, and the result returned by the upload method is recorded in the uploadDatas collection; The server uses the WebDriverWait.until(callBack)SDK method provided by Selenium to detect the values of page imageSize and uploadDatas.size() every second. When the imageSize value is -1, it means that the rendering of this graphic report is abnormal. The WebDriver.quit()SDK method is called to disconnect the communication between the server application and the web browser, and record the failure record for subsequent retries. When it is detected that the imageSize and uploadDatas.size() values are equal, it means that the rendering of this batch of generated graphic reports is completed, and the communication between the server and the web browser is closed to release resources.
4. The method for generating graphic reports based on server-side calls according to claim 3 is characterized in that: Use the scheduling platform to wake up the task of timing triggering the front-end page in the report generation service; specifically, the server introduces Selenium-related dependencies and configures the driver corresponding to the browser version installed in the remote server; the server calls the SDK provided by the Selenium dependency package to communicate with the browser in the remote server, creates a browser access process, and the program automatically enters the URL provided by the front-end chart generation service to trigger the front-end page loading; the specific implementation is as follows: (1) Install the Selenium library and introduce the WebDriver 3.x component (WebDriver is an API and protocol that defines a language-neutral interface for controlling the behavior of a web browser). In this case, Maven is used to reference the selenium-java jar package dependency to complete the installation. (2) Download the driver corresponding to your local web browser from the official Selenium Manager website and use System.setProperty("webdriver.chrome.driver",driverFile) to load the local driver. (3) Use ChromeOptions to complete the necessary parameters for WebDriver to control the behavior of the web browser, and use newChromeDriver(ChromeOptions) to complete the initialization operation of WebDriver; (4) Call the WebDriver.get() SDK method provided by WebDriver, create a server application to communicate with the web browser, create a browser access process, control the web browser to automatically input the graphic report generation URL provided in step 2, and then trigger the graphic report rendering process produced in step 2; (5) The graphic report page uses echarts to render the graphic report and listens for the rendering completion event. After the rendering is completed, the report is converted into a file and the service file upload interface is called to persist the final generated graphic report in the server-side file server; (6) Call the WebDriverWait and WebDriverWait.until(callBack) SDK methods provided by WebDriver to periodically detect the page DOM structure provided in step 2, and try to obtain the specific DOM node required by the server and the client to complete the page rendering. If detected, it means that the current page has been successfully rendered. Call the WebDriver.quit() SDK method to disconnect the communication between the server application and the web browser, and complete the task of actively triggering the client network connection.
Citation Information
Patent Citations
React and Nodejs-based server-side rendering method
CN109324788A
Method for generating public opinion report based on Selenium
CN111523296A
Report platform front-end test method, device and equipment and storage medium
CN113238966A
Systems and methods for automated on-device performance testing of mobile applications
US20150099493A1
Beta tungsten thin films with giant spin Hall effect for use in compositions and structures with perpendicular magnetic anisotropy
US20170338021A1
