fix(report): 公司名改取系统配置 sys_application_config,不用静态 Spring 值
用户指正:报表抬头公司名应取系统配置的值。新增 ReportTemplateRepository.loadCompanyName() 读 sys_application_config[com.dsasp.server.organize.COMPANY](客户系统参数里维护的公司名,如「苏州第五建筑集团有限公司」);ReportController 优先用它,缺失才回退 eip4.report.company。部署无需额外配置,直接复用客户已维护的系统参数。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -222,9 +222,14 @@ public class ReportController {
|
||||
Map<String, String> client = collectReportParams(request);
|
||||
Map<String, String> safe = ReportParamGuard.sanitizeClientParams(client, referenced);
|
||||
Map<String, String> withId = ReportParamGuard.applyTrustedIdentity(safe, referenced, trustedIdentity());
|
||||
// COMPANY 经 jatools =COMPANY 绑定(非 ${}),按声明探测注入配置公司名,覆盖占位"XXXXXX公司"。
|
||||
// COMPANY 经 jatools =COMPANY 绑定(非 ${}),按声明探测注入公司名,覆盖占位"XXXXXX公司"。
|
||||
// 优先取客户系统配置(sys_application_config[com.dsasp.server.organize.COMPANY]),缺失再回退 eip4.report.company。
|
||||
String company = templateRepository.loadCompanyName();
|
||||
if (company == null || company.isBlank()) {
|
||||
company = reportCompany;
|
||||
}
|
||||
return ReportParamGuard.applyConfiguredCompany(withId,
|
||||
new String(xmlBytes, StandardCharsets.ISO_8859_1), reportCompany);
|
||||
new String(xmlBytes, StandardCharsets.ISO_8859_1), company);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,6 +34,11 @@ public class ReportTemplateRepository {
|
||||
private static final String NAME_SQL =
|
||||
"SELECT name FROM eip3.view_template WHERE trim(view_template_id) = ? AND type = 200";
|
||||
|
||||
/** 报表抬头公司名:取自客户系统配置 {@code sys_application_config} 的固定键(dsasp 全局参数)。 */
|
||||
private static final String COMPANY_CONFIG_KEY = "com.dsasp.server.organize.COMPANY";
|
||||
private static final String COMPANY_SQL =
|
||||
"SELECT value FROM eip3.sys_application_config WHERE trim(sys_application_config_id) = ? AND isactive = 1";
|
||||
|
||||
/**
|
||||
* 对象级授权(防 IDOR):该 templateId 报表是否经某个<em>用户可见菜单</em>暴露给该用户。
|
||||
* 关联 {@code view_sys_menu.view_templateid} ←→ {@code view_sys_usermenuid}(用户→可见菜单);
|
||||
@@ -94,6 +99,25 @@ public class ReportTemplateRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 报表抬头公司名:取自客户系统配置 {@code sys_application_config[com.dsasp.server.organize.COMPANY]}
|
||||
* (即系统参数管理里维护的公司名,如「苏州第五建筑集团有限公司」)。最佳努力:找不到/异常返回 {@code null}
|
||||
* (调用方回退 {@code eip4.report.company} 配置),绝不因取名失败影响渲染。
|
||||
*/
|
||||
public String loadCompanyName() {
|
||||
try {
|
||||
List<String> rows = jdbcTemplate.queryForList(COMPANY_SQL, String.class, COMPANY_CONFIG_KEY);
|
||||
if (rows.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
String v = rows.get(0);
|
||||
return v == null || v.isBlank() ? null : v.trim();
|
||||
} catch (RuntimeException e) {
|
||||
log.debug("取系统公司名失败 key={} : {}", COMPANY_CONFIG_KEY, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前用户能否访问该报表(经其可见菜单暴露)。userId/templateId 为空返回 {@code false}。
|
||||
* 仅做存在性判定,超管放行由调用方(控制器)按身份决定,本方法不含超管旁路。
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.eip4.platform.report;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
* 报表抬头公司名取自客户系统配置 {@code sys_application_config[com.dsasp.server.organize.COMPANY]},
|
||||
* 而非静态 Spring 配置(用户指正:应用系统配置的值)。最佳努力,失败回退 null 由调用方兜底。
|
||||
*
|
||||
* <p>platform-report 测试不引入 Mockito,故用手写 {@link JdbcTemplate} 桩覆写 {@code queryForList}。
|
||||
*/
|
||||
class ReportTemplateRepositoryTest {
|
||||
|
||||
private static ReportTemplateRepository repo(List<String> rows, boolean throwErr) {
|
||||
JdbcTemplate jdbc = new JdbcTemplate() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> queryForList(String sql, Class<T> elementType, Object... args) {
|
||||
if (throwErr) {
|
||||
throw new RuntimeException("db down");
|
||||
}
|
||||
return (List<T>) rows;
|
||||
}
|
||||
};
|
||||
return new ReportTemplateRepository(jdbc);
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadCompanyName_returns_trimmed_system_config_value() {
|
||||
assertEquals("苏州第五建筑集团有限公司",
|
||||
repo(List.of("苏州第五建筑集团有限公司 "), false).loadCompanyName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadCompanyName_null_when_no_config_row() {
|
||||
assertNull(repo(List.of(), false).loadCompanyName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadCompanyName_null_on_query_error() {
|
||||
assertNull(repo(List.of(), true).loadCompanyName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user