fix(report): 注入配置公司名覆盖模板占位「XXXXXX公司」
报表抬头绑自定义参数 COMPANY(经 jatools =COMPANY 表达式,非 ${}宏),默认值是占位「XXXXXX公司」,EIP4 从不注入 → 显占位。新增 ReportParamGuard.applyConfiguredCompany():模板声明 COMPANY 时注入 eip4.report.company 配置值。部署设客户公司名即全报表生效。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -64,6 +64,10 @@ public class ReportController {
|
|||||||
@Value("${eip4.report.require-menu-grant:true}")
|
@Value("${eip4.report.require-menu-grant:true}")
|
||||||
private boolean requireMenuGrant;
|
private boolean requireMenuGrant;
|
||||||
|
|
||||||
|
/** 报表公司名(注入模板自定义 COMPANY 参数,覆盖设计期占位"XXXXXX公司")。与 JatoolsConfig 同源配置,部署时设为客户公司名。 */
|
||||||
|
@Value("${eip4.report.company:EIP4}")
|
||||||
|
private String reportCompany;
|
||||||
|
|
||||||
public ReportController(ReportService reportService,
|
public ReportController(ReportService reportService,
|
||||||
ReportTemplateRepository templateRepository,
|
ReportTemplateRepository templateRepository,
|
||||||
Environment environment) {
|
Environment environment) {
|
||||||
@@ -217,7 +221,10 @@ public class ReportController {
|
|||||||
new String(xmlBytes, StandardCharsets.ISO_8859_1));
|
new String(xmlBytes, StandardCharsets.ISO_8859_1));
|
||||||
Map<String, String> client = collectReportParams(request);
|
Map<String, String> client = collectReportParams(request);
|
||||||
Map<String, String> safe = ReportParamGuard.sanitizeClientParams(client, referenced);
|
Map<String, String> safe = ReportParamGuard.sanitizeClientParams(client, referenced);
|
||||||
return ReportParamGuard.applyTrustedIdentity(safe, referenced, trustedIdentity());
|
Map<String, String> withId = ReportParamGuard.applyTrustedIdentity(safe, referenced, trustedIdentity());
|
||||||
|
// COMPANY 经 jatools =COMPANY 绑定(非 ${}),按声明探测注入配置公司名,覆盖占位"XXXXXX公司"。
|
||||||
|
return ReportParamGuard.applyConfiguredCompany(withId,
|
||||||
|
new String(xmlBytes, StandardCharsets.ISO_8859_1), reportCompany);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -143,4 +143,26 @@ public final class ReportParamGuard {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 报表标题等用的公司名参数。模板常把它声明为自定义参数,默认值是占位符如「XXXXXX公司」。 */
|
||||||
|
static final String COMPANY_PARAM = "COMPANY";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板声明了 {@code COMPANY} 变量/参数时,注入服务端配置的公司名(覆盖设计期占位默认,如「XXXXXX公司」)。
|
||||||
|
*
|
||||||
|
* <p>{@code COMPANY} 经 jatools {@code =COMPANY} 表达式绑定(非 {@code ${}} 宏),不在
|
||||||
|
* {@link #extractReferencedParamNames} 覆盖内,故单独按声明 token 探测。值来自服务端配置
|
||||||
|
* ({@code eip4.report.company}),非客户端输入,无需走 {@link #isSafeValue}(且公司名常含中文/空格)。
|
||||||
|
*
|
||||||
|
* @param company 配置的真实公司名;空 / 模板未声明 COMPANY → 原样返回(保持占位,零回归)
|
||||||
|
*/
|
||||||
|
static Map<String, String> applyConfiguredCompany(Map<String, String> params, String templateXml, String company) {
|
||||||
|
if (company == null || company.isBlank() || templateXml == null
|
||||||
|
|| !(templateXml.contains("Name=\"COMPANY\"") || templateXml.contains("<Name>COMPANY</Name>"))) {
|
||||||
|
return params == null ? Map.of() : params;
|
||||||
|
}
|
||||||
|
Map<String, String> out = new LinkedHashMap<>(params == null ? Map.of() : params);
|
||||||
|
out.put(COMPANY_PARAM, company);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,4 +201,35 @@ class ReportParamGuardTest {
|
|||||||
assertEquals(safe, ReportParamGuard.applyTrustedIdentity(safe, referenced, null));
|
assertEquals(safe, ReportParamGuard.applyTrustedIdentity(safe, referenced, null));
|
||||||
assertEquals(safe, ReportParamGuard.applyTrustedIdentity(safe, referenced, Map.of()));
|
assertEquals(safe, ReportParamGuard.applyTrustedIdentity(safe, referenced, Map.of()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- applyConfiguredCompany:模板声明 COMPANY 参数时注入配置公司名,覆盖占位默认("XXXXXX公司") ----
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void applyConfiguredCompany_injects_when_template_declares_COMPANY() {
|
||||||
|
Map<String, String> params = new LinkedHashMap<>();
|
||||||
|
params.put("PROJECTID", "P-1");
|
||||||
|
String xml = "<Report><Variables><Item style=\"Parameter\" Name=\"COMPANY\">"
|
||||||
|
+ "<Name>COMPANY</Name><DefaultValue>XXXXXX公司</DefaultValue></Item></Variables></Report>";
|
||||||
|
|
||||||
|
Map<String, String> out = ReportParamGuard.applyConfiguredCompany(params, xml, "示例科技有限公司");
|
||||||
|
|
||||||
|
assertEquals("示例科技有限公司", out.get("COMPANY"), "声明 COMPANY 的模板应注入配置公司名");
|
||||||
|
assertEquals("P-1", out.get("PROJECTID"), "其他参数不动");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void applyConfiguredCompany_noop_when_no_COMPANY_param() {
|
||||||
|
Map<String, String> params = Map.of("PROJECTID", "P-1");
|
||||||
|
Map<String, String> out = ReportParamGuard.applyConfiguredCompany(params, "<Report><Variables/></Report>", "示例公司");
|
||||||
|
assertFalse(out.containsKey("COMPANY"), "未声明 COMPANY → 不注入");
|
||||||
|
assertEquals("P-1", out.get("PROJECTID"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void applyConfiguredCompany_noop_when_company_blank_or_null() {
|
||||||
|
String xml = "<Item Name=\"COMPANY\"><Name>COMPANY</Name></Item>";
|
||||||
|
assertFalse(ReportParamGuard.applyConfiguredCompany(new LinkedHashMap<>(), xml, "").containsKey("COMPANY"));
|
||||||
|
assertFalse(ReportParamGuard.applyConfiguredCompany(new LinkedHashMap<>(), xml, null).containsKey("COMPANY"));
|
||||||
|
assertFalse(ReportParamGuard.applyConfiguredCompany(new LinkedHashMap<>(), xml, " ").containsKey("COMPANY"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user