fix(report): 套打打印按选中行主键直接渲染,修单据打印空白
navigation+reportnosearch 打印按钮原嵌报表查看器,报表唯一的主键选择字段被 F3-1 剔除,选中行主键到不了 /api/report/render → SQL 用设计期默认 ID(库内不存在) → 空白。改为读目标报表 <search> 真实参数名,弹窗直接 iframe 渲染并注入选中行同名列(${selectedItems[0].P})。覆盖 195 个打印页(参数 PK/ID/PROJECTID 各异)。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -806,15 +806,27 @@ public class TemplateToAmisConverter {
|
||||
String navTitle = UiTypeMapper.firstNonBlank(b.attributeValue("funcname"), btnName);
|
||||
String pkCol = table + "_ID";
|
||||
boolean needSelected = !"false".equals(b.attributeValue("isneedselected"));
|
||||
boolean reportNoSearch = "true".equals(b.attributeValue("reportnosearch"));
|
||||
btn.put("actionType", "dialog");
|
||||
if (needSelected) {
|
||||
btn.put("disabledOn", DISABLED_ON_NO_SELECTION);
|
||||
}
|
||||
Map<String, Object> dlg = buildNavigationDialog(navTitle, funcId, pkCol, needSelected, result);
|
||||
btn.put("dialog", dlg);
|
||||
result.note("button[navigation] " + btnName + " → dialog service schemaApi=/api/page/schema/"
|
||||
+ funcId + "(funcname=" + navTitle + ",注入默认查询 " + pkCol + "=选中行主键"
|
||||
+ (needSelected ? ",需选中" : "") + ")");
|
||||
// 单据套打打印(reportnosearch + funcid→type=200 报表):老系统语义=对选中行直接出图、无查询表单。
|
||||
// → 直接 iframe 渲染 /api/report/render,按目标报表 <search> 参数名注入选中行同名列。
|
||||
// (原通用导航嵌报表查看器会把报表唯一的主键选择字段被 F3-1 剔除,选中行主键到不了 render → 空白单据。)
|
||||
List<String> reportParams = reportNoSearch ? loadReportSearchParams(funcId) : List.of();
|
||||
if (!reportParams.isEmpty()) {
|
||||
btn.put("dialog", buildReportPrintDialog(navTitle, funcId, reportParams));
|
||||
result.note("button[navigation] " + btnName + " → 套打直接渲染 /api/report/render/"
|
||||
+ funcId + "(reportnosearch,参数 " + String.join(",", reportParams)
|
||||
+ "=选中行同名列;funcname=" + navTitle + ")");
|
||||
} else {
|
||||
Map<String, Object> dlg = buildNavigationDialog(navTitle, funcId, pkCol, needSelected, result);
|
||||
btn.put("dialog", dlg);
|
||||
result.note("button[navigation] " + btnName + " → dialog service schemaApi=/api/page/schema/"
|
||||
+ funcId + "(funcname=" + navTitle + ",注入默认查询 " + pkCol + "=选中行主键"
|
||||
+ (needSelected ? ",需选中" : "") + ")");
|
||||
}
|
||||
}
|
||||
default -> result.note("button[" + btnType + "] " + btnName + " → 普通按钮占位");
|
||||
}
|
||||
@@ -921,6 +933,77 @@ public class TemplateToAmisConverter {
|
||||
return dlg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单据套打打印:navigation {@code reportnosearch=true} 按钮的目标 funcid 若指向 type=200 报表,
|
||||
* 返回该报表 {@code <search>} 的参数名列表(调用方按选中行同名列回填 {@code ${selectedItems[0].P}})。
|
||||
* 非报表 / 无 search 参 / 无库 / 查询异常 → 空表(调用方回退普通导航弹窗),保持零回归。
|
||||
*/
|
||||
private List<String> loadReportSearchParams(String funcId) {
|
||||
if (funcId == null || funcId.isBlank() || jdbcTemplate == null) {
|
||||
return List.of();
|
||||
}
|
||||
try {
|
||||
List<String> xmls = jdbcTemplate.query(
|
||||
"SELECT xml::text FROM view_template WHERE trim(view_template_id) = ? AND type = 200",
|
||||
(rs, n) -> rs.getString(1), funcId.trim());
|
||||
if (xmls.isEmpty() || xmls.get(0) == null || xmls.get(0).isBlank()) {
|
||||
return List.of();
|
||||
}
|
||||
Element search = DocumentHelper.parseText(xmls.get(0)).getRootElement().element("search");
|
||||
if (search == null) {
|
||||
return List.of();
|
||||
}
|
||||
List<String> params = new ArrayList<>();
|
||||
for (Element f : search.elements("field")) {
|
||||
String n = f.attributeValue("name", "");
|
||||
if (n != null && !n.isBlank() && !params.contains(n.trim())) {
|
||||
params.add(n.trim());
|
||||
}
|
||||
}
|
||||
return params;
|
||||
} catch (Exception e) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单据套打打印弹窗(navigation reportnosearch + funcid→type=200 报表):直接 iframe 渲染目标报表,
|
||||
* 把选中行同名列按报表 {@code <search>} 参数名注入 dialog data({@code ${selectedItems[0].P}},按钮作用域求值),
|
||||
* iframe / 导出 URL 内引用 {@code ${P}};无查询表单(reportnosearch 语义)。+ 导出 PDF/Excel + 关闭。
|
||||
*
|
||||
* <p>参数名为元数据字段名(IDENT,无 URL 特殊字符),裸拼安全;{@code ${P}} 须保持字面量供 amis 运行时插值。
|
||||
* 服务端 {@code ReportParamGuard} 仅放行报表 {@code <search>} 引用的参数并做白名单校验,越权/注入再过一道。
|
||||
*/
|
||||
private Map<String, Object> buildReportPrintDialog(String title, String funcId, List<String> params) {
|
||||
String tid = funcId.trim();
|
||||
Map<String, Object> dlg = new LinkedHashMap<>();
|
||||
dlg.put("type", "dialog");
|
||||
dlg.put("title", title);
|
||||
dlg.put("size", "lg");
|
||||
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
StringBuilder qp = new StringBuilder();
|
||||
for (String p : params) {
|
||||
data.put(p, selectedSingleIdExpr(p)); // ${selectedItems[0].P}
|
||||
qp.append('&').append(p).append("=${").append(p).append('}');
|
||||
}
|
||||
dlg.put("data", data);
|
||||
|
||||
String renderBase = "/api/report/render/" + tid + "?format=";
|
||||
Map<String, Object> html = new LinkedHashMap<>();
|
||||
html.put("type", "html");
|
||||
html.put("html", "<iframe src=\"" + renderBase + "html" + qp
|
||||
+ "\" style=\"width:100%;min-height:680px;border:0;\" frameborder=\"0\"></iframe>");
|
||||
dlg.put("body", html);
|
||||
|
||||
List<Map<String, Object>> actions = new ArrayList<>();
|
||||
actions.add(reportExportButton("导出PDF", renderBase + "pdf" + qp));
|
||||
actions.add(reportExportButton("导出Excel", renderBase + "xls" + qp));
|
||||
actions.add(new LinkedHashMap<>(Map.of("type", "button", "actionType", "close", "label", "关闭")));
|
||||
dlg.put("actions", actions);
|
||||
return dlg;
|
||||
}
|
||||
|
||||
/**
|
||||
* F2-17 / 服务流分派:构造 dialog body 为 service 加载 /api/page/schema/{templateId} 的 dialog。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user