Merge feat/report-jor-rehost: JOR 报表引擎重宿主(Phase 1 后端 + /api/report)
Some checks failed
ci / build-test-parity (push) Has been cancelled

This commit is contained in:
2026-06-25 17:56:50 +08:00
100 changed files with 1181 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
# 报表迁移:JOR(jatools)引擎重宿主到 EIP4 — design + 实施
> 2026-06-25。回答「EIP3 的真报表(JOR 套打)能否迁移」=**能**,PoC 已证(headless 渲染 + 连真库 + 跑报表 SQL,见 `/tmp/eip4-report-poc.html` 与浏览器截图 `在建工程项目收付款信息表`)。本文为把 PoC 变成可用功能的设计与实施。
## 0. 关键结论(PoC 已验)
- EIP3 报表 = `jatools` JOR **套打模板**(633 个 `.xml`,合并单元格/边框/公式列/分组小计/分页/签字栏),引擎是**纯 Java 服务端**,导出 HTML/PDF/XLS/RTF,浏览器显示(H5;旧 ActiveX `.cab` 仅 IE 已死)。
- **不用移植 900 个源文件**:整套**预编译成品**在 `/Users/zhengwr/workspace/eip3/framework/com.dsasp.client.report/lib/`:
`jatools.jar`(引擎) + `bsh2.0.jar`(改造版 BeanShell,含 8 个自定义类) + 全部依赖(`itext.jar`/`jxl.jar`/`jsqlparser.jar`/`jfreechart-1.0.13.jar`+`jcommon`+`chart.jar`/`barcode4j.jar`+`zxing2.1.core.jar`/`commons-*`/`log4j-1.2.8`/`jaxen`/`xercesImpl`/`postgresql.jar`)。授权许可:`jatools.dat`(912B ASCII),预编译 jar 在 server 模式直接跑通(无物理 dongle);生产需确认授权(客户 EIP3 本就在用)。
- **渲染 recipe(已验)**:`ReportDocument.load(xml)` → 设参数 → `jatools.engine.ReportJob.printAsDHTML(imp, writer)`(HTML)/`printAsPDF(os)`/`printAsXLS(ba)`。headless:`-Djava.awt.headless=true`,`java.desktop@21` 在。
## 1. 参数绑定(查询条件,需求①)
EIP3 `ReportExporter` 的真实通道(`jor/jatools/server/ReportExporter.java`):
- 每个请求参数 `job.setParameter(name, value)`;
- `declareExternalVariables(doc, script, params)`:把 params 注入 script,并遍历 `doc.getVariableContext().variables(VariableContext.PARAMETER)`,按 `Parameter.castValue` 类型转换后 `script.set(p.getName(), value)`;
- 报表 SQL 里的 `${PARAM}` 即由这些已声明变量替换(`SqlReader` 检 `sql.indexOf("${")`)。
- 注:`LocalReportJob` 路径**不做** declareExternalVariables(故 PoC 里用 params 传 DBJdbcUrl 无效);**必须走 `ReportJob` 路径**。
- DB 连接:模板 `<Connection>` 用 `${property("DBJdbcUrl")/DBUser/DBPassword}`,`property()=System2.getProperty()=jatools.properties`。EIP4 须在启动时把 `DBJdbcUrl/DBUser/DBPassword` 注入 System2(指向客户库)。
## 2. 目标架构
- **platform-report 模块**:依赖上述预编译 jar。打包进 fat jar 的可靠做法 = `mvn install:install-file` 各 jar 进**项目内本地仓** `platform-report/local-repo/`(随码提交,坐标如 `com.dsasp.thirdparty:jatools:eip3`),pom 加 `<repository>file://.../local-repo</repository>` 正常依赖。**勿用 system scope**(不进 fat jar)。
- **ReportService**(复刻 ReportExporter 核心,去掉 com.dsasp 应用胶水):`render(templateXml, Map<String,String> params, format) → bytes/String`。`ReportJob` + `FileResourceOutputFactory(tmpDir)` + `printAsDHTML/PDF/XLS`。
- **ReportController**:`GET /api/report/{templateId}?format=html|pdf|xls&<查询参数>` → 加载 JOR 模板 → ReportService → `text/html` / `application/pdf` / xls。
- **模板来源**:633 个 `.xml`。v1:配置一个模板根目录(EIP3 report 目录)+ `templateId→xml` 映射;后续:导入 `sys_report_template` 表(随 sys_* 平台表,Flyway 管)。
- **System2 连接注入**:启动时用 EIP4 `spring.datasource` 配置写入 jatools 的 DBJdbcUrl/DBUser/DBPassword(经 System2 的 setProperty 或可解析的 jatools.properties)。
## 3. 前端集成(菜单页,需求②:不是独立 tab)
- type=200 报表页**已是** sys_page_schema 里的菜单功能页(转换器已生成,含查询条件表单——见 `项目安全费用投入明细` 的 amis filter)。
- 改造该页 body:把 amis CRUD 表换成**报表查看器**(amis `iframe`/`html` 组件)指向 `/api/report/{templateId}?{查询表单参数}`;查询表单 onSubmit 刷新 viewer。
- 仍是原菜单页(满足需求②);查询条件表单字段名 = 报表 VariableContext PARAMETER 名(PROJECTID/日期段/…)。
## 4. 分期
- **Phase 1(后端,本批次)**:platform-report 模块 + ReportService + `/api/report` 端点,headless 渲染一张带查询参数的 JOR 模板→HTML/PDF,接进 platform-app,curl 验证返回报表 HTML。
- **Phase 2(前端集成)**:报表页 body 换查看器 + 查询表单喂参数 + 菜单可达,端到端一张报表(对完整客户库出数据)。
- **Phase 3(铺量)**:633 模板导入 `sys_report_template`;type=200 页批量改造;字体保真;PDF/Excel 下载;图表(B 类,jfreechart 已在 lib)。
## 5. 风险
- headless 中文字体保真(版式已通,需装字体)。
- jatools 授权(生产确认;客户已持有)。
- System2 连接为进程级全局(单客户部署 OK;多租户需改造)。
- 模板里 `<Url>reportviewer.jsp?...`(钻取链接)需改写为 EIP4 路由(Phase 3)。
- eip4dev 是**部分** dev 库,缺部分报表源表/视图;数据验收须对**完整客户库**。

View File

@@ -19,6 +19,8 @@
<dependency><groupId>com.eip4</groupId><artifactId>platform-flow-gateway</artifactId></dependency>
<dependency><groupId>com.eip4</groupId><artifactId>platform-converter</artifactId></dependency>
<dependency><groupId>com.eip4</groupId><artifactId>platform-ai</artifactId></dependency>
<!-- P3 报表迁移:JOR(jatools)报表引擎重宿主模块,提供 /api/report/render 端点 -->
<dependency><groupId>com.eip4</groupId><artifactId>platform-report</artifactId></dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
<!-- 可观测性(总览 §10.2):仅 /actuator/health(含 liveness/readiness 探针),不上 Prometheus 全家桶 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>

View File

@@ -95,6 +95,9 @@ public class SecurityConfig {
.httpBasic(AbstractHttpConfigurer::disable)
.logout(AbstractHttpConfigurer::disable)
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
// 报表查看器以 iframe 内嵌 /api/report/render 的 HTML(同源)。Spring Security 默认
// X-Frame-Options:DENY 会拦掉同源 iframe → 改 sameOrigin 放行(生产 nginx 单源,同源成立)。
.headers(h -> h.frameOptions(fo -> fo.sameOrigin()))
.addFilterBefore(new JwtAuthFilter(jwtService, roleResolver),
UsernamePasswordAuthenticationFilter.class);
}

48
platform-report/install-libs.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Installs the prebuilt EIP3 jatools (JOR) report-engine jars into the PROJECT-LOCAL
# Maven repo (platform-report/local-repo) under stable coordinates so the module can
# depend on them normally (and they get packaged into the Spring Boot fat jar).
#
# Re-run this only if the jars in ./lib change. The resulting ./local-repo is committed
# with the module, so a normal `mvn install` does NOT need this script.
#
# Requires JAVA_HOME=/opt/homebrew/opt/openjdk@21 (or any JDK21) and mvn on PATH.
set -euo pipefail
cd "$(dirname "$0")"
REPO="$(pwd)/local-repo"
LIB="$(pwd)/lib"
GROUP="com.dsasp.thirdparty"
VERSION="eip3"
install() {
local artifact="$1" jar="$2"
mvn -q org.apache.maven.plugins:maven-install-plugin:3.1.1:install-file \
-Dfile="$LIB/$jar" \
-DgroupId="$GROUP" \
-DartifactId="$artifact" \
-Dversion="$VERSION" \
-Dpackaging=jar \
-DlocalRepositoryPath="$REPO"
echo "installed $GROUP:$artifact:$VERSION <- $jar"
}
install jatools jatools.jar
install bsh bsh2.0.jar
install itext itext.jar
install jxl jxl.jar
install jsqlparser jsqlparser.jar
install jfreechart jfreechart-1.0.13.jar
install jcommon jcommon-1.0.16.jar
install jchart chart.jar
install barcode4j barcode4j.jar
install zxing zxing2.1.core.jar
install commons-beanutils commons-beanutils.jar
install commons-collections commons-collections-3.0.jar
install commons-httpclient commons-httpclient-2.0.1.jar
install commons-lang commons-lang-2.0.jar
install commons-logging commons-logging-1.0.1.jar
install log4j log4j-1.2.8.jar
install jaxen jaxen1.1.1.jar
install xerces xercesImpl.jar
echo "DONE. local-repo populated at $REPO"

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
platform-report/lib/jxl.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:04:00 CST 2026
barcode4j-eip3.jar>=
barcode4j-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>barcode4j</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>barcode4j</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090400</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:03:51 CST 2026
bsh-eip3.jar>=
bsh-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>bsh</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>bsh</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090351</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:04:03 CST 2026
commons-beanutils-eip3.jar>=
commons-beanutils-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>commons-beanutils</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>commons-beanutils</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090403</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:04:04 CST 2026
commons-collections-eip3.jar>=
commons-collections-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>commons-collections</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>commons-collections</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090404</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:04:05 CST 2026
commons-httpclient-eip3.jar>=
commons-httpclient-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>commons-httpclient</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>commons-httpclient</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090405</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:04:06 CST 2026
commons-lang-eip3.jar>=
commons-lang-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>commons-lang</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>commons-lang</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090406</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:04:08 CST 2026
commons-logging-eip3.jar>=
commons-logging-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>commons-logging</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>commons-logging</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090407</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:03:52 CST 2026
itext-eip3.jar>=
itext-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>itext</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>itext</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090352</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:03:50 CST 2026
jatools-eip3.jar>=
jatools-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jatools</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jatools</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090347</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:04:10 CST 2026
jaxen-eip3.jar>=
jaxen-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jaxen</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jaxen</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090410</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:03:59 CST 2026
jchart-eip3.jar>=
jchart-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jchart</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jchart</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090359</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:03:57 CST 2026
jcommon-eip3.jar>=
jcommon-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jcommon</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jcommon</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090357</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:03:56 CST 2026
jfreechart-eip3.jar>=
jfreechart-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jfreechart</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jfreechart</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090356</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:03:55 CST 2026
jsqlparser-eip3.jar>=
jsqlparser-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jsqlparser</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jsqlparser</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090355</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:03:54 CST 2026
jxl-eip3.jar>=
jxl-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jxl</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>jxl</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090354</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:04:09 CST 2026
log4j-eip3.jar>=
log4j-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>log4j</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>log4j</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090409</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:04:11 CST 2026
xerces-eip3.jar>=
xerces-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>xerces</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>xerces</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090411</lastUpdated>
</versioning>
</metadata>

View File

@@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Thu Jun 25 17:04:02 CST 2026
zxing-eip3.jar>=
zxing-eip3.pom>=

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>zxing</artifactId>
<version>eip3</version>
<description>POM was created from install:install-file</description>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.dsasp.thirdparty</groupId>
<artifactId>zxing</artifactId>
<versioning>
<release>eip3</release>
<versions>
<version>eip3</version>
</versions>
<lastUpdated>20260625090401</lastUpdated>
</versioning>
</metadata>

104
platform-report/pom.xml Normal file
View File

@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.eip4</groupId>
<artifactId>eip4-platform</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>platform-report</artifactId>
<name>platform-report</name>
<description>EIP3 JOR (jatools) 报表引擎重宿主:用预编译成品 jar headless 渲染 JOR 套打模板为 HTML/PDF/XLS</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>21</maven.compiler.release>
</properties>
<!-- 预编译报表引擎 jar 装入项目内本地仓(local-repo/,随码提交)。
坐标 com.dsasp.thirdparty:*:eip3,由 install-libs.sh 用 mvn install:install-file 生成。
不用 system scope —— system scope 不会被 spring-boot-maven-plugin 打进 fat jar。 -->
<repositories>
<repository>
<id>eip3-local</id>
<url>file://${project.basedir}/local-repo</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<!-- ===== JOR(jatools) 报表引擎预编译成品 ===== -->
<!-- 引擎本体 -->
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>jatools</artifactId><version>eip3</version></dependency>
<!-- jatools 改造版 BeanShell(公式求值核心,含 8 个自定义类):必须用这份 fork,非 stock bsh -->
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>bsh</artifactId><version>eip3</version></dependency>
<!-- PDF 导出 -->
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>itext</artifactId><version>eip3</version></dependency>
<!-- XLS 导出 -->
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>jxl</artifactId><version>eip3</version></dependency>
<!-- 报表 SQL 解析 -->
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>jsqlparser</artifactId><version>eip3</version></dependency>
<!-- 图表(B 类报表,jfreechart + jcommon + jatools chart 封装) -->
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>jfreechart</artifactId><version>eip3</version></dependency>
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>jcommon</artifactId><version>eip3</version></dependency>
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>jchart</artifactId><version>eip3</version></dependency>
<!-- 条码 / 二维码 -->
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>barcode4j</artifactId><version>eip3</version></dependency>
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>zxing</artifactId><version>eip3</version></dependency>
<!-- 引擎运行期依赖的旧版 commons / log4j1 / jaxen / xerces。给独立坐标避免与平台托管版本误判去重。 -->
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>commons-beanutils</artifactId><version>eip3</version></dependency>
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>commons-collections</artifactId><version>eip3</version></dependency>
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>commons-httpclient</artifactId><version>eip3</version></dependency>
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>commons-lang</artifactId><version>eip3</version></dependency>
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>commons-logging</artifactId><version>eip3</version></dependency>
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>log4j</artifactId><version>eip3</version></dependency>
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>jaxen</artifactId><version>eip3</version></dependency>
<dependency><groupId>com.dsasp.thirdparty</groupId><artifactId>xerces</artifactId><version>eip3</version></dependency>
<!-- ===== Spring(控制器 / 注入 DataSource 配置) ===== -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- JdbcTemplate:按 templateId 从 view_template(type=200) 取 JOR 模板。
DataSource 由运行宿主 platform-app 提供(spring.datasource.*)。 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- 数据库驱动:模板 <Connection> 按驱动类名加载 org.postgresql.Driver,需在 classpath -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>21</release>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,143 @@
package com.eip4.platform.report;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.DefaultFontMapper;
import jatools.engine.System2;
/**
* 把 jatools 引擎所需配置在启动时注入 {@code jatools.engine.System2}。
*
* <p>背景:引擎通过 {@code System2.getProperty(name)} 读配置 —— 其实现是:若静态字段
* {@code System2.properties} 为 null,则按 {@code 工作目录/[WEB-INF/]jatools.properties}
* 用 {@code FileInputStream} 加载(依赖进程 CWD,脆弱)。{@code System2.properties} 是
* <b>public static</b> 字段,故这里直接构造一份 {@link java.util.PropertyResourceBundle}
* 赋值给它,彻底绕开文件加载。
*
* <p>注入的键:
* <ul>
* <li>{@code timeformat} / {@code dayformat} / {@code company} —— 系统变量(NOW/TODAY/COMPANY)</li>
* <li>{@code font.dirs} —— 字体目录(加 macOS 与 Linux 路径,服务端版式/中文保真)</li>
* <li>{@code DBJdbcUrl} / {@code DBUser} / {@code DBPassword} —— 报表模板 {@code <Connection>}
* 里的 {@code ${property("DBJdbcUrl")}} 等,必须解析到 EIP4 数据源</li>
* </ul>
* DB 三键默认取 EIP4 的 {@code spring.datasource.*};本地验证默认指向 dev 库
* {@code jdbc:postgresql://localhost:5433/eip4dev?currentSchema=eip3}(用户 zhengwr,无密码)。
*/
@Component
public class JatoolsConfig {
private static final Logger log = LoggerFactory.getLogger(JatoolsConfig.class);
@Value("${spring.datasource.url:jdbc:postgresql://localhost:5433/eip4dev?currentSchema=eip3}")
private String jdbcUrl;
@Value("${spring.datasource.username:zhengwr}")
private String dbUser;
@Value("${spring.datasource.password:}")
private String dbPassword;
@Value("${eip4.report.company:EIP4}")
private String company;
/**
* PDF 导出兜底字体(CJK 保真)候选路径,按序探测,取首个可加载者注册为
* iText {@code DefaultFontMapper.defaultFont}。覆盖 macOS(本地验证)与常见 Linux 路径。
* {@code .ttc} 字体集需 {@code ,索引} 后缀(如 {@code ,0})。
*/
private static final String[] PDF_FALLBACK_FONTS = {
// macOS
"/System/Library/Fonts/STHeiti Light.ttc,0",
"/System/Library/Fonts/Supplemental/Songti.ttc,0",
"/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
"/Library/Fonts/Arial Unicode.ttf",
// Linux(常见中文字体包)
"/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc,0",
"/usr/share/fonts/wenquanyi/wqy-zenhei/wqy-zenhei.ttc,0",
"/usr/share/fonts/truetype/arphic/uming.ttc,0",
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc,0",
"/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc,0"
};
private volatile boolean initialized = false;
@PostConstruct
public synchronized void init() {
if (initialized) {
return;
}
Properties p = new Properties();
// 日期/时间格式(对齐 EIP3 jatools.properties)
p.setProperty("timeformat", "hh:mm:ss");
p.setProperty("dayformat", "yyyy-MM-dd");
p.setProperty("company", company == null ? "EIP4" : company);
// 字体目录:覆盖 macOS(本地验证)与 Linux(生产部署),服务端 Graphics2D 版式/中文保真
p.setProperty("font.dirs",
"/System/Library/Fonts;/Library/Fonts;"
+ "/usr/share/fonts;/usr/share/fonts/truetype;/usr/local/share/fonts");
// 报表模板 <Connection> 解析到 EIP4 数据源
p.setProperty("DBJdbcUrl", jdbcUrl == null ? "" : jdbcUrl);
p.setProperty("DBUser", dbUser == null ? "" : dbUser);
p.setProperty("DBPassword", dbPassword == null ? "" : dbPassword);
try {
// PropertyResourceBundle 用 ISO-8859-1 读字节流;键值均 ASCII,安全。
ByteArrayOutputStream baos = new ByteArrayOutputStream();
p.store(baos, "EIP4 injected jatools config");
System2.properties = new java.util.PropertyResourceBundle(
new ByteArrayInputStream(baos.toByteArray()));
log.info("jatools 配置已注入 System2.properties: DBJdbcUrl={}, DBUser={}", jdbcUrl, dbUser);
} catch (Exception e) {
throw new IllegalStateException("注入 jatools System2 配置失败: " + e.getMessage(), e);
}
registerPdfFallbackFont();
initialized = true;
}
/**
* PDF 导出兜底字体注册。EIP3 引擎 {@code _Job.printAsPDF} 用 iText 无参 {@code createGraphics}
* (空 {@code DefaultFontMapper}),AWT 逻辑字体(Dialog 等)无映射会抛"既找不到字体...也找不到默认字体"。
* iText {@code DefaultFontMapper.awtToPdf} 在找不到具名字体时会回落到 {@code defaultFont}(静态字段),
* 故注册一个 CJK TrueType 作 defaultFont 即可让 PDF 不崩,并尽量保中文。最佳努力,失败仅告警。
*/
private void registerPdfFallbackFont() {
for (String spec : PDF_FALLBACK_FONTS) {
String path = spec.contains(",") ? spec.substring(0, spec.indexOf(',')) : spec;
if (!new java.io.File(path).isFile()) {
continue;
}
try {
BaseFont bf = BaseFont.createFont(spec, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
DefaultFontMapper.defaultFont = bf;
log.info("PDF 兜底字体已注册(DefaultFontMapper.defaultFont): {}", spec);
return;
} catch (Exception e) {
log.debug("PDF 兜底字体加载失败,跳过: {} ({})", spec, e.getMessage());
}
}
log.warn("未找到可用 CJK 兜底字体,PDF 导出可能因字体缺失失败;HTML/XLS 不受影响。候选: {}",
String.join(", ", PDF_FALLBACK_FONTS));
}
/** 供 {@link ReportService} 构造时确保配置已就绪(@PostConstruct 顺序保险)。 */
public void ensureInitialized() {
if (!initialized) {
init();
}
}
}

View File

@@ -0,0 +1,130 @@
package com.eip4.platform.report;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import jakarta.servlet.http.HttpServletRequest;
/**
* 报表渲染端点。
*
* <p>{@code GET /api/report/render/{templateId}?format=html|pdf|xls&<查询参数...>}
* → 把 {@code templateId} 解析为 JOR 模板 .xml → {@link ReportService#render} → 返回
* 渲染产物(HTML/PDF/XLS)。除 {@code format}/{@code tpl} 外的全部查询参数原样作为报表参数
* 透传(报表 SQL 里的 {@code ${PARAM}} 据此绑定)。
*
* <p>模板解析(v1):
* <ul>
* <li>{@code ?tpl=<绝对路径>} —— 验证/演示用,直接指定 .xml 绝对路径(仅 dev/local 便利)。</li>
* <li>否则把 {@code templateId} 当作相对 {@code eip4.report.templates-dir} 的路径解析,
* 默认基目录指向 EIP3 report 根。Phase 3 改为查 {@code sys_report_template} 表。</li>
* </ul>
*
* <p>注:不与既有 {@code /api/report/menu-tree}(platform-metadata)冲突 —— 该控制器只占
* {@code /api/report/render/**}。安全:这是 {@code /api/**} 端点,在 dev/local/ci 宽松链下放行,
* 严格 profile 下走 {@code authenticated()},沿用既有安全模型,无需改 SecurityConfig。
*/
@RestController
public class ReportController {
private static final Logger log = LoggerFactory.getLogger(ReportController.class);
private final ReportService reportService;
private final ReportTemplateRepository templateRepository;
@Value("${eip4.report.templates-dir:/Users/zhengwr/workspace/EIP-3.0}")
private String templatesDir;
public ReportController(ReportService reportService,
ReportTemplateRepository templateRepository) {
this.reportService = reportService;
this.templateRepository = templateRepository;
}
@GetMapping("/api/report/render/{templateId}")
public ResponseEntity<byte[]> render(@PathVariable("templateId") String templateId,
@RequestParam(value = "format", required = false, defaultValue = "html") String format,
@RequestParam(value = "tpl", required = false) String tplPath,
HttpServletRequest request) {
Map<String, String> params = collectReportParams(request);
ReportService.Format fmt = ReportService.Format.parse(format);
byte[] body;
try {
if (tplPath != null && !tplPath.isBlank()) {
// dev/演示覆盖:直接渲染指定 .xml 文件(可为 JOR 文档或 view_template 外壳)。
Path xml = resolveTemplate(templateId, tplPath);
try (InputStream is = Files.newInputStream(xml)) {
body = reportService.render(is, params, format);
}
} else {
// 标准路径:按 templateId 从 view_template(type=200) 取 JOR 文档并渲染。
String jorXml = templateRepository.loadJorXml(templateId);
body = reportService.render(jorXml, params, format);
}
} catch (ReportTemplateRepository.ReportTemplateNotFoundException e) {
log.warn("报表模板未找到 templateId={} : {}", templateId, e.getMessage());
throw new ResponseStatusException(HttpStatus.NOT_FOUND, e.getMessage(), e);
} catch (ReportService.ReportRenderException e) {
log.warn("报表渲染失败 templateId={} tpl={} : {}", templateId, tplPath, e.getMessage());
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e);
} catch (ResponseStatusException e) {
throw e;
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,
"读取/渲染报表模板失败: " + e.getMessage(), e);
}
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(fmt.contentType()))
.body(body);
}
/** templateId / ?tpl 解析为模板文件路径。 */
private Path resolveTemplate(String templateId, String tplPath) {
Path xml;
if (tplPath != null && !tplPath.isBlank()) {
xml = Path.of(tplPath);
} else {
String rel = templateId;
if (!rel.toLowerCase().endsWith(".xml")) {
rel = rel + ".xml";
}
xml = Path.of(templatesDir).resolve(rel);
}
if (!Files.isRegularFile(xml)) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND,
"报表模板未找到: " + xml);
}
return xml;
}
/** 除 format/tpl 外的查询参数 = 报表参数(只取第一个值)。 */
private Map<String, String> collectReportParams(HttpServletRequest request) {
Map<String, String> params = new LinkedHashMap<>();
request.getParameterMap().forEach((name, values) -> {
if ("format".equals(name) || "tpl".equals(name)) {
return;
}
if (values != null && values.length > 0) {
params.put(name, values[0]);
}
});
return params;
}
}

View File

@@ -0,0 +1,154 @@
package com.eip4.platform.report;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import jatools.ReportDocument;
import jatools.engine.ReportJob;
import jatools.io.FileResourceOutputFactory;
import jatools.io.ResourceOutputFactory;
/**
* EIP3 JOR(jatools)报表引擎的 headless 渲染服务。
*
* <p>用预编译成品 {@code jatools.jar} 把 JOR 套打模板(.xml)在无界面环境下渲染为
* HTML / PDF / XLS。复刻 EIP3 {@code jatools.server.ReportExporter} 的纯引擎核心,
* 去掉所有 {@code com.dsasp.*} 应用胶水(SysConfig/POJOCRUDService/UserSession 等)。
*
* <p>渲染通道 = {@code jatools.engine.ReportJob}(而非 {@code LocalReportJob}):
* {@code ReportJob} 的 print 路径内部经 {@code ReportPrinter.declareExternalVariables}
* 把 {@link ReportJob#setParameter} 设入的查询参数声明为脚本变量,报表 SQL 里的
* {@code ${PARAM}} / {@code ${iif(PARAM,...)}} 由此绑定。{@code LocalReportJob} 不做这一步,
* 故必须走 {@code ReportJob}。
*
* <p>jatools 配置(timeformat / dayformat / company / font.dirs / DB 连接键)由
* {@link JatoolsConfig} 在 Bean 构造时注入 {@code jatools.engine.System2.properties}。
*/
@Service
public class ReportService {
private static final Logger log = LoggerFactory.getLogger(ReportService.class);
static {
// 引擎大量触及 java.awt(版式度量/图表/字体),无显示环境必须 headless。
System.setProperty("java.awt.headless", "true");
}
public ReportService(JatoolsConfig jatoolsConfig) {
// 触发 JatoolsConfig 构造(@PostConstruct 注入 System2 配置)先于任何渲染。
jatoolsConfig.ensureInitialized();
}
/** 支持的导出格式。 */
public enum Format {
HTML, PDF, XLS;
static Format parse(String s) {
if (s == null || s.isBlank()) {
return HTML;
}
return switch (s.trim().toLowerCase()) {
case "html", "dhtml", "htm" -> HTML;
case "pdf" -> PDF;
case "xls", "xlsx", "excel" -> XLS;
default -> throw new IllegalArgumentException("不支持的报表格式: " + s);
};
}
public String contentType() {
return switch (this) {
case HTML -> "text/html;charset=UTF-8";
case PDF -> "application/pdf";
case XLS -> "application/vnd.ms-excel";
};
}
}
/**
* 渲染一张 JOR 报表模板。
*
* @param templateXml 模板 XML 输入流(JOR .xml,如 EIP3 report 目录里的套打模板)
* @param params 查询参数(name → value);报表 SQL 中的 {@code ${PARAM}} 由此绑定
* @param format {@code html} / {@code pdf} / {@code xls}(大小写不敏感)
* @return 渲染产物字节(HTML 为 UTF-8 文本字节)
*/
/**
* 渲染一张 JOR 报表模板(从 JOR XML 字符串)。等同 {@link #render(InputStream, Map, String)},
* 便于直接喂从 DB({@code view_template}) 抽出的 JOR 文档。
*
* @param jorXml JOR 文档文本(以 {@code <jatools}/{@code <?xml ...><jatools} 开头)
*/
public byte[] render(String jorXml, Map<String, String> params, String format) {
return render(new ByteArrayInputStream(jorXml.getBytes(StandardCharsets.UTF_8)), params, format);
}
public byte[] render(InputStream templateXml, Map<String, String> params, String format) {
Format fmt = Format.parse(format);
File tmpDir = null;
try {
ReportDocument doc = ReportDocument.load(templateXml);
ReportJob job = new ReportJob(doc);
if (params != null) {
for (Map.Entry<String, String> e : params.entrySet()) {
if (e.getKey() != null) {
job.setParameter(e.getKey(), e.getValue());
}
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
switch (fmt) {
case HTML -> {
// HTML 内嵌图片等资源经 ResourceOutputFactory 落到临时目录(替代 servlet 会话沉淀)。
tmpDir = Files.createTempDirectory("eip4-report-").toFile();
ResourceOutputFactory imp = new FileResourceOutputFactory(tmpDir);
OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
job.printAsDHTML(imp, writer);
writer.flush();
}
case PDF -> job.printAsPDF(out);
case XLS -> job.printAsXLS(out);
}
return out.toByteArray();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new ReportRenderException("报表渲染失败 (format=" + fmt + "): " + e.getMessage(), e);
} finally {
deleteQuietly(tmpDir);
}
}
private static void deleteQuietly(File dir) {
if (dir == null || !dir.exists()) {
return;
}
File[] kids = dir.listFiles();
if (kids != null) {
for (File k : kids) {
deleteQuietly(k);
}
}
if (!dir.delete()) {
log.debug("临时目录清理失败(忽略): {}", dir);
}
}
/** 报表渲染异常(包裹 jatools 引擎抛出的受检异常)。 */
public static class ReportRenderException extends RuntimeException {
public ReportRenderException(String message, Throwable cause) {
super(message, cause);
}
}
}

View File

@@ -0,0 +1,100 @@
package com.eip4.platform.report;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
/**
* 按 {@code templateId} 从 EIP3 {@code view_template} 表(type=200 报表)取出可渲染的 JOR 模板。
*
* <p>{@code view_template.xml}(PG xml 列)对 type=200 行的结构:
* <pre>{@code
* <report entityid=... templateid=...>
* <display><field .../>...</display> <!-- 列定义 -->
* <reportfile><![CDATA[ <jatools ...>...ReportDocument... ]]></reportfile> <!-- 真正的 JOR 文档 -->
* <field name=... uitype=.../> <!-- 查询条件字段 -->
* </report>
* }</pre>
* 本类抽取 {@code <reportfile>...</reportfile>} 内层文本(剥掉 CDATA 包裹),得到以 {@code <jatools}
* 开头、含 {@code ReportDocument} 的 JOR 文档,交给 {@link ReportService#render} 渲染。
*/
@Repository
public class ReportTemplateRepository {
private static final Logger log = LoggerFactory.getLogger(ReportTemplateRepository.class);
/** 仅取 type=200 的报表模板;schema 限定到 eip3(模板/页面表所在 schema)。 */
private static final String LOAD_SQL =
"SELECT xml::text FROM eip3.view_template WHERE trim(view_template_id) = ? AND type = 200";
private final JdbcTemplate jdbcTemplate;
public ReportTemplateRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
/**
* 按 templateId 加载并抽取 JOR 文档。
*
* @param templateId {@code view_template.view_template_id}(允许含两端空白,内部 trim)
* @return 可渲染的 JOR XML(以 {@code <jatools}/{@code <?xml ...><jatools} 开头),找不到/无 reportfile 时抛出
*/
public String loadJorXml(String templateId) {
String id = templateId == null ? "" : templateId.trim();
List<String> rows = jdbcTemplate.queryForList(LOAD_SQL, String.class, id);
if (rows.isEmpty()) {
throw new ReportTemplateNotFoundException("未找到 type=200 报表模板: view_template_id=" + id);
}
String reportXml = rows.get(0);
if (reportXml == null || reportXml.isBlank()) {
throw new ReportTemplateNotFoundException("报表模板 xml 为空: view_template_id=" + id);
}
String jor = extractReportFile(reportXml);
if (jor == null) {
throw new ReportTemplateNotFoundException(
"报表模板缺少 <reportfile> JOR 文档: view_template_id=" + id);
}
log.debug("已加载 JOR 模板 templateId={} reportXmlBytes={} jorBytes={}", id, reportXml.length(), jor.length());
return jor;
}
/**
* 从 {@code <report>} 外壳里抽出 {@code <reportfile>} 内层 JOR 文档。
*
* <p>内层通常被 {@code <![CDATA[ ... ]]>} 包裹;剥掉 CDATA 后即得以 {@code <?xml ...><jatools ...>}
* 开头的 jatools ReportDocument。无 {@code <reportfile>} 节点时返回 {@code null}。
*/
static String extractReportFile(String reportXml) {
int open = reportXml.indexOf("<reportfile");
if (open < 0) {
return null;
}
int gt = reportXml.indexOf('>', open);
if (gt < 0) {
return null;
}
int close = reportXml.indexOf("</reportfile>", gt);
if (close < 0) {
return null;
}
String inner = reportXml.substring(gt + 1, close).trim();
if (inner.startsWith("<![CDATA[")) {
inner = inner.substring("<![CDATA[".length());
if (inner.endsWith("]]>")) {
inner = inner.substring(0, inner.length() - "]]>".length());
}
inner = inner.trim();
}
return inner.isEmpty() ? null : inner;
}
/** 模板未找到 / 无法抽取 JOR 文档。 */
public static class ReportTemplateNotFoundException extends RuntimeException {
public ReportTemplateNotFoundException(String message) {
super(message);
}
}
}

View File

@@ -28,6 +28,7 @@
<module>platform-cli</module>
<module>platform-mcp</module>
<module>platform-parity</module>
<module>platform-report</module>
<module>platform-app</module>
<!-- P3:Flowable 独立工作流服务(单客户交付四进程之一,独立可执行 jar,端口 8089) -->
<module>flowable-service</module>
@@ -87,6 +88,11 @@
<artifactId>platform-mcp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.eip4</groupId>
<artifactId>platform-report</artifactId>
<version>${project.version}</version>
</dependency>
<!-- G2: MCP Java SDK(BOM 管理版本;用 jackson2 路线与平台 jackson 2.x 一致) -->
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>